diff --git a/lib/bcoin/script.js b/lib/bcoin/script.js index cd47d62d..22ae7d6b 100644 --- a/lib/bcoin/script.js +++ b/lib/bcoin/script.js @@ -2493,43 +2493,6 @@ Script.prototype.isStandard = function isStandard() { return type !== 'unknown'; }; -/** - * Test whether the program is standard (i.e. would it fail verification - * with non-mandatory flags). - * @returns {Boolean} - */ - -Script.prototype.isStandardProgram = function isStandardProgram(witness, flags) { - var program = this.getWitnessProgram(); - var i; - - assert(program); - assert((flags & constants.flags.VERIFY_WITNESS) !== 0); - - if (program.version === 0) { - if (program.data.length === 32) { - if (witness.items.length === 0) - return false; - } else if (program.data.length === 20) { - if (witness.items.length !== 2) - return false; - } else { - return false; - } - } else { - if (flags & constants.flags.VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM) - return false; - return true; - } - - for (i = 0; i < witness.items.length; i++) { - if (witness.items[i].length > constants.script.MAX_PUSH) - return false; - } - - return true; -}; - /** * Calculate size of script excluding the varint size bytes. * @returns {Number} @@ -2906,7 +2869,7 @@ Script.createOutputScript = function createOutputScript(options) { */ Script.prototype.isPubkeyInput = function isPubkeyInput() { - if (this.raw.length < 14) + if (this.raw.length < 10) return false; if (this.raw.length > 78) return false; @@ -2922,7 +2885,7 @@ Script.prototype.isPubkeyInput = function isPubkeyInput() { */ Script.prototype.isPubkeyhashInput = function isPubkeyhashInput() { - if (this.raw.length < 52) + if (this.raw.length < 44) return false; if (this.raw.length > 148) return false; @@ -2942,7 +2905,7 @@ Script.prototype.isPubkeyhashInput = function isPubkeyhashInput() { Script.prototype.isMultisigInput = function isMultisigInput() { var i; - if (this.raw.length < 28) + if (this.raw.length < 20) return false; if (this.raw[0] !== opcodes.OP_0) @@ -4480,18 +4443,6 @@ Opcode.fromPush = function fromPush(data) { */ Opcode.fromNumber = function fromNumber(num) { - if (bn.isBN(num)) { - if (!(num.cmpn(-1) >= 0 && num.cmpn(16) <= 0)) - return Opcode.fromData(Script.array(num)); - num = num.toNumber(); - } - - if (num >= 1 && num <= 16) - return Opcode.fromOp(num + 0x50); - - if (num === -1) - return Opcode.fromOp(opcodes.OP_1NEGATE); - return Opcode.fromData(Script.array(num)); }; @@ -4504,6 +4455,7 @@ Opcode.fromNumber = function fromNumber(num) { Opcode.fromString = function fromString(data, enc) { if (typeof data === 'string') data = new Buffer(data, enc); + return Opcode.fromPush(data); }; @@ -4516,12 +4468,16 @@ Opcode.fromString = function fromString(data, enc) { Opcode.from = function from(data) { if (data instanceof Opcode) return data; + if (typeof data === 'number') return Opcode.fromOp(data); + if (bn.isBN(data)) return Opcode.fromNumber(data); + if (typeof data === 'string') return Opcode.fromString(data, 'utf8'); + return Opcode.fromPush(data); };