@bitcoinerlab/descriptors 1.1.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +138 -145
- package/dist/checksum.d.ts +4 -0
- package/dist/checksum.js +4 -0
- package/dist/descriptors.d.ts +415 -37
- package/dist/descriptors.js +283 -130
- package/dist/index.d.ts +25 -5
- package/dist/index.js +12 -2
- package/dist/keyExpressions.d.ts +54 -5
- package/dist/keyExpressions.js +30 -2
- package/dist/ledger.d.ts +89 -12
- package/dist/ledger.js +241 -28
- package/dist/scriptExpressions.d.ts +73 -28
- package/dist/scriptExpressions.js +26 -4
- package/dist/signers.d.ts +34 -1
- package/dist/signers.js +102 -41
- package/dist/types.d.ts +71 -39
- package/package.json +3 -2
package/dist/descriptors.d.ts
CHANGED
|
@@ -3,24 +3,246 @@ import { Network, Payment, Psbt } from 'bitcoinjs-lib';
|
|
|
3
3
|
import type { PartialSig } from 'bip174/src/lib/interfaces';
|
|
4
4
|
import { BIP32API } from 'bip32';
|
|
5
5
|
import { ECPairAPI } from 'ecpair';
|
|
6
|
-
import type { TinySecp256k1Interface, Preimage, TimeConstraints,
|
|
6
|
+
import type { TinySecp256k1Interface, Preimage, TimeConstraints, Expansion, ExpansionMap, ParseKeyExpression } from './types';
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* Constructs the necessary functions and classes for working with descriptors
|
|
9
|
+
* using an external elliptic curve (ecc) library.
|
|
10
|
+
*
|
|
11
|
+
* Notably, it returns the {@link _Internal_.Output | `Output`} class, which
|
|
12
|
+
* provides methods to create, sign, and finalize PSBTs based on descriptor
|
|
13
|
+
* expressions.
|
|
14
|
+
*
|
|
15
|
+
* While this Factory function includes the `Descriptor` class, note that
|
|
16
|
+
* this class was deprecated in v2.0 in favor of `Output`. For backward
|
|
17
|
+
* compatibility, the `Descriptor` class remains, but using `Output` is advised.
|
|
18
|
+
*
|
|
19
|
+
* The Factory also returns utility methods like `expand` (detailed below)
|
|
20
|
+
* and `parseKeyExpression` (see {@link ParseKeyExpression}).
|
|
21
|
+
*
|
|
22
|
+
* Additionally, for convenience, the function returns `BIP32` and `ECPair`.
|
|
23
|
+
* These are {@link https://github.com/bitcoinjs bitcoinjs-lib} classes designed
|
|
24
|
+
* for managing {@link https://github.com/bitcoinjs/bip32 | `BIP32`} keys and
|
|
25
|
+
* public/private key pairs:
|
|
26
|
+
* {@link https://github.com/bitcoinjs/ecpair | `ECPair`}, respectively.
|
|
27
|
+
*
|
|
28
|
+
* @param {Object} ecc - An object with elliptic curve operations, such as
|
|
29
|
+
* [tiny-secp256k1](https://github.com/bitcoinjs/tiny-secp256k1) or
|
|
30
|
+
* [@bitcoinerlab/secp256k1](https://github.com/bitcoinerlab/secp256k1).
|
|
10
31
|
*/
|
|
11
32
|
export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
|
|
12
|
-
Descriptor: {
|
|
13
|
-
new ({ expression,
|
|
33
|
+
/** @deprecated */ Descriptor: {
|
|
34
|
+
new ({ expression, ...rest }: {
|
|
35
|
+
expression: string;
|
|
36
|
+
index?: number;
|
|
37
|
+
checksumRequired?: boolean;
|
|
38
|
+
allowMiniscriptInP2SH?: boolean;
|
|
39
|
+
network?: Network;
|
|
40
|
+
preimages?: Preimage[];
|
|
41
|
+
signersPubKeys?: Buffer[];
|
|
42
|
+
}): {
|
|
43
|
+
readonly "__#1@#payment": Payment;
|
|
44
|
+
readonly "__#1@#preimages": Preimage[];
|
|
45
|
+
readonly "__#1@#signersPubKeys": Buffer[];
|
|
46
|
+
readonly "__#1@#miniscript"?: string;
|
|
47
|
+
readonly "__#1@#witnessScript"?: Buffer;
|
|
48
|
+
readonly "__#1@#redeemScript"?: Buffer;
|
|
49
|
+
readonly "__#1@#isSegwit"?: boolean;
|
|
50
|
+
readonly "__#1@#expandedExpression"?: string;
|
|
51
|
+
readonly "__#1@#expandedMiniscript"?: string;
|
|
52
|
+
readonly "__#1@#expansionMap"?: ExpansionMap;
|
|
53
|
+
readonly "__#1@#network": Network;
|
|
54
|
+
/**
|
|
55
|
+
* Gets the TimeConstraints (nSequence and nLockTime) of the miniscript
|
|
56
|
+
* descriptor as passed in the constructor, just using the expression,
|
|
57
|
+
* the signersPubKeys and preimages.
|
|
58
|
+
*
|
|
59
|
+
* We just need to know which will be the signatures that will be
|
|
60
|
+
* used (signersPubKeys) but final signatures are not necessary for
|
|
61
|
+
* obtaning nLockTime and nSequence.
|
|
62
|
+
*
|
|
63
|
+
* Remember: nSequence and nLockTime are part of the hash that is signed.
|
|
64
|
+
* Thus, they must not change after computing the signatures.
|
|
65
|
+
* When running getScriptSatisfaction, using the final signatures,
|
|
66
|
+
* satisfyMiniscript verifies that the time constraints did not change.
|
|
67
|
+
*/
|
|
68
|
+
"__#1@#getTimeConstraints"(): TimeConstraints | undefined;
|
|
14
69
|
/**
|
|
15
|
-
*
|
|
70
|
+
* Creates and returns an instance of bitcoinjs-lib
|
|
71
|
+
* [`Payment`](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/ts_src/payments/index.ts)'s interface with the `scriptPubKey` of this `Output`.
|
|
16
72
|
*/
|
|
17
|
-
|
|
73
|
+
getPayment(): Payment;
|
|
74
|
+
/**
|
|
75
|
+
* Returns the Bitcoin Address of this `Output`.
|
|
76
|
+
*/
|
|
77
|
+
getAddress(): string;
|
|
78
|
+
/**
|
|
79
|
+
* Returns this `Output`'s scriptPubKey.
|
|
80
|
+
*/
|
|
81
|
+
getScriptPubKey(): Buffer;
|
|
82
|
+
/**
|
|
83
|
+
* Returns the compiled Script Satisfaction if this `Output` was created
|
|
84
|
+
* using a miniscript-based descriptor.
|
|
85
|
+
*
|
|
86
|
+
* The Satisfaction is the unlocking script that fulfills
|
|
87
|
+
* (satisfies) this `Output` and it is derived using the Safisfier algorithm
|
|
88
|
+
* [described here](https://bitcoin.sipa.be/miniscript/).
|
|
89
|
+
*
|
|
90
|
+
* Important: As mentioned above, note that this function only applies to
|
|
91
|
+
* miniscript descriptors.
|
|
92
|
+
*/
|
|
93
|
+
getScriptSatisfaction(signatures: PartialSig[]): Buffer;
|
|
94
|
+
/**
|
|
95
|
+
* Gets the nSequence required to fulfill this `Output`.
|
|
96
|
+
*/
|
|
97
|
+
getSequence(): number | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Gets the nLockTime required to fulfill this `Output`.
|
|
100
|
+
*/
|
|
101
|
+
getLockTime(): number | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Gets the witnessScript required to fulfill this `Output`. Only applies to
|
|
104
|
+
* Segwit outputs.
|
|
105
|
+
*/
|
|
106
|
+
getWitnessScript(): Buffer | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* Gets the redeemScript required to fullfill this `Output`. Only applies to
|
|
109
|
+
* SH outputs: sh(wpkh), sh(wsh), sh(lockingScript).
|
|
110
|
+
*/
|
|
111
|
+
getRedeemScript(): Buffer | undefined;
|
|
112
|
+
/**
|
|
113
|
+
* Gets the bitcoinjs-lib [`network`](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/ts_src/networks.ts) used to create this `Output`.
|
|
114
|
+
*/
|
|
115
|
+
getNetwork(): Network;
|
|
116
|
+
/**
|
|
117
|
+
* Whether this `Output` is Segwit.
|
|
118
|
+
*/
|
|
119
|
+
isSegwit(): boolean | undefined;
|
|
120
|
+
/** @deprecated - Use updatePsbtAsInput instead
|
|
121
|
+
* @hidden
|
|
122
|
+
*/
|
|
123
|
+
updatePsbt(params: {
|
|
124
|
+
psbt: Psbt;
|
|
125
|
+
txHex?: string;
|
|
126
|
+
txId?: string;
|
|
127
|
+
value?: number;
|
|
128
|
+
vout: number;
|
|
129
|
+
}): number;
|
|
130
|
+
/**
|
|
131
|
+
* Sets this output as an input of the provided `psbt` and updates the
|
|
132
|
+
* `psbt` locktime if required by the descriptor.
|
|
133
|
+
*
|
|
134
|
+
* `psbt` and `vout` are mandatory. Include `txHex` as well. The pair
|
|
135
|
+
* `vout` and `txHex` define the transaction and output number this instance
|
|
136
|
+
* pertains to.
|
|
137
|
+
*
|
|
138
|
+
* Though not advised, for Segwit inputs you can pass `txId` and `value`
|
|
139
|
+
* in lieu of `txHex`. If doing so, ensure `value` accuracy to avoid
|
|
140
|
+
* potential fee attacks -
|
|
141
|
+
* [See this issue](https://github.com/bitcoinjs/bitcoinjs-lib/issues/1625).
|
|
142
|
+
*
|
|
143
|
+
* Note: Hardware wallets need the [full `txHex` for Segwit](https://blog.trezor.io/details-of-firmware-updates-for-trezor-one-version-1-9-1-and-trezor-model-t-version-2-3-1-1eba8f60f2dd).
|
|
144
|
+
*
|
|
145
|
+
* When unsure, always use `txHex`, and skip `txId` and `value` for safety.
|
|
146
|
+
*
|
|
147
|
+
* @returns A finalizer function to be used after signing the `psbt`.
|
|
148
|
+
* This function ensures that this input is properly finalized.
|
|
149
|
+
* The finalizer has this signature:
|
|
150
|
+
*
|
|
151
|
+
* `( { psbt, validate = true } : { psbt: Psbt; validate: boolean | undefined } ) => void`
|
|
152
|
+
*
|
|
153
|
+
*/
|
|
154
|
+
updatePsbtAsInput({ psbt, txHex, txId, value, vout }: {
|
|
155
|
+
psbt: Psbt;
|
|
156
|
+
txHex?: string;
|
|
157
|
+
txId?: string;
|
|
158
|
+
value?: number;
|
|
159
|
+
vout: number;
|
|
160
|
+
}): ({ psbt, validate }: {
|
|
161
|
+
psbt: Psbt;
|
|
162
|
+
/** Runs further test on the validity of the signatures.
|
|
163
|
+
* It speeds down the finalization process but makes sure the psbt will
|
|
164
|
+
* be valid.
|
|
165
|
+
* @default true */
|
|
166
|
+
validate?: boolean | undefined;
|
|
167
|
+
}) => void;
|
|
168
|
+
/**
|
|
169
|
+
* Adds this output as an output of the provided `psbt` with the given
|
|
170
|
+
* value.
|
|
171
|
+
*
|
|
172
|
+
* @param psbt - The Partially Signed Bitcoin Transaction.
|
|
173
|
+
* @param value - The value for the output in satoshis.
|
|
174
|
+
*/
|
|
175
|
+
updatePsbtAsOutput({ psbt, value }: {
|
|
176
|
+
psbt: Psbt;
|
|
177
|
+
value: number;
|
|
178
|
+
}): void;
|
|
179
|
+
"__#1@#assertPsbtInput"({ psbt, index }: {
|
|
180
|
+
psbt: Psbt;
|
|
181
|
+
index: number;
|
|
182
|
+
}): void;
|
|
183
|
+
/**
|
|
184
|
+
* Finalizes a PSBT input by adding the necessary unlocking script that satisfies this `Output`'s
|
|
185
|
+
* spending conditions.
|
|
186
|
+
*
|
|
187
|
+
* 🔴 IMPORTANT 🔴
|
|
188
|
+
* It is STRONGLY RECOMMENDED to use the finalizer function returned by
|
|
189
|
+
* {@link _Internal_.Output.updatePsbtAsInput | `updatePsbtAsInput`} instead
|
|
190
|
+
* of calling this method directly.
|
|
191
|
+
* This approach eliminates the need to manage the `Output` instance and the
|
|
192
|
+
* input's index, simplifying the process.
|
|
193
|
+
*
|
|
194
|
+
* The `finalizePsbtInput` method completes a PSBT input by adding the
|
|
195
|
+
* unlocking script (`scriptWitness` or `scriptSig`) that satisfies
|
|
196
|
+
* this `Output`'s spending conditions. Bear in mind that both
|
|
197
|
+
* `scriptSig` and `scriptWitness` incorporate signatures. As such, you
|
|
198
|
+
* should complete all necessary signing operations before calling this
|
|
199
|
+
* method.
|
|
200
|
+
*
|
|
201
|
+
* For each unspent output from a previous transaction that you're
|
|
202
|
+
* referencing in a `psbt` as an input to be spent, apply this method as
|
|
203
|
+
* follows: `output.finalizePsbtInput({ index, psbt })`.
|
|
204
|
+
*
|
|
205
|
+
* It's essential to specify the exact position (or `index`) of the input in
|
|
206
|
+
* the `psbt` that references this unspent `Output`. This `index` should
|
|
207
|
+
* align with the value returned by the `updatePsbtAsInput` method.
|
|
208
|
+
* Note:
|
|
209
|
+
* The `index` corresponds to the position of the input in the `psbt`.
|
|
210
|
+
* To get this index, right after calling `updatePsbtAsInput()`, use:
|
|
211
|
+
* `index = psbt.data.inputs.length - 1`.
|
|
212
|
+
*/
|
|
213
|
+
finalizePsbtInput({ index, psbt, validate }: {
|
|
214
|
+
index: number;
|
|
215
|
+
psbt: Psbt;
|
|
216
|
+
/** Runs further test on the validity of the signatures.
|
|
217
|
+
* It speeds down the finalization process but makes sure the psbt will
|
|
218
|
+
* be valid.
|
|
219
|
+
* @default true */
|
|
220
|
+
validate?: boolean | undefined;
|
|
221
|
+
}): void;
|
|
222
|
+
/**
|
|
223
|
+
* Decomposes the descriptor used to form this `Output` into its elemental
|
|
224
|
+
* parts. See {@link ExpansionMap ExpansionMap} for a detailed explanation.
|
|
225
|
+
*/
|
|
226
|
+
expand(): {
|
|
227
|
+
expansionMap?: ExpansionMap;
|
|
228
|
+
expandedMiniscript?: string;
|
|
229
|
+
miniscript?: string;
|
|
230
|
+
expandedExpression?: string;
|
|
231
|
+
};
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
Output: {
|
|
235
|
+
new ({ descriptor, index, checksumRequired, allowMiniscriptInP2SH, network, preimages, signersPubKeys }: {
|
|
236
|
+
/**
|
|
237
|
+
* The descriptor string in ASCII format. It may include a "*" to denote an arbitrary index (aka ranged descriptors).
|
|
238
|
+
*/
|
|
239
|
+
descriptor: string;
|
|
18
240
|
/**
|
|
19
241
|
* The descriptor's index in the case of a range descriptor (must be an integer >=0).
|
|
20
242
|
*/
|
|
21
243
|
index?: number;
|
|
22
244
|
/**
|
|
23
|
-
*
|
|
245
|
+
* An optional flag indicating whether the descriptor is required to include a checksum.
|
|
24
246
|
* @defaultValue false
|
|
25
247
|
*/
|
|
26
248
|
checksumRequired?: boolean;
|
|
@@ -40,7 +262,19 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
|
|
|
40
262
|
*/
|
|
41
263
|
preimages?: Preimage[];
|
|
42
264
|
/**
|
|
43
|
-
* An array of the public keys used for signing the transaction when
|
|
265
|
+
* An array of the public keys used for signing the transaction when
|
|
266
|
+
* spending the output associated with this descriptor. This parameter is
|
|
267
|
+
* only used if the descriptor object is being used to finalize a
|
|
268
|
+
* transaction. It is necessary to specify the spending path when working
|
|
269
|
+
* with miniscript-based expressions that have multiple spending paths.
|
|
270
|
+
* Set this parameter to an array containing the public keys involved in
|
|
271
|
+
* the desired spending path. Leave it `undefined` if you only need to
|
|
272
|
+
* generate the `scriptPubKey` or `address` for a descriptor, or if all
|
|
273
|
+
* the public keys involved in the descriptor will sign the transaction.
|
|
274
|
+
* In the latter case, the satisfier will automatically choose the most
|
|
275
|
+
* optimal spending path (if more than one is available).
|
|
276
|
+
* For more details on using this parameter, refer to [this Stack Exchange
|
|
277
|
+
* answer](https://bitcoin.stackexchange.com/a/118036/89665).
|
|
44
278
|
*/
|
|
45
279
|
signersPubKeys?: Buffer[];
|
|
46
280
|
}): {
|
|
@@ -70,60 +304,163 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
|
|
|
70
304
|
* satisfyMiniscript verifies that the time constraints did not change.
|
|
71
305
|
*/
|
|
72
306
|
"__#1@#getTimeConstraints"(): TimeConstraints | undefined;
|
|
307
|
+
/**
|
|
308
|
+
* Creates and returns an instance of bitcoinjs-lib
|
|
309
|
+
* [`Payment`](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/ts_src/payments/index.ts)'s interface with the `scriptPubKey` of this `Output`.
|
|
310
|
+
*/
|
|
73
311
|
getPayment(): Payment;
|
|
74
312
|
/**
|
|
75
|
-
* Returns the Bitcoin Address
|
|
313
|
+
* Returns the Bitcoin Address of this `Output`.
|
|
76
314
|
*/
|
|
77
315
|
getAddress(): string;
|
|
316
|
+
/**
|
|
317
|
+
* Returns this `Output`'s scriptPubKey.
|
|
318
|
+
*/
|
|
78
319
|
getScriptPubKey(): Buffer;
|
|
79
320
|
/**
|
|
80
|
-
* Returns the compiled
|
|
81
|
-
*
|
|
82
|
-
*
|
|
321
|
+
* Returns the compiled Script Satisfaction if this `Output` was created
|
|
322
|
+
* using a miniscript-based descriptor.
|
|
323
|
+
*
|
|
324
|
+
* The Satisfaction is the unlocking script that fulfills
|
|
325
|
+
* (satisfies) this `Output` and it is derived using the Safisfier algorithm
|
|
326
|
+
* [described here](https://bitcoin.sipa.be/miniscript/).
|
|
327
|
+
*
|
|
328
|
+
* Important: As mentioned above, note that this function only applies to
|
|
329
|
+
* miniscript descriptors.
|
|
83
330
|
*/
|
|
84
331
|
getScriptSatisfaction(signatures: PartialSig[]): Buffer;
|
|
332
|
+
/**
|
|
333
|
+
* Gets the nSequence required to fulfill this `Output`.
|
|
334
|
+
*/
|
|
85
335
|
getSequence(): number | undefined;
|
|
336
|
+
/**
|
|
337
|
+
* Gets the nLockTime required to fulfill this `Output`.
|
|
338
|
+
*/
|
|
86
339
|
getLockTime(): number | undefined;
|
|
340
|
+
/**
|
|
341
|
+
* Gets the witnessScript required to fulfill this `Output`. Only applies to
|
|
342
|
+
* Segwit outputs.
|
|
343
|
+
*/
|
|
87
344
|
getWitnessScript(): Buffer | undefined;
|
|
345
|
+
/**
|
|
346
|
+
* Gets the redeemScript required to fullfill this `Output`. Only applies to
|
|
347
|
+
* SH outputs: sh(wpkh), sh(wsh), sh(lockingScript).
|
|
348
|
+
*/
|
|
88
349
|
getRedeemScript(): Buffer | undefined;
|
|
350
|
+
/**
|
|
351
|
+
* Gets the bitcoinjs-lib [`network`](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/ts_src/networks.ts) used to create this `Output`.
|
|
352
|
+
*/
|
|
89
353
|
getNetwork(): Network;
|
|
354
|
+
/**
|
|
355
|
+
* Whether this `Output` is Segwit.
|
|
356
|
+
*/
|
|
90
357
|
isSegwit(): boolean | undefined;
|
|
358
|
+
/** @deprecated - Use updatePsbtAsInput instead
|
|
359
|
+
* @hidden
|
|
360
|
+
*/
|
|
361
|
+
updatePsbt(params: {
|
|
362
|
+
psbt: Psbt;
|
|
363
|
+
txHex?: string;
|
|
364
|
+
txId?: string;
|
|
365
|
+
value?: number;
|
|
366
|
+
vout: number;
|
|
367
|
+
}): number;
|
|
91
368
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
369
|
+
* Sets this output as an input of the provided `psbt` and updates the
|
|
370
|
+
* `psbt` locktime if required by the descriptor.
|
|
371
|
+
*
|
|
372
|
+
* `psbt` and `vout` are mandatory. Include `txHex` as well. The pair
|
|
373
|
+
* `vout` and `txHex` define the transaction and output number this instance
|
|
374
|
+
* pertains to.
|
|
375
|
+
*
|
|
376
|
+
* Though not advised, for Segwit inputs you can pass `txId` and `value`
|
|
377
|
+
* in lieu of `txHex`. If doing so, ensure `value` accuracy to avoid
|
|
378
|
+
* potential fee attacks -
|
|
379
|
+
* [See this issue](https://github.com/bitcoinjs/bitcoinjs-lib/issues/1625).
|
|
380
|
+
*
|
|
381
|
+
* Note: Hardware wallets need the [full `txHex` for Segwit](https://blog.trezor.io/details-of-firmware-updates-for-trezor-one-version-1-9-1-and-trezor-model-t-version-2-3-1-1eba8f60f2dd).
|
|
94
382
|
*
|
|
95
|
-
*
|
|
96
|
-
* It also adds a new input to the Psbt based on txHex
|
|
97
|
-
* It returns the number of the input that is added.
|
|
98
|
-
* psbt and vout are mandatory. Also pass txHex.
|
|
383
|
+
* When unsure, always use `txHex`, and skip `txId` and `value` for safety.
|
|
99
384
|
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* Note that HW wallets require the full txHex also for Segwit anyways:
|
|
106
|
-
* https://blog.trezor.io/details-of-firmware-updates-for-trezor-one-version-1-9-1-and-trezor-model-t-version-2-3-1-1eba8f60f2dd
|
|
385
|
+
* @returns A finalizer function to be used after signing the `psbt`.
|
|
386
|
+
* This function ensures that this input is properly finalized.
|
|
387
|
+
* The finalizer has this signature:
|
|
388
|
+
*
|
|
389
|
+
* `( { psbt, validate = true } : { psbt: Psbt; validate: boolean | undefined } ) => void`
|
|
107
390
|
*
|
|
108
|
-
* In doubt, simply pass txHex (and you can skip passing txId and value) and
|
|
109
|
-
* you shall be fine.
|
|
110
391
|
*/
|
|
111
|
-
|
|
392
|
+
updatePsbtAsInput({ psbt, txHex, txId, value, vout }: {
|
|
112
393
|
psbt: Psbt;
|
|
113
394
|
txHex?: string;
|
|
114
395
|
txId?: string;
|
|
115
396
|
value?: number;
|
|
116
397
|
vout: number;
|
|
117
|
-
}):
|
|
398
|
+
}): ({ psbt, validate }: {
|
|
399
|
+
psbt: Psbt;
|
|
400
|
+
/** Runs further test on the validity of the signatures.
|
|
401
|
+
* It speeds down the finalization process but makes sure the psbt will
|
|
402
|
+
* be valid.
|
|
403
|
+
* @default true */
|
|
404
|
+
validate?: boolean | undefined;
|
|
405
|
+
}) => void;
|
|
406
|
+
/**
|
|
407
|
+
* Adds this output as an output of the provided `psbt` with the given
|
|
408
|
+
* value.
|
|
409
|
+
*
|
|
410
|
+
* @param psbt - The Partially Signed Bitcoin Transaction.
|
|
411
|
+
* @param value - The value for the output in satoshis.
|
|
412
|
+
*/
|
|
413
|
+
updatePsbtAsOutput({ psbt, value }: {
|
|
414
|
+
psbt: Psbt;
|
|
415
|
+
value: number;
|
|
416
|
+
}): void;
|
|
118
417
|
"__#1@#assertPsbtInput"({ psbt, index }: {
|
|
119
418
|
psbt: Psbt;
|
|
120
419
|
index: number;
|
|
121
420
|
}): void;
|
|
421
|
+
/**
|
|
422
|
+
* Finalizes a PSBT input by adding the necessary unlocking script that satisfies this `Output`'s
|
|
423
|
+
* spending conditions.
|
|
424
|
+
*
|
|
425
|
+
* 🔴 IMPORTANT 🔴
|
|
426
|
+
* It is STRONGLY RECOMMENDED to use the finalizer function returned by
|
|
427
|
+
* {@link _Internal_.Output.updatePsbtAsInput | `updatePsbtAsInput`} instead
|
|
428
|
+
* of calling this method directly.
|
|
429
|
+
* This approach eliminates the need to manage the `Output` instance and the
|
|
430
|
+
* input's index, simplifying the process.
|
|
431
|
+
*
|
|
432
|
+
* The `finalizePsbtInput` method completes a PSBT input by adding the
|
|
433
|
+
* unlocking script (`scriptWitness` or `scriptSig`) that satisfies
|
|
434
|
+
* this `Output`'s spending conditions. Bear in mind that both
|
|
435
|
+
* `scriptSig` and `scriptWitness` incorporate signatures. As such, you
|
|
436
|
+
* should complete all necessary signing operations before calling this
|
|
437
|
+
* method.
|
|
438
|
+
*
|
|
439
|
+
* For each unspent output from a previous transaction that you're
|
|
440
|
+
* referencing in a `psbt` as an input to be spent, apply this method as
|
|
441
|
+
* follows: `output.finalizePsbtInput({ index, psbt })`.
|
|
442
|
+
*
|
|
443
|
+
* It's essential to specify the exact position (or `index`) of the input in
|
|
444
|
+
* the `psbt` that references this unspent `Output`. This `index` should
|
|
445
|
+
* align with the value returned by the `updatePsbtAsInput` method.
|
|
446
|
+
* Note:
|
|
447
|
+
* The `index` corresponds to the position of the input in the `psbt`.
|
|
448
|
+
* To get this index, right after calling `updatePsbtAsInput()`, use:
|
|
449
|
+
* `index = psbt.data.inputs.length - 1`.
|
|
450
|
+
*/
|
|
122
451
|
finalizePsbtInput({ index, psbt, validate }: {
|
|
123
452
|
index: number;
|
|
124
453
|
psbt: Psbt;
|
|
454
|
+
/** Runs further test on the validity of the signatures.
|
|
455
|
+
* It speeds down the finalization process but makes sure the psbt will
|
|
456
|
+
* be valid.
|
|
457
|
+
* @default true */
|
|
125
458
|
validate?: boolean | undefined;
|
|
126
459
|
}): void;
|
|
460
|
+
/**
|
|
461
|
+
* Decomposes the descriptor used to form this `Output` into its elemental
|
|
462
|
+
* parts. See {@link ExpansionMap ExpansionMap} for a detailed explanation.
|
|
463
|
+
*/
|
|
127
464
|
expand(): {
|
|
128
465
|
expansionMap?: ExpansionMap;
|
|
129
466
|
expandedMiniscript?: string;
|
|
@@ -133,17 +470,58 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
|
|
|
133
470
|
};
|
|
134
471
|
};
|
|
135
472
|
parseKeyExpression: ParseKeyExpression;
|
|
136
|
-
expand:
|
|
473
|
+
expand: {
|
|
474
|
+
(params: {
|
|
475
|
+
/**
|
|
476
|
+
* The descriptor expression to be expanded.
|
|
477
|
+
*/
|
|
478
|
+
descriptor: string;
|
|
479
|
+
/**
|
|
480
|
+
* The descriptor index, if ranged.
|
|
481
|
+
*/
|
|
482
|
+
index?: number;
|
|
483
|
+
/**
|
|
484
|
+
* A flag indicating whether the descriptor is required to include a checksum.
|
|
485
|
+
* @defaultValue false
|
|
486
|
+
*/
|
|
487
|
+
checksumRequired?: boolean;
|
|
488
|
+
/**
|
|
489
|
+
* The Bitcoin network to use.
|
|
490
|
+
* @defaultValue `networks.bitcoin`
|
|
491
|
+
*/
|
|
492
|
+
network?: Network;
|
|
493
|
+
/**
|
|
494
|
+
* Flag to allow miniscript in P2SH.
|
|
495
|
+
* @defaultValue false
|
|
496
|
+
*/
|
|
497
|
+
allowMiniscriptInP2SH?: boolean;
|
|
498
|
+
}): Expansion;
|
|
499
|
+
(params: {
|
|
500
|
+
expression: string;
|
|
501
|
+
index?: number;
|
|
502
|
+
checksumRequired?: boolean;
|
|
503
|
+
network?: Network;
|
|
504
|
+
allowMiniscriptInP2SH?: boolean;
|
|
505
|
+
}): Expansion;
|
|
506
|
+
};
|
|
137
507
|
ECPair: ECPairAPI;
|
|
138
508
|
BIP32: BIP32API;
|
|
139
509
|
};
|
|
510
|
+
/** @hidden @deprecated */
|
|
511
|
+
type DescriptorConstructor = ReturnType<typeof DescriptorsFactory>['Descriptor'];
|
|
512
|
+
/** @hidden @deprecated */
|
|
513
|
+
type DescriptorInstance = InstanceType<DescriptorConstructor>;
|
|
514
|
+
export { DescriptorInstance, DescriptorConstructor };
|
|
515
|
+
type OutputConstructor = ReturnType<typeof DescriptorsFactory>['Output'];
|
|
140
516
|
/**
|
|
141
|
-
* The {@link DescriptorsFactory | `DescriptorsFactory`} function internally
|
|
517
|
+
* The {@link DescriptorsFactory | `DescriptorsFactory`} function internally
|
|
518
|
+
* creates and returns the {@link _Internal_.Output | `Descriptor`} class.
|
|
142
519
|
* This class is specialized for the provided `TinySecp256k1Interface`.
|
|
143
|
-
* Use `
|
|
520
|
+
* Use `OutputInstance` to declare instances for this class:
|
|
521
|
+
* `const: OutputInstance = new Output();`
|
|
144
522
|
*
|
|
145
|
-
* See the {@link _Internal_.
|
|
523
|
+
* See the {@link _Internal_.Output | documentation for the internal `Output`
|
|
524
|
+
* class} for a complete list of available methods.
|
|
146
525
|
*/
|
|
147
|
-
type
|
|
148
|
-
|
|
149
|
-
export { DescriptorInstance, DescriptorConstructor };
|
|
526
|
+
type OutputInstance = InstanceType<OutputConstructor>;
|
|
527
|
+
export { OutputInstance, OutputConstructor };
|