add random key for network encryption

This commit is contained in:
Matias Alejo Garcia 2014-04-30 12:58:40 -03:00
commit 2dc59de87e
8 changed files with 99 additions and 55 deletions

View file

@ -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()) {