@bitgo/wasm-utxo 4.31.0 → 4.33.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.
@@ -3,6 +3,15 @@ import { BitGoPsbt, type CreateEmptyOptions, type HydrationUnspent } from "./Bit
3
3
  import { ZcashTransaction, type ITransaction } from "../transaction.js";
4
4
  /** Zcash network names */
5
5
  export type ZcashNetworkName = "zcash" | "zcashTest" | "zec" | "tzec";
6
+ /**
7
+ * Zcash v6 (Ironwood) version group id (0xd884b698). Its presence marks a PSBT as v6 — see
8
+ * `ZcashIronwoodBitGoPsbt`.
9
+ *
10
+ * Read from the wasm layer rather than hard-coded, so it cannot drift from
11
+ * `ZCASH_IRONWOOD_VERSION_GROUP_ID` in `src/zcash/transaction.rs`: a divergence would make the
12
+ * v4/v6 discrimination in {@link ZcashBitGoPsbt.fromBytes} silently classify v6 bytes as v4.
13
+ */
14
+ export declare const IRONWOOD_VERSION_GROUP_ID: number;
6
15
  /** Options for creating an empty Zcash PSBT (preferred method using block height) */
7
16
  export type CreateEmptyZcashOptions = CreateEmptyOptions & {
8
17
  /** Block height to determine consensus branch ID automatically */
@@ -98,6 +107,8 @@ export declare class ZcashBitGoPsbt extends BitGoPsbt {
98
107
  *
99
108
  * @param bytes - The PSBT bytes
100
109
  * @param network - Zcash network name ("zcash", "zcashTest", "zec", "tzec")
110
+ * @throws Error if the deserialized PSBT is a v6 (Ironwood) PSBT — use
111
+ * {@link ZcashIronwoodBitGoPsbt.fromBytes} instead
101
112
  * @returns A ZcashBitGoPsbt instance
102
113
  */
103
114
  static fromBytes(bytes: Uint8Array, network: ZcashNetworkName): ZcashBitGoPsbt;
@@ -1,10 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ZcashBitGoPsbt = void 0;
3
+ exports.ZcashBitGoPsbt = exports.IRONWOOD_VERSION_GROUP_ID = void 0;
4
4
  const wasm_utxo_js_1 = require("../wasm/wasm_utxo.js");
5
5
  const RootWalletKeys_js_1 = require("./RootWalletKeys.js");
6
6
  const BitGoPsbt_js_1 = require("./BitGoPsbt.js");
7
7
  const transaction_js_1 = require("../transaction.js");
8
+ /**
9
+ * Zcash v6 (Ironwood) version group id (0xd884b698). Its presence marks a PSBT as v6 — see
10
+ * `ZcashIronwoodBitGoPsbt`.
11
+ *
12
+ * Read from the wasm layer rather than hard-coded, so it cannot drift from
13
+ * `ZCASH_IRONWOOD_VERSION_GROUP_ID` in `src/zcash/transaction.rs`: a divergence would make the
14
+ * v4/v6 discrimination in {@link ZcashBitGoPsbt.fromBytes} silently classify v6 bytes as v4.
15
+ */
16
+ exports.IRONWOOD_VERSION_GROUP_ID = (0, wasm_utxo_js_1.zcash_ironwood_version_group_id)();
8
17
  /**
9
18
  * Zcash-specific PSBT implementation
10
19
  *
@@ -90,11 +99,17 @@ class ZcashBitGoPsbt extends BitGoPsbt_js_1.BitGoPsbt {
90
99
  *
91
100
  * @param bytes - The PSBT bytes
92
101
  * @param network - Zcash network name ("zcash", "zcashTest", "zec", "tzec")
102
+ * @throws Error if the deserialized PSBT is a v6 (Ironwood) PSBT — use
103
+ * {@link ZcashIronwoodBitGoPsbt.fromBytes} instead
93
104
  * @returns A ZcashBitGoPsbt instance
94
105
  */
95
106
  static fromBytes(bytes, network) {
96
107
  const wasm = wasm_utxo_js_1.BitGoPsbt.from_bytes(bytes, network);
97
- return new ZcashBitGoPsbt(wasm);
108
+ const psbt = new ZcashBitGoPsbt(wasm);
109
+ if (psbt.versionGroupId === exports.IRONWOOD_VERSION_GROUP_ID) {
110
+ throw new Error("this is a v6 (Ironwood) PSBT: use ZcashIronwoodBitGoPsbt.fromBytes instead");
111
+ }
112
+ return psbt;
98
113
  }
99
114
  /**
100
115
  * Reconstruct a Zcash PSBT from a network-format transaction (unsigned, half-signed, or fully-signed).
@@ -0,0 +1,233 @@
1
+ import { type BIP32Arg } from "../bip32.js";
2
+ import { type ECPairArg } from "../ecpair.js";
3
+ import { type WalletKeysArg } from "./RootWalletKeys.js";
4
+ import { ZcashBitGoPsbt, type ZcashNetworkName } from "./ZcashBitGoPsbt.js";
5
+ /**
6
+ * Options for creating an empty Zcash v6 (Ironwood) shielding PSBT.
7
+ *
8
+ * Deliberately narrower than `CreateEmptyZcashOptions`: `version` and `versionGroupId` are fixed by
9
+ * the v6 format, so accepting them would only let a caller ask for something that is then ignored.
10
+ */
11
+ export type CreateEmptyIronwoodOptions = {
12
+ /** Block height to determine the consensus branch ID automatically (at/after NU6.3 activation) */
13
+ blockHeight: number;
14
+ /** Lock time (default: 0) */
15
+ lockTime?: number;
16
+ /** Zcash transaction expiry height */
17
+ expiryHeight?: number;
18
+ };
19
+ /**
20
+ * Options for creating an empty Zcash v6 (Ironwood) shielding PSBT with an explicit consensus
21
+ * branch ID.
22
+ *
23
+ * Like {@link CreateEmptyIronwoodOptions}, this omits `version` and `versionGroupId` — both are
24
+ * fixed by the v6 format. The consensus branch ID is *not* fixed: it tracks the active network
25
+ * upgrade, so it stays a caller-supplied parameter exactly as it is for v4.
26
+ */
27
+ export type CreateEmptyIronwoodWithConsensusBranchIdOptions = {
28
+ /** Zcash consensus branch ID (e.g. the NU6.3 branch ID) */
29
+ consensusBranchId: number;
30
+ /** Lock time (default: 0) */
31
+ lockTime?: number;
32
+ /** Zcash transaction expiry height */
33
+ expiryHeight?: number;
34
+ };
35
+ /**
36
+ * A fresh ZIP-302 "no memo" memo field: the `0xf6` marker byte followed by 511 zero bytes. The
37
+ * default for {@link ZcashIronwoodBitGoPsbt.addShieldedOutput}'s `memo` option.
38
+ *
39
+ * Not the same as an all-zeros memo, which decodes as a *text* memo holding the empty string and is
40
+ * rendered as such by wallets. Exported so callers can pass it explicitly, and so the distinction is
41
+ * visible rather than buried in a default.
42
+ *
43
+ * A function rather than a shared constant: a module-level `Uint8Array` is mutable, so one caller
44
+ * writing into it would silently change the default memo for every later output.
45
+ */
46
+ export declare function zip302NoMemo(): Uint8Array;
47
+ /**
48
+ * A Zcash **v6 (Ironwood / NU6.3)** shielding PSBT.
49
+ *
50
+ * Distinct from the generic `ZcashBitGoPsbt` (v4/Sapling-shaped transactions): a v6 PSBT carries
51
+ * its shielded side as an orchard PCZT in the proprietary map rather than Sapling fields, and its
52
+ * lifecycle mirrors the microservice build → sign → combine flow rather than the v4 ZIP-243
53
+ * signing path.
54
+ *
55
+ * Method names carry no `ironwood` prefix — the class name already says it. They follow the base
56
+ * `BitGoPsbt` vocabulary (`createEmpty`, `fromBytes`, `addOutput`-style adders, `getId`) so the v6
57
+ * surface reads the same as the v4 one; the wasm bindings keep their `ironwood_v6_*` names because
58
+ * they live on the single flat `BitGoPsbt` struct, where the prefix is what disambiguates them.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const psbt = ZcashIronwoodBitGoPsbt.createEmpty("zcash", walletKeys, { blockHeight });
63
+ * psbt.addWalletInput(...);
64
+ * psbt.addWalletOutput(...);
65
+ * psbt.addShieldedOutput(recipient, amount, { anchor });
66
+ * const sighash = psbt.transparentSighash(0);
67
+ * // ... sign sighash externally, then:
68
+ * psbt.addTransparentSignature(0, pubkey, sig);
69
+ * const tx = psbt.combineProof(proof);
70
+ * ```
71
+ */
72
+ export declare class ZcashIronwoodBitGoPsbt extends ZcashBitGoPsbt {
73
+ /**
74
+ * Create an empty Zcash **v6 (Ironwood)** shielding PSBT, with the consensus branch ID
75
+ * determined from block height.
76
+ *
77
+ * Add transparent inputs/outputs with the usual `addWalletInput` / `addWalletOutput`, the
78
+ * shielded output with {@link addShieldedOutput}, then sign the transparent inputs over
79
+ * {@link transparentSighash} and finish with {@link combineProof}.
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 - Options including blockHeight (at/after NU6.3 activation)
84
+ */
85
+ static createEmpty(network: ZcashNetworkName, walletKeys: WalletKeysArg, options: CreateEmptyIronwoodOptions): ZcashIronwoodBitGoPsbt;
86
+ /**
87
+ * Create an empty Zcash **v6 (Ironwood)** shielding PSBT with an explicit consensus branch ID.
88
+ *
89
+ * **Advanced use only.** Prefer {@link createEmpty}, which derives the branch ID from a block
90
+ * height and rejects heights before NU6.3 activation. Reach for this only when you already know
91
+ * the branch ID — regtest, a future upgrade, or replaying a known-good value.
92
+ *
93
+ * Only the *version group ID* is fixed by the v6 format; the consensus branch ID tracks the active
94
+ * network upgrade and remains caller-supplied, exactly as for v4.
95
+ *
96
+ * @param network - Zcash network name ("zcash", "zcashTest", "zec", "tzec")
97
+ * @param walletKeys - The wallet's root keys (sets global xpubs in the PSBT)
98
+ * @param options - Options including the required consensusBranchId
99
+ */
100
+ static createEmptyWithConsensusBranchId(network: ZcashNetworkName, walletKeys: WalletKeysArg, options: CreateEmptyIronwoodWithConsensusBranchIdOptions): ZcashIronwoodBitGoPsbt;
101
+ /**
102
+ * Not applicable to v6, and not implementable: a broadcast v6 transaction carries the shielded
103
+ * side as a proof plus a binding signature, while every v6 operation here needs the PCZT — which
104
+ * holds witness data (`rseed`, `rcv`, `alpha`, the note plaintext) that is deliberately *not*
105
+ * recoverable from the transaction. Decoding the transparent skeleton alone would yield a PSBT
106
+ * that `getId`, `transparentSighash`, `combineProof`, and even `serialize`/{@link fromBytes} all
107
+ * reject. Inherited only because JS statics are inherited.
108
+ */
109
+ static fromNetworkFormat(): never;
110
+ /**
111
+ * Not applicable to v6: the legacy half-signed format is a v4-era p2ms encoding with no way to
112
+ * carry the PCZT, and no v6 transaction has ever been produced in it. Inherited only because JS
113
+ * statics are inherited.
114
+ */
115
+ static fromHalfSignedLegacyTransaction(): never;
116
+ /**
117
+ * Deserialize a v6 (Ironwood) Zcash PSBT from bytes.
118
+ *
119
+ * @param bytes - The PSBT bytes
120
+ * @param network - Zcash network name ("zcash", "zcashTest", "zec", "tzec")
121
+ * @throws Error if the deserialized PSBT is not a v6 (Ironwood) PSBT
122
+ * @returns A ZcashIronwoodBitGoPsbt instance
123
+ */
124
+ static fromBytes(bytes: Uint8Array, network: ZcashNetworkName): ZcashIronwoodBitGoPsbt;
125
+ /**
126
+ * Add the shielded output (Constructor role). Stores the orchard PCZT in the PSBT.
127
+ *
128
+ * Named for the shielded/transparent split rather than the note type, leaving room for a
129
+ * transparent-output variant alongside the inherited `addOutput` / `addWalletOutput`.
130
+ *
131
+ * @param recipient - 43-byte raw Orchard/Ironwood address
132
+ * @param amount - note value in zatoshi
133
+ * @param options.anchor - 32-byte Ironwood note-commitment-tree root
134
+ * @param options.memo - optional 512-byte memo (defaults to the ZIP-302 "no memo" encoding)
135
+ * @param options.ovk - optional 32-byte outgoing viewing key (omit for a keyless build)
136
+ */
137
+ addShieldedOutput(recipient: Uint8Array, amount: bigint, options: {
138
+ anchor: Uint8Array;
139
+ memo?: Uint8Array;
140
+ ovk?: Uint8Array;
141
+ }): void;
142
+ /**
143
+ * Client-managed `ovk`: re-encrypt the shielded output's `out_ciphertext` under **this wallet's**
144
+ * `ovk`, derived as the ECDH agreement of `rootWalletKeys.bitgoKey()` and `userKey`. Both are root
145
+ * keys, so the `ovk` does not depend on which inputs the transaction spends, and the server can
146
+ * re-derive the identical value from its own private key plus the user's public key in order to
147
+ * validate `out_ciphertext` before countersigning. The server never sees `userKey` or the `ovk`.
148
+ *
149
+ * `userKey` must be the wallet's user root key — passing the backup or BitGo key throws, since an
150
+ * `ovk` derived from those is one neither the user nor the server can reproduce, and the resulting
151
+ * transaction would broadcast fine while leaving the shielded output permanently unrecoverable.
152
+ *
153
+ * Normally you do not call this directly: {@link sign} performs it on the first signing round.
154
+ *
155
+ * Must be called **before** signing: `out_ciphertext` is committed by the ZIP-244 sighash, so
156
+ * calling this after any transparent signature has been added (via
157
+ * {@link addTransparentSignature}) throws rather than silently invalidating that signature.
158
+ *
159
+ * @param actionIndex - index of the Ironwood action whose output to re-encrypt (always `0`: only
160
+ * one shielded output per transaction is supported, see {@link addShieldedOutput})
161
+ * @param userKey - the wallet's user root key (an xpriv)
162
+ * @param rootWalletKeys - the wallet's root keys, supplying the BitGo cosigner pubkey
163
+ */
164
+ setShieldedOutCiphertext(actionIndex: number, userKey: BIP32Arg, rootWalletKeys: WalletKeysArg): void;
165
+ /**
166
+ * The canonical (display-order) ZIP-244 v6 txid as a lowercase hex string, matching
167
+ * `ITransaction.getId()`. Defined once the transparent inputs/outputs and the shielded output are
168
+ * in place; unchanged by signing or proving.
169
+ */
170
+ getId(): string;
171
+ /**
172
+ * The ZIP-244 per-input transparent sighash (32 bytes) the key controlling transparent input
173
+ * `index` must sign.
174
+ */
175
+ transparentSighash(index: number): Uint8Array;
176
+ /**
177
+ * Ingest a transparent-input signature returned by the client/HSM, after verifying it against
178
+ * {@link transparentSighash} for that input.
179
+ *
180
+ * @param index - transparent input index
181
+ * @param pubkey - the signing public key
182
+ * @param sig - DER ECDSA signature with the trailing SIGHASH_ALL byte (as in a scriptSig)
183
+ */
184
+ addTransparentSignature(index: number, pubkey: Uint8Array, sig: Uint8Array): void;
185
+ /**
186
+ * Sign every transparent input `key` resolves a private key for, over the ZIP-244 transparent
187
+ * sighash. The v6 (Ironwood) counterpart to the inherited `sign(key)` — that base implementation
188
+ * rejects v6 PSBTs outright, since it only knows the ZIP-243 digest.
189
+ *
190
+ * If no transparent signature has been added to this PSBT yet, this is the first signing round and
191
+ * `key` must be the wallet's user root key: it is used with `rootWalletKeys.bitgoKey()` to derive
192
+ * this wallet's `ovk` and finalize `out_ciphertext` — the client-managed-`ovk` flow — before any
193
+ * sighash is computed. Once a signature exists, that step is a no-op, so a caller passes
194
+ * `rootWalletKeys` on every signing round unconditionally: `psbt.sign(userXpriv, rootWalletKeys)`
195
+ * and later `psbt.sign(bitgoXpriv, rootWalletKeys)` — only the first call actually uses it.
196
+ * `rootWalletKeys` is mandatory precisely so that step can never be silently skipped by omission.
197
+ *
198
+ * **The user must sign first**, and this is enforced: a first round opened by any other key throws
199
+ * rather than deriving an `ovk` that neither the user nor the server can reproduce. One consequence
200
+ * is that a backup-key recovery cannot open the first signing round of a shielding transaction.
201
+ *
202
+ * `rootWalletKeys` is typed optional only so this override type-checks against the inherited
203
+ * `sign(key)` signature — omitting it throws at runtime rather than silently signing without the
204
+ * `ovk` step.
205
+ *
206
+ * @param key - an xpriv (BIP32Arg); raw privkeys (ECPairArg) are not meaningful here, since
207
+ * `out_ciphertext` derivation needs the key's `bip32_derivation` path
208
+ * @param rootWalletKeys - the wallet's root keys (required). Any {@link WalletKeysArg} form, same
209
+ * as {@link setShieldedOutCiphertext} and {@link createEmpty} — an xpub triple, a utxo-lib
210
+ * `RootWalletKeys`, or this package's own — so it is never sensitive to which copy of the class
211
+ * a caller's `RootWalletKeys` came from.
212
+ * @returns the transparent input indices that were signed
213
+ */
214
+ sign(key: BIP32Arg | ECPairArg, rootWalletKeys?: WalletKeysArg): number[];
215
+ /**
216
+ * @deprecated Not supported for v6 (Ironwood): always throws. Inherited only because the base
217
+ * class's single-input overload must be preserved for the override to type-check; use
218
+ * {@link sign} (all matching inputs) instead.
219
+ */
220
+ sign(inputIndex: number, key: BIP32Arg | ECPairArg): void;
221
+ /**
222
+ * Transaction Extractor role: given the external prover's `proof` bytes, finalize the
223
+ * transparent inputs, apply the shielded binding signature, and return the broadcast-ready v6
224
+ * transaction bytes. Requires every transparent input to be signed via
225
+ * {@link addTransparentSignature}.
226
+ *
227
+ * Terminal: the wasm binding drops the stored PCZT on success, so any later v6 call on this PSBT
228
+ * throws — including after a `serialize`/{@link fromBytes} round-trip, since the PCZT is gone
229
+ * from the bytes too. Build a fresh PSBT instead. On failure nothing is dropped, so a call that
230
+ * errors (bad proof, unsigned input) leaves the PSBT retryable.
231
+ */
232
+ combineProof(proof: Uint8Array): Uint8Array;
233
+ }
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZcashIronwoodBitGoPsbt = void 0;
4
+ exports.zip302NoMemo = zip302NoMemo;
5
+ const wasm_utxo_js_1 = require("../wasm/wasm_utxo.js");
6
+ const bip32_js_1 = require("../bip32.js");
7
+ const RootWalletKeys_js_1 = require("./RootWalletKeys.js");
8
+ const ZcashBitGoPsbt_js_1 = require("./ZcashBitGoPsbt.js");
9
+ /**
10
+ * A fresh ZIP-302 "no memo" memo field: the `0xf6` marker byte followed by 511 zero bytes. The
11
+ * default for {@link ZcashIronwoodBitGoPsbt.addShieldedOutput}'s `memo` option.
12
+ *
13
+ * Not the same as an all-zeros memo, which decodes as a *text* memo holding the empty string and is
14
+ * rendered as such by wallets. Exported so callers can pass it explicitly, and so the distinction is
15
+ * visible rather than buried in a default.
16
+ *
17
+ * A function rather than a shared constant: a module-level `Uint8Array` is mutable, so one caller
18
+ * writing into it would silently change the default memo for every later output.
19
+ */
20
+ function zip302NoMemo() {
21
+ const memo = new Uint8Array(512);
22
+ memo[0] = 0xf6;
23
+ return memo;
24
+ }
25
+ /**
26
+ * A Zcash **v6 (Ironwood / NU6.3)** shielding PSBT.
27
+ *
28
+ * Distinct from the generic `ZcashBitGoPsbt` (v4/Sapling-shaped transactions): a v6 PSBT carries
29
+ * its shielded side as an orchard PCZT in the proprietary map rather than Sapling fields, and its
30
+ * lifecycle mirrors the microservice build → sign → combine flow rather than the v4 ZIP-243
31
+ * signing path.
32
+ *
33
+ * Method names carry no `ironwood` prefix — the class name already says it. They follow the base
34
+ * `BitGoPsbt` vocabulary (`createEmpty`, `fromBytes`, `addOutput`-style adders, `getId`) so the v6
35
+ * surface reads the same as the v4 one; the wasm bindings keep their `ironwood_v6_*` names because
36
+ * they live on the single flat `BitGoPsbt` struct, where the prefix is what disambiguates them.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const psbt = ZcashIronwoodBitGoPsbt.createEmpty("zcash", walletKeys, { blockHeight });
41
+ * psbt.addWalletInput(...);
42
+ * psbt.addWalletOutput(...);
43
+ * psbt.addShieldedOutput(recipient, amount, { anchor });
44
+ * const sighash = psbt.transparentSighash(0);
45
+ * // ... sign sighash externally, then:
46
+ * psbt.addTransparentSignature(0, pubkey, sig);
47
+ * const tx = psbt.combineProof(proof);
48
+ * ```
49
+ */
50
+ class ZcashIronwoodBitGoPsbt extends ZcashBitGoPsbt_js_1.ZcashBitGoPsbt {
51
+ /**
52
+ * Create an empty Zcash **v6 (Ironwood)** shielding PSBT, with the consensus branch ID
53
+ * determined from block height.
54
+ *
55
+ * Add transparent inputs/outputs with the usual `addWalletInput` / `addWalletOutput`, the
56
+ * shielded output with {@link addShieldedOutput}, then sign the transparent inputs over
57
+ * {@link transparentSighash} and finish with {@link combineProof}.
58
+ *
59
+ * @param network - Zcash network name ("zcash", "zcashTest", "zec", "tzec")
60
+ * @param walletKeys - The wallet's root keys (sets global xpubs in the PSBT)
61
+ * @param options - Options including blockHeight (at/after NU6.3 activation)
62
+ */
63
+ static createEmpty(network, walletKeys, options) {
64
+ const keys = RootWalletKeys_js_1.RootWalletKeys.from(walletKeys);
65
+ const wasm = wasm_utxo_js_1.BitGoPsbt.create_empty_zcash_v6_at_height(network, keys.wasm, options.blockHeight, options.lockTime, options.expiryHeight);
66
+ return new ZcashIronwoodBitGoPsbt(wasm);
67
+ }
68
+ /**
69
+ * Create an empty Zcash **v6 (Ironwood)** shielding PSBT with an explicit consensus branch ID.
70
+ *
71
+ * **Advanced use only.** Prefer {@link createEmpty}, which derives the branch ID from a block
72
+ * height and rejects heights before NU6.3 activation. Reach for this only when you already know
73
+ * the branch ID — regtest, a future upgrade, or replaying a known-good value.
74
+ *
75
+ * Only the *version group ID* is fixed by the v6 format; the consensus branch ID tracks the active
76
+ * network upgrade and remains caller-supplied, exactly as for v4.
77
+ *
78
+ * @param network - Zcash network name ("zcash", "zcashTest", "zec", "tzec")
79
+ * @param walletKeys - The wallet's root keys (sets global xpubs in the PSBT)
80
+ * @param options - Options including the required consensusBranchId
81
+ */
82
+ static createEmptyWithConsensusBranchId(network, walletKeys, options) {
83
+ const keys = RootWalletKeys_js_1.RootWalletKeys.from(walletKeys);
84
+ const wasm = wasm_utxo_js_1.BitGoPsbt.create_empty_zcash_v6(network, keys.wasm, options.consensusBranchId, options.lockTime, options.expiryHeight);
85
+ return new ZcashIronwoodBitGoPsbt(wasm);
86
+ }
87
+ /**
88
+ * Not applicable to v6, and not implementable: a broadcast v6 transaction carries the shielded
89
+ * side as a proof plus a binding signature, while every v6 operation here needs the PCZT — which
90
+ * holds witness data (`rseed`, `rcv`, `alpha`, the note plaintext) that is deliberately *not*
91
+ * recoverable from the transaction. Decoding the transparent skeleton alone would yield a PSBT
92
+ * that `getId`, `transparentSighash`, `combineProof`, and even `serialize`/{@link fromBytes} all
93
+ * reject. Inherited only because JS statics are inherited.
94
+ */
95
+ static fromNetworkFormat() {
96
+ throw new Error("not supported for v6 (Ironwood): the PCZT witness data cannot be recovered from a broadcast " +
97
+ "transaction; rebuild the PSBT with createEmpty");
98
+ }
99
+ /**
100
+ * Not applicable to v6: the legacy half-signed format is a v4-era p2ms encoding with no way to
101
+ * carry the PCZT, and no v6 transaction has ever been produced in it. Inherited only because JS
102
+ * statics are inherited.
103
+ */
104
+ static fromHalfSignedLegacyTransaction() {
105
+ throw new Error("not supported for v6 (Ironwood): the legacy half-signed format is v4-only; " +
106
+ "rebuild the PSBT with createEmpty");
107
+ }
108
+ /**
109
+ * Deserialize a v6 (Ironwood) Zcash PSBT from bytes.
110
+ *
111
+ * @param bytes - The PSBT bytes
112
+ * @param network - Zcash network name ("zcash", "zcashTest", "zec", "tzec")
113
+ * @throws Error if the deserialized PSBT is not a v6 (Ironwood) PSBT
114
+ * @returns A ZcashIronwoodBitGoPsbt instance
115
+ */
116
+ static fromBytes(bytes, network) {
117
+ const wasm = wasm_utxo_js_1.BitGoPsbt.from_bytes(bytes, network);
118
+ const psbt = new ZcashIronwoodBitGoPsbt(wasm);
119
+ if (psbt.versionGroupId !== ZcashBitGoPsbt_js_1.IRONWOOD_VERSION_GROUP_ID) {
120
+ throw new Error("not a v6 (Ironwood) PSBT: use ZcashBitGoPsbt.fromBytes for v4/Sapling-shaped PSBTs");
121
+ }
122
+ return psbt;
123
+ }
124
+ /**
125
+ * Add the shielded output (Constructor role). Stores the orchard PCZT in the PSBT.
126
+ *
127
+ * Named for the shielded/transparent split rather than the note type, leaving room for a
128
+ * transparent-output variant alongside the inherited `addOutput` / `addWalletOutput`.
129
+ *
130
+ * @param recipient - 43-byte raw Orchard/Ironwood address
131
+ * @param amount - note value in zatoshi
132
+ * @param options.anchor - 32-byte Ironwood note-commitment-tree root
133
+ * @param options.memo - optional 512-byte memo (defaults to the ZIP-302 "no memo" encoding)
134
+ * @param options.ovk - optional 32-byte outgoing viewing key (omit for a keyless build)
135
+ */
136
+ addShieldedOutput(recipient, amount, options) {
137
+ const memo = options.memo ?? zip302NoMemo();
138
+ this.wasm.add_ironwood_output(recipient, amount, options.ovk, options.anchor, memo);
139
+ }
140
+ /**
141
+ * Client-managed `ovk`: re-encrypt the shielded output's `out_ciphertext` under **this wallet's**
142
+ * `ovk`, derived as the ECDH agreement of `rootWalletKeys.bitgoKey()` and `userKey`. Both are root
143
+ * keys, so the `ovk` does not depend on which inputs the transaction spends, and the server can
144
+ * re-derive the identical value from its own private key plus the user's public key in order to
145
+ * validate `out_ciphertext` before countersigning. The server never sees `userKey` or the `ovk`.
146
+ *
147
+ * `userKey` must be the wallet's user root key — passing the backup or BitGo key throws, since an
148
+ * `ovk` derived from those is one neither the user nor the server can reproduce, and the resulting
149
+ * transaction would broadcast fine while leaving the shielded output permanently unrecoverable.
150
+ *
151
+ * Normally you do not call this directly: {@link sign} performs it on the first signing round.
152
+ *
153
+ * Must be called **before** signing: `out_ciphertext` is committed by the ZIP-244 sighash, so
154
+ * calling this after any transparent signature has been added (via
155
+ * {@link addTransparentSignature}) throws rather than silently invalidating that signature.
156
+ *
157
+ * @param actionIndex - index of the Ironwood action whose output to re-encrypt (always `0`: only
158
+ * one shielded output per transaction is supported, see {@link addShieldedOutput})
159
+ * @param userKey - the wallet's user root key (an xpriv)
160
+ * @param rootWalletKeys - the wallet's root keys, supplying the BitGo cosigner pubkey
161
+ */
162
+ setShieldedOutCiphertext(actionIndex, userKey, rootWalletKeys) {
163
+ this.wasm.set_ironwood_out_ciphertext(actionIndex, bip32_js_1.BIP32.from(userKey).wasm, RootWalletKeys_js_1.RootWalletKeys.from(rootWalletKeys).wasm);
164
+ }
165
+ /**
166
+ * The canonical (display-order) ZIP-244 v6 txid as a lowercase hex string, matching
167
+ * `ITransaction.getId()`. Defined once the transparent inputs/outputs and the shielded output are
168
+ * in place; unchanged by signing or proving.
169
+ */
170
+ getId() {
171
+ return this.wasm.ironwood_v6_txid();
172
+ }
173
+ /**
174
+ * The ZIP-244 per-input transparent sighash (32 bytes) the key controlling transparent input
175
+ * `index` must sign.
176
+ */
177
+ transparentSighash(index) {
178
+ return this.wasm.ironwood_v6_transparent_sighash(index);
179
+ }
180
+ /**
181
+ * Ingest a transparent-input signature returned by the client/HSM, after verifying it against
182
+ * {@link transparentSighash} for that input.
183
+ *
184
+ * @param index - transparent input index
185
+ * @param pubkey - the signing public key
186
+ * @param sig - DER ECDSA signature with the trailing SIGHASH_ALL byte (as in a scriptSig)
187
+ */
188
+ addTransparentSignature(index, pubkey, sig) {
189
+ this.wasm.add_ironwood_v6_signature(index, pubkey, sig);
190
+ }
191
+ // The second parameter is `WalletKeysArg` in the public (first) overload above — the only form
192
+ // callers see. It widens here solely to stay assignable to the deprecated `(inputIndex, key)`
193
+ // overload, whose own second parameter is a key; narrowing it to `WalletKeysArg` is TS2394.
194
+ sign(keyOrIndex, keyOrRootWalletKeys) {
195
+ if (typeof keyOrIndex === "number") {
196
+ throw new Error("not supported for v6 (Ironwood): single-input sign(inputIndex, key) has no ZIP-244 " +
197
+ "equivalent; use sign(key) to sign all matching inputs");
198
+ }
199
+ if (!(0, bip32_js_1.isBIP32Arg)(keyOrIndex)) {
200
+ throw new Error("not supported for v6 (Ironwood): a raw privkey (ECPairArg) has no bip32_derivation path " +
201
+ "to resolve out_ciphertext's ovk from; pass an xpriv");
202
+ }
203
+ if (keyOrRootWalletKeys === undefined) {
204
+ throw new Error("rootWalletKeys is required for v6 (Ironwood) signing: sign(key, rootWalletKeys) — pass it " +
205
+ "on every signing round, even Bitgo's, so the client-managed-ovk step is never silently " +
206
+ "skipped");
207
+ }
208
+ const wasmKey = bip32_js_1.BIP32.from(keyOrIndex).wasm;
209
+ const keys = RootWalletKeys_js_1.RootWalletKeys.from(keyOrRootWalletKeys);
210
+ return Array.from(this.wasm.sign_ironwood_v6(wasmKey, keys.wasm), Number);
211
+ }
212
+ /**
213
+ * Transaction Extractor role: given the external prover's `proof` bytes, finalize the
214
+ * transparent inputs, apply the shielded binding signature, and return the broadcast-ready v6
215
+ * transaction bytes. Requires every transparent input to be signed via
216
+ * {@link addTransparentSignature}.
217
+ *
218
+ * Terminal: the wasm binding drops the stored PCZT on success, so any later v6 call on this PSBT
219
+ * throws — including after a `serialize`/{@link fromBytes} round-trip, since the PCZT is gone
220
+ * from the bytes too. Build a fresh PSBT instead. On failure nothing is dropped, so a call that
221
+ * errors (bad proof, unsigned input) leaves the PSBT retryable.
222
+ */
223
+ combineProof(proof) {
224
+ return this.wasm.combine_ironwood_proof(proof);
225
+ }
226
+ }
227
+ exports.ZcashIronwoodBitGoPsbt = ZcashIronwoodBitGoPsbt;
@@ -8,7 +8,8 @@ export { ChainCode, chainCodes, assertChainCode, type Scope } from "./chains.js"
8
8
  export { requiresPrevTxForP2sh } from "./prevTx.js";
9
9
  export { BitGoPsbt, getWalletKeysFromPsbt, type NetworkName, type ScriptId, type ParsedInput, type ParsedOutput, type ParsedTransaction, type SignPath, type CreateEmptyOptions, type AddInputOptions, type AddOutputOptions, type AddWalletInputOptions, type AddWalletOutputOptions, type ParseTransactionOptions, type ParseOutputsOptions, type HydrationUnspent, } from "./BitGoPsbt.js";
10
10
  export { BitGoKeySubtype, type PsbtKvKey } from "./BitGoKeySubtype.js";
11
- export { ZcashBitGoPsbt, type ZcashNetworkName, type CreateEmptyZcashOptions, } from "./ZcashBitGoPsbt.js";
11
+ export { ZcashBitGoPsbt, type ZcashNetworkName, type CreateEmptyZcashOptions, IRONWOOD_VERSION_GROUP_ID, } from "./ZcashBitGoPsbt.js";
12
+ export { ZcashIronwoodBitGoPsbt, zip302NoMemo, type CreateEmptyIronwoodOptions, type CreateEmptyIronwoodWithConsensusBranchIdOptions, } from "./ZcashIronwoodBitGoPsbt.js";
12
13
  export { ZcashUnifiedAddress } from "./ZcashUnifiedAddress.js";
13
14
  export { ZcashV6Transaction } from "./ZcashV6Transaction.js";
14
15
  import type { ScriptType } from "./scriptType.js";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ZcashV6Transaction = exports.ZcashUnifiedAddress = exports.ZcashBitGoPsbt = exports.BitGoKeySubtype = exports.getWalletKeysFromPsbt = exports.BitGoPsbt = exports.requiresPrevTxForP2sh = exports.assertChainCode = exports.chainCodes = exports.ChainCode = exports.inputScriptTypes = exports.outputScriptTypes = exports.Dimensions = exports.address = exports.outputScript = exports.ReplayProtection = exports.RootWalletKeys = void 0;
3
+ exports.ZcashV6Transaction = exports.ZcashUnifiedAddress = exports.zip302NoMemo = exports.ZcashIronwoodBitGoPsbt = exports.IRONWOOD_VERSION_GROUP_ID = exports.ZcashBitGoPsbt = exports.BitGoKeySubtype = exports.getWalletKeysFromPsbt = exports.BitGoPsbt = exports.requiresPrevTxForP2sh = exports.assertChainCode = exports.chainCodes = exports.ChainCode = exports.inputScriptTypes = exports.outputScriptTypes = exports.Dimensions = exports.address = exports.outputScript = exports.ReplayProtection = exports.RootWalletKeys = void 0;
4
4
  exports.supportsScriptType = supportsScriptType;
5
5
  exports.createOpReturnScript = createOpReturnScript;
6
6
  exports.p2shP2pkOutputScript = p2shP2pkOutputScript;
@@ -33,6 +33,11 @@ Object.defineProperty(exports, "BitGoKeySubtype", { enumerable: true, get: funct
33
33
  // Zcash-specific PSBT subclass
34
34
  var ZcashBitGoPsbt_js_1 = require("./ZcashBitGoPsbt.js");
35
35
  Object.defineProperty(exports, "ZcashBitGoPsbt", { enumerable: true, get: function () { return ZcashBitGoPsbt_js_1.ZcashBitGoPsbt; } });
36
+ Object.defineProperty(exports, "IRONWOOD_VERSION_GROUP_ID", { enumerable: true, get: function () { return ZcashBitGoPsbt_js_1.IRONWOOD_VERSION_GROUP_ID; } });
37
+ // Zcash v6 (Ironwood / NU6.3) shielding PSBT
38
+ var ZcashIronwoodBitGoPsbt_js_1 = require("./ZcashIronwoodBitGoPsbt.js");
39
+ Object.defineProperty(exports, "ZcashIronwoodBitGoPsbt", { enumerable: true, get: function () { return ZcashIronwoodBitGoPsbt_js_1.ZcashIronwoodBitGoPsbt; } });
40
+ Object.defineProperty(exports, "zip302NoMemo", { enumerable: true, get: function () { return ZcashIronwoodBitGoPsbt_js_1.zip302NoMemo; } });
36
41
  // Zcash ZIP-316 Unified Address
37
42
  var ZcashUnifiedAddress_js_1 = require("./ZcashUnifiedAddress.js");
38
43
  Object.defineProperty(exports, "ZcashUnifiedAddress", { enumerable: true, get: function () { return ZcashUnifiedAddress_js_1.ZcashUnifiedAddress; } });