|
|
@ -516,32 +516,30 @@ Script.prototype.removeCodeseparators = function() { |
|
|
|
/** |
|
|
|
* @returns a new Multisig output script for given public keys, |
|
|
|
* requiring m of those public keys to spend |
|
|
|
* @param {PublicKey[]} pubkeys - list of all public keys controlling the output |
|
|
|
* @param {number} m - amount of required signatures to spend the output |
|
|
|
* @param {PublicKey[]} publicKeys - list of all public keys controlling the output |
|
|
|
* @param {number} threshold - amount of required signatures to spend the output |
|
|
|
* @param {Object} [opts] - Several options: |
|
|
|
* - noSorting: defaults to false, if true, don't sort the given |
|
|
|
* public keys before creating the script |
|
|
|
*/ |
|
|
|
Script.buildMultisigOut = function(pubkeys, m, opts) { |
|
|
|
Script.buildMultisigOut = function(publicKeys, threshold, opts) { |
|
|
|
opts = opts || {}; |
|
|
|
var s = new Script(); |
|
|
|
s.add(Opcode.smallInt(m)); |
|
|
|
pubkeys = _.map(pubkeys, function(pubkey) { |
|
|
|
return PublicKey(pubkey); |
|
|
|
}); |
|
|
|
var sorted = pubkeys; |
|
|
|
var script = new Script(); |
|
|
|
script.add(Opcode.smallInt(threshold)); |
|
|
|
publicKeys = _.map(publicKeys, PublicKey); |
|
|
|
var sorted = publicKeys; |
|
|
|
if (!opts.noSorting) { |
|
|
|
sorted = _.sortBy(pubkeys, function(pubkey) { |
|
|
|
return pubkey.toString('hex'); |
|
|
|
sorted = _.sortBy(publicKeys, function(publicKey) { |
|
|
|
return publicKey.toString('hex'); |
|
|
|
}); |
|
|
|
} |
|
|
|
for (var i = 0; i < sorted.length; i++) { |
|
|
|
var pubkey = sorted[i]; |
|
|
|
s.add(pubkey.toBuffer()); |
|
|
|
var publicKey = sorted[i]; |
|
|
|
script.add(publicKey.toBuffer()); |
|
|
|
} |
|
|
|
s.add(Opcode.smallInt(pubkeys.length)); |
|
|
|
s.add(Opcode.OP_CHECKMULTISIG); |
|
|
|
return s; |
|
|
|
script.add(Opcode.smallInt(publicKeys.length)); |
|
|
|
script.add(Opcode.OP_CHECKMULTISIG); |
|
|
|
return script; |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|