1 |
|
2 | import { Psbt as PsbtBase } from 'bip174';
|
3 | import { KeyValue, PsbtGlobalUpdate, PsbtInput, PsbtInputUpdate, PsbtOutput, PsbtOutputUpdate } from 'bip174/src/lib/interfaces';
|
4 | import { Network } from './networks';
|
5 | import { Transaction } from './transaction';
|
6 | export interface TransactionInput {
|
7 | hash: string | Buffer;
|
8 | index: number;
|
9 | sequence?: number;
|
10 | }
|
11 | export interface PsbtTxInput extends TransactionInput {
|
12 | hash: Buffer;
|
13 | }
|
14 | export interface TransactionOutput {
|
15 | script: Buffer;
|
16 | value: number;
|
17 | }
|
18 | export interface PsbtTxOutput extends TransactionOutput {
|
19 | address: string | undefined;
|
20 | }
|
21 | export type ValidateSigFunction = (pubkey: Buffer, msghash: Buffer, signature: Buffer) => boolean;
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | export declare class Psbt {
|
55 | readonly data: PsbtBase;
|
56 | static fromBase64(data: string, opts?: PsbtOptsOptional): Psbt;
|
57 | static fromHex(data: string, opts?: PsbtOptsOptional): Psbt;
|
58 | static fromBuffer(buffer: Buffer, opts?: PsbtOptsOptional): Psbt;
|
59 | private __CACHE;
|
60 | private opts;
|
61 | constructor(opts?: PsbtOptsOptional, data?: PsbtBase);
|
62 | get inputCount(): number;
|
63 | get version(): number;
|
64 | set version(version: number);
|
65 | get locktime(): number;
|
66 | set locktime(locktime: number);
|
67 | get txInputs(): PsbtTxInput[];
|
68 | get txOutputs(): PsbtTxOutput[];
|
69 | combine(...those: Psbt[]): this;
|
70 | clone(): Psbt;
|
71 | setMaximumFeeRate(satoshiPerByte: number): void;
|
72 | setVersion(version: number): this;
|
73 | setLocktime(locktime: number): this;
|
74 | setInputSequence(inputIndex: number, sequence: number): this;
|
75 | addInputs(inputDatas: PsbtInputExtended[]): this;
|
76 | addInput(inputData: PsbtInputExtended): this;
|
77 | addOutputs(outputDatas: PsbtOutputExtended[]): this;
|
78 | addOutput(outputData: PsbtOutputExtended): this;
|
79 | extractTransaction(disableFeeCheck?: boolean): Transaction;
|
80 | getFeeRate(): number;
|
81 | getFee(): number;
|
82 | finalizeAllInputs(): this;
|
83 | finalizeInput(inputIndex: number, finalScriptsFunc?: FinalScriptsFunc | FinalTaprootScriptsFunc): this;
|
84 | finalizeTaprootInput(inputIndex: number, tapLeafHashToFinalize?: Buffer, finalScriptsFunc?: FinalTaprootScriptsFunc): this;
|
85 | private _finalizeInput;
|
86 | private _finalizeTaprootInput;
|
87 | getInputType(inputIndex: number): AllScriptType;
|
88 | inputHasPubkey(inputIndex: number, pubkey: Buffer): boolean;
|
89 | inputHasHDKey(inputIndex: number, root: HDSigner): boolean;
|
90 | outputHasPubkey(outputIndex: number, pubkey: Buffer): boolean;
|
91 | outputHasHDKey(outputIndex: number, root: HDSigner): boolean;
|
92 | validateSignaturesOfAllInputs(validator: ValidateSigFunction): boolean;
|
93 | validateSignaturesOfInput(inputIndex: number, validator: ValidateSigFunction, pubkey?: Buffer): boolean;
|
94 | private _validateSignaturesOfInput;
|
95 | private validateSignaturesOfTaprootInput;
|
96 | signAllInputsHD(hdKeyPair: HDSigner, sighashTypes?: number[]): this;
|
97 | signAllInputsHDAsync(hdKeyPair: HDSigner | HDSignerAsync, sighashTypes?: number[]): Promise<void>;
|
98 | signInputHD(inputIndex: number, hdKeyPair: HDSigner, sighashTypes?: number[]): this;
|
99 | signInputHDAsync(inputIndex: number, hdKeyPair: HDSigner | HDSignerAsync, sighashTypes?: number[]): Promise<void>;
|
100 | signAllInputs(keyPair: Signer, sighashTypes?: number[]): this;
|
101 | signAllInputsAsync(keyPair: Signer | SignerAsync, sighashTypes?: number[]): Promise<void>;
|
102 | signInput(inputIndex: number, keyPair: Signer, sighashTypes?: number[]): this;
|
103 | signTaprootInput(inputIndex: number, keyPair: Signer, tapLeafHashToSign?: Buffer, sighashTypes?: number[]): this;
|
104 | private _signInput;
|
105 | private _signTaprootInput;
|
106 | signInputAsync(inputIndex: number, keyPair: Signer | SignerAsync, sighashTypes?: number[]): Promise<void>;
|
107 | signTaprootInputAsync(inputIndex: number, keyPair: Signer | SignerAsync, tapLeafHash?: Buffer, sighashTypes?: number[]): Promise<void>;
|
108 | private _signInputAsync;
|
109 | private _signTaprootInputAsync;
|
110 | private checkTaprootHashesForSig;
|
111 | toBuffer(): Buffer;
|
112 | toHex(): string;
|
113 | toBase64(): string;
|
114 | updateGlobal(updateData: PsbtGlobalUpdate): this;
|
115 | updateInput(inputIndex: number, updateData: PsbtInputUpdate): this;
|
116 | updateOutput(outputIndex: number, updateData: PsbtOutputUpdate): this;
|
117 | addUnknownKeyValToGlobal(keyVal: KeyValue): this;
|
118 | addUnknownKeyValToInput(inputIndex: number, keyVal: KeyValue): this;
|
119 | addUnknownKeyValToOutput(outputIndex: number, keyVal: KeyValue): this;
|
120 | clearFinalizedInput(inputIndex: number): this;
|
121 | }
|
122 | interface PsbtOptsOptional {
|
123 | network?: Network;
|
124 | maximumFeeRate?: number;
|
125 | }
|
126 | interface PsbtInputExtended extends PsbtInput, TransactionInput {
|
127 | }
|
128 | type PsbtOutputExtended = PsbtOutputExtendedAddress | PsbtOutputExtendedScript;
|
129 | interface PsbtOutputExtendedAddress extends PsbtOutput {
|
130 | address: string;
|
131 | value: number;
|
132 | }
|
133 | interface PsbtOutputExtendedScript extends PsbtOutput {
|
134 | script: Buffer;
|
135 | value: number;
|
136 | }
|
137 | interface HDSignerBase {
|
138 | |
139 |
|
140 |
|
141 | publicKey: Buffer;
|
142 | |
143 |
|
144 |
|
145 | fingerprint: Buffer;
|
146 | }
|
147 | export interface HDSigner extends HDSignerBase {
|
148 | |
149 |
|
150 |
|
151 |
|
152 | derivePath(path: string): HDSigner;
|
153 | |
154 |
|
155 |
|
156 |
|
157 | sign(hash: Buffer): Buffer;
|
158 | }
|
159 |
|
160 |
|
161 |
|
162 | export interface HDSignerAsync extends HDSignerBase {
|
163 | derivePath(path: string): HDSignerAsync;
|
164 | sign(hash: Buffer): Promise<Buffer>;
|
165 | }
|
166 | export interface Signer {
|
167 | publicKey: Buffer;
|
168 | network?: any;
|
169 | sign(hash: Buffer, lowR?: boolean): Buffer;
|
170 | signSchnorr?(hash: Buffer): Buffer;
|
171 | getPublicKey?(): Buffer;
|
172 | }
|
173 | export interface SignerAsync {
|
174 | publicKey: Buffer;
|
175 | network?: any;
|
176 | sign(hash: Buffer, lowR?: boolean): Promise<Buffer>;
|
177 | signSchnorr?(hash: Buffer): Promise<Buffer>;
|
178 | getPublicKey?(): Buffer;
|
179 | }
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 | type FinalScriptsFunc = (inputIndex: number,
|
187 | input: PsbtInput,
|
188 | script: Buffer,
|
189 | isSegwit: boolean,
|
190 | isP2SH: boolean,
|
191 | isP2WSH: boolean) => {
|
192 | finalScriptSig: Buffer | undefined;
|
193 | finalScriptWitness: Buffer | undefined;
|
194 | };
|
195 | type FinalTaprootScriptsFunc = (inputIndex: number,
|
196 | input: PsbtInput,
|
197 | tapLeafHashToFinalize?: Buffer) => {
|
198 | finalScriptWitness: Buffer | undefined;
|
199 | };
|
200 | type AllScriptType = 'witnesspubkeyhash' | 'pubkeyhash' | 'multisig' | 'pubkey' | 'nonstandard' | 'p2sh-witnesspubkeyhash' | 'p2sh-pubkeyhash' | 'p2sh-multisig' | 'p2sh-pubkey' | 'p2sh-nonstandard' | 'p2wsh-pubkeyhash' | 'p2wsh-multisig' | 'p2wsh-pubkey' | 'p2wsh-nonstandard' | 'p2sh-p2wsh-pubkeyhash' | 'p2sh-p2wsh-multisig' | 'p2sh-p2wsh-pubkey' | 'p2sh-p2wsh-nonstandard';
|
201 | export {};
|