From 8d5d78431c8e8b6a5ffbfb167d66cedb63febfd6 Mon Sep 17 00:00:00 2001 From: junderw Date: Thu, 7 Mar 2019 12:47:26 +0900 Subject: [PATCH] Fix P2PK payment lint --- src/payments/p2pk.js | 14 +++++++------- ts_src/payments/index.ts | 1 + ts_src/payments/p2pk.ts | 22 +++++++++++----------- types/payments/index.d.ts | 1 + 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/payments/p2pk.js b/src/payments/p2pk.js index 9c9318f..81fe427 100644 --- a/src/payments/p2pk.js +++ b/src/payments/p2pk.js @@ -1,8 +1,8 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +const networks_1 = require("../networks"); const bscript = require("../script"); const lazy = require("./lazy"); -const networks_1 = require("../networks"); const typef = require('typeforce'); const OPS = bscript.OPS; const ecc = require('tiny-secp256k1'); @@ -19,32 +19,32 @@ function p2pk(a, opts) { signature: typef.maybe(bscript.isCanonicalScriptSignature), input: typef.maybe(typef.Buffer), }, a); - const _chunks = lazy.value(function () { + const _chunks = lazy.value(() => { return bscript.decompile(a.input); }); const network = a.network || networks_1.bitcoin; const o = { network }; - lazy.prop(o, 'output', function () { + lazy.prop(o, 'output', () => { if (!a.pubkey) return; return bscript.compile([a.pubkey, OPS.OP_CHECKSIG]); }); - lazy.prop(o, 'pubkey', function () { + lazy.prop(o, 'pubkey', () => { if (!a.output) return; return a.output.slice(1, -1); }); - lazy.prop(o, 'signature', function () { + lazy.prop(o, 'signature', () => { if (!a.input) return; return _chunks()[0]; }); - lazy.prop(o, 'input', function () { + lazy.prop(o, 'input', () => { if (!a.signature) return; return bscript.compile([a.signature]); }); - lazy.prop(o, 'witness', function () { + lazy.prop(o, 'witness', () => { if (!o.input) return; return []; diff --git a/ts_src/payments/index.ts b/ts_src/payments/index.ts index 4f6eb75..0c70fba 100644 --- a/ts_src/payments/index.ts +++ b/ts_src/payments/index.ts @@ -31,6 +31,7 @@ export interface PaymentOpts { export type StackElement = Buffer | number; export type Stack = StackElement[]; +export type StackFunction = () => Stack; export { embed, p2ms, p2pk, p2pkh, p2sh, p2wpkh, p2wsh }; diff --git a/ts_src/payments/p2pk.ts b/ts_src/payments/p2pk.ts index 69fb404..d14aacf 100644 --- a/ts_src/payments/p2pk.ts +++ b/ts_src/payments/p2pk.ts @@ -1,7 +1,7 @@ -import { Payment, PaymentOpts } from './index'; -import * as bscript from '../script'; -import * as lazy from './lazy'; import { bitcoin as BITCOIN_NETWORK } from '../networks'; +import * as bscript from '../script'; +import { Payment, PaymentOpts, StackFunction } from './index'; +import * as lazy from './lazy'; const typef = require('typeforce'); const OPS = bscript.OPS; const ecc = require('tiny-secp256k1'); @@ -25,30 +25,30 @@ export function p2pk(a: Payment, opts?: PaymentOpts): Payment { a, ); - const _chunks = <() => Array>lazy.value(function() { + const _chunks = lazy.value(() => { return bscript.decompile(a.input!); - }); + }) as StackFunction; const network = a.network || BITCOIN_NETWORK; const o: Payment = { network }; - lazy.prop(o, 'output', function() { + lazy.prop(o, 'output', () => { if (!a.pubkey) return; return bscript.compile([a.pubkey, OPS.OP_CHECKSIG]); }); - lazy.prop(o, 'pubkey', function() { + lazy.prop(o, 'pubkey', () => { if (!a.output) return; return a.output.slice(1, -1); }); - lazy.prop(o, 'signature', function() { + lazy.prop(o, 'signature', () => { if (!a.input) return; - return _chunks()[0]; + return _chunks()[0] as Buffer; }); - lazy.prop(o, 'input', function() { + lazy.prop(o, 'input', () => { if (!a.signature) return; return bscript.compile([a.signature]); }); - lazy.prop(o, 'witness', function() { + lazy.prop(o, 'witness', () => { if (!o.input) return; return []; }); diff --git a/types/payments/index.d.ts b/types/payments/index.d.ts index 3009bef..66654d2 100644 --- a/types/payments/index.d.ts +++ b/types/payments/index.d.ts @@ -29,4 +29,5 @@ export interface PaymentOpts { } export declare type StackElement = Buffer | number; export declare type Stack = StackElement[]; +export declare type StackFunction = () => Stack; export { embed, p2ms, p2pk, p2pkh, p2sh, p2wpkh, p2wsh };