diff --git a/src/scripts.js b/src/scripts.js index 661285a..88e3e61 100644 --- a/src/scripts.js +++ b/src/scripts.js @@ -238,9 +238,13 @@ function multisigInput(signatures, scriptPubKey) { if (scriptPubKey) { assert(isMultisigOutput.call(scriptPubKey)) - var m = scriptPubKey.chunks[0] - var k = m - (opcodes.OP_1 - 1) - assert(k <= signatures.length, 'Not enough signatures provided') + var mOp = scriptPubKey.chunks[0] + var nOp = scriptPubKey.chunks[scriptPubKey.chunks.length - 2] + var m = mOp - (opcodes.OP_1 - 1) + var n = nOp - (opcodes.OP_1 - 1) + + assert(signatures.length >= m, 'Not enough signatures provided') + assert(signatures.length <= n, 'Too many signatures provided') } return Script.fromChunks([].concat(opcodes.OP_0, signatures)) diff --git a/test/fixtures/scripts.json b/test/fixtures/scripts.json index 666ea59..e264a4a 100644 --- a/test/fixtures/scripts.json +++ b/test/fixtures/scripts.json @@ -101,6 +101,19 @@ "304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801" ], "scriptPubKey": false + }, + { + "exception": "Too many signatures provided", + "pubKeys": [ + "02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1", + "0395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a" + ], + "signatures": [ + "304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801", + "3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501", + "3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501" + ], + "scriptPubKey": false } ] }