From 28abd09845d6d20e720a39123204ce17c28b4e75 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 6 Jun 2014 03:10:21 -0500 Subject: [PATCH] wallet: allow inputs and offset to be passed into wallet.sign. --- lib/bcoin/wallet.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/bcoin/wallet.js b/lib/bcoin/wallet.js index 6051fdc1..cd4106c3 100644 --- a/lib/bcoin/wallet.js +++ b/lib/bcoin/wallet.js @@ -207,13 +207,16 @@ Wallet.prototype.ownInput = function ownInput(tx, index) { return inputs; }; -Wallet.prototype.sign = function sign(tx, type) { +Wallet.prototype.sign = function sign(tx, type, inputs, off) { if (!type) type = 'all'; assert.equal(type, 'all'); + if (!off) + off = 0; + // Filter inputs that this wallet own - var inputs = tx.inputs.filter(function(input) { + var inputs = inputs || tx.inputs.filter(function(input) { return input.out.tx && this.ownOutput(input.out.tx); }, this); var pub = this.getPublicKey(); @@ -221,7 +224,7 @@ Wallet.prototype.sign = function sign(tx, type) { // Add signature script to each input inputs.forEach(function(input, i) { var s = input.out.tx.getSubscript(input.out.index); - var hash = tx.subscriptHash(i, s, type); + var hash = tx.subscriptHash(off + i, s, type); var signature = bcoin.ecdsa.sign(hash, this.key).toDER(); signature = signature.concat(bcoin.protocol.constants.hashType[type]);