From c7b9091da0c0d6bafc909c4d6f45e662e87cc61d Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 30 Jun 2016 08:11:43 -0700 Subject: [PATCH] drop unoptimized sighashing. --- lib/bcoin/tx.js | 103 ------------------------------------------------ 1 file changed, 103 deletions(-) diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index 000104cb..6327feb3 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -480,109 +480,6 @@ TX.prototype.signatureHash = function signatureHash(index, prev, type, version) * @returns {Buffer} */ -TX.prototype.signatureHashCopy = function signatureHashV0(index, prev, type) { - var p = new BufferWriter(); - var empty = new Script(); - var i, copy, input, output; - - if (typeof index !== 'number') - index = this.inputs.indexOf(index); - - if (typeof type === 'string') - type = constants.hashType[type.toUpperCase()]; - - assert(index >= 0 && index < this.inputs.length); - assert(prev instanceof Script); - - // Clone the transaction. - copy = new TX(); - - copy.version = this.version; - - for (i = 0; i < this.inputs.length; i++) { - input = new bcoin.input(); - input.prevout = this.inputs[i].prevout; - input.script = this.inputs[i].script; - input.sequence = this.inputs[i].sequence; - copy.inputs.push(input); - } - - for (i = 0; i < this.outputs.length; i++) { - output = new bcoin.output(); - output.value = this.outputs[i].value; - output.script = this.outputs[i].script; - copy.outputs.push(output); - } - - copy.locktime = this.locktime; - - // Remove all signatures. - for (i = 0; i < copy.inputs.length; i++) - copy.inputs[i].script = empty; - - // Remove all code separators. - prev = prev.removeSeparators(); - - // Set our input to previous output's script - copy.inputs[index].script = prev; - - if ((type & 0x1f) === constants.hashType.NONE) { - // Drop all outputs. We don't want to sign them. - copy.outputs.length = 0; - - // Allow input sequence updates for other inputs. - for (i = 0; i < copy.inputs.length; i++) { - if (i !== index) - copy.inputs[i].sequence = 0; - } - } else if ((type & 0x1f) === constants.hashType.SINGLE) { - // Bitcoind used to return 1 as an error code: - // it ended up being treated like a hash. - if (index >= copy.outputs.length) - return utils.copy(constants.ONE_HASH); - - // Drop all the outputs after the input index. - copy.outputs.length = index + 1; - - // Null outputs that are not the at current input index. - for (i = 0; i < copy.outputs.length; i++) { - if (i !== index) { - copy.outputs[i].script = empty; - copy.outputs[i].value = -1; - } - } - - // Allow input sequence updates for other inputs. - for (i = 0; i < copy.inputs.length; i++) { - if (i !== index) - copy.inputs[i].sequence = 0; - } - } - - // Only sign our input. Allows anyone to add inputs. - if (type & constants.hashType.ANYONECANPAY) { - copy.inputs[0] = copy.inputs[index]; - copy.inputs.length = 1; - } - - // Render the copy and append the hashtype. - copy.toRaw(p); - p.writeU32(type); - - return utils.hash256(p.render()); -}; - -/** - * Legacy sighashing -- O(n^2). - * Note: Optimized version. No - * transaction copy necessary. - * @private - * @param {Number} index - * @param {Script} prev - * @param {SighashType} type - * @returns {Buffer} - */ - TX.prototype.signatureHashV0 = function signatureHashV0(index, prev, type) { var i, input, output; var p = new BufferWriter();