@umbra-privacy/sdk 2.1.1 → 4.0.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 (45) hide show
  1. package/dist/{chunk-GP26R377.js → chunk-AUNYA6JP.js} +2 -2
  2. package/dist/chunk-AUNYA6JP.js.map +1 -0
  3. package/dist/{chunk-BL6WXLPV.cjs → chunk-KCHHJKQN.cjs} +2 -2
  4. package/dist/chunk-KCHHJKQN.cjs.map +1 -0
  5. package/dist/{chunk-KMRROOME.js → chunk-YA66JLHI.js} +9 -4
  6. package/dist/chunk-YA66JLHI.js.map +1 -0
  7. package/dist/{chunk-3LS5P32X.cjs → chunk-YFUGKMNS.cjs} +9 -4
  8. package/dist/chunk-YFUGKMNS.cjs.map +1 -0
  9. package/dist/{client-Cb53GYes.d.cts → client-Baxe29tj.d.cts} +128 -51
  10. package/dist/{client-CJ5S6Qln.d.ts → client-Cqv_5hHQ.d.ts} +128 -51
  11. package/dist/constants/index.cjs +1 -1
  12. package/dist/constants/index.js +1 -1
  13. package/dist/crypto/index.cjs +142 -142
  14. package/dist/crypto/index.d.cts +1 -1
  15. package/dist/crypto/index.d.ts +1 -1
  16. package/dist/crypto/index.js +1 -1
  17. package/dist/errors/index.cjs +28 -28
  18. package/dist/errors/index.d.cts +1 -1
  19. package/dist/errors/index.d.ts +1 -1
  20. package/dist/errors/index.js +1 -1
  21. package/dist/{errors-DAIrstEL.d.cts → errors-BqAlwXfh.d.cts} +3 -5
  22. package/dist/{errors-DPNMfyh0.d.ts → errors-Crx4Jf9K.d.ts} +3 -5
  23. package/dist/{index-B5wNTNZr.d.cts → index-BRLHQNe9.d.cts} +27 -12
  24. package/dist/{index-Cd76ZBHA.d.ts → index-gpTrCX61.d.ts} +27 -12
  25. package/dist/index.cjs +817 -1072
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.cts +25 -276
  28. package/dist/index.d.ts +25 -276
  29. package/dist/index.js +322 -573
  30. package/dist/index.js.map +1 -1
  31. package/dist/indexer-NHZDFABY.js +311 -0
  32. package/dist/indexer-NHZDFABY.js.map +1 -0
  33. package/dist/indexer-XOUBVRNU.cjs +316 -0
  34. package/dist/indexer-XOUBVRNU.cjs.map +1 -0
  35. package/dist/interfaces/index.d.cts +2 -2
  36. package/dist/interfaces/index.d.ts +2 -2
  37. package/dist/solana/index.d.cts +2 -2
  38. package/dist/solana/index.d.ts +2 -2
  39. package/dist/{transaction-forwarder-Dme9whAc.d.ts → transaction-forwarder-Cv3OlsaZ.d.ts} +1 -1
  40. package/dist/{transaction-forwarder-0GZRKXIr.d.cts → transaction-forwarder-DH07CEkG.d.cts} +1 -1
  41. package/package.json +3 -3
  42. package/dist/chunk-3LS5P32X.cjs.map +0 -1
  43. package/dist/chunk-BL6WXLPV.cjs.map +0 -1
  44. package/dist/chunk-GP26R377.js.map +0 -1
  45. package/dist/chunk-KMRROOME.js.map +0 -1
@@ -965,6 +965,23 @@ interface ComputationPrunedResult {
965
965
  /** The current slot at the time pruning was detected. */
966
966
  readonly currentSlot: bigint;
967
967
  }
968
+ /**
969
+ * Result when the computation monitoring timed out.
970
+ *
971
+ * This occurs when the wall-clock safety timeout fires (RPC unresponsive)
972
+ * or the monitoring was cancelled via an external `AbortSignal`. Unlike
973
+ * `"pruned"`, this does not necessarily mean the computation failed — it may
974
+ * still finalize later. However, the monitor has stopped watching.
975
+ *
976
+ * @since 3.0.0
977
+ * @public
978
+ */
979
+ interface ComputationTimedOutResult {
980
+ /** The monitor gave up before observing finalization or pruning. */
981
+ readonly status: "timed-out";
982
+ /** Wall-clock milliseconds from monitor start to timeout. */
983
+ readonly elapsedMs: number;
984
+ }
968
985
  /**
969
986
  * Discriminated union of all computation monitoring outcomes.
970
987
  *
@@ -972,19 +989,25 @@ interface ComputationPrunedResult {
972
989
  * Callers must check `result.status` to determine the outcome:
973
990
  *
974
991
  * ```typescript
975
- * const result = await monitor.awaitComputation(address);
976
- * if (result.status === "finalized") {
977
- * // MPC succeeded — continue with the encrypted result
978
- * } else {
979
- * // Pruned — the computation will never finalize
980
- * console.log(`Pruned: ${result.currentSlot - result.queuedSlot} slots elapsed`);
992
+ * const result = await prepared.awaitComputation();
993
+ * switch (result.status) {
994
+ * case "finalized":
995
+ * // MPC succeeded — continue with the encrypted result
996
+ * break;
997
+ * case "pruned":
998
+ * // Pruned — the computation will never finalize
999
+ * console.log(`Pruned: ${result.currentSlot - result.queuedSlot} slots elapsed`);
1000
+ * break;
1001
+ * case "timed-out":
1002
+ * // Monitor gave up — computation may still finalize later
1003
+ * break;
981
1004
  * }
982
1005
  * ```
983
1006
  *
984
1007
  * @since 2.0.0
985
1008
  * @public
986
1009
  */
987
- type ComputationMonitorResult = ComputationFinalizedResult | ComputationPrunedResult;
1010
+ type ComputationMonitorResult = ComputationFinalizedResult | ComputationPrunedResult | ComputationTimedOutResult;
988
1011
  /**
989
1012
  * Extended finalized result with a guaranteed callback signature.
990
1013
  * Returned when `retrieveCallbackSignature` is `true` and the computation finalized.
@@ -999,12 +1022,12 @@ interface ComputationFinalizedResultWithSignature extends Omit<ComputationFinali
999
1022
  /**
1000
1023
  * Result type when `retrieveCallbackSignature` is `true`.
1001
1024
  * If finalized, the callback signature is guaranteed present.
1002
- * If pruned, no signature is available.
1025
+ * If pruned or timed out, no signature is available.
1003
1026
  *
1004
1027
  * @since 2.0.0
1005
1028
  * @public
1006
1029
  */
1007
- type ComputationMonitorResultWithSignature = ComputationFinalizedResultWithSignature | ComputationPrunedResult;
1030
+ type ComputationMonitorResultWithSignature = ComputationFinalizedResultWithSignature | ComputationPrunedResult | ComputationTimedOutResult;
1008
1031
  /**
1009
1032
  * Progress event types fired via the `onProgress` callback.
1010
1033
  *
@@ -1101,33 +1124,70 @@ interface PollingComputationMonitorOptions extends ComputationMonitorOptions {
1101
1124
  readonly pollingIntervalMs?: number;
1102
1125
  }
1103
1126
  /**
1104
- * Monitors an Arcium `ComputationAccount` for finalization or pruning.
1127
+ * A prepared computation monitor with an active subscription.
1105
1128
  *
1106
- * @since 2.0.0
1129
+ * Created by {@link ComputationMonitor.prepareMonitor}. The subscription is
1130
+ * established during preparation so that no account change notifications are
1131
+ * missed between the queue transaction and the start of monitoring.
1132
+ *
1133
+ * @remarks
1134
+ * Callers **must** call {@link cleanup} when the monitor is no longer needed,
1135
+ * even if {@link awaitComputation} was never called (e.g. if the queue
1136
+ * transaction fails). {@link cleanup} is idempotent.
1137
+ *
1138
+ * @since 3.0.0
1139
+ * @public
1140
+ */
1141
+ interface PreparedComputationMonitor {
1142
+ /**
1143
+ * Waits for the computation to finalize, prune, or time out.
1144
+ *
1145
+ * The first account-change notification (from the `queue_computation`
1146
+ * transaction itself) is consumed silently — only the MPC callback
1147
+ * notification triggers a finalized result.
1148
+ *
1149
+ * @returns A promise resolving to a finalized, pruned, or timed-out result.
1150
+ *
1151
+ * @throws {ComputationMonitorError} With stage `"subscription"` if the
1152
+ * underlying transport (WebSocket) encounters an unrecoverable failure.
1153
+ * @throws {ComputationMonitorError} With stage `"signature-retrieval"` if
1154
+ * callback signature lookup fails after finalization.
1155
+ */
1156
+ awaitComputation(): Promise<ComputationMonitorResult | ComputationMonitorResultWithSignature>;
1157
+ /**
1158
+ * Tears down the underlying subscription and timers.
1159
+ *
1160
+ * Safe to call multiple times. Called automatically at the end of
1161
+ * {@link awaitComputation}, but should also be called if
1162
+ * `awaitComputation` is never invoked (e.g. when the queue transaction
1163
+ * fails before monitoring begins).
1164
+ */
1165
+ cleanup(): void;
1166
+ }
1167
+ /**
1168
+ * Factory for preparing computation monitors.
1169
+ *
1170
+ * The two-phase design (prepare → await) ensures the subscription is active
1171
+ * **before** the `queue_computation` transaction is sent, eliminating the race
1172
+ * condition where a fast MPC callback could land between transaction confirmation
1173
+ * and subscription establishment.
1174
+ *
1175
+ * @since 3.0.0
1107
1176
  * @public
1108
1177
  */
1109
1178
  interface ComputationMonitor {
1110
1179
  /**
1111
- * Monitors a ComputationAccount until it finalizes or is pruned.
1180
+ * Establishes a subscription for the given computation account and returns
1181
+ * a {@link PreparedComputationMonitor} ready to await finalization.
1112
1182
  *
1113
1183
  * @param computationAddress - The on-chain address of the ComputationAccount PDA.
1114
- * @param options - Monitor options.
1115
- * @returns A promise resolving to a finalized or pruned result.
1116
- *
1117
- * @throws {ComputationMonitorError} With stage `"timeout"` if the safety wall-clock
1118
- * timeout fires (indicates RPC issues, not normal pruning).
1119
- * @throws {ComputationMonitorError} With stage `"subscription"` if WebSocket fails.
1120
- * @throws {ComputationMonitorError} With stage `"signature-retrieval"` if callback
1121
- * signature lookup fails after finalization.
1184
+ * @param options - Monitor options (slot window, timeout, progress, etc.).
1185
+ * @returns A prepared monitor whose subscription is already active.
1186
+ *
1187
+ * @throws {ComputationMonitorError} With stage `"subscription"` if the
1188
+ * initial subscription setup fails.
1122
1189
  */
1123
- awaitComputation: {
1124
- (computationAddress: Address, options?: ComputationMonitorOptions & {
1125
- retrieveCallbackSignature?: false;
1126
- }): Promise<ComputationMonitorResult>;
1127
- (computationAddress: Address, options: ComputationMonitorOptions & {
1128
- retrieveCallbackSignature: true;
1129
- }): Promise<ComputationMonitorResultWithSignature>;
1130
- };
1190
+ prepareMonitor(computationAddress: Address, options?: ComputationMonitorOptions): Promise<PreparedComputationMonitor>;
1131
1191
  }
1132
1192
  /**
1133
1193
  * Configuration for the WebSocket-based computation monitor.
@@ -1178,22 +1238,22 @@ interface PollingBasedComputationMonitorDeps {
1178
1238
  * subscriptions for real-time detection of computation finalization or pruning.
1179
1239
  *
1180
1240
  * @remarks
1181
- * **Detection strategy:** Subscribes to `accountNotifications` for the
1182
- * computation account. On each notification, decodes the account and checks
1183
- * the `status` field. Periodically fetches the current slot to detect pruning
1184
- * when the slot window is exceeded.
1241
+ * **Two-phase design:** {@link ComputationMonitor.prepareMonitor | prepareMonitor}
1242
+ * establishes the WebSocket subscription immediately so it is active before the
1243
+ * `queue_computation` transaction is sent. This eliminates the race condition
1244
+ * where a fast MPC callback could land between transaction confirmation and
1245
+ * subscription establishment.
1185
1246
  *
1186
- * **Initial state check:** Before subscribing, performs an HTTP fetch to handle
1187
- * the case where the computation already finalized before the monitor started.
1247
+ * **Detection strategy:** Subscribes to `accountNotifications` for the
1248
+ * computation account. The first notification (from the `queue_computation`
1249
+ * transaction itself) is consumed silently to capture the queued slot. Subsequent
1250
+ * notifications are checked for `Finalized` status. Periodic slot checks detect
1251
+ * pruning when the slot window is exceeded.
1188
1252
  *
1189
1253
  * @param config - HTTP RPC URL and WebSocket URL.
1190
1254
  * @param deps - Optional dependency overrides for testing.
1191
1255
  * @returns A {@link ComputationMonitor} instance.
1192
1256
  *
1193
- * @throws {ComputationMonitorError} Stage `"timeout"` if safety timeout fires.
1194
- * @throws {ComputationMonitorError} Stage `"subscription"` if WebSocket fails.
1195
- * @throws {ComputationMonitorError} Stage `"signature-retrieval"` if lookup fails.
1196
- *
1197
1257
  * @example
1198
1258
  * ```typescript
1199
1259
  * const monitor = getWebsocketComputationMonitor({
@@ -1201,16 +1261,29 @@ interface PollingBasedComputationMonitorDeps {
1201
1261
  * rpcSubscriptionsUrl: "wss://api.mainnet-beta.solana.com",
1202
1262
  * });
1203
1263
  *
1204
- * const result = await monitor.awaitComputation(computationAddress);
1205
- * if (result.status === "finalized") {
1206
- * console.log(`Done in ${result.elapsedMs}ms`);
1207
- * } else {
1208
- * console.log(`Pruned after ${result.currentSlot - result.queuedSlot} slots`);
1264
+ * // Phase 1: establish subscription
1265
+ * const prepared = await monitor.prepareMonitor(computationAddress);
1266
+ *
1267
+ * // Phase 2: send queue_computation transaction
1268
+ * await forwarder.forwardSequentially([signedTx]);
1269
+ *
1270
+ * // Phase 3: await result (first WS notification from queue tx is ignored)
1271
+ * const result = await prepared.awaitComputation();
1272
+ * switch (result.status) {
1273
+ * case "finalized":
1274
+ * console.log(`Done in ${result.elapsedMs}ms`);
1275
+ * break;
1276
+ * case "pruned":
1277
+ * console.log(`Pruned after ${result.currentSlot - result.queuedSlot} slots`);
1278
+ * break;
1279
+ * case "timed-out":
1280
+ * console.log(`Timed out after ${result.elapsedMs}ms`);
1281
+ * break;
1209
1282
  * }
1210
1283
  * ```
1211
1284
  *
1212
1285
  * @see {@link getPollingComputationMonitor} for the polling alternative
1213
- * @since 2.0.0
1286
+ * @since 3.0.0
1214
1287
  * @public
1215
1288
  */
1216
1289
  declare function getWebsocketComputationMonitor(config: WebsocketBasedComputationMonitorConfig, deps?: WebsocketBasedComputationMonitorDeps): ComputationMonitor;
@@ -1221,7 +1294,8 @@ declare function getWebsocketComputationMonitor(config: WebsocketBasedComputatio
1221
1294
  * @remarks
1222
1295
  * Each poll iteration fetches the `ComputationAccount` and the current slot
1223
1296
  * in parallel. If the account is finalized, the monitor resolves. If the slot
1224
- * window is exceeded, the monitor resolves with a pruned result.
1297
+ * window is exceeded, the monitor resolves with a pruned result. If the
1298
+ * wall-clock safety timeout fires, a `"timed-out"` result is returned.
1225
1299
  *
1226
1300
  * **Transient error handling** — RPC fetch errors during polling are silently
1227
1301
  * swallowed and the poll loop continues.
@@ -1230,7 +1304,6 @@ declare function getWebsocketComputationMonitor(config: WebsocketBasedComputatio
1230
1304
  * @param deps - Optional dependency overrides for testing.
1231
1305
  * @returns A {@link ComputationMonitor} instance.
1232
1306
  *
1233
- * @throws {ComputationMonitorError} Stage `"timeout"` if safety timeout fires.
1234
1307
  * @throws {ComputationMonitorError} Stage `"signature-retrieval"` if lookup fails.
1235
1308
  *
1236
1309
  * @example
@@ -1239,19 +1312,22 @@ declare function getWebsocketComputationMonitor(config: WebsocketBasedComputatio
1239
1312
  * rpcUrl: "https://api.mainnet-beta.solana.com",
1240
1313
  * });
1241
1314
  *
1242
- * const result = await monitor.awaitComputation(computationAddress, {
1315
+ * const prepared = await monitor.prepareMonitor(computationAddress, {
1243
1316
  * maxSlotWindow: 250,
1244
1317
  * pollingIntervalMs: 3_000,
1245
1318
  * retrieveCallbackSignature: true,
1246
1319
  * });
1247
1320
  *
1321
+ * // ... send queue_computation transaction ...
1322
+ *
1323
+ * const result = await prepared.awaitComputation();
1248
1324
  * if (result.status === "finalized") {
1249
1325
  * console.log(`Callback: ${result.callbackSignature}`);
1250
1326
  * }
1251
1327
  * ```
1252
1328
  *
1253
1329
  * @see {@link getWebsocketComputationMonitor} for the WebSocket alternative
1254
- * @since 2.0.0
1330
+ * @since 3.0.0
1255
1331
  * @public
1256
1332
  */
1257
1333
  declare function getPollingComputationMonitor(config: PollingBasedComputationMonitorConfig, deps?: PollingBasedComputationMonitorDeps): ComputationMonitor;
@@ -2444,8 +2520,9 @@ interface IUmbraClient {
2444
2520
  *
2445
2521
  * @remarks
2446
2522
  * When provided, enables monitoring of ComputationAccount status changes
2447
- * (Queued → Finalized) after queue_computation transactions. Callers invoke
2448
- * `computationMonitor.awaitComputation(address)` to wait for finalization.
2523
+ * (Queued → Finalized) after queue_computation transactions. The monitor
2524
+ * is prepared before the queue transaction is sent, then awaited afterward
2525
+ * via `prepareMonitor(address).awaitComputation()`.
2449
2526
  *
2450
2527
  * If not provided, callers must implement their own monitoring logic or
2451
2528
  * use fire-and-forget behavior (send the queue transaction and don't wait
@@ -2625,4 +2702,4 @@ interface IUmbraClient {
2625
2702
  };
2626
2703
  }
2627
2704
 
2628
- export { type MerkleProofData as $, type AccountInfoProviderFunction as A, type BatchMerkleProofFetcherFunction as B, type CreateSolanaRpcFunction as C, DEFAULT_MAX_SLOT_WINDOW as D, type PollingBasedComputationMonitorDeps as E, type PollingComputationMonitorOptions as F, type GetLatestBlockhash as G, type WebsocketBasedComputationMonitorDeps as H, type IUmbraSigner as I, getPollingComputationMonitor as J, getWebsocketComputationMonitor as K, type GetMasterSeedFunction as L, type MerkleProofFetcherFunction as M, type ClaimableUtxoResult as N, type DecryptedUtxoData as O, type PollingBasedComputationMonitorConfig as P, type EpochInfoResult as Q, type FireAndForget as R, type SendAndConfirmTransactionFactoryFunction as S, type TransactionForwarder as T, type UtxoDataFetcherFunction as U, type ForwardInParallel as V, type WebsocketBasedComputationMonitorConfig as W, type ForwardSequentially as X, type H1Components as Y, type IUmbraIndexer as Z, type LatestBlockhashResult as _, type GetEpochInfo as a, type ScannedUtxoResult as a0, type SignableTransaction as a1, type SignedMessage as a2, type TimestampComponents as a3, type UtxoDataItem as a4, type UtxoFetchResult as a5, type CreateSolanaRpcSubscriptionsFunction as b, type ComputationMonitor as c, type IUmbraClient as d, type GetMerkleProofFetcherArgs as e, type GetMerkleProofFetcherDeps as f, type GetUtxoDataFetcherArgs as g, type GetUtxoDataFetcherDeps as h, type ScannedUtxoData as i, type BatchMerkleProofResult as j, type ClaimableUtxoData as k, type GetClaimableUtxoScannerFunctionArgs as l, type GetClaimableUtxoScannerFunctionDeps as m, type ClaimableUtxoScannerFunction as n, type AesDecryptorFunction as o, type AesEncryptorFunction as p, type ComputationFinalizedResult as q, type ComputationFinalizedResultWithSignature as r, type ComputationMonitorOptions as s, type ComputationMonitorProgressEvent as t, type ComputationMonitorResult as u, type ComputationMonitorResultWithSignature as v, type ComputationPrunedResult as w, DEFAULT_POLLING_INTERVAL_MS as x, DEFAULT_SAFETY_TIMEOUT_MS as y, DEFAULT_SIGNATURE_RETRIEVAL_LIMIT as z };
2705
+ export { type MerkleProofData as $, type AccountInfoProviderFunction as A, type BatchMerkleProofResult as B, type CreateSolanaRpcFunction as C, DEFAULT_MAX_SLOT_WINDOW as D, getPollingComputationMonitor as E, getWebsocketComputationMonitor as F, type GetLatestBlockhash as G, type GetMasterSeedFunction as H, type IUmbraSigner as I, type BatchMerkleProofFetcherFunction as J, type ClaimableUtxoResult as K, type DecryptedUtxoData as L, type EpochInfoResult as M, type FireAndForget as N, type ForwardInParallel as O, type PollingBasedComputationMonitorConfig as P, type ForwardSequentially as Q, type GetMerkleProofFetcherArgs as R, type SendAndConfirmTransactionFactoryFunction as S, type TransactionForwarder as T, type GetMerkleProofFetcherDeps as U, type GetUtxoDataFetcherArgs as V, type WebsocketBasedComputationMonitorConfig as W, type GetUtxoDataFetcherDeps as X, type H1Components as Y, type IUmbraIndexer as Z, type LatestBlockhashResult as _, type GetEpochInfo as a, type MerkleProofFetcherFunction as a0, type ScannedUtxoResult as a1, type SignableTransaction as a2, type SignedMessage as a3, type TimestampComponents as a4, type UtxoDataFetcherFunction as a5, type UtxoDataItem as a6, type UtxoFetchResult as a7, type CreateSolanaRpcSubscriptionsFunction as b, type ComputationMonitor as c, type IUmbraClient as d, type ScannedUtxoData as e, type ClaimableUtxoData as f, type GetClaimableUtxoScannerFunctionArgs as g, type GetClaimableUtxoScannerFunctionDeps as h, type ClaimableUtxoScannerFunction as i, type AesDecryptorFunction as j, type AesEncryptorFunction as k, type ComputationFinalizedResult as l, type ComputationFinalizedResultWithSignature as m, type ComputationMonitorOptions as n, type ComputationMonitorProgressEvent as o, type ComputationMonitorResult as p, type ComputationMonitorResultWithSignature as q, type ComputationPrunedResult as r, type ComputationTimedOutResult as s, DEFAULT_POLLING_INTERVAL_MS as t, DEFAULT_SAFETY_TIMEOUT_MS as u, DEFAULT_SIGNATURE_RETRIEVAL_LIMIT as v, type PollingBasedComputationMonitorDeps as w, type PollingComputationMonitorOptions as x, type PreparedComputationMonitor as y, type WebsocketBasedComputationMonitorDeps as z };
@@ -965,6 +965,23 @@ interface ComputationPrunedResult {
965
965
  /** The current slot at the time pruning was detected. */
966
966
  readonly currentSlot: bigint;
967
967
  }
968
+ /**
969
+ * Result when the computation monitoring timed out.
970
+ *
971
+ * This occurs when the wall-clock safety timeout fires (RPC unresponsive)
972
+ * or the monitoring was cancelled via an external `AbortSignal`. Unlike
973
+ * `"pruned"`, this does not necessarily mean the computation failed — it may
974
+ * still finalize later. However, the monitor has stopped watching.
975
+ *
976
+ * @since 3.0.0
977
+ * @public
978
+ */
979
+ interface ComputationTimedOutResult {
980
+ /** The monitor gave up before observing finalization or pruning. */
981
+ readonly status: "timed-out";
982
+ /** Wall-clock milliseconds from monitor start to timeout. */
983
+ readonly elapsedMs: number;
984
+ }
968
985
  /**
969
986
  * Discriminated union of all computation monitoring outcomes.
970
987
  *
@@ -972,19 +989,25 @@ interface ComputationPrunedResult {
972
989
  * Callers must check `result.status` to determine the outcome:
973
990
  *
974
991
  * ```typescript
975
- * const result = await monitor.awaitComputation(address);
976
- * if (result.status === "finalized") {
977
- * // MPC succeeded — continue with the encrypted result
978
- * } else {
979
- * // Pruned — the computation will never finalize
980
- * console.log(`Pruned: ${result.currentSlot - result.queuedSlot} slots elapsed`);
992
+ * const result = await prepared.awaitComputation();
993
+ * switch (result.status) {
994
+ * case "finalized":
995
+ * // MPC succeeded — continue with the encrypted result
996
+ * break;
997
+ * case "pruned":
998
+ * // Pruned — the computation will never finalize
999
+ * console.log(`Pruned: ${result.currentSlot - result.queuedSlot} slots elapsed`);
1000
+ * break;
1001
+ * case "timed-out":
1002
+ * // Monitor gave up — computation may still finalize later
1003
+ * break;
981
1004
  * }
982
1005
  * ```
983
1006
  *
984
1007
  * @since 2.0.0
985
1008
  * @public
986
1009
  */
987
- type ComputationMonitorResult = ComputationFinalizedResult | ComputationPrunedResult;
1010
+ type ComputationMonitorResult = ComputationFinalizedResult | ComputationPrunedResult | ComputationTimedOutResult;
988
1011
  /**
989
1012
  * Extended finalized result with a guaranteed callback signature.
990
1013
  * Returned when `retrieveCallbackSignature` is `true` and the computation finalized.
@@ -999,12 +1022,12 @@ interface ComputationFinalizedResultWithSignature extends Omit<ComputationFinali
999
1022
  /**
1000
1023
  * Result type when `retrieveCallbackSignature` is `true`.
1001
1024
  * If finalized, the callback signature is guaranteed present.
1002
- * If pruned, no signature is available.
1025
+ * If pruned or timed out, no signature is available.
1003
1026
  *
1004
1027
  * @since 2.0.0
1005
1028
  * @public
1006
1029
  */
1007
- type ComputationMonitorResultWithSignature = ComputationFinalizedResultWithSignature | ComputationPrunedResult;
1030
+ type ComputationMonitorResultWithSignature = ComputationFinalizedResultWithSignature | ComputationPrunedResult | ComputationTimedOutResult;
1008
1031
  /**
1009
1032
  * Progress event types fired via the `onProgress` callback.
1010
1033
  *
@@ -1101,33 +1124,70 @@ interface PollingComputationMonitorOptions extends ComputationMonitorOptions {
1101
1124
  readonly pollingIntervalMs?: number;
1102
1125
  }
1103
1126
  /**
1104
- * Monitors an Arcium `ComputationAccount` for finalization or pruning.
1127
+ * A prepared computation monitor with an active subscription.
1105
1128
  *
1106
- * @since 2.0.0
1129
+ * Created by {@link ComputationMonitor.prepareMonitor}. The subscription is
1130
+ * established during preparation so that no account change notifications are
1131
+ * missed between the queue transaction and the start of monitoring.
1132
+ *
1133
+ * @remarks
1134
+ * Callers **must** call {@link cleanup} when the monitor is no longer needed,
1135
+ * even if {@link awaitComputation} was never called (e.g. if the queue
1136
+ * transaction fails). {@link cleanup} is idempotent.
1137
+ *
1138
+ * @since 3.0.0
1139
+ * @public
1140
+ */
1141
+ interface PreparedComputationMonitor {
1142
+ /**
1143
+ * Waits for the computation to finalize, prune, or time out.
1144
+ *
1145
+ * The first account-change notification (from the `queue_computation`
1146
+ * transaction itself) is consumed silently — only the MPC callback
1147
+ * notification triggers a finalized result.
1148
+ *
1149
+ * @returns A promise resolving to a finalized, pruned, or timed-out result.
1150
+ *
1151
+ * @throws {ComputationMonitorError} With stage `"subscription"` if the
1152
+ * underlying transport (WebSocket) encounters an unrecoverable failure.
1153
+ * @throws {ComputationMonitorError} With stage `"signature-retrieval"` if
1154
+ * callback signature lookup fails after finalization.
1155
+ */
1156
+ awaitComputation(): Promise<ComputationMonitorResult | ComputationMonitorResultWithSignature>;
1157
+ /**
1158
+ * Tears down the underlying subscription and timers.
1159
+ *
1160
+ * Safe to call multiple times. Called automatically at the end of
1161
+ * {@link awaitComputation}, but should also be called if
1162
+ * `awaitComputation` is never invoked (e.g. when the queue transaction
1163
+ * fails before monitoring begins).
1164
+ */
1165
+ cleanup(): void;
1166
+ }
1167
+ /**
1168
+ * Factory for preparing computation monitors.
1169
+ *
1170
+ * The two-phase design (prepare → await) ensures the subscription is active
1171
+ * **before** the `queue_computation` transaction is sent, eliminating the race
1172
+ * condition where a fast MPC callback could land between transaction confirmation
1173
+ * and subscription establishment.
1174
+ *
1175
+ * @since 3.0.0
1107
1176
  * @public
1108
1177
  */
1109
1178
  interface ComputationMonitor {
1110
1179
  /**
1111
- * Monitors a ComputationAccount until it finalizes or is pruned.
1180
+ * Establishes a subscription for the given computation account and returns
1181
+ * a {@link PreparedComputationMonitor} ready to await finalization.
1112
1182
  *
1113
1183
  * @param computationAddress - The on-chain address of the ComputationAccount PDA.
1114
- * @param options - Monitor options.
1115
- * @returns A promise resolving to a finalized or pruned result.
1116
- *
1117
- * @throws {ComputationMonitorError} With stage `"timeout"` if the safety wall-clock
1118
- * timeout fires (indicates RPC issues, not normal pruning).
1119
- * @throws {ComputationMonitorError} With stage `"subscription"` if WebSocket fails.
1120
- * @throws {ComputationMonitorError} With stage `"signature-retrieval"` if callback
1121
- * signature lookup fails after finalization.
1184
+ * @param options - Monitor options (slot window, timeout, progress, etc.).
1185
+ * @returns A prepared monitor whose subscription is already active.
1186
+ *
1187
+ * @throws {ComputationMonitorError} With stage `"subscription"` if the
1188
+ * initial subscription setup fails.
1122
1189
  */
1123
- awaitComputation: {
1124
- (computationAddress: Address, options?: ComputationMonitorOptions & {
1125
- retrieveCallbackSignature?: false;
1126
- }): Promise<ComputationMonitorResult>;
1127
- (computationAddress: Address, options: ComputationMonitorOptions & {
1128
- retrieveCallbackSignature: true;
1129
- }): Promise<ComputationMonitorResultWithSignature>;
1130
- };
1190
+ prepareMonitor(computationAddress: Address, options?: ComputationMonitorOptions): Promise<PreparedComputationMonitor>;
1131
1191
  }
1132
1192
  /**
1133
1193
  * Configuration for the WebSocket-based computation monitor.
@@ -1178,22 +1238,22 @@ interface PollingBasedComputationMonitorDeps {
1178
1238
  * subscriptions for real-time detection of computation finalization or pruning.
1179
1239
  *
1180
1240
  * @remarks
1181
- * **Detection strategy:** Subscribes to `accountNotifications` for the
1182
- * computation account. On each notification, decodes the account and checks
1183
- * the `status` field. Periodically fetches the current slot to detect pruning
1184
- * when the slot window is exceeded.
1241
+ * **Two-phase design:** {@link ComputationMonitor.prepareMonitor | prepareMonitor}
1242
+ * establishes the WebSocket subscription immediately so it is active before the
1243
+ * `queue_computation` transaction is sent. This eliminates the race condition
1244
+ * where a fast MPC callback could land between transaction confirmation and
1245
+ * subscription establishment.
1185
1246
  *
1186
- * **Initial state check:** Before subscribing, performs an HTTP fetch to handle
1187
- * the case where the computation already finalized before the monitor started.
1247
+ * **Detection strategy:** Subscribes to `accountNotifications` for the
1248
+ * computation account. The first notification (from the `queue_computation`
1249
+ * transaction itself) is consumed silently to capture the queued slot. Subsequent
1250
+ * notifications are checked for `Finalized` status. Periodic slot checks detect
1251
+ * pruning when the slot window is exceeded.
1188
1252
  *
1189
1253
  * @param config - HTTP RPC URL and WebSocket URL.
1190
1254
  * @param deps - Optional dependency overrides for testing.
1191
1255
  * @returns A {@link ComputationMonitor} instance.
1192
1256
  *
1193
- * @throws {ComputationMonitorError} Stage `"timeout"` if safety timeout fires.
1194
- * @throws {ComputationMonitorError} Stage `"subscription"` if WebSocket fails.
1195
- * @throws {ComputationMonitorError} Stage `"signature-retrieval"` if lookup fails.
1196
- *
1197
1257
  * @example
1198
1258
  * ```typescript
1199
1259
  * const monitor = getWebsocketComputationMonitor({
@@ -1201,16 +1261,29 @@ interface PollingBasedComputationMonitorDeps {
1201
1261
  * rpcSubscriptionsUrl: "wss://api.mainnet-beta.solana.com",
1202
1262
  * });
1203
1263
  *
1204
- * const result = await monitor.awaitComputation(computationAddress);
1205
- * if (result.status === "finalized") {
1206
- * console.log(`Done in ${result.elapsedMs}ms`);
1207
- * } else {
1208
- * console.log(`Pruned after ${result.currentSlot - result.queuedSlot} slots`);
1264
+ * // Phase 1: establish subscription
1265
+ * const prepared = await monitor.prepareMonitor(computationAddress);
1266
+ *
1267
+ * // Phase 2: send queue_computation transaction
1268
+ * await forwarder.forwardSequentially([signedTx]);
1269
+ *
1270
+ * // Phase 3: await result (first WS notification from queue tx is ignored)
1271
+ * const result = await prepared.awaitComputation();
1272
+ * switch (result.status) {
1273
+ * case "finalized":
1274
+ * console.log(`Done in ${result.elapsedMs}ms`);
1275
+ * break;
1276
+ * case "pruned":
1277
+ * console.log(`Pruned after ${result.currentSlot - result.queuedSlot} slots`);
1278
+ * break;
1279
+ * case "timed-out":
1280
+ * console.log(`Timed out after ${result.elapsedMs}ms`);
1281
+ * break;
1209
1282
  * }
1210
1283
  * ```
1211
1284
  *
1212
1285
  * @see {@link getPollingComputationMonitor} for the polling alternative
1213
- * @since 2.0.0
1286
+ * @since 3.0.0
1214
1287
  * @public
1215
1288
  */
1216
1289
  declare function getWebsocketComputationMonitor(config: WebsocketBasedComputationMonitorConfig, deps?: WebsocketBasedComputationMonitorDeps): ComputationMonitor;
@@ -1221,7 +1294,8 @@ declare function getWebsocketComputationMonitor(config: WebsocketBasedComputatio
1221
1294
  * @remarks
1222
1295
  * Each poll iteration fetches the `ComputationAccount` and the current slot
1223
1296
  * in parallel. If the account is finalized, the monitor resolves. If the slot
1224
- * window is exceeded, the monitor resolves with a pruned result.
1297
+ * window is exceeded, the monitor resolves with a pruned result. If the
1298
+ * wall-clock safety timeout fires, a `"timed-out"` result is returned.
1225
1299
  *
1226
1300
  * **Transient error handling** — RPC fetch errors during polling are silently
1227
1301
  * swallowed and the poll loop continues.
@@ -1230,7 +1304,6 @@ declare function getWebsocketComputationMonitor(config: WebsocketBasedComputatio
1230
1304
  * @param deps - Optional dependency overrides for testing.
1231
1305
  * @returns A {@link ComputationMonitor} instance.
1232
1306
  *
1233
- * @throws {ComputationMonitorError} Stage `"timeout"` if safety timeout fires.
1234
1307
  * @throws {ComputationMonitorError} Stage `"signature-retrieval"` if lookup fails.
1235
1308
  *
1236
1309
  * @example
@@ -1239,19 +1312,22 @@ declare function getWebsocketComputationMonitor(config: WebsocketBasedComputatio
1239
1312
  * rpcUrl: "https://api.mainnet-beta.solana.com",
1240
1313
  * });
1241
1314
  *
1242
- * const result = await monitor.awaitComputation(computationAddress, {
1315
+ * const prepared = await monitor.prepareMonitor(computationAddress, {
1243
1316
  * maxSlotWindow: 250,
1244
1317
  * pollingIntervalMs: 3_000,
1245
1318
  * retrieveCallbackSignature: true,
1246
1319
  * });
1247
1320
  *
1321
+ * // ... send queue_computation transaction ...
1322
+ *
1323
+ * const result = await prepared.awaitComputation();
1248
1324
  * if (result.status === "finalized") {
1249
1325
  * console.log(`Callback: ${result.callbackSignature}`);
1250
1326
  * }
1251
1327
  * ```
1252
1328
  *
1253
1329
  * @see {@link getWebsocketComputationMonitor} for the WebSocket alternative
1254
- * @since 2.0.0
1330
+ * @since 3.0.0
1255
1331
  * @public
1256
1332
  */
1257
1333
  declare function getPollingComputationMonitor(config: PollingBasedComputationMonitorConfig, deps?: PollingBasedComputationMonitorDeps): ComputationMonitor;
@@ -2444,8 +2520,9 @@ interface IUmbraClient {
2444
2520
  *
2445
2521
  * @remarks
2446
2522
  * When provided, enables monitoring of ComputationAccount status changes
2447
- * (Queued → Finalized) after queue_computation transactions. Callers invoke
2448
- * `computationMonitor.awaitComputation(address)` to wait for finalization.
2523
+ * (Queued → Finalized) after queue_computation transactions. The monitor
2524
+ * is prepared before the queue transaction is sent, then awaited afterward
2525
+ * via `prepareMonitor(address).awaitComputation()`.
2449
2526
  *
2450
2527
  * If not provided, callers must implement their own monitoring logic or
2451
2528
  * use fire-and-forget behavior (send the queue transaction and don't wait
@@ -2625,4 +2702,4 @@ interface IUmbraClient {
2625
2702
  };
2626
2703
  }
2627
2704
 
2628
- export { type MerkleProofData as $, type AccountInfoProviderFunction as A, type BatchMerkleProofFetcherFunction as B, type CreateSolanaRpcFunction as C, DEFAULT_MAX_SLOT_WINDOW as D, type PollingBasedComputationMonitorDeps as E, type PollingComputationMonitorOptions as F, type GetLatestBlockhash as G, type WebsocketBasedComputationMonitorDeps as H, type IUmbraSigner as I, getPollingComputationMonitor as J, getWebsocketComputationMonitor as K, type GetMasterSeedFunction as L, type MerkleProofFetcherFunction as M, type ClaimableUtxoResult as N, type DecryptedUtxoData as O, type PollingBasedComputationMonitorConfig as P, type EpochInfoResult as Q, type FireAndForget as R, type SendAndConfirmTransactionFactoryFunction as S, type TransactionForwarder as T, type UtxoDataFetcherFunction as U, type ForwardInParallel as V, type WebsocketBasedComputationMonitorConfig as W, type ForwardSequentially as X, type H1Components as Y, type IUmbraIndexer as Z, type LatestBlockhashResult as _, type GetEpochInfo as a, type ScannedUtxoResult as a0, type SignableTransaction as a1, type SignedMessage as a2, type TimestampComponents as a3, type UtxoDataItem as a4, type UtxoFetchResult as a5, type CreateSolanaRpcSubscriptionsFunction as b, type ComputationMonitor as c, type IUmbraClient as d, type GetMerkleProofFetcherArgs as e, type GetMerkleProofFetcherDeps as f, type GetUtxoDataFetcherArgs as g, type GetUtxoDataFetcherDeps as h, type ScannedUtxoData as i, type BatchMerkleProofResult as j, type ClaimableUtxoData as k, type GetClaimableUtxoScannerFunctionArgs as l, type GetClaimableUtxoScannerFunctionDeps as m, type ClaimableUtxoScannerFunction as n, type AesDecryptorFunction as o, type AesEncryptorFunction as p, type ComputationFinalizedResult as q, type ComputationFinalizedResultWithSignature as r, type ComputationMonitorOptions as s, type ComputationMonitorProgressEvent as t, type ComputationMonitorResult as u, type ComputationMonitorResultWithSignature as v, type ComputationPrunedResult as w, DEFAULT_POLLING_INTERVAL_MS as x, DEFAULT_SAFETY_TIMEOUT_MS as y, DEFAULT_SIGNATURE_RETRIEVAL_LIMIT as z };
2705
+ export { type MerkleProofData as $, type AccountInfoProviderFunction as A, type BatchMerkleProofResult as B, type CreateSolanaRpcFunction as C, DEFAULT_MAX_SLOT_WINDOW as D, getPollingComputationMonitor as E, getWebsocketComputationMonitor as F, type GetLatestBlockhash as G, type GetMasterSeedFunction as H, type IUmbraSigner as I, type BatchMerkleProofFetcherFunction as J, type ClaimableUtxoResult as K, type DecryptedUtxoData as L, type EpochInfoResult as M, type FireAndForget as N, type ForwardInParallel as O, type PollingBasedComputationMonitorConfig as P, type ForwardSequentially as Q, type GetMerkleProofFetcherArgs as R, type SendAndConfirmTransactionFactoryFunction as S, type TransactionForwarder as T, type GetMerkleProofFetcherDeps as U, type GetUtxoDataFetcherArgs as V, type WebsocketBasedComputationMonitorConfig as W, type GetUtxoDataFetcherDeps as X, type H1Components as Y, type IUmbraIndexer as Z, type LatestBlockhashResult as _, type GetEpochInfo as a, type MerkleProofFetcherFunction as a0, type ScannedUtxoResult as a1, type SignableTransaction as a2, type SignedMessage as a3, type TimestampComponents as a4, type UtxoDataFetcherFunction as a5, type UtxoDataItem as a6, type UtxoFetchResult as a7, type CreateSolanaRpcSubscriptionsFunction as b, type ComputationMonitor as c, type IUmbraClient as d, type ScannedUtxoData as e, type ClaimableUtxoData as f, type GetClaimableUtxoScannerFunctionArgs as g, type GetClaimableUtxoScannerFunctionDeps as h, type ClaimableUtxoScannerFunction as i, type AesDecryptorFunction as j, type AesEncryptorFunction as k, type ComputationFinalizedResult as l, type ComputationFinalizedResultWithSignature as m, type ComputationMonitorOptions as n, type ComputationMonitorProgressEvent as o, type ComputationMonitorResult as p, type ComputationMonitorResultWithSignature as q, type ComputationPrunedResult as r, type ComputationTimedOutResult as s, DEFAULT_POLLING_INTERVAL_MS as t, DEFAULT_SAFETY_TIMEOUT_MS as u, DEFAULT_SIGNATURE_RETRIEVAL_LIMIT as v, type PollingBasedComputationMonitorDeps as w, type PollingComputationMonitorOptions as x, type PreparedComputationMonitor as y, type WebsocketBasedComputationMonitorDeps as z };
@@ -2,7 +2,7 @@
2
2
 
3
3
  var chunk43JEHY7D_cjs = require('../chunk-43JEHY7D.cjs');
4
4
  var chunkTQQZGNOI_cjs = require('../chunk-TQQZGNOI.cjs');
5
- require('../chunk-BL6WXLPV.cjs');
5
+ require('../chunk-KCHHJKQN.cjs');
6
6
  require('../chunk-FSK2ICMB.cjs');
7
7
  require('../chunk-QJAUUYZU.cjs');
8
8
  var chunkPK6SKIKE_cjs = require('../chunk-PK6SKIKE.cjs');
@@ -1,6 +1,6 @@
1
1
  export { ASSOCIATED_TOKEN_PROGRAM_ID, DEFAULT_ALGORITHM_VERSION, DEFAULT_NETWORK, DEFAULT_PROTOCOL_VERSION, DEFAULT_SCHEME_VERSION, SPL_TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, assertNetwork, assertValidAlgorithmVersion, assertValidProtocolVersion, assertValidSchemeVersion, assertValidVersion, getDefaultAlgorithmVersion, getDefaultProtocolVersion, getDefaultSchemeVersion, getNetworkConfig, getNetworkSpecifier } from '../chunk-FQDYYTPG.js';
2
2
  export { ARCIUM_CLUSTER_SEED, ARCIUM_COMPUTATION_SEED, ARCIUM_COMP_DEF_SEED, ARCIUM_EXEC_POOL_SEED, ARCIUM_MEMPOOL_SEED, ARCIUM_MXE_ACCOUNT_SEED, ARCIUM_OFFSET_BUFFER_SIZE } from '../chunk-EEKF4553.js';
3
- import '../chunk-GP26R377.js';
3
+ import '../chunk-AUNYA6JP.js';
4
4
  import '../chunk-5KPQXPQM.js';
5
5
  import '../chunk-4TZVXB5G.js';
6
6
  import { __name } from '../chunk-7QVYU63E.js';