@bitgo/wasm-utxo 1.6.0 → 1.7.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 (53) 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.d.ts → fixedScriptWallet/BitGoPsbt.d.ts} +38 -41
  6. package/dist/cjs/js/{fixedScriptWallet.js → fixedScriptWallet/BitGoPsbt.js} +50 -36
  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 +254 -22
  19. package/dist/cjs/js/wasm/wasm_utxo.js +1081 -223
  20. package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
  21. package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +53 -8
  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.d.ts → fixedScriptWallet/BitGoPsbt.d.ts} +38 -41
  28. package/dist/esm/js/{fixedScriptWallet.js → fixedScriptWallet/BitGoPsbt.js} +49 -33
  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 +254 -22
  41. package/dist/esm/js/wasm/wasm_utxo_bg.js +1070 -220
  42. package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
  43. package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +53 -8
  44. package/dist/esm/test/bip32.d.ts +1 -0
  45. package/dist/esm/test/bip32.js +242 -0
  46. package/dist/esm/test/ecpair.d.ts +1 -0
  47. package/dist/esm/test/ecpair.js +137 -0
  48. package/dist/esm/test/fixedScript/fixtureUtil.d.ts +4 -2
  49. package/dist/esm/test/fixedScript/fixtureUtil.js +18 -7
  50. package/dist/esm/test/fixedScript/parseTransactionWithWalletKeys.js +7 -7
  51. package/dist/esm/test/fixedScript/verifySignature.js +72 -26
  52. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  53. package/package.json +1 -1
@@ -19,23 +19,6 @@ export class BitGoPsbt {
19
19
  * Get the unsigned transaction ID
20
20
  */
21
21
  unsigned_txid(): string;
22
- /**
23
- * Verify if a valid signature exists for a given xpub at the specified input index
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).
28
- *
29
- * # Arguments
30
- * - `input_index`: The index of the input to check
31
- * - `xpub_str`: The extended public key as a base58-encoded string
32
- *
33
- * # 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
37
- */
38
- verify_signature(input_index: number, xpub_str: string): boolean;
39
22
  /**
40
23
  * Extract the final transaction from a finalized PSBT
41
24
  *
@@ -58,16 +41,55 @@ export class BitGoPsbt {
58
41
  * - `Err(WasmUtxoError)` if any input failed to finalize
59
42
  */
60
43
  finalize_all_inputs(): void;
44
+ /**
45
+ * Verify if a valid signature exists for a given ECPair key at the specified input index
46
+ *
47
+ * This method verifies the signature directly with the provided ECPair's public key. It supports:
48
+ * - ECDSA signatures (for legacy/SegWit inputs)
49
+ * - Schnorr signatures (for Taproot script path inputs)
50
+ *
51
+ * Note: This method does NOT support MuSig2 inputs, as MuSig2 requires derivation from xpubs.
52
+ * Use `verify_signature_with_xpub` for MuSig2 inputs.
53
+ *
54
+ * # Arguments
55
+ * - `input_index`: The index of the input to check
56
+ * - `ecpair`: The ECPair key (uses the public key for verification)
57
+ *
58
+ * # Returns
59
+ * - `Ok(true)` if a valid signature exists for the public key
60
+ * - `Ok(false)` if no signature exists for the public key
61
+ * - `Err(WasmUtxoError)` if the input index is out of bounds or verification fails
62
+ */
63
+ verify_signature_with_pub(input_index: number, ecpair: WasmECPair): boolean;
64
+ /**
65
+ * Verify if a valid signature exists for a given xpub at the specified input index
66
+ *
67
+ * This method derives the public key from the xpub using the derivation path found in the
68
+ * PSBT input, then verifies the signature. It supports:
69
+ * - ECDSA signatures (for legacy/SegWit inputs)
70
+ * - Schnorr signatures (for Taproot script path inputs)
71
+ * - MuSig2 partial signatures (for Taproot keypath MuSig2 inputs)
72
+ *
73
+ * # Arguments
74
+ * - `input_index`: The index of the input to check
75
+ * - `xpub`: The extended public key as a WasmBIP32 instance
76
+ *
77
+ * # Returns
78
+ * - `Ok(true)` if a valid signature exists for the derived public key
79
+ * - `Ok(false)` if no signature exists for the derived public key
80
+ * - `Err(WasmUtxoError)` if the input index is out of bounds, derivation fails, or verification fails
81
+ */
82
+ verify_signature_with_xpub(input_index: number, xpub: WasmBIP32): boolean;
61
83
  /**
62
84
  * Parse outputs with wallet keys to identify which outputs belong to a wallet
63
85
  *
64
86
  * Note: This method does NOT validate wallet inputs. It only parses outputs.
65
87
  */
66
- parse_outputs_with_wallet_keys(wallet_keys: any): any;
88
+ parse_outputs_with_wallet_keys(wallet_keys: WasmRootWalletKeys): any;
67
89
  /**
68
90
  * Parse transaction with wallet keys to identify wallet inputs/outputs
69
91
  */
70
- parse_transaction_with_wallet_keys(wallet_keys: any, replay_protection: any): any;
92
+ parse_transaction_with_wallet_keys(wallet_keys: WasmRootWalletKeys, replay_protection: WasmReplayProtection): any;
71
93
  /**
72
94
  * Verify if a replay protection input has a valid signature
73
95
  *
@@ -85,7 +107,11 @@ export class BitGoPsbt {
85
107
  * - `Ok(false)` if the input is a replay protection input but has no valid signature
86
108
  * - `Err(WasmUtxoError)` if the input is not a replay protection input, index is out of bounds, or configuration is invalid
87
109
  */
88
- verify_replay_protection_signature(input_index: number, replay_protection: any): boolean;
110
+ verify_replay_protection_signature(input_index: number, replay_protection: WasmReplayProtection): boolean;
111
+ /**
112
+ * Get the network of the PSBT
113
+ */
114
+ network(): string;
89
115
  /**
90
116
  * Serialize the PSBT to bytes
91
117
  *
@@ -98,8 +124,8 @@ export class FixedScriptWalletNamespace {
98
124
  private constructor();
99
125
  free(): void;
100
126
  [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;
127
+ static output_script(keys: WasmRootWalletKeys, chain: number, index: number, network: any): Uint8Array;
128
+ static address(keys: WasmRootWalletKeys, chain: number, index: number, network: any, address_format?: string | null): string;
103
129
  }
104
130
  export class UtxolibCompatNamespace {
105
131
  private constructor();
@@ -124,6 +150,212 @@ export class UtxolibCompatNamespace {
124
150
  */
125
151
  static from_output_script(script: Uint8Array, network: any, format?: string | null): string;
126
152
  }
153
+ /**
154
+ * WASM wrapper for BIP32 extended keys (Xpub/Xpriv)
155
+ * Implements the BIP32Interface TypeScript interface
156
+ */
157
+ export class WasmBIP32 {
158
+ private constructor();
159
+ free(): void;
160
+ [Symbol.dispose](): void;
161
+ /**
162
+ * Derive a key using a derivation path (e.g., "0/1/2" or "m/0/1/2")
163
+ */
164
+ derive_path(path: string): WasmBIP32;
165
+ /**
166
+ * Create a BIP32 key from a base58 string (xpub/xprv/tpub/tprv)
167
+ */
168
+ static from_base58(base58_str: string): WasmBIP32;
169
+ /**
170
+ * Check if this is a neutered (public) key
171
+ */
172
+ is_neutered(): boolean;
173
+ /**
174
+ * Derive a hardened child key (only works for private keys)
175
+ */
176
+ derive_hardened(index: number): WasmBIP32;
177
+ /**
178
+ * Create a BIP32 key from a BIP32Interface JavaScript object properties
179
+ * Expects an object with: network.bip32.public, depth, parentFingerprint,
180
+ * index, chainCode, and publicKey properties
181
+ */
182
+ static from_bip32_interface(bip32_key: any): WasmBIP32;
183
+ /**
184
+ * Create a BIP32 key from BIP32 properties
185
+ * Extracts properties from a JavaScript object and constructs an xpub
186
+ */
187
+ static from_bip32_properties(bip32_key: any): WasmBIP32;
188
+ /**
189
+ * Derive a normal (non-hardened) child key
190
+ */
191
+ derive(index: number): WasmBIP32;
192
+ /**
193
+ * Get the WIF encoding of the private key
194
+ */
195
+ to_wif(): string;
196
+ /**
197
+ * Get the neutered (public) version of this key
198
+ */
199
+ neutered(): WasmBIP32;
200
+ /**
201
+ * Create a BIP32 master key from a seed
202
+ */
203
+ static from_seed(seed: Uint8Array, network?: string | null): WasmBIP32;
204
+ /**
205
+ * Create a BIP32 key from an xprv string (base58-encoded)
206
+ */
207
+ static from_xprv(xprv_str: string): WasmBIP32;
208
+ /**
209
+ * Create a BIP32 key from an xpub string (base58-encoded)
210
+ */
211
+ static from_xpub(xpub_str: string): WasmBIP32;
212
+ /**
213
+ * Serialize to base58 string
214
+ */
215
+ to_base58(): string;
216
+ /**
217
+ * Get the chain code as a Uint8Array
218
+ */
219
+ readonly chain_code: Uint8Array;
220
+ /**
221
+ * Get the identifier as a Uint8Array
222
+ */
223
+ readonly identifier: Uint8Array;
224
+ /**
225
+ * Get the public key as a Uint8Array
226
+ */
227
+ readonly public_key: Uint8Array;
228
+ /**
229
+ * Get the fingerprint as a Uint8Array
230
+ */
231
+ readonly fingerprint: Uint8Array;
232
+ /**
233
+ * Get the private key as a Uint8Array (if available)
234
+ */
235
+ readonly private_key: Uint8Array | undefined;
236
+ /**
237
+ * Get the parent fingerprint
238
+ */
239
+ readonly parent_fingerprint: number;
240
+ /**
241
+ * Get the depth
242
+ */
243
+ readonly depth: number;
244
+ /**
245
+ * Get the child index
246
+ */
247
+ readonly index: number;
248
+ }
249
+ /**
250
+ * WASM wrapper for elliptic curve key pairs (always uses compressed keys)
251
+ */
252
+ export class WasmECPair {
253
+ private constructor();
254
+ free(): void;
255
+ [Symbol.dispose](): void;
256
+ /**
257
+ * Convert to mainnet WIF string
258
+ */
259
+ to_wif_mainnet(): string;
260
+ /**
261
+ * Convert to testnet WIF string
262
+ */
263
+ to_wif_testnet(): string;
264
+ /**
265
+ * Create an ECPair from a public key (always uses compressed keys)
266
+ */
267
+ static from_public_key(public_key: Uint8Array): WasmECPair;
268
+ /**
269
+ * Create an ECPair from a private key (always uses compressed keys)
270
+ */
271
+ static from_private_key(private_key: Uint8Array): WasmECPair;
272
+ /**
273
+ * Create an ECPair from a mainnet WIF string
274
+ */
275
+ static from_wif_mainnet(wif_string: string): WasmECPair;
276
+ /**
277
+ * Create an ECPair from a testnet WIF string
278
+ */
279
+ static from_wif_testnet(wif_string: string): WasmECPair;
280
+ /**
281
+ * Convert to WIF string (mainnet)
282
+ */
283
+ to_wif(): string;
284
+ /**
285
+ * Create an ECPair from a WIF string (auto-detects network)
286
+ */
287
+ static from_wif(wif_string: string): WasmECPair;
288
+ /**
289
+ * Get the compressed public key as a Uint8Array (always 33 bytes)
290
+ */
291
+ readonly public_key: Uint8Array;
292
+ /**
293
+ * Get the private key as a Uint8Array (if available)
294
+ */
295
+ readonly private_key: Uint8Array | undefined;
296
+ }
297
+ /**
298
+ * WASM wrapper for ReplayProtection
299
+ */
300
+ export class WasmReplayProtection {
301
+ private constructor();
302
+ free(): void;
303
+ [Symbol.dispose](): void;
304
+ /**
305
+ * Create from addresses (requires network for decoding)
306
+ */
307
+ static from_addresses(addresses: any[], network: string): WasmReplayProtection;
308
+ /**
309
+ * Create from public keys (derives P2SH-P2PK output scripts)
310
+ */
311
+ static from_public_keys(public_keys: Uint8Array[]): WasmReplayProtection;
312
+ /**
313
+ * Create from output scripts directly
314
+ */
315
+ static from_output_scripts(output_scripts: Uint8Array[]): WasmReplayProtection;
316
+ }
317
+ /**
318
+ * WASM wrapper for RootWalletKeys
319
+ * Represents a set of three extended public keys with their derivation prefixes
320
+ */
321
+ export class WasmRootWalletKeys {
322
+ free(): void;
323
+ [Symbol.dispose](): void;
324
+ /**
325
+ * Get the backup key (second xpub)
326
+ */
327
+ backup_key(): WasmBIP32;
328
+ /**
329
+ * Create a RootWalletKeys from three BIP32 keys with custom derivation prefixes
330
+ *
331
+ * # Arguments
332
+ * - `user`: User key (first xpub)
333
+ * - `backup`: Backup key (second xpub)
334
+ * - `bitgo`: BitGo key (third xpub)
335
+ * - `user_derivation`: Derivation path for user key (e.g., "m/0/0")
336
+ * - `backup_derivation`: Derivation path for backup key (e.g., "m/0/0")
337
+ * - `bitgo_derivation`: Derivation path for bitgo key (e.g., "m/0/0")
338
+ */
339
+ static with_derivation_prefixes(user: WasmBIP32, backup: WasmBIP32, bitgo: WasmBIP32, user_derivation: string, backup_derivation: string, bitgo_derivation: string): WasmRootWalletKeys;
340
+ /**
341
+ * Create a RootWalletKeys from three BIP32 keys
342
+ * Uses default derivation prefix of m/0/0 for all three keys
343
+ *
344
+ * # Arguments
345
+ * - `user`: User key (first xpub)
346
+ * - `backup`: Backup key (second xpub)
347
+ * - `bitgo`: BitGo key (third xpub)
348
+ */
349
+ constructor(user: WasmBIP32, backup: WasmBIP32, bitgo: WasmBIP32);
350
+ /**
351
+ * Get the user key (first xpub)
352
+ */
353
+ user_key(): WasmBIP32;
354
+ /**
355
+ * Get the bitgo key (third xpub)
356
+ */
357
+ bitgo_key(): WasmBIP32;
358
+ }
127
359
  export class WrapDescriptor {
128
360
  private constructor();
129
361
  free(): void;