UNPKG

@node-dlc/bitcoin

Version:
111 lines (110 loc) 4.23 kB
/// <reference types="node" /> import { LockTime } from './LockTime'; import { OutPoint } from './OutPoint'; import { Script } from './Script'; import { Sequence } from './Sequence'; import { Tx } from './Tx'; import { TxIn } from './TxIn'; import { TxOut } from './TxOut'; import { Value } from './Value'; export declare class TxBuilder { private _version; private _locktime; private _inputs; private _outputs; private _hashPrevOuts; private _hashSequence; private _hashOutputs; constructor(); /** * Gets or sets the transaction version. Valid transaction versions * are > 1. */ get version(): number; set version(val: number); /** * Gets or sets the absolute locktime for the transaction */ get locktime(): LockTime; set locktime(val: LockTime); /** * Gets the inputs */ get inputs(): TxIn[]; /** * Gets the outputs */ get outputs(): TxOut[]; /** * Adds a new transaction input * @param outpoint the previous output represented as an outpoint */ addInput(outpoint: TxIn | string | OutPoint, sequence?: Sequence): void; /** * Adds a transaction output * @param value value sent to the lock script. When represented as a * number, the value is in Bitcoin. * @param scriptPubKey the locking script encumbering the funds send * to this output */ addOutput(value: TxOut | number | Value, scriptPubKey?: Script): void; /** * Creates a signature hash including all inputs and all outputs, * which is referred to as SIGHASH_ALL. The scriptSig of all inputs * is removed (as it is never signed), however we commit to the * signatory input using the scriptPubKey from the prevOut or the * redeemScript. The hash is constructed as the serialization of * all information (with the input scriptSig replaced as just * described) and then appending a 4-byte LE sighash type. We then * take the hash256 of that serialized transaction. * * @param input signatory input index * @param commitScript the scriptSig used for the signature input */ hashLegacy(input: number, commitScript: Script): Buffer; /** * Creates a signature hash using the new segregated witness digets * alorithm defined in BIP143. The current version only supports * SIGHASH_ALL and does not account for OP_CODESEPARATOR. * * This algorithm has side-effects in that it caches hashPrevOut, * hashSequence, and hashOutput values used. This means transaction * should not change after signing, though the code does not yet * enforce this. * * @param index signatory input index * @param commitScript the scriptSig used for the signature input * @param value the value of the input */ hashSegwitv0(index: number, commitScript: Script, value: Value): Buffer; /** * Signs an input and returns the DER encoded signature. The * script that is committed to will depend on the type of the * signature. This is usually the locking script used in the prior * output, but in the case of p2sh transactions, this is the * redeem script, or the underlying script that is hashed in the * prior output. * * @param input index of input that should be signed * @param commitScript Script that is committed during signature * @param privateKey 32-byte private key */ sign(input: number, commitScript: Script, privateKey: Buffer): Buffer; /** * Signs an SegWit v0 input and returns the DER encoded signature. * The script that is committed to will depend on the type of the * input. This is usually the locking script or redeem script. * * @param input index of input that should be signed * @param commitScript Script that is committed during signature * @param privateKey 32-byte private key * @param value value of the prior input */ signSegWitv0(input: number, commitScript: Script, privateKey: Buffer, value: Value): Buffer; /** * Returns an immutable transaction */ toTx(): Tx; serialize(): Buffer; toHex(pretty?: boolean): string; }