fix signature for nreq>2
This commit is contained in:
parent
7d608c254f
commit
cf2e13fc62
3 changed files with 24 additions and 9 deletions
|
|
@ -233,6 +233,7 @@ TxProposal.prototype._addSignatureAndVerify = function(signatures) {
|
||||||
var ret = [];
|
var ret = [];
|
||||||
var tx = self.builder.build();
|
var tx = self.builder.build();
|
||||||
|
|
||||||
|
var inputsFullySigned = 0;
|
||||||
var newScriptSigs = [];
|
var newScriptSigs = [];
|
||||||
_.each(tx.ins, function(input, index) {
|
_.each(tx.ins, function(input, index) {
|
||||||
var scriptSig = new Script(input.s);
|
var scriptSig = new Script(input.s);
|
||||||
|
|
@ -268,14 +269,16 @@ TxProposal.prototype._addSignatureAndVerify = function(signatures) {
|
||||||
});
|
});
|
||||||
|
|
||||||
var insertAt = 0;
|
var insertAt = 0;
|
||||||
while ( !_.isUndefined(currentPrios[insertAt]) && prio > currentPrios[insertAt] )
|
while (!_.isUndefined(currentPrios[insertAt]) && prio > currentPrios[insertAt])
|
||||||
insertAt++;
|
insertAt++;
|
||||||
|
|
||||||
// Insert it! (1 is OP_0!)
|
// Insert it! (1 is OP_0!)
|
||||||
scriptSig.chunks.splice(1 + insertAt, 0, sig);
|
scriptSig.chunks.splice(1 + insertAt, 0, sig);
|
||||||
scriptSig.updateBuffer();
|
scriptSig.updateBuffer();
|
||||||
|
|
||||||
|
if (info.nreq == currentKeys.length + 1) {
|
||||||
|
inputsFullySigned++;
|
||||||
|
}
|
||||||
newScriptSigs.push(scriptSig.buffer);
|
newScriptSigs.push(scriptSig.buffer);
|
||||||
});
|
});
|
||||||
preconditions.checkState(newScriptSigs.length === tx.ins.length);
|
preconditions.checkState(newScriptSigs.length === tx.ins.length);
|
||||||
|
|
@ -284,9 +287,11 @@ TxProposal.prototype._addSignatureAndVerify = function(signatures) {
|
||||||
_.each(tx.ins, function(input, index) {
|
_.each(tx.ins, function(input, index) {
|
||||||
input.s = newScriptSigs[index];
|
input.s = newScriptSigs[index];
|
||||||
|
|
||||||
// TODO just to keep TransactionBuilder
|
// just to keep TransactionBuilder updated
|
||||||
self.builder.inputsSigned++;
|
if (tx.ins.length == inputsFullySigned)
|
||||||
|
self.builder.inputsSigned++;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.resetCache();
|
this.resetCache();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -312,9 +317,9 @@ TxProposal.prototype.addSignature = function(copayerId, signatures) {
|
||||||
preconditions.checkArgument(signatures.length === tx.ins.length, 'Wrong number of signatures given');
|
preconditions.checkArgument(signatures.length === tx.ins.length, 'Wrong number of signatures given');
|
||||||
|
|
||||||
this._addSignatureAndVerify(signatures);
|
this._addSignatureAndVerify(signatures);
|
||||||
this._setSigned(copayerId);
|
|
||||||
|
|
||||||
return false;
|
this._setSigned(copayerId);
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -508,11 +513,13 @@ TxProposal.infoFromRedeemScript = function(s) {
|
||||||
if (!redeemScript)
|
if (!redeemScript)
|
||||||
throw new Error('Bad scriptSig (no redeemscript)');
|
throw new Error('Bad scriptSig (no redeemscript)');
|
||||||
|
|
||||||
|
var nreq = nreq = redeemScript.chunks[0] - 80; //see OP_2-OP_16
|
||||||
var pubkeys = redeemScript.capture();
|
var pubkeys = redeemScript.capture();
|
||||||
if (!pubkeys || !pubkeys.length)
|
if (!pubkeys || !pubkeys.length)
|
||||||
throw new Error('Bad scriptSig (no pubkeys)');
|
throw new Error('Bad scriptSig (no pubkeys)');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
nreq: nreq,
|
||||||
keys: pubkeys,
|
keys: pubkeys,
|
||||||
script: redeemScript,
|
script: redeemScript,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -499,7 +499,8 @@ Wallet.prototype._processIncomingNewTxProposal = function(txp, cb) {
|
||||||
self._processTxProposalPayPro(txp, function(err) {
|
self._processTxProposalPayPro(txp, function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
||||||
self._setTxProposalSeen(txp);
|
// Disabled, not been shown on the UX now.
|
||||||
|
//self._setTxProposalSeen(txp);
|
||||||
|
|
||||||
var tx = txp.builder.build();
|
var tx = txp.builder.build();
|
||||||
if (tx.isComplete() && !txp.getSent())
|
if (tx.isComplete() && !txp.getSent())
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@ describe('TxProposal', function() {
|
||||||
amountSatStr: '123',
|
amountSatStr: '123',
|
||||||
}]),
|
}]),
|
||||||
};
|
};
|
||||||
|
builder.inputsSigned =0;
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
};
|
};
|
||||||
|
|
@ -338,6 +339,7 @@ describe('TxProposal', function() {
|
||||||
sigs[0][1].should.equal(SIG1);
|
sigs[0][1].should.equal(SIG1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#addSignature', function() {
|
describe('#addSignature', function() {
|
||||||
it('should add signatures maintaing pubkeys order', function() {
|
it('should add signatures maintaing pubkeys order', function() {
|
||||||
var txp = dummyProposal({
|
var txp = dummyProposal({
|
||||||
|
|
@ -353,8 +355,13 @@ describe('TxProposal', function() {
|
||||||
keysSorted.should.deep.equal(keys);
|
keysSorted.should.deep.equal(keys);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
it('should add signatures to incomplete txs ', function() {
|
||||||
|
var txp = dummyProposal({
|
||||||
|
nsig:1
|
||||||
|
});
|
||||||
|
txp.addSignature('pepe', [SIG1]);
|
||||||
|
txp.builder.inputsSigned.should.be.equal(0);
|
||||||
|
});
|
||||||
|
|
||||||
it('should fail with invalid signatures', function() {
|
it('should fail with invalid signatures', function() {
|
||||||
var txp = dummyProposal({
|
var txp = dummyProposal({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue