diff --git a/lib/Script.js b/lib/Script.js index c1ced7b..6f73243 100644 --- a/lib/Script.js +++ b/lib/Script.js @@ -115,6 +115,13 @@ Script.prototype.isMultiSig = function() { this.chunks[this.chunks.length - 1] == Opcode.map.OP_CHECKMULTISIG); }; +Script.prototype.isPubkeyHashScript = function() { + // TODO: add more restrictions to chunks + return (this.chunks.length == 2 && + Buffer.isBuffer(this.chunks[0]) && + Buffer.isBuffer(this.chunks[1])); +}; + Script.prototype.isP2shScriptSig = function() { if (!isSmallIntOp(this.chunks[0]) || this.chunks[0] !== 0) return false; @@ -133,20 +140,65 @@ Script.prototype.isMultiSigScriptSig = function() { Script.prototype.countSignatures = function() { var ret = 0; var l = this.chunks.length; - // Multisig? if (this.isMultiSigScriptSig()) { ret = l - 1; - } else if (this.isP2shScriptSig()) { + } + // p2sh + else if (this.isP2shScriptSig()) { ret = l - 2; } - // p2pubkey or p2pubkeyhash + // p2pubkeyhash + else if (this.isPubkeyHashScript()) { + ret = 1; + } + // p2pubkey else { - ret = buffertools.compare(this.getBuffer(), util.EMPTY_BUFFER) === 0 ? 0 : 1; + ret = 0; } return ret; }; + +Script.prototype.getSignatures = function() { + ret = []; + var l = this.chunks.length; + // Multisig? + if (this.isMultiSigScriptSig()) { + for(var i = 1; i