From ac60920f985eaef2cd25775c67e4adcec17f987f Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 6 Jun 2014 12:26:24 -0500 Subject: [PATCH] fix: keep track of the input index better for subscript hashing. --- lib/bcoin/wallet.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/bcoin/wallet.js b/lib/bcoin/wallet.js index cd4106c3..15cb69ce 100644 --- a/lib/bcoin/wallet.js +++ b/lib/bcoin/wallet.js @@ -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();