UNPKG

2.35 kBTypeScriptView Raw
1/// <reference types="node" />
2export interface Output {
3 script: Buffer;
4 value: number;
5}
6export interface Input {
7 hash: Buffer;
8 index: number;
9 script: Buffer;
10 sequence: number;
11 witness: Buffer[];
12}
13/**
14 * Represents a Bitcoin transaction.
15 */
16export declare class Transaction {
17 static readonly DEFAULT_SEQUENCE = 4294967295;
18 static readonly SIGHASH_DEFAULT = 0;
19 static readonly SIGHASH_ALL = 1;
20 static readonly SIGHASH_NONE = 2;
21 static readonly SIGHASH_SINGLE = 3;
22 static readonly SIGHASH_ANYONECANPAY = 128;
23 static readonly SIGHASH_OUTPUT_MASK = 3;
24 static readonly SIGHASH_INPUT_MASK = 128;
25 static readonly ADVANCED_TRANSACTION_MARKER = 0;
26 static readonly ADVANCED_TRANSACTION_FLAG = 1;
27 static fromBuffer(buffer: Buffer, _NO_STRICT?: boolean): Transaction;
28 static fromHex(hex: string): Transaction;
29 static isCoinbaseHash(buffer: Buffer): boolean;
30 version: number;
31 locktime: number;
32 ins: Input[];
33 outs: Output[];
34 isCoinbase(): boolean;
35 addInput(hash: Buffer, index: number, sequence?: number, scriptSig?: Buffer): number;
36 addOutput(scriptPubKey: Buffer, value: number): number;
37 hasWitnesses(): boolean;
38 stripWitnesses(): void;
39 weight(): number;
40 virtualSize(): number;
41 byteLength(_ALLOW_WITNESS?: boolean): number;
42 clone(): Transaction;
43 /**
44 * Hash transaction for signing a specific input.
45 *
46 * Bitcoin uses a different hash for each signed transaction input.
47 * This method copies the transaction, makes the necessary changes based on the
48 * hashType, and then hashes the result.
49 * This hash can then be used to sign the provided transaction input.
50 */
51 hashForSignature(inIndex: number, prevOutScript: Buffer, hashType: number): Buffer;
52 hashForWitnessV1(inIndex: number, prevOutScripts: Buffer[], values: number[], hashType: number, leafHash?: Buffer, annex?: Buffer): Buffer;
53 hashForWitnessV0(inIndex: number, prevOutScript: Buffer, value: number, hashType: number): Buffer;
54 getHash(forWitness?: boolean): Buffer;
55 getId(): string;
56 toBuffer(buffer?: Buffer, initialOffset?: number): Buffer;
57 toHex(): string;
58 setInputScript(index: number, scriptSig: Buffer): void;
59 setWitness(index: number, witness: Buffer[]): void;
60 private __toBuffer;
61}