From 4e0c23092b7215ab6bb78f8e3522188d73b3e20a Mon Sep 17 00:00:00 2001 From: Vasu-08 <20bcs241@iiitdmj.ac.in> Date: Fri, 11 Aug 2023 02:49:45 +0530 Subject: [PATCH 1/2] feat: add descriptor support in createmultisig rpc --- lib/descriptor/abstractdescriptor.js | 4 +- lib/descriptor/common.js | 11 +++++ lib/node/rpc.js | 66 +++++++++++++++++++++++----- 3 files changed, 67 insertions(+), 14 deletions(-) diff --git a/lib/descriptor/abstractdescriptor.js b/lib/descriptor/abstractdescriptor.js index cbc3fd26c..9269943de 100644 --- a/lib/descriptor/abstractdescriptor.js +++ b/lib/descriptor/abstractdescriptor.js @@ -241,7 +241,7 @@ class AbstractDescriptor { * @returns {Script[]} */ - generateScripts(pos) { + generateScripts(pos = 0) { const pubkeys = []; const subscripts = []; @@ -274,7 +274,7 @@ class AbstractDescriptor { * @returns {Address[]} */ - getAddresses(pos) { + getAddresses(pos = 0) { const scripts = this.generateScripts(pos); const addresses = []; diff --git a/lib/descriptor/common.js b/lib/descriptor/common.js index 5db8d7d66..9332dc306 100644 --- a/lib/descriptor/common.js +++ b/lib/descriptor/common.js @@ -58,6 +58,17 @@ common.scriptContext = { P2WSH: 'P2WSH' }; +/** + * output types for descriptor + * @const {Object} + */ + +common.outputTypes = { + LEGACY: 'legacy', + BECH32: 'bech32', + P2SH_SEGWIT: 'p2sh-segwit' +}; + /** * Allowed characters in descriptor expressions for checksum to work. * @see https://github.com/bitcoin/bips/blob/master/bip-0380.mediawiki#character-set diff --git a/lib/node/rpc.js b/lib/node/rpc.js index 409096e76..95228a463 100644 --- a/lib/node/rpc.js +++ b/lib/node/rpc.js @@ -35,10 +35,15 @@ const TX = require('../primitives/tx'); const consensus = require('../protocol/consensus'); const pkg = require('../pkg'); const {filters} = require('../blockstore/common'); -const {createChecksum} = require('../descriptor/common'); +const MultisigDescriptor = require('../descriptor/type/multisig'); +const SHDescriptor = require('../descriptor/type/sh'); +const WSHDescriptor = require('../descriptor/type/wsh'); const {parse} = require('../descriptor/parser'); const RPCBase = bweb.RPC; const RPCError = bweb.RPCError; +const { + createChecksum, outputTypes, scriptContext +} = require('../descriptor/common'); /* * Constants @@ -2050,20 +2055,32 @@ class RPC extends RPCBase { */ async createMultisig(args, help) { - if (help || args.length < 2 || args.length > 2) { + if (help || args.length < 2 || args.length > 3) { throw new RPCError(errs.MISC_ERROR, - 'createmultisig nrequired ["key",...]'); + 'createmultisig nrequired ["key",...] (address_type)'); } const valid = new Validator(args); const keys = valid.array(1, []); + let outputType = valid.str(2); + + if (outputType === null) { + outputType = outputTypes.LEGACY; + } + + assert( + Object.values(outputTypes).includes(outputType), + `Unknown address type '${outputType}'.` + ); + const m = valid.u32(0, 0); const n = keys.length; - if (m < 1 || n < m || n > 16) + if (m < 1 || n < m || n > 20) throw new RPCError(errs.INVALID_PARAMETER, 'Invalid m and n values.'); const items = new Validator(keys); + let keyString = ''; for (let i = 0; i < keys.length; i++) { const key = items.buf(i); @@ -2074,21 +2091,46 @@ class RPC extends RPCBase { if (!secp256k1.publicKeyVerify(key)) throw new RPCError(errs.INVALID_ADDRESS_OR_KEY, 'Invalid key.'); + keyString += items.str(i) + ','; keys[i] = key; } - const script = Script.fromMultisig(m, n, keys, true, false); + keyString = keyString.slice(0, -1); - if (script.getSize() > consensus.MAX_SCRIPT_PUSH) { - throw new RPCError(errs.VERIFY_ERROR, - 'Redeem script exceeds size limit.'); - } + const isWitness = outputType !== outputTypes.LEGACY; + const script = Script.fromMultisig(m, n, keys, false, isWitness); - const addr = script.getAddress(); + const {P2SH, P2WSH} = scriptContext; + const context = outputType === outputTypes.LEGACY ? P2SH : P2WSH; + + const subdesc = MultisigDescriptor.fromString( + `multi(${m},${keyString})`, this.network, context + ); + + let descriptor; + + const options = { + subdescriptors: [subdesc], + network: this.network + }; + + switch (outputType) { + case outputTypes.LEGACY: + descriptor = SHDescriptor.fromOptions(options); + break; + case outputTypes.BECH32: + descriptor = WSHDescriptor.fromOptions(options); + break; + case outputTypes.P2SH_SEGWIT: { + options.subdescriptors = [WSHDescriptor.fromOptions(options)]; + descriptor = SHDescriptor.fromOptions(options); + } + } return { - address: addr.toString(this.network), - redeemScript: script.toJSON() + address: descriptor.getAddresses()[0], + redeemScript: script.toJSON(), + descriptor: descriptor.toString() }; } From 77be48be77c98c3a867d496c67189790e27fb8da Mon Sep 17 00:00:00 2001 From: Vasu-08 <20bcs241@iiitdmj.ac.in> Date: Wed, 6 Sep 2023 00:38:58 +0530 Subject: [PATCH 2/2] test: cover createmultisig rpc --- test/node-rpc-test.js | 161 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/test/node-rpc-test.js b/test/node-rpc-test.js index f9086463f..ffc636a9d 100644 --- a/test/node-rpc-test.js +++ b/test/node-rpc-test.js @@ -234,6 +234,167 @@ describe('RPC', function() { } }); + it('should rpc createmultisig', async () => { + const data = [ + { + 'm': 2, + 'keys': [ + '02f293c4d026a536a082453f8327f305ae0a0c59350b396205e15fbec2af67390b', + '03d7b6a7e972f6e1a532f9f49a7cc35055a0ffd7cec5f81728f6a3fdf4dad93672', + '021f360d51b8eb43422fe942c837ad16e36bab87c5f7567609de9a38e205fb51ed', + '03a778eaee9cc18a4e5e02a78f403082d4e6f3a9c0d9edaea20b9ad86089de7fc9', + '02a3c95e41e8272c6842df8c9da492ef5e03bbc4ca17c22ce1f88570e716e187db', + '032e1d465bc5cdea674337934fb861d097dd7ab20289e4d41de14a6cafcd61d30a', + '0370fd35da88778a805ce9acc88c0020e3b14cacaa30f99d829207e1896d782ea1', + '03878a4b831af4fee069964448ccca999071633fcc751d296e8c5325167274febf', + '0248f8621596029568070dda40bc1e3ace78df320b5ebf0d6a431536e9af3ec894', + '03f757260835b7e439b244a9b10f5645966d7dcff9d2648c400a0d6827f4a64ac4', + '023b3972554e123985b6c3d8575e6fd3384f59a58ef91e0d39ba5905dad49e7372', + '02e32652928f21764e02822d39ffd1075c428e372a06fe7247023d5b60f1d01596', + '020e002818c48b1d1766f6196e09db90f51e155bbd49be0ad743d1fa6b7e8efcae', + '03725d482f0c77f4feb1ecbea28f036b30889f462222002e88aa8f8346dce94474', + '031fa2798d9f40bc2746f91f300460be9091e10f1b4baa37843cd41c965b0f9b41', + '0235b7b545398ce9692f319e6eefe114eae50f008f46d33baf19418e0f17e3bc65', + '02ff72a2b54370c0b1501228b6a210bc36a16535cc358bf7839c85a6ae2c41725c', + '0282ce44556f5a81c7a698dc8fdba12089740df420af93002e80a752020e5d939e', + '0279f5b244862e27f69284befb0299909139b899d2702b3e74b4317ed5b2947e03', + '0293d0b090906afdee07dabedf34798293246ce06ade2e3887302f289008f25f4d' + ], + 'address_type': 'p2sh-segwit', + 'result': { + 'address': '2NCFqiBT6cswU7rkm1ZTvxBuMDdwaFUWKJj', + 'redeemScript': '522102f293c4d026a536a082453f8327f305ae0a0c59350b396205e15fbec2af67390b2103d7b6a7e972f6e1a532f9f49a7cc35055a0ffd7cec5f81728f6a3fdf4dad9367221021f360d51b8eb43422fe942c837ad16e36bab87c5f7567609de9a38e205fb51ed2103a778eaee9cc18a4e5e02a78f403082d4e6f3a9c0d9edaea20b9ad86089de7fc92102a3c95e41e8272c6842df8c9da492ef5e03bbc4ca17c22ce1f88570e716e187db21032e1d465bc5cdea674337934fb861d097dd7ab20289e4d41de14a6cafcd61d30a210370fd35da88778a805ce9acc88c0020e3b14cacaa30f99d829207e1896d782ea12103878a4b831af4fee069964448ccca999071633fcc751d296e8c5325167274febf210248f8621596029568070dda40bc1e3ace78df320b5ebf0d6a431536e9af3ec8942103f757260835b7e439b244a9b10f5645966d7dcff9d2648c400a0d6827f4a64ac421023b3972554e123985b6c3d8575e6fd3384f59a58ef91e0d39ba5905dad49e73722102e32652928f21764e02822d39ffd1075c428e372a06fe7247023d5b60f1d0159621020e002818c48b1d1766f6196e09db90f51e155bbd49be0ad743d1fa6b7e8efcae2103725d482f0c77f4feb1ecbea28f036b30889f462222002e88aa8f8346dce9447421031fa2798d9f40bc2746f91f300460be9091e10f1b4baa37843cd41c965b0f9b41210235b7b545398ce9692f319e6eefe114eae50f008f46d33baf19418e0f17e3bc652102ff72a2b54370c0b1501228b6a210bc36a16535cc358bf7839c85a6ae2c41725c210282ce44556f5a81c7a698dc8fdba12089740df420af93002e80a752020e5d939e210279f5b244862e27f69284befb0299909139b899d2702b3e74b4317ed5b2947e03210293d0b090906afdee07dabedf34798293246ce06ade2e3887302f289008f25f4d0114ae', + 'descriptor': 'sh(wsh(multi(2,02f293c4d026a536a082453f8327f305ae0a0c59350b396205e15fbec2af67390b,03d7b6a7e972f6e1a532f9f49a7cc35055a0ffd7cec5f81728f6a3fdf4dad93672,021f360d51b8eb43422fe942c837ad16e36bab87c5f7567609de9a38e205fb51ed,03a778eaee9cc18a4e5e02a78f403082d4e6f3a9c0d9edaea20b9ad86089de7fc9,02a3c95e41e8272c6842df8c9da492ef5e03bbc4ca17c22ce1f88570e716e187db,032e1d465bc5cdea674337934fb861d097dd7ab20289e4d41de14a6cafcd61d30a,0370fd35da88778a805ce9acc88c0020e3b14cacaa30f99d829207e1896d782ea1,03878a4b831af4fee069964448ccca999071633fcc751d296e8c5325167274febf,0248f8621596029568070dda40bc1e3ace78df320b5ebf0d6a431536e9af3ec894,03f757260835b7e439b244a9b10f5645966d7dcff9d2648c400a0d6827f4a64ac4,023b3972554e123985b6c3d8575e6fd3384f59a58ef91e0d39ba5905dad49e7372,02e32652928f21764e02822d39ffd1075c428e372a06fe7247023d5b60f1d01596,020e002818c48b1d1766f6196e09db90f51e155bbd49be0ad743d1fa6b7e8efcae,03725d482f0c77f4feb1ecbea28f036b30889f462222002e88aa8f8346dce94474,031fa2798d9f40bc2746f91f300460be9091e10f1b4baa37843cd41c965b0f9b41,0235b7b545398ce9692f319e6eefe114eae50f008f46d33baf19418e0f17e3bc65,02ff72a2b54370c0b1501228b6a210bc36a16535cc358bf7839c85a6ae2c41725c,0282ce44556f5a81c7a698dc8fdba12089740df420af93002e80a752020e5d939e,0279f5b244862e27f69284befb0299909139b899d2702b3e74b4317ed5b2947e03,0293d0b090906afdee07dabedf34798293246ce06ade2e3887302f289008f25f4d)))#28tx9y39' + } + }, + { + 'm': 4, + 'keys': [ + '02f293c4d026a536a082453f8327f305ae0a0c59350b396205e15fbec2af67390b', + '03d7b6a7e972f6e1a532f9f49a7cc35055a0ffd7cec5f81728f6a3fdf4dad93672', + '021f360d51b8eb43422fe942c837ad16e36bab87c5f7567609de9a38e205fb51ed', + '03a778eaee9cc18a4e5e02a78f403082d4e6f3a9c0d9edaea20b9ad86089de7fc9', + '02a3c95e41e8272c6842df8c9da492ef5e03bbc4ca17c22ce1f88570e716e187db', + '032e1d465bc5cdea674337934fb861d097dd7ab20289e4d41de14a6cafcd61d30a', + '0370fd35da88778a805ce9acc88c0020e3b14cacaa30f99d829207e1896d782ea1', + '03878a4b831af4fee069964448ccca999071633fcc751d296e8c5325167274febf', + '0248f8621596029568070dda40bc1e3ace78df320b5ebf0d6a431536e9af3ec894', + '03f757260835b7e439b244a9b10f5645966d7dcff9d2648c400a0d6827f4a64ac4', + '023b3972554e123985b6c3d8575e6fd3384f59a58ef91e0d39ba5905dad49e7372', + '02e32652928f21764e02822d39ffd1075c428e372a06fe7247023d5b60f1d01596', + '020e002818c48b1d1766f6196e09db90f51e155bbd49be0ad743d1fa6b7e8efcae', + '03725d482f0c77f4feb1ecbea28f036b30889f462222002e88aa8f8346dce94474' + ], + 'address_type': 'p2sh-segwit', + 'result': { + 'address': '2N5YHZJYNqXqCwiX2FTQ9ZgwCoW4qksY2CE', + 'redeemScript': '542102f293c4d026a536a082453f8327f305ae0a0c59350b396205e15fbec2af67390b2103d7b6a7e972f6e1a532f9f49a7cc35055a0ffd7cec5f81728f6a3fdf4dad9367221021f360d51b8eb43422fe942c837ad16e36bab87c5f7567609de9a38e205fb51ed2103a778eaee9cc18a4e5e02a78f403082d4e6f3a9c0d9edaea20b9ad86089de7fc92102a3c95e41e8272c6842df8c9da492ef5e03bbc4ca17c22ce1f88570e716e187db21032e1d465bc5cdea674337934fb861d097dd7ab20289e4d41de14a6cafcd61d30a210370fd35da88778a805ce9acc88c0020e3b14cacaa30f99d829207e1896d782ea12103878a4b831af4fee069964448ccca999071633fcc751d296e8c5325167274febf210248f8621596029568070dda40bc1e3ace78df320b5ebf0d6a431536e9af3ec8942103f757260835b7e439b244a9b10f5645966d7dcff9d2648c400a0d6827f4a64ac421023b3972554e123985b6c3d8575e6fd3384f59a58ef91e0d39ba5905dad49e73722102e32652928f21764e02822d39ffd1075c428e372a06fe7247023d5b60f1d0159621020e002818c48b1d1766f6196e09db90f51e155bbd49be0ad743d1fa6b7e8efcae2103725d482f0c77f4feb1ecbea28f036b30889f462222002e88aa8f8346dce944745eae', + 'descriptor': 'sh(wsh(multi(4,02f293c4d026a536a082453f8327f305ae0a0c59350b396205e15fbec2af67390b,03d7b6a7e972f6e1a532f9f49a7cc35055a0ffd7cec5f81728f6a3fdf4dad93672,021f360d51b8eb43422fe942c837ad16e36bab87c5f7567609de9a38e205fb51ed,03a778eaee9cc18a4e5e02a78f403082d4e6f3a9c0d9edaea20b9ad86089de7fc9,02a3c95e41e8272c6842df8c9da492ef5e03bbc4ca17c22ce1f88570e716e187db,032e1d465bc5cdea674337934fb861d097dd7ab20289e4d41de14a6cafcd61d30a,0370fd35da88778a805ce9acc88c0020e3b14cacaa30f99d829207e1896d782ea1,03878a4b831af4fee069964448ccca999071633fcc751d296e8c5325167274febf,0248f8621596029568070dda40bc1e3ace78df320b5ebf0d6a431536e9af3ec894,03f757260835b7e439b244a9b10f5645966d7dcff9d2648c400a0d6827f4a64ac4,023b3972554e123985b6c3d8575e6fd3384f59a58ef91e0d39ba5905dad49e7372,02e32652928f21764e02822d39ffd1075c428e372a06fe7247023d5b60f1d01596,020e002818c48b1d1766f6196e09db90f51e155bbd49be0ad743d1fa6b7e8efcae,03725d482f0c77f4feb1ecbea28f036b30889f462222002e88aa8f8346dce94474)))#a880m646' + } + }, + { + 'm': 4, + 'keys': [ + '02f293c4d026a536a082453f8327f305ae0a0c59350b396205e15fbec2af67390b', + '03d7b6a7e972f6e1a532f9f49a7cc35055a0ffd7cec5f81728f6a3fdf4dad93672', + '021f360d51b8eb43422fe942c837ad16e36bab87c5f7567609de9a38e205fb51ed', + '03a778eaee9cc18a4e5e02a78f403082d4e6f3a9c0d9edaea20b9ad86089de7fc9', + '02a3c95e41e8272c6842df8c9da492ef5e03bbc4ca17c22ce1f88570e716e187db', + '032e1d465bc5cdea674337934fb861d097dd7ab20289e4d41de14a6cafcd61d30a', + '0370fd35da88778a805ce9acc88c0020e3b14cacaa30f99d829207e1896d782ea1', + '03878a4b831af4fee069964448ccca999071633fcc751d296e8c5325167274febf', + '0248f8621596029568070dda40bc1e3ace78df320b5ebf0d6a431536e9af3ec894', + '03f757260835b7e439b244a9b10f5645966d7dcff9d2648c400a0d6827f4a64ac4', + '023b3972554e123985b6c3d8575e6fd3384f59a58ef91e0d39ba5905dad49e7372', + '02e32652928f21764e02822d39ffd1075c428e372a06fe7247023d5b60f1d01596', + '020e002818c48b1d1766f6196e09db90f51e155bbd49be0ad743d1fa6b7e8efcae', + '03725d482f0c77f4feb1ecbea28f036b30889f462222002e88aa8f8346dce94474' + ], + 'address_type': 'bech32', + 'result': { + 'address': 'bcrt1qwn0zfduv4tu2jga3dl4a3r87dpk3da6ke5t2uhy306ynlrpg5eas47sw6n', + 'redeemScript': '542102f293c4d026a536a082453f8327f305ae0a0c59350b396205e15fbec2af67390b2103d7b6a7e972f6e1a532f9f49a7cc35055a0ffd7cec5f81728f6a3fdf4dad9367221021f360d51b8eb43422fe942c837ad16e36bab87c5f7567609de9a38e205fb51ed2103a778eaee9cc18a4e5e02a78f403082d4e6f3a9c0d9edaea20b9ad86089de7fc92102a3c95e41e8272c6842df8c9da492ef5e03bbc4ca17c22ce1f88570e716e187db21032e1d465bc5cdea674337934fb861d097dd7ab20289e4d41de14a6cafcd61d30a210370fd35da88778a805ce9acc88c0020e3b14cacaa30f99d829207e1896d782ea12103878a4b831af4fee069964448ccca999071633fcc751d296e8c5325167274febf210248f8621596029568070dda40bc1e3ace78df320b5ebf0d6a431536e9af3ec8942103f757260835b7e439b244a9b10f5645966d7dcff9d2648c400a0d6827f4a64ac421023b3972554e123985b6c3d8575e6fd3384f59a58ef91e0d39ba5905dad49e73722102e32652928f21764e02822d39ffd1075c428e372a06fe7247023d5b60f1d0159621020e002818c48b1d1766f6196e09db90f51e155bbd49be0ad743d1fa6b7e8efcae2103725d482f0c77f4feb1ecbea28f036b30889f462222002e88aa8f8346dce944745eae', + 'descriptor': 'wsh(multi(4,02f293c4d026a536a082453f8327f305ae0a0c59350b396205e15fbec2af67390b,03d7b6a7e972f6e1a532f9f49a7cc35055a0ffd7cec5f81728f6a3fdf4dad93672,021f360d51b8eb43422fe942c837ad16e36bab87c5f7567609de9a38e205fb51ed,03a778eaee9cc18a4e5e02a78f403082d4e6f3a9c0d9edaea20b9ad86089de7fc9,02a3c95e41e8272c6842df8c9da492ef5e03bbc4ca17c22ce1f88570e716e187db,032e1d465bc5cdea674337934fb861d097dd7ab20289e4d41de14a6cafcd61d30a,0370fd35da88778a805ce9acc88c0020e3b14cacaa30f99d829207e1896d782ea1,03878a4b831af4fee069964448ccca999071633fcc751d296e8c5325167274febf,0248f8621596029568070dda40bc1e3ace78df320b5ebf0d6a431536e9af3ec894,03f757260835b7e439b244a9b10f5645966d7dcff9d2648c400a0d6827f4a64ac4,023b3972554e123985b6c3d8575e6fd3384f59a58ef91e0d39ba5905dad49e7372,02e32652928f21764e02822d39ffd1075c428e372a06fe7247023d5b60f1d01596,020e002818c48b1d1766f6196e09db90f51e155bbd49be0ad743d1fa6b7e8efcae,03725d482f0c77f4feb1ecbea28f036b30889f462222002e88aa8f8346dce94474))#t7k5jeyy' + } + }, + { + 'm': 4, + 'keys': [ + '02f293c4d026a536a082453f8327f305ae0a0c59350b396205e15fbec2af67390b', + '03d7b6a7e972f6e1a532f9f49a7cc35055a0ffd7cec5f81728f6a3fdf4dad93672', + '021f360d51b8eb43422fe942c837ad16e36bab87c5f7567609de9a38e205fb51ed', + '03a778eaee9cc18a4e5e02a78f403082d4e6f3a9c0d9edaea20b9ad86089de7fc9', + '02a3c95e41e8272c6842df8c9da492ef5e03bbc4ca17c22ce1f88570e716e187db', + '032e1d465bc5cdea674337934fb861d097dd7ab20289e4d41de14a6cafcd61d30a', + '0370fd35da88778a805ce9acc88c0020e3b14cacaa30f99d829207e1896d782ea1', + '03878a4b831af4fee069964448ccca999071633fcc751d296e8c5325167274febf', + '0248f8621596029568070dda40bc1e3ace78df320b5ebf0d6a431536e9af3ec894', + '03f757260835b7e439b244a9b10f5645966d7dcff9d2648c400a0d6827f4a64ac4', + '023b3972554e123985b6c3d8575e6fd3384f59a58ef91e0d39ba5905dad49e7372', + '02e32652928f21764e02822d39ffd1075c428e372a06fe7247023d5b60f1d01596', + '020e002818c48b1d1766f6196e09db90f51e155bbd49be0ad743d1fa6b7e8efcae', + '03725d482f0c77f4feb1ecbea28f036b30889f462222002e88aa8f8346dce94474' + ], + 'address_type': 'legacy', + 'result': { + 'address': '2NDLRy5WPdnfPYyKYfBCfJXEce3QQhZD8ps', + 'redeemScript': '542102f293c4d026a536a082453f8327f305ae0a0c59350b396205e15fbec2af67390b2103d7b6a7e972f6e1a532f9f49a7cc35055a0ffd7cec5f81728f6a3fdf4dad9367221021f360d51b8eb43422fe942c837ad16e36bab87c5f7567609de9a38e205fb51ed2103a778eaee9cc18a4e5e02a78f403082d4e6f3a9c0d9edaea20b9ad86089de7fc92102a3c95e41e8272c6842df8c9da492ef5e03bbc4ca17c22ce1f88570e716e187db21032e1d465bc5cdea674337934fb861d097dd7ab20289e4d41de14a6cafcd61d30a210370fd35da88778a805ce9acc88c0020e3b14cacaa30f99d829207e1896d782ea12103878a4b831af4fee069964448ccca999071633fcc751d296e8c5325167274febf210248f8621596029568070dda40bc1e3ace78df320b5ebf0d6a431536e9af3ec8942103f757260835b7e439b244a9b10f5645966d7dcff9d2648c400a0d6827f4a64ac421023b3972554e123985b6c3d8575e6fd3384f59a58ef91e0d39ba5905dad49e73722102e32652928f21764e02822d39ffd1075c428e372a06fe7247023d5b60f1d0159621020e002818c48b1d1766f6196e09db90f51e155bbd49be0ad743d1fa6b7e8efcae2103725d482f0c77f4feb1ecbea28f036b30889f462222002e88aa8f8346dce944745eae', + 'descriptor': 'sh(multi(4,02f293c4d026a536a082453f8327f305ae0a0c59350b396205e15fbec2af67390b,03d7b6a7e972f6e1a532f9f49a7cc35055a0ffd7cec5f81728f6a3fdf4dad93672,021f360d51b8eb43422fe942c837ad16e36bab87c5f7567609de9a38e205fb51ed,03a778eaee9cc18a4e5e02a78f403082d4e6f3a9c0d9edaea20b9ad86089de7fc9,02a3c95e41e8272c6842df8c9da492ef5e03bbc4ca17c22ce1f88570e716e187db,032e1d465bc5cdea674337934fb861d097dd7ab20289e4d41de14a6cafcd61d30a,0370fd35da88778a805ce9acc88c0020e3b14cacaa30f99d829207e1896d782ea1,03878a4b831af4fee069964448ccca999071633fcc751d296e8c5325167274febf,0248f8621596029568070dda40bc1e3ace78df320b5ebf0d6a431536e9af3ec894,03f757260835b7e439b244a9b10f5645966d7dcff9d2648c400a0d6827f4a64ac4,023b3972554e123985b6c3d8575e6fd3384f59a58ef91e0d39ba5905dad49e7372,02e32652928f21764e02822d39ffd1075c428e372a06fe7247023d5b60f1d01596,020e002818c48b1d1766f6196e09db90f51e155bbd49be0ad743d1fa6b7e8efcae,03725d482f0c77f4feb1ecbea28f036b30889f462222002e88aa8f8346dce94474))#kcuhkkas' + } + }, + { + 'm': 1, + 'keys': [ + '02f293c4d026a536a082453f8327f305ae0a0c59350b396205e15fbec2af67390b', + '03d7b6a7e972f6e1a532f9f49a7cc35055a0ffd7cec5f81728f6a3fdf4dad93672' + ], + 'address_type': 'BECH32', + 'error': `Unknown address type 'BECH32'.` + }, + { + 'm': 4, + 'n': 1, + 'error': 'Invalid m and n values.' + }, + { + 'm': 4, + 'keys': [ + '02f293c4d026a536a082453f8327f305ae0a0c59350b396205e15fbec2af67390b', + '03d7b6a7e972f6e1a532f9f49a7cc35055a0ffd7cec5f81728f6a3fdf4dad93672', + '021f360d51b8eb43422fe942c837ad16e36bab87c5f7567609de9a38e205fb51ed', + '03a778eaee9cc18a4e5e02a78f403082d4e6f3a9c0d9edaea20b9ad86089de7fc9', + '02a3c95e41e8272c6842df8c9da492ef5e03bbc4ca17c22ce1f88570e716e187db', + '032e1d465bc5cdea674337934fb861d097dd7ab20289e4d41de14a6cafcd61d30a', + '0370fd35da88778a805ce9acc88c0020e3b14cacaa30f99d829207e1896d782ea1', + '03878a4b831af4fee069964448ccca999071633fcc751d296e8c5325167274febf', + '0248f8621596029568070dda40bc1e3ace78df320b5ebf0d6a431536e9af3ec894', + '03f757260835b7e439b244a9b10f5645966d7dcff9d2648c400a0d6827f4a64ac4', + '023b3972554e123985b6c3d8575e6fd3384f59a58ef91e0d39ba5905dad49e7372', + '02e32652928f21764e02822d39ffd1075c428e372a06fe7247023d5b60f1d01596', + '020e002818c48b1d1766f6196e09db90f51e155bbd49be0ad743d1fa6b7e8efcae', + '03725d482f0c77f4feb1ecbea28f036b30889f462222002e88aa8f8346dce94474', + '0370fd35da88778a805ce9acc88c0020e3b14cacaa30f99d829207e1896d782ea1', + '03878a4b831af4fee069964448ccca999071633fcc751d296e8c5325167274febf', + '0248f8621596029568070dda40bc1e3ace78df320b5ebf0d6a431536e9af3ec894', + '03f757260835b7e439b244a9b10f5645966d7dcff9d2648c400a0d6827f4a64ac4', + '023b3972554e123985b6c3d8575e6fd3384f59a58ef91e0d39ba5905dad49e7372', + '023b3972554e123985b6c3d8575e6fd3384f59a58ef91e0d39ba5905dad49e7372' + ], + 'address_type': 'legacy', + 'error': 'Script size is too large' + } + ]; + + for (const test of data) { + try { + const result = test.address_type ? await nclient.execute('createmultisig', [test.m, test.keys, test.address_type]) : await nclient.execute('createmultisig', [test.m, test.keys, test.address_type]); + assert.deepStrictEqual(result, test.result); + } catch (e) { + assert.strictEqual(e.message, test.error); + } + } + }); + it('should rpc getblockhash', async () => { const info = await nclient.execute('getblockhash', [node.chain.tip.height]); assert.strictEqual(util.revHex(node.chain.tip.hash), info);