From 3db951fc6454d61e7ebb40d6c873124e8f9f75db Mon Sep 17 00:00:00 2001 From: junderw Date: Fri, 28 Dec 2018 14:32:20 +0900 Subject: [PATCH] Add p2pkh template --- src/templates/pubkeyhash/index.ts | 10 ++++++---- src/templates/pubkeyhash/input.ts | 11 ++++------- src/templates/pubkeyhash/output.ts | 7 ++----- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/templates/pubkeyhash/index.ts b/src/templates/pubkeyhash/index.ts index 7192cfd..42aeb7b 100644 --- a/src/templates/pubkeyhash/index.ts +++ b/src/templates/pubkeyhash/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/pubkeyhash/input.ts b/src/templates/pubkeyhash/input.ts index cab6f0a..ffdc929 100644 --- a/src/templates/pubkeyhash/input.ts +++ b/src/templates/pubkeyhash/input.ts @@ -1,15 +1,12 @@ // {signature} {pubKey} -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 === 2 && - bscript.isCanonicalScriptSignature(chunks[0]) && - bscript.isCanonicalPubKey(chunks[1]) + bscript.isCanonicalScriptSignature(chunks[0]) && + bscript.isCanonicalPubKey(chunks[1]) } check.toJSON = function () { return 'pubKeyHash input' } - -module.exports = { check } -export {} diff --git a/src/templates/pubkeyhash/output.ts b/src/templates/pubkeyhash/output.ts index bf34b83..71c1acb 100644 --- a/src/templates/pubkeyhash/output.ts +++ b/src/templates/pubkeyhash/output.ts @@ -1,9 +1,9 @@ // OP_DUP OP_HASH160 {pubKeyHash} OP_EQUALVERIFY 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 buffer = bscript.compile(script) return buffer.length === 25 && @@ -14,6 +14,3 @@ function check (script) { buffer[24] === OPS.OP_CHECKSIG } check.toJSON = function () { return 'pubKeyHash output' } - -module.exports = { check } -export {}