@bitgo/wasm-utxo 1.27.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.
@@ -731,6 +731,25 @@ class BitGoPsbt {
731
731
  wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
732
732
  }
733
733
  }
734
+ /**
735
+ * Check if an input is a MuSig2 keypath input.
736
+ *
737
+ * MuSig2 inputs require special handling: nonces must be generated first with
738
+ * `generate_musig2_nonces()`, then signed with `sign_musig2_input()`.
739
+ *
740
+ * # Arguments
741
+ * - `input_index`: The index of the input to check (0-based)
742
+ *
743
+ * # Returns
744
+ * - `true` if the input is a MuSig2 keypath input
745
+ * - `false` otherwise (or if input_index is out of bounds)
746
+ * @param {number} input_index
747
+ * @returns {boolean}
748
+ */
749
+ is_musig2_input(input_index) {
750
+ const ret = wasm.bitgopsbt_is_musig2_input(this.__wbg_ptr, input_index);
751
+ return ret !== 0;
752
+ }
734
753
  /**
735
754
  * Sign a single input with an extended private key (xpriv)
736
755
  *
@@ -866,6 +885,75 @@ class BitGoPsbt {
866
885
  wasm.__wbindgen_add_to_stack_pointer(16);
867
886
  }
868
887
  }
888
+ /**
889
+ * Sign a single MuSig2 keypath input.
890
+ *
891
+ * This uses the FirstRound state generated by `generate_musig2_nonces()`.
892
+ * Each FirstRound can only be used once (nonce reuse is a security risk).
893
+ *
894
+ * For non-MuSig2 inputs, returns an error (use `sign_wallet_input` instead).
895
+ *
896
+ * # Arguments
897
+ * - `input_index`: The index of the input to sign (0-based)
898
+ * - `xpriv`: The extended private key as a WasmBIP32 instance
899
+ *
900
+ * # Returns
901
+ * - `Ok(())` if signing was successful
902
+ * - `Err(WasmUtxoError)` if signing fails, no FirstRound exists, or not a MuSig2 input
903
+ * @param {number} input_index
904
+ * @param {WasmBIP32} xpriv
905
+ */
906
+ sign_musig2_input(input_index, xpriv) {
907
+ try {
908
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
909
+ _assertClass(xpriv, WasmBIP32);
910
+ wasm.bitgopsbt_sign_musig2_input(retptr, this.__wbg_ptr, input_index, xpriv.__wbg_ptr);
911
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
912
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
913
+ if (r1) {
914
+ throw takeObject(r0);
915
+ }
916
+ } finally {
917
+ wasm.__wbindgen_add_to_stack_pointer(16);
918
+ }
919
+ }
920
+ /**
921
+ * Sign a single non-MuSig2 wallet input using save/restore pattern.
922
+ *
923
+ * For MuSig2 inputs, returns an error (use `sign_musig2_input` instead).
924
+ * For ECDSA inputs, this uses a save/restore pattern: clones the PSBT,
925
+ * signs all inputs on the clone, then copies only the target input's
926
+ * signatures back.
927
+ *
928
+ * **Important:** This is NOT faster than `sign_all_wallet_inputs()` for ECDSA inputs.
929
+ * The underlying library signs all inputs regardless. This method just ensures
930
+ * that only the specified input gets signatures added to the PSBT.
931
+ * Use `sign_all_wallet_inputs()` when signing multiple inputs with the same key.
932
+ *
933
+ * # Arguments
934
+ * - `input_index`: The index of the input to sign (0-based)
935
+ * - `xpriv`: The extended private key as a WasmBIP32 instance
936
+ *
937
+ * # Returns
938
+ * - `Ok(())` if the input was signed
939
+ * - `Err(WasmUtxoError)` if signing fails or input is MuSig2
940
+ * @param {number} input_index
941
+ * @param {WasmBIP32} xpriv
942
+ */
943
+ sign_wallet_input(input_index, xpriv) {
944
+ try {
945
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
946
+ _assertClass(xpriv, WasmBIP32);
947
+ wasm.bitgopsbt_sign_single_input_with_xpriv(retptr, this.__wbg_ptr, input_index, xpriv.__wbg_ptr);
948
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
949
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
950
+ if (r1) {
951
+ throw takeObject(r0);
952
+ }
953
+ } finally {
954
+ wasm.__wbindgen_add_to_stack_pointer(16);
955
+ }
956
+ }
869
957
  /**
870
958
  * Sign a single input with a raw private key
871
959
  *
@@ -994,6 +1082,41 @@ class BitGoPsbt {
994
1082
  wasm.__wbindgen_add_to_stack_pointer(16);
995
1083
  }
996
1084
  }
1085
+ /**
1086
+ * Sign all non-MuSig2 inputs with an extended private key (xpriv) in a single pass.
1087
+ *
1088
+ * This is more efficient than calling `sign_with_xpriv` for each input individually.
1089
+ * The underlying miniscript library's `sign` method signs all matching inputs at once.
1090
+ *
1091
+ * **Note:** MuSig2 inputs are skipped by this method because they require FirstRound
1092
+ * state from nonce generation. After calling this method, sign MuSig2 inputs
1093
+ * individually using `sign_with_xpriv`.
1094
+ *
1095
+ * # Arguments
1096
+ * - `xpriv`: The extended private key as a WasmBIP32 instance
1097
+ *
1098
+ * # Returns
1099
+ * - `Ok(JsValue)` with an array of input indices that were signed
1100
+ * - `Err(WasmUtxoError)` if signing fails
1101
+ * @param {WasmBIP32} xpriv
1102
+ * @returns {any}
1103
+ */
1104
+ sign_all_with_xpriv(xpriv) {
1105
+ try {
1106
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1107
+ _assertClass(xpriv, WasmBIP32);
1108
+ wasm.bitgopsbt_sign_all_wallet_inputs(retptr, this.__wbg_ptr, xpriv.__wbg_ptr);
1109
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1110
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1111
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1112
+ if (r2) {
1113
+ throw takeObject(r1);
1114
+ }
1115
+ return takeObject(r0);
1116
+ } finally {
1117
+ wasm.__wbindgen_add_to_stack_pointer(16);
1118
+ }
1119
+ }
997
1120
  /**
998
1121
  * Add a PayGo attestation to a PSBT output
999
1122
  *
@@ -1103,6 +1226,75 @@ class BitGoPsbt {
1103
1226
  wasm.__wbindgen_add_to_stack_pointer(16);
1104
1227
  }
1105
1228
  }
1229
+ /**
1230
+ * Sign all MuSig2 keypath inputs in a single pass with optimized sighash computation.
1231
+ *
1232
+ * This is more efficient than calling `sign_musig2_input()` for each input because
1233
+ * it reuses the SighashCache across all inputs, avoiding redundant computation of
1234
+ * sha_prevouts, sha_amounts, sha_scriptpubkeys, sha_sequences, and sha_outputs.
1235
+ *
1236
+ * Each MuSig2 input requires a FirstRound from `generate_musig2_nonces()`.
1237
+ * FirstRounds that have already been consumed (signed) are skipped.
1238
+ *
1239
+ * # Arguments
1240
+ * - `xpriv`: The extended private key as a WasmBIP32 instance
1241
+ *
1242
+ * # Returns
1243
+ * - `Ok(JsValue)` with an array of input indices that were signed
1244
+ * - `Err(WasmUtxoError)` if signing fails
1245
+ * @param {WasmBIP32} xpriv
1246
+ * @returns {any}
1247
+ */
1248
+ sign_all_musig2_inputs(xpriv) {
1249
+ try {
1250
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1251
+ _assertClass(xpriv, WasmBIP32);
1252
+ wasm.bitgopsbt_sign_all_musig2_inputs(retptr, this.__wbg_ptr, xpriv.__wbg_ptr);
1253
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1254
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1255
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1256
+ if (r2) {
1257
+ throw takeObject(r1);
1258
+ }
1259
+ return takeObject(r0);
1260
+ } finally {
1261
+ wasm.__wbindgen_add_to_stack_pointer(16);
1262
+ }
1263
+ }
1264
+ /**
1265
+ * Sign all non-MuSig2 wallet inputs in a single efficient pass.
1266
+ *
1267
+ * This signs all ECDSA (P2SH, P2SH-P2WSH, P2WSH) and Taproot script path (P2TR)
1268
+ * inputs that match the provided xpriv. MuSig2 keypath inputs are skipped.
1269
+ *
1270
+ * This is the most efficient way to sign wallet inputs. After calling this,
1271
+ * sign any MuSig2 inputs using `sign_all_musig2_inputs()` or `sign_musig2_input()`.
1272
+ *
1273
+ * # Arguments
1274
+ * - `xpriv`: The extended private key as a WasmBIP32 instance
1275
+ *
1276
+ * # Returns
1277
+ * - `Ok(JsValue)` with an array of input indices that were signed
1278
+ * - `Err(WasmUtxoError)` if signing fails
1279
+ * @param {WasmBIP32} xpriv
1280
+ * @returns {any}
1281
+ */
1282
+ sign_all_wallet_inputs(xpriv) {
1283
+ try {
1284
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1285
+ _assertClass(xpriv, WasmBIP32);
1286
+ wasm.bitgopsbt_sign_all_wallet_inputs(retptr, this.__wbg_ptr, xpriv.__wbg_ptr);
1287
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1288
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1289
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1290
+ if (r2) {
1291
+ throw takeObject(r1);
1292
+ }
1293
+ return takeObject(r0);
1294
+ } finally {
1295
+ wasm.__wbindgen_add_to_stack_pointer(16);
1296
+ }
1297
+ }
1106
1298
  /**
1107
1299
  * Add an output to the PSBT by address
1108
1300
  *
@@ -1292,6 +1484,72 @@ class BitGoPsbt {
1292
1484
  wasm.__wbindgen_add_to_stack_pointer(16);
1293
1485
  }
1294
1486
  }
1487
+ /**
1488
+ * Sign a single input with an extended private key, using save/restore for ECDSA inputs.
1489
+ *
1490
+ * For MuSig2 inputs, this returns an error (use sign_with_xpriv which handles FirstRound).
1491
+ * For ECDSA inputs, this clones the PSBT, signs all, then copies only the target
1492
+ * input's signatures back.
1493
+ *
1494
+ * **Important:** This is NOT faster than `sign_all_with_xpriv` for ECDSA inputs.
1495
+ * The underlying miniscript library signs all inputs regardless. This method
1496
+ * just prevents signatures from being added to other inputs.
1497
+ *
1498
+ * # Arguments
1499
+ * - `input_index`: The index of the input to sign (0-based)
1500
+ * - `xpriv`: The extended private key as a WasmBIP32 instance
1501
+ *
1502
+ * # Returns
1503
+ * - `Ok(())` if the input was signed
1504
+ * - `Err(WasmUtxoError)` if signing fails
1505
+ * @param {number} input_index
1506
+ * @param {WasmBIP32} xpriv
1507
+ */
1508
+ sign_single_input_with_xpriv(input_index, xpriv) {
1509
+ try {
1510
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1511
+ _assertClass(xpriv, WasmBIP32);
1512
+ wasm.bitgopsbt_sign_single_input_with_xpriv(retptr, this.__wbg_ptr, input_index, xpriv.__wbg_ptr);
1513
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1514
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1515
+ if (r1) {
1516
+ throw takeObject(r0);
1517
+ }
1518
+ } finally {
1519
+ wasm.__wbindgen_add_to_stack_pointer(16);
1520
+ }
1521
+ }
1522
+ /**
1523
+ * Sign all replay protection inputs with a raw private key.
1524
+ *
1525
+ * This iterates through all inputs looking for P2SH-P2PK (replay protection) inputs
1526
+ * that match the provided public key and signs them.
1527
+ *
1528
+ * # Arguments
1529
+ * - `ecpair`: The ECPair containing the private key
1530
+ *
1531
+ * # Returns
1532
+ * - `Ok(JsValue)` with an array of input indices that were signed
1533
+ * - `Err(WasmUtxoError)` if signing fails
1534
+ * @param {WasmECPair} ecpair
1535
+ * @returns {any}
1536
+ */
1537
+ sign_replay_protection_inputs(ecpair) {
1538
+ try {
1539
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1540
+ _assertClass(ecpair, WasmECPair);
1541
+ wasm.bitgopsbt_sign_all_replay_protection_inputs(retptr, this.__wbg_ptr, ecpair.__wbg_ptr);
1542
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1543
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1544
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1545
+ if (r2) {
1546
+ throw takeObject(r1);
1547
+ }
1548
+ return takeObject(r0);
1549
+ } finally {
1550
+ wasm.__wbindgen_add_to_stack_pointer(16);
1551
+ }
1552
+ }
1295
1553
  /**
1296
1554
  * Parse outputs with wallet keys to identify which outputs belong to a wallet
1297
1555
  *
@@ -1318,6 +1576,71 @@ class BitGoPsbt {
1318
1576
  wasm.__wbindgen_add_to_stack_pointer(16);
1319
1577
  }
1320
1578
  }
1579
+ /**
1580
+ * Sign a single input with a raw private key, using save/restore for regular inputs.
1581
+ *
1582
+ * For replay protection inputs (P2SH-P2PK), this uses direct signing which is
1583
+ * already single-input. For regular inputs, this clones the PSBT, signs all,
1584
+ * then copies only the target input's signatures back.
1585
+ *
1586
+ * **Important:** This is NOT faster than signing all inputs for regular (non-RP) inputs.
1587
+ * The underlying miniscript library signs all inputs regardless.
1588
+ *
1589
+ * # Arguments
1590
+ * - `input_index`: The index of the input to sign (0-based)
1591
+ * - `ecpair`: The ECPair containing the private key
1592
+ *
1593
+ * # Returns
1594
+ * - `Ok(())` if the input was signed
1595
+ * - `Err(WasmUtxoError)` if signing fails
1596
+ * @param {number} input_index
1597
+ * @param {WasmECPair} ecpair
1598
+ */
1599
+ sign_single_input_with_privkey(input_index, ecpair) {
1600
+ try {
1601
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1602
+ _assertClass(ecpair, WasmECPair);
1603
+ wasm.bitgopsbt_sign_single_input_with_privkey(retptr, this.__wbg_ptr, input_index, ecpair.__wbg_ptr);
1604
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1605
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1606
+ if (r1) {
1607
+ throw takeObject(r0);
1608
+ }
1609
+ } finally {
1610
+ wasm.__wbindgen_add_to_stack_pointer(16);
1611
+ }
1612
+ }
1613
+ /**
1614
+ * Sign all replay protection inputs with a raw private key.
1615
+ *
1616
+ * This iterates through all inputs looking for P2SH-P2PK (replay protection) inputs
1617
+ * that match the provided public key and signs them.
1618
+ *
1619
+ * # Arguments
1620
+ * - `ecpair`: The ECPair containing the private key
1621
+ *
1622
+ * # Returns
1623
+ * - `Ok(JsValue)` with an array of input indices that were signed
1624
+ * - `Err(WasmUtxoError)` if signing fails
1625
+ * @param {WasmECPair} ecpair
1626
+ * @returns {any}
1627
+ */
1628
+ sign_all_replay_protection_inputs(ecpair) {
1629
+ try {
1630
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1631
+ _assertClass(ecpair, WasmECPair);
1632
+ wasm.bitgopsbt_sign_all_replay_protection_inputs(retptr, this.__wbg_ptr, ecpair.__wbg_ptr);
1633
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1634
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1635
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1636
+ if (r2) {
1637
+ throw takeObject(r1);
1638
+ }
1639
+ return takeObject(r0);
1640
+ } finally {
1641
+ wasm.__wbindgen_add_to_stack_pointer(16);
1642
+ }
1643
+ }
1321
1644
  /**
1322
1645
  * Parse transaction with wallet keys to identify wallet inputs/outputs
1323
1646
  * @param {WasmRootWalletKeys} wallet_keys
Binary file
@@ -2,16 +2,60 @@
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const __wbg_addressnamespace_free: (a: number, b: number) => void;
5
+ export const __wbg_inscriptionsnamespace_free: (a: number, b: number) => void;
6
+ export const __wbg_utxolibcompatnamespace_free: (a: number, b: number) => void;
7
+ export const __wbg_wasmtransaction_free: (a: number, b: number) => void;
8
+ export const __wbg_wasmzcashtransaction_free: (a: number, b: number) => void;
9
+ export const __wbg_wrapdescriptor_free: (a: number, b: number) => void;
10
+ export const __wbg_wrapminiscript_free: (a: number, b: number) => void;
11
+ export const __wbg_wrappsbt_free: (a: number, b: number) => void;
12
+ export const addressnamespace_from_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
13
+ export const addressnamespace_to_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number) => void;
14
+ export const inscriptionsnamespace_create_inscription_reveal_data: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
15
+ export const inscriptionsnamespace_sign_reveal_transaction: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: bigint) => void;
16
+ export const utxolibcompatnamespace_from_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
17
+ export const utxolibcompatnamespace_to_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
18
+ export const wasmtransaction_from_bytes: (a: number, b: number, c: number) => void;
19
+ export const wasmtransaction_get_vsize: (a: number) => number;
20
+ export const wasmtransaction_to_bytes: (a: number, b: number) => void;
21
+ export const wasmzcashtransaction_from_bytes: (a: number, b: number, c: number) => void;
22
+ export const wasmzcashtransaction_to_bytes: (a: number, b: number) => void;
23
+ export const wrapdescriptor_atDerivationIndex: (a: number, b: number, c: number) => void;
24
+ export const wrapdescriptor_descType: (a: number, b: number) => void;
25
+ export const wrapdescriptor_encode: (a: number, b: number) => void;
26
+ export const wrapdescriptor_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
27
+ export const wrapdescriptor_fromStringDetectType: (a: number, b: number, c: number) => void;
28
+ export const wrapdescriptor_hasWildcard: (a: number) => number;
29
+ export const wrapdescriptor_maxWeightToSatisfy: (a: number, b: number) => void;
30
+ export const wrapdescriptor_node: (a: number, b: number) => void;
31
+ export const wrapdescriptor_scriptPubkey: (a: number, b: number) => void;
32
+ export const wrapdescriptor_toAsmString: (a: number, b: number) => void;
33
+ export const wrapdescriptor_toString: (a: number, b: number) => void;
34
+ export const wrapminiscript_encode: (a: number, b: number) => void;
35
+ export const wrapminiscript_fromBitcoinScript: (a: number, b: number, c: number, d: number, e: number) => void;
36
+ export const wrapminiscript_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
37
+ export const wrapminiscript_node: (a: number, b: number) => void;
38
+ export const wrapminiscript_toAsmString: (a: number, b: number) => void;
39
+ export const wrapminiscript_toString: (a: number, b: number) => void;
40
+ export const wrappsbt_addInput: (a: number, b: number, c: number, d: number, e: number, f: bigint, g: number, h: number, i: number) => void;
41
+ export const wrappsbt_addOutput: (a: number, b: number, c: number, d: bigint) => number;
42
+ export const wrappsbt_clone: (a: number) => number;
43
+ export const wrappsbt_deserialize: (a: number, b: number, c: number) => void;
44
+ export const wrappsbt_finalize: (a: number, b: number) => void;
45
+ export const wrappsbt_getUnsignedTx: (a: number, b: number) => void;
46
+ export const wrappsbt_new: (a: number, b: number) => number;
47
+ export const wrappsbt_serialize: (a: number, b: number) => void;
48
+ export const wrappsbt_signWithPrv: (a: number, b: number, c: number, d: number) => void;
49
+ export const wrappsbt_signWithXprv: (a: number, b: number, c: number, d: number) => void;
50
+ export const wrappsbt_updateInputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
51
+ export const wrappsbt_updateOutputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
5
52
  export const __wbg_bip322namespace_free: (a: number, b: number) => void;
6
53
  export const __wbg_bitgopsbt_free: (a: number, b: number) => void;
7
54
  export const __wbg_fixedscriptwalletnamespace_free: (a: number, b: number) => void;
8
- export const __wbg_utxolibcompatnamespace_free: (a: number, b: number) => void;
9
55
  export const __wbg_wasmbip32_free: (a: number, b: number) => void;
10
56
  export const __wbg_wasmdimensions_free: (a: number, b: number) => void;
11
57
  export const __wbg_wasmecpair_free: (a: number, b: number) => void;
12
- export const __wbg_wasmreplayprotection_free: (a: number, b: number) => void;
13
- export const addressnamespace_from_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
14
- export const addressnamespace_to_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number) => void;
58
+ export const __wbg_wasmrootwalletkeys_free: (a: number, b: number) => void;
15
59
  export const bip322namespace_add_bip322_input: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number) => void;
16
60
  export const bip322namespace_verify_bip322_psbt_input: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
17
61
  export const bip322namespace_verify_bip322_psbt_input_with_pubkeys: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => void;
@@ -33,11 +77,18 @@ export const bitgopsbt_extract_transaction: (a: number, b: number) => void;
33
77
  export const bitgopsbt_finalize_all_inputs: (a: number, b: number) => void;
34
78
  export const bitgopsbt_from_bytes: (a: number, b: number, c: number, d: number, e: number) => void;
35
79
  export const bitgopsbt_generate_musig2_nonces: (a: number, b: number, c: number, d: number, e: number) => void;
80
+ export const bitgopsbt_is_musig2_input: (a: number, b: number) => number;
36
81
  export const bitgopsbt_lock_time: (a: number) => number;
37
82
  export const bitgopsbt_network: (a: number, b: number) => void;
38
83
  export const bitgopsbt_parse_outputs_with_wallet_keys: (a: number, b: number, c: number, d: number, e: number) => void;
39
84
  export const bitgopsbt_parse_transaction_with_wallet_keys: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
40
85
  export const bitgopsbt_serialize: (a: number, b: number) => void;
86
+ export const bitgopsbt_sign_all_musig2_inputs: (a: number, b: number, c: number) => void;
87
+ export const bitgopsbt_sign_all_replay_protection_inputs: (a: number, b: number, c: number) => void;
88
+ export const bitgopsbt_sign_all_wallet_inputs: (a: number, b: number, c: number) => void;
89
+ export const bitgopsbt_sign_musig2_input: (a: number, b: number, c: number, d: number) => void;
90
+ export const bitgopsbt_sign_single_input_with_privkey: (a: number, b: number, c: number, d: number) => void;
91
+ export const bitgopsbt_sign_single_input_with_xpriv: (a: number, b: number, c: number, d: number) => void;
41
92
  export const bitgopsbt_sign_with_privkey: (a: number, b: number, c: number, d: number) => void;
42
93
  export const bitgopsbt_sign_with_xpriv: (a: number, b: number, c: number, d: number) => void;
43
94
  export const bitgopsbt_unsigned_txid: (a: number, b: number) => void;
@@ -52,8 +103,6 @@ export const fixedscriptwalletnamespace_chain_code_table: () => number;
52
103
  export const fixedscriptwalletnamespace_output_script: (a: number, b: number, c: number, d: number, e: number) => void;
53
104
  export const fixedscriptwalletnamespace_output_script_with_network_str: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
54
105
  export const fixedscriptwalletnamespace_supports_script_type: (a: number, b: number, c: number, d: number, e: number) => void;
55
- export const utxolibcompatnamespace_from_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
56
- export const utxolibcompatnamespace_to_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
57
106
  export const wasmbip32_chain_code: (a: number) => number;
58
107
  export const wasmbip32_depth: (a: number) => number;
59
108
  export const wasmbip32_derive: (a: number, b: number, c: number) => void;
@@ -99,61 +148,22 @@ export const wasmecpair_public_key: (a: number) => number;
99
148
  export const wasmecpair_to_wif: (a: number, b: number) => void;
100
149
  export const wasmecpair_to_wif_mainnet: (a: number, b: number) => void;
101
150
  export const wasmecpair_to_wif_testnet: (a: number, b: number) => void;
102
- export const wasmreplayprotection_from_addresses: (a: number, b: number, c: number, d: number, e: number) => void;
103
- export const wasmreplayprotection_from_output_scripts: (a: number, b: number) => number;
104
- export const wasmreplayprotection_from_public_keys: (a: number, b: number, c: number) => void;
105
- export const wasmbip32_from_bip32_properties: (a: number, b: number) => void;
106
- export const __wbg_inscriptionsnamespace_free: (a: number, b: number) => void;
107
- export const __wbg_wasmdashtransaction_free: (a: number, b: number) => void;
108
- export const __wbg_wasmrootwalletkeys_free: (a: number, b: number) => void;
109
- export const __wbg_wasmtransaction_free: (a: number, b: number) => void;
110
- export const __wbg_wasmzcashtransaction_free: (a: number, b: number) => void;
111
- export const __wbg_wrapdescriptor_free: (a: number, b: number) => void;
112
- export const __wbg_wrapminiscript_free: (a: number, b: number) => void;
113
- export const __wbg_wrappsbt_free: (a: number, b: number) => void;
114
- export const inscriptionsnamespace_create_inscription_reveal_data: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
115
- export const inscriptionsnamespace_sign_reveal_transaction: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: bigint) => void;
116
- export const wasmdashtransaction_from_bytes: (a: number, b: number, c: number) => void;
117
- export const wasmdashtransaction_to_bytes: (a: number, b: number) => void;
118
151
  export const wasmrootwalletkeys_backup_key: (a: number) => number;
119
152
  export const wasmrootwalletkeys_bitgo_key: (a: number) => number;
120
153
  export const wasmrootwalletkeys_new: (a: number, b: number, c: number, d: number) => void;
121
154
  export const wasmrootwalletkeys_user_key: (a: number) => number;
122
155
  export const wasmrootwalletkeys_with_derivation_prefixes: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
123
- export const wasmtransaction_from_bytes: (a: number, b: number, c: number) => void;
124
- export const wasmtransaction_get_vsize: (a: number) => number;
125
- export const wasmtransaction_to_bytes: (a: number, b: number) => void;
126
- export const wasmzcashtransaction_from_bytes: (a: number, b: number, c: number) => void;
127
- export const wasmzcashtransaction_to_bytes: (a: number, b: number) => void;
128
- export const wrapdescriptor_atDerivationIndex: (a: number, b: number, c: number) => void;
129
- export const wrapdescriptor_descType: (a: number, b: number) => void;
130
- export const wrapdescriptor_encode: (a: number, b: number) => void;
131
- export const wrapdescriptor_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
132
- export const wrapdescriptor_fromStringDetectType: (a: number, b: number, c: number) => void;
133
- export const wrapdescriptor_hasWildcard: (a: number) => number;
134
- export const wrapdescriptor_maxWeightToSatisfy: (a: number, b: number) => void;
135
- export const wrapdescriptor_node: (a: number, b: number) => void;
136
- export const wrapdescriptor_scriptPubkey: (a: number, b: number) => void;
137
- export const wrapdescriptor_toAsmString: (a: number, b: number) => void;
138
- export const wrapdescriptor_toString: (a: number, b: number) => void;
139
- export const wrapminiscript_encode: (a: number, b: number) => void;
140
- export const wrapminiscript_fromBitcoinScript: (a: number, b: number, c: number, d: number, e: number) => void;
141
- export const wrapminiscript_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
142
- export const wrapminiscript_node: (a: number, b: number) => void;
143
- export const wrapminiscript_toAsmString: (a: number, b: number) => void;
144
- export const wrapminiscript_toString: (a: number, b: number) => void;
145
- export const wrappsbt_addInput: (a: number, b: number, c: number, d: number, e: number, f: bigint, g: number, h: number, i: number) => void;
146
- export const wrappsbt_addOutput: (a: number, b: number, c: number, d: bigint) => number;
147
- export const wrappsbt_clone: (a: number) => number;
148
- export const wrappsbt_deserialize: (a: number, b: number, c: number) => void;
149
- export const wrappsbt_finalize: (a: number, b: number) => void;
150
- export const wrappsbt_getUnsignedTx: (a: number, b: number) => void;
151
- export const wrappsbt_new: (a: number, b: number) => number;
152
- export const wrappsbt_serialize: (a: number, b: number) => void;
153
- export const wrappsbt_signWithPrv: (a: number, b: number, c: number, d: number) => void;
154
- export const wrappsbt_signWithXprv: (a: number, b: number, c: number, d: number) => void;
155
- export const wrappsbt_updateInputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
156
- export const wrappsbt_updateOutputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
156
+ export const wasmbip32_from_bip32_properties: (a: number, b: number) => void;
157
+ export const bitgopsbt_sign_all_with_xpriv: (a: number, b: number, c: number) => void;
158
+ export const bitgopsbt_sign_replay_protection_inputs: (a: number, b: number, c: number) => void;
159
+ export const bitgopsbt_sign_wallet_input: (a: number, b: number, c: number, d: number) => void;
160
+ export const __wbg_wasmdashtransaction_free: (a: number, b: number) => void;
161
+ export const __wbg_wasmreplayprotection_free: (a: number, b: number) => void;
162
+ export const wasmdashtransaction_from_bytes: (a: number, b: number, c: number) => void;
163
+ export const wasmdashtransaction_to_bytes: (a: number, b: number) => void;
164
+ export const wasmreplayprotection_from_addresses: (a: number, b: number, c: number, d: number, e: number) => void;
165
+ export const wasmreplayprotection_from_output_scripts: (a: number, b: number) => number;
166
+ export const wasmreplayprotection_from_public_keys: (a: number, b: number, c: number) => void;
157
167
  export const rustsecp256k1_v0_10_0_context_create: (a: number) => number;
158
168
  export const rustsecp256k1_v0_10_0_context_destroy: (a: number) => void;
159
169
  export const rustsecp256k1_v0_10_0_default_error_callback_fn: (a: number, b: number) => void;
@@ -138,3 +138,10 @@ export declare class BIP32 implements BIP32Interface {
138
138
  */
139
139
  get wasm(): WasmBIP32;
140
140
  }
141
+ /**
142
+ * Type guard to check if a value is a BIP32Arg
143
+ *
144
+ * @param key - The value to check
145
+ * @returns true if the value is a BIP32Arg (string, BIP32, WasmBIP32, or BIP32Interface)
146
+ */
147
+ export declare function isBIP32Arg(key: unknown): key is BIP32Arg;
@@ -171,3 +171,18 @@ export class BIP32 {
171
171
  return this._wasm;
172
172
  }
173
173
  }
174
+ /**
175
+ * Type guard to check if a value is a BIP32Arg
176
+ *
177
+ * @param key - The value to check
178
+ * @returns true if the value is a BIP32Arg (string, BIP32, WasmBIP32, or BIP32Interface)
179
+ */
180
+ export function isBIP32Arg(key) {
181
+ return (typeof key === "string" ||
182
+ key instanceof BIP32 ||
183
+ key instanceof WasmBIP32 ||
184
+ (typeof key === "object" &&
185
+ key !== null &&
186
+ "derive" in key &&
187
+ typeof key.derive === "function"));
188
+ }
@@ -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
  *