From c488001b824a6c60f25af0aaf220bec98631bddf Mon Sep 17 00:00:00 2001 From: junderw Date: Fri, 28 Dec 2018 14:45:17 +0900 Subject: [PATCH] Add P2WPKH --- src/templates/witnesspubkeyhash/index.ts | 10 ++++++---- src/templates/witnesspubkeyhash/input.ts | 13 +++++-------- src/templates/witnesspubkeyhash/output.ts | 9 ++------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/templates/witnesspubkeyhash/index.ts b/src/templates/witnesspubkeyhash/index.ts index 7192cfd..42aeb7b 100644 --- a/src/templates/witnesspubkeyhash/index.ts +++ b/src/templates/witnesspubkeyhash/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/witnesspubkeyhash/input.ts b/src/templates/witnesspubkeyhash/input.ts index ec93c47..36f0606 100644 --- a/src/templates/witnesspubkeyhash/input.ts +++ b/src/templates/witnesspubkeyhash/input.ts @@ -1,19 +1,16 @@ // {signature} {pubKey} -const bscript = require('../../script') +import * as bscript from '../../script' -function isCompressedCanonicalPubKey (pubKey) { +function isCompressedCanonicalPubKey (pubKey: Buffer): boolean { return bscript.isCanonicalPubKey(pubKey) && pubKey.length === 33 } -function check (script) { +export function check (script: Buffer | Array): boolean { const chunks = bscript.decompile(script) return chunks.length === 2 && - bscript.isCanonicalScriptSignature(chunks[0]) && - isCompressedCanonicalPubKey(chunks[1]) + bscript.isCanonicalScriptSignature(chunks[0]) && + isCompressedCanonicalPubKey(chunks[1]) } check.toJSON = function () { return 'witnessPubKeyHash input' } - -module.exports = { check } -export {} diff --git a/src/templates/witnesspubkeyhash/output.ts b/src/templates/witnesspubkeyhash/output.ts index a289038..46fb444 100644 --- a/src/templates/witnesspubkeyhash/output.ts +++ b/src/templates/witnesspubkeyhash/output.ts @@ -1,9 +1,9 @@ // OP_0 {pubKeyHash} -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 === 22 && @@ -11,8 +11,3 @@ function check (script) { buffer[1] === 0x14 } check.toJSON = function () { return 'Witness pubKeyHash output' } - -module.exports = { - check -} -export {}