Store secret number

This commit is contained in:
Ivan Socolsky 2014-10-03 09:56:35 -03:00 committed by Matias Alejo Garcia
commit b3c1447376

View file

@ -81,7 +81,7 @@ function Wallet(opts) {
this.id = opts.id || Wallet.getRandomId(); this.id = opts.id || Wallet.getRandomId();
this.secretNumber = opts.secretNumber || Wallet.getRandomNumber(); this.secretNumber = opts.secretNumber || Wallet.getRandomSecretNumber();
this.lock = new WalletLock(this.storage, this.id, opts.lockTimeOutMin); this.lock = new WalletLock(this.storage, this.id, opts.lockTimeOutMin);
this.settings = opts.settings || copayConfig.wallet.settings; this.settings = opts.settings || copayConfig.wallet.settings;
this.name = opts.name; this.name = opts.name;
@ -149,6 +149,7 @@ Wallet.PERSISTED_PROPERTIES = [
'addressBook', 'addressBook',
'backupOffered', 'backupOffered',
'lastTimestamp', 'lastTimestamp',
'secretNumber',
]; ];
Wallet.COPAYER_PAIR_LIMITS = { Wallet.COPAYER_PAIR_LIMITS = {
@ -200,11 +201,11 @@ Wallet.getRandomId = function() {
}; };
/** /**
* @desc Get a random 8 byte number and encode it as a hexa string * @desc Retrieve a random secret number to secure wallet secret
* @return {string} * @return {string} 5 bytes, hexa encoded
*/ */
Wallet.getRandomNumber = function() { Wallet.getRandomSecretNumber = function() {
var r = bitcore.SecureRandom.getPseudoRandomBuffer(5).toString('hex'); var r = bitcore.SecureRandom.getPseudoRandomBuffer(5).toString('hex')
return r; return r;
}; };
@ -828,8 +829,6 @@ Wallet.prototype.getMyCopayerNickname = function() {
* @return {string} my own pubkey, base58 encoded * @return {string} my own pubkey, base58 encoded
*/ */
Wallet.prototype.getSecretNumber = function() { Wallet.prototype.getSecretNumber = function() {
if (this.secretNumber) return this.secretNumber;
this.secretNumber = Wallet.getRandomNumber();
return this.secretNumber; return this.secretNumber;
}; };
@ -1066,6 +1065,7 @@ Wallet.prototype.toObj = function() {
privateKey: this.privateKey ? this.privateKey.toObj() : undefined, privateKey: this.privateKey ? this.privateKey.toObj() : undefined,
addressBook: this.addressBook, addressBook: this.addressBook,
lastTimestamp: this.lastTimestamp || 0, lastTimestamp: this.lastTimestamp || 0,
secretNumber: this.secretNumber,
}; };
return walletObj; return walletObj;
@ -1131,6 +1131,8 @@ Wallet.fromObj = function(o, readOpts) {
}); });
} }
opts.secretNumber = o.secretNumber;
if (o.publicKeyRing) { if (o.publicKeyRing) {
opts.publicKeyRing = PublicKeyRing.fromObj(o.publicKeyRing); opts.publicKeyRing = PublicKeyRing.fromObj(o.publicKeyRing);
} else { } else {