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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue