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

View File

@ -586,3 +586,9 @@ utils.hidden = function(obj, prop, value) {
}); });
return obj; 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); this.keys.push(key);
// Keys need to be in a predictable order. this.keys = utils.sortKeys(this.keys);
this.keys = this.keys.sort(function(a, b) {
return new bn(a).cmp(new bn(b)) > 0;
});
}; };
Wallet.prototype.removeKey = function removeKey(key) { Wallet.prototype.removeKey = function removeKey(key) {
@ -190,10 +187,7 @@ Wallet.prototype.removeKey = function removeKey(key) {
this.keys.splice(index, 1); this.keys.splice(index, 1);
// Keys need to be in a predictable order. this.keys = utils.sortKeys(this.keys);
this.keys = this.keys.sort(function(a, b) {
return new bn(a).cmp(new bn(b)) > 0;
});
}; };
Wallet.prototype.derive = function derive() { Wallet.prototype.derive = function derive() {
@ -267,10 +261,7 @@ Wallet.prototype.getPublicKey = function getPublicKey(enc) {
Wallet.prototype.getPublicKeys = function() { Wallet.prototype.getPublicKeys = function() {
var keys = this.keys.slice().map(utils.toKeyArray); var keys = this.keys.slice().map(utils.toKeyArray);
// Keys need to be in a predictable order. keys = utils.sortKeys(keys);
keys = keys.sort(function(a, b) {
return new bn(a).cmp(new bn(b)) > 0;
});
return keys; return keys;
}; };