@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
@@ -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;