add random key for network encryption
This commit is contained in:
parent
add1b084cc
commit
2dc59de87e
8 changed files with 99 additions and 55 deletions
|
|
@ -9,6 +9,8 @@ var Builder = bitcore.TransactionBuilder;
|
|||
var http = require('http');
|
||||
var EventEmitter = imports.EventEmitter || require('events').EventEmitter;
|
||||
var copay = copay || require('../../../copay');
|
||||
var SecureRandom = bitcore.SecureRandom;
|
||||
var Base58Check = bitcore.Base58.base58Check;
|
||||
|
||||
function Wallet(opts) {
|
||||
var self = this;
|
||||
|
|
@ -26,6 +28,8 @@ function Wallet(opts) {
|
|||
|
||||
this.id = opts.id || Wallet.getRandomId();
|
||||
this.name = opts.name;
|
||||
this.netKey = opts.netKey || SecureRandom.getRandomBuffer(8).toString('base64');
|
||||
|
||||
this.verbose = opts.verbose;
|
||||
this.publicKeyRing.walletId = this.id;
|
||||
this.txProposals.walletId = this.id;
|
||||
|
|
@ -124,6 +128,7 @@ Wallet.prototype._optsToObj = function() {
|
|||
requiredCopayers: this.requiredCopayers,
|
||||
totalCopayers: this.totalCopayers,
|
||||
name: this.name,
|
||||
netKey: this.netKey,
|
||||
};
|
||||
|
||||
return obj;
|
||||
|
|
@ -139,6 +144,26 @@ Wallet.prototype.getMyCopayerId = function() {
|
|||
return this.getCopayerId(0);
|
||||
};
|
||||
|
||||
|
||||
Wallet.prototype.getSecret = function() {
|
||||
var i = new Buffer(this.getMyCopayerId(),'hex');
|
||||
var k = new Buffer(this.netKey,'base64');
|
||||
var b = Buffer.concat([i,k]);
|
||||
var str = Base58Check.encode(b);
|
||||
return str;
|
||||
};
|
||||
|
||||
|
||||
Wallet.decodeSecret = function(secretB) {
|
||||
var secret = Base58Check.decode(secretB);
|
||||
var netKeyBuf = secret.slice(-8);
|
||||
var pubKeyBuf = secret.slice(0,33);
|
||||
return {
|
||||
pubKey: pubKeyBuf.toString('hex'),
|
||||
netKey: netKeyBuf.toString('base64'),
|
||||
}
|
||||
};
|
||||
|
||||
Wallet.prototype._lockIncomming = function() {
|
||||
this.network.lockIncommingConnections(this.publicKeyRing.getAllCopayerIds());
|
||||
};
|
||||
|
|
@ -162,6 +187,7 @@ Wallet.prototype.netStart = function() {
|
|||
var startOpts = {
|
||||
copayerId: myId,
|
||||
maxPeers: self.totalCopayers,
|
||||
netKey: this.netKey,
|
||||
};
|
||||
|
||||
if (this.publicKeyRing.isComplete()) {
|
||||
|
|
|
|||
|
|
@ -149,27 +149,35 @@ WalletFactory.prototype.remove = function(walletId) {
|
|||
};
|
||||
|
||||
|
||||
WalletFactory.prototype.joinCreateSession = function(copayerId, cb) {
|
||||
WalletFactory.prototype.joinCreateSession = function(secret, cb) {
|
||||
var self = this;
|
||||
|
||||
var s;
|
||||
try {
|
||||
s=Wallet.decodeSecret(secret);
|
||||
} catch (e) {
|
||||
return cb('badSecret');
|
||||
}
|
||||
|
||||
//Create our PrivateK
|
||||
var privateKey = new PrivateKey({ networkName: this.networkName });
|
||||
this.log('\t### PrivateKey Initialized');
|
||||
var opts = {
|
||||
copayerId: privateKey.getId(),
|
||||
netKey: s.netKey,
|
||||
};
|
||||
self.network.cleanUp();
|
||||
self.network.start(opts, function() {
|
||||
self.network.connectTo(copayerId);
|
||||
self.network.connectTo(s.pubKey);
|
||||
self.network.on('onlyYou', function(sender, data) {
|
||||
return cb();
|
||||
return cb('joinError');
|
||||
});
|
||||
self.network.on('data', function(sender, data) {
|
||||
if (data.type ==='walletId') {
|
||||
data.opts.privateKey = privateKey;
|
||||
var w = self.open(data.walletId, data.opts);
|
||||
w.firstCopayerId = copayerId;
|
||||
return cb(w);
|
||||
w.firstCopayerId = s.pubKey;
|
||||
return cb(null, w);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue