@bitgo/wasm-utxo 1.14.1 → 1.16.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.
@@ -0,0 +1,113 @@
1
+ import { type WalletKeysArg } from "./RootWalletKeys.js";
2
+ import { BitGoPsbt, type CreateEmptyOptions } from "./BitGoPsbt.js";
3
+ /** Zcash network names */
4
+ export type ZcashNetworkName = "zcash" | "zcashTest" | "zec" | "tzec";
5
+ /** Options for creating an empty Zcash PSBT (preferred method using block height) */
6
+ export type CreateEmptyZcashOptions = CreateEmptyOptions & {
7
+ /** Block height to determine consensus branch ID automatically */
8
+ blockHeight: number;
9
+ /** Zcash version group ID (defaults to Sapling: 0x892F2085) */
10
+ versionGroupId?: number;
11
+ /** Zcash transaction expiry height */
12
+ expiryHeight?: number;
13
+ };
14
+ /** Options for creating an empty Zcash PSBT with explicit consensus branch ID (advanced use) */
15
+ export type CreateEmptyZcashWithConsensusBranchIdOptions = CreateEmptyOptions & {
16
+ /** Zcash consensus branch ID (required, e.g., 0xC2D6D0B4 for NU5, 0x76B809BB for Sapling) */
17
+ consensusBranchId: number;
18
+ /** Zcash version group ID (defaults to Sapling: 0x892F2085) */
19
+ versionGroupId?: number;
20
+ /** Zcash transaction expiry height */
21
+ expiryHeight?: number;
22
+ };
23
+ /**
24
+ * Zcash-specific PSBT implementation
25
+ *
26
+ * This class extends BitGoPsbt with Zcash-specific functionality:
27
+ * - Required consensus branch ID for sighash computation
28
+ * - Version group ID for Zcash transaction format
29
+ * - Expiry height for transaction validity
30
+ *
31
+ * All Zcash-specific getters return non-optional types since they're
32
+ * guaranteed to be present for Zcash PSBTs.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * // Create a new Zcash PSBT
37
+ * const psbt = ZcashBitGoPsbt.createEmpty("zcash", walletKeys, {
38
+ * consensusBranchId: 0x76B809BB, // Sapling
39
+ * });
40
+ *
41
+ * // Deserialize from bytes
42
+ * const psbt = ZcashBitGoPsbt.fromBytes(bytes, "zcash");
43
+ * ```
44
+ */
45
+ export declare class ZcashBitGoPsbt extends BitGoPsbt {
46
+ /**
47
+ * Create an empty Zcash PSBT with consensus branch ID determined from block height
48
+ *
49
+ * **This is the preferred method for creating Zcash PSBTs.** It automatically determines
50
+ * the correct consensus branch ID based on the network and block height using Zcash
51
+ * network upgrade activation heights, eliminating the need to manually look up branch IDs.
52
+ *
53
+ * @param network - Zcash network name ("zcash", "zcashTest", "zec", "tzec")
54
+ * @param walletKeys - The wallet's root keys (sets global xpubs in the PSBT)
55
+ * @param options - Options including blockHeight to determine consensus rules
56
+ * @returns A new ZcashBitGoPsbt instance
57
+ * @throws Error if block height is before Overwinter activation
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * // Create PSBT for a specific block height (recommended)
62
+ * const psbt = ZcashBitGoPsbt.createEmpty("zcash", walletKeys, {
63
+ * blockHeight: 1687104, // Automatically uses Nu5 branch ID
64
+ * });
65
+ *
66
+ * // Create PSBT for current block height
67
+ * const currentHeight = await getBlockHeight();
68
+ * const psbt = ZcashBitGoPsbt.createEmpty("zcash", walletKeys, {
69
+ * blockHeight: currentHeight,
70
+ * });
71
+ * ```
72
+ */
73
+ static createEmpty(network: ZcashNetworkName, walletKeys: WalletKeysArg, options: CreateEmptyZcashOptions): ZcashBitGoPsbt;
74
+ /**
75
+ * Create an empty Zcash PSBT with explicit consensus branch ID
76
+ *
77
+ * **Advanced use only.** This method requires manually specifying the consensus branch ID.
78
+ * In most cases, you should use `createEmpty()` instead, which automatically determines
79
+ * the correct branch ID from the block height.
80
+ *
81
+ * @param network - Zcash network name ("zcash", "zcashTest", "zec", "tzec")
82
+ * @param walletKeys - The wallet's root keys (sets global xpubs in the PSBT)
83
+ * @param options - Zcash-specific options including required consensusBranchId
84
+ * @returns A new ZcashBitGoPsbt instance
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * // Only use this if you need explicit control over the branch ID
89
+ * const psbt = ZcashBitGoPsbt.createEmptyWithConsensusBranchId("zcash", walletKeys, {
90
+ * consensusBranchId: 0xC2D6D0B4, // Nu5 branch ID
91
+ * });
92
+ * ```
93
+ */
94
+ static createEmptyWithConsensusBranchId(network: ZcashNetworkName, walletKeys: WalletKeysArg, options: CreateEmptyZcashWithConsensusBranchIdOptions): ZcashBitGoPsbt;
95
+ /**
96
+ * Deserialize a Zcash PSBT from bytes
97
+ *
98
+ * @param bytes - The PSBT bytes
99
+ * @param network - Zcash network name ("zcash", "zcashTest", "zec", "tzec")
100
+ * @returns A ZcashBitGoPsbt instance
101
+ */
102
+ static fromBytes(bytes: Uint8Array, network: ZcashNetworkName): ZcashBitGoPsbt;
103
+ /**
104
+ * Get the Zcash version group ID
105
+ * @returns The version group ID (e.g., 0x892F2085 for Sapling)
106
+ */
107
+ get versionGroupId(): number;
108
+ /**
109
+ * Get the Zcash expiry height
110
+ * @returns The expiry height (0 if not set)
111
+ */
112
+ get expiryHeight(): number;
113
+ }
@@ -0,0 +1,110 @@
1
+ import { BitGoPsbt as WasmBitGoPsbt } from "../wasm/wasm_utxo.js";
2
+ import { RootWalletKeys } from "./RootWalletKeys.js";
3
+ import { BitGoPsbt } from "./BitGoPsbt.js";
4
+ /**
5
+ * Zcash-specific PSBT implementation
6
+ *
7
+ * This class extends BitGoPsbt with Zcash-specific functionality:
8
+ * - Required consensus branch ID for sighash computation
9
+ * - Version group ID for Zcash transaction format
10
+ * - Expiry height for transaction validity
11
+ *
12
+ * All Zcash-specific getters return non-optional types since they're
13
+ * guaranteed to be present for Zcash PSBTs.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * // Create a new Zcash PSBT
18
+ * const psbt = ZcashBitGoPsbt.createEmpty("zcash", walletKeys, {
19
+ * consensusBranchId: 0x76B809BB, // Sapling
20
+ * });
21
+ *
22
+ * // Deserialize from bytes
23
+ * const psbt = ZcashBitGoPsbt.fromBytes(bytes, "zcash");
24
+ * ```
25
+ */
26
+ export class ZcashBitGoPsbt extends BitGoPsbt {
27
+ /**
28
+ * Create an empty Zcash PSBT with consensus branch ID determined from block height
29
+ *
30
+ * **This is the preferred method for creating Zcash PSBTs.** It automatically determines
31
+ * the correct consensus branch ID based on the network and block height using Zcash
32
+ * network upgrade activation heights, eliminating the need to manually look up branch IDs.
33
+ *
34
+ * @param network - Zcash network name ("zcash", "zcashTest", "zec", "tzec")
35
+ * @param walletKeys - The wallet's root keys (sets global xpubs in the PSBT)
36
+ * @param options - Options including blockHeight to determine consensus rules
37
+ * @returns A new ZcashBitGoPsbt instance
38
+ * @throws Error if block height is before Overwinter activation
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * // Create PSBT for a specific block height (recommended)
43
+ * const psbt = ZcashBitGoPsbt.createEmpty("zcash", walletKeys, {
44
+ * blockHeight: 1687104, // Automatically uses Nu5 branch ID
45
+ * });
46
+ *
47
+ * // Create PSBT for current block height
48
+ * const currentHeight = await getBlockHeight();
49
+ * const psbt = ZcashBitGoPsbt.createEmpty("zcash", walletKeys, {
50
+ * blockHeight: currentHeight,
51
+ * });
52
+ * ```
53
+ */
54
+ static createEmpty(network, walletKeys, options) {
55
+ const keys = RootWalletKeys.from(walletKeys);
56
+ const wasm = WasmBitGoPsbt.create_empty_zcash_at_height(network, keys.wasm, options.blockHeight, options.version, options.lockTime, options.versionGroupId, options.expiryHeight);
57
+ return new ZcashBitGoPsbt(wasm);
58
+ }
59
+ /**
60
+ * Create an empty Zcash PSBT with explicit consensus branch ID
61
+ *
62
+ * **Advanced use only.** This method requires manually specifying the consensus branch ID.
63
+ * In most cases, you should use `createEmpty()` instead, which automatically determines
64
+ * the correct branch ID from the block height.
65
+ *
66
+ * @param network - Zcash network name ("zcash", "zcashTest", "zec", "tzec")
67
+ * @param walletKeys - The wallet's root keys (sets global xpubs in the PSBT)
68
+ * @param options - Zcash-specific options including required consensusBranchId
69
+ * @returns A new ZcashBitGoPsbt instance
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * // Only use this if you need explicit control over the branch ID
74
+ * const psbt = ZcashBitGoPsbt.createEmptyWithConsensusBranchId("zcash", walletKeys, {
75
+ * consensusBranchId: 0xC2D6D0B4, // Nu5 branch ID
76
+ * });
77
+ * ```
78
+ */
79
+ static createEmptyWithConsensusBranchId(network, walletKeys, options) {
80
+ const keys = RootWalletKeys.from(walletKeys);
81
+ const wasm = WasmBitGoPsbt.create_empty_zcash(network, keys.wasm, options.consensusBranchId, options.version, options.lockTime, options.versionGroupId, options.expiryHeight);
82
+ return new ZcashBitGoPsbt(wasm);
83
+ }
84
+ /**
85
+ * Deserialize a Zcash PSBT from bytes
86
+ *
87
+ * @param bytes - The PSBT bytes
88
+ * @param network - Zcash network name ("zcash", "zcashTest", "zec", "tzec")
89
+ * @returns A ZcashBitGoPsbt instance
90
+ */
91
+ static fromBytes(bytes, network) {
92
+ const wasm = WasmBitGoPsbt.from_bytes(bytes, network);
93
+ return new ZcashBitGoPsbt(wasm);
94
+ }
95
+ // --- Zcash-specific getters ---
96
+ /**
97
+ * Get the Zcash version group ID
98
+ * @returns The version group ID (e.g., 0x892F2085 for Sapling)
99
+ */
100
+ get versionGroupId() {
101
+ return this.wasm.version_group_id();
102
+ }
103
+ /**
104
+ * Get the Zcash expiry height
105
+ * @returns The expiry height (0 if not set)
106
+ */
107
+ get expiryHeight() {
108
+ return this.wasm.expiry_height();
109
+ }
110
+ }
@@ -1,4 +1,5 @@
1
1
  export { RootWalletKeys, type WalletKeysArg, type IWalletKeys } from "./RootWalletKeys.js";
2
2
  export { ReplayProtection, type ReplayProtectionArg } from "./ReplayProtection.js";
3
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";
4
+ export { BitGoPsbt, type NetworkName, type ScriptId, type InputScriptType, type ParsedInput, type ParsedOutput, type ParsedTransaction, type SignPath, type CreateEmptyOptions, type AddInputOptions, type AddOutputOptions, type AddWalletInputOptions, type AddWalletOutputOptions, } from "./BitGoPsbt.js";
5
+ export { ZcashBitGoPsbt, type ZcashNetworkName, type CreateEmptyZcashOptions, } from "./ZcashBitGoPsbt.js";
@@ -1,4 +1,7 @@
1
1
  export { RootWalletKeys } from "./RootWalletKeys.js";
2
2
  export { ReplayProtection } from "./ReplayProtection.js";
3
3
  export { outputScript, address } from "./address.js";
4
+ // Bitcoin-like PSBT (for all non-Zcash networks)
4
5
  export { BitGoPsbt, } from "./BitGoPsbt.js";
6
+ // Zcash-specific PSBT subclass
7
+ export { ZcashBitGoPsbt, } from "./ZcashBitGoPsbt.js";
@@ -13,10 +13,35 @@ export class BitGoPsbt {
13
13
  private constructor();
14
14
  free(): void;
15
15
  [Symbol.dispose](): void;
16
+ /**
17
+ * Add an output to the PSBT
18
+ *
19
+ * # Arguments
20
+ * * `script` - The output script (scriptPubKey)
21
+ * * `value` - The value in satoshis
22
+ *
23
+ * # Returns
24
+ * The index of the newly added output
25
+ */
26
+ add_output(script: Uint8Array, value: bigint): number;
16
27
  /**
17
28
  * Deserialize a PSBT from bytes with network-specific logic
18
29
  */
19
30
  static from_bytes(bytes: Uint8Array, network: string): BitGoPsbt;
31
+ /**
32
+ * Create an empty PSBT for the given network with wallet keys
33
+ *
34
+ * # Arguments
35
+ * * `network` - Network name (utxolib or coin name)
36
+ * * `wallet_keys` - The wallet's root keys (used to set global xpubs)
37
+ * * `version` - Optional transaction version (default: 2)
38
+ * * `lock_time` - Optional lock time (default: 0)
39
+ */
40
+ static create_empty(network: string, wallet_keys: WasmRootWalletKeys, version?: number | null, lock_time?: number | null): BitGoPsbt;
41
+ /**
42
+ * Get the Zcash expiry height (returns None for non-Zcash PSBTs)
43
+ */
44
+ expiry_height(): number | undefined;
20
45
  /**
21
46
  * Get the unsigned transaction ID
22
47
  */
@@ -41,6 +66,48 @@ export class BitGoPsbt {
41
66
  * - `Err(WasmUtxoError)` if signing fails
42
67
  */
43
68
  sign_with_xpriv(input_index: number, xpriv: WasmBIP32): void;
69
+ /**
70
+ * Add a wallet input with full PSBT metadata
71
+ *
72
+ * This is a higher-level method that adds an input and populates all required
73
+ * PSBT fields (scripts, derivation info, etc.) based on the wallet's chain type.
74
+ *
75
+ * # Arguments
76
+ * * `txid` - The transaction ID (hex string)
77
+ * * `vout` - The output index being spent
78
+ * * `value` - The value in satoshis
79
+ * * `chain` - The chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2)
80
+ * * `index` - The derivation index
81
+ * * `wallet_keys` - The root wallet keys
82
+ * * `signer` - The key that will sign ("user", "backup", or "bitgo") - required for p2tr/p2trMusig2
83
+ * * `cosigner` - The key that will co-sign - required for p2tr/p2trMusig2
84
+ * * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
85
+ * * `prev_tx` - Optional full previous transaction bytes (for non-segwit)
86
+ *
87
+ * # Returns
88
+ * The index of the newly added input
89
+ */
90
+ add_wallet_input(txid: string, vout: number, value: bigint, wallet_keys: WasmRootWalletKeys, chain: number, index: number, signer?: string | null, cosigner?: string | null, sequence?: number | null, prev_tx?: Uint8Array | null): number;
91
+ /**
92
+ * Get the Zcash version group ID (returns None for non-Zcash PSBTs)
93
+ */
94
+ version_group_id(): number | undefined;
95
+ /**
96
+ * Add a wallet output with full PSBT metadata
97
+ *
98
+ * This creates a verifiable wallet output (typically for change) with all required
99
+ * PSBT fields (scripts, derivation info) based on the wallet's chain type.
100
+ *
101
+ * # Arguments
102
+ * * `chain` - The chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2)
103
+ * * `index` - The derivation index
104
+ * * `value` - The value in satoshis
105
+ * * `wallet_keys` - The root wallet keys
106
+ *
107
+ * # Returns
108
+ * The index of the newly added output
109
+ */
110
+ add_wallet_output(chain: number, index: number, value: bigint, wallet_keys: WasmRootWalletKeys): number;
44
111
  /**
45
112
  * Sign a single input with a raw private key
46
113
  *
@@ -61,6 +128,22 @@ export class BitGoPsbt {
61
128
  * - `Err(WasmUtxoError)` if signing fails
62
129
  */
63
130
  sign_with_privkey(input_index: number, ecpair: WasmECPair): void;
131
+ /**
132
+ * Create an empty Zcash PSBT with the required consensus branch ID
133
+ *
134
+ * This method is specifically for Zcash networks which require additional
135
+ * parameters for sighash computation.
136
+ *
137
+ * # Arguments
138
+ * * `network` - Network name (must be "zcash" or "zcashTest")
139
+ * * `wallet_keys` - The wallet's root keys (used to set global xpubs)
140
+ * * `consensus_branch_id` - Zcash consensus branch ID (e.g., 0xC2D6D0B4 for NU5)
141
+ * * `version` - Optional transaction version (default: 4 for Zcash Sapling+)
142
+ * * `lock_time` - Optional lock time (default: 0)
143
+ * * `version_group_id` - Optional version group ID (defaults to Sapling: 0x892F2085)
144
+ * * `expiry_height` - Optional expiry height
145
+ */
146
+ static create_empty_zcash(network: string, wallet_keys: WasmRootWalletKeys, consensus_branch_id: number, version?: number | null, lock_time?: number | null, version_group_id?: number | null, expiry_height?: number | null): BitGoPsbt;
64
147
  /**
65
148
  * Extract the final transaction from a finalized PSBT
66
149
  *
@@ -181,6 +264,42 @@ export class BitGoPsbt {
181
264
  * - `Err(WasmUtxoError)` if the input index is out of bounds, derivation fails, or verification fails
182
265
  */
183
266
  verify_signature_with_xpub(input_index: number, xpub: WasmBIP32): boolean;
267
+ /**
268
+ * Add a replay protection input to the PSBT
269
+ *
270
+ * Replay protection inputs are P2SH-P2PK inputs used on forked networks to prevent
271
+ * transaction replay attacks. They use a simple pubkey script without wallet derivation.
272
+ *
273
+ * # Arguments
274
+ * * `ecpair` - The ECPair containing the public key for the replay protection input
275
+ * * `txid` - The transaction ID (hex string) of the output being spent
276
+ * * `vout` - The output index being spent
277
+ * * `value` - The value in satoshis
278
+ * * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
279
+ *
280
+ * # Returns
281
+ * The index of the newly added input
282
+ */
283
+ add_replay_protection_input(ecpair: WasmECPair, txid: string, vout: number, value: bigint, sequence?: number | null): number;
284
+ /**
285
+ * Create an empty Zcash PSBT with consensus branch ID determined from block height
286
+ *
287
+ * This method automatically determines the correct consensus branch ID based on
288
+ * the network and block height using the network upgrade activation heights.
289
+ *
290
+ * # Arguments
291
+ * * `network` - Network name (must be "zcash" or "zcashTest")
292
+ * * `wallet_keys` - The wallet's root keys (used to set global xpubs)
293
+ * * `block_height` - Block height to determine consensus rules
294
+ * * `version` - Optional transaction version (default: 4 for Zcash Sapling+)
295
+ * * `lock_time` - Optional lock time (default: 0)
296
+ * * `version_group_id` - Optional version group ID (defaults to Sapling: 0x892F2085)
297
+ * * `expiry_height` - Optional expiry height
298
+ *
299
+ * # Errors
300
+ * Returns error if block height is before Overwinter activation
301
+ */
302
+ static create_empty_zcash_at_height(network: string, wallet_keys: WasmRootWalletKeys, block_height: number, version?: number | null, lock_time?: number | null, version_group_id?: number | null, expiry_height?: number | null): BitGoPsbt;
184
303
  /**
185
304
  * Parse outputs with wallet keys to identify which outputs belong to a wallet
186
305
  *
@@ -213,6 +332,28 @@ export class BitGoPsbt {
213
332
  * Get the network of the PSBT
214
333
  */
215
334
  network(): string;
335
+ /**
336
+ * Get the transaction version
337
+ */
338
+ version(): number;
339
+ /**
340
+ * Add an input to the PSBT
341
+ *
342
+ * # Arguments
343
+ * * `txid` - The transaction ID (hex string) of the output being spent
344
+ * * `vout` - The output index being spent
345
+ * * `value` - The value in satoshis of the output being spent
346
+ * * `script` - The output script (scriptPubKey) of the output being spent
347
+ * * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
348
+ *
349
+ * # Returns
350
+ * The index of the newly added input
351
+ */
352
+ add_input(txid: string, vout: number, value: bigint, script: Uint8Array, sequence?: number | null, prev_tx?: Uint8Array | null): number;
353
+ /**
354
+ * Get the transaction lock time
355
+ */
356
+ lock_time(): number;
216
357
  /**
217
358
  * Serialize the PSBT to bytes
218
359
  *