fix: keep track of the input index better for subscript hashing.

This commit is contained in:
Christopher Jeffrey 2014-06-06 12:26:24 -05:00
parent 11b56e32d7
commit ac60920f98

View File

@ -215,14 +215,15 @@ Wallet.prototype.sign = function sign(tx, type, inputs, off) {
if (!off)
off = 0;
// Filter inputs that this wallet own
var inputs = inputs || tx.inputs.filter(function(input) {
return input.out.tx && this.ownOutput(input.out.tx);
}, this);
var pub = this.getPublicKey();
inputs = inputs || tx.inputs;
// Add signature script to each input
inputs.forEach(function(input, i) {
// Filter inputs that this wallet own
if (!input.out.tx || !this.ownOutput(input.out.tx))
return;
var s = input.out.tx.getSubscript(input.out.index);
var hash = tx.subscriptHash(off + i, s, type);
var signature = bcoin.ecdsa.sign(hash, this.key).toDER();