move key sorting to utils.

This commit is contained in:
Christopher Jeffrey 2015-12-17 17:23:33 -08:00
parent b74e8de067
commit efe1181bc1
3 changed files with 10 additions and 16 deletions

View File

@ -781,10 +781,7 @@ script.multisig = function(keys, m, n) {
while (keys.length < n)
keys.push([]);
// Keys need to be in a predictable order.
keys = keys.sort(function(a, b) {
return new bn(a).cmp(new bn(b)) > 0;
});
keys = utils.sortKeys(keys);
return [ m ].concat(
keys,

View File

@ -586,3 +586,9 @@ utils.hidden = function(obj, prop, value) {
});
return obj;
};
utils.sortKeys = function(keys) {
return keys.sort(function(a, b) {
return new bn(a).cmp(new bn(b)) > 0;
});
};

View File

@ -170,10 +170,7 @@ Wallet.prototype.addKey = function addKey(key) {
this.keys.push(key);
// Keys need to be in a predictable order.
this.keys = this.keys.sort(function(a, b) {
return new bn(a).cmp(new bn(b)) > 0;
});
this.keys = utils.sortKeys(this.keys);
};
Wallet.prototype.removeKey = function removeKey(key) {
@ -190,10 +187,7 @@ Wallet.prototype.removeKey = function removeKey(key) {
this.keys.splice(index, 1);
// Keys need to be in a predictable order.
this.keys = this.keys.sort(function(a, b) {
return new bn(a).cmp(new bn(b)) > 0;
});
this.keys = utils.sortKeys(this.keys);
};
Wallet.prototype.derive = function derive() {
@ -267,10 +261,7 @@ Wallet.prototype.getPublicKey = function getPublicKey(enc) {
Wallet.prototype.getPublicKeys = function() {
var keys = this.keys.slice().map(utils.toKeyArray);
// Keys need to be in a predictable order.
keys = keys.sort(function(a, b) {
return new bn(a).cmp(new bn(b)) > 0;
});
keys = utils.sortKeys(keys);
return keys;
};