settings: added network to wallet secret
This commit is contained in:
parent
fc1d098135
commit
520fd762ba
2 changed files with 17 additions and 16 deletions
|
|
@ -647,7 +647,11 @@ Wallet.prototype.getSecretNumber = function() {
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
Wallet.prototype.getSecret = function() {
|
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);
|
var str = Base58Check.encode(buf);
|
||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
|
|
@ -662,9 +666,11 @@ Wallet.decodeSecret = function(secretB) {
|
||||||
var secret = Base58Check.decode(secretB);
|
var secret = Base58Check.decode(secretB);
|
||||||
var pubKeyBuf = secret.slice(0, 33);
|
var pubKeyBuf = secret.slice(0, 33);
|
||||||
var secretNumber = secret.slice(33, 38);
|
var secretNumber = secret.slice(33, 38);
|
||||||
|
var networkName = secret.slice(38, 39) === 'L' ? 'livenet' : 'testnet';
|
||||||
return {
|
return {
|
||||||
pubKey: pubKeyBuf.toString('hex'),
|
pubKey: pubKeyBuf.toString('hex'),
|
||||||
secretNumber: secretNumber.toString('hex')
|
secretNumber: secretNumber.toString('hex'),
|
||||||
|
networkName: networkName,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,6 @@ function WalletFactory(config, version) {
|
||||||
this.network = new this.Network(config.network);
|
this.network = new this.Network(config.network);
|
||||||
this.blockchain = new this.Blockchain(config.network);
|
this.blockchain = new this.Blockchain(config.network);
|
||||||
|
|
||||||
this.networkName = config.networkName;
|
|
||||||
this.walletDefaults = config.wallet;
|
this.walletDefaults = config.wallet;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
};
|
};
|
||||||
|
|
@ -82,9 +81,6 @@ WalletFactory.prototype.fromObj = function(obj, skipFields) {
|
||||||
// not stored options
|
// not stored options
|
||||||
obj.opts.reconnectDelay = this.walletDefaults.reconnectDelay;
|
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 = skipFields || [];
|
||||||
skipFields.forEach(function(k) {
|
skipFields.forEach(function(k) {
|
||||||
if (obj[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'));
|
log.debug('### CREATING NEW WALLET.' + (opts.id ? ' USING ID: ' + opts.id : ' NEW ID') + (opts.privateKey ? ' USING PrivateKey: ' + opts.privateKey.getId() : ' NEW PrivateKey'));
|
||||||
|
|
||||||
var privOpts = {
|
var privOpts = {
|
||||||
networkName: this.networkName,
|
networkName: opts.networkName,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (opts.privateKeyHex && opts.privateKeyHex.length > 1) {
|
if (opts.privateKeyHex && opts.privateKeyHex.length > 1) {
|
||||||
|
|
@ -192,7 +188,7 @@ WalletFactory.prototype.create = function(opts) {
|
||||||
opts.lockTimeoutMin = this.walletDefaults.idleDurationMin;
|
opts.lockTimeoutMin = this.walletDefaults.idleDurationMin;
|
||||||
|
|
||||||
opts.publicKeyRing = opts.publicKeyRing || new PublicKeyRing({
|
opts.publicKeyRing = opts.publicKeyRing || new PublicKeyRing({
|
||||||
networkName: this.networkName,
|
networkName: opts.networkName,
|
||||||
requiredCopayers: requiredCopayers,
|
requiredCopayers: requiredCopayers,
|
||||||
totalCopayers: totalCopayers,
|
totalCopayers: totalCopayers,
|
||||||
});
|
});
|
||||||
|
|
@ -203,7 +199,7 @@ WalletFactory.prototype.create = function(opts) {
|
||||||
log.debug('\t### PublicKeyRing Initialized');
|
log.debug('\t### PublicKeyRing Initialized');
|
||||||
|
|
||||||
opts.txProposals = opts.txProposals || new TxProposals({
|
opts.txProposals = opts.txProposals || new TxProposals({
|
||||||
networkName: this.networkName,
|
networkName: opts.networkName,
|
||||||
});
|
});
|
||||||
log.debug('\t### TxProposals Initialized');
|
log.debug('\t### TxProposals Initialized');
|
||||||
|
|
||||||
|
|
@ -332,11 +328,11 @@ WalletFactory.prototype.decodeSecret = function(secret) {
|
||||||
*/
|
*/
|
||||||
WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphrase, privateHex, cb) {
|
WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphrase, privateHex, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var s = self.decodeSecret(secret);
|
var decodedSecret = self.decodeSecret(secret);
|
||||||
if (!s) return cb('badSecret');
|
if (!decodedSecret) return cb('badSecret');
|
||||||
|
|
||||||
var privOpts = {
|
var privOpts = {
|
||||||
networkName: this.networkName,
|
networkName: decodedSecret.networkName,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (privateHex && privateHex.length > 1) {
|
if (privateHex && privateHex.length > 1) {
|
||||||
|
|
@ -350,7 +346,7 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras
|
||||||
copayerId: privateKey.getId(),
|
copayerId: privateKey.getId(),
|
||||||
privkey: privateKey.getIdPriv(),
|
privkey: privateKey.getIdPriv(),
|
||||||
key: privateKey.getIdKey(),
|
key: privateKey.getIdKey(),
|
||||||
secretNumber: s.secretNumber,
|
secretNumber: decodedSecret.secretNumber,
|
||||||
};
|
};
|
||||||
self.network.cleanUp();
|
self.network.cleanUp();
|
||||||
|
|
||||||
|
|
@ -365,7 +361,7 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras
|
||||||
});
|
});
|
||||||
|
|
||||||
self.network.start(opts, function() {
|
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) {
|
self.network.on('data', function(sender, data) {
|
||||||
if (data.type === 'walletId') {
|
if (data.type === 'walletId') {
|
||||||
if (data.networkName !== self.networkName) {
|
if (data.networkName !== self.networkName) {
|
||||||
|
|
@ -377,8 +373,7 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras
|
||||||
data.opts.passphrase = passphrase;
|
data.opts.passphrase = passphrase;
|
||||||
data.opts.id = data.walletId;
|
data.opts.id = data.walletId;
|
||||||
var w = self.create(data.opts);
|
var w = self.create(data.opts);
|
||||||
w.sendWalletReady(s.pubKey);
|
w.sendWalletReady(decodedSecret.pubKey);
|
||||||
//w.seedCopayer(s.pubKey);
|
|
||||||
return cb(null, w);
|
return cb(null, w);
|
||||||
} else {
|
} else {
|
||||||
return cb('walletFull', w);
|
return cb('walletFull', w);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue