#
sign
Signs a Bitcoin transaction. Options can be passed in that determine which inputs to sign, the sigHash type to use, and which script to use.
#
Type
(
tx: BitcoinLib.Transaction,
opts: {
inputIndex?: number
sighashType?: number
inputScript?: Buffer
}
) => void
#
Syntax
computer.sign(tx, opts)
#
Parameters
#
tx
A Bitcoin transaction, possibly partially signed.
#
opts
An object with specific parameters to use when signing
#
Return value
By default, the sign
function will make a best effort to sign all inputs, but will not throw an error if the signature cannot be added due to hash mismatch.
This is useful in the case of partially signed transactions, where a user can encode an expression, sign with the user private key and send the generated partially signed transaction to another user. Then, the receiver can sign other inputs.
#
Examples
class C extends Contract {}
const tx = await computer.encode({
exp: `${C} new ${C.name}()`
sign: false
})
await computer.fund(tx)
computer.sign(tx)