comments explaining signing logic.

This commit is contained in:
Christopher Jeffrey 2015-12-05 00:02:23 -08:00
parent acbe4d0c2e
commit 1d210589c5

View File

@ -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