diff --git a/lib/script.js b/lib/script.js index 65fcb55..008c487 100644 --- a/lib/script.js +++ b/lib/script.js @@ -196,21 +196,27 @@ Script.prototype.isPublicKeyHashIn = function() { this.chunks[0].buf.length >= 0x47 && this.chunks[0].buf.length <= 0x49 && this.chunks[1].buf && + PublicKey.isValid(this.chunks[1].buf)); + /* ( // compressed public key - (this.chunks[1].buf[0] === 0x03 && this.chunks[1].buf.length === 0x21) || + ( + (this.chunks[1].buf[0] === 0x02 || this.chunks[1].buf[0] === 0x03) && + this.chunks[1].buf.length === 0x21) || // uncompressed public key (this.chunks[1].buf[0] === 0x04 && this.chunks[1].buf.length === 0x41)) ); + */ }; /** * @returns true if this is a public key output script */ Script.prototype.isPublicKeyOut = function() { + console.log(this.toString()); return this.chunks.length === 2 && Buffer.isBuffer(this.chunks[0].buf) && - this.chunks[0].buf.length === 0x41 && + PublicKey.isValid(this.chunks[0].buf) && this.chunks[1] === Opcode('OP_CHECKSIG').toNumber(); }; @@ -404,13 +410,15 @@ Script.prototype._addOpcode = function(opcode, prepend) { Script.prototype._addBuffer = function(buf, prepend) { var opcodenum; var len = buf.length; - if (buf.length > 0 && buf.length < Opcode.map.OP_PUSHDATA1) { - opcodenum = buf.length; - } else if (buf.length < Math.pow(2, 8)) { + if (len === 0) { + return; + } else if (len > 0 && len < Opcode.map.OP_PUSHDATA1) { + opcodenum = len; + } else if (len < Math.pow(2, 8)) { opcodenum = Opcode.map.OP_PUSHDATA1; - } else if (buf.length < Math.pow(2, 16)) { + } else if (len < Math.pow(2, 16)) { opcodenum = Opcode.map.OP_PUSHDATA2; - } else if (buf.length < Math.pow(2, 32)) { + } else if (len < Math.pow(2, 32)) { opcodenum = Opcode.map.OP_PUSHDATA4; } else { throw new Error('You can\'t push that much data'); @@ -433,7 +441,7 @@ Script.prototype._addBuffer = function(buf, prepend) { Script.buildMultisigOut = function(pubkeys, m) { var s = new Script(); s.add(Opcode.smallInt(m)); - for (var i = 0; i