Browse Source

txbuilder: add missing signature P2MS fixture

v4
Daniel Cousens 6 years ago
parent
commit
1119a449a5
  1. 28
      src/transaction_builder.js
  2. 23
      test/fixtures/transaction_builder.json

28
src/transaction_builder.js

@ -57,7 +57,7 @@ function expandInput (scriptSig, witnessStack, type, scriptPubKey) {
} }
case SCRIPT_TYPES.P2MS: { case SCRIPT_TYPES.P2MS: {
const { pubkeys, signatures } = payments.p2ms({ const { m, pubkeys, signatures } = payments.p2ms({
input: scriptSig, input: scriptSig,
output: scriptPubKey output: scriptPubKey
}, { allowIncomplete: true }) }, { allowIncomplete: true })
@ -65,7 +65,8 @@ function expandInput (scriptSig, witnessStack, type, scriptPubKey) {
return { return {
prevOutType: SCRIPT_TYPES.P2MS, prevOutType: SCRIPT_TYPES.P2MS,
pubkeys: pubkeys, pubkeys: pubkeys,
signatures: signatures signatures: signatures,
maxSignatures: m
} }
} }
} }
@ -207,7 +208,8 @@ function expandOutput (script, ourPubKey) {
return { return {
type, type,
pubkeys: p2ms.pubkeys, pubkeys: p2ms.pubkeys,
signatures: p2ms.pubkeys.map(() => undefined) signatures: p2ms.pubkeys.map(() => undefined),
maxSignatures: p2ms.m
} }
} }
} }
@ -250,7 +252,8 @@ function prepareInput (input, ourPubKey, redeemScript, witnessValue, witnessScri
signType: expanded.type, signType: expanded.type,
pubkeys: expanded.pubkeys, pubkeys: expanded.pubkeys,
signatures: expanded.signatures signatures: expanded.signatures,
maxSignatures: expanded.maxSignatures
} }
} }
@ -288,7 +291,8 @@ function prepareInput (input, ourPubKey, redeemScript, witnessValue, witnessScri
signType: expanded.type, signType: expanded.type,
pubkeys: expanded.pubkeys, pubkeys: expanded.pubkeys,
signatures: expanded.signatures signatures: expanded.signatures,
maxSignatures: expanded.maxSignatures
} }
} }
@ -321,7 +325,8 @@ function prepareInput (input, ourPubKey, redeemScript, witnessValue, witnessScri
signType: expanded.type, signType: expanded.type,
pubkeys: expanded.pubkeys, pubkeys: expanded.pubkeys,
signatures: expanded.signatures signatures: expanded.signatures,
maxSignatures: expanded.maxSignatures
} }
} }
@ -351,7 +356,8 @@ function prepareInput (input, ourPubKey, redeemScript, witnessValue, witnessScri
signType: expanded.type, signType: expanded.type,
pubkeys: expanded.pubkeys, pubkeys: expanded.pubkeys,
signatures: expanded.signatures signatures: expanded.signatures,
maxSignatures: expanded.maxSignatures
} }
} }
@ -365,7 +371,8 @@ function prepareInput (input, ourPubKey, redeemScript, witnessValue, witnessScri
signType: SCRIPT_TYPES.P2PKH, signType: SCRIPT_TYPES.P2PKH,
pubkeys: [ourPubKey], pubkeys: [ourPubKey],
signatures: [undefined] signatures: [undefined],
maxSignatures: 1
} }
} }
@ -393,13 +400,14 @@ function build (type, input, allowIncomplete) {
return payments.p2pk({ signature: signatures[0] }) return payments.p2pk({ signature: signatures[0] })
} }
case SCRIPT_TYPES.P2MS: { case SCRIPT_TYPES.P2MS: {
const m = input.maxSignatures
if (allowIncomplete) { if (allowIncomplete) {
signatures = signatures.map(x => x || ops.OP_0) signatures = signatures.map(x => x || ops.OP_0)
} else { } else {
signatures = signatures.filter(x => x) signatures = signatures.filter(x => x)
} }
const validate = !allowIncomplete || (m === signatures.length)
return payments.p2ms({ signatures }, { allowIncomplete }) return payments.p2ms({ m, pubkeys, signatures }, { allowIncomplete, validate })
} }
case SCRIPT_TYPES.P2SH: { case SCRIPT_TYPES.P2SH: {
const redeem = build(input.redeemScriptType, input, allowIncomplete) const redeem = build(input.redeemScriptType, input, allowIncomplete)

23
test/fixtures/transaction_builder.json

@ -1917,6 +1917,29 @@
} }
] ]
}, },
{
"description": "Incomplete Transaction P2SH(P2MS 2/3), missing signature",
"exception": "Not enough signatures provided",
"network": "testnet",
"inputs": [
{
"txId": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"vout": 0,
"signs": [
{
"keyPair": "91avARGdfge8E4tZfYLoxeJ5sGBdNJQH4kvjJoQFacbgwmaKkrx",
"redeemScript": "OP_2 0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 04c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a 04f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672 OP_3 OP_CHECKMULTISIG"
}
]
}
],
"outputs": [
{
"script": "OP_DUP OP_HASH160 aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5 OP_EQUALVERIFY OP_CHECKSIG",
"value": 1000
}
]
},
{ {
"description": "Duplicate transaction outs", "description": "Duplicate transaction outs",
"exception": "Duplicate TxOut: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff:0", "exception": "Duplicate TxOut: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff:0",

Loading…
Cancel
Save