From 73bf8a42ea3e2b070e03baba4237305f05f4c002 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Thu, 5 Feb 2015 14:48:29 +1100 Subject: [PATCH] TxBuilder: hashtype only relevant to things we can sign --- src/transaction_builder.js | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/transaction_builder.js b/src/transaction_builder.js index e1ede83..40a5546 100644 --- a/src/transaction_builder.js +++ b/src/transaction_builder.js @@ -268,26 +268,23 @@ TransactionBuilder.prototype.sign = function(index, privKey, redeemScript, hashT hashType = hashType || Transaction.SIGHASH_ALL var input = this.inputs[index] + var canSign = input.hashType && + input.prevOutScript && + input.prevOutType && + input.pubKeys && + input.scriptType && + input.signatures - if (input.hashType !== undefined) { - assert.equal(input.hashType, hashType, 'Inconsistent hashType') - } - - var initialized = input.hashType && - input.prevOutScript && - input.prevOutType && - input.pubKeys && - input.scriptType && - input.signatures - - // are we already initialized? - if (initialized) { - // redeemScript only needed to initialize, but if provided again, enforce consistency + // are we almost ready to sign? + if (canSign) { + // if redeemScript was provided, enforce consistency if (redeemScript) { assert.deepEqual(input.redeemScript, redeemScript, 'Inconsistent redeemScript') } - // initialize it + assert.equal(input.hashType, hashType, 'Inconsistent hashType') + + // no? prepare } else { if (redeemScript) { // if we have a prevOutScript, enforce scriptHash equality to the redeemScript