Skip to content

Commit

Permalink
add sorting of pubkeys for multisig addr generation
Browse files Browse the repository at this point in the history
  • Loading branch information
matiu committed Apr 4, 2014
1 parent 710be7b commit 921bc2f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 22 additions & 1 deletion Script.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,28 @@ Script.createPubKeyHashOut = function(pubKeyHash) {
return script;
};

Script.createMultisig = function(n_required, keys) {
Script._sortKeys = function(keys) {
return keys.sort(function(buf1, buf2) {
var len = buf1.length > buf1.length ? buf1.length : buf2.length;
for (var i = 0; i <= len; i++) {
if (buf1[i] === undefined)
return -1; //shorter strings come first
if (buf2[i] === undefined)
return 1;
if (buf1[i] < buf2[i])
return -1;
if (buf1[i] > buf2[i])
return 1;
else
continue;
}
return 0;
});
};

Script.createMultisig = function(n_required, inKeys, opts) {
opts = opts || {};
var keys = opts.noSorting ? i || inKeys : this._sortKeys(inKeys);
var script = new Script();
script.writeN(n_required);
keys.forEach(function(key) {
Expand Down
2 changes: 1 addition & 1 deletion test/data/unspentSign.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
],
"unspentP2sh": [
{
"address": "2Mwswt6Eih28xH8611fexpqKqJCLJMomveK",
"address": "2NDJbzwzsmRgD2o5HHXPhuq5g6tkKTjYkd6",
"scriptPubKey": "a91432d272ce8a9b482b363408a0b1dd28123d59c63387",
"txid": "2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1",
"vout": 1,
Expand Down

0 comments on commit 921bc2f

Please sign in to comment.