diff --git a/src/key-formats/multisig.js b/src/key-formats/multisig.js index 1c17ec2..63c105a 100644 --- a/src/key-formats/multisig.js +++ b/src/key-formats/multisig.js @@ -3,13 +3,17 @@ const bitcoin = require('bitcoinjs-lib'); const generateRedeemScript = ({pubkeys, m}) => { const keyPair = bitcoin.ECPair.makeRandom(); const {publicKey} = keyPair; + + // BIP 67 lexicographically ordered pubkeys + pubkeys = [ + ...pubkeys, + publicKey + ].sort(Buffer.comapre); + let redeemScript; let n; ({output: redeemScript, m, n, pubkeys} = bitcoin.payments.p2ms({ - pubkeys: [ - ...pubkeys, - publicKey - ], + pubkeys, m }));