diff --git a/lib/bcoin/wallet.js b/lib/bcoin/wallet.js index ffab83e2..063b0194 100644 --- a/lib/bcoin/wallet.js +++ b/lib/bcoin/wallet.js @@ -283,9 +283,18 @@ Wallet.prototype.sign = function sign(tx, type, inputs, off) { if (!input.out.tx || !this.ownOutput(input.out.tx)) return false; + // Get the previous output's subscript var s = input.out.tx.getSubscript(input.out.index); + + // Get the hash of the current tx, minus the other inputs, plus the sighash. + // `off` is used here in a case where we have multiple wallet objects + // signing the same tx. var hash = tx.subscriptHash(off + i, s, type); + + // Sign the transaction with our one input var signature = bcoin.ecdsa.sign(hash, this.key).toDER(); + + // Add the sighash as a single byte to the signature signature = signature.concat(bcoin.protocol.constants.hashType[type]); // P2PKH and simple tx