txproposal comuninication between peers. Still WIP
This commit is contained in:
parent
dbd5ed4346
commit
333ecb352a
12 changed files with 282 additions and 124 deletions
|
|
@ -12,7 +12,9 @@ var PublicKeyRing = require('./PublicKeyRing');
|
|||
function PrivateKey(opts) {
|
||||
this.network = opts.networkName === 'testnet' ?
|
||||
networks.testnet : networks.livenet;
|
||||
this.BIP32 = opts.BIP32 || new BIP32(opts.extendedPrivateKeyString || this.network.name);
|
||||
var init = opts.extendedPrivateKeyString || this.network.name;
|
||||
console.log('[PrivateKey.js.15:init:]',init); //TODO
|
||||
this.BIP32 = opts.BIP32 || new BIP32(init);
|
||||
this._calcId();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,8 @@ PublicKeyRing.ChangeBranch = function (index) {
|
|||
};
|
||||
|
||||
PublicKeyRing.getRandomId = function () {
|
||||
return buffertools.toHex(coinUtil.generateNonce());
|
||||
var r = buffertools.toHex(coinUtil.generateNonce());
|
||||
return r;
|
||||
};
|
||||
|
||||
PublicKeyRing.decrypt = function (passphrase, encPayload) {
|
||||
|
|
@ -64,6 +65,9 @@ PublicKeyRing.encrypt = function (passphrase, payload) {
|
|||
};
|
||||
|
||||
PublicKeyRing.fromObj = function (data) {
|
||||
if (!data.ts) {
|
||||
throw new Error('bad data format: Did you use .toObj()?');
|
||||
}
|
||||
var config = { networkName: data.networkName || 'livenet' };
|
||||
|
||||
var w = new PublicKeyRing(config);
|
||||
|
|
@ -73,11 +77,11 @@ PublicKeyRing.fromObj = function (data) {
|
|||
w.addressIndex = data.addressIndex;
|
||||
w.changeAddressIndex = data.changeAddressIndex;
|
||||
|
||||
// this.bip32 = ;
|
||||
w.copayersBIP32 = data.copayersExtPubKeys.map( function (pk) {
|
||||
return new BIP32(pk);
|
||||
});
|
||||
|
||||
w.ts = data.ts;
|
||||
return w;
|
||||
};
|
||||
|
||||
|
|
@ -258,16 +262,11 @@ PublicKeyRing.prototype.getRedeemScriptMap = function () {
|
|||
|
||||
PublicKeyRing.prototype._checkInPRK = function(inPKR, ignoreId) {
|
||||
|
||||
|
||||
if (!inPKR.ts) {
|
||||
throw new Error('inPRK bad format: Did you use .toObj()?');
|
||||
}
|
||||
|
||||
if (!ignoreId && this.id !== inPKR.id) {
|
||||
throw new Error('inPRK id mismatch');
|
||||
}
|
||||
|
||||
if (this.network.name !== inPKR.networkName)
|
||||
if (this.network.name !== inPKR.network.name)
|
||||
throw new Error('inPRK network mismatch');
|
||||
|
||||
if (
|
||||
|
|
@ -279,9 +278,6 @@ PublicKeyRing.prototype._checkInPRK = function(inPKR, ignoreId) {
|
|||
this.totalCopayers && inPKR.totalCopayers &&
|
||||
(this.totalCopayers !== inPKR.totalCopayers))
|
||||
throw new Error('inPRK requiredCopayers mismatch');
|
||||
|
||||
if (! inPKR.ts)
|
||||
throw new Error('no ts at inPRK');
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -302,13 +298,13 @@ PublicKeyRing.prototype._mergeIndexes = function(inPKR) {
|
|||
};
|
||||
|
||||
PublicKeyRing.prototype._mergePubkeys = function(inPKR) {
|
||||
var hasChanged = false;
|
||||
var l= this.copayersBIP32.length;
|
||||
|
||||
var self = this;
|
||||
var hasChanged = false;
|
||||
var l= self.copayersBIP32.length;
|
||||
|
||||
inPKR.copayersExtPubKeys.forEach( function(epk) {
|
||||
inPKR.copayersBIP32.forEach( function(b) {
|
||||
var haveIt = false;
|
||||
var epk = b.extendedPublicKeyString();
|
||||
for(var j=0; j<l; j++) {
|
||||
if (self.copayersBIP32[j].extendedPublicKeyString() === epk) {
|
||||
haveIt=true;
|
||||
|
|
@ -316,6 +312,10 @@ PublicKeyRing.prototype._mergePubkeys = function(inPKR) {
|
|||
}
|
||||
}
|
||||
if (!haveIt) {
|
||||
if (self.isComplete()) {
|
||||
console.log('[PublicKeyRing.js.318] REPEATED KEY', epk); //TODO
|
||||
throw new Error('trying to add more pubkeys, when PKR isComplete at merge');
|
||||
}
|
||||
self.copayersBIP32.push(new BIP32(epk));
|
||||
hasChanged=true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ module.exports = require('soop')(TxProposal);
|
|||
|
||||
function TxProposals(opts) {
|
||||
opts = opts || {};
|
||||
this.walletId = opts.walletId;
|
||||
this.network = opts.networkName === 'livenet' ?
|
||||
bitcore.networks.livenet : bitcore.networks.testnet;
|
||||
this.publicKeyRing = opts.publicKeyRing;
|
||||
|
|
@ -32,10 +33,11 @@ function TxProposals(opts) {
|
|||
TxProposals.fromObj = function(o) {
|
||||
var ret = new TxProposals({
|
||||
networkName: o.networkName,
|
||||
walletId: o.walletId,
|
||||
});
|
||||
o.txps.forEach(function(t) {
|
||||
var tx = new Transaction;
|
||||
tx.parse(t.txHex);
|
||||
tx.parse(new Buffer(t.txHex,'hex'));
|
||||
ret.txps.push({
|
||||
seenBy: t.seenBy,
|
||||
signedBy: t.signedBy,
|
||||
|
|
@ -45,6 +47,7 @@ TxProposals.fromObj = function(o) {
|
|||
return ret;
|
||||
};
|
||||
|
||||
|
||||
TxProposals.prototype.toObj = function() {
|
||||
var ret = [];
|
||||
this.txps.forEach(function(t) {
|
||||
|
|
@ -56,6 +59,7 @@ TxProposals.prototype.toObj = function() {
|
|||
});
|
||||
return {
|
||||
txps: ret,
|
||||
walletId: this.walletId,
|
||||
networkName: this.network.name,
|
||||
};
|
||||
};
|
||||
|
|
@ -140,7 +144,7 @@ TxProposals.prototype._chunkIsEmpty = function(chunk) {
|
|||
// this assumes that the same signature can not be v0 / v1 (which shouldnt be!)
|
||||
TxProposals.prototype._mergeInputSig = function(s0buf, s1buf) {
|
||||
if (buffertools.compare(s0buf,s1buf) === 0) {
|
||||
console.log('BUFFERS .s MATCH'); //TODO
|
||||
// console.log('BUFFERS .s MATCH'); //TODO
|
||||
return s0buf;
|
||||
}
|
||||
// Is multisig?
|
||||
|
|
@ -225,7 +229,7 @@ TxProposals.prototype._mergeSignatures = function(myTxps, theirTxps, mergeInfo)
|
|||
|
||||
TxProposals.prototype.merge = function(t) {
|
||||
if (this.network.name !== t.network.name)
|
||||
throw new Error('network mismatch');
|
||||
throw new Error('network mismatch in:', t);
|
||||
|
||||
var res = [];
|
||||
|
||||
|
|
@ -244,10 +248,12 @@ TxProposals.prototype.merge = function(t) {
|
|||
return mergeInfo.stats;
|
||||
};
|
||||
|
||||
TxProposals.prototype.create = function(toAddress, amountSat, utxos, priv, opts) {
|
||||
TxProposals.prototype.create = function(toAddress, amountSatStr, utxos, priv, opts) {
|
||||
var pkr = this.publicKeyRing;
|
||||
opts = opts || {};
|
||||
|
||||
var amountSat = bitcore.bignum(amountSatStr);
|
||||
|
||||
if (! pkr.isComplete() ) {
|
||||
throw new Error('publicKeyRing is not complete');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue