diff --git a/lib/bcoin/script.js b/lib/bcoin/script.js index 8d3ed316..dd5225dc 100644 --- a/lib/bcoin/script.js +++ b/lib/bcoin/script.js @@ -290,3 +290,22 @@ script.isPubkeyhashInput = function isPubkeyhashInput(s) { return 9 <= s[0].length && s[0].length <= 73 && 33 <= s[1].length && s[1].length <= 65; }; + +script.isScripthash = function isScripthash(s) { + if (s.length !== 3) + return false; + + return s[0] === 'hash160' && + Array.isArray(s[1]) && + s[1].length === 20 && + s[2] === 'eq'; +}; + +script.isNullData = function isNullData(s) { + if (s.length !== 2) + return false; + + return s[0] === 'ret' && + Array.isArray(s[1]) && + s[1].length <= 40; +}; diff --git a/test/script-test.js b/test/script-test.js index 5ec732ce..3b5e24ea 100644 --- a/test/script-test.js +++ b/test/script-test.js @@ -30,4 +30,18 @@ describe('Script', function() { var decoded = bcoin.script.decode(encoded); assert.deepEqual(decoded, script); }); + + it('should recognize a P2SH output', function () { + var hex = 'a91419a7d869032368fd1f1e26e5e73a4ad0e474960e87' + var encoded = bcoin.utils.toArray(hex, 'hex') + var decoded = bcoin.script.decode(encoded); + assert(bcoin.script.isScripthash(decoded)) + }) + + it('should recognize a Null Data output', function () { + var hex = '6a28590c080112220a1b353930632e6f7267282a5f5e294f7665726c6179404f7261636c65103b1a010c' + var encoded = bcoin.utils.toArray(hex, 'hex') + var decoded = bcoin.script.decode(encoded); + assert(bcoin.script.isNullData(decoded)) + }) });