@bitgo/wasm-utxo 1.6.0 → 1.8.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 (63) hide show
  1. package/dist/cjs/js/bip32.d.ts +140 -0
  2. package/dist/cjs/js/bip32.js +177 -0
  3. package/dist/cjs/js/ecpair.d.ts +96 -0
  4. package/dist/cjs/js/ecpair.js +134 -0
  5. package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.d.ts +242 -0
  6. package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.js +274 -0
  7. package/dist/cjs/js/fixedScriptWallet/ReplayProtection.d.ts +58 -0
  8. package/dist/cjs/js/fixedScriptWallet/ReplayProtection.js +89 -0
  9. package/dist/cjs/js/fixedScriptWallet/RootWalletKeys.d.ts +66 -0
  10. package/dist/cjs/js/fixedScriptWallet/RootWalletKeys.js +108 -0
  11. package/dist/cjs/js/fixedScriptWallet/address.d.ts +20 -0
  12. package/dist/cjs/js/fixedScriptWallet/address.js +29 -0
  13. package/dist/cjs/js/fixedScriptWallet/index.d.ts +4 -0
  14. package/dist/cjs/js/fixedScriptWallet/index.js +12 -0
  15. package/dist/cjs/js/index.d.ts +5 -1
  16. package/dist/cjs/js/index.js +11 -2
  17. package/dist/cjs/js/utxolibCompat.d.ts +0 -18
  18. package/dist/cjs/js/wasm/wasm_utxo.d.ts +333 -15
  19. package/dist/cjs/js/wasm/wasm_utxo.js +1311 -201
  20. package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
  21. package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +64 -15
  22. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  23. package/dist/esm/js/bip32.d.ts +140 -0
  24. package/dist/esm/js/bip32.js +173 -0
  25. package/dist/esm/js/ecpair.d.ts +96 -0
  26. package/dist/esm/js/ecpair.js +130 -0
  27. package/dist/esm/js/fixedScriptWallet/BitGoPsbt.d.ts +242 -0
  28. package/dist/esm/js/fixedScriptWallet/BitGoPsbt.js +270 -0
  29. package/dist/esm/js/fixedScriptWallet/ReplayProtection.d.ts +58 -0
  30. package/dist/esm/js/fixedScriptWallet/ReplayProtection.js +85 -0
  31. package/dist/esm/js/fixedScriptWallet/RootWalletKeys.d.ts +66 -0
  32. package/dist/esm/js/fixedScriptWallet/RootWalletKeys.js +104 -0
  33. package/dist/esm/js/fixedScriptWallet/address.d.ts +20 -0
  34. package/dist/esm/js/fixedScriptWallet/address.js +25 -0
  35. package/dist/esm/js/fixedScriptWallet/index.d.ts +4 -0
  36. package/dist/esm/js/fixedScriptWallet/index.js +4 -0
  37. package/dist/esm/js/index.d.ts +5 -1
  38. package/dist/esm/js/index.js +8 -1
  39. package/dist/esm/js/utxolibCompat.d.ts +0 -18
  40. package/dist/esm/js/wasm/wasm_utxo.d.ts +333 -15
  41. package/dist/esm/js/wasm/wasm_utxo_bg.js +1301 -199
  42. package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
  43. package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +64 -15
  44. package/dist/esm/test/bip32.js +242 -0
  45. package/dist/esm/test/ecpair.d.ts +1 -0
  46. package/dist/esm/test/ecpair.js +137 -0
  47. package/dist/esm/test/fixedScript/fixtureUtil.d.ts +12 -2
  48. package/dist/esm/test/fixedScript/fixtureUtil.js +28 -7
  49. package/dist/esm/test/fixedScript/musig2Nonces.d.ts +1 -0
  50. package/dist/esm/test/fixedScript/musig2Nonces.js +77 -0
  51. package/dist/esm/test/fixedScript/parseTransactionWithWalletKeys.js +7 -7
  52. package/dist/esm/test/fixedScript/signAndVerifySignature.d.ts +1 -0
  53. package/dist/esm/test/fixedScript/signAndVerifySignature.js +268 -0
  54. package/dist/esm/test/fixedScript/walletKeys.util.d.ts +12 -0
  55. package/dist/esm/test/fixedScript/walletKeys.util.js +17 -0
  56. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  57. package/package.json +1 -1
  58. package/dist/cjs/js/fixedScriptWallet.d.ts +0 -146
  59. package/dist/cjs/js/fixedScriptWallet.js +0 -138
  60. package/dist/esm/js/fixedScriptWallet.d.ts +0 -146
  61. package/dist/esm/js/fixedScriptWallet.js +0 -132
  62. package/dist/esm/test/fixedScript/verifySignature.js +0 -141
  63. /package/dist/esm/test/{fixedScript/verifySignature.d.ts → bip32.d.ts} +0 -0
@@ -20,22 +20,45 @@ export class BitGoPsbt {
20
20
  */
21
21
  unsigned_txid(): string;
22
22
  /**
23
- * Verify if a valid signature exists for a given xpub at the specified input index
23
+ * Sign a single input with an extended private key (xpriv)
24
24
  *
25
- * This method derives the public key from the xpub using the derivation path found in the
26
- * PSBT input, then verifies the signature. It supports both ECDSA signatures (for legacy/SegWit
27
- * inputs) and Schnorr signatures (for Taproot script path inputs).
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)
28
32
  *
29
33
  * # Arguments
30
- * - `input_index`: The index of the input to check
31
- * - `xpub_str`: The extended public key as a base58-encoded string
34
+ * - `input_index`: The index of the input to sign (0-based)
35
+ * - `xpriv`: The extended private key as a WasmBIP32 instance
32
36
  *
33
37
  * # Returns
34
- * - `Ok(true)` if a valid signature exists for the derived public key
35
- * - `Ok(false)` if no signature exists for the derived public key
36
- * - `Err(WasmUtxoError)` if the input index is out of bounds, xpub is invalid, derivation fails, or verification fails
38
+ * - `Ok(())` if signing was successful
39
+ * - `Err(WasmUtxoError)` if signing fails
37
40
  */
38
- verify_signature(input_index: number, xpub_str: string): boolean;
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;
39
62
  /**
40
63
  * Extract the final transaction from a finalized PSBT
41
64
  *
@@ -58,16 +81,101 @@ export class BitGoPsbt {
58
81
  * - `Err(WasmUtxoError)` if any input failed to finalize
59
82
  */
60
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;
130
+ /**
131
+ * Verify if a valid signature exists for a given ECPair key at the specified input index
132
+ *
133
+ * This method verifies the signature directly with the provided ECPair's public key. It supports:
134
+ * - ECDSA signatures (for legacy/SegWit inputs)
135
+ * - Schnorr signatures (for Taproot script path inputs)
136
+ *
137
+ * Note: This method does NOT support MuSig2 inputs, as MuSig2 requires derivation from xpubs.
138
+ * Use `verify_signature_with_xpub` for MuSig2 inputs.
139
+ *
140
+ * # Arguments
141
+ * - `input_index`: The index of the input to check
142
+ * - `ecpair`: The ECPair key (uses the public key for verification)
143
+ *
144
+ * # Returns
145
+ * - `Ok(true)` if a valid signature exists for the public key
146
+ * - `Ok(false)` if no signature exists for the public key
147
+ * - `Err(WasmUtxoError)` if the input index is out of bounds or verification fails
148
+ */
149
+ verify_signature_with_pub(input_index: number, ecpair: WasmECPair): boolean;
150
+ /**
151
+ * Verify if a valid signature exists for a given xpub at the specified input index
152
+ *
153
+ * This method derives the public key from the xpub using the derivation path found in the
154
+ * PSBT input, then verifies the signature. It supports:
155
+ * - ECDSA signatures (for legacy/SegWit inputs)
156
+ * - Schnorr signatures (for Taproot script path inputs)
157
+ * - MuSig2 partial signatures (for Taproot keypath MuSig2 inputs)
158
+ *
159
+ * # Arguments
160
+ * - `input_index`: The index of the input to check
161
+ * - `xpub`: The extended public key as a WasmBIP32 instance
162
+ *
163
+ * # Returns
164
+ * - `Ok(true)` if a valid signature exists for the derived public key
165
+ * - `Ok(false)` if no signature exists for the derived public key
166
+ * - `Err(WasmUtxoError)` if the input index is out of bounds, derivation fails, or verification fails
167
+ */
168
+ verify_signature_with_xpub(input_index: number, xpub: WasmBIP32): boolean;
61
169
  /**
62
170
  * Parse outputs with wallet keys to identify which outputs belong to a wallet
63
171
  *
64
172
  * Note: This method does NOT validate wallet inputs. It only parses outputs.
65
173
  */
66
- parse_outputs_with_wallet_keys(wallet_keys: any): any;
174
+ parse_outputs_with_wallet_keys(wallet_keys: WasmRootWalletKeys): any;
67
175
  /**
68
176
  * Parse transaction with wallet keys to identify wallet inputs/outputs
69
177
  */
70
- parse_transaction_with_wallet_keys(wallet_keys: any, replay_protection: any): any;
178
+ parse_transaction_with_wallet_keys(wallet_keys: WasmRootWalletKeys, replay_protection: WasmReplayProtection): any;
71
179
  /**
72
180
  * Verify if a replay protection input has a valid signature
73
181
  *
@@ -85,7 +193,11 @@ export class BitGoPsbt {
85
193
  * - `Ok(false)` if the input is a replay protection input but has no valid signature
86
194
  * - `Err(WasmUtxoError)` if the input is not a replay protection input, index is out of bounds, or configuration is invalid
87
195
  */
88
- verify_replay_protection_signature(input_index: number, replay_protection: any): boolean;
196
+ verify_replay_protection_signature(input_index: number, replay_protection: WasmReplayProtection): boolean;
197
+ /**
198
+ * Get the network of the PSBT
199
+ */
200
+ network(): string;
89
201
  /**
90
202
  * Serialize the PSBT to bytes
91
203
  *
@@ -98,8 +210,8 @@ export class FixedScriptWalletNamespace {
98
210
  private constructor();
99
211
  free(): void;
100
212
  [Symbol.dispose](): void;
101
- static output_script(keys: any, chain: number, index: number, network: any): Uint8Array;
102
- static address(keys: any, chain: number, index: number, network: any, address_format?: string | null): string;
213
+ static output_script(keys: WasmRootWalletKeys, chain: number, index: number, network: any): Uint8Array;
214
+ static address(keys: WasmRootWalletKeys, chain: number, index: number, network: any, address_format?: string | null): string;
103
215
  }
104
216
  export class UtxolibCompatNamespace {
105
217
  private constructor();
@@ -124,6 +236,212 @@ export class UtxolibCompatNamespace {
124
236
  */
125
237
  static from_output_script(script: Uint8Array, network: any, format?: string | null): string;
126
238
  }
239
+ /**
240
+ * WASM wrapper for BIP32 extended keys (Xpub/Xpriv)
241
+ * Implements the BIP32Interface TypeScript interface
242
+ */
243
+ export class WasmBIP32 {
244
+ private constructor();
245
+ free(): void;
246
+ [Symbol.dispose](): void;
247
+ /**
248
+ * Derive a key using a derivation path (e.g., "0/1/2" or "m/0/1/2")
249
+ */
250
+ derive_path(path: string): WasmBIP32;
251
+ /**
252
+ * Create a BIP32 key from a base58 string (xpub/xprv/tpub/tprv)
253
+ */
254
+ static from_base58(base58_str: string): WasmBIP32;
255
+ /**
256
+ * Check if this is a neutered (public) key
257
+ */
258
+ is_neutered(): boolean;
259
+ /**
260
+ * Derive a hardened child key (only works for private keys)
261
+ */
262
+ derive_hardened(index: number): WasmBIP32;
263
+ /**
264
+ * Create a BIP32 key from a BIP32Interface JavaScript object properties
265
+ * Expects an object with: network.bip32.public, depth, parentFingerprint,
266
+ * index, chainCode, and publicKey properties
267
+ */
268
+ static from_bip32_interface(bip32_key: any): WasmBIP32;
269
+ /**
270
+ * Create a BIP32 key from BIP32 properties
271
+ * Extracts properties from a JavaScript object and constructs an xpub
272
+ */
273
+ static from_bip32_properties(bip32_key: any): WasmBIP32;
274
+ /**
275
+ * Derive a normal (non-hardened) child key
276
+ */
277
+ derive(index: number): WasmBIP32;
278
+ /**
279
+ * Get the WIF encoding of the private key
280
+ */
281
+ to_wif(): string;
282
+ /**
283
+ * Get the neutered (public) version of this key
284
+ */
285
+ neutered(): WasmBIP32;
286
+ /**
287
+ * Create a BIP32 master key from a seed
288
+ */
289
+ static from_seed(seed: Uint8Array, network?: string | null): WasmBIP32;
290
+ /**
291
+ * Create a BIP32 key from an xprv string (base58-encoded)
292
+ */
293
+ static from_xprv(xprv_str: string): WasmBIP32;
294
+ /**
295
+ * Create a BIP32 key from an xpub string (base58-encoded)
296
+ */
297
+ static from_xpub(xpub_str: string): WasmBIP32;
298
+ /**
299
+ * Serialize to base58 string
300
+ */
301
+ to_base58(): string;
302
+ /**
303
+ * Get the chain code as a Uint8Array
304
+ */
305
+ readonly chain_code: Uint8Array;
306
+ /**
307
+ * Get the identifier as a Uint8Array
308
+ */
309
+ readonly identifier: Uint8Array;
310
+ /**
311
+ * Get the public key as a Uint8Array
312
+ */
313
+ readonly public_key: Uint8Array;
314
+ /**
315
+ * Get the fingerprint as a Uint8Array
316
+ */
317
+ readonly fingerprint: Uint8Array;
318
+ /**
319
+ * Get the private key as a Uint8Array (if available)
320
+ */
321
+ readonly private_key: Uint8Array | undefined;
322
+ /**
323
+ * Get the parent fingerprint
324
+ */
325
+ readonly parent_fingerprint: number;
326
+ /**
327
+ * Get the depth
328
+ */
329
+ readonly depth: number;
330
+ /**
331
+ * Get the child index
332
+ */
333
+ readonly index: number;
334
+ }
335
+ /**
336
+ * WASM wrapper for elliptic curve key pairs (always uses compressed keys)
337
+ */
338
+ export class WasmECPair {
339
+ private constructor();
340
+ free(): void;
341
+ [Symbol.dispose](): void;
342
+ /**
343
+ * Convert to mainnet WIF string
344
+ */
345
+ to_wif_mainnet(): string;
346
+ /**
347
+ * Convert to testnet WIF string
348
+ */
349
+ to_wif_testnet(): string;
350
+ /**
351
+ * Create an ECPair from a public key (always uses compressed keys)
352
+ */
353
+ static from_public_key(public_key: Uint8Array): WasmECPair;
354
+ /**
355
+ * Create an ECPair from a private key (always uses compressed keys)
356
+ */
357
+ static from_private_key(private_key: Uint8Array): WasmECPair;
358
+ /**
359
+ * Create an ECPair from a mainnet WIF string
360
+ */
361
+ static from_wif_mainnet(wif_string: string): WasmECPair;
362
+ /**
363
+ * Create an ECPair from a testnet WIF string
364
+ */
365
+ static from_wif_testnet(wif_string: string): WasmECPair;
366
+ /**
367
+ * Convert to WIF string (mainnet)
368
+ */
369
+ to_wif(): string;
370
+ /**
371
+ * Create an ECPair from a WIF string (auto-detects network)
372
+ */
373
+ static from_wif(wif_string: string): WasmECPair;
374
+ /**
375
+ * Get the compressed public key as a Uint8Array (always 33 bytes)
376
+ */
377
+ readonly public_key: Uint8Array;
378
+ /**
379
+ * Get the private key as a Uint8Array (if available)
380
+ */
381
+ readonly private_key: Uint8Array | undefined;
382
+ }
383
+ /**
384
+ * WASM wrapper for ReplayProtection
385
+ */
386
+ export class WasmReplayProtection {
387
+ private constructor();
388
+ free(): void;
389
+ [Symbol.dispose](): void;
390
+ /**
391
+ * Create from addresses (requires network for decoding)
392
+ */
393
+ static from_addresses(addresses: any[], network: string): WasmReplayProtection;
394
+ /**
395
+ * Create from public keys (derives P2SH-P2PK output scripts)
396
+ */
397
+ static from_public_keys(public_keys: Uint8Array[]): WasmReplayProtection;
398
+ /**
399
+ * Create from output scripts directly
400
+ */
401
+ static from_output_scripts(output_scripts: Uint8Array[]): WasmReplayProtection;
402
+ }
403
+ /**
404
+ * WASM wrapper for RootWalletKeys
405
+ * Represents a set of three extended public keys with their derivation prefixes
406
+ */
407
+ export class WasmRootWalletKeys {
408
+ free(): void;
409
+ [Symbol.dispose](): void;
410
+ /**
411
+ * Get the backup key (second xpub)
412
+ */
413
+ backup_key(): WasmBIP32;
414
+ /**
415
+ * Create a RootWalletKeys from three BIP32 keys with custom derivation prefixes
416
+ *
417
+ * # Arguments
418
+ * - `user`: User key (first xpub)
419
+ * - `backup`: Backup key (second xpub)
420
+ * - `bitgo`: BitGo key (third xpub)
421
+ * - `user_derivation`: Derivation path for user key (e.g., "m/0/0")
422
+ * - `backup_derivation`: Derivation path for backup key (e.g., "m/0/0")
423
+ * - `bitgo_derivation`: Derivation path for bitgo key (e.g., "m/0/0")
424
+ */
425
+ static with_derivation_prefixes(user: WasmBIP32, backup: WasmBIP32, bitgo: WasmBIP32, user_derivation: string, backup_derivation: string, bitgo_derivation: string): WasmRootWalletKeys;
426
+ /**
427
+ * Create a RootWalletKeys from three BIP32 keys
428
+ * Uses default derivation prefix of m/0/0 for all three keys
429
+ *
430
+ * # Arguments
431
+ * - `user`: User key (first xpub)
432
+ * - `backup`: Backup key (second xpub)
433
+ * - `bitgo`: BitGo key (third xpub)
434
+ */
435
+ constructor(user: WasmBIP32, backup: WasmBIP32, bitgo: WasmBIP32);
436
+ /**
437
+ * Get the user key (first xpub)
438
+ */
439
+ user_key(): WasmBIP32;
440
+ /**
441
+ * Get the bitgo key (third xpub)
442
+ */
443
+ bitgo_key(): WasmBIP32;
444
+ }
127
445
  export class WrapDescriptor {
128
446
  private constructor();
129
447
  free(): void;