diff --git a/lib/Script.js b/lib/Script.js index 6f73243..f611f74 100644 --- a/lib/Script.js +++ b/lib/Script.js @@ -115,8 +115,8 @@ Script.prototype.isMultiSig = function() { this.chunks[this.chunks.length - 1] == Opcode.map.OP_CHECKMULTISIG); }; -Script.prototype.isPubkeyHashScript = function() { - // TODO: add more restrictions to chunks +Script.prototype.isPubkeyHashScriptSig = function() { + // TODO: add more restrictions to chunks? return (this.chunks.length == 2 && Buffer.isBuffer(this.chunks[0]) && Buffer.isBuffer(this.chunks[1])); @@ -149,7 +149,7 @@ Script.prototype.countSignatures = function() { ret = l - 2; } // p2pubkeyhash - else if (this.isPubkeyHashScript()) { + else if (this.isPubkeyHashScriptSig()) { ret = 1; } // p2pubkey @@ -176,7 +176,7 @@ Script.prototype.getSignatures = function() { } } // p2pubkeyhash - else if (this.isPubkeyHashScript()) { + else if (this.isPubkeyHashScriptSig()) { ret.push(this.chunks[0]); } // p2pubkey diff --git a/test/test.Script.js b/test/test.Script.js index c3fb878..01d4f14 100644 --- a/test/test.Script.js +++ b/test/test.Script.js @@ -191,5 +191,23 @@ describe('Script', function() { }); }); + describe('#isPubkeyHashScriptSig', function() { + var testPKHSS = function(raw, result) { + var s = new Script(new Buffer(raw, 'hex'); + s.isPubkeyHashScriptSig().should.equal(result); + }; + it('should identify pubkeyhash scriptsig', function() { + testPKHSS(pkhss, true); + }); + it('should not identify pubkey scriptsig', function() { + testPKHSS(pkss, false); + }); + it('should not identify p2sh scriptsig', function() { + testPKHSS(p2shss, false); + }); + it('should not identify multisig scriptsig', function() { + testPKHSS(msss, false); + }); + }); });