@bitgo/wasm-utxo 1.28.0 → 1.29.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 (33) hide show
  1. package/dist/cjs/js/fixedScriptWallet/chains.d.ts +5 -0
  2. package/dist/cjs/js/fixedScriptWallet/chains.js +6 -2
  3. package/dist/cjs/js/fixedScriptWallet/index.d.ts +19 -2
  4. package/dist/cjs/js/fixedScriptWallet/index.js +25 -1
  5. package/dist/cjs/js/fixedScriptWallet/scriptType.d.ts +15 -5
  6. package/dist/cjs/js/fixedScriptWallet/scriptType.js +28 -0
  7. package/dist/cjs/js/testutils/AcidTest.d.ts +132 -0
  8. package/dist/cjs/js/testutils/AcidTest.js +306 -0
  9. package/dist/cjs/js/testutils/index.d.ts +2 -0
  10. package/dist/cjs/js/testutils/index.js +18 -0
  11. package/dist/cjs/js/testutils/keys.d.ts +76 -0
  12. package/dist/cjs/js/testutils/keys.js +154 -0
  13. package/dist/cjs/js/wasm/wasm_utxo.d.ts +10 -0
  14. package/dist/cjs/js/wasm/wasm_utxo.js +31 -0
  15. package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
  16. package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +2 -1
  17. package/dist/esm/js/fixedScriptWallet/chains.d.ts +5 -0
  18. package/dist/esm/js/fixedScriptWallet/chains.js +6 -3
  19. package/dist/esm/js/fixedScriptWallet/index.d.ts +19 -2
  20. package/dist/esm/js/fixedScriptWallet/index.js +21 -1
  21. package/dist/esm/js/fixedScriptWallet/scriptType.d.ts +15 -5
  22. package/dist/esm/js/fixedScriptWallet/scriptType.js +27 -1
  23. package/dist/esm/js/testutils/AcidTest.d.ts +132 -0
  24. package/dist/esm/js/testutils/AcidTest.js +302 -0
  25. package/dist/esm/js/testutils/index.d.ts +2 -0
  26. package/dist/esm/js/testutils/index.js +2 -0
  27. package/dist/esm/js/testutils/keys.d.ts +76 -0
  28. package/dist/esm/js/testutils/keys.js +113 -0
  29. package/dist/esm/js/wasm/wasm_utxo.d.ts +10 -0
  30. package/dist/esm/js/wasm/wasm_utxo_bg.js +31 -0
  31. package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
  32. package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +2 -1
  33. package/package.json +1 -1
@@ -0,0 +1,76 @@
1
+ import { BIP32 } from "../bip32.js";
2
+ import { RootWalletKeys } from "../fixedScriptWallet/RootWalletKeys.js";
3
+ import type { Triple } from "../triple.js";
4
+ /**
5
+ * Generate a deterministic BIP32 key from a seed string.
6
+ * Uses SHA256 hash of the seed to create the key, matching utxo-lib's implementation.
7
+ *
8
+ * @param seed - Seed string for deterministic key generation
9
+ * @returns BIP32 key derived from the seed
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const key = getKey("user");
14
+ * const xpub = key.neutered().toBase58();
15
+ * ```
16
+ */
17
+ export declare function getKey(seed: string): BIP32;
18
+ /**
19
+ * Generate a triple of BIP32 keys for a 2-of-3 multisig wallet.
20
+ * Keys are generated deterministically from the seed string with suffixes .0, .1, .2
21
+ * for user, backup, and bitgo keys respectively.
22
+ *
23
+ * @param seed - Base seed string for key generation
24
+ * @returns Triple of BIP32 keys [user, backup, bitgo]
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const keys = getKeyTriple("default");
29
+ * const [user, backup, bitgo] = keys;
30
+ * ```
31
+ */
32
+ export declare function getKeyTriple(seed: string): Triple<BIP32>;
33
+ /**
34
+ * Create RootWalletKeys from a seed string.
35
+ * Uses standard derivation prefixes ["m/0/0", "m/0/0", "m/0/0"].
36
+ *
37
+ * @param seed - Seed string for key generation
38
+ * @returns RootWalletKeys instance
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * const walletKeys = getWalletKeysForSeed("default");
43
+ * ```
44
+ */
45
+ export declare function getWalletKeysForSeed(seed: string): RootWalletKeys;
46
+ /**
47
+ * Get the default wallet keys for testing.
48
+ * Equivalent to getWalletKeysForSeed("default").
49
+ *
50
+ * @returns RootWalletKeys instance with default seed
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const walletKeys = getDefaultWalletKeys();
55
+ * ```
56
+ */
57
+ export declare function getDefaultWalletKeys(): RootWalletKeys;
58
+ /**
59
+ * Get the key name (user, backup, or bitgo) for a given key in a triple.
60
+ *
61
+ * @param triple - Triple of BIP32 keys
62
+ * @param key - Key to find in the triple
63
+ * @returns "user", "backup", "bitgo", or undefined if not found
64
+ */
65
+ export declare function getKeyName(triple: Triple<BIP32>, key: BIP32): "user" | "backup" | "bitgo" | undefined;
66
+ /**
67
+ * Get the default cosigner for a given signer key.
68
+ * - If signer is user, returns bitgo
69
+ * - If signer is backup, returns bitgo
70
+ * - If signer is bitgo, returns user
71
+ *
72
+ * @param keyset - Triple of keys [user, backup, bitgo]
73
+ * @param signer - The signing key
74
+ * @returns The default cosigner key
75
+ */
76
+ export declare function getDefaultCosigner<T>(keyset: Triple<T>, signer: T): T;
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.getKey = getKey;
37
+ exports.getKeyTriple = getKeyTriple;
38
+ exports.getWalletKeysForSeed = getWalletKeysForSeed;
39
+ exports.getDefaultWalletKeys = getDefaultWalletKeys;
40
+ exports.getKeyName = getKeyName;
41
+ exports.getDefaultCosigner = getDefaultCosigner;
42
+ const crypto = __importStar(require("crypto"));
43
+ const bip32_js_1 = require("../bip32.js");
44
+ const RootWalletKeys_js_1 = require("../fixedScriptWallet/RootWalletKeys.js");
45
+ /**
46
+ * Generate a deterministic BIP32 key from a seed string.
47
+ * Uses SHA256 hash of the seed to create the key, matching utxo-lib's implementation.
48
+ *
49
+ * @param seed - Seed string for deterministic key generation
50
+ * @returns BIP32 key derived from the seed
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const key = getKey("user");
55
+ * const xpub = key.neutered().toBase58();
56
+ * ```
57
+ */
58
+ function getKey(seed) {
59
+ return bip32_js_1.BIP32.fromSeed(crypto.createHash("sha256").update(seed).digest());
60
+ }
61
+ /**
62
+ * Generate a triple of BIP32 keys for a 2-of-3 multisig wallet.
63
+ * Keys are generated deterministically from the seed string with suffixes .0, .1, .2
64
+ * for user, backup, and bitgo keys respectively.
65
+ *
66
+ * @param seed - Base seed string for key generation
67
+ * @returns Triple of BIP32 keys [user, backup, bitgo]
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * const keys = getKeyTriple("default");
72
+ * const [user, backup, bitgo] = keys;
73
+ * ```
74
+ */
75
+ function getKeyTriple(seed) {
76
+ return [getKey(seed + ".0"), getKey(seed + ".1"), getKey(seed + ".2")];
77
+ }
78
+ /**
79
+ * Create RootWalletKeys from a seed string.
80
+ * Uses standard derivation prefixes ["m/0/0", "m/0/0", "m/0/0"].
81
+ *
82
+ * @param seed - Seed string for key generation
83
+ * @returns RootWalletKeys instance
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const walletKeys = getWalletKeysForSeed("default");
88
+ * ```
89
+ */
90
+ function getWalletKeysForSeed(seed) {
91
+ const triple = getKeyTriple(seed);
92
+ return RootWalletKeys_js_1.RootWalletKeys.from({
93
+ triple,
94
+ derivationPrefixes: ["m/0/0", "m/0/0", "m/0/0"],
95
+ });
96
+ }
97
+ /**
98
+ * Get the default wallet keys for testing.
99
+ * Equivalent to getWalletKeysForSeed("default").
100
+ *
101
+ * @returns RootWalletKeys instance with default seed
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * const walletKeys = getDefaultWalletKeys();
106
+ * ```
107
+ */
108
+ function getDefaultWalletKeys() {
109
+ return getWalletKeysForSeed("default");
110
+ }
111
+ /**
112
+ * Get the key name (user, backup, or bitgo) for a given key in a triple.
113
+ *
114
+ * @param triple - Triple of BIP32 keys
115
+ * @param key - Key to find in the triple
116
+ * @returns "user", "backup", "bitgo", or undefined if not found
117
+ */
118
+ function getKeyName(triple, key) {
119
+ const index = triple.findIndex((k) => {
120
+ const kb58 = k.toBase58();
121
+ const keyb58 = key.toBase58();
122
+ return kb58 === keyb58;
123
+ });
124
+ if (index === 0)
125
+ return "user";
126
+ if (index === 1)
127
+ return "backup";
128
+ if (index === 2)
129
+ return "bitgo";
130
+ return undefined;
131
+ }
132
+ /**
133
+ * Get the default cosigner for a given signer key.
134
+ * - If signer is user, returns bitgo
135
+ * - If signer is backup, returns bitgo
136
+ * - If signer is bitgo, returns user
137
+ *
138
+ * @param keyset - Triple of keys [user, backup, bitgo]
139
+ * @param signer - The signing key
140
+ * @returns The default cosigner key
141
+ */
142
+ function getDefaultCosigner(keyset, signer) {
143
+ const [user, backup, bitgo] = keyset;
144
+ if (signer === user) {
145
+ return bitgo;
146
+ }
147
+ if (signer === backup) {
148
+ return bitgo;
149
+ }
150
+ if (signer === bitgo) {
151
+ return user;
152
+ }
153
+ throw new Error("signer not in keyset");
154
+ }
@@ -677,6 +677,16 @@ export class FixedScriptWalletNamespace {
677
677
  * - Dogecoin only supports legacy scripts (p2sh)
678
678
  */
679
679
  static supports_script_type(coin: string, script_type: string): boolean;
680
+ /**
681
+ * Create an OP_RETURN output script with optional data
682
+ *
683
+ * # Arguments
684
+ * * `data` - Optional data bytes to include in the OP_RETURN script
685
+ *
686
+ * # Returns
687
+ * The OP_RETURN script as bytes
688
+ */
689
+ static create_op_return_script(data?: Uint8Array | null): Uint8Array;
680
690
  static address_with_network_str(keys: WasmRootWalletKeys, chain: number, index: number, network: string, address_format?: string | null): string;
681
691
  static output_script_with_network_str(keys: WasmRootWalletKeys, chain: number, index: number, network: string): Uint8Array;
682
692
  static address(keys: WasmRootWalletKeys, chain: number, index: number, network: any, address_format?: string | null): string;
@@ -1896,6 +1896,37 @@ class FixedScriptWalletNamespace {
1896
1896
  wasm.__wbindgen_add_to_stack_pointer(16);
1897
1897
  }
1898
1898
  }
1899
+ /**
1900
+ * Create an OP_RETURN output script with optional data
1901
+ *
1902
+ * # Arguments
1903
+ * * `data` - Optional data bytes to include in the OP_RETURN script
1904
+ *
1905
+ * # Returns
1906
+ * The OP_RETURN script as bytes
1907
+ * @param {Uint8Array | null} [data]
1908
+ * @returns {Uint8Array}
1909
+ */
1910
+ static create_op_return_script(data) {
1911
+ try {
1912
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1913
+ var ptr0 = isLikeNone(data) ? 0 : passArray8ToWasm0(data, wasm.__wbindgen_export);
1914
+ var len0 = WASM_VECTOR_LEN;
1915
+ wasm.fixedscriptwalletnamespace_create_op_return_script(retptr, ptr0, len0);
1916
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1917
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1918
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1919
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1920
+ if (r3) {
1921
+ throw takeObject(r2);
1922
+ }
1923
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
1924
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
1925
+ return v2;
1926
+ } finally {
1927
+ wasm.__wbindgen_add_to_stack_pointer(16);
1928
+ }
1929
+ }
1899
1930
  /**
1900
1931
  * @param {WasmRootWalletKeys} keys
1901
1932
  * @param {number} chain
Binary file
@@ -100,6 +100,7 @@ export const bitgopsbt_version_group_id: (a: number) => number;
100
100
  export const fixedscriptwalletnamespace_address: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
101
101
  export const fixedscriptwalletnamespace_address_with_network_str: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
102
102
  export const fixedscriptwalletnamespace_chain_code_table: () => number;
103
+ export const fixedscriptwalletnamespace_create_op_return_script: (a: number, b: number, c: number) => void;
103
104
  export const fixedscriptwalletnamespace_output_script: (a: number, b: number, c: number, d: number, e: number) => void;
104
105
  export const fixedscriptwalletnamespace_output_script_with_network_str: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
105
106
  export const fixedscriptwalletnamespace_supports_script_type: (a: number, b: number, c: number, d: number, e: number) => void;
@@ -154,8 +155,8 @@ export const wasmrootwalletkeys_new: (a: number, b: number, c: number, d: number
154
155
  export const wasmrootwalletkeys_user_key: (a: number) => number;
155
156
  export const wasmrootwalletkeys_with_derivation_prefixes: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
156
157
  export const wasmbip32_from_bip32_properties: (a: number, b: number) => void;
157
- export const bitgopsbt_sign_all_with_xpriv: (a: number, b: number, c: number) => void;
158
158
  export const bitgopsbt_sign_replay_protection_inputs: (a: number, b: number, c: number) => void;
159
+ export const bitgopsbt_sign_all_with_xpriv: (a: number, b: number, c: number) => void;
159
160
  export const bitgopsbt_sign_wallet_input: (a: number, b: number, c: number, d: number) => void;
160
161
  export const __wbg_wasmdashtransaction_free: (a: number, b: number) => void;
161
162
  export const __wbg_wasmreplayprotection_free: (a: number, b: number) => void;
@@ -5,6 +5,11 @@ export declare const chainCodes: readonly [0, 1, 10, 11, 20, 21, 30, 31, 40, 41]
5
5
  export type ChainCode = (typeof chainCodes)[number];
6
6
  /** Whether a chain is for receiving (external) or change (internal) addresses */
7
7
  export type Scope = "internal" | "external";
8
+ /**
9
+ * Assert that a number is a valid chain code.
10
+ * @throws Error if the number is not a valid chain code
11
+ */
12
+ export declare function assertChainCode(n: number): ChainCode;
8
13
  /**
9
14
  * ChainCode namespace with utility functions for working with chain codes.
10
15
  */
@@ -11,10 +11,13 @@ export const chainCodes = [0, 1, 10, 11, 20, 21, 30, 31, 40, 41];
11
11
  const chainCodeSet = new Set(chainCodes);
12
12
  const chainToMeta = new Map();
13
13
  const scriptTypeToChain = new Map();
14
- // Initialize from WASM (called once at load time)
15
- function assertChainCode(n) {
14
+ /**
15
+ * Assert that a number is a valid chain code.
16
+ * @throws Error if the number is not a valid chain code
17
+ */
18
+ export function assertChainCode(n) {
16
19
  if (!chainCodeSet.has(n)) {
17
- throw new Error(`Invalid chain code from WASM: ${n}`);
20
+ throw new Error(`Invalid chain code: ${n}`);
18
21
  }
19
22
  return n;
20
23
  }
@@ -3,8 +3,8 @@ export { RootWalletKeys, type WalletKeysArg, type IWalletKeys } from "./RootWall
3
3
  export { ReplayProtection, type ReplayProtectionArg } from "./ReplayProtection.js";
4
4
  export { outputScript, address } from "./address.js";
5
5
  export { Dimensions } from "./Dimensions.js";
6
- export { type OutputScriptType, type InputScriptType, type ScriptType } from "./scriptType.js";
7
- export { ChainCode, chainCodes, type Scope } from "./chains.js";
6
+ export { outputScriptTypes, inputScriptTypes, type OutputScriptType, type InputScriptType, type ScriptType, } from "./scriptType.js";
7
+ export { ChainCode, chainCodes, assertChainCode, type Scope } from "./chains.js";
8
8
  export { BitGoPsbt, type NetworkName, type ScriptId, type ParsedInput, type ParsedOutput, type ParsedTransaction, type SignPath, type CreateEmptyOptions, type AddInputOptions, type AddOutputOptions, type AddWalletInputOptions, type AddWalletOutputOptions, } from "./BitGoPsbt.js";
9
9
  export { ZcashBitGoPsbt, type ZcashNetworkName, type CreateEmptyZcashOptions, } from "./ZcashBitGoPsbt.js";
10
10
  import type { ScriptType } from "./scriptType.js";
@@ -34,3 +34,20 @@ import type { ScriptType } from "./scriptType.js";
34
34
  * ```
35
35
  */
36
36
  export declare function supportsScriptType(coin: CoinName, scriptType: ScriptType): boolean;
37
+ /**
38
+ * Create an OP_RETURN output script with optional data
39
+ *
40
+ * @param data - Optional data bytes to include in the OP_RETURN script
41
+ * @returns The OP_RETURN script as a Uint8Array
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * // Empty OP_RETURN
46
+ * const script = createOpReturnScript();
47
+ *
48
+ * // OP_RETURN with data
49
+ * const data = new Uint8Array([1, 2, 3, 4]);
50
+ * const script = createOpReturnScript(data);
51
+ * ```
52
+ */
53
+ export declare function createOpReturnScript(data?: Uint8Array): Uint8Array;
@@ -3,7 +3,8 @@ export { RootWalletKeys } from "./RootWalletKeys.js";
3
3
  export { ReplayProtection } from "./ReplayProtection.js";
4
4
  export { outputScript, address } from "./address.js";
5
5
  export { Dimensions } from "./Dimensions.js";
6
- export { ChainCode, chainCodes } from "./chains.js";
6
+ export { outputScriptTypes, inputScriptTypes, } from "./scriptType.js";
7
+ export { ChainCode, chainCodes, assertChainCode } from "./chains.js";
7
8
  // Bitcoin-like PSBT (for all non-Zcash networks)
8
9
  export { BitGoPsbt, } from "./BitGoPsbt.js";
9
10
  // Zcash-specific PSBT subclass
@@ -36,3 +37,22 @@ export { ZcashBitGoPsbt, } from "./ZcashBitGoPsbt.js";
36
37
  export function supportsScriptType(coin, scriptType) {
37
38
  return FixedScriptWalletNamespace.supports_script_type(coin, scriptType);
38
39
  }
40
+ /**
41
+ * Create an OP_RETURN output script with optional data
42
+ *
43
+ * @param data - Optional data bytes to include in the OP_RETURN script
44
+ * @returns The OP_RETURN script as a Uint8Array
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * // Empty OP_RETURN
49
+ * const script = createOpReturnScript();
50
+ *
51
+ * // OP_RETURN with data
52
+ * const data = new Uint8Array([1, 2, 3, 4]);
53
+ * const script = createOpReturnScript(data);
54
+ * ```
55
+ */
56
+ export function createOpReturnScript(data) {
57
+ return FixedScriptWalletNamespace.create_op_return_script(data);
58
+ }
@@ -1,16 +1,26 @@
1
1
  /**
2
- * Fixed-script wallet output script types (2-of-3 multisig)
2
+ * All output script types for fixed-script wallets (2-of-3 multisig)
3
3
  *
4
- * This type represents the abstract script type, independent of chain (external/internal).
4
+ * This represents the abstract script type, independent of chain (external/internal).
5
5
  * Use this for checking network support or when you need the script type without derivation info.
6
6
  */
7
- export type OutputScriptType = "p2sh" | "p2shP2wsh" | "p2wsh" | "p2tr" | "p2trLegacy" | "p2trMusig2";
7
+ export declare const outputScriptTypes: readonly ["p2sh", "p2shP2wsh", "p2wsh", "p2trLegacy", "p2trMusig2"];
8
8
  /**
9
- * Input script types for fixed-script wallets
9
+ * Output script type for fixed-script wallets
10
+ *
11
+ * Note: "p2tr" is an alias for "p2trLegacy" for backward compatibility.
12
+ */
13
+ export type OutputScriptType = (typeof outputScriptTypes)[number] | "p2tr";
14
+ /**
15
+ * All input script types for fixed-script wallets
10
16
  *
11
17
  * These are more specific than output types and include single-sig and taproot variants.
12
18
  */
13
- export type InputScriptType = "p2shP2pk" | "p2sh" | "p2shP2wsh" | "p2wsh" | "p2trLegacy" | "p2trMusig2ScriptPath" | "p2trMusig2KeyPath";
19
+ export declare const inputScriptTypes: readonly ["p2shP2pk", "p2sh", "p2shP2wsh", "p2wsh", "p2trLegacy", "p2trMusig2ScriptPath", "p2trMusig2KeyPath"];
20
+ /**
21
+ * Input script type for fixed-script wallets
22
+ */
23
+ export type InputScriptType = (typeof inputScriptTypes)[number];
14
24
  /**
15
25
  * Union of all script types that can be checked for network support
16
26
  */
@@ -1 +1,27 @@
1
- export {};
1
+ /**
2
+ * All output script types for fixed-script wallets (2-of-3 multisig)
3
+ *
4
+ * This represents the abstract script type, independent of chain (external/internal).
5
+ * Use this for checking network support or when you need the script type without derivation info.
6
+ */
7
+ export const outputScriptTypes = [
8
+ "p2sh",
9
+ "p2shP2wsh",
10
+ "p2wsh",
11
+ "p2trLegacy",
12
+ "p2trMusig2",
13
+ ];
14
+ /**
15
+ * All input script types for fixed-script wallets
16
+ *
17
+ * These are more specific than output types and include single-sig and taproot variants.
18
+ */
19
+ export const inputScriptTypes = [
20
+ "p2shP2pk",
21
+ "p2sh",
22
+ "p2shP2wsh",
23
+ "p2wsh",
24
+ "p2trLegacy",
25
+ "p2trMusig2ScriptPath",
26
+ "p2trMusig2KeyPath",
27
+ ];
@@ -0,0 +1,132 @@
1
+ import { BitGoPsbt } from "../fixedScriptWallet/BitGoPsbt.js";
2
+ import { RootWalletKeys } from "../fixedScriptWallet/RootWalletKeys.js";
3
+ import { BIP32 } from "../bip32.js";
4
+ import { inputScriptTypes, outputScriptTypes, type InputScriptType, type OutputScriptType, type ScriptId } from "../fixedScriptWallet/index.js";
5
+ import type { CoinName } from "../coinName.js";
6
+ import type { Triple } from "../triple.js";
7
+ export declare const signStages: readonly ["unsigned", "halfsigned", "fullsigned"];
8
+ export type SignStage = (typeof signStages)[number];
9
+ export declare const txFormats: readonly ["psbt", "psbt-lite"];
10
+ export type TxFormat = (typeof txFormats)[number];
11
+ /**
12
+ * Utility type to make union variants mutually exclusive.
13
+ * For each variant T in the union, adds `?: never` for all keys from other variants.
14
+ */
15
+ type Exclusive<T, U = T> = T extends unknown ? T & Partial<Record<Exclude<U extends unknown ? keyof U : never, keyof T>, never>> : never;
16
+ /** Base input fields */
17
+ type InputBase = {
18
+ value: bigint;
19
+ /** Wallet keys to use. Defaults to root wallet keys */
20
+ walletKeys?: RootWalletKeys;
21
+ };
22
+ /** Input variant types */
23
+ type InputVariant = {
24
+ scriptType: InputScriptType;
25
+ index?: number;
26
+ } | {
27
+ scriptId: ScriptId;
28
+ };
29
+ /**
30
+ * Input configuration for AcidTest PSBT
31
+ *
32
+ * Either specify `scriptType` (chain derived from type, index defaults to position)
33
+ * or specify `scriptId` (explicit chain + index).
34
+ */
35
+ export type Input = InputBase & Exclusive<InputVariant>;
36
+ /** Base output fields */
37
+ type OutputBase = {
38
+ value: bigint;
39
+ /** Wallet keys to use. Defaults to root wallet keys. null = external output (no bip32 derivation) */
40
+ walletKeys?: RootWalletKeys | null;
41
+ };
42
+ /** Output variant types */
43
+ type OutputVariant = {
44
+ scriptType: OutputScriptType;
45
+ index?: number;
46
+ } | {
47
+ scriptId: ScriptId;
48
+ } | {
49
+ opReturn: string;
50
+ } | {
51
+ address: string;
52
+ } | {
53
+ script: Uint8Array;
54
+ };
55
+ /**
56
+ * Output configuration for AcidTest PSBT
57
+ *
58
+ * Specify one of:
59
+ * - `scriptType` (chain derived from type, index defaults to position)
60
+ * - `scriptId` (explicit chain + index)
61
+ * - `opReturn` for OP_RETURN data output
62
+ * - `address` for address-based output
63
+ * - `script` for raw script output
64
+ */
65
+ export type Output = OutputBase & Exclusive<OutputVariant>;
66
+ type SuiteConfig = {
67
+ /**
68
+ * By default, we exclude p2trMusig2ScriptPath from the inputs since
69
+ * it uses user + backup keys (not typical 2-of-3 with user + bitgo).
70
+ * Set to true to include this input type.
71
+ */
72
+ includeP2trMusig2ScriptPath?: boolean;
73
+ };
74
+ export { inputScriptTypes, outputScriptTypes };
75
+ /**
76
+ * Creates a valid PSBT with as many features as possible (kitchen sink).
77
+ *
78
+ * - Inputs:
79
+ * - All wallet script types supported by the network
80
+ * - A p2shP2pk input (for replay protection)
81
+ * - Outputs:
82
+ * - All wallet script types supported by the network
83
+ * - A p2sh output with derivation info of a different wallet
84
+ * - A p2sh output with no derivation info (external output)
85
+ * - An OP_RETURN output
86
+ *
87
+ * Signature stages:
88
+ * - unsigned: No signatures
89
+ * - halfsigned: One signature per input (user key)
90
+ * - fullsigned: Two signatures per input (user + bitgo)
91
+ *
92
+ * Transaction formats:
93
+ * - psbt: Full PSBT with non_witness_utxo
94
+ * - psbt-lite: Only witness_utxo (no non_witness_utxo)
95
+ */
96
+ export declare class AcidTest {
97
+ readonly network: CoinName;
98
+ readonly signStage: SignStage;
99
+ readonly txFormat: TxFormat;
100
+ readonly rootWalletKeys: RootWalletKeys;
101
+ readonly otherWalletKeys: RootWalletKeys;
102
+ readonly inputs: Input[];
103
+ readonly outputs: Output[];
104
+ private readonly userXprv;
105
+ private readonly backupXprv;
106
+ private readonly bitgoXprv;
107
+ constructor(network: CoinName, signStage: SignStage, txFormat: TxFormat, rootWalletKeys: RootWalletKeys, otherWalletKeys: RootWalletKeys, inputs: Input[], outputs: Output[], xprvTriple: Triple<BIP32>);
108
+ /**
109
+ * Create an AcidTest with specific configuration
110
+ */
111
+ static withConfig(network: CoinName, signStage: SignStage, txFormat: TxFormat, suiteConfig?: SuiteConfig): AcidTest;
112
+ /**
113
+ * Get a human-readable name for this test configuration
114
+ */
115
+ get name(): string;
116
+ /**
117
+ * Get the BIP32 user key for replay protection (p2shP2pk)
118
+ */
119
+ getReplayProtectionKey(): BIP32;
120
+ /**
121
+ * Create the actual PSBT with all inputs and outputs
122
+ */
123
+ createPsbt(): BitGoPsbt;
124
+ /**
125
+ * Sign the PSBT according to the sign stage
126
+ */
127
+ private signPsbt;
128
+ /**
129
+ * Generate test suite for all networks, sign stages, and tx formats
130
+ */
131
+ static forAllNetworksSignStagesTxFormats(suiteConfig?: SuiteConfig): AcidTest[];
132
+ }