@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
@@ -1,31 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BitGoPsbt = void 0;
4
- exports.outputScript = outputScript;
5
- exports.address = address;
6
- const wasm_utxo_js_1 = require("./wasm/wasm_utxo.js");
7
- /**
8
- * Create the output script for a given wallet keys and chain and index
9
- */
10
- function outputScript(keys, chain, index, network) {
11
- return wasm_utxo_js_1.FixedScriptWalletNamespace.output_script(keys, chain, index, network);
12
- }
13
- /**
14
- * Create the address for a given wallet keys and chain and index and network.
15
- * Wrapper for outputScript that also encodes the script to an address.
16
- * @param keys - The wallet keys to use.
17
- * @param chain - The chain to use.
18
- * @param index - The index to use.
19
- * @param network - The network to use.
20
- * @param addressFormat - The address format to use.
21
- * Only relevant for Bitcoin Cash and eCash networks, where:
22
- * - "default" means base58check,
23
- * - "cashaddr" means cashaddr.
24
- */
25
- function address(keys, chain, index, network, addressFormat) {
26
- return wasm_utxo_js_1.FixedScriptWalletNamespace.address(keys, chain, index, network, addressFormat);
27
- }
28
- const wasm_utxo_js_2 = require("./wasm/wasm_utxo.js");
4
+ const wasm_utxo_js_1 = require("../wasm/wasm_utxo.js");
5
+ const RootWalletKeys_js_1 = require("./RootWalletKeys.js");
6
+ const ReplayProtection_js_1 = require("./ReplayProtection.js");
7
+ const bip32_js_1 = require("../bip32.js");
8
+ const ecpair_js_1 = require("../ecpair.js");
29
9
  class BitGoPsbt {
30
10
  wasm;
31
11
  constructor(wasm) {
@@ -38,7 +18,7 @@ class BitGoPsbt {
38
18
  * @returns A BitGoPsbt instance
39
19
  */
40
20
  static fromBytes(bytes, network) {
41
- const wasm = wasm_utxo_js_2.BitGoPsbt.from_bytes(bytes, network);
21
+ const wasm = wasm_utxo_js_1.BitGoPsbt.from_bytes(bytes, network);
42
22
  return new BitGoPsbt(wasm);
43
23
  }
44
24
  /**
@@ -55,7 +35,9 @@ class BitGoPsbt {
55
35
  * @returns Parsed transaction information
56
36
  */
57
37
  parseTransactionWithWalletKeys(walletKeys, replayProtection) {
58
- return this.wasm.parse_transaction_with_wallet_keys(walletKeys, replayProtection);
38
+ const keys = RootWalletKeys_js_1.RootWalletKeys.from(walletKeys);
39
+ const rp = ReplayProtection_js_1.ReplayProtection.from(replayProtection, this.wasm.network());
40
+ return this.wasm.parse_transaction_with_wallet_keys(keys.wasm, rp.wasm);
59
41
  }
60
42
  /**
61
43
  * Parse outputs with wallet keys to identify which outputs belong to a wallet
@@ -69,26 +51,57 @@ class BitGoPsbt {
69
51
  * @note This method does NOT validate wallet inputs. It only parses outputs.
70
52
  */
71
53
  parseOutputsWithWalletKeys(walletKeys) {
72
- return this.wasm.parse_outputs_with_wallet_keys(walletKeys);
54
+ const keys = RootWalletKeys_js_1.RootWalletKeys.from(walletKeys);
55
+ return this.wasm.parse_outputs_with_wallet_keys(keys.wasm);
73
56
  }
74
57
  /**
75
- * Verify if a valid signature exists for a given extended public key at the specified input index.
58
+ * Verify if a valid signature exists for a given key at the specified input index.
59
+ *
60
+ * This method can verify signatures using either:
61
+ * - Extended public key (xpub): Derives the public key using the derivation path from PSBT
62
+ * - ECPair (private key): Extracts the public key and verifies directly
76
63
  *
77
- * This method derives the public key from the xpub using the derivation path found in the
78
- * PSBT input, then verifies the signature. It supports:
64
+ * When using xpub, it supports:
79
65
  * - ECDSA signatures (for legacy/SegWit inputs)
80
66
  * - Schnorr signatures (for Taproot script path inputs)
81
67
  * - MuSig2 partial signatures (for Taproot keypath MuSig2 inputs)
82
68
  *
69
+ * When using ECPair, it supports:
70
+ * - ECDSA signatures (for legacy/SegWit inputs)
71
+ * - Schnorr signatures (for Taproot script path inputs)
72
+ * Note: MuSig2 inputs require xpubs for derivation
73
+ *
83
74
  * @param inputIndex - The index of the input to check (0-based)
84
- * @param xpub - The extended public key as a base58-encoded string
75
+ * @param key - Either an extended public key (base58 string, BIP32 instance, or WasmBIP32) or an ECPair (private key Buffer, ECPair instance, or WasmECPair)
85
76
  * @returns true if a valid signature exists, false if no signature exists
86
- * @throws Error if input index is out of bounds, xpub is invalid, or verification fails
77
+ * @throws Error if input index is out of bounds, key is invalid, or verification fails
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * // Verify wallet input signature with xpub
82
+ * const hasUserSig = psbt.verifySignature(0, userXpub);
83
+ *
84
+ * // Verify signature with ECPair (private key)
85
+ * const ecpair = ECPair.fromPrivateKey(privateKeyBuffer);
86
+ * const hasReplaySig = psbt.verifySignature(1, ecpair);
87
+ *
88
+ * // Or pass private key directly
89
+ * const hasReplaySig2 = psbt.verifySignature(1, privateKeyBuffer);
90
+ * ```
87
91
  */
88
- verifySignature(inputIndex, xpub) {
89
- return this.wasm.verify_signature(inputIndex, xpub);
92
+ verifySignature(inputIndex, key) {
93
+ // Try to parse as BIP32Arg first (string or BIP32 instance)
94
+ if (typeof key === "string" || ("derive" in key && typeof key.derive === "function")) {
95
+ const wasmKey = bip32_js_1.BIP32.from(key).wasm;
96
+ return this.wasm.verify_signature_with_xpub(inputIndex, wasmKey);
97
+ }
98
+ // Otherwise it's an ECPairArg (Uint8Array, ECPair, or WasmECPair)
99
+ const wasmECPair = ecpair_js_1.ECPair.from(key).wasm;
100
+ return this.wasm.verify_signature_with_pub(inputIndex, wasmECPair);
90
101
  }
91
102
  /**
103
+ * @deprecated - use verifySignature with the replay protection key instead
104
+ *
92
105
  * Verify if a replay protection input has a valid signature.
93
106
  *
94
107
  * This method checks if a given input is a replay protection input (like P2shP2pk) and verifies
@@ -107,7 +120,8 @@ class BitGoPsbt {
107
120
  * @throws Error if the input is not a replay protection input, index is out of bounds, or scripts are invalid
108
121
  */
109
122
  verifyReplayProtectionSignature(inputIndex, replayProtection) {
110
- return this.wasm.verify_replay_protection_signature(inputIndex, replayProtection);
123
+ const rp = ReplayProtection_js_1.ReplayProtection.from(replayProtection, this.wasm.network());
124
+ return this.wasm.verify_replay_protection_signature(inputIndex, rp.wasm);
111
125
  }
112
126
  /**
113
127
  * Serialize the PSBT to bytes
@@ -0,0 +1,58 @@
1
+ import { WasmReplayProtection } from "../wasm/wasm_utxo.js";
2
+ import { type ECPairArg } from "../ecpair.js";
3
+ /**
4
+ * ReplayProtectionArg represents the various forms that replay protection can take
5
+ * before being converted to a WasmReplayProtection instance
6
+ */
7
+ export type ReplayProtectionArg = ReplayProtection | WasmReplayProtection | {
8
+ publicKeys: ECPairArg[];
9
+ } | {
10
+ /** @deprecated - use publicKeys instead */
11
+ outputScripts: Uint8Array[];
12
+ } | {
13
+ /** @deprecated - use publicKeys instead */
14
+ addresses: string[];
15
+ };
16
+ /**
17
+ * ReplayProtection wrapper class for PSBT replay protection inputs
18
+ */
19
+ export declare class ReplayProtection {
20
+ private _wasm;
21
+ private constructor();
22
+ /**
23
+ * Create a ReplayProtection instance from a WasmReplayProtection instance (internal use)
24
+ * @internal
25
+ */
26
+ static fromWasm(wasm: WasmReplayProtection): ReplayProtection;
27
+ /**
28
+ * Convert ReplayProtectionArg to ReplayProtection instance
29
+ * @param arg - The replay protection in various formats
30
+ * @param network - Optional network string (required for addresses variant)
31
+ * @returns ReplayProtection instance
32
+ */
33
+ static from(arg: ReplayProtectionArg, network?: string): ReplayProtection;
34
+ /**
35
+ * Create from public keys (derives P2SH-P2PK output scripts)
36
+ * @param publicKeys - Array of ECPair instances or arguments
37
+ * @returns ReplayProtection instance
38
+ */
39
+ static fromPublicKeys(publicKeys: ECPairArg[]): ReplayProtection;
40
+ /**
41
+ * Create from output scripts
42
+ * @param outputScripts - Array of output script buffers
43
+ * @returns ReplayProtection instance
44
+ */
45
+ static fromOutputScripts(outputScripts: Uint8Array[]): ReplayProtection;
46
+ /**
47
+ * Create from addresses
48
+ * @param addresses - Array of address strings
49
+ * @param network - Network string (e.g., "bitcoin", "testnet", "btc", "tbtc")
50
+ * @returns ReplayProtection instance
51
+ */
52
+ static fromAddresses(addresses: string[], network: string): ReplayProtection;
53
+ /**
54
+ * Get the underlying WASM instance (internal use only)
55
+ * @internal
56
+ */
57
+ get wasm(): WasmReplayProtection;
58
+ }
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReplayProtection = void 0;
4
+ const wasm_utxo_js_1 = require("../wasm/wasm_utxo.js");
5
+ const ecpair_js_1 = require("../ecpair.js");
6
+ /**
7
+ * ReplayProtection wrapper class for PSBT replay protection inputs
8
+ */
9
+ class ReplayProtection {
10
+ _wasm;
11
+ constructor(_wasm) {
12
+ this._wasm = _wasm;
13
+ }
14
+ /**
15
+ * Create a ReplayProtection instance from a WasmReplayProtection instance (internal use)
16
+ * @internal
17
+ */
18
+ static fromWasm(wasm) {
19
+ return new ReplayProtection(wasm);
20
+ }
21
+ /**
22
+ * Convert ReplayProtectionArg to ReplayProtection instance
23
+ * @param arg - The replay protection in various formats
24
+ * @param network - Optional network string (required for addresses variant)
25
+ * @returns ReplayProtection instance
26
+ */
27
+ static from(arg, network) {
28
+ // Short-circuit if already a ReplayProtection instance
29
+ if (arg instanceof ReplayProtection) {
30
+ return arg;
31
+ }
32
+ // If it's a WasmReplayProtection instance, wrap it
33
+ if (arg instanceof wasm_utxo_js_1.WasmReplayProtection) {
34
+ return new ReplayProtection(arg);
35
+ }
36
+ // Handle object variants
37
+ if ("publicKeys" in arg) {
38
+ // Convert ECPairArg to public key bytes
39
+ const publicKeyBytes = arg.publicKeys.map((key) => ecpair_js_1.ECPair.from(key).publicKey);
40
+ const wasm = wasm_utxo_js_1.WasmReplayProtection.from_public_keys(publicKeyBytes);
41
+ return new ReplayProtection(wasm);
42
+ }
43
+ if ("outputScripts" in arg) {
44
+ const wasm = wasm_utxo_js_1.WasmReplayProtection.from_output_scripts(arg.outputScripts);
45
+ return new ReplayProtection(wasm);
46
+ }
47
+ if ("addresses" in arg) {
48
+ if (!network) {
49
+ throw new Error("Network is required when using addresses variant");
50
+ }
51
+ const wasm = wasm_utxo_js_1.WasmReplayProtection.from_addresses(arg.addresses, network);
52
+ return new ReplayProtection(wasm);
53
+ }
54
+ throw new Error("Invalid ReplayProtectionArg type");
55
+ }
56
+ /**
57
+ * Create from public keys (derives P2SH-P2PK output scripts)
58
+ * @param publicKeys - Array of ECPair instances or arguments
59
+ * @returns ReplayProtection instance
60
+ */
61
+ static fromPublicKeys(publicKeys) {
62
+ return ReplayProtection.from({ publicKeys });
63
+ }
64
+ /**
65
+ * Create from output scripts
66
+ * @param outputScripts - Array of output script buffers
67
+ * @returns ReplayProtection instance
68
+ */
69
+ static fromOutputScripts(outputScripts) {
70
+ return ReplayProtection.from({ outputScripts });
71
+ }
72
+ /**
73
+ * Create from addresses
74
+ * @param addresses - Array of address strings
75
+ * @param network - Network string (e.g., "bitcoin", "testnet", "btc", "tbtc")
76
+ * @returns ReplayProtection instance
77
+ */
78
+ static fromAddresses(addresses, network) {
79
+ return ReplayProtection.from({ addresses }, network);
80
+ }
81
+ /**
82
+ * Get the underlying WASM instance (internal use only)
83
+ * @internal
84
+ */
85
+ get wasm() {
86
+ return this._wasm;
87
+ }
88
+ }
89
+ exports.ReplayProtection = ReplayProtection;
@@ -0,0 +1,66 @@
1
+ import type { BIP32Interface } from "../bip32.js";
2
+ import { BIP32 } from "../bip32.js";
3
+ import { Triple } from "../triple.js";
4
+ import { WasmRootWalletKeys } from "../wasm/wasm_utxo.js";
5
+ /**
6
+ * IWalletKeys represents the various forms that wallet keys can take
7
+ * before being converted to a RootWalletKeys instance
8
+ */
9
+ export type IWalletKeys = {
10
+ triple: Triple<BIP32Interface>;
11
+ derivationPrefixes: Triple<string>;
12
+ };
13
+ export type WalletKeysArg =
14
+ /** Just an xpub triple, will assume default derivation prefixes */
15
+ Triple<string>
16
+ /** Compatible with utxolib RootWalletKeys */
17
+ | IWalletKeys
18
+ /** RootWalletKeys instance */
19
+ | RootWalletKeys;
20
+ /**
21
+ * RootWalletKeys represents a set of three extended public keys with their derivation prefixes
22
+ */
23
+ export declare class RootWalletKeys {
24
+ private _wasm;
25
+ private constructor();
26
+ /**
27
+ * Create a RootWalletKeys from various input formats
28
+ * @param keys - Can be a triple of xpub strings, an IWalletKeys object, or another RootWalletKeys instance
29
+ * @returns A RootWalletKeys instance
30
+ */
31
+ static from(keys: WalletKeysArg): RootWalletKeys;
32
+ /**
33
+ * Create a RootWalletKeys from three xpub strings
34
+ * Uses default derivation prefix of m/0/0 for all three keys
35
+ * @param xpubs - Triple of xpub strings
36
+ * @returns A RootWalletKeys instance
37
+ */
38
+ static fromXpubs(xpubs: Triple<string>): RootWalletKeys;
39
+ /**
40
+ * Create a RootWalletKeys from three xpub strings with custom derivation prefixes
41
+ * @param xpubs - Triple of xpub strings
42
+ * @param derivationPrefixes - Triple of derivation path strings (e.g., ["0/0", "0/0", "0/0"])
43
+ * @returns A RootWalletKeys instance
44
+ */
45
+ static withDerivationPrefixes(xpubs: Triple<string>, derivationPrefixes: Triple<string>): RootWalletKeys;
46
+ /**
47
+ * Get the user key (first xpub)
48
+ * @returns The user key as a BIP32 instance
49
+ */
50
+ userKey(): BIP32;
51
+ /**
52
+ * Get the backup key (second xpub)
53
+ * @returns The backup key as a BIP32 instance
54
+ */
55
+ backupKey(): BIP32;
56
+ /**
57
+ * Get the BitGo key (third xpub)
58
+ * @returns The BitGo key as a BIP32 instance
59
+ */
60
+ bitgoKey(): BIP32;
61
+ /**
62
+ * Get the underlying WASM instance (internal use only)
63
+ * @internal
64
+ */
65
+ get wasm(): WasmRootWalletKeys;
66
+ }
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RootWalletKeys = void 0;
4
+ const bip32_js_1 = require("../bip32.js");
5
+ const wasm_utxo_js_1 = require("../wasm/wasm_utxo.js");
6
+ /**
7
+ * Convert WalletKeysArg to a triple of BIP32 instances
8
+ */
9
+ function toBIP32Triple(keys) {
10
+ if (keys instanceof RootWalletKeys) {
11
+ return [keys.userKey(), keys.backupKey(), keys.bitgoKey()];
12
+ }
13
+ // Check if it's an IWalletKeys object
14
+ if (typeof keys === "object" && "triple" in keys) {
15
+ // Extract BIP32 keys from the triple
16
+ return keys.triple.map((key) => bip32_js_1.BIP32.from(key));
17
+ }
18
+ // Otherwise it's a triple of strings (xpubs)
19
+ return keys.map((xpub) => bip32_js_1.BIP32.fromWasm(wasm_utxo_js_1.WasmBIP32.from_xpub(xpub)));
20
+ }
21
+ /**
22
+ * Extract derivation prefixes from WalletKeysArg, if present
23
+ */
24
+ function extractDerivationPrefixes(keys) {
25
+ if (typeof keys === "object" && "derivationPrefixes" in keys) {
26
+ return keys.derivationPrefixes;
27
+ }
28
+ return null;
29
+ }
30
+ /**
31
+ * RootWalletKeys represents a set of three extended public keys with their derivation prefixes
32
+ */
33
+ class RootWalletKeys {
34
+ _wasm;
35
+ constructor(_wasm) {
36
+ this._wasm = _wasm;
37
+ }
38
+ /**
39
+ * Create a RootWalletKeys from various input formats
40
+ * @param keys - Can be a triple of xpub strings, an IWalletKeys object, or another RootWalletKeys instance
41
+ * @returns A RootWalletKeys instance
42
+ */
43
+ static from(keys) {
44
+ if (keys instanceof RootWalletKeys) {
45
+ return keys;
46
+ }
47
+ const [user, backup, bitgo] = toBIP32Triple(keys);
48
+ const derivationPrefixes = extractDerivationPrefixes(keys);
49
+ const wasm = derivationPrefixes
50
+ ? wasm_utxo_js_1.WasmRootWalletKeys.with_derivation_prefixes(user.wasm, backup.wasm, bitgo.wasm, derivationPrefixes[0], derivationPrefixes[1], derivationPrefixes[2])
51
+ : new wasm_utxo_js_1.WasmRootWalletKeys(user.wasm, backup.wasm, bitgo.wasm);
52
+ return new RootWalletKeys(wasm);
53
+ }
54
+ /**
55
+ * Create a RootWalletKeys from three xpub strings
56
+ * Uses default derivation prefix of m/0/0 for all three keys
57
+ * @param xpubs - Triple of xpub strings
58
+ * @returns A RootWalletKeys instance
59
+ */
60
+ static fromXpubs(xpubs) {
61
+ const [user, backup, bitgo] = xpubs.map((xpub) => wasm_utxo_js_1.WasmBIP32.from_xpub(xpub));
62
+ const wasm = new wasm_utxo_js_1.WasmRootWalletKeys(user, backup, bitgo);
63
+ return new RootWalletKeys(wasm);
64
+ }
65
+ /**
66
+ * Create a RootWalletKeys from three xpub strings with custom derivation prefixes
67
+ * @param xpubs - Triple of xpub strings
68
+ * @param derivationPrefixes - Triple of derivation path strings (e.g., ["0/0", "0/0", "0/0"])
69
+ * @returns A RootWalletKeys instance
70
+ */
71
+ static withDerivationPrefixes(xpubs, derivationPrefixes) {
72
+ const [user, backup, bitgo] = xpubs.map((xpub) => wasm_utxo_js_1.WasmBIP32.from_xpub(xpub));
73
+ const wasm = wasm_utxo_js_1.WasmRootWalletKeys.with_derivation_prefixes(user, backup, bitgo, derivationPrefixes[0], derivationPrefixes[1], derivationPrefixes[2]);
74
+ return new RootWalletKeys(wasm);
75
+ }
76
+ /**
77
+ * Get the user key (first xpub)
78
+ * @returns The user key as a BIP32 instance
79
+ */
80
+ userKey() {
81
+ const wasm = this._wasm.user_key();
82
+ return bip32_js_1.BIP32.fromWasm(wasm);
83
+ }
84
+ /**
85
+ * Get the backup key (second xpub)
86
+ * @returns The backup key as a BIP32 instance
87
+ */
88
+ backupKey() {
89
+ const wasm = this._wasm.backup_key();
90
+ return bip32_js_1.BIP32.fromWasm(wasm);
91
+ }
92
+ /**
93
+ * Get the BitGo key (third xpub)
94
+ * @returns The BitGo key as a BIP32 instance
95
+ */
96
+ bitgoKey() {
97
+ const wasm = this._wasm.bitgo_key();
98
+ return bip32_js_1.BIP32.fromWasm(wasm);
99
+ }
100
+ /**
101
+ * Get the underlying WASM instance (internal use only)
102
+ * @internal
103
+ */
104
+ get wasm() {
105
+ return this._wasm;
106
+ }
107
+ }
108
+ exports.RootWalletKeys = RootWalletKeys;
@@ -0,0 +1,20 @@
1
+ import { type WalletKeysArg } from "./RootWalletKeys.js";
2
+ import type { UtxolibNetwork } from "../utxolibCompat.js";
3
+ import { AddressFormat } from "../address.js";
4
+ /**
5
+ * Create the output script for a given wallet keys and chain and index
6
+ */
7
+ export declare function outputScript(keys: WalletKeysArg, chain: number, index: number, network: UtxolibNetwork): Uint8Array;
8
+ /**
9
+ * Create the address for a given wallet keys and chain and index and network.
10
+ * Wrapper for outputScript that also encodes the script to an address.
11
+ * @param keys - The wallet keys to use.
12
+ * @param chain - The chain to use.
13
+ * @param index - The index to use.
14
+ * @param network - The network to use.
15
+ * @param addressFormat - The address format to use.
16
+ * Only relevant for Bitcoin Cash and eCash networks, where:
17
+ * - "default" means base58check,
18
+ * - "cashaddr" means cashaddr.
19
+ */
20
+ export declare function address(keys: WalletKeysArg, chain: number, index: number, network: UtxolibNetwork, addressFormat?: AddressFormat): string;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.outputScript = outputScript;
4
+ exports.address = address;
5
+ const wasm_utxo_js_1 = require("../wasm/wasm_utxo.js");
6
+ const RootWalletKeys_js_1 = require("./RootWalletKeys.js");
7
+ /**
8
+ * Create the output script for a given wallet keys and chain and index
9
+ */
10
+ function outputScript(keys, chain, index, network) {
11
+ const walletKeys = RootWalletKeys_js_1.RootWalletKeys.from(keys);
12
+ return wasm_utxo_js_1.FixedScriptWalletNamespace.output_script(walletKeys.wasm, chain, index, network);
13
+ }
14
+ /**
15
+ * Create the address for a given wallet keys and chain and index and network.
16
+ * Wrapper for outputScript that also encodes the script to an address.
17
+ * @param keys - The wallet keys to use.
18
+ * @param chain - The chain to use.
19
+ * @param index - The index to use.
20
+ * @param network - The network to use.
21
+ * @param addressFormat - The address format to use.
22
+ * Only relevant for Bitcoin Cash and eCash networks, where:
23
+ * - "default" means base58check,
24
+ * - "cashaddr" means cashaddr.
25
+ */
26
+ function address(keys, chain, index, network, addressFormat) {
27
+ const walletKeys = RootWalletKeys_js_1.RootWalletKeys.from(keys);
28
+ return wasm_utxo_js_1.FixedScriptWalletNamespace.address(walletKeys.wasm, chain, index, network, addressFormat);
29
+ }
@@ -0,0 +1,4 @@
1
+ export { RootWalletKeys, type WalletKeysArg, type IWalletKeys } from "./RootWalletKeys.js";
2
+ export { ReplayProtection, type ReplayProtectionArg } from "./ReplayProtection.js";
3
+ export { outputScript, address } from "./address.js";
4
+ export { BitGoPsbt, type NetworkName, type ScriptId, type InputScriptType, type ParsedInput, type ParsedOutput, type ParsedTransaction, } from "./BitGoPsbt.js";
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BitGoPsbt = exports.address = exports.outputScript = exports.ReplayProtection = exports.RootWalletKeys = void 0;
4
+ var RootWalletKeys_js_1 = require("./RootWalletKeys.js");
5
+ Object.defineProperty(exports, "RootWalletKeys", { enumerable: true, get: function () { return RootWalletKeys_js_1.RootWalletKeys; } });
6
+ var ReplayProtection_js_1 = require("./ReplayProtection.js");
7
+ Object.defineProperty(exports, "ReplayProtection", { enumerable: true, get: function () { return ReplayProtection_js_1.ReplayProtection; } });
8
+ var address_js_1 = require("./address.js");
9
+ Object.defineProperty(exports, "outputScript", { enumerable: true, get: function () { return address_js_1.outputScript; } });
10
+ Object.defineProperty(exports, "address", { enumerable: true, get: function () { return address_js_1.address; } });
11
+ var BitGoPsbt_js_1 = require("./BitGoPsbt.js");
12
+ Object.defineProperty(exports, "BitGoPsbt", { enumerable: true, get: function () { return BitGoPsbt_js_1.BitGoPsbt; } });
@@ -1,7 +1,11 @@
1
1
  export * as address from "./address.js";
2
2
  export * as ast from "./ast/index.js";
3
3
  export * as utxolibCompat from "./utxolibCompat.js";
4
- export * as fixedScriptWallet from "./fixedScriptWallet.js";
4
+ export * as fixedScriptWallet from "./fixedScriptWallet/index.js";
5
+ export * as bip32 from "./bip32.js";
6
+ export * as ecpair from "./ecpair.js";
7
+ export { ECPair } from "./ecpair.js";
8
+ export { BIP32 } from "./bip32.js";
5
9
  export type { CoinName } from "./coinName.js";
6
10
  export type { Triple } from "./triple.js";
7
11
  export type { AddressFormat } from "./address.js";
@@ -33,15 +33,24 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.Psbt = exports.Miniscript = exports.Descriptor = exports.fixedScriptWallet = exports.utxolibCompat = exports.ast = exports.address = void 0;
36
+ exports.Psbt = exports.Miniscript = exports.Descriptor = exports.BIP32 = exports.ECPair = exports.ecpair = exports.bip32 = exports.fixedScriptWallet = exports.utxolibCompat = exports.ast = exports.address = void 0;
37
37
  const wasm = __importStar(require("./wasm/wasm_utxo.js"));
38
38
  // we need to access the wasm module here, otherwise webpack gets all weird
39
39
  // and forgets to include it in the bundle
40
40
  void wasm;
41
+ // Most exports are namespaced to avoid polluting the top-level namespace
42
+ // and to make imports more explicit (e.g., `import { address } from '@bitgo/wasm-utxo'`)
41
43
  exports.address = __importStar(require("./address.js"));
42
44
  exports.ast = __importStar(require("./ast/index.js"));
43
45
  exports.utxolibCompat = __importStar(require("./utxolibCompat.js"));
44
- exports.fixedScriptWallet = __importStar(require("./fixedScriptWallet.js"));
46
+ exports.fixedScriptWallet = __importStar(require("./fixedScriptWallet/index.js"));
47
+ exports.bip32 = __importStar(require("./bip32.js"));
48
+ exports.ecpair = __importStar(require("./ecpair.js"));
49
+ // Only the most commonly used classes and types are exported at the top level for convenience
50
+ var ecpair_js_1 = require("./ecpair.js");
51
+ Object.defineProperty(exports, "ECPair", { enumerable: true, get: function () { return ecpair_js_1.ECPair; } });
52
+ var bip32_js_1 = require("./bip32.js");
53
+ Object.defineProperty(exports, "BIP32", { enumerable: true, get: function () { return bip32_js_1.BIP32; } });
45
54
  var wasm_utxo_js_1 = require("./wasm/wasm_utxo.js");
46
55
  Object.defineProperty(exports, "Descriptor", { enumerable: true, get: function () { return wasm_utxo_js_1.WrapDescriptor; } });
47
56
  var wasm_utxo_js_2 = require("./wasm/wasm_utxo.js");
@@ -1,23 +1,5 @@
1
1
  import type { AddressFormat } from "./address.js";
2
- import { Triple } from "./triple.js";
3
2
  export type UtxolibName = "bitcoin" | "testnet" | "bitcoinTestnet4" | "bitcoinPublicSignet" | "bitcoinBitGoSignet" | "bitcoincash" | "bitcoincashTestnet" | "ecash" | "ecashTest" | "bitcoingold" | "bitcoingoldTestnet" | "bitcoinsv" | "bitcoinsvTestnet" | "dash" | "dashTest" | "dogecoin" | "dogecoinTest" | "litecoin" | "litecoinTest" | "zcash" | "zcashTest";
4
- export type BIP32Interface = {
5
- network: {
6
- bip32: {
7
- public: number;
8
- };
9
- };
10
- depth: number;
11
- parentFingerprint: number;
12
- index: number;
13
- chainCode: Uint8Array;
14
- publicKey: Uint8Array;
15
- toBase58?(): string;
16
- };
17
- export type UtxolibRootWalletKeys = {
18
- triple: Triple<BIP32Interface>;
19
- derivationPrefixes: Triple<string>;
20
- };
21
3
  export type UtxolibNetwork = {
22
4
  pubKeyHash: number;
23
5
  scriptHash: number;