@bitcoinerlab/descriptors 2.3.6 → 3.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.
@@ -1,8 +1,10 @@
1
1
  import { Network, Payment, Psbt } from 'bitcoinjs-lib';
2
- import type { PartialSig } from 'bip174/src/lib/interfaces';
2
+ import type { PartialSig } from 'bip174';
3
3
  import { BIP32API } from 'bip32';
4
4
  import { ECPairAPI } from 'ecpair';
5
- import type { TinySecp256k1Interface, Preimage, TimeConstraints, Expansion, ExpansionMap, ParseKeyExpression } from './types';
5
+ import type { TinySecp256k1Interface, Preimage, Expansion, ExpansionMap, KeyExpressionParser } from './types';
6
+ import type { TapTreeInfoNode, TapTreeNode } from './tapTree';
7
+ import type { TaprootLeafSatisfaction } from './tapMiniscript';
6
8
  /**
7
9
  * Constructs the necessary functions and classes for working with descriptors
8
10
  * using an external elliptic curve (ecc) library.
@@ -11,12 +13,8 @@ import type { TinySecp256k1Interface, Preimage, TimeConstraints, Expansion, Expa
11
13
  * provides methods to create, sign, and finalize PSBTs based on descriptor
12
14
  * expressions.
13
15
  *
14
- * While this Factory function includes the `Descriptor` class, note that
15
- * this class was deprecated in v2.0 in favor of `Output`. For backward
16
- * compatibility, the `Descriptor` class remains, but using `Output` is advised.
17
- *
18
16
  * The Factory also returns utility methods like `expand` (detailed below)
19
- * and `parseKeyExpression` (see {@link ParseKeyExpression}).
17
+ * and `parseKeyExpression` (see {@link KeyExpressionParser}).
20
18
  *
21
19
  * Additionally, for convenience, the function returns `BIP32` and `ECPair`.
22
20
  * These are {@link https://github.com/bitcoinjs bitcoinjs-lib} classes designed
@@ -29,280 +27,34 @@ import type { TinySecp256k1Interface, Preimage, TimeConstraints, Expansion, Expa
29
27
  * [@bitcoinerlab/secp256k1](https://github.com/bitcoinerlab/secp256k1).
30
28
  */
31
29
  export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
32
- /** @deprecated @hidden */ Descriptor: {
33
- new ({ expression, ...rest }: {
34
- expression: string;
35
- index?: number;
36
- checksumRequired?: boolean;
37
- allowMiniscriptInP2SH?: boolean;
38
- network?: Network;
39
- preimages?: Preimage[];
40
- signersPubKeys?: Buffer[];
41
- }): {
42
- readonly "__#private@#payment": Payment;
43
- readonly "__#private@#preimages": Preimage[];
44
- readonly "__#private@#signersPubKeys": Buffer[];
45
- readonly "__#private@#miniscript"?: string;
46
- readonly "__#private@#witnessScript"?: Buffer;
47
- readonly "__#private@#redeemScript"?: Buffer;
48
- readonly "__#private@#isSegwit"?: boolean;
49
- readonly "__#private@#isTaproot"?: boolean;
50
- readonly "__#private@#expandedExpression"?: string;
51
- readonly "__#private@#expandedMiniscript"?: string;
52
- readonly "__#private@#expansionMap"?: ExpansionMap;
53
- readonly "__#private@#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
- "__#private@#getTimeConstraints"(): TimeConstraints | undefined;
69
- /**
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`.
72
- */
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[] | "DANGEROUSLY_USE_FAKE_SIGNATURES"): 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
- * *NOTE:* When the descriptor in an input is `addr(address)`, it is assumed
120
- * that any `addr(SH_TYPE_ADDRESS)` is in fact a Segwit `SH_WPKH`
121
- * (Script Hash-Witness Public Key Hash).
122
- * For inputs using arbitrary scripts (not standard addresses),
123
- * use a descriptor in the format `sh(MINISCRIPT)`.
124
- *
125
- */
126
- isSegwit(): boolean | undefined;
127
- /**
128
- * Whether this `Output` is Taproot.
129
- */
130
- isTaproot(): boolean | undefined;
131
- /**
132
- * Attempts to determine the type of output script by testing it against
133
- * various payment types.
134
- *
135
- * This method tries to identify if the output is one of the following types:
136
- * - P2SH (Pay to Script Hash)
137
- * - P2WSH (Pay to Witness Script Hash)
138
- * - P2WPKH (Pay to Witness Public Key Hash)
139
- * - P2PKH (Pay to Public Key Hash)
140
- * - P2TR (Pay to Taproot)
141
- *
142
- * @returns An object { isPKH: boolean; isWPKH: boolean; isSH: boolean; isWSH: boolean; isTR: boolean;}
143
- * with boolean properties indicating the detected output type
144
- */
145
- guessOutput(): {
146
- isPKH: boolean;
147
- isWPKH: boolean;
148
- isSH: boolean;
149
- isWSH: boolean;
150
- isTR: boolean;
151
- };
152
- /**
153
- * Computes the Weight Unit contributions of this Output as if it were the
154
- * input in a tx.
155
- *
156
- * *NOTE:* When the descriptor in an input is `addr(address)`, it is assumed
157
- * that any `addr(SH_TYPE_ADDRESS)` is in fact a Segwit `SH_WPKH`
158
- * (Script Hash-Witness Public Key Hash).
159
- *, Also any `addr(SINGLE_KEY_ADDRESS)` * is assumed to be a single key Taproot
160
- * address (like those defined in BIP86).
161
- * For inputs using arbitrary scripts (not standard addresses),
162
- * use a descriptor in the format `sh(MINISCRIPT)` or `tr(MINISCRIPT)`.
163
- * Note however that tr(MINISCRIPT) is not yet supported for non-single-key
164
- * expressions.
165
- */
166
- inputWeight(isSegwitTx: boolean, signatures: PartialSig[] | "DANGEROUSLY_USE_FAKE_SIGNATURES"): number;
30
+ Output: {
31
+ new ({ descriptor, index, change, checksumRequired, allowMiniscriptInP2SH, network, preimages, signersPubKeys, taprootSpendPath, tapLeaf }: {
167
32
  /**
168
- * Computes the Weight Unit contributions of this Output as if it were the
169
- * output in a tx.
170
- */
171
- outputWeight(): number;
172
- /** @deprecated - Use updatePsbtAsInput instead
173
- * @hidden
33
+ * The descriptor string in ASCII format. It may include a "*" to denote an arbitrary index (aka ranged descriptors).
174
34
  */
175
- updatePsbt(params: {
176
- psbt: Psbt;
177
- txHex?: string;
178
- txId?: string;
179
- value?: number;
180
- vout: number;
181
- rbf?: boolean;
182
- }): number;
35
+ descriptor: string;
183
36
  /**
184
- * Sets this output as an input of the provided `psbt` and updates the
185
- * `psbt` locktime if required by the descriptor.
186
- *
187
- * `psbt` and `vout` are mandatory. Include `txHex` as well. The pair
188
- * `vout` and `txHex` define the transaction and output number this instance
189
- * pertains to.
190
- *
191
- * Though not advised, for Segwit inputs you can pass `txId` and `value`
192
- * in lieu of `txHex`. If doing so, ensure `value` accuracy to avoid
193
- * potential fee attacks -
194
- * [See this issue](https://github.com/bitcoinjs/bitcoinjs-lib/issues/1625).
195
- *
196
- * 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).
197
- *
198
- * When unsure, always use `txHex`, and skip `txId` and `value` for safety.
199
- *
200
- * Use `rbf` to mark whether this tx can be replaced with another with
201
- * higher fee while being in the mempool. Note that a tx will automatically
202
- * be marked as replacable if a single input requests it.
203
- * Note that any transaction using a relative timelock (nSequence < 0x80000000)
204
- * also falls within the RBF range (nSequence < 0xFFFFFFFE), making it
205
- * inherently replaceable. So don't set `rbf` to false if this is tx uses
206
- * relative time locks.
207
- *
208
- * @returns A finalizer function to be used after signing the `psbt`.
209
- * This function ensures that this input is properly finalized.
210
- * The finalizer has this signature:
211
- *
212
- * `( { psbt, validate = true } : { psbt: Psbt; validate: boolean | undefined } ) => void`
37
+ * The descriptor's index in the case of a range descriptor (must be an integer >=0).
213
38
  *
39
+ * This `Output` class always models a concrete spendable output.
40
+ * If the descriptor contains any wildcard (`*`), an `index` is required.
214
41
  */
215
- updatePsbtAsInput({ psbt, txHex, txId, value, vout, rbf }: {
216
- psbt: Psbt;
217
- txHex?: string;
218
- txId?: string;
219
- value?: number;
220
- vout: number;
221
- rbf?: boolean;
222
- }): ({ psbt, validate }: {
223
- psbt: Psbt;
224
- /** Runs further test on the validity of the signatures.
225
- * It speeds down the finalization process but makes sure the psbt will
226
- * be valid.
227
- * @default true */
228
- validate?: boolean | undefined;
229
- }) => void;
230
- /**
231
- * Adds this output as an output of the provided `psbt` with the given
232
- * value.
233
- * @param params - The parameters for the method.
234
- * @param params.psbt - The Partially Signed Bitcoin Transaction.
235
- * @param params.value - The value for the output in satoshis.
236
- */
237
- updatePsbtAsOutput({ psbt, value }: {
238
- psbt: Psbt;
239
- value: number;
240
- }): void;
241
- "__#private@#assertPsbtInput"({ psbt, index }: {
242
- psbt: Psbt;
243
- index: number;
244
- }): void;
42
+ index?: number;
245
43
  /**
246
- * Finalizes a PSBT input by adding the necessary unlocking script that satisfies this `Output`'s
247
- * spending conditions.
44
+ * Multipath branch selector for key-path tuples like `/<0;1>/*`.
248
45
  *
249
- * 🔴 IMPORTANT 🔴
250
- * It is STRONGLY RECOMMENDED to use the finalizer function returned by
251
- * {@link _Internal_.Output.updatePsbtAsInput | `updatePsbtAsInput`} instead
252
- * of calling this method directly.
253
- * This approach eliminates the need to manage the `Output` instance and the
254
- * input's index, simplifying the process.
46
+ * The value passed in `change` must be one of the numbers present in the
47
+ * tuple.
255
48
  *
256
- * The `finalizePsbtInput` method completes a PSBT input by adding the
257
- * unlocking script (`scriptWitness` or `scriptSig`) that satisfies
258
- * this `Output`'s spending conditions. Bear in mind that both
259
- * `scriptSig` and `scriptWitness` incorporate signatures. As such, you
260
- * should complete all necessary signing operations before calling this
261
- * method.
49
+ * Examples:
50
+ * - `/<0;1>/*` accepts `change: 0` (typically receive) or `change: 1`
51
+ * (typically change).
52
+ * - `/<0;1;2>/*` accepts `change: 0`, `1` or `2`.
262
53
  *
263
- * For each unspent output from a previous transaction that you're
264
- * referencing in a `psbt` as an input to be spent, apply this method as
265
- * follows: `output.finalizePsbtInput({ index, psbt })`.
266
- *
267
- * It's essential to specify the exact position (or `index`) of the input in
268
- * the `psbt` that references this unspent `Output`. This `index` should
269
- * align with the value returned by the `updatePsbtAsInput` method.
270
- * Note:
271
- * The `index` corresponds to the position of the input in the `psbt`.
272
- * To get this index, right after calling `updatePsbtAsInput()`, use:
273
- * `index = psbt.data.inputs.length - 1`.
274
- */
275
- finalizePsbtInput({ index, psbt, validate }: {
276
- index: number;
277
- psbt: Psbt;
278
- /** Runs further test on the validity of the signatures.
279
- * It speeds down the finalization process but makes sure the psbt will
280
- * be valid.
281
- * @default true */
282
- validate?: boolean | undefined;
283
- }): void;
284
- /**
285
- * Decomposes the descriptor used to form this `Output` into its elemental
286
- * parts. See {@link ExpansionMap ExpansionMap} for a detailed explanation.
287
- */
288
- expand(): {
289
- expansionMap?: ExpansionMap;
290
- expandedMiniscript?: string;
291
- miniscript?: string;
292
- expandedExpression?: string;
293
- };
294
- };
295
- };
296
- Output: {
297
- new ({ descriptor, index, checksumRequired, allowMiniscriptInP2SH, network, preimages, signersPubKeys }: {
298
- /**
299
- * The descriptor string in ASCII format. It may include a "*" to denote an arbitrary index (aka ranged descriptors).
54
+ * This parameter is independent from `index`: `change` resolves
55
+ * multipath tuples, while `index` resolves the final wildcard `*`.
300
56
  */
301
- descriptor: string;
302
- /**
303
- * The descriptor's index in the case of a range descriptor (must be an integer >=0).
304
- */
305
- index?: number;
57
+ change?: number;
306
58
  /**
307
59
  * An optional flag indicating whether the descriptor is required to include a checksum.
308
60
  * @defaultValue false
@@ -346,28 +98,92 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
346
98
  * or if all the public keys involved in the descriptor will sign the
347
99
  * transaction. In the latter case, the satisfier will automatically
348
100
  * choose the most optimal spending path (if more than one is available).
101
+ * If omitted, this library assumes that all keys in the miniscript can
102
+ * sign. For taproot script-path spends, keys are inferred per leaf.
349
103
  *
350
104
  * For more details on using this parameter, refer to [this Stack Exchange
351
105
  * answer](https://bitcoin.stackexchange.com/a/118036/89665).
352
106
  */
353
- signersPubKeys?: Buffer[];
107
+ signersPubKeys?: Uint8Array[];
108
+ /**
109
+ * Taproot spend path policy. Use `key` to force key-path estimation,
110
+ * or `script` to estimate script-path spends.
111
+ *
112
+ * This setting only applies to `tr(KEY,TREE)` descriptors.
113
+ * For `tr(KEY)` descriptors, only key-path is available.
114
+ *
115
+ * When `script` is selected:
116
+ * - if `tapLeaf` is provided, that leaf is used.
117
+ * - if `tapLeaf` is omitted, the satisfier auto-selects the leaf with the
118
+ * smallest witness among satisfiable candidates.
119
+ *
120
+ * Default policy is `script` for `tr(KEY,TREE)` and `key` for key-only
121
+ * taproot descriptors (`tr(KEY)` and `addr(TR_ADDRESS)`).
122
+ */
123
+ taprootSpendPath?: "key" | "script";
124
+ /**
125
+ * Optional taproot leaf selector (tapleaf hash or miniscript string).
126
+ * Only used when taprootSpendPath is `script` and descriptor is
127
+ * `tr(KEY,TREE)`. If omitted, the smallest satisfiable leaf is selected.
128
+ */
129
+ tapLeaf?: Uint8Array | string;
354
130
  }): {
355
131
  readonly "__#private@#payment": Payment;
356
132
  readonly "__#private@#preimages": Preimage[];
357
- readonly "__#private@#signersPubKeys": Buffer[];
133
+ readonly "__#private@#signersPubKeys"?: Uint8Array[];
358
134
  readonly "__#private@#miniscript"?: string;
359
- readonly "__#private@#witnessScript"?: Buffer;
360
- readonly "__#private@#redeemScript"?: Buffer;
135
+ readonly "__#private@#witnessScript"?: Uint8Array;
136
+ readonly "__#private@#redeemScript"?: Uint8Array;
361
137
  readonly "__#private@#isSegwit"?: boolean;
362
138
  readonly "__#private@#isTaproot"?: boolean;
363
139
  readonly "__#private@#expandedExpression"?: string;
364
140
  readonly "__#private@#expandedMiniscript"?: string;
141
+ readonly "__#private@#tapTreeExpression"?: string;
142
+ readonly "__#private@#tapTree"?: TapTreeNode;
143
+ readonly "__#private@#tapTreeInfo"?: TapTreeInfoNode;
144
+ readonly "__#private@#taprootSpendPath": "key" | "script";
145
+ readonly "__#private@#tapLeaf"?: Uint8Array | string;
365
146
  readonly "__#private@#expansionMap"?: ExpansionMap;
366
147
  readonly "__#private@#network": Network;
148
+ "__#private@#resolveMiniscriptSignersPubKeys"(): Uint8Array[];
149
+ "__#private@#assertMiniscriptSatisfactionResourceLimits"(scriptSatisfaction: Uint8Array): void;
150
+ /**
151
+ * Returns the compiled Script Satisfaction for a miniscript-based Output.
152
+ * The satisfaction is the unlocking script, derived by the Satisfier
153
+ * algorithm (https://bitcoin.sipa.be/miniscript/).
154
+ *
155
+ * This method uses a two-pass flow:
156
+ * 1) Planning: constraints (nLockTime/nSequence) are computed using fake
157
+ * signatures. This is done since the final solution may not need all the
158
+ * signatures in signersPubKeys. And we may avoid the user do extra
159
+ * signing (tedious op with HWW).
160
+ * 2) Signing: the provided signatures are used to build the final
161
+ * satisfaction, while enforcing the planned constraints so the same
162
+ * solution is selected. Not all the signatures of signersPubKeys may
163
+ * be required.
164
+ *
165
+ * The return value includes the satisfaction script and the constraints.
166
+ */
167
+ getScriptSatisfaction(signatures: PartialSig[]): {
168
+ scriptSatisfaction: Uint8Array;
169
+ nLockTime: number | undefined;
170
+ nSequence: number | undefined;
171
+ };
172
+ "__#private@#resolveTapTreeSignersPubKeys"(): Uint8Array[];
173
+ /**
174
+ * Returns the taproot script‑path satisfaction for a tap miniscript
175
+ * descriptor. This mirrors {@link getScriptSatisfaction} and uses the same
176
+ * two‑pass plan/sign flow.
177
+ *
178
+ * In addition to nLockTime/nSequence, it returns the selected tapLeafHash
179
+ * (the leaf chosen during planning) and the leaf’s tapscript.
180
+ */
181
+ getTapScriptSatisfaction(signatures: PartialSig[]): TaprootLeafSatisfaction;
367
182
  /**
368
- * Gets the TimeConstraints (nSequence and nLockTime) of the miniscript
369
- * descriptor as passed in the constructor, just using the expression,
370
- * the signersPubKeys and preimages.
183
+ * Gets the planning constraints (nSequence and nLockTime) derived from the
184
+ * descriptor, just using the expression, signersPubKeys and preimages
185
+ * (using fake signatures).
186
+ * For taproot script-path spends, it also returns the selected tapLeafHash.
371
187
  *
372
188
  * We just need to know which will be the signatures that will be
373
189
  * used (signersPubKeys) but final signatures are not necessary for
@@ -375,10 +191,14 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
375
191
  *
376
192
  * Remember: nSequence and nLockTime are part of the hash that is signed.
377
193
  * Thus, they must not change after computing the signatures.
378
- * When running getScriptSatisfaction, using the final signatures,
194
+ * When running miniscript satisfactions with final signatures,
379
195
  * satisfyMiniscript verifies that the time constraints did not change.
380
196
  */
381
- "__#private@#getTimeConstraints"(): TimeConstraints | undefined;
197
+ "__#private@#getConstraints"(): {
198
+ nLockTime: number | undefined;
199
+ nSequence: number | undefined;
200
+ tapLeafHash: Uint8Array | undefined;
201
+ } | undefined;
382
202
  /**
383
203
  * Creates and returns an instance of bitcoinjs-lib
384
204
  * [`Payment`](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/ts_src/payments/index.ts)'s interface with the `scriptPubKey` of this `Output`.
@@ -391,19 +211,7 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
391
211
  /**
392
212
  * Returns this `Output`'s scriptPubKey.
393
213
  */
394
- getScriptPubKey(): Buffer;
395
- /**
396
- * Returns the compiled Script Satisfaction if this `Output` was created
397
- * using a miniscript-based descriptor.
398
- *
399
- * The Satisfaction is the unlocking script that fulfills
400
- * (satisfies) this `Output` and it is derived using the Safisfier algorithm
401
- * [described here](https://bitcoin.sipa.be/miniscript/).
402
- *
403
- * Important: As mentioned above, note that this function only applies to
404
- * miniscript descriptors.
405
- */
406
- getScriptSatisfaction(signatures: PartialSig[] | "DANGEROUSLY_USE_FAKE_SIGNATURES"): Buffer;
214
+ getScriptPubKey(): Uint8Array;
407
215
  /**
408
216
  * Gets the nSequence required to fulfill this `Output`.
409
217
  */
@@ -412,16 +220,23 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
412
220
  * Gets the nLockTime required to fulfill this `Output`.
413
221
  */
414
222
  getLockTime(): number | undefined;
223
+ /**
224
+ * Returns the tapleaf hash selected during planning for taproot script-path
225
+ * spends. If signersPubKeys are provided, selection is optimized for those
226
+ * pubkeys. If a specific tapLeaf selector is used in spending calls, this
227
+ * reflects that selection.
228
+ */
229
+ getTapLeafHash(): Uint8Array | undefined;
415
230
  /**
416
231
  * Gets the witnessScript required to fulfill this `Output`. Only applies to
417
232
  * Segwit outputs.
418
233
  */
419
- getWitnessScript(): Buffer | undefined;
234
+ getWitnessScript(): Uint8Array | undefined;
420
235
  /**
421
236
  * Gets the redeemScript required to fullfill this `Output`. Only applies to
422
237
  * SH outputs: sh(wpkh), sh(wsh), sh(lockingScript).
423
238
  */
424
- getRedeemScript(): Buffer | undefined;
239
+ getRedeemScript(): Uint8Array | undefined;
425
240
  /**
426
241
  * Gets the bitcoinjs-lib [`network`](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/ts_src/networks.ts) used to create this `Output`.
427
242
  */
@@ -472,27 +287,17 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
472
287
  *, Also any `addr(SINGLE_KEY_ADDRESS)` * is assumed to be a single key Taproot
473
288
  * address (like those defined in BIP86).
474
289
  * For inputs using arbitrary scripts (not standard addresses),
475
- * use a descriptor in the format `sh(MINISCRIPT)` or `tr(MINISCRIPT)`.
476
- * Note however that tr(MINISCRIPT) is not yet supported for non-single-key
477
- * expressions.
290
+ * use a descriptor in the format `sh(MINISCRIPT)`, `wsh(MINISCRIPT)` or
291
+ * `tr(KEY,TREE)` for taproot script-path expressions.
478
292
  */
479
- inputWeight(isSegwitTx: boolean, signatures: PartialSig[] | "DANGEROUSLY_USE_FAKE_SIGNATURES"): number;
293
+ inputWeight(isSegwitTx: boolean, signatures: PartialSig[] | "DANGEROUSLY_USE_FAKE_SIGNATURES", options?: {
294
+ taprootSighash?: "SIGHASH_DEFAULT" | "non-SIGHASH_DEFAULT";
295
+ }): number;
480
296
  /**
481
297
  * Computes the Weight Unit contributions of this Output as if it were the
482
298
  * output in a tx.
483
299
  */
484
300
  outputWeight(): number;
485
- /** @deprecated - Use updatePsbtAsInput instead
486
- * @hidden
487
- */
488
- updatePsbt(params: {
489
- psbt: Psbt;
490
- txHex?: string;
491
- txId?: string;
492
- value?: number;
493
- vout: number;
494
- rbf?: boolean;
495
- }): number;
496
301
  /**
497
302
  * Sets this output as an input of the provided `psbt` and updates the
498
303
  * `psbt` locktime if required by the descriptor.
@@ -520,6 +325,10 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
520
325
  *
521
326
  * @returns A finalizer function to be used after signing the `psbt`.
522
327
  * This function ensures that this input is properly finalized.
328
+ * The finalizer completes the PSBT input by adding the unlocking script
329
+ * (`scriptWitness` or `scriptSig`) that satisfies this `Output`'s spending
330
+ * conditions. Because these scripts include signatures, you should finish
331
+ * all signing operations before calling the finalizer.
523
332
  * The finalizer has this signature:
524
333
  *
525
334
  * `( { psbt, validate = true } : { psbt: Psbt; validate: boolean | undefined } ) => void`
@@ -529,7 +338,7 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
529
338
  psbt: Psbt;
530
339
  txHex?: string;
531
340
  txId?: string;
532
- value?: number;
341
+ value?: bigint;
533
342
  vout: number;
534
343
  rbf?: boolean;
535
344
  }): ({ psbt, validate }: {
@@ -549,110 +358,70 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
549
358
  */
550
359
  updatePsbtAsOutput({ psbt, value }: {
551
360
  psbt: Psbt;
552
- value: number;
361
+ value: bigint;
553
362
  }): void;
554
363
  "__#private@#assertPsbtInput"({ psbt, index }: {
555
364
  psbt: Psbt;
556
365
  index: number;
557
366
  }): void;
558
- /**
559
- * Finalizes a PSBT input by adding the necessary unlocking script that satisfies this `Output`'s
560
- * spending conditions.
561
- *
562
- * 🔴 IMPORTANT 🔴
563
- * It is STRONGLY RECOMMENDED to use the finalizer function returned by
564
- * {@link _Internal_.Output.updatePsbtAsInput | `updatePsbtAsInput`} instead
565
- * of calling this method directly.
566
- * This approach eliminates the need to manage the `Output` instance and the
567
- * input's index, simplifying the process.
568
- *
569
- * The `finalizePsbtInput` method completes a PSBT input by adding the
570
- * unlocking script (`scriptWitness` or `scriptSig`) that satisfies
571
- * this `Output`'s spending conditions. Bear in mind that both
572
- * `scriptSig` and `scriptWitness` incorporate signatures. As such, you
573
- * should complete all necessary signing operations before calling this
574
- * method.
575
- *
576
- * For each unspent output from a previous transaction that you're
577
- * referencing in a `psbt` as an input to be spent, apply this method as
578
- * follows: `output.finalizePsbtInput({ index, psbt })`.
579
- *
580
- * It's essential to specify the exact position (or `index`) of the input in
581
- * the `psbt` that references this unspent `Output`. This `index` should
582
- * align with the value returned by the `updatePsbtAsInput` method.
583
- * Note:
584
- * The `index` corresponds to the position of the input in the `psbt`.
585
- * To get this index, right after calling `updatePsbtAsInput()`, use:
586
- * `index = psbt.data.inputs.length - 1`.
587
- */
588
- finalizePsbtInput({ index, psbt, validate }: {
589
- index: number;
590
- psbt: Psbt;
591
- /** Runs further test on the validity of the signatures.
592
- * It speeds down the finalization process but makes sure the psbt will
593
- * be valid.
594
- * @default true */
595
- validate?: boolean | undefined;
596
- }): void;
597
367
  /**
598
368
  * Decomposes the descriptor used to form this `Output` into its elemental
599
369
  * parts. See {@link ExpansionMap ExpansionMap} for a detailed explanation.
600
370
  */
601
371
  expand(): {
602
372
  expansionMap?: ExpansionMap;
373
+ tapTreeInfo?: TapTreeInfoNode;
374
+ tapTree?: TapTreeNode;
375
+ tapTreeExpression?: string;
603
376
  expandedMiniscript?: string;
604
377
  miniscript?: string;
605
378
  expandedExpression?: string;
606
379
  };
607
380
  };
608
381
  };
609
- parseKeyExpression: ParseKeyExpression;
610
- expand: {
611
- (params: {
612
- /**
613
- * The descriptor expression to be expanded.
614
- */
615
- descriptor: string;
616
- /**
617
- * The descriptor index, if ranged.
618
- */
619
- index?: number;
620
- /**
621
- * A flag indicating whether the descriptor is required to include a checksum.
622
- * @defaultValue false
623
- */
624
- checksumRequired?: boolean;
625
- /**
626
- * The Bitcoin network to use.
627
- * @defaultValue `networks.bitcoin`
628
- */
629
- network?: Network;
630
- /**
631
- * Flag to allow miniscript in P2SH.
632
- * @defaultValue false
633
- */
634
- allowMiniscriptInP2SH?: boolean;
635
- }): Expansion;
636
- (params: {
637
- expression: string;
638
- index?: number;
639
- checksumRequired?: boolean;
640
- network?: Network;
641
- allowMiniscriptInP2SH?: boolean;
642
- }): Expansion;
643
- };
382
+ parseKeyExpression: KeyExpressionParser;
383
+ expand: (params: {
384
+ /**
385
+ * The descriptor expression to be expanded.
386
+ */
387
+ descriptor: string;
388
+ /**
389
+ * The descriptor index, if ranged.
390
+ */
391
+ index?: number;
392
+ /**
393
+ * Multipath branch selector used for descriptor key-path tuples like
394
+ * `/<0;1>/*` (and shorthand `/**`).
395
+ *
396
+ * The value passed in `change` must be one of the numbers present in the
397
+ * tuple. For example:
398
+ * - `/<0;1>/*` accepts `change: 0` or `change: 1`
399
+ * - `/<0;1;2>/*` accepts `change: 0`, `1` or `2`
400
+ */
401
+ change?: number;
402
+ /**
403
+ * A flag indicating whether the descriptor is required to include a checksum.
404
+ * @defaultValue false
405
+ */
406
+ checksumRequired?: boolean;
407
+ /**
408
+ * The Bitcoin network to use.
409
+ * @defaultValue `networks.bitcoin`
410
+ */
411
+ network?: Network;
412
+ /**
413
+ * Flag to allow miniscript in P2SH.
414
+ * @defaultValue false
415
+ */
416
+ allowMiniscriptInP2SH?: boolean;
417
+ }) => Expansion;
644
418
  ECPair: ECPairAPI;
645
419
  BIP32: BIP32API;
646
420
  };
647
- /** @hidden @deprecated */
648
- type DescriptorConstructor = ReturnType<typeof DescriptorsFactory>['Descriptor'];
649
- /** @hidden @deprecated */
650
- type DescriptorInstance = InstanceType<DescriptorConstructor>;
651
- export { DescriptorInstance, DescriptorConstructor };
652
421
  type OutputConstructor = ReturnType<typeof DescriptorsFactory>['Output'];
653
422
  /**
654
423
  * The {@link DescriptorsFactory | `DescriptorsFactory`} function internally
655
- * creates and returns the {@link _Internal_.Output | `Descriptor`} class.
424
+ * creates and returns the {@link _Internal_.Output | `Output`} class.
656
425
  * This class is specialized for the provided `TinySecp256k1Interface`.
657
426
  * Use `OutputInstance` to declare instances for this class:
658
427
  * `const: OutputInstance = new Output();`