mocha tests passing
This commit is contained in:
parent
18ffaa172a
commit
51a42cce8e
4 changed files with 99 additions and 26 deletions
|
|
@ -328,6 +328,8 @@ PublicKeyRing.prototype.copayersForPubkeys = function(pubkeys, paths) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(var i in inKeyMap)
|
||||
throw new Error('Pubkey not identified')
|
||||
|
||||
|
|
|
|||
|
|
@ -86,12 +86,10 @@ TxProposal.prototype._updateSignedBy = function() {
|
|||
for (var i in tx.ins) {
|
||||
var scriptSig = new Script(tx.ins[i].s);
|
||||
var signatureCount = scriptSig.countSignatures();
|
||||
console.log('[TxProposal.js.88:signatureCount:]', i, '#sig:', signatureCount); //TODO
|
||||
|
||||
var info = TxProposal._infoFromRedeemScript(scriptSig);
|
||||
var txSigHash = tx.hashForSignature(info.script, parseInt(i), Transaction.SIGHASH_ALL);
|
||||
var signersPubKey = TxProposal._verifySignatures(info.keys, scriptSig, txSigHash);
|
||||
console.log('[TxProposal.js.94:signersPubKey:]', signersPubKey, signatureCount); //TODO
|
||||
if (signersPubKey.length !== signatureCount)
|
||||
throw new Error('Invalid signature');
|
||||
|
||||
|
|
@ -254,6 +252,7 @@ TxProposal.prototype._allSignatures = function() {
|
|||
|
||||
|
||||
TxProposal.prototype.setCopayers = function(senderId, keyMap, readOnlyPeers) {
|
||||
console.log('[TxProposal.js.256:setCopayers:]'); //TODO
|
||||
var newCopayer = {},
|
||||
oldCopayers = {},
|
||||
newSignedBy = {},
|
||||
|
|
@ -281,6 +280,7 @@ TxProposal.prototype.setCopayers = function(senderId, keyMap, readOnlyPeers) {
|
|||
var iSig = this._inputSigners[0];
|
||||
for (var i in iSig) {
|
||||
var copayerId = keyMap[iSig[i]];
|
||||
|
||||
if (!copayerId)
|
||||
throw new Error('Found unknown signature')
|
||||
|
||||
|
|
|
|||
|
|
@ -173,30 +173,32 @@ txId: ntxid
|
|||
*/
|
||||
Wallet.prototype._getKeyMap = function(txp) {
|
||||
preconditions.checkArgument(txp);
|
||||
console.log('[Wallet.js.175:txp:]',txp); //TODO
|
||||
var inSig0, keyMapAll = {};
|
||||
|
||||
var keyMap = this.publicKeyRing.copayersForPubkeys(txp._inputSigners[0], txp.inputChainPaths);
|
||||
|
||||
var inSig = JSON.stringify(txp._inputSigners[0].sort());
|
||||
|
||||
console.log('[Wallet.js.179:inSig:]',inSig); //TODO
|
||||
|
||||
if (JSON.stringify(Object.keys(keyMap).sort()) !== inSig) {
|
||||
throw new Error('inputSignatures dont match know copayers pubkeys');
|
||||
}
|
||||
|
||||
var keyMapStr = JSON.stringify(keyMap);
|
||||
console.log('[Wallet.js.187:keyMapStr:]',keyMapStr); //TODO
|
||||
// All inputs must be signed with the same copayers
|
||||
for (var i in txp._inputSigners) {
|
||||
console.log('[Wallet.js.190]',i); //TODO
|
||||
var keyMap = this.publicKeyRing.copayersForPubkeys(txp._inputSigners[i], txp.inputChainPaths);
|
||||
|
||||
if (!i) continue;
|
||||
var inSigX = JSON.stringify(txp._inputSigners[i].sort());
|
||||
if (inSigX !== inSig)
|
||||
throw new Error('found inputs with different signatures:');
|
||||
if (Object.keys(keyMap).length !== txp._inputSigners[i].length)
|
||||
throw new Error('Signature does not match known copayers');
|
||||
|
||||
for(var j in keyMap) {
|
||||
keyMapAll[j] = keyMap[j];
|
||||
}
|
||||
|
||||
// From here -> only to check that all inputs have the same sigs
|
||||
var inSigArr = [];
|
||||
Object.keys(keyMap).forEach(function(k){
|
||||
inSigArr.push(keyMap[k]);
|
||||
});
|
||||
var inSig = JSON.stringify(inSigArr.sort());
|
||||
if (i === '0') {
|
||||
inSig0 = inSig;
|
||||
continue;
|
||||
}
|
||||
if (inSig !== inSig0)
|
||||
throw new Error('found inputs with different signatures');
|
||||
}
|
||||
return keyMap;
|
||||
return keyMapAll;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1122,7 +1122,6 @@ describe('Wallet model', function() {
|
|||
it('should throw if unmatched sigs', function() {
|
||||
var stub = sinon.stub(w.publicKeyRing, 'copayersForPubkeys', function() {
|
||||
return {
|
||||
'123': 'juan'
|
||||
};
|
||||
});
|
||||
var txp = {
|
||||
|
|
@ -1133,7 +1132,25 @@ describe('Wallet model', function() {
|
|||
};
|
||||
(function() {
|
||||
w._getKeyMap(txp);
|
||||
}).should.throw('dont match know copayers');
|
||||
}).should.throw('does not match known copayers');
|
||||
stub.restore();
|
||||
});
|
||||
|
||||
it('should throw if unmatched sigs (case 2)', function() {
|
||||
var stub = sinon.stub(w.publicKeyRing, 'copayersForPubkeys', function() {
|
||||
return {
|
||||
};
|
||||
});
|
||||
var txp = {
|
||||
_inputSigners: [
|
||||
['234','321'],
|
||||
['234','322']
|
||||
],
|
||||
inputChainPaths: ['/m/1'],
|
||||
};
|
||||
(function() {
|
||||
w._getKeyMap(txp);
|
||||
}).should.throw('does not match known copayers');
|
||||
stub.restore();
|
||||
});
|
||||
|
||||
|
|
@ -1157,9 +1174,12 @@ describe('Wallet model', function() {
|
|||
stub.restore();
|
||||
});
|
||||
|
||||
it('should throw is one inputs has missing sigs', function() {
|
||||
it('should throw if one inputs has missing sigs', function() {
|
||||
var call=0;
|
||||
var stub = sinon.stub(w.publicKeyRing, 'copayersForPubkeys', function() {
|
||||
return {
|
||||
return call++ ? {
|
||||
'555': 'pepe',
|
||||
}: {
|
||||
'123': 'juan',
|
||||
'234': 'pepe',
|
||||
};
|
||||
|
|
@ -1167,7 +1187,7 @@ describe('Wallet model', function() {
|
|||
var txp = {
|
||||
_inputSigners: [
|
||||
['234', '123'],
|
||||
['234']
|
||||
['555']
|
||||
],
|
||||
inputChainPaths: ['/m/1'],
|
||||
};
|
||||
|
|
@ -1176,6 +1196,55 @@ describe('Wallet model', function() {
|
|||
}).should.throw('different sig');
|
||||
stub.restore();
|
||||
});
|
||||
|
||||
|
||||
it('should throw if one inputs has different sigs', function() {
|
||||
var call=0;
|
||||
var stub = sinon.stub(w.publicKeyRing, 'copayersForPubkeys', function() {
|
||||
return call++ ? {
|
||||
'555': 'pepe',
|
||||
'666': 'pedro',
|
||||
}: {
|
||||
'123': 'juan',
|
||||
'234': 'pepe',
|
||||
};
|
||||
});
|
||||
var txp = {
|
||||
_inputSigners: [
|
||||
['234', '123'],
|
||||
['555', '666']
|
||||
],
|
||||
inputChainPaths: ['/m/1'],
|
||||
};
|
||||
(function() {
|
||||
w._getKeyMap(txp);
|
||||
}).should.throw('different sig');
|
||||
stub.restore();
|
||||
});
|
||||
|
||||
|
||||
it('should not throw if 2 inputs has different pubs, same copayers', function() {
|
||||
var call=0;
|
||||
var stub = sinon.stub(w.publicKeyRing, 'copayersForPubkeys', function() {
|
||||
return call++ ? {
|
||||
'555': 'pepe',
|
||||
'666': 'pedro',
|
||||
}: {
|
||||
'123': 'pedro',
|
||||
'234': 'pepe',
|
||||
};
|
||||
});
|
||||
var txp = {
|
||||
_inputSigners: [
|
||||
['234', '123'],
|
||||
['555', '666']
|
||||
],
|
||||
inputChainPaths: ['/m/1'],
|
||||
};
|
||||
var gk = w._getKeyMap(txp);
|
||||
gk.should.deep.equal({ '123': 'pedro', '234': 'pepe', '555': 'pepe', '666': 'pedro' });
|
||||
stub.restore();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue