From 9da1c95f890ef7dc7142a2be338d487149d93886 Mon Sep 17 00:00:00 2001 From: junderw Date: Fri, 28 Dec 2018 13:23:23 +0900 Subject: [PATCH] Add P2PK templates --- src/templates/multisig/input.ts | 4 ++-- src/templates/pubkey/index.ts | 10 ++++++---- src/templates/pubkey/input.ts | 11 +++-------- src/templates/pubkey/output.ts | 9 +++------ 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/templates/multisig/input.ts b/src/templates/multisig/input.ts index 864c793..2060242 100644 --- a/src/templates/multisig/input.ts +++ b/src/templates/multisig/input.ts @@ -3,8 +3,8 @@ import * as bscript from '../../script' const OPS = require('bitcoin-ops') -function partialSignature (value) { - return value === OPS.OP_0 || bscript.isCanonicalScriptSignature(value) +function partialSignature (value: number | Buffer): boolean { + return value === OPS.OP_0 || bscript.isCanonicalScriptSignature(value) } export function check (script: Buffer | Array, allowIncomplete?: boolean): boolean { diff --git a/src/templates/pubkey/index.ts b/src/templates/pubkey/index.ts index 7192cfd..42aeb7b 100644 --- a/src/templates/pubkey/index.ts +++ b/src/templates/pubkey/index.ts @@ -1,5 +1,7 @@ -module.exports = { - input: require('./input'), - output: require('./output') +import * as input from './input' +import * as output from './output' + +export { + input, + output, } -export {} diff --git a/src/templates/pubkey/input.ts b/src/templates/pubkey/input.ts index b6963e7..f4b8bf7 100644 --- a/src/templates/pubkey/input.ts +++ b/src/templates/pubkey/input.ts @@ -1,16 +1,11 @@ // {signature} -const bscript = require('../../script') +import * as bscript from '../../script' -function check (script) { +export function check (script: Buffer | Array): boolean { const chunks = bscript.decompile(script) return chunks.length === 1 && - bscript.isCanonicalScriptSignature(chunks[0]) + bscript.isCanonicalScriptSignature(chunks[0]) } check.toJSON = function () { return 'pubKey input' } - -module.exports = { - check: check -} -export {} diff --git a/src/templates/pubkey/output.ts b/src/templates/pubkey/output.ts index b64c596..2728f68 100644 --- a/src/templates/pubkey/output.ts +++ b/src/templates/pubkey/output.ts @@ -1,16 +1,13 @@ // {pubKey} OP_CHECKSIG -const bscript = require('../../script') +import * as bscript from '../../script' const OPS = require('bitcoin-ops') -function check (script) { +export function check (script: Buffer | Array): boolean { const chunks = bscript.decompile(script) return chunks.length === 2 && - bscript.isCanonicalPubKey(chunks[0]) && + bscript.isCanonicalPubKey(chunks[0]) && chunks[1] === OPS.OP_CHECKSIG } check.toJSON = function () { return 'pubKey output' } - -module.exports = { check } -export {}