@bitgo/wasm-utxo 1.27.0 → 1.29.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.
Files changed (41) hide show
  1. package/dist/cjs/js/bip32.d.ts +7 -0
  2. package/dist/cjs/js/bip32.js +16 -0
  3. package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.d.ts +60 -26
  4. package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.js +56 -36
  5. package/dist/cjs/js/fixedScriptWallet/chains.d.ts +5 -0
  6. package/dist/cjs/js/fixedScriptWallet/chains.js +6 -2
  7. package/dist/cjs/js/fixedScriptWallet/index.d.ts +19 -2
  8. package/dist/cjs/js/fixedScriptWallet/index.js +25 -1
  9. package/dist/cjs/js/fixedScriptWallet/scriptType.d.ts +15 -5
  10. package/dist/cjs/js/fixedScriptWallet/scriptType.js +28 -0
  11. package/dist/cjs/js/testutils/AcidTest.d.ts +132 -0
  12. package/dist/cjs/js/testutils/AcidTest.js +306 -0
  13. package/dist/cjs/js/testutils/index.d.ts +2 -0
  14. package/dist/cjs/js/testutils/index.js +18 -0
  15. package/dist/cjs/js/testutils/keys.d.ts +76 -0
  16. package/dist/cjs/js/testutils/keys.js +154 -0
  17. package/dist/cjs/js/wasm/wasm_utxo.d.ts +183 -0
  18. package/dist/cjs/js/wasm/wasm_utxo.js +354 -0
  19. package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
  20. package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +67 -56
  21. package/dist/esm/js/bip32.d.ts +7 -0
  22. package/dist/esm/js/bip32.js +15 -0
  23. package/dist/esm/js/fixedScriptWallet/BitGoPsbt.d.ts +60 -26
  24. package/dist/esm/js/fixedScriptWallet/BitGoPsbt.js +57 -37
  25. package/dist/esm/js/fixedScriptWallet/chains.d.ts +5 -0
  26. package/dist/esm/js/fixedScriptWallet/chains.js +6 -3
  27. package/dist/esm/js/fixedScriptWallet/index.d.ts +19 -2
  28. package/dist/esm/js/fixedScriptWallet/index.js +21 -1
  29. package/dist/esm/js/fixedScriptWallet/scriptType.d.ts +15 -5
  30. package/dist/esm/js/fixedScriptWallet/scriptType.js +27 -1
  31. package/dist/esm/js/testutils/AcidTest.d.ts +132 -0
  32. package/dist/esm/js/testutils/AcidTest.js +302 -0
  33. package/dist/esm/js/testutils/index.d.ts +2 -0
  34. package/dist/esm/js/testutils/index.js +2 -0
  35. package/dist/esm/js/testutils/keys.d.ts +76 -0
  36. package/dist/esm/js/testutils/keys.js +113 -0
  37. package/dist/esm/js/wasm/wasm_utxo.d.ts +183 -0
  38. package/dist/esm/js/wasm/wasm_utxo_bg.js +354 -0
  39. package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
  40. package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +67 -56
  41. package/package.json +2 -1
@@ -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;
@@ -49,11 +100,10 @@ export const bitgopsbt_version_group_id: (a: number) => number;
49
100
  export const fixedscriptwalletnamespace_address: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
50
101
  export const fixedscriptwalletnamespace_address_with_network_str: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
51
102
  export const fixedscriptwalletnamespace_chain_code_table: () => number;
103
+ export const fixedscriptwalletnamespace_create_op_return_script: (a: number, b: number, c: number) => void;
52
104
  export const fixedscriptwalletnamespace_output_script: (a: number, b: number, c: number, d: number, e: number) => void;
53
105
  export const fixedscriptwalletnamespace_output_script_with_network_str: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
54
106
  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
107
  export const wasmbip32_chain_code: (a: number) => number;
58
108
  export const wasmbip32_depth: (a: number) => number;
59
109
  export const wasmbip32_derive: (a: number, b: number, c: number) => void;
@@ -99,61 +149,22 @@ export const wasmecpair_public_key: (a: number) => number;
99
149
  export const wasmecpair_to_wif: (a: number, b: number) => void;
100
150
  export const wasmecpair_to_wif_mainnet: (a: number, b: number) => void;
101
151
  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
152
  export const wasmrootwalletkeys_backup_key: (a: number) => number;
119
153
  export const wasmrootwalletkeys_bitgo_key: (a: number) => number;
120
154
  export const wasmrootwalletkeys_new: (a: number, b: number, c: number, d: number) => void;
121
155
  export const wasmrootwalletkeys_user_key: (a: number) => number;
122
156
  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;
157
+ export const wasmbip32_from_bip32_properties: (a: number, b: number) => void;
158
+ export const bitgopsbt_sign_replay_protection_inputs: (a: number, b: number, c: number) => void;
159
+ export const bitgopsbt_sign_all_with_xpriv: (a: number, b: number, c: number) => void;
160
+ export const bitgopsbt_sign_wallet_input: (a: number, b: number, c: number, d: number) => void;
161
+ export const __wbg_wasmdashtransaction_free: (a: number, b: number) => void;
162
+ export const __wbg_wasmreplayprotection_free: (a: number, b: number) => void;
163
+ export const wasmdashtransaction_from_bytes: (a: number, b: number, c: number) => void;
164
+ export const wasmdashtransaction_to_bytes: (a: number, b: number) => void;
165
+ export const wasmreplayprotection_from_addresses: (a: number, b: number, c: number, d: number, e: number) => void;
166
+ export const wasmreplayprotection_from_output_scripts: (a: number, b: number) => number;
167
+ export const wasmreplayprotection_from_public_keys: (a: number, b: number, c: number) => void;
157
168
  export const rustsecp256k1_v0_10_0_context_create: (a: number) => number;
158
169
  export const rustsecp256k1_v0_10_0_context_destroy: (a: number) => void;
159
170
  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
  *
@@ -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
  }
@@ -5,6 +5,11 @@ export declare const chainCodes: readonly [0, 1, 10, 11, 20, 21, 30, 31, 40, 41]
5
5
  export type ChainCode = (typeof chainCodes)[number];
6
6
  /** Whether a chain is for receiving (external) or change (internal) addresses */
7
7
  export type Scope = "internal" | "external";
8
+ /**
9
+ * Assert that a number is a valid chain code.
10
+ * @throws Error if the number is not a valid chain code
11
+ */
12
+ export declare function assertChainCode(n: number): ChainCode;
8
13
  /**
9
14
  * ChainCode namespace with utility functions for working with chain codes.
10
15
  */
@@ -11,10 +11,13 @@ export const chainCodes = [0, 1, 10, 11, 20, 21, 30, 31, 40, 41];
11
11
  const chainCodeSet = new Set(chainCodes);
12
12
  const chainToMeta = new Map();
13
13
  const scriptTypeToChain = new Map();
14
- // Initialize from WASM (called once at load time)
15
- function assertChainCode(n) {
14
+ /**
15
+ * Assert that a number is a valid chain code.
16
+ * @throws Error if the number is not a valid chain code
17
+ */
18
+ export function assertChainCode(n) {
16
19
  if (!chainCodeSet.has(n)) {
17
- throw new Error(`Invalid chain code from WASM: ${n}`);
20
+ throw new Error(`Invalid chain code: ${n}`);
18
21
  }
19
22
  return n;
20
23
  }
@@ -3,8 +3,8 @@ export { RootWalletKeys, type WalletKeysArg, type IWalletKeys } from "./RootWall
3
3
  export { ReplayProtection, type ReplayProtectionArg } from "./ReplayProtection.js";
4
4
  export { outputScript, address } from "./address.js";
5
5
  export { Dimensions } from "./Dimensions.js";
6
- export { type OutputScriptType, type InputScriptType, type ScriptType } from "./scriptType.js";
7
- export { ChainCode, chainCodes, type Scope } from "./chains.js";
6
+ export { outputScriptTypes, inputScriptTypes, type OutputScriptType, type InputScriptType, type ScriptType, } from "./scriptType.js";
7
+ export { ChainCode, chainCodes, assertChainCode, type Scope } from "./chains.js";
8
8
  export { BitGoPsbt, type NetworkName, type ScriptId, type ParsedInput, type ParsedOutput, type ParsedTransaction, type SignPath, type CreateEmptyOptions, type AddInputOptions, type AddOutputOptions, type AddWalletInputOptions, type AddWalletOutputOptions, } from "./BitGoPsbt.js";
9
9
  export { ZcashBitGoPsbt, type ZcashNetworkName, type CreateEmptyZcashOptions, } from "./ZcashBitGoPsbt.js";
10
10
  import type { ScriptType } from "./scriptType.js";
@@ -34,3 +34,20 @@ import type { ScriptType } from "./scriptType.js";
34
34
  * ```
35
35
  */
36
36
  export declare function supportsScriptType(coin: CoinName, scriptType: ScriptType): boolean;
37
+ /**
38
+ * Create an OP_RETURN output script with optional data
39
+ *
40
+ * @param data - Optional data bytes to include in the OP_RETURN script
41
+ * @returns The OP_RETURN script as a Uint8Array
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * // Empty OP_RETURN
46
+ * const script = createOpReturnScript();
47
+ *
48
+ * // OP_RETURN with data
49
+ * const data = new Uint8Array([1, 2, 3, 4]);
50
+ * const script = createOpReturnScript(data);
51
+ * ```
52
+ */
53
+ export declare function createOpReturnScript(data?: Uint8Array): Uint8Array;
@@ -3,7 +3,8 @@ export { RootWalletKeys } from "./RootWalletKeys.js";
3
3
  export { ReplayProtection } from "./ReplayProtection.js";
4
4
  export { outputScript, address } from "./address.js";
5
5
  export { Dimensions } from "./Dimensions.js";
6
- export { ChainCode, chainCodes } from "./chains.js";
6
+ export { outputScriptTypes, inputScriptTypes, } from "./scriptType.js";
7
+ export { ChainCode, chainCodes, assertChainCode } from "./chains.js";
7
8
  // Bitcoin-like PSBT (for all non-Zcash networks)
8
9
  export { BitGoPsbt, } from "./BitGoPsbt.js";
9
10
  // Zcash-specific PSBT subclass
@@ -36,3 +37,22 @@ export { ZcashBitGoPsbt, } from "./ZcashBitGoPsbt.js";
36
37
  export function supportsScriptType(coin, scriptType) {
37
38
  return FixedScriptWalletNamespace.supports_script_type(coin, scriptType);
38
39
  }
40
+ /**
41
+ * Create an OP_RETURN output script with optional data
42
+ *
43
+ * @param data - Optional data bytes to include in the OP_RETURN script
44
+ * @returns The OP_RETURN script as a Uint8Array
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * // Empty OP_RETURN
49
+ * const script = createOpReturnScript();
50
+ *
51
+ * // OP_RETURN with data
52
+ * const data = new Uint8Array([1, 2, 3, 4]);
53
+ * const script = createOpReturnScript(data);
54
+ * ```
55
+ */
56
+ export function createOpReturnScript(data) {
57
+ return FixedScriptWalletNamespace.create_op_return_script(data);
58
+ }
@@ -1,16 +1,26 @@
1
1
  /**
2
- * Fixed-script wallet output script types (2-of-3 multisig)
2
+ * All output script types for fixed-script wallets (2-of-3 multisig)
3
3
  *
4
- * This type represents the abstract script type, independent of chain (external/internal).
4
+ * This represents the abstract script type, independent of chain (external/internal).
5
5
  * Use this for checking network support or when you need the script type without derivation info.
6
6
  */
7
- export type OutputScriptType = "p2sh" | "p2shP2wsh" | "p2wsh" | "p2tr" | "p2trLegacy" | "p2trMusig2";
7
+ export declare const outputScriptTypes: readonly ["p2sh", "p2shP2wsh", "p2wsh", "p2trLegacy", "p2trMusig2"];
8
8
  /**
9
- * Input script types for fixed-script wallets
9
+ * Output script type for fixed-script wallets
10
+ *
11
+ * Note: "p2tr" is an alias for "p2trLegacy" for backward compatibility.
12
+ */
13
+ export type OutputScriptType = (typeof outputScriptTypes)[number] | "p2tr";
14
+ /**
15
+ * All input script types for fixed-script wallets
10
16
  *
11
17
  * These are more specific than output types and include single-sig and taproot variants.
12
18
  */
13
- export type InputScriptType = "p2shP2pk" | "p2sh" | "p2shP2wsh" | "p2wsh" | "p2trLegacy" | "p2trMusig2ScriptPath" | "p2trMusig2KeyPath";
19
+ export declare const inputScriptTypes: readonly ["p2shP2pk", "p2sh", "p2shP2wsh", "p2wsh", "p2trLegacy", "p2trMusig2ScriptPath", "p2trMusig2KeyPath"];
20
+ /**
21
+ * Input script type for fixed-script wallets
22
+ */
23
+ export type InputScriptType = (typeof inputScriptTypes)[number];
14
24
  /**
15
25
  * Union of all script types that can be checked for network support
16
26
  */
@@ -1 +1,27 @@
1
- export {};
1
+ /**
2
+ * All output script types for fixed-script wallets (2-of-3 multisig)
3
+ *
4
+ * This represents the abstract script type, independent of chain (external/internal).
5
+ * Use this for checking network support or when you need the script type without derivation info.
6
+ */
7
+ export const outputScriptTypes = [
8
+ "p2sh",
9
+ "p2shP2wsh",
10
+ "p2wsh",
11
+ "p2trLegacy",
12
+ "p2trMusig2",
13
+ ];
14
+ /**
15
+ * All input script types for fixed-script wallets
16
+ *
17
+ * These are more specific than output types and include single-sig and taproot variants.
18
+ */
19
+ export const inputScriptTypes = [
20
+ "p2shP2pk",
21
+ "p2sh",
22
+ "p2shP2wsh",
23
+ "p2wsh",
24
+ "p2trLegacy",
25
+ "p2trMusig2ScriptPath",
26
+ "p2trMusig2KeyPath",
27
+ ];