@bitgo/wasm-utxo 1.26.0 → 1.28.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 +1,60 @@
1
- export {};
1
+ // BitGo coin names (from Network::from_coin_name in src/networks.rs)
2
+ export const coinNames = [
3
+ "btc",
4
+ "tbtc",
5
+ "tbtc4",
6
+ "tbtcsig",
7
+ "tbtcbgsig",
8
+ "bch",
9
+ "tbch",
10
+ "bcha",
11
+ "tbcha",
12
+ "btg",
13
+ "tbtg",
14
+ "bsv",
15
+ "tbsv",
16
+ "dash",
17
+ "tdash",
18
+ "doge",
19
+ "tdoge",
20
+ "ltc",
21
+ "tltc",
22
+ "zec",
23
+ "tzec",
24
+ ];
25
+ export function getMainnet(name) {
26
+ switch (name) {
27
+ case "tbtc":
28
+ case "tbtc4":
29
+ case "tbtcsig":
30
+ case "tbtcbgsig":
31
+ return "btc";
32
+ case "tbch":
33
+ return "bch";
34
+ case "tbcha":
35
+ return "bcha";
36
+ case "tbtg":
37
+ return "btg";
38
+ case "tbsv":
39
+ return "bsv";
40
+ case "tdash":
41
+ return "dash";
42
+ case "tdoge":
43
+ return "doge";
44
+ case "tltc":
45
+ return "ltc";
46
+ case "tzec":
47
+ return "zec";
48
+ default:
49
+ return name;
50
+ }
51
+ }
52
+ export function isMainnet(name) {
53
+ return getMainnet(name) === name;
54
+ }
55
+ export function isTestnet(name) {
56
+ return getMainnet(name) !== name;
57
+ }
58
+ export function isCoinName(v) {
59
+ return coinNames.includes(v);
60
+ }
@@ -371,16 +371,63 @@ export declare class BitGoPsbt {
371
371
  */
372
372
  verifySignature(inputIndex: number, key: BIP32Arg | ECPairArg): boolean;
373
373
  /**
374
- * Sign a single input with a private key
374
+ * Sign all matching inputs with a private key.
375
+ *
376
+ * This method signs all inputs that match the provided key in a single efficient pass.
377
+ * It accepts either:
378
+ * - An xpriv (BIP32Arg: base58 string, BIP32 instance, or WasmBIP32) for wallet inputs
379
+ * - A raw privkey (ECPairArg: Buffer, ECPair instance, or WasmECPair) for replay protection inputs
380
+ *
381
+ * **Note:** MuSig2 inputs are skipped by this method when using xpriv because they require
382
+ * FirstRound state. After calling this method, sign MuSig2 inputs individually using
383
+ * `signInput()` after calling `generateMusig2Nonces()`.
384
+ *
385
+ * @param key - Either an xpriv (BIP32Arg) or a raw privkey (ECPairArg)
386
+ * @returns Array of input indices that were signed
387
+ * @throws Error if signing fails
388
+ *
389
+ * @example
390
+ * ```typescript
391
+ * // Sign all wallet inputs with user's xpriv
392
+ * const signedIndices = psbt.sign(userXpriv);
393
+ * console.log(`Signed inputs: ${signedIndices.join(", ")}`);
394
+ *
395
+ * // Sign all replay protection inputs with raw privkey
396
+ * const rpSignedIndices = psbt.sign(replayProtectionPrivkey);
397
+ * ```
398
+ */
399
+ sign(key: BIP32Arg | ECPairArg): number[];
400
+ /**
401
+ * Sign a single input with a private key.
402
+ *
403
+ * @deprecated Use `sign(key)` to sign all matching inputs (more efficient), or use
404
+ * `signInput(inputIndex, key)` for explicit single-input signing.
405
+ *
406
+ * **Note:** This method is NOT more efficient than `sign(key)` for non-MuSig2 inputs.
407
+ * The underlying miniscript library signs all inputs regardless. This overload exists
408
+ * for backward compatibility only.
409
+ *
410
+ * @param inputIndex - The index of the input to sign (0-based)
411
+ * @param key - Either an xpriv (BIP32Arg) or a raw privkey (ECPairArg)
412
+ * @throws Error if signing fails, or if generateMusig2Nonces() was not called first for MuSig2 inputs
413
+ */
414
+ sign(inputIndex: number, key: BIP32Arg | ECPairArg): void;
415
+ /**
416
+ * Sign a single input with a private key.
375
417
  *
376
418
  * This method signs a specific input using the provided key. It accepts either:
377
- * - An xpriv (BIP32Arg: base58 string, BIP32 instance, or WasmBIP32) for wallet inputs - derives the key and signs
378
- * - A raw privkey (ECPairArg: Buffer, ECPair instance, or WasmECPair) for replay protection inputs - signs directly
419
+ * - An xpriv (BIP32Arg: base58 string, BIP32 instance, or WasmBIP32) for wallet inputs
420
+ * - A raw privkey (ECPairArg: Buffer, ECPair instance, or WasmECPair) for replay protection inputs
379
421
  *
380
- * This method automatically detects and handles different input types:
381
- * - For regular inputs: uses standard PSBT signing
382
- * - For MuSig2 inputs: uses the FirstRound state stored by generateMusig2Nonces()
383
- * - For replay protection inputs: signs with legacy P2SH sighash
422
+ * **Important:** This method is NOT faster than `sign(key)` for non-MuSig2 inputs.
423
+ * The underlying miniscript library signs all inputs regardless. This method uses a
424
+ * save/restore pattern to ensure only the target input receives the signature.
425
+ *
426
+ * Use this method only when you need precise control over which inputs are signed,
427
+ * for example:
428
+ * - Signing MuSig2 inputs (after calling generateMusig2Nonces())
429
+ * - Mixed transactions where different inputs need different keys
430
+ * - Testing or debugging signing behavior
384
431
  *
385
432
  * @param inputIndex - The index of the input to sign (0-based)
386
433
  * @param key - Either an xpriv (BIP32Arg) or a raw privkey (ECPairArg)
@@ -388,28 +435,15 @@ export declare class BitGoPsbt {
388
435
  *
389
436
  * @example
390
437
  * ```typescript
391
- * // Parse transaction to identify input types
392
- * const parsed = psbt.parseTransactionWithWalletKeys(walletKeys, replayProtection);
393
- *
394
- * // Sign regular wallet inputs with xpriv
395
- * for (let i = 0; i < parsed.inputs.length; i++) {
396
- * const input = parsed.inputs[i];
397
- * if (input.scriptId !== null && input.scriptType !== "p2shP2pk") {
398
- * psbt.sign(i, userXpriv);
399
- * }
400
- * }
438
+ * // Sign a specific MuSig2 input after nonce generation
439
+ * psbt.generateMusig2Nonces(userXpriv);
440
+ * psbt.signInput(musig2InputIndex, userXpriv);
401
441
  *
402
- * // Sign replay protection inputs with raw privkey
403
- * const userPrivkey = bip32.fromBase58(userXpriv).privateKey!;
404
- * for (let i = 0; i < parsed.inputs.length; i++) {
405
- * const input = parsed.inputs[i];
406
- * if (input.scriptType === "p2shP2pk") {
407
- * psbt.sign(i, userPrivkey);
408
- * }
409
- * }
442
+ * // Sign a specific replay protection input
443
+ * psbt.signInput(rpInputIndex, replayProtectionPrivkey);
410
444
  * ```
411
445
  */
412
- sign(inputIndex: number, key: BIP32Arg | ECPairArg): void;
446
+ signInput(inputIndex: number, key: BIP32Arg | ECPairArg): void;
413
447
  /**
414
448
  * @deprecated - use verifySignature with the replay protection key instead
415
449
  *
@@ -1,7 +1,7 @@
1
1
  import { BitGoPsbt as WasmBitGoPsbt } from "../wasm/wasm_utxo.js";
2
2
  import { RootWalletKeys } from "./RootWalletKeys.js";
3
3
  import { ReplayProtection } from "./ReplayProtection.js";
4
- import { BIP32 } from "../bip32.js";
4
+ import { BIP32, isBIP32Arg } from "../bip32.js";
5
5
  import { ECPair } from "../ecpair.js";
6
6
  export class BitGoPsbt {
7
7
  _wasm;
@@ -303,17 +303,49 @@ export class BitGoPsbt {
303
303
  const wasmECPair = ECPair.from(key).wasm;
304
304
  return this._wasm.verify_signature_with_pub(inputIndex, wasmECPair);
305
305
  }
306
+ sign(inputIndexOrKey, key) {
307
+ // Detect which overload was called
308
+ if (typeof inputIndexOrKey === "number") {
309
+ // Called as sign(inputIndex, key) - deprecated single-input signing
310
+ if (key === undefined) {
311
+ throw new Error("Key is required when signing a single input");
312
+ }
313
+ this.signInput(inputIndexOrKey, key);
314
+ return;
315
+ }
316
+ // Called as sign(key) - sign all matching inputs
317
+ const keyArg = inputIndexOrKey;
318
+ if (isBIP32Arg(keyArg)) {
319
+ // It's a BIP32Arg - sign all wallet inputs (ECDSA + MuSig2)
320
+ const wasmKey = BIP32.from(keyArg);
321
+ // Sign all non-MuSig2 wallet inputs
322
+ const walletSigned = this._wasm.sign_all_wallet_inputs(wasmKey.wasm);
323
+ // Sign all MuSig2 keypath inputs (more efficient - reuses SighashCache)
324
+ const musig2Signed = this._wasm.sign_all_musig2_inputs(wasmKey.wasm);
325
+ return [...walletSigned, ...musig2Signed];
326
+ }
327
+ else {
328
+ // It's an ECPairArg - sign all replay protection inputs
329
+ const wasmKey = ECPair.from(keyArg);
330
+ return this._wasm.sign_replay_protection_inputs(wasmKey.wasm);
331
+ }
332
+ }
306
333
  /**
307
- * Sign a single input with a private key
334
+ * Sign a single input with a private key.
308
335
  *
309
336
  * This method signs a specific input using the provided key. It accepts either:
310
- * - An xpriv (BIP32Arg: base58 string, BIP32 instance, or WasmBIP32) for wallet inputs - derives the key and signs
311
- * - A raw privkey (ECPairArg: Buffer, ECPair instance, or WasmECPair) for replay protection inputs - signs directly
337
+ * - An xpriv (BIP32Arg: base58 string, BIP32 instance, or WasmBIP32) for wallet inputs
338
+ * - A raw privkey (ECPairArg: Buffer, ECPair instance, or WasmECPair) for replay protection inputs
339
+ *
340
+ * **Important:** This method is NOT faster than `sign(key)` for non-MuSig2 inputs.
341
+ * The underlying miniscript library signs all inputs regardless. This method uses a
342
+ * save/restore pattern to ensure only the target input receives the signature.
312
343
  *
313
- * This method automatically detects and handles different input types:
314
- * - For regular inputs: uses standard PSBT signing
315
- * - For MuSig2 inputs: uses the FirstRound state stored by generateMusig2Nonces()
316
- * - For replay protection inputs: signs with legacy P2SH sighash
344
+ * Use this method only when you need precise control over which inputs are signed,
345
+ * for example:
346
+ * - Signing MuSig2 inputs (after calling generateMusig2Nonces())
347
+ * - Mixed transactions where different inputs need different keys
348
+ * - Testing or debugging signing behavior
317
349
  *
318
350
  * @param inputIndex - The index of the input to sign (0-based)
319
351
  * @param key - Either an xpriv (BIP32Arg) or a raw privkey (ECPairArg)
@@ -321,42 +353,30 @@ export class BitGoPsbt {
321
353
  *
322
354
  * @example
323
355
  * ```typescript
324
- * // Parse transaction to identify input types
325
- * const parsed = psbt.parseTransactionWithWalletKeys(walletKeys, replayProtection);
326
- *
327
- * // Sign regular wallet inputs with xpriv
328
- * for (let i = 0; i < parsed.inputs.length; i++) {
329
- * const input = parsed.inputs[i];
330
- * if (input.scriptId !== null && input.scriptType !== "p2shP2pk") {
331
- * psbt.sign(i, userXpriv);
332
- * }
333
- * }
356
+ * // Sign a specific MuSig2 input after nonce generation
357
+ * psbt.generateMusig2Nonces(userXpriv);
358
+ * psbt.signInput(musig2InputIndex, userXpriv);
334
359
  *
335
- * // Sign replay protection inputs with raw privkey
336
- * const userPrivkey = bip32.fromBase58(userXpriv).privateKey!;
337
- * for (let i = 0; i < parsed.inputs.length; i++) {
338
- * const input = parsed.inputs[i];
339
- * if (input.scriptType === "p2shP2pk") {
340
- * psbt.sign(i, userPrivkey);
341
- * }
342
- * }
360
+ * // Sign a specific replay protection input
361
+ * psbt.signInput(rpInputIndex, replayProtectionPrivkey);
343
362
  * ```
344
363
  */
345
- sign(inputIndex, key) {
346
- // Detect key type
347
- // If string or has 'derive' method → BIP32Arg
348
- // Otherwise → ECPairArg
349
- if (typeof key === "string" ||
350
- (typeof key === "object" &&
351
- key !== null &&
352
- "derive" in key &&
353
- typeof key.derive === "function")) {
364
+ signInput(inputIndex, key) {
365
+ if (isBIP32Arg(key)) {
354
366
  // It's a BIP32Arg
355
367
  const wasmKey = BIP32.from(key);
356
- this._wasm.sign_with_xpriv(inputIndex, wasmKey.wasm);
368
+ // Route to the appropriate method based on input type
369
+ if (this._wasm.is_musig2_input(inputIndex)) {
370
+ // MuSig2 keypath: true single-input signing (efficient)
371
+ this._wasm.sign_musig2_input(inputIndex, wasmKey.wasm);
372
+ }
373
+ else {
374
+ // ECDSA/Schnorr script path: save/restore pattern (not faster than bulk)
375
+ this._wasm.sign_wallet_input(inputIndex, wasmKey.wasm);
376
+ }
357
377
  }
358
378
  else {
359
- // It's an ECPairArg
379
+ // It's an ECPairArg - for replay protection inputs
360
380
  const wasmKey = ECPair.from(key);
361
381
  this._wasm.sign_with_privkey(inputIndex, wasmKey.wasm);
362
382
  }
@@ -146,6 +146,20 @@ export class BitGoPsbt {
146
146
  * Get the unsigned transaction ID
147
147
  */
148
148
  unsigned_txid(): string;
149
+ /**
150
+ * Check if an input is a MuSig2 keypath input.
151
+ *
152
+ * MuSig2 inputs require special handling: nonces must be generated first with
153
+ * `generate_musig2_nonces()`, then signed with `sign_musig2_input()`.
154
+ *
155
+ * # Arguments
156
+ * - `input_index`: The index of the input to check (0-based)
157
+ *
158
+ * # Returns
159
+ * - `true` if the input is a MuSig2 keypath input
160
+ * - `false` otherwise (or if input_index is out of bounds)
161
+ */
162
+ is_musig2_input(input_index: number): boolean;
149
163
  /**
150
164
  * Sign a single input with an extended private key (xpriv)
151
165
  *
@@ -208,6 +222,45 @@ export class BitGoPsbt {
208
222
  * The index of the newly added output
209
223
  */
210
224
  add_wallet_output(chain: number, index: number, value: bigint, wallet_keys: WasmRootWalletKeys): number;
225
+ /**
226
+ * Sign a single MuSig2 keypath input.
227
+ *
228
+ * This uses the FirstRound state generated by `generate_musig2_nonces()`.
229
+ * Each FirstRound can only be used once (nonce reuse is a security risk).
230
+ *
231
+ * For non-MuSig2 inputs, returns an error (use `sign_wallet_input` instead).
232
+ *
233
+ * # Arguments
234
+ * - `input_index`: The index of the input to sign (0-based)
235
+ * - `xpriv`: The extended private key as a WasmBIP32 instance
236
+ *
237
+ * # Returns
238
+ * - `Ok(())` if signing was successful
239
+ * - `Err(WasmUtxoError)` if signing fails, no FirstRound exists, or not a MuSig2 input
240
+ */
241
+ sign_musig2_input(input_index: number, xpriv: WasmBIP32): void;
242
+ /**
243
+ * Sign a single non-MuSig2 wallet input using save/restore pattern.
244
+ *
245
+ * For MuSig2 inputs, returns an error (use `sign_musig2_input` instead).
246
+ * For ECDSA inputs, this uses a save/restore pattern: clones the PSBT,
247
+ * signs all inputs on the clone, then copies only the target input's
248
+ * signatures back.
249
+ *
250
+ * **Important:** This is NOT faster than `sign_all_wallet_inputs()` for ECDSA inputs.
251
+ * The underlying library signs all inputs regardless. This method just ensures
252
+ * that only the specified input gets signatures added to the PSBT.
253
+ * Use `sign_all_wallet_inputs()` when signing multiple inputs with the same key.
254
+ *
255
+ * # Arguments
256
+ * - `input_index`: The index of the input to sign (0-based)
257
+ * - `xpriv`: The extended private key as a WasmBIP32 instance
258
+ *
259
+ * # Returns
260
+ * - `Ok(())` if the input was signed
261
+ * - `Err(WasmUtxoError)` if signing fails or input is MuSig2
262
+ */
263
+ sign_wallet_input(input_index: number, xpriv: WasmBIP32): void;
211
264
  /**
212
265
  * Sign a single input with a raw private key
213
266
  *
@@ -266,6 +319,24 @@ export class BitGoPsbt {
266
319
  * - `Err(WasmUtxoError)` if any input failed to finalize
267
320
  */
268
321
  finalize_all_inputs(): void;
322
+ /**
323
+ * Sign all non-MuSig2 inputs with an extended private key (xpriv) in a single pass.
324
+ *
325
+ * This is more efficient than calling `sign_with_xpriv` for each input individually.
326
+ * The underlying miniscript library's `sign` method signs all matching inputs at once.
327
+ *
328
+ * **Note:** MuSig2 inputs are skipped by this method because they require FirstRound
329
+ * state from nonce generation. After calling this method, sign MuSig2 inputs
330
+ * individually using `sign_with_xpriv`.
331
+ *
332
+ * # Arguments
333
+ * - `xpriv`: The extended private key as a WasmBIP32 instance
334
+ *
335
+ * # Returns
336
+ * - `Ok(JsValue)` with an array of input indices that were signed
337
+ * - `Err(WasmUtxoError)` if signing fails
338
+ */
339
+ sign_all_with_xpriv(xpriv: WasmBIP32): any;
269
340
  /**
270
341
  * Add a PayGo attestation to a PSBT output
271
342
  *
@@ -325,6 +396,41 @@ export class BitGoPsbt {
325
396
  * generated for security. Custom session_id is only allowed on testnets for testing purposes.
326
397
  */
327
398
  generate_musig2_nonces(xpriv: WasmBIP32, session_id_bytes?: Uint8Array | null): void;
399
+ /**
400
+ * Sign all MuSig2 keypath inputs in a single pass with optimized sighash computation.
401
+ *
402
+ * This is more efficient than calling `sign_musig2_input()` for each input because
403
+ * it reuses the SighashCache across all inputs, avoiding redundant computation of
404
+ * sha_prevouts, sha_amounts, sha_scriptpubkeys, sha_sequences, and sha_outputs.
405
+ *
406
+ * Each MuSig2 input requires a FirstRound from `generate_musig2_nonces()`.
407
+ * FirstRounds that have already been consumed (signed) are skipped.
408
+ *
409
+ * # Arguments
410
+ * - `xpriv`: The extended private key as a WasmBIP32 instance
411
+ *
412
+ * # Returns
413
+ * - `Ok(JsValue)` with an array of input indices that were signed
414
+ * - `Err(WasmUtxoError)` if signing fails
415
+ */
416
+ sign_all_musig2_inputs(xpriv: WasmBIP32): any;
417
+ /**
418
+ * Sign all non-MuSig2 wallet inputs in a single efficient pass.
419
+ *
420
+ * This signs all ECDSA (P2SH, P2SH-P2WSH, P2WSH) and Taproot script path (P2TR)
421
+ * inputs that match the provided xpriv. MuSig2 keypath inputs are skipped.
422
+ *
423
+ * This is the most efficient way to sign wallet inputs. After calling this,
424
+ * sign any MuSig2 inputs using `sign_all_musig2_inputs()` or `sign_musig2_input()`.
425
+ *
426
+ * # Arguments
427
+ * - `xpriv`: The extended private key as a WasmBIP32 instance
428
+ *
429
+ * # Returns
430
+ * - `Ok(JsValue)` with an array of input indices that were signed
431
+ * - `Err(WasmUtxoError)` if signing fails
432
+ */
433
+ sign_all_wallet_inputs(xpriv: WasmBIP32): any;
328
434
  /**
329
435
  * Add an output to the PSBT by address
330
436
  *
@@ -411,12 +517,79 @@ export class BitGoPsbt {
411
517
  * Returns error if block height is before Overwinter activation
412
518
  */
413
519
  static create_empty_zcash_at_height(network: string, wallet_keys: WasmRootWalletKeys, block_height: number, version?: number | null, lock_time?: number | null, version_group_id?: number | null, expiry_height?: number | null): BitGoPsbt;
520
+ /**
521
+ * Sign a single input with an extended private key, using save/restore for ECDSA inputs.
522
+ *
523
+ * For MuSig2 inputs, this returns an error (use sign_with_xpriv which handles FirstRound).
524
+ * For ECDSA inputs, this clones the PSBT, signs all, then copies only the target
525
+ * input's signatures back.
526
+ *
527
+ * **Important:** This is NOT faster than `sign_all_with_xpriv` for ECDSA inputs.
528
+ * The underlying miniscript library signs all inputs regardless. This method
529
+ * just prevents signatures from being added to other inputs.
530
+ *
531
+ * # Arguments
532
+ * - `input_index`: The index of the input to sign (0-based)
533
+ * - `xpriv`: The extended private key as a WasmBIP32 instance
534
+ *
535
+ * # Returns
536
+ * - `Ok(())` if the input was signed
537
+ * - `Err(WasmUtxoError)` if signing fails
538
+ */
539
+ sign_single_input_with_xpriv(input_index: number, xpriv: WasmBIP32): void;
540
+ /**
541
+ * Sign all replay protection inputs with a raw private key.
542
+ *
543
+ * This iterates through all inputs looking for P2SH-P2PK (replay protection) inputs
544
+ * that match the provided public key and signs them.
545
+ *
546
+ * # Arguments
547
+ * - `ecpair`: The ECPair containing the private key
548
+ *
549
+ * # Returns
550
+ * - `Ok(JsValue)` with an array of input indices that were signed
551
+ * - `Err(WasmUtxoError)` if signing fails
552
+ */
553
+ sign_replay_protection_inputs(ecpair: WasmECPair): any;
414
554
  /**
415
555
  * Parse outputs with wallet keys to identify which outputs belong to a wallet
416
556
  *
417
557
  * Note: This method does NOT validate wallet inputs. It only parses outputs.
418
558
  */
419
559
  parse_outputs_with_wallet_keys(wallet_keys: WasmRootWalletKeys, paygo_pubkeys?: WasmECPair[] | null): any;
560
+ /**
561
+ * Sign a single input with a raw private key, using save/restore for regular inputs.
562
+ *
563
+ * For replay protection inputs (P2SH-P2PK), this uses direct signing which is
564
+ * already single-input. For regular inputs, this clones the PSBT, signs all,
565
+ * then copies only the target input's signatures back.
566
+ *
567
+ * **Important:** This is NOT faster than signing all inputs for regular (non-RP) inputs.
568
+ * The underlying miniscript library signs all inputs regardless.
569
+ *
570
+ * # Arguments
571
+ * - `input_index`: The index of the input to sign (0-based)
572
+ * - `ecpair`: The ECPair containing the private key
573
+ *
574
+ * # Returns
575
+ * - `Ok(())` if the input was signed
576
+ * - `Err(WasmUtxoError)` if signing fails
577
+ */
578
+ sign_single_input_with_privkey(input_index: number, ecpair: WasmECPair): void;
579
+ /**
580
+ * Sign all replay protection inputs with a raw private key.
581
+ *
582
+ * This iterates through all inputs looking for P2SH-P2PK (replay protection) inputs
583
+ * that match the provided public key and signs them.
584
+ *
585
+ * # Arguments
586
+ * - `ecpair`: The ECPair containing the private key
587
+ *
588
+ * # Returns
589
+ * - `Ok(JsValue)` with an array of input indices that were signed
590
+ * - `Err(WasmUtxoError)` if signing fails
591
+ */
592
+ sign_all_replay_protection_inputs(ecpair: WasmECPair): any;
420
593
  /**
421
594
  * Parse transaction with wallet keys to identify wallet inputs/outputs
422
595
  */
@@ -963,15 +1136,54 @@ export class WrapMiniscript {
963
1136
  }
964
1137
 
965
1138
  export class WrapPsbt {
966
- private constructor();
967
1139
  free(): void;
968
1140
  [Symbol.dispose](): void;
1141
+ /**
1142
+ * Add an output to the PSBT
1143
+ *
1144
+ * # Arguments
1145
+ * * `script` - The output script (scriptPubKey)
1146
+ * * `value` - Value in satoshis
1147
+ *
1148
+ * # Returns
1149
+ * The index of the newly added output
1150
+ */
1151
+ addOutput(script: Uint8Array, value: bigint): number;
969
1152
  static deserialize(psbt: Uint8Array): WrapPsbt;
970
1153
  finalize(): void;
971
1154
  signWithPrv(prv: Uint8Array): any;
972
1155
  signWithXprv(xprv: string): any;
1156
+ /**
1157
+ * Get the unsigned transaction bytes
1158
+ *
1159
+ * # Returns
1160
+ * The serialized unsigned transaction
1161
+ */
1162
+ getUnsignedTx(): Uint8Array;
973
1163
  updateInputWithDescriptor(input_index: number, descriptor: WrapDescriptor): void;
974
1164
  updateOutputWithDescriptor(output_index: number, descriptor: WrapDescriptor): void;
1165
+ /**
1166
+ * Create an empty PSBT
1167
+ *
1168
+ * # Arguments
1169
+ * * `version` - Transaction version (default: 2)
1170
+ * * `lock_time` - Transaction lock time (default: 0)
1171
+ */
1172
+ constructor(version?: number | null, lock_time?: number | null);
975
1173
  clone(): WrapPsbt;
1174
+ /**
1175
+ * Add an input to the PSBT
1176
+ *
1177
+ * # Arguments
1178
+ * * `txid` - Transaction ID (hex string, 32 bytes reversed)
1179
+ * * `vout` - Output index being spent
1180
+ * * `value` - Value in satoshis of the output being spent
1181
+ * * `script` - The scriptPubKey of the output being spent
1182
+ * * `sequence` - Sequence number (default: 0xFFFFFFFE for RBF)
1183
+ *
1184
+ * # Returns
1185
+ * The index of the newly added input
1186
+ */
1187
+ addInput(txid: string, vout: number, value: bigint, script: Uint8Array, sequence?: number | null): number;
976
1188
  serialize(): Uint8Array;
977
1189
  }