diff --git a/src/templates/multisig/input.js b/src/templates/multisig/input.js index 1bc00f2..847ebe9 100644 --- a/src/templates/multisig/input.js +++ b/src/templates/multisig/input.js @@ -19,6 +19,7 @@ function check (script, allowIncomplete) { return chunks.slice(1).every(bscript.isCanonicalSignature) } +check.toJSON = function () { return 'multi-sig input' } function encode (signatures, scriptPubKey) { typeforce([partialSignature], signatures) diff --git a/src/templates/multisig/output.js b/src/templates/multisig/output.js index 087530b..0f4fe7d 100644 --- a/src/templates/multisig/output.js +++ b/src/templates/multisig/output.js @@ -25,6 +25,7 @@ function check (script, allowIncomplete) { var keys = chunks.slice(1, -2) return keys.every(bscript.isCanonicalPubKey) } +check.toJSON = function () { return 'multi-sig output' } function encode (m, pubKeys) { typeforce({ diff --git a/src/templates/nulldata.js b/src/templates/nulldata.js index 5b6af90..163249f 100644 --- a/src/templates/nulldata.js +++ b/src/templates/nulldata.js @@ -11,6 +11,7 @@ function check (script) { return buffer.length > 1 && buffer[0] === OPS.OP_RETURN } +check.toJSON = function () { return 'null data output' } function encode (data) { typeforce(types.Buffer, data) diff --git a/src/templates/pubkey/input.js b/src/templates/pubkey/input.js index 82a2dfe..7357adc 100644 --- a/src/templates/pubkey/input.js +++ b/src/templates/pubkey/input.js @@ -10,6 +10,7 @@ function check (script) { return chunks.length === 1 && bscript.isCanonicalSignature(chunks[0]) } +check.toJSON = function () { return 'pubKey input' } function encode (signature) { typeforce(types.Buffer, signature) diff --git a/src/templates/pubkey/output.js b/src/templates/pubkey/output.js index 1e6f961..83b5c50 100644 --- a/src/templates/pubkey/output.js +++ b/src/templates/pubkey/output.js @@ -11,6 +11,7 @@ function check (script) { bscript.isCanonicalPubKey(chunks[0]) && chunks[1] === OPS.OP_CHECKSIG } +check.toJSON = function () { return 'pubKey output' } function encode (pubKey) { typeforce(bscript.isCanonicalPubKey, pubKey) diff --git a/src/templates/pubkeyhash/input.js b/src/templates/pubkeyhash/input.js index 8a55ab7..f91a322 100644 --- a/src/templates/pubkeyhash/input.js +++ b/src/templates/pubkeyhash/input.js @@ -11,6 +11,7 @@ function check (script) { bscript.isCanonicalSignature(chunks[0]) && bscript.isCanonicalPubKey(chunks[1]) } +check.toJSON = function () { return 'pubKeyHash input' } function encode (signature, pubKey) { typeforce({ diff --git a/src/templates/pubkeyhash/output.js b/src/templates/pubkeyhash/output.js index a7d87b9..4c11006 100644 --- a/src/templates/pubkeyhash/output.js +++ b/src/templates/pubkeyhash/output.js @@ -15,6 +15,7 @@ function check (script) { buffer[23] === OPS.OP_EQUALVERIFY && buffer[24] === OPS.OP_CHECKSIG } +check.toJSON = function () { return 'pubKeyHash output' } function encode (pubKeyHash) { typeforce(types.Hash160bit, pubKeyHash) diff --git a/src/templates/scripthash/input.js b/src/templates/scripthash/input.js index 569b2a9..319b2cc 100644 --- a/src/templates/scripthash/input.js +++ b/src/templates/scripthash/input.js @@ -20,6 +20,7 @@ function check (script, allowIncomplete) { var outputType = bscript.classifyOutput(redeemScriptChunks) return inputType === outputType } +check.toJSON = function () { return 'scriptHash input' } function encode (scriptSignature, scriptPubKey) { var scriptSigChunks = bscript.decompile(scriptSignature) diff --git a/src/templates/scripthash/output.js b/src/templates/scripthash/output.js index d73aa8b..fe3b5ce 100644 --- a/src/templates/scripthash/output.js +++ b/src/templates/scripthash/output.js @@ -13,6 +13,7 @@ function check (script) { buffer[1] === 0x14 && buffer[22] === OPS.OP_EQUAL } +check.toJSON = function () { return 'scriptHash output' } function encode (scriptHash) { typeforce(types.Hash160bit, scriptHash) diff --git a/src/templates/witnesspubkeyhash/output.js b/src/templates/witnesspubkeyhash/output.js index fdf2ae2..0eae63e 100644 --- a/src/templates/witnesspubkeyhash/output.js +++ b/src/templates/witnesspubkeyhash/output.js @@ -12,6 +12,7 @@ function check (script) { buffer[0] === OPS.OP_0 && buffer[1] === 0x14 } +check.toJSON = function () { return 'Witness pubKeyHash output' } function encode (pubKeyHash) { typeforce(types.Hash160bit, pubKeyHash) diff --git a/src/templates/witnessscripthash/output.js b/src/templates/witnessscripthash/output.js index a8f92a0..00fb838 100644 --- a/src/templates/witnessscripthash/output.js +++ b/src/templates/witnessscripthash/output.js @@ -12,6 +12,7 @@ function check (script) { buffer[0] === OPS.OP_0 && buffer[1] === 0x20 } +check.toJSON = function () { return 'Witness scriptHash output' } function encode (scriptHash) { typeforce(types.Hash256bit, scriptHash) diff --git a/test/templates.js b/test/templates.js index 6edcfbd..9fc8d95 100644 --- a/test/templates.js +++ b/test/templates.js @@ -323,17 +323,22 @@ describe('script-templates', function () { }) }) - describe('witnessScriptHash.outputs.encode', function () { + describe('witnessScriptHash.output', function () { fixtures.valid.forEach(function (f) { if (f.type !== 'witnessscripthash') return if (!f.scriptPubKey) return - it('returns ' + f.scriptPubKey, function () { - var witnessScriptPubKey = bscript.fromASM(f.witnessScriptPubKey) - var scriptPubKey = bscript.witnessScriptHash.output.encode(bcrypto.hash256(witnessScriptPubKey)) + var witnessScriptPubKey = bscript.fromASM(f.witnessScriptPubKey) + var scriptHash = bcrypto.hash256(witnessScriptPubKey) + var scriptPubKey = bscript.witnessScriptHash.output.encode(scriptHash) + it('encodes to ' + f.scriptPubKey, function () { assert.strictEqual(bscript.toASM(scriptPubKey), f.scriptPubKey) }) + + it('decodes to ' + scriptHash.toString('hex'), function () { + assert.deepEqual(bscript.witnessScriptHash.output.decode(scriptHash), witnessScriptPubKey) + }) }) fixtures.invalid.witnessScriptHash.outputs.forEach(function (f) {