fix conflics
This commit is contained in:
parent
b2f377da18
commit
1e8895f4b8
10 changed files with 144 additions and 64 deletions
|
|
@ -32,6 +32,8 @@ function PublicKeyRing(opts) {
|
|||
this.addressIndex= opts.addressIndex || 0;
|
||||
|
||||
this.publicKeysCache = opts.publicKeysCache || {};
|
||||
this.nicknameFor = opts.nicknameFor || {};
|
||||
this.copayerIds = [];
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -54,10 +56,13 @@ PublicKeyRing.fromObj = function (data) {
|
|||
if (data instanceof PublicKeyRing) {
|
||||
throw new Error('bad data format: Did you use .toObj()?');
|
||||
}
|
||||
data.copayersBIP32 = data.copayersExtPubKeys.map(function(pk) {
|
||||
return new BIP32(pk);
|
||||
});
|
||||
return new PublicKeyRing(data);
|
||||
var ret = new PublicKeyRing(data);
|
||||
|
||||
for (var k in data.copayersExtPubKeys) {
|
||||
ret.addCopayer(data.copayersExtPubKeys[k]);
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.toObj = function() {
|
||||
|
|
@ -72,23 +77,12 @@ PublicKeyRing.prototype.toObj = function() {
|
|||
copayersExtPubKeys: this.copayersBIP32.map( function (b) {
|
||||
return b.extendedPublicKeyString();
|
||||
}),
|
||||
nicknameFor: this.nicknameFor,
|
||||
publicKeysCache: this.publicKeysCache
|
||||
};
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.serialize = function () {
|
||||
return JSON.stringify(this.toObj());
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.getCopayerId = function(i) {
|
||||
this.copayerIds = this.copayerIds || [];
|
||||
|
||||
if (!this.copayerIds[i]) {
|
||||
var path = PublicKeyRing.ID_BRANCH;
|
||||
var bip32 = this.copayersBIP32[i].derive(path);
|
||||
this.copayerIds[i]= bip32.eckey.public.toString('hex');
|
||||
}
|
||||
|
||||
return this.copayerIds[i];
|
||||
};
|
||||
|
||||
|
|
@ -101,12 +95,7 @@ PublicKeyRing.prototype.isComplete = function () {
|
|||
};
|
||||
|
||||
PublicKeyRing.prototype.getAllCopayerIds = function() {
|
||||
var ret = [];
|
||||
var l = this.registeredCopayers();
|
||||
for(var i=0; i<l; i++) {
|
||||
ret.push(this.getCopayerId(i));
|
||||
}
|
||||
return ret;
|
||||
return this.copayerIds;
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.myCopayerId = function(i) {
|
||||
|
|
@ -119,14 +108,30 @@ PublicKeyRing.prototype._checkKeys = function() {
|
|||
throw new Error('dont have required keys yet');
|
||||
};
|
||||
|
||||
|
||||
PublicKeyRing.prototype._newExtendedPublicKey = function () {
|
||||
return new BIP32(this.network.name)
|
||||
.extendedPublicKeyString();
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.addCopayer = function (newEpk) {
|
||||
PublicKeyRing.prototype._updateBip = function (index) {
|
||||
var path = PublicKeyRing.ID_BRANCH;
|
||||
var bip32 = this.copayersBIP32[index].derive(path);
|
||||
this.copayerIds[index]= bip32.eckey.public.toString('hex');
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype._setNicknameForIndex = function (index, nickname) {
|
||||
this.nicknameFor[this.copayerIds[index]] = nickname;
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.nicknameForIndex = function (index) {
|
||||
return this.nicknameFor[this.copayerIds[index]];
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.nicknameForCopayer = function (copayerId) {
|
||||
return this.nicknameFor[copayerId];
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.addCopayer = function (newEpk, nickname) {
|
||||
if (this.isComplete())
|
||||
throw new Error('already have all required key:' + this.totalCopayers);
|
||||
|
||||
|
|
@ -139,7 +144,13 @@ PublicKeyRing.prototype.addCopayer = function (newEpk) {
|
|||
throw new Error('already have that key');
|
||||
});
|
||||
|
||||
this.copayersBIP32.push(new BIP32(newEpk));
|
||||
var i=this.copayersBIP32.length;
|
||||
var bip = new BIP32(newEpk);
|
||||
this.copayersBIP32.push(bip);
|
||||
this._updateBip(i);
|
||||
if (nickname) {
|
||||
this._setNicknameForIndex(i,nickname);
|
||||
}
|
||||
return newEpk;
|
||||
};
|
||||
|
||||
|
|
@ -156,9 +167,9 @@ PublicKeyRing.prototype.getPubKeys = function (index, isChange) {
|
|||
pubKeys[i] = bip32.eckey.public;
|
||||
}
|
||||
this.publicKeysCache[path] = pubKeys.map(function(pk){return pk.toString('hex');});
|
||||
} else {
|
||||
pubKeys = pubKeys.map(function(s){return new Buffer(s,'hex')});
|
||||
//console.log('public keys cache HIT');
|
||||
}
|
||||
else {
|
||||
pubKeys = pubKeys.map(function(s){return new Buffer(s,'hex');});
|
||||
}
|
||||
|
||||
return pubKeys;
|
||||
|
|
@ -193,7 +204,6 @@ PublicKeyRing.prototype.getScriptPubKeyHex = function (index, isChange) {
|
|||
return Script.createP2SH(addr.payload()).getBuffer().toString('hex');
|
||||
};
|
||||
|
||||
|
||||
//generate a new address, update index.
|
||||
PublicKeyRing.prototype.generateAddress = function(isChange) {
|
||||
|
||||
|
|
@ -206,7 +216,6 @@ PublicKeyRing.prototype.generateAddress = function(isChange) {
|
|||
}
|
||||
|
||||
return ret;
|
||||
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.getAddresses = function(excludeChange) {
|
||||
|
|
@ -254,8 +263,6 @@ PublicKeyRing.prototype.getRedeemScriptMap = function () {
|
|||
return ret;
|
||||
};
|
||||
|
||||
|
||||
|
||||
PublicKeyRing.prototype._checkInPRK = function(inPKR, ignoreId) {
|
||||
|
||||
if (!ignoreId && this.walletId !== inPKR.walletId) {
|
||||
|
|
@ -313,7 +320,11 @@ PublicKeyRing.prototype._mergePubkeys = function(inPKR) {
|
|||
if (self.isComplete()) {
|
||||
throw new Error('trying to add more pubkeys, when PKR isComplete at merge');
|
||||
}
|
||||
var l2 = self.copayersBIP32.length;
|
||||
self.copayersBIP32.push(new BIP32(epk));
|
||||
self._updateBip(l2);
|
||||
if (inPKR.nicknameFor[self.getCopayerId(l2)])
|
||||
self._setNicknameForIndex(l2,inPKR.nicknameFor[self.getCopayerId(l2)]);
|
||||
hasChanged=true;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ function Wallet(opts) {
|
|||
this.verbose = opts.verbose;
|
||||
this.publicKeyRing.walletId = this.id;
|
||||
this.txProposals.walletId = this.id;
|
||||
|
||||
this.network.maxPeers = this.totalCopayers;
|
||||
this.registeredPeerIds = [];
|
||||
}
|
||||
|
||||
Wallet.parent = EventEmitter;
|
||||
|
|
@ -196,7 +196,6 @@ Wallet.prototype.netStart = function() {
|
|||
|
||||
net.start(startOpts, function() {
|
||||
self.emit('created', net.getPeer());
|
||||
var registered = self.getRegisteredPeerIds();
|
||||
for (var i = 0; i < self.publicKeyRing.registeredCopayers(); i++) {
|
||||
var otherId = self.getCopayerId(i);
|
||||
if (otherId !== myId) {
|
||||
|
|
@ -216,13 +215,19 @@ Wallet.prototype.getOnlinePeerIDs = function() {
|
|||
};
|
||||
|
||||
Wallet.prototype.getRegisteredPeerIds = function() {
|
||||
var ret = [];
|
||||
for (var i = 0; i < this.publicKeyRing.registeredCopayers(); i++) {
|
||||
var cid = this.getCopayerId(i)
|
||||
var pid = this.network.peerFromCopayer(cid);
|
||||
ret.push(pid);
|
||||
var l = this.publicKeyRing.registeredCopayers();
|
||||
if (this.registeredPeerIds.length !== l) {
|
||||
this.registeredPeerIds = [];
|
||||
for (var i = 0; i < l; i++) {
|
||||
var cid = this.getCopayerId(i);
|
||||
var pid = this.network.peerFromCopayer(cid);
|
||||
this.registeredPeerIds.push({
|
||||
peerId: pid,
|
||||
nick: this.publicKeyRing.nicknameForCopayer(cid)
|
||||
});
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
return this.registeredPeerIds;
|
||||
};
|
||||
|
||||
Wallet.prototype.store = function(isSync) {
|
||||
|
|
@ -416,8 +421,8 @@ Wallet.prototype.getAddressesInfo = function(excludeChange) {
|
|||
return this.publicKeyRing.getAddressesInfo(excludeChange);
|
||||
};
|
||||
|
||||
Wallet.prototype.addressIsOwn = function(addrStr) {
|
||||
var addrList = this.getAddressesStr();
|
||||
Wallet.prototype.addressIsOwn = function(addrStr, excludeChange) {
|
||||
var addrList = this.getAddressesStr(excludeChange);
|
||||
var l = addrList.length;
|
||||
var ret = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ WalletFactory.prototype.create = function(opts) {
|
|||
requiredCopayers: requiredCopayers,
|
||||
totalCopayers: totalCopayers,
|
||||
});
|
||||
opts.publicKeyRing.addCopayer(opts.privateKey.getExtendedPublicKeyString());
|
||||
opts.publicKeyRing.addCopayer(opts.privateKey.getExtendedPublicKeyString(), opts.nickname);
|
||||
this.log('\t### PublicKeyRing Initialized');
|
||||
|
||||
opts.txProposals = opts.txProposals || new TxProposals({
|
||||
|
|
@ -149,7 +149,7 @@ WalletFactory.prototype.remove = function(walletId) {
|
|||
};
|
||||
|
||||
|
||||
WalletFactory.prototype.joinCreateSession = function(secret, cb) {
|
||||
WalletFactory.prototype.joinCreateSession = function(secret, nickname, cb) {
|
||||
var self = this;
|
||||
|
||||
var s;
|
||||
|
|
@ -175,6 +175,7 @@ WalletFactory.prototype.joinCreateSession = function(secret, cb) {
|
|||
self.network.on('data', function(sender, data) {
|
||||
if (data.type ==='walletId') {
|
||||
data.opts.privateKey = privateKey;
|
||||
data.opts.nickname = nickname;
|
||||
var w = self.open(data.walletId, data.opts);
|
||||
w.firstCopayerId = s.pubKey;
|
||||
return cb(null, w);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue