Skip to content

Commit

Permalink
txbuilder: refactor for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Mar 13, 2015
1 parent 6800518 commit 4660b84
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/transaction_builder.js
Expand Up @@ -371,22 +371,20 @@ TransactionBuilder.prototype.sign = function (index, privKey, redeemScript, hash
var signatureScript = input.redeemScript || input.prevOutScript
var signatureHash = this.tx.hashForSignature(index, signatureScript, hashType)

// enforce signature order matches public keys
if (input.scriptType === 'multisig' && input.redeemScript && input.signatures.length !== input.pubKeys.length) {
// store signatures locally
var _signatures = input.signatures.slice()

// loop over pubKeys to set their respective signature or set it to OP_0
input.signatures = input.pubKeys.map(function (pubKey) {
var signature = null
_signatures.forEach(function (_signature, _sigIdx) {
// check if the signature is not null / false / OP_0 and verify if it belongs to the pubKey
if (!signature && _signature && pubKey.verify(signatureHash, _signature)) {
// use .splice to remove the signature from the list, so we won't verify it again
signature = _signatures.splice(_sigIdx, 1)[0]
}
var match

// check for any matching signatures
input.signatures.some(function (signature) {
if (!pubKey.verify(signatureHash, signature)) return false
match = signature

return true
})

return signature || ops.OP_0
return match || undefined
})
}

Expand Down

0 comments on commit 4660b84

Please sign in to comment.