From 343289229eff85223f030c0f5e63c98854b6da22 Mon Sep 17 00:00:00 2001 From: John Russell Date: Wed, 28 May 2014 01:28:14 -0700 Subject: [PATCH] ensures that pubKey length is greater than m ensure that pubKey length is greater than m use Array.isArray over instanceof error message --- src/script.js | 2 ++ test/script.js | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/script.js b/src/script.js index 8a28f10..188b0c3 100644 --- a/src/script.js +++ b/src/script.js @@ -304,6 +304,8 @@ Script.createP2SHScriptPubKey = function(hash) { // m [pubKeys ...] n OP_CHECKMULTISIG Script.createMultisigScriptPubKey = function(m, pubKeys) { + assert(Array.isArray(pubKeys), 'Expected Array, got: ' + pubKeys) + assert(pubKeys.length >= m, 'Not enough pubKeys provided') var script = new Script() var n = pubKeys.length diff --git a/test/script.js b/test/script.js index 41efcbd..c22361c 100644 --- a/test/script.js +++ b/test/script.js @@ -120,6 +120,10 @@ describe('Script', function() { assert.equal(multisigAddress.toString(), '32vYjxBb7pHJJyXgNk8UoK3BdRDxBzny2v') }) + + it('should throw on not enough pubKeys provided', function() { + assert.throws(function() {Script.createMultisigScriptPubKey(4, pubKeys)}, /Not enough pubKeys provided/) + }) }) describe('2-of-2 Multisig scriptSig', function() {