From 520fd762ba080952833b8283fb7550a1f69a996c Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 9 Sep 2014 15:30:49 -0700 Subject: [PATCH] settings: added network to wallet secret --- js/models/core/Wallet.js | 10 ++++++++-- js/models/core/WalletFactory.js | 23 +++++++++-------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 5fe1611da..56d216ab5 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -647,7 +647,11 @@ Wallet.prototype.getSecretNumber = function() { * @return {string} */ Wallet.prototype.getSecret = function() { - var buf = new Buffer(this.getMyCopayerId() + this.getSecretNumber(), 'hex'); + var buf = new Buffer( + this.getMyCopayerId() + + this.getSecretNumber() + + this.getNetworkName() === 'livenet' ? 'L' : 'T', + 'hex'); var str = Base58Check.encode(buf); return str; }; @@ -662,9 +666,11 @@ Wallet.decodeSecret = function(secretB) { var secret = Base58Check.decode(secretB); var pubKeyBuf = secret.slice(0, 33); var secretNumber = secret.slice(33, 38); + var networkName = secret.slice(38, 39) === 'L' ? 'livenet' : 'testnet'; return { pubKey: pubKeyBuf.toString('hex'), - secretNumber: secretNumber.toString('hex') + secretNumber: secretNumber.toString('hex'), + networkName: networkName, } }; diff --git a/js/models/core/WalletFactory.js b/js/models/core/WalletFactory.js index e205896e6..3902d6763 100644 --- a/js/models/core/WalletFactory.js +++ b/js/models/core/WalletFactory.js @@ -44,7 +44,6 @@ function WalletFactory(config, version) { this.network = new this.Network(config.network); this.blockchain = new this.Blockchain(config.network); - this.networkName = config.networkName; this.walletDefaults = config.wallet; this.version = version; }; @@ -82,9 +81,6 @@ WalletFactory.prototype.fromObj = function(obj, skipFields) { // not stored options obj.opts.reconnectDelay = this.walletDefaults.reconnectDelay; - // this is only used if private key or public key ring is skipped - obj.opts.networkName = this.networkName; - skipFields = skipFields || []; skipFields.forEach(function(k) { if (obj[k]) { @@ -178,7 +174,7 @@ WalletFactory.prototype.create = function(opts) { log.debug('### CREATING NEW WALLET.' + (opts.id ? ' USING ID: ' + opts.id : ' NEW ID') + (opts.privateKey ? ' USING PrivateKey: ' + opts.privateKey.getId() : ' NEW PrivateKey')); var privOpts = { - networkName: this.networkName, + networkName: opts.networkName, }; if (opts.privateKeyHex && opts.privateKeyHex.length > 1) { @@ -192,7 +188,7 @@ WalletFactory.prototype.create = function(opts) { opts.lockTimeoutMin = this.walletDefaults.idleDurationMin; opts.publicKeyRing = opts.publicKeyRing || new PublicKeyRing({ - networkName: this.networkName, + networkName: opts.networkName, requiredCopayers: requiredCopayers, totalCopayers: totalCopayers, }); @@ -203,7 +199,7 @@ WalletFactory.prototype.create = function(opts) { log.debug('\t### PublicKeyRing Initialized'); opts.txProposals = opts.txProposals || new TxProposals({ - networkName: this.networkName, + networkName: opts.networkName, }); log.debug('\t### TxProposals Initialized'); @@ -332,11 +328,11 @@ WalletFactory.prototype.decodeSecret = function(secret) { */ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphrase, privateHex, cb) { var self = this; - var s = self.decodeSecret(secret); - if (!s) return cb('badSecret'); + var decodedSecret = self.decodeSecret(secret); + if (!decodedSecret) return cb('badSecret'); var privOpts = { - networkName: this.networkName, + networkName: decodedSecret.networkName, }; if (privateHex && privateHex.length > 1) { @@ -350,7 +346,7 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras copayerId: privateKey.getId(), privkey: privateKey.getIdPriv(), key: privateKey.getIdKey(), - secretNumber: s.secretNumber, + secretNumber: decodedSecret.secretNumber, }; self.network.cleanUp(); @@ -365,7 +361,7 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras }); self.network.start(opts, function() { - self.network.greet(s.pubKey, opts.secretNumber); + self.network.greet(decodedSecret.pubKey, opts.secretNumber); self.network.on('data', function(sender, data) { if (data.type === 'walletId') { if (data.networkName !== self.networkName) { @@ -377,8 +373,7 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras data.opts.passphrase = passphrase; data.opts.id = data.walletId; var w = self.create(data.opts); - w.sendWalletReady(s.pubKey); - //w.seedCopayer(s.pubKey); + w.sendWalletReady(decodedSecret.pubKey); return cb(null, w); } else { return cb('walletFull', w);