peer authentication
This commit is contained in:
parent
08fa60d41c
commit
6ace16e20d
9 changed files with 136 additions and 62 deletions
|
|
@ -18,13 +18,22 @@ function PrivateKey(opts) {
|
|||
this.privateKeyCache = opts.privateKeyCache || {};
|
||||
};
|
||||
|
||||
PrivateKey.prototype.getId = function(prefix) {
|
||||
var buf = this.bip.extendedPublicKey;
|
||||
if (prefix) {
|
||||
buf = Buffer.concat([prefix, buf]);
|
||||
PrivateKey.prototype.getId = function() {
|
||||
if (!this.id) {
|
||||
var path = PublicKeyRing.SIGNING_BRANCH;
|
||||
var bip32 = this.bip.derive(path);
|
||||
this.id= bip32.eckey.public.toString('hex');
|
||||
}
|
||||
var hash = util.sha256(buf).toString('hex');
|
||||
return hash.substring(0, hash.length/2);
|
||||
return this.id;
|
||||
};
|
||||
|
||||
PrivateKey.prototype.getSigningKey = function() {
|
||||
if (!this.sid) {
|
||||
var path = PublicKeyRing.SIGNING_BRANCH;
|
||||
var bip32 = this.bip.derive(path);
|
||||
this.sid= bip32.eckey.private.toString('hex');
|
||||
}
|
||||
return this.sid;
|
||||
};
|
||||
|
||||
PrivateKey.fromObj = function(obj) {
|
||||
|
|
|
|||
|
|
@ -44,9 +44,12 @@ function PublicKeyRing(opts) {
|
|||
*/
|
||||
|
||||
PublicKeyRing.Branch = function (index, isChange) {
|
||||
return 'm/'+(isChange?1:0)+'/'+index;
|
||||
// first 0 is for future use: could be copayerId.
|
||||
return 'm/0/'+(isChange?1:0)+'/'+index;
|
||||
};
|
||||
|
||||
PublicKeyRing.SIGNING_BRANCH = 'm/100/0/0';
|
||||
|
||||
PublicKeyRing.fromObj = function (data) {
|
||||
if (data instanceof PublicKeyRing) {
|
||||
throw new Error('bad data format: Did you use .toObj()?');
|
||||
|
|
@ -77,17 +80,20 @@ PublicKeyRing.prototype.serialize = function () {
|
|||
return JSON.stringify(this.toObj());
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.getCopayerId = function(i, prefix) {
|
||||
var buf = this.copayersBIP32[i].extendedPublicKey;
|
||||
if (prefix) {
|
||||
buf = Buffer.concat([prefix, buf]);
|
||||
PublicKeyRing.prototype.getCopayerId = function(i) {
|
||||
this.copayerIds = this.copayerIds || [];
|
||||
|
||||
if (!this.copayerIds[i]) {
|
||||
var path = PublicKeyRing.SIGNING_BRANCH;
|
||||
var bip32 = this.copayersBIP32[i].derive(path);
|
||||
this.copayerIds[i]= bip32.eckey.public.toString('hex');
|
||||
}
|
||||
var hash = util.sha256(buf).toString('hex');
|
||||
return hash.substring(0, hash.length/2);
|
||||
|
||||
return this.copayerIds[i];
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.myCopayerId = function(i, prefix) {
|
||||
return this.getCopayerId(0,prefix);
|
||||
PublicKeyRing.prototype.myCopayerId = function(i) {
|
||||
return this.getCopayerId(0);
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.registeredCopayers = function () {
|
||||
|
|
|
|||
|
|
@ -169,9 +169,10 @@ Wallet.prototype.netStart = function() {
|
|||
|
||||
var myId = self.getMyCopayerId();
|
||||
var startOpts = {
|
||||
copayerId: myId
|
||||
copayerId: myId,
|
||||
signingKeyHex: self.privateKey.getSigningKey(),
|
||||
};
|
||||
net.start(function() {
|
||||
net.start(startOpts, function() {
|
||||
self.emit('created');
|
||||
for (var i=0; i<self.publicKeyRing.registeredCopayers(); i++) {
|
||||
var otherId = self.getCopayerId(i);
|
||||
|
|
@ -184,7 +185,7 @@ Wallet.prototype.netStart = function() {
|
|||
}
|
||||
self.emit('refresh');
|
||||
}
|
||||
}, startOpts);
|
||||
});
|
||||
};
|
||||
|
||||
Wallet.prototype.store = function(isSync) {
|
||||
|
|
|
|||
|
|
@ -146,8 +146,8 @@ WalletFactory.prototype.joinCreateSession = function(copayerId, cb) {
|
|||
var privateKey = new PrivateKey({ networkName: this.networkName });
|
||||
this.log('\t### PrivateKey Initialized');
|
||||
self.network.setCopayerId(privateKey.getId());
|
||||
|
||||
self.network.start(function() {
|
||||
self.network.setSigningKey(privateKey.getSigningKey());
|
||||
self.network.start({}, function() {
|
||||
self.network.connectTo(copayerId);
|
||||
self.network.on('data', function(sender, data) {
|
||||
if (data.type ==='walletId') {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue