From 604072ffaded0f9a982aa8cefd39227044b62da3 Mon Sep 17 00:00:00 2001 From: junderw Date: Fri, 28 Dec 2018 14:57:30 +0900 Subject: [PATCH] Add P2SH --- src/templates/scripthash/index.ts | 10 ++++++---- src/templates/scripthash/input.ts | 21 +++++++++------------ src/templates/scripthash/output.ts | 7 ++----- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/templates/scripthash/index.ts b/src/templates/scripthash/index.ts index 7192cfd..42aeb7b 100644 --- a/src/templates/scripthash/index.ts +++ b/src/templates/scripthash/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/scripthash/input.ts b/src/templates/scripthash/input.ts index ad53df9..908a87b 100644 --- a/src/templates/scripthash/input.ts +++ b/src/templates/scripthash/input.ts @@ -1,15 +1,15 @@ // {serialized scriptPubKey script} +import * as bscript from '../../script' +import * as p2ms from '../multisig' +import * as p2pk from '../pubkey' +import * as p2pkh from '../pubkeyhash' +import * as p2wpkho from '../witnesspubkeyhash/output' +import * as p2wsho from '../witnessscripthash/output' + const Buffer = require('safe-buffer').Buffer -const bscript = require('../../script') -const p2ms = require('../multisig/') -const p2pk = require('../pubkey/') -const p2pkh = require('../pubkeyhash/') -const p2wpkho = require('../witnesspubkeyhash/output') -const p2wsho = require('../witnessscripthash/output') - -function check (script, allowIncomplete) { +export function check (script: Buffer | Array, allowIncomplete?: boolean): boolean { const chunks = bscript.decompile(script) if (chunks.length < 1) return false @@ -17,7 +17,7 @@ function check (script, allowIncomplete) { if (!Buffer.isBuffer(lastChunk)) return false const scriptSigChunks = bscript.decompile(bscript.compile(chunks.slice(0, -1))) - const redeemScriptChunks = bscript.decompile(lastChunk) + const redeemScriptChunks = bscript.decompile(lastChunk) // is redeemScript a valid script? if (!redeemScriptChunks) return false @@ -44,6 +44,3 @@ function check (script, allowIncomplete) { return false } check.toJSON = function () { return 'scriptHash input' } - -module.exports = { check } -export {} diff --git a/src/templates/scripthash/output.ts b/src/templates/scripthash/output.ts index 9f91f17..3215c25 100644 --- a/src/templates/scripthash/output.ts +++ b/src/templates/scripthash/output.ts @@ -1,9 +1,9 @@ // OP_HASH160 {scriptHash} OP_EQUAL -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 === 23 && @@ -12,6 +12,3 @@ function check (script) { buffer[22] === OPS.OP_EQUAL } check.toJSON = function () { return 'scriptHash output' } - -module.exports = { check } -export {}