Merge pull request #1133 from matiu/bug/nn-name

Bug/nn name
This commit is contained in:
Gustavo Maximiliano Cortez 2014-08-19 16:45:51 -03:00
commit 068f8cad52
7 changed files with 51 additions and 36 deletions

View file

@ -13,8 +13,8 @@ function PrivateKey(opts) {
this.network = opts.networkName === 'testnet' ?
networks.testnet : networks.livenet;
var init = opts.extendedPrivateKeyString || this.network.name;
this.bip = opts.HK || new HK(init);
this.privateKeyCache = opts.privateKeyCache || {};
this.bip = new HK(init);
this.privateKeyCache = {};
this.publicHex = this.deriveBIP45Branch().eckey.public.toString('hex');
};
@ -54,15 +54,24 @@ PrivateKey.prototype.deriveBIP45Branch = function() {
return this.bip45Branch;
}
PrivateKey.trim = function(data) {
var opts = {};
['networkName', 'extendedPrivateKeyString'].forEach(function(k){
opts[k] = data[k];
});
return opts;
};
PrivateKey.fromObj = function(obj) {
return new PrivateKey(obj);
return new PrivateKey(PrivateKey.trim(obj));
};
PrivateKey.prototype.toObj = function() {
return {
extendedPrivateKeyString: this.getExtendedPrivateKeyString(),
networkName: this.network.name,
privateKeyCache: this.privateKeyCache
};
};

View file

@ -21,31 +21,42 @@ function PublicKeyRing(opts) {
this.requiredCopayers = opts.requiredCopayers || 3;
this.totalCopayers = opts.totalCopayers || 5;
this.copayersHK = opts.copayersHK || [];
this.copayersHK = [];
this.indexes = opts.indexes ? HDParams.fromList(opts.indexes) : HDParams.init(this.totalCopayers);
this.publicKeysCache = opts.publicKeysCache || {};
this.publicKeysCache = {};
this.nicknameFor = opts.nicknameFor || {};
this.copayerIds = [];
this.copayersBackup = opts.copayersBackup || [];
this.addressToPath = {};
}
PublicKeyRing.trim = function(data) {
var opts = {};
['walletId', 'networkName', 'requiredCopayers', 'totalCopayers','indexes','nicknameFor','copayersBackup', 'copayersExtPubKeys' ].forEach(function(k){
opts[k] = data[k];
});
return opts;
};
PublicKeyRing.fromObj = function(data) {
if (data instanceof PublicKeyRing) {
throw new Error('bad data format: Did you use .toObj()?');
}
var opts = PublicKeyRing.trim(data);
// Support old indexes schema
if (!Array.isArray(data.indexes)) {
data.indexes = HDParams.update(data.indexes, data.totalCopayers);
if (!Array.isArray(opts.indexes)) {
opts.indexes = HDParams.update(opts.indexes, opts.totalCopayers);
}
var ret = new PublicKeyRing(data);
var ret = new PublicKeyRing(opts);
for (var k in data.copayersExtPubKeys) {
ret.addCopayer(data.copayersExtPubKeys[k]);
for (var k in opts.copayersExtPubKeys) {
ret.addCopayer(opts.copayersExtPubKeys[k]);
}
return ret;
@ -64,7 +75,6 @@ PublicKeyRing.prototype.toObj = function() {
return b.extendedPublicKeyString();
}),
nicknameFor: this.nicknameFor,
publicKeysCache: this.publicKeysCache
};
};
@ -366,8 +376,10 @@ PublicKeyRing.prototype._checkInPKR = function(inPKR, ignoreId) {
PublicKeyRing.prototype._mergePubkeys = function(inPKR) {
var self = this;
var hasChanged = false;
var l = self.copayersHK.length;
if (self.isComplete())
return;
@ -422,7 +434,7 @@ PublicKeyRing.prototype.merge = function(inPKR, ignoreId) {
var hasChanged = false;
hasChanged |= this.mergeIndexes(inPKR.indexes);
hasChanged |= this._mergePubkeys(inPKR);
hasChanged |= this.mergeBackups(inPKR.copayersBackup);
hasChanged |= this._mergeBackups(inPKR.copayersBackup);
return !!hasChanged;
};
@ -439,7 +451,7 @@ PublicKeyRing.prototype.mergeIndexes = function(indexes) {
return !!hasChanged
}
PublicKeyRing.prototype.mergeBackups = function(backups) {
PublicKeyRing.prototype._mergeBackups = function(backups) {
var self = this;
var hasChanged = false;

View file

@ -618,7 +618,6 @@ Wallet.prototype.sendWalletId = function(recipients) {
Wallet.prototype.sendPublicKeyRing = function(recipients) {
this.log('### SENDING publicKeyRing TO:', recipients || 'All', this.publicKeyRing.toObj());
var publicKeyRing = this.publicKeyRing.toObj();
delete publicKeyRing.publicKeysCache; // exclude publicKeysCache from network obj
this.send(recipients, {
type: 'publicKeyRing',