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

View file

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

View file

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

View file

@ -91,6 +91,21 @@ describe('TxProposal', function() {
should.not.exist(o.builder); should.not.exist(o.builder);
should.exist(o.builderObj); should.exist(o.builderObj);
}); });
it('toObjTrim', function() {
var b = new FakeBuilder();
var txp = new TxProposal({
creator: 1,
createdTs: 1,
builder: b,
inputChainPaths: 'm/1',
});
var o = txp.toObjTrim();
should.exist(o);
should.not.exist(o.creator);
should.not.exist(o.builder);
should.exist(o.builderObj);
});
}); });
describe('#fromObj', function() { describe('#fromObj', function() {
it.skip('should create from Object', function() { it.skip('should create from Object', function() {
@ -309,7 +324,8 @@ describe('TxProposal', function() {
}).should.throw('unknown sig'); }).should.throw('unknown sig');
}); });
it("should be signed by sender", function() { // This was disabled. Unnecessary to check this.
it.skip("should be signed by sender", function() {
var txp = dummyProposal; var txp = dummyProposal;
var ts = Date.now(); var ts = Date.now();
txp._inputSignatures = [ txp._inputSignatures = [

View file

@ -440,19 +440,7 @@ describe('Wallet model', function() {
var w = createW(); var w = createW();
var txp = { var txp = {
'txProposal': { 'txProposal': {
creator: '02c643ef43c14481fa8e81e61438c2cbc39a59024663f8cab575d28a248fe53d96', inputChainPaths: ['m/1'],
createdTs: '2014-07-24T23:54:26.682Z',
seenBy: {
'02c643ef43c14481fa8e81e61438c2cbc39a59024663f8cab575d28a248fe53d96': 1406246066682
},
signedBy: {
'02c643ef43c14481fa8e81e61438c2cbc39a59024663f8cab575d28a248fe53d96': 1406246066682
},
rejectedBy: {},
sentTs: null,
sentTxid: null,
inputChainPaths: ['m/45\'/2/0/0'],
comment: null,
builderObj: { builderObj: {
version: 1, version: 1,
outs: [{ outs: [{
@ -480,9 +468,13 @@ describe('Wallet model', function() {
} }
}; };
var stub = sinon.stub(w.publicKeyRing,'copayersForPubkeys').returns(
{'027445ab3a935dce7aee1dadb0d103ed6147a0f83deb80474a04538b2c5bc4d509':'pepe'}
);
w._handleTxProposal('senderID', txp, true); w._handleTxProposal('senderID', txp, true);
Object.keys(w.txProposals.txps).length.should.equal(1); Object.keys(w.txProposals.txps).length.should.equal(1);
w.getTxProposals().length.should.equal(1); w.getTxProposals().length.should.equal(1);
//stub.restore();
}); });
var newId = '00bacacafe'; var newId = '00bacacafe';
@ -1054,7 +1046,7 @@ describe('Wallet model', function() {
_inputSignatures: [ _inputSignatures: [
['123'] ['123']
], ],
paths: ['/m/1'], inputChainPaths: ['/m/1'],
}; };
var map = w._getKeyMap(txp); var map = w._getKeyMap(txp);
Object.keys(map).length.should.equal(1); Object.keys(map).length.should.equal(1);
@ -1072,7 +1064,7 @@ describe('Wallet model', function() {
_inputSignatures: [ _inputSignatures: [
['234'] ['234']
], ],
paths: ['/m/1'], inputChainPaths: ['/m/1'],
}; };
(function() { (function() {
w._getKeyMap(txp); w._getKeyMap(txp);
@ -1091,7 +1083,7 @@ describe('Wallet model', function() {
_inputSignatures: [ _inputSignatures: [
['234', '123'] ['234', '123']
], ],
paths: ['/m/1'], inputChainPaths: ['/m/1'],
}; };
var map = w._getKeyMap(txp); var map = w._getKeyMap(txp);
Object.keys(map).length.should.equal(2); Object.keys(map).length.should.equal(2);
@ -1112,7 +1104,7 @@ describe('Wallet model', function() {
['234', '123'], ['234', '123'],
['234'] ['234']
], ],
paths: ['/m/1'], inputChainPaths: ['/m/1'],
}; };
(function() { (function() {
w._getKeyMap(txp); w._getKeyMap(txp);
@ -1194,18 +1186,18 @@ describe('Wallet model', function() {
}); });
it('should reject a tx', function() { it('should reject a tx', function() {
var w = cachedCreateW(); var w = cachedCreateW();
function txp() { function txp() {
this.ok=0; this.ok = 0;
this.signedBy = {}; this.signedBy = {};
}; };
txp.prototype.setRejected = function() { txp.prototype.setRejected = function() {
this.ok=1; this.ok = 1;
};
txp.prototype.toObj = function() {
}; };
txp.prototype.toObj = function() {};
var spy1 = sinon.spy(w,'store'); var spy1 = sinon.spy(w, 'store');
var spy2 = sinon.spy(w,'emit'); var spy2 = sinon.spy(w, 'emit');
w.txProposals.txps['qwerty'] = new txp(); w.txProposals.txps['qwerty'] = new txp();
w.txProposals.txps['qwerty'].ok.should.equal(0); w.txProposals.txps['qwerty'].ok.should.equal(0);
w._handleReject('john', { w._handleReject('john', {
@ -1215,8 +1207,8 @@ describe('Wallet model', function() {
spy1.calledOnce.should.equal(true); spy1.calledOnce.should.equal(true);
spy2.callCount.should.equal(2); spy2.callCount.should.equal(2);
spy2.firstCall.args.should.deep.equal(['txProposalsUpdated']); spy2.firstCall.args.should.deep.equal(['txProposalsUpdated']);
spy2.secondCall.args.should.deep.equal(['txProposalEvent',{ spy2.secondCall.args.should.deep.equal(['txProposalEvent', {
type:'rejected', type: 'rejected',
cId: 'john', cId: 'john',
txId: 'qwerty', txId: 'qwerty',
}]); }]);
@ -1235,18 +1227,18 @@ describe('Wallet model', function() {
}); });
it('should set seen a tx', function() { it('should set seen a tx', function() {
var w = cachedCreateW(); var w = cachedCreateW();
function txp() { function txp() {
this.ok=0; this.ok = 0;
this.signedBy = {}; this.signedBy = {};
}; };
txp.prototype.setSeen = function() { txp.prototype.setSeen = function() {
this.ok=1; this.ok = 1;
};
txp.prototype.toObj = function() {
}; };
txp.prototype.toObj = function() {};
var spy1 = sinon.spy(w,'store'); var spy1 = sinon.spy(w, 'store');
var spy2 = sinon.spy(w,'emit'); var spy2 = sinon.spy(w, 'emit');
w.txProposals.txps['qwerty'] = new txp(); w.txProposals.txps['qwerty'] = new txp();
w.txProposals.txps['qwerty'].ok.should.equal(0); w.txProposals.txps['qwerty'].ok.should.equal(0);
w._handleSeen('john', { w._handleSeen('john', {
@ -1256,8 +1248,8 @@ describe('Wallet model', function() {
spy1.calledOnce.should.equal(true); spy1.calledOnce.should.equal(true);
spy2.callCount.should.equal(2); spy2.callCount.should.equal(2);
spy2.firstCall.args.should.deep.equal(['txProposalsUpdated']); spy2.firstCall.args.should.deep.equal(['txProposalsUpdated']);
spy2.secondCall.args.should.deep.equal(['txProposalEvent',{ spy2.secondCall.args.should.deep.equal(['txProposalEvent', {
type:'seen', type: 'seen',
cId: 'john', cId: 'john',
txId: 'qwerty', txId: 'qwerty',
}]); }]);
@ -1273,7 +1265,7 @@ describe('Wallet model', function() {
it('#disconnect', function() { it('#disconnect', function() {
var w = cachedCreateW(); var w = cachedCreateW();
var spy1 = sinon.spy(w.network,'disconnect'); var spy1 = sinon.spy(w.network, 'disconnect');
w.disconnect(); w.disconnect();
spy1.callCount.should.equal(1); spy1.callCount.should.equal(1);
}); });