remove sender sig check

This commit is contained in:
Matias Alejo Garcia 2014-08-04 17:12:53 -03:00
commit 91829f8410
5 changed files with 90 additions and 63 deletions

View file

@ -285,6 +285,7 @@ PublicKeyRing.prototype.getForPath = function(path) {
};
PublicKeyRing.prototype.getForPaths = function(paths) {
preconditions.checkArgument(paths);
return paths.map(this.getForPath.bind(this));
};
@ -299,6 +300,8 @@ PublicKeyRing.prototype.forPaths = function(paths) {
// returns pubkey -> copayerId.
PublicKeyRing.prototype.copayersForPubkeys = function(pubkeys, paths) {
preconditions.checkArgument(pubkeys);
preconditions.checkArgument(paths);
var inKeyMap = {}, ret = {};
for(var i in pubkeys ){

View file

@ -134,9 +134,12 @@ TxProposal.fromObj = function(o, forceOpts) {
};
TxProposal.fromUntrustedObj = function(o, forceOpts) {
return TxProposal.fromObj(TxProposal._trim(o),forceOpts);
return TxProposal.fromObj(TxProposal._trim(o), forceOpts);
};
TxProposal.prototype.toObjTrim = function() {
return TxProposal._trim(this.toObj());
};
TxProposal._formatKeys = function(keys) {
var ret = [];
@ -234,21 +237,31 @@ TxProposal.prototype._allSignatures = function() {
TxProposal.prototype.setCopayers = function(senderId, keyMap, readOnlyPeers) {
var newCopayer = {},
oldCopayers = {}, newSignedBy = {}, readOnlyPeers = {}, isNew = 1;
oldCopayers = {},
newSignedBy = {},
readOnlyPeers = {},
isNew = 1;
for(var k in this.signedBy) {
for (var k in this.signedBy) {
oldCopayers[k] = 1;
isNew = 0;
};
if (isNew == 0 && (!this.creator || !this.createdTs))
throw new Error('Existing TX has no creator');
if (isNew == 0) {
if (!this.creator || !this.createdTs)
throw new Error('Existing TX has no creator');
if (!this.signedBy[this.creator])
throw new Error('Existing TX is not signed by creator');
if (Object.keys(this.signedBy).length === 0)
throw new Error('Existing TX has no signatures');
}
if (isNew == 0 && (!this.signedBy[this.creator]))
throw new Error('Existing TX is not signed by creator');
var iSig = this._inputSignatures[0];
for(var i in iSig){
for (var i in iSig) {
var copayerId = keyMap[iSig[i]];
if (!copayerId)
throw new Error('Found unknown signature')
@ -256,15 +269,16 @@ TxProposal.prototype.setCopayers = function(senderId, keyMap, readOnlyPeers) {
if (oldCopayers[copayerId]) {
//Already have it. Do nothing
} else {
newCopayer[copayerId] = Date.now();
newCopayer[copayerId] = Date.now();
delete oldCopayers[i];
}
}
if (!newCopayer[senderId] && !readOnlyPeers[senderId])
throw new Error('TX must have a (new) senders signature')
// Seems unncessary to check this:
// if (!newCopayer[senderId] && !readOnlyPeers[senderId])
// throw new Error('TX must have a (new) senders signature')
if (Object.keys(newCopayer).length>1)
if (Object.keys(newCopayer).length > 1)
throw new Error('New TX must have only 1 new signature');
// Handler creator / createdTs.
@ -272,16 +286,16 @@ TxProposal.prototype.setCopayers = function(senderId, keyMap, readOnlyPeers) {
if (isNew) {
this.creator = Object.keys(newCopayer)[0];
this.seenBy[this.creator] = this.createdTs = Date.now();
}
}
//Ended. Update this.
for(var i in newCopayer) {
for (var i in newCopayer) {
this.signedBy[i] = newCopayer[i];
}
// signedBy has preference over rejectedBy
for(var i in this.signedBy) {
delete this.rejectedBy[i];
for (var i in this.signedBy) {
delete this.rejectedBy[i];
}
return Object.keys(newCopayer);

View file

@ -165,8 +165,9 @@ txId: ntxid
});
*/
Wallet.prototype._getKeyMap = function(txp) {
preconditions.checkArgument(txp);
var keyMap = this.publicKeyRing.copayersForPubkeys(txp._inputSignatures[0], txp.paths);
var keyMap = this.publicKeyRing.copayersForPubkeys(txp._inputSignatures[0], txp.inputChainPaths);
var inSig = JSON.stringify(txp._inputSignatures[0].sort());
@ -191,12 +192,12 @@ Wallet.prototype._handleTxProposal = function(senderId, data) {
var m;
try {
m = this.txProposals.merge(data.txProposal, Wallet.builderOpts);
var keyMap = this._getKeyMap(m.tpx);
ret.newCopayer = m.txp.setCopayers(senderId, keyMap);
m = this.txProposals.merge(data.txProposal, Wallet.builderOpts);
var keyMap = this._getKeyMap(m.txp);
ret.newCopayer = m.txp.setCopayers(senderId, keyMap);
} catch (e) {
this.log('Corrupt TX proposal received', senderId, e);
this.log('Corrupt TX proposal received from:', senderId, e);
}
if (m) {
@ -524,10 +525,11 @@ Wallet.prototype.sendAllTxProposals = function(recipients) {
Wallet.prototype.sendTxProposal = function(ntxid, recipients) {
preconditions.checkArgument(ntxid);
preconditions.checkState(this.txProposals.txps[ntxid]);
this.log('### SENDING txProposal ' + ntxid + ' TO:', recipients || 'All', this.txProposals);
this.send(recipients, {
type: 'txProposal',
txProposal: this.txProposals.txps[ntxid].toObj(),
txProposal: this.txProposals.txps[ntxid].toObjTrim(),
walletId: this.id,
});
};