TransactionBuilder: localize fixMultisigOrder assumptions
This commit is contained in:
parent
0e2480523a
commit
a58c959099
1 changed files with 9 additions and 14 deletions
|
@ -218,14 +218,16 @@ function prepareInput (input, kpPubKey, redeemScript, hashType) {
|
||||||
|
|
||||||
function fixMultisigOrder (input, transaction, vin) {
|
function fixMultisigOrder (input, transaction, vin) {
|
||||||
var hashScriptType = input.redeemScriptType || input.prevOutType
|
var hashScriptType = input.redeemScriptType || input.prevOutType
|
||||||
if (hashScriptType !== 'multisig') throw new TypeError('Expected multisig input')
|
if (hashScriptType !== 'multisig') return
|
||||||
|
|
||||||
var hashType = input.hashType || Transaction.SIGHASH_ALL
|
|
||||||
var hashScript = input.redeemScript || input.prevOutScript
|
var hashScript = input.redeemScript || input.prevOutScript
|
||||||
|
if (!hashScript) return
|
||||||
|
if (!input.pubKeys) return
|
||||||
|
if (input.pubKeys.length === input.signatures.length) return
|
||||||
|
|
||||||
// maintain a local copy of unmatched signatures
|
|
||||||
var unmatched = input.signatures.concat()
|
var unmatched = input.signatures.concat()
|
||||||
var signatureHash = transaction.hashForSignature(vin, hashScript, hashType)
|
var hashType = input.hashType || Transaction.SIGHASH_ALL
|
||||||
|
var hash = transaction.hashForSignature(vin, hashScript, hashType)
|
||||||
|
|
||||||
input.signatures = input.pubKeys.map(function (pubKey, y) {
|
input.signatures = input.pubKeys.map(function (pubKey, y) {
|
||||||
var keyPair = ECPair.fromPublicKeyBuffer(pubKey)
|
var keyPair = ECPair.fromPublicKeyBuffer(pubKey)
|
||||||
|
@ -237,7 +239,7 @@ function fixMultisigOrder (input, transaction, vin) {
|
||||||
if (!signature) return false
|
if (!signature) return false
|
||||||
|
|
||||||
// skip if signature does not match pubKey
|
// skip if signature does not match pubKey
|
||||||
if (!keyPair.verify(signatureHash, signature)) return false
|
if (!keyPair.verify(hash, signature)) return false
|
||||||
|
|
||||||
// remove matched signature from unmatched
|
// remove matched signature from unmatched
|
||||||
unmatched[i] = undefined
|
unmatched[i] = undefined
|
||||||
|
@ -246,7 +248,7 @@ function fixMultisigOrder (input, transaction, vin) {
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
return match || undefined
|
return match
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,14 +301,7 @@ TransactionBuilder.fromTransaction = function (transaction, network) {
|
||||||
|
|
||||||
// fix some things not possible through the public API
|
// fix some things not possible through the public API
|
||||||
txb.inputs.forEach(function (input, i) {
|
txb.inputs.forEach(function (input, i) {
|
||||||
// attempt to fix any multisig inputs if they exist
|
|
||||||
if ((input.redeemScriptType || input.prevOutType) === 'multisig') {
|
|
||||||
// pubKeys will only exist for 'multisig' if a redeemScript was found
|
|
||||||
if (!input.pubKeys || !input.signatures) return
|
|
||||||
if (input.pubKeys.length === input.signatures.length) return
|
|
||||||
|
|
||||||
fixMultisigOrder(input, transaction, i)
|
fixMultisigOrder(input, transaction, i)
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return txb
|
return txb
|
||||||
|
|
Loading…
Reference in a new issue