From 49c6ebe3a0a0b0407c2cb8105e00d36bd695fddc Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Tue, 27 Sep 2016 15:10:38 +1000 Subject: [PATCH 1/3] TransactionBuilder: reword error for correctness --- src/transaction_builder.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/transaction_builder.js b/src/transaction_builder.js index 9a3c566..37f7b6f 100644 --- a/src/transaction_builder.js +++ b/src/transaction_builder.js @@ -249,12 +249,12 @@ TransactionBuilder.prototype.addInput = function (txHash, vout, sequence, prevOu throw new Error('No, this would invalidate signatures') } - var prevOut = txHash.toString('hex') + ':' + vout - if (this.prevTxMap[prevOut]) throw new Error('Transaction is already an input') + var prevTxOut = txHash.toString('hex') + ':' + vout + if (this.prevTxMap[prevTxOut]) throw new Error('Duplicate TxOut: ' + prevTxOut) var vin = this.tx.addInput(txHash, vout, sequence) this.inputs[vin] = input - this.prevTxMap[prevOut] = vin + this.prevTxMap[prevTxOut] = vin return vin } From fbcc23fa143ba2b00e131bced2fde206051e17dc Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Tue, 27 Sep 2016 15:41:46 +1000 Subject: [PATCH 2/3] TransactionBuilder: avoid unnecessary cache object --- src/transaction_builder.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/transaction_builder.js b/src/transaction_builder.js index 37f7b6f..c635754 100644 --- a/src/transaction_builder.js +++ b/src/transaction_builder.js @@ -16,7 +16,7 @@ var Transaction = require('./transaction') function fixMSSignatures (transaction, vin, pubKeys, signatures, prevOutScript, hashType, skipPubKey) { // maintain a local copy of unmatched signatures var unmatched = signatures.slice() - var cache = {} + var signatureHash return pubKeys.map(function (pubKey) { // skip optionally provided pubKey @@ -30,7 +30,9 @@ function fixMSSignatures (transaction, vin, pubKeys, signatures, prevOutScript, // skip if undefined || OP_0 if (!signature) return false - var signatureHash = cache[hashType] = cache[hashType] || transaction.hashForSignature(vin, prevOutScript, hashType) + if (!signatureHash) { + signatureHash = transaction.hashForSignature(vin, prevOutScript, hashType) + } if (!keyPair2.verify(signatureHash, signature)) return false // remove matched signature from unmatched From 302b4f079652525c80287cc3fb28da3379fc7eb1 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Tue, 27 Sep 2016 16:31:09 +1000 Subject: [PATCH 3/3] TransactionBuilder: signatureScript is only defined once --- src/transaction_builder.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/transaction_builder.js b/src/transaction_builder.js index c635754..08ac655 100644 --- a/src/transaction_builder.js +++ b/src/transaction_builder.js @@ -424,7 +424,6 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash input.signatures.length === input.pubKeys.length var kpPubKey = keyPair.getPublicKeyBuffer() - var signatureScript // are we ready to sign? if (canSign) { @@ -482,7 +481,7 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash } // ready to sign? - signatureScript = signatureScript || input.redeemScript || input.prevOutScript + var signatureScript = input.redeemScript || input.prevOutScript var signatureHash = this.tx.hashForSignature(index, signatureScript, hashType) // enforce in order signing of public keys