@bitgo/wasm-utxo 1.7.0 → 1.9.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 (56) hide show
  1. package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.d.ts +99 -0
  2. package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.js +122 -0
  3. package/dist/cjs/js/wasm/wasm_utxo.d.ts +86 -0
  4. package/dist/cjs/js/wasm/wasm_utxo.js +276 -24
  5. package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
  6. package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +21 -17
  7. package/dist/esm/js/fixedScriptWallet/BitGoPsbt.d.ts +99 -0
  8. package/dist/esm/js/fixedScriptWallet/BitGoPsbt.js +122 -0
  9. package/dist/esm/js/wasm/wasm_utxo.d.ts +86 -0
  10. package/dist/esm/js/wasm/wasm_utxo_bg.js +276 -24
  11. package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
  12. package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +21 -17
  13. package/package.json +3 -3
  14. package/dist/cjs/package.json +0 -1
  15. package/dist/cjs/tsconfig.cjs.tsbuildinfo +0 -1
  16. package/dist/esm/test/address/utxolibCompat.d.ts +0 -1
  17. package/dist/esm/test/address/utxolibCompat.js +0 -107
  18. package/dist/esm/test/ast/formatNode.d.ts +0 -1
  19. package/dist/esm/test/ast/formatNode.js +0 -15
  20. package/dist/esm/test/bip32.d.ts +0 -1
  21. package/dist/esm/test/bip32.js +0 -242
  22. package/dist/esm/test/descriptorFixtures.d.ts +0 -25
  23. package/dist/esm/test/descriptorFixtures.js +0 -605
  24. package/dist/esm/test/descriptorUtil.d.ts +0 -13
  25. package/dist/esm/test/descriptorUtil.js +0 -52
  26. package/dist/esm/test/ecpair.d.ts +0 -1
  27. package/dist/esm/test/ecpair.js +0 -137
  28. package/dist/esm/test/fixedScript/address.d.ts +0 -1
  29. package/dist/esm/test/fixedScript/address.js +0 -66
  30. package/dist/esm/test/fixedScript/finalizeExtract.d.ts +0 -1
  31. package/dist/esm/test/fixedScript/finalizeExtract.js +0 -66
  32. package/dist/esm/test/fixedScript/fixtureUtil.d.ts +0 -95
  33. package/dist/esm/test/fixedScript/fixtureUtil.js +0 -55
  34. package/dist/esm/test/fixedScript/parseTransactionWithWalletKeys.d.ts +0 -1
  35. package/dist/esm/test/fixedScript/parseTransactionWithWalletKeys.js +0 -168
  36. package/dist/esm/test/fixedScript/verifySignature.d.ts +0 -1
  37. package/dist/esm/test/fixedScript/verifySignature.js +0 -187
  38. package/dist/esm/test/fixedScriptToDescriptor.d.ts +0 -1
  39. package/dist/esm/test/fixedScriptToDescriptor.js +0 -93
  40. package/dist/esm/test/fixtures.d.ts +0 -1
  41. package/dist/esm/test/fixtures.js +0 -16
  42. package/dist/esm/test/opdrop.d.ts +0 -1
  43. package/dist/esm/test/opdrop.js +0 -85
  44. package/dist/esm/test/psbt.util.d.ts +0 -8
  45. package/dist/esm/test/psbt.util.js +0 -113
  46. package/dist/esm/test/psbtFixedScriptCompat.d.ts +0 -1
  47. package/dist/esm/test/psbtFixedScriptCompat.js +0 -116
  48. package/dist/esm/test/psbtFixedScriptCompatFixtures.d.ts +0 -10
  49. package/dist/esm/test/psbtFixedScriptCompatFixtures.js +0 -53
  50. package/dist/esm/test/psbtFromDescriptor.d.ts +0 -1
  51. package/dist/esm/test/psbtFromDescriptor.js +0 -104
  52. package/dist/esm/test/psbtFromDescriptor.util.d.ts +0 -63
  53. package/dist/esm/test/psbtFromDescriptor.util.js +0 -101
  54. package/dist/esm/test/test.d.ts +0 -1
  55. package/dist/esm/test/test.js +0 -123
  56. package/dist/esm/tsconfig.tsbuildinfo +0 -1
@@ -96,6 +96,64 @@ export class BitGoPsbt {
96
96
  const wasmECPair = ECPair.from(key).wasm;
97
97
  return this.wasm.verify_signature_with_pub(inputIndex, wasmECPair);
98
98
  }
99
+ /**
100
+ * Sign a single input with a private key
101
+ *
102
+ * This method signs a specific input using the provided key. It accepts either:
103
+ * - An xpriv (BIP32Arg: base58 string, BIP32 instance, or WasmBIP32) for wallet inputs - derives the key and signs
104
+ * - A raw privkey (ECPairArg: Buffer, ECPair instance, or WasmECPair) for replay protection inputs - signs directly
105
+ *
106
+ * This method automatically detects and handles different input types:
107
+ * - For regular inputs: uses standard PSBT signing
108
+ * - For MuSig2 inputs: uses the FirstRound state stored by generateMusig2Nonces()
109
+ * - For replay protection inputs: signs with legacy P2SH sighash
110
+ *
111
+ * @param inputIndex - The index of the input to sign (0-based)
112
+ * @param key - Either an xpriv (BIP32Arg) or a raw privkey (ECPairArg)
113
+ * @throws Error if signing fails, or if generateMusig2Nonces() was not called first for MuSig2 inputs
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * // Parse transaction to identify input types
118
+ * const parsed = psbt.parseTransactionWithWalletKeys(walletKeys, replayProtection);
119
+ *
120
+ * // Sign regular wallet inputs with xpriv
121
+ * for (let i = 0; i < parsed.inputs.length; i++) {
122
+ * const input = parsed.inputs[i];
123
+ * if (input.scriptId !== null && input.scriptType !== "p2shP2pk") {
124
+ * psbt.sign(i, userXpriv);
125
+ * }
126
+ * }
127
+ *
128
+ * // Sign replay protection inputs with raw privkey
129
+ * const userPrivkey = bip32.fromBase58(userXpriv).privateKey!;
130
+ * for (let i = 0; i < parsed.inputs.length; i++) {
131
+ * const input = parsed.inputs[i];
132
+ * if (input.scriptType === "p2shP2pk") {
133
+ * psbt.sign(i, userPrivkey);
134
+ * }
135
+ * }
136
+ * ```
137
+ */
138
+ sign(inputIndex, key) {
139
+ // Detect key type
140
+ // If string or has 'derive' method → BIP32Arg
141
+ // Otherwise → ECPairArg
142
+ if (typeof key === "string" ||
143
+ (typeof key === "object" &&
144
+ key !== null &&
145
+ "derive" in key &&
146
+ typeof key.derive === "function")) {
147
+ // It's a BIP32Arg
148
+ const wasmKey = BIP32.from(key);
149
+ this.wasm.sign_with_xpriv(inputIndex, wasmKey.wasm);
150
+ }
151
+ else {
152
+ // It's an ECPairArg
153
+ const wasmKey = ECPair.from(key);
154
+ this.wasm.sign_with_privkey(inputIndex, wasmKey.wasm);
155
+ }
156
+ }
99
157
  /**
100
158
  * @deprecated - use verifySignature with the replay protection key instead
101
159
  *
@@ -128,6 +186,70 @@ export class BitGoPsbt {
128
186
  serialize() {
129
187
  return this.wasm.serialize();
130
188
  }
189
+ /**
190
+ * Generate and store MuSig2 nonces for all MuSig2 inputs
191
+ *
192
+ * This method generates nonces using the State-Machine API and stores them in the PSBT.
193
+ * The nonces are stored as proprietary fields in the PSBT and will be included when serialized.
194
+ * After ALL participants have generated their nonces, you can sign MuSig2 inputs using
195
+ * sign().
196
+ *
197
+ * @param key - The extended private key (xpriv) for signing. Can be a base58 string, BIP32 instance, or WasmBIP32
198
+ * @param sessionId - Optional 32-byte session ID for nonce generation. **Only allowed on testnets**.
199
+ * On mainnets, a secure random session ID is always generated automatically.
200
+ * Must be unique per signing session.
201
+ * @throws Error if nonce generation fails, sessionId length is invalid, or custom sessionId is
202
+ * provided on a mainnet (security restriction)
203
+ *
204
+ * @security The sessionId MUST be cryptographically random and unique for each signing session.
205
+ * Never reuse a sessionId with the same key! On mainnets, sessionId is always randomly
206
+ * generated for security. Custom sessionId is only allowed on testnets for testing purposes.
207
+ *
208
+ * @example
209
+ * ```typescript
210
+ * // Phase 1: Both parties generate nonces (with auto-generated session ID)
211
+ * psbt.generateMusig2Nonces(userXpriv);
212
+ * // Nonces are stored in the PSBT
213
+ * // Send PSBT to counterparty
214
+ *
215
+ * // Phase 2: After receiving counterparty PSBT with their nonces
216
+ * const counterpartyPsbt = BitGoPsbt.fromBytes(counterpartyPsbtBytes, network);
217
+ * psbt.combineMusig2Nonces(counterpartyPsbt);
218
+ * // Sign MuSig2 key path inputs
219
+ * const parsed = psbt.parseTransactionWithWalletKeys(walletKeys, replayProtection);
220
+ * for (let i = 0; i < parsed.inputs.length; i++) {
221
+ * if (parsed.inputs[i].scriptType === "p2trMusig2KeyPath") {
222
+ * psbt.sign(i, userXpriv);
223
+ * }
224
+ * }
225
+ * ```
226
+ */
227
+ generateMusig2Nonces(key, sessionId) {
228
+ const wasmKey = BIP32.from(key);
229
+ this.wasm.generate_musig2_nonces(wasmKey.wasm, sessionId);
230
+ }
231
+ /**
232
+ * Combine/merge data from another PSBT into this one
233
+ *
234
+ * This method copies MuSig2 nonces and signatures (proprietary key-value pairs) from the
235
+ * source PSBT to this PSBT. This is useful for merging PSBTs during the nonce exchange
236
+ * and signature collection phases.
237
+ *
238
+ * @param sourcePsbt - The source PSBT containing data to merge
239
+ * @throws Error if networks don't match
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * // After receiving counterparty's PSBT with their nonces
244
+ * const counterpartyPsbt = BitGoPsbt.fromBytes(counterpartyPsbtBytes, network);
245
+ * psbt.combineMusig2Nonces(counterpartyPsbt);
246
+ * // Now can sign with all nonces present
247
+ * psbt.sign(0, userXpriv);
248
+ * ```
249
+ */
250
+ combineMusig2Nonces(sourcePsbt) {
251
+ this.wasm.combine_musig2_nonces(sourcePsbt.wasm);
252
+ }
131
253
  /**
132
254
  * Finalize all inputs in the PSBT
133
255
  *
@@ -19,6 +19,46 @@ export class BitGoPsbt {
19
19
  * Get the unsigned transaction ID
20
20
  */
21
21
  unsigned_txid(): string;
22
+ /**
23
+ * Sign a single input with an extended private key (xpriv)
24
+ *
25
+ * This method signs a specific input using the provided xpriv. It accepts:
26
+ * - An xpriv (WasmBIP32) for wallet inputs - derives the key and signs
27
+ *
28
+ * This method automatically detects and handles different input types:
29
+ * - For regular inputs: uses standard PSBT signing
30
+ * - For MuSig2 inputs: uses the FirstRound state stored by generate_musig2_nonces()
31
+ * - For replay protection inputs: returns error (use sign_with_privkey instead)
32
+ *
33
+ * # Arguments
34
+ * - `input_index`: The index of the input to sign (0-based)
35
+ * - `xpriv`: The extended private key as a WasmBIP32 instance
36
+ *
37
+ * # Returns
38
+ * - `Ok(())` if signing was successful
39
+ * - `Err(WasmUtxoError)` if signing fails
40
+ */
41
+ sign_with_xpriv(input_index: number, xpriv: WasmBIP32): void;
42
+ /**
43
+ * Sign a single input with a raw private key
44
+ *
45
+ * This method signs a specific input using the provided ECPair. It accepts:
46
+ * - A raw privkey (WasmECPair) for replay protection inputs - signs directly
47
+ *
48
+ * This method automatically detects and handles different input types:
49
+ * - For replay protection inputs: signs with legacy P2SH sighash
50
+ * - For regular inputs: uses standard PSBT signing
51
+ * - For MuSig2 inputs: returns error (requires FirstRound, use sign_with_xpriv instead)
52
+ *
53
+ * # Arguments
54
+ * - `input_index`: The index of the input to sign (0-based)
55
+ * - `ecpair`: The ECPair containing the private key
56
+ *
57
+ * # Returns
58
+ * - `Ok(())` if signing was successful
59
+ * - `Err(WasmUtxoError)` if signing fails
60
+ */
61
+ sign_with_privkey(input_index: number, ecpair: WasmECPair): void;
22
62
  /**
23
63
  * Extract the final transaction from a finalized PSBT
24
64
  *
@@ -41,6 +81,52 @@ export class BitGoPsbt {
41
81
  * - `Err(WasmUtxoError)` if any input failed to finalize
42
82
  */
43
83
  finalize_all_inputs(): void;
84
+ /**
85
+ * Combine/merge data from another PSBT into this one
86
+ *
87
+ * This method copies MuSig2 nonces and signatures (proprietary key-value pairs) from the
88
+ * source PSBT to this PSBT. This is useful for merging PSBTs during the nonce exchange
89
+ * and signature collection phases.
90
+ *
91
+ * # Arguments
92
+ * * `source_psbt` - The source PSBT containing data to merge
93
+ *
94
+ * # Returns
95
+ * Ok(()) if data was successfully merged
96
+ *
97
+ * # Errors
98
+ * Returns error if networks don't match
99
+ */
100
+ combine_musig2_nonces(source_psbt: BitGoPsbt): void;
101
+ /**
102
+ * Generate and store MuSig2 nonces for all MuSig2 inputs
103
+ *
104
+ * This method generates nonces using the State-Machine API and stores them in the PSBT.
105
+ * The nonces are stored as proprietary fields in the PSBT and will be included when serialized.
106
+ * After ALL participants have generated their nonces, they can sign MuSig2 inputs using
107
+ * sign_with_xpriv().
108
+ *
109
+ * # Arguments
110
+ * * `xpriv` - The extended private key (xpriv) for signing
111
+ * * `session_id_bytes` - Optional 32-byte session ID for nonce generation. **Only allowed on testnets**.
112
+ * On mainnets, a secure random session ID is always generated automatically.
113
+ * Must be unique per signing session.
114
+ *
115
+ * # Returns
116
+ * Ok(()) if nonces were successfully generated and stored
117
+ *
118
+ * # Errors
119
+ * Returns error if:
120
+ * - Nonce generation fails
121
+ * - session_id length is invalid
122
+ * - Custom session_id is provided on a mainnet (security restriction)
123
+ *
124
+ * # Security
125
+ * The session_id MUST be cryptographically random and unique for each signing session.
126
+ * Never reuse a session_id with the same key! On mainnets, session_id is always randomly
127
+ * generated for security. Custom session_id is only allowed on testnets for testing purposes.
128
+ */
129
+ generate_musig2_nonces(xpriv: WasmBIP32, session_id_bytes?: Uint8Array | null): void;
44
130
  /**
45
131
  * Verify if a valid signature exists for a given ECPair key at the specified input index
46
132
  *
@@ -64,6 +64,18 @@ function getArrayU8FromWasm0(ptr, len) {
64
64
  return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
65
65
  }
66
66
 
67
+ function dropObject(idx) {
68
+ if (idx < 132) return;
69
+ heap[idx] = heap_next;
70
+ heap_next = idx;
71
+ }
72
+
73
+ function takeObject(idx) {
74
+ const ret = getObject(idx);
75
+ dropObject(idx);
76
+ return ret;
77
+ }
78
+
67
79
  function isLikeNone(x) {
68
80
  return x === undefined || x === null;
69
81
  }
@@ -131,24 +143,6 @@ function passStringToWasm0(arg, malloc, realloc) {
131
143
  return ptr;
132
144
  }
133
145
 
134
- function dropObject(idx) {
135
- if (idx < 132) return;
136
- heap[idx] = heap_next;
137
- heap_next = idx;
138
- }
139
-
140
- function takeObject(idx) {
141
- const ret = getObject(idx);
142
- dropObject(idx);
143
- return ret;
144
- }
145
-
146
- function _assertClass(instance, klass) {
147
- if (!(instance instanceof klass)) {
148
- throw new Error(`expected instance of ${klass.name}`);
149
- }
150
- }
151
-
152
146
  function passArray8ToWasm0(arg, malloc) {
153
147
  const ptr = malloc(arg.length * 1, 1) >>> 0;
154
148
  getUint8ArrayMemory0().set(arg, ptr / 1);
@@ -156,12 +150,10 @@ function passArray8ToWasm0(arg, malloc) {
156
150
  return ptr;
157
151
  }
158
152
 
159
- let stack_pointer = 128;
160
-
161
- function addBorrowedObject(obj) {
162
- if (stack_pointer == 1) throw new Error('out of js stack');
163
- heap[--stack_pointer] = obj;
164
- return stack_pointer;
153
+ function _assertClass(instance, klass) {
154
+ if (!(instance instanceof klass)) {
155
+ throw new Error(`expected instance of ${klass.name}`);
156
+ }
165
157
  }
166
158
 
167
159
  function passArrayJsValueToWasm0(array, malloc) {
@@ -174,6 +166,14 @@ function passArrayJsValueToWasm0(array, malloc) {
174
166
  return ptr;
175
167
  }
176
168
 
169
+ let stack_pointer = 128;
170
+
171
+ function addBorrowedObject(obj) {
172
+ if (stack_pointer == 1) throw new Error('out of js stack');
173
+ heap[--stack_pointer] = obj;
174
+ return stack_pointer;
175
+ }
176
+
177
177
  const AddressNamespaceFinalization = (typeof FinalizationRegistry === 'undefined')
178
178
  ? { register: () => {}, unregister: () => {} }
179
179
  : new FinalizationRegistry(ptr => wasm.__wbg_addressnamespace_free(ptr >>> 0, 1));
@@ -327,6 +327,76 @@ export class BitGoPsbt {
327
327
  wasm.__wbindgen_export_3(deferred1_0, deferred1_1, 1);
328
328
  }
329
329
  }
330
+ /**
331
+ * Sign a single input with an extended private key (xpriv)
332
+ *
333
+ * This method signs a specific input using the provided xpriv. It accepts:
334
+ * - An xpriv (WasmBIP32) for wallet inputs - derives the key and signs
335
+ *
336
+ * This method automatically detects and handles different input types:
337
+ * - For regular inputs: uses standard PSBT signing
338
+ * - For MuSig2 inputs: uses the FirstRound state stored by generate_musig2_nonces()
339
+ * - For replay protection inputs: returns error (use sign_with_privkey instead)
340
+ *
341
+ * # Arguments
342
+ * - `input_index`: The index of the input to sign (0-based)
343
+ * - `xpriv`: The extended private key as a WasmBIP32 instance
344
+ *
345
+ * # Returns
346
+ * - `Ok(())` if signing was successful
347
+ * - `Err(WasmUtxoError)` if signing fails
348
+ * @param {number} input_index
349
+ * @param {WasmBIP32} xpriv
350
+ */
351
+ sign_with_xpriv(input_index, xpriv) {
352
+ try {
353
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
354
+ _assertClass(xpriv, WasmBIP32);
355
+ wasm.bitgopsbt_sign_with_xpriv(retptr, this.__wbg_ptr, input_index, xpriv.__wbg_ptr);
356
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
357
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
358
+ if (r1) {
359
+ throw takeObject(r0);
360
+ }
361
+ } finally {
362
+ wasm.__wbindgen_add_to_stack_pointer(16);
363
+ }
364
+ }
365
+ /**
366
+ * Sign a single input with a raw private key
367
+ *
368
+ * This method signs a specific input using the provided ECPair. It accepts:
369
+ * - A raw privkey (WasmECPair) for replay protection inputs - signs directly
370
+ *
371
+ * This method automatically detects and handles different input types:
372
+ * - For replay protection inputs: signs with legacy P2SH sighash
373
+ * - For regular inputs: uses standard PSBT signing
374
+ * - For MuSig2 inputs: returns error (requires FirstRound, use sign_with_xpriv instead)
375
+ *
376
+ * # Arguments
377
+ * - `input_index`: The index of the input to sign (0-based)
378
+ * - `ecpair`: The ECPair containing the private key
379
+ *
380
+ * # Returns
381
+ * - `Ok(())` if signing was successful
382
+ * - `Err(WasmUtxoError)` if signing fails
383
+ * @param {number} input_index
384
+ * @param {WasmECPair} ecpair
385
+ */
386
+ sign_with_privkey(input_index, ecpair) {
387
+ try {
388
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
389
+ _assertClass(ecpair, WasmECPair);
390
+ wasm.bitgopsbt_sign_with_privkey(retptr, this.__wbg_ptr, input_index, ecpair.__wbg_ptr);
391
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
392
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
393
+ if (r1) {
394
+ throw takeObject(r0);
395
+ }
396
+ } finally {
397
+ wasm.__wbindgen_add_to_stack_pointer(16);
398
+ }
399
+ }
330
400
  /**
331
401
  * Extract the final transaction from a finalized PSBT
332
402
  *
@@ -379,6 +449,83 @@ export class BitGoPsbt {
379
449
  wasm.__wbindgen_add_to_stack_pointer(16);
380
450
  }
381
451
  }
452
+ /**
453
+ * Combine/merge data from another PSBT into this one
454
+ *
455
+ * This method copies MuSig2 nonces and signatures (proprietary key-value pairs) from the
456
+ * source PSBT to this PSBT. This is useful for merging PSBTs during the nonce exchange
457
+ * and signature collection phases.
458
+ *
459
+ * # Arguments
460
+ * * `source_psbt` - The source PSBT containing data to merge
461
+ *
462
+ * # Returns
463
+ * Ok(()) if data was successfully merged
464
+ *
465
+ * # Errors
466
+ * Returns error if networks don't match
467
+ * @param {BitGoPsbt} source_psbt
468
+ */
469
+ combine_musig2_nonces(source_psbt) {
470
+ try {
471
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
472
+ _assertClass(source_psbt, BitGoPsbt);
473
+ wasm.bitgopsbt_combine_musig2_nonces(retptr, this.__wbg_ptr, source_psbt.__wbg_ptr);
474
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
475
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
476
+ if (r1) {
477
+ throw takeObject(r0);
478
+ }
479
+ } finally {
480
+ wasm.__wbindgen_add_to_stack_pointer(16);
481
+ }
482
+ }
483
+ /**
484
+ * Generate and store MuSig2 nonces for all MuSig2 inputs
485
+ *
486
+ * This method generates nonces using the State-Machine API and stores them in the PSBT.
487
+ * The nonces are stored as proprietary fields in the PSBT and will be included when serialized.
488
+ * After ALL participants have generated their nonces, they can sign MuSig2 inputs using
489
+ * sign_with_xpriv().
490
+ *
491
+ * # Arguments
492
+ * * `xpriv` - The extended private key (xpriv) for signing
493
+ * * `session_id_bytes` - Optional 32-byte session ID for nonce generation. **Only allowed on testnets**.
494
+ * On mainnets, a secure random session ID is always generated automatically.
495
+ * Must be unique per signing session.
496
+ *
497
+ * # Returns
498
+ * Ok(()) if nonces were successfully generated and stored
499
+ *
500
+ * # Errors
501
+ * Returns error if:
502
+ * - Nonce generation fails
503
+ * - session_id length is invalid
504
+ * - Custom session_id is provided on a mainnet (security restriction)
505
+ *
506
+ * # Security
507
+ * The session_id MUST be cryptographically random and unique for each signing session.
508
+ * Never reuse a session_id with the same key! On mainnets, session_id is always randomly
509
+ * generated for security. Custom session_id is only allowed on testnets for testing purposes.
510
+ * @param {WasmBIP32} xpriv
511
+ * @param {Uint8Array | null} [session_id_bytes]
512
+ */
513
+ generate_musig2_nonces(xpriv, session_id_bytes) {
514
+ try {
515
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
516
+ _assertClass(xpriv, WasmBIP32);
517
+ var ptr0 = isLikeNone(session_id_bytes) ? 0 : passArray8ToWasm0(session_id_bytes, wasm.__wbindgen_export_1);
518
+ var len0 = WASM_VECTOR_LEN;
519
+ wasm.bitgopsbt_generate_musig2_nonces(retptr, this.__wbg_ptr, xpriv.__wbg_ptr, ptr0, len0);
520
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
521
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
522
+ if (r1) {
523
+ throw takeObject(r0);
524
+ }
525
+ } finally {
526
+ wasm.__wbindgen_add_to_stack_pointer(16);
527
+ }
528
+ }
382
529
  /**
383
530
  * Verify if a valid signature exists for a given ECPair key at the specified input index
384
531
  *
@@ -2184,6 +2331,25 @@ export function __wbg_Error_e17e777aac105295(arg0, arg1) {
2184
2331
  return addHeapObject(ret);
2185
2332
  };
2186
2333
 
2334
+ export function __wbg_call_13410aac570ffff7() { return handleError(function (arg0, arg1) {
2335
+ const ret = getObject(arg0).call(getObject(arg1));
2336
+ return addHeapObject(ret);
2337
+ }, arguments) };
2338
+
2339
+ export function __wbg_call_a5400b25a865cfd8() { return handleError(function (arg0, arg1, arg2) {
2340
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
2341
+ return addHeapObject(ret);
2342
+ }, arguments) };
2343
+
2344
+ export function __wbg_crypto_574e78ad8b13b65f(arg0) {
2345
+ const ret = getObject(arg0).crypto;
2346
+ return addHeapObject(ret);
2347
+ };
2348
+
2349
+ export function __wbg_getRandomValues_b8f5dbd5f3995a9e() { return handleError(function (arg0, arg1) {
2350
+ getObject(arg0).getRandomValues(getObject(arg1));
2351
+ }, arguments) };
2352
+
2187
2353
  export function __wbg_get_458e874b43b18b25() { return handleError(function (arg0, arg1) {
2188
2354
  const ret = Reflect.get(getObject(arg0), getObject(arg1));
2189
2355
  return addHeapObject(ret);
@@ -2194,6 +2360,11 @@ export function __wbg_length_6bb7e81f9d7713e4(arg0) {
2194
2360
  return ret;
2195
2361
  };
2196
2362
 
2363
+ export function __wbg_msCrypto_a61aeb35a24c1329(arg0) {
2364
+ const ret = getObject(arg0).msCrypto;
2365
+ return addHeapObject(ret);
2366
+ };
2367
+
2197
2368
  export function __wbg_new_19c25a3f2fa63a02() {
2198
2369
  const ret = new Object();
2199
2370
  return addHeapObject(ret);
@@ -2219,6 +2390,26 @@ export function __wbg_newfromslice_074c56947bd43469(arg0, arg1) {
2219
2390
  return addHeapObject(ret);
2220
2391
  };
2221
2392
 
2393
+ export function __wbg_newnoargs_254190557c45b4ec(arg0, arg1) {
2394
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
2395
+ return addHeapObject(ret);
2396
+ };
2397
+
2398
+ export function __wbg_newwithlength_a167dcc7aaa3ba77(arg0) {
2399
+ const ret = new Uint8Array(arg0 >>> 0);
2400
+ return addHeapObject(ret);
2401
+ };
2402
+
2403
+ export function __wbg_node_905d3e251edff8a2(arg0) {
2404
+ const ret = getObject(arg0).node;
2405
+ return addHeapObject(ret);
2406
+ };
2407
+
2408
+ export function __wbg_process_dc0fbacc7c1c06f7(arg0) {
2409
+ const ret = getObject(arg0).process;
2410
+ return addHeapObject(ret);
2411
+ };
2412
+
2222
2413
  export function __wbg_prototypesetcall_3d4a26c1ed734349(arg0, arg1, arg2) {
2223
2414
  Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
2224
2415
  };
@@ -2228,16 +2419,71 @@ export function __wbg_push_330b2eb93e4e1212(arg0, arg1) {
2228
2419
  return ret;
2229
2420
  };
2230
2421
 
2422
+ export function __wbg_randomFillSync_ac0988aba3254290() { return handleError(function (arg0, arg1) {
2423
+ getObject(arg0).randomFillSync(takeObject(arg1));
2424
+ }, arguments) };
2425
+
2426
+ export function __wbg_require_60cc747a6bc5215a() { return handleError(function () {
2427
+ const ret = module.require;
2428
+ return addHeapObject(ret);
2429
+ }, arguments) };
2430
+
2231
2431
  export function __wbg_set_453345bcda80b89a() { return handleError(function (arg0, arg1, arg2) {
2232
2432
  const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
2233
2433
  return ret;
2234
2434
  }, arguments) };
2235
2435
 
2436
+ export function __wbg_static_accessor_GLOBAL_8921f820c2ce3f12() {
2437
+ const ret = typeof global === 'undefined' ? null : global;
2438
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
2439
+ };
2440
+
2441
+ export function __wbg_static_accessor_GLOBAL_THIS_f0a4409105898184() {
2442
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
2443
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
2444
+ };
2445
+
2446
+ export function __wbg_static_accessor_SELF_995b214ae681ff99() {
2447
+ const ret = typeof self === 'undefined' ? null : self;
2448
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
2449
+ };
2450
+
2451
+ export function __wbg_static_accessor_WINDOW_cde3890479c675ea() {
2452
+ const ret = typeof window === 'undefined' ? null : window;
2453
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
2454
+ };
2455
+
2456
+ export function __wbg_subarray_70fd07feefe14294(arg0, arg1, arg2) {
2457
+ const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
2458
+ return addHeapObject(ret);
2459
+ };
2460
+
2461
+ export function __wbg_versions_c01dfd4722a88165(arg0) {
2462
+ const ret = getObject(arg0).versions;
2463
+ return addHeapObject(ret);
2464
+ };
2465
+
2466
+ export function __wbg_wbindgenisfunction_8cee7dce3725ae74(arg0) {
2467
+ const ret = typeof(getObject(arg0)) === 'function';
2468
+ return ret;
2469
+ };
2470
+
2236
2471
  export function __wbg_wbindgenisnull_f3037694abe4d97a(arg0) {
2237
2472
  const ret = getObject(arg0) === null;
2238
2473
  return ret;
2239
2474
  };
2240
2475
 
2476
+ export function __wbg_wbindgenisobject_307a53c6bd97fbf8(arg0) {
2477
+ const val = getObject(arg0);
2478
+ const ret = typeof(val) === 'object' && val !== null;
2479
+ return ret;
2480
+ };
2481
+
2482
+ export function __wbg_wbindgenisstring_d4fa939789f003b0(arg0) {
2483
+ const ret = typeof(getObject(arg0)) === 'string';
2484
+ return ret;
2485
+ };
2486
+
2241
2487
  export function __wbg_wbindgenisundefined_c4b71d073b92f3c5(arg0) {
2242
2488
  const ret = getObject(arg0) === undefined;
2243
2489
  return ret;
@@ -2275,6 +2521,12 @@ export function __wbindgen_cast_4625c577ab2ec9ee(arg0) {
2275
2521
  return addHeapObject(ret);
2276
2522
  };
2277
2523
 
2524
+ export function __wbindgen_cast_cb9088102bce6b30(arg0, arg1) {
2525
+ // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
2526
+ const ret = getArrayU8FromWasm0(arg0, arg1);
2527
+ return addHeapObject(ret);
2528
+ };
2529
+
2278
2530
  export function __wbindgen_cast_d6cd19b81560fd6e(arg0) {
2279
2531
  // Cast intrinsic for `F64 -> Externref`.
2280
2532
  const ret = arg0;
Binary file