@cofhe/sdk 1.1.0-alpha.0 → 1.1.0-alpha.1

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.
@@ -465,6 +465,7 @@ declare class DecryptForViewBuilder<U extends FheTypes> extends BaseBuilder {
465
465
  private acp?;
466
466
  private pollCallback?;
467
467
  private retry404TimeoutMs;
468
+ private timeoutMs?;
468
469
  constructor(params: DecryptForViewBuilderParams<U>);
469
470
  /**
470
471
  * @param chainId - Chain to decrypt values from. Used to fetch the threshold network URL and use the correct acp.
@@ -500,6 +501,12 @@ declare class DecryptForViewBuilder<U extends FheTypes> extends BaseBuilder {
500
501
  getAccount(): string | undefined;
501
502
  onPoll(callback: DecryptPollCallbackFunction): DecryptForViewBuilder<U>;
502
503
  set404RetryTimeout(timeoutMs: number): DecryptForViewBuilder<U>;
504
+ /**
505
+ * The whole budget of this decrypt in milliseconds, submit retries and status polling together
506
+ * (5 minutes by default). Past it, `execute()` rejects with `SealOutputFailed`; a request still
507
+ * processing on the threshold network is not cancelled.
508
+ */
509
+ setTimeout(timeoutMs: number): DecryptForViewBuilder<U>;
503
510
  /**
504
511
  * Select "use acp" mode (optional).
505
512
  *
@@ -603,6 +610,7 @@ declare class DecryptForTxBuilder extends BaseBuilder {
603
610
  private acpSelection;
604
611
  private pollCallback?;
605
612
  private retry404TimeoutMs;
613
+ private timeoutMs?;
606
614
  constructor(params: DecryptForTxBuilderParams);
607
615
  /**
608
616
  * @param chainId - Chain to decrypt values from. Used to fetch the threshold network URL and use the correct acp.
@@ -642,6 +650,13 @@ declare class DecryptForTxBuilder extends BaseBuilder {
642
650
  onPoll(this: DecryptForTxBuilderSelected, callback: DecryptPollCallbackFunction): DecryptForTxBuilderSelected;
643
651
  set404RetryTimeout(this: DecryptForTxBuilderUnset, timeoutMs: number): DecryptForTxBuilderUnset;
644
652
  set404RetryTimeout(this: DecryptForTxBuilderSelected, timeoutMs: number): DecryptForTxBuilderSelected;
653
+ /**
654
+ * The whole budget of this decrypt in milliseconds, submit retries and status polling together
655
+ * (5 minutes by default). Past it, `execute()` rejects with `DecryptFailed`; a request still
656
+ * processing on the threshold network is not cancelled.
657
+ */
658
+ setTimeout(this: DecryptForTxBuilderUnset, timeoutMs: number): DecryptForTxBuilderUnset;
659
+ setTimeout(this: DecryptForTxBuilderSelected, timeoutMs: number): DecryptForTxBuilderSelected;
645
660
  /**
646
661
  * Select "use acp" mode.
647
662
  *
package/dist/core.cjs CHANGED
@@ -3984,6 +3984,16 @@ function mapApiErrorCodeToCofheErrorCode(apiErrorCode, fallback) {
3984
3984
 
3985
3985
  // core/decrypt/submitRetry.ts
3986
3986
  var DEFAULT_404_RETRY_TIMEOUT_MS = 1e4;
3987
+ var DEFAULT_DECRYPT_TIMEOUT_MS = 5 * 60 * 1e3;
3988
+ function assertDecryptTimeoutMs(timeoutMs, operationLabel) {
3989
+ if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
3990
+ throw new CofheError({
3991
+ code: "INTERNAL_ERROR" /* InternalError */,
3992
+ message: `${operationLabel}: setTimeout(timeoutMs) expects a finite number greater than 0.`,
3993
+ context: { timeoutMs }
3994
+ });
3995
+ }
3996
+ }
3987
3997
  function normalize404RetryTimeoutMs(params) {
3988
3998
  const { timeoutMs, operationLabel, errorCode } = params;
3989
3999
  if (timeoutMs === void 0)
@@ -4122,7 +4132,6 @@ function parseDecryptedBytesToBigInt(decrypted) {
4122
4132
  // core/decrypt/tnSealOutputV2.ts
4123
4133
  var POLL_INTERVAL_MS = 1e3;
4124
4134
  var POLL_MAX_INTERVAL_MS = 1e4;
4125
- var SEAL_OUTPUT_TIMEOUT_MS = 5 * 60 * 1e3;
4126
4135
  var SUBMIT_RETRY_INTERVAL_MS = 1e3;
4127
4136
  function numberArrayToUint8Array(arr) {
4128
4137
  return new Uint8Array(arr);
@@ -4180,7 +4189,7 @@ function parseCompletedSealOutputResponse(params) {
4180
4189
  }
4181
4190
  return convertSealedData(sealed);
4182
4191
  }
4183
- async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, acp, overallStartTime, retry404TimeoutMs, onPoll) {
4192
+ async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, acp, overallStartTime, retry404TimeoutMs, timeoutMs, onPoll) {
4184
4193
  const body = {
4185
4194
  ct_tempkey: BigInt(ctHash).toString(16).padStart(64, "0"),
4186
4195
  host_chain_id: chainId,
@@ -4283,7 +4292,7 @@ async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, acp
4283
4292
  status: responseClassification.status,
4284
4293
  elapsedMs,
4285
4294
  retry404TimeoutMs,
4286
- overallTimeoutMs: SEAL_OUTPUT_TIMEOUT_MS,
4295
+ overallTimeoutMs: timeoutMs,
4287
4296
  thresholdNetworkUrl,
4288
4297
  body,
4289
4298
  attemptIndex,
@@ -4295,13 +4304,13 @@ async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, acp
4295
4304
  attemptIndex,
4296
4305
  elapsedMs,
4297
4306
  intervalMs: SUBMIT_RETRY_INTERVAL_MS,
4298
- timeoutMs: SEAL_OUTPUT_TIMEOUT_MS
4307
+ timeoutMs
4299
4308
  });
4300
4309
  await new Promise((resolve) => setTimeout(resolve, SUBMIT_RETRY_INTERVAL_MS));
4301
4310
  attemptIndex += 1;
4302
4311
  }
4303
4312
  }
4304
- async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStartTime, onPoll) {
4313
+ async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStartTime, timeoutMs, onPoll) {
4305
4314
  let attemptIndex = 0;
4306
4315
  while (true) {
4307
4316
  const elapsedMs = Date.now() - overallStartTime;
@@ -4315,17 +4324,17 @@ async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStart
4315
4324
  attemptIndex,
4316
4325
  elapsedMs,
4317
4326
  intervalMs,
4318
- timeoutMs: SEAL_OUTPUT_TIMEOUT_MS
4327
+ timeoutMs
4319
4328
  });
4320
- if (elapsedMs > SEAL_OUTPUT_TIMEOUT_MS) {
4329
+ if (elapsedMs > timeoutMs) {
4321
4330
  throw new CofheError({
4322
4331
  code: "SEAL_OUTPUT_FAILED" /* SealOutputFailed */,
4323
- message: `sealOutput polling timed out after ${SEAL_OUTPUT_TIMEOUT_MS}ms`,
4332
+ message: `sealOutput polling timed out after ${timeoutMs}ms`,
4324
4333
  hint: "The request may still be processing. Try again later.",
4325
4334
  context: {
4326
4335
  thresholdNetworkUrl,
4327
4336
  requestId,
4328
- timeoutMs: SEAL_OUTPUT_TIMEOUT_MS
4337
+ timeoutMs
4329
4338
  }
4330
4339
  });
4331
4340
  }
@@ -4413,6 +4422,7 @@ async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStart
4413
4422
  }
4414
4423
  async function tnSealOutputV2(params) {
4415
4424
  const { thresholdNetworkUrl, ctHash, chainId, acp, retry404TimeoutMs, onPoll } = params;
4425
+ const timeoutMs = params.timeoutMs ?? DEFAULT_DECRYPT_TIMEOUT_MS;
4416
4426
  const normalized404RetryTimeoutMs = normalize404RetryTimeoutMs({
4417
4427
  timeoutMs: retry404TimeoutMs,
4418
4428
  operationLabel: "sealOutput",
@@ -4426,12 +4436,13 @@ async function tnSealOutputV2(params) {
4426
4436
  acp,
4427
4437
  overallStartTime,
4428
4438
  normalized404RetryTimeoutMs,
4439
+ timeoutMs,
4429
4440
  onPoll
4430
4441
  );
4431
4442
  if (submitResult.kind === "completed") {
4432
4443
  return submitResult.sealed;
4433
4444
  }
4434
- return await pollSealOutputStatus(thresholdNetworkUrl, submitResult.requestId, overallStartTime, onPoll);
4445
+ return await pollSealOutputStatus(thresholdNetworkUrl, submitResult.requestId, overallStartTime, timeoutMs, onPoll);
4435
4446
  }
4436
4447
 
4437
4448
  // core/decrypt/decryptForViewBuilder.ts
@@ -4443,6 +4454,7 @@ var DecryptForViewBuilder = class extends BaseBuilder {
4443
4454
  acp;
4444
4455
  pollCallback;
4445
4456
  retry404TimeoutMs = DEFAULT_404_RETRY_TIMEOUT_MS2;
4457
+ timeoutMs;
4446
4458
  constructor(params) {
4447
4459
  super({
4448
4460
  config: params.config,
@@ -4516,6 +4528,16 @@ var DecryptForViewBuilder = class extends BaseBuilder {
4516
4528
  this.retry404TimeoutMs = timeoutMs;
4517
4529
  return this;
4518
4530
  }
4531
+ /**
4532
+ * The whole budget of this decrypt in milliseconds, submit retries and status polling together
4533
+ * (5 minutes by default). Past it, `execute()` rejects with `SealOutputFailed`; a request still
4534
+ * processing on the threshold network is not cancelled.
4535
+ */
4536
+ setTimeout(timeoutMs) {
4537
+ assertDecryptTimeoutMs(timeoutMs, "decryptForView");
4538
+ this.timeoutMs = timeoutMs;
4539
+ return this;
4540
+ }
4519
4541
  withACP(acpOrACPHash) {
4520
4542
  if (typeof acpOrACPHash === "string") {
4521
4543
  this.acpHash = acpOrACPHash;
@@ -4645,6 +4667,7 @@ var DecryptForViewBuilder = class extends BaseBuilder {
4645
4667
  acp: wireAcp,
4646
4668
  thresholdNetworkUrl,
4647
4669
  retry404TimeoutMs: this.retry404TimeoutMs,
4670
+ timeoutMs: this.timeoutMs,
4648
4671
  onPoll: this.pollCallback
4649
4672
  });
4650
4673
  return ACPUtils.unseal(acp, sealed);
@@ -4747,7 +4770,6 @@ async function cofheMocksDecryptForTx(ctHash, utype, acp, publicClient) {
4747
4770
  // core/decrypt/tnDecryptV2.ts
4748
4771
  var POLL_INTERVAL_MS2 = 1e3;
4749
4772
  var POLL_MAX_INTERVAL_MS2 = 1e4;
4750
- var DECRYPT_TIMEOUT_MS = 5 * 60 * 1e3;
4751
4773
  var SUBMIT_RETRY_INTERVAL_MS2 = 1e3;
4752
4774
  function assertDecryptSubmitResponseV2(value) {
4753
4775
  if (value == null || typeof value !== "object") {
@@ -4864,7 +4886,7 @@ function assertDecryptStatusResponseV2(value) {
4864
4886
  }
4865
4887
  return value;
4866
4888
  }
4867
- async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, acp, overallStartTime, retry404TimeoutMs, onPoll) {
4889
+ async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, acp, overallStartTime, retry404TimeoutMs, timeoutMs, onPoll) {
4868
4890
  const body = {
4869
4891
  ct_tempkey: BigInt(ctHash).toString(16).padStart(64, "0"),
4870
4892
  host_chain_id: chainId
@@ -4971,7 +4993,7 @@ async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, acp,
4971
4993
  status: responseClassification.status,
4972
4994
  elapsedMs,
4973
4995
  retry404TimeoutMs,
4974
- overallTimeoutMs: DECRYPT_TIMEOUT_MS,
4996
+ overallTimeoutMs: timeoutMs,
4975
4997
  thresholdNetworkUrl,
4976
4998
  body,
4977
4999
  attemptIndex,
@@ -4983,13 +5005,13 @@ async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, acp,
4983
5005
  attemptIndex,
4984
5006
  elapsedMs,
4985
5007
  intervalMs: SUBMIT_RETRY_INTERVAL_MS2,
4986
- timeoutMs: DECRYPT_TIMEOUT_MS
5008
+ timeoutMs
4987
5009
  });
4988
5010
  await new Promise((resolve) => setTimeout(resolve, SUBMIT_RETRY_INTERVAL_MS2));
4989
5011
  attemptIndex += 1;
4990
5012
  }
4991
5013
  }
4992
- async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartTime, onPoll) {
5014
+ async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartTime, timeoutMs, onPoll) {
4993
5015
  let attemptIndex = 0;
4994
5016
  while (true) {
4995
5017
  const elapsedMs = Date.now() - overallStartTime;
@@ -5003,17 +5025,17 @@ async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartT
5003
5025
  attemptIndex,
5004
5026
  elapsedMs,
5005
5027
  intervalMs,
5006
- timeoutMs: DECRYPT_TIMEOUT_MS
5028
+ timeoutMs
5007
5029
  });
5008
- if (elapsedMs > DECRYPT_TIMEOUT_MS) {
5030
+ if (elapsedMs > timeoutMs) {
5009
5031
  throw new CofheError({
5010
5032
  code: "DECRYPT_FAILED" /* DecryptFailed */,
5011
- message: `decrypt polling timed out after ${DECRYPT_TIMEOUT_MS}ms`,
5033
+ message: `decrypt polling timed out after ${timeoutMs}ms`,
5012
5034
  hint: "The request may still be processing. Try again later.",
5013
5035
  context: {
5014
5036
  thresholdNetworkUrl,
5015
5037
  requestId,
5016
- timeoutMs: DECRYPT_TIMEOUT_MS
5038
+ timeoutMs
5017
5039
  }
5018
5040
  });
5019
5041
  }
@@ -5102,6 +5124,7 @@ async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartT
5102
5124
  }
5103
5125
  async function tnDecryptV2(params) {
5104
5126
  const { thresholdNetworkUrl, ctHash, chainId, acp, retry404TimeoutMs, onPoll } = params;
5127
+ const timeoutMs = params.timeoutMs ?? DEFAULT_DECRYPT_TIMEOUT_MS;
5105
5128
  const normalized404RetryTimeoutMs = normalize404RetryTimeoutMs({
5106
5129
  timeoutMs: retry404TimeoutMs,
5107
5130
  operationLabel: "decrypt",
@@ -5115,12 +5138,13 @@ async function tnDecryptV2(params) {
5115
5138
  acp,
5116
5139
  overallStartTime,
5117
5140
  normalized404RetryTimeoutMs,
5141
+ timeoutMs,
5118
5142
  onPoll
5119
5143
  );
5120
5144
  if (submitResult.kind === "completed") {
5121
5145
  return submitResult;
5122
5146
  }
5123
- return await pollDecryptStatusV2(thresholdNetworkUrl, submitResult.requestId, overallStartTime, onPoll);
5147
+ return await pollDecryptStatusV2(thresholdNetworkUrl, submitResult.requestId, overallStartTime, timeoutMs, onPoll);
5124
5148
  }
5125
5149
 
5126
5150
  // core/decrypt/decryptForTxBuilder.ts
@@ -5132,6 +5156,7 @@ var DecryptForTxBuilder = class extends BaseBuilder {
5132
5156
  acpSelection = "unset";
5133
5157
  pollCallback;
5134
5158
  retry404TimeoutMs = DEFAULT_404_RETRY_TIMEOUT_MS3;
5159
+ timeoutMs;
5135
5160
  constructor(params) {
5136
5161
  super({
5137
5162
  config: params.config,
@@ -5174,6 +5199,11 @@ var DecryptForTxBuilder = class extends BaseBuilder {
5174
5199
  this.retry404TimeoutMs = timeoutMs;
5175
5200
  return this;
5176
5201
  }
5202
+ setTimeout(timeoutMs) {
5203
+ assertDecryptTimeoutMs(timeoutMs, "decryptForTx");
5204
+ this.timeoutMs = timeoutMs;
5205
+ return this;
5206
+ }
5177
5207
  withACP(acpOrACPHash) {
5178
5208
  if (this.acpSelection === "with-acp") {
5179
5209
  throw new CofheError({
@@ -5307,6 +5337,7 @@ var DecryptForTxBuilder = class extends BaseBuilder {
5307
5337
  acp: wireAcp,
5308
5338
  thresholdNetworkUrl,
5309
5339
  retry404TimeoutMs: this.retry404TimeoutMs,
5340
+ timeoutMs: this.timeoutMs,
5310
5341
  onPoll: this.pollCallback
5311
5342
  });
5312
5343
  return {
package/dist/core.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as CofheConfig, c as CofheClientParams, b as CofheClient, d as CofheClientConnectionState, F as FheTypes } from './clientTypes-RXwLVWou.cjs';
2
- export { A as AnyExternalHash, i as CofheClientACPs, C as CofheInputConfig, h as CofheInternalConfig, K as DecryptEndpoint, a4 as DecryptForTxBuilder, a5 as DecryptForTxResult, a3 as DecryptForViewBuilder, J as DecryptPollCallbackContext, G as DecryptPollCallbackFunction, a1 as EncryptInputsBuilder, a2 as EncryptInputsBuilderUnset, M as EncryptSetStateFn, W as EncryptStep, N as EncryptStepCallbackContext, S as Encryptable, p as EncryptableAddress, j as EncryptableBool, E as EncryptableItem, B as EncryptableToExternalHashMap, o as EncryptableUint128, l as EncryptableUint16, m as EncryptableUint32, n as EncryptableUint64, k as EncryptableUint8, q as EncryptedNumber, y as ExternalAddressHash, s as ExternalBoolHash, z as ExternalHashProof, D as ExternalItemHashes, x as ExternalUint128Hash, u as ExternalUint16Hash, v as ExternalUint32Hash, w as ExternalUint64Hash, t as ExternalUint8Hash, R as FheAllUTypes, Z as FheKeyDeserializer, r as FheTypeValue, Q as FheUintUTypes, H as HashPlusProofResult, I as IStorage, $ as KeysStorage, a0 as KeysStore, L as LiteralToPrimitive, P as Primitive, T as TfheInitializer, O as TfheThreadsSetting, U as UnsealedItem, a6 as ZkBuilderAndCrsGenerator, a7 as ZkProveWorkerFunction, a8 as ZkProveWorkerRequest, a9 as ZkProveWorkerResponse, f as assertNoRenamedConfigKeys, e as createCofheConfigBase, _ as createKeysStore, Y as fetchKeys, g as getCofheConfigItem, V as isEncryptableItem, X as isLastEncryptionStep, aa as zkProveWithWorker } from './clientTypes-RXwLVWou.cjs';
1
+ import { a as CofheConfig, c as CofheClientParams, b as CofheClient, d as CofheClientConnectionState, F as FheTypes } from './clientTypes-D2djRDoH.cjs';
2
+ export { A as AnyExternalHash, i as CofheClientACPs, C as CofheInputConfig, h as CofheInternalConfig, K as DecryptEndpoint, a4 as DecryptForTxBuilder, a5 as DecryptForTxResult, a3 as DecryptForViewBuilder, J as DecryptPollCallbackContext, G as DecryptPollCallbackFunction, a1 as EncryptInputsBuilder, a2 as EncryptInputsBuilderUnset, M as EncryptSetStateFn, W as EncryptStep, N as EncryptStepCallbackContext, S as Encryptable, p as EncryptableAddress, j as EncryptableBool, E as EncryptableItem, B as EncryptableToExternalHashMap, o as EncryptableUint128, l as EncryptableUint16, m as EncryptableUint32, n as EncryptableUint64, k as EncryptableUint8, q as EncryptedNumber, y as ExternalAddressHash, s as ExternalBoolHash, z as ExternalHashProof, D as ExternalItemHashes, x as ExternalUint128Hash, u as ExternalUint16Hash, v as ExternalUint32Hash, w as ExternalUint64Hash, t as ExternalUint8Hash, R as FheAllUTypes, Z as FheKeyDeserializer, r as FheTypeValue, Q as FheUintUTypes, H as HashPlusProofResult, I as IStorage, $ as KeysStorage, a0 as KeysStore, L as LiteralToPrimitive, P as Primitive, T as TfheInitializer, O as TfheThreadsSetting, U as UnsealedItem, a6 as ZkBuilderAndCrsGenerator, a7 as ZkProveWorkerFunction, a8 as ZkProveWorkerRequest, a9 as ZkProveWorkerResponse, f as assertNoRenamedConfigKeys, e as createCofheConfigBase, _ as createKeysStore, Y as fetchKeys, g as getCofheConfigItem, V as isEncryptableItem, X as isLastEncryptionStep, aa as zkProveWithWorker } from './clientTypes-D2djRDoH.cjs';
3
3
  import { PublicClient, Address, Hex } from 'viem';
4
4
  import './types-C07FK-cL.cjs';
5
5
  import 'zod';
package/dist/core.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as CofheConfig, c as CofheClientParams, b as CofheClient, d as CofheClientConnectionState, F as FheTypes } from './clientTypes-CnslFzxB.js';
2
- export { A as AnyExternalHash, i as CofheClientACPs, C as CofheInputConfig, h as CofheInternalConfig, K as DecryptEndpoint, a4 as DecryptForTxBuilder, a5 as DecryptForTxResult, a3 as DecryptForViewBuilder, J as DecryptPollCallbackContext, G as DecryptPollCallbackFunction, a1 as EncryptInputsBuilder, a2 as EncryptInputsBuilderUnset, M as EncryptSetStateFn, W as EncryptStep, N as EncryptStepCallbackContext, S as Encryptable, p as EncryptableAddress, j as EncryptableBool, E as EncryptableItem, B as EncryptableToExternalHashMap, o as EncryptableUint128, l as EncryptableUint16, m as EncryptableUint32, n as EncryptableUint64, k as EncryptableUint8, q as EncryptedNumber, y as ExternalAddressHash, s as ExternalBoolHash, z as ExternalHashProof, D as ExternalItemHashes, x as ExternalUint128Hash, u as ExternalUint16Hash, v as ExternalUint32Hash, w as ExternalUint64Hash, t as ExternalUint8Hash, R as FheAllUTypes, Z as FheKeyDeserializer, r as FheTypeValue, Q as FheUintUTypes, H as HashPlusProofResult, I as IStorage, $ as KeysStorage, a0 as KeysStore, L as LiteralToPrimitive, P as Primitive, T as TfheInitializer, O as TfheThreadsSetting, U as UnsealedItem, a6 as ZkBuilderAndCrsGenerator, a7 as ZkProveWorkerFunction, a8 as ZkProveWorkerRequest, a9 as ZkProveWorkerResponse, f as assertNoRenamedConfigKeys, e as createCofheConfigBase, _ as createKeysStore, Y as fetchKeys, g as getCofheConfigItem, V as isEncryptableItem, X as isLastEncryptionStep, aa as zkProveWithWorker } from './clientTypes-CnslFzxB.js';
1
+ import { a as CofheConfig, c as CofheClientParams, b as CofheClient, d as CofheClientConnectionState, F as FheTypes } from './clientTypes-B-qOZCx0.js';
2
+ export { A as AnyExternalHash, i as CofheClientACPs, C as CofheInputConfig, h as CofheInternalConfig, K as DecryptEndpoint, a4 as DecryptForTxBuilder, a5 as DecryptForTxResult, a3 as DecryptForViewBuilder, J as DecryptPollCallbackContext, G as DecryptPollCallbackFunction, a1 as EncryptInputsBuilder, a2 as EncryptInputsBuilderUnset, M as EncryptSetStateFn, W as EncryptStep, N as EncryptStepCallbackContext, S as Encryptable, p as EncryptableAddress, j as EncryptableBool, E as EncryptableItem, B as EncryptableToExternalHashMap, o as EncryptableUint128, l as EncryptableUint16, m as EncryptableUint32, n as EncryptableUint64, k as EncryptableUint8, q as EncryptedNumber, y as ExternalAddressHash, s as ExternalBoolHash, z as ExternalHashProof, D as ExternalItemHashes, x as ExternalUint128Hash, u as ExternalUint16Hash, v as ExternalUint32Hash, w as ExternalUint64Hash, t as ExternalUint8Hash, R as FheAllUTypes, Z as FheKeyDeserializer, r as FheTypeValue, Q as FheUintUTypes, H as HashPlusProofResult, I as IStorage, $ as KeysStorage, a0 as KeysStore, L as LiteralToPrimitive, P as Primitive, T as TfheInitializer, O as TfheThreadsSetting, U as UnsealedItem, a6 as ZkBuilderAndCrsGenerator, a7 as ZkProveWorkerFunction, a8 as ZkProveWorkerRequest, a9 as ZkProveWorkerResponse, f as assertNoRenamedConfigKeys, e as createCofheConfigBase, _ as createKeysStore, Y as fetchKeys, g as getCofheConfigItem, V as isEncryptableItem, X as isLastEncryptionStep, aa as zkProveWithWorker } from './clientTypes-B-qOZCx0.js';
3
3
  import { PublicClient, Address, Hex } from 'viem';
4
4
  import './types-C07FK-cL.js';
5
5
  import 'zod';
package/dist/core.js CHANGED
@@ -1,4 +1,4 @@
1
- export { InitialConnectStore as CONNECT_STORE_DEFAULTS, DecryptForTxBuilder, DecryptForViewBuilder, EncryptInputsBuilder, assertNoRenamedConfigKeys, cofheFetch, createCofheClientBase, createCofheConfigBase, createKeysStore, fetchKeys, getCofheConfigItem, getCofheDebugInterceptors, setCofheDebugInterceptors, verifyDecryptResult, zkProveWithWorker } from './chunk-2EO4JSR7.js';
1
+ export { InitialConnectStore as CONNECT_STORE_DEFAULTS, DecryptForTxBuilder, DecryptForViewBuilder, EncryptInputsBuilder, assertNoRenamedConfigKeys, cofheFetch, createCofheClientBase, createCofheConfigBase, createKeysStore, fetchKeys, getCofheConfigItem, getCofheDebugInterceptors, setCofheDebugInterceptors, verifyDecryptResult, zkProveWithWorker } from './chunk-VE7DKXSF.js';
2
2
  import './chunk-UKQAJK4N.js';
3
3
  export { getTaskManagerAddress } from './chunk-3L2IVPMI.js';
4
4
  export { EncryptStep, Encryptable, FheAllUTypes, FheTypes, FheUintUTypes, fheTypeToString, isEncryptableItem, isLastEncryptionStep } from './chunk-WJGTPW7K.js';
package/dist/node.cjs CHANGED
@@ -3770,6 +3770,16 @@ function mapApiErrorCodeToCofheErrorCode(apiErrorCode, fallback) {
3770
3770
 
3771
3771
  // core/decrypt/submitRetry.ts
3772
3772
  var DEFAULT_404_RETRY_TIMEOUT_MS = 1e4;
3773
+ var DEFAULT_DECRYPT_TIMEOUT_MS = 5 * 60 * 1e3;
3774
+ function assertDecryptTimeoutMs(timeoutMs, operationLabel) {
3775
+ if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
3776
+ throw new CofheError({
3777
+ code: "INTERNAL_ERROR" /* InternalError */,
3778
+ message: `${operationLabel}: setTimeout(timeoutMs) expects a finite number greater than 0.`,
3779
+ context: { timeoutMs }
3780
+ });
3781
+ }
3782
+ }
3773
3783
  function normalize404RetryTimeoutMs(params) {
3774
3784
  const { timeoutMs, operationLabel, errorCode } = params;
3775
3785
  if (timeoutMs === void 0)
@@ -3908,7 +3918,6 @@ function parseDecryptedBytesToBigInt(decrypted) {
3908
3918
  // core/decrypt/tnSealOutputV2.ts
3909
3919
  var POLL_INTERVAL_MS = 1e3;
3910
3920
  var POLL_MAX_INTERVAL_MS = 1e4;
3911
- var SEAL_OUTPUT_TIMEOUT_MS = 5 * 60 * 1e3;
3912
3921
  var SUBMIT_RETRY_INTERVAL_MS = 1e3;
3913
3922
  function numberArrayToUint8Array(arr) {
3914
3923
  return new Uint8Array(arr);
@@ -3966,7 +3975,7 @@ function parseCompletedSealOutputResponse(params) {
3966
3975
  }
3967
3976
  return convertSealedData(sealed);
3968
3977
  }
3969
- async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, acp, overallStartTime, retry404TimeoutMs, onPoll) {
3978
+ async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, acp, overallStartTime, retry404TimeoutMs, timeoutMs, onPoll) {
3970
3979
  const body = {
3971
3980
  ct_tempkey: BigInt(ctHash).toString(16).padStart(64, "0"),
3972
3981
  host_chain_id: chainId,
@@ -4069,7 +4078,7 @@ async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, acp
4069
4078
  status: responseClassification.status,
4070
4079
  elapsedMs,
4071
4080
  retry404TimeoutMs,
4072
- overallTimeoutMs: SEAL_OUTPUT_TIMEOUT_MS,
4081
+ overallTimeoutMs: timeoutMs,
4073
4082
  thresholdNetworkUrl,
4074
4083
  body,
4075
4084
  attemptIndex,
@@ -4081,13 +4090,13 @@ async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, acp
4081
4090
  attemptIndex,
4082
4091
  elapsedMs,
4083
4092
  intervalMs: SUBMIT_RETRY_INTERVAL_MS,
4084
- timeoutMs: SEAL_OUTPUT_TIMEOUT_MS
4093
+ timeoutMs
4085
4094
  });
4086
4095
  await new Promise((resolve) => setTimeout(resolve, SUBMIT_RETRY_INTERVAL_MS));
4087
4096
  attemptIndex += 1;
4088
4097
  }
4089
4098
  }
4090
- async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStartTime, onPoll) {
4099
+ async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStartTime, timeoutMs, onPoll) {
4091
4100
  let attemptIndex = 0;
4092
4101
  while (true) {
4093
4102
  const elapsedMs = Date.now() - overallStartTime;
@@ -4101,17 +4110,17 @@ async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStart
4101
4110
  attemptIndex,
4102
4111
  elapsedMs,
4103
4112
  intervalMs,
4104
- timeoutMs: SEAL_OUTPUT_TIMEOUT_MS
4113
+ timeoutMs
4105
4114
  });
4106
- if (elapsedMs > SEAL_OUTPUT_TIMEOUT_MS) {
4115
+ if (elapsedMs > timeoutMs) {
4107
4116
  throw new CofheError({
4108
4117
  code: "SEAL_OUTPUT_FAILED" /* SealOutputFailed */,
4109
- message: `sealOutput polling timed out after ${SEAL_OUTPUT_TIMEOUT_MS}ms`,
4118
+ message: `sealOutput polling timed out after ${timeoutMs}ms`,
4110
4119
  hint: "The request may still be processing. Try again later.",
4111
4120
  context: {
4112
4121
  thresholdNetworkUrl,
4113
4122
  requestId,
4114
- timeoutMs: SEAL_OUTPUT_TIMEOUT_MS
4123
+ timeoutMs
4115
4124
  }
4116
4125
  });
4117
4126
  }
@@ -4199,6 +4208,7 @@ async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStart
4199
4208
  }
4200
4209
  async function tnSealOutputV2(params) {
4201
4210
  const { thresholdNetworkUrl, ctHash, chainId, acp, retry404TimeoutMs, onPoll } = params;
4211
+ const timeoutMs = params.timeoutMs ?? DEFAULT_DECRYPT_TIMEOUT_MS;
4202
4212
  const normalized404RetryTimeoutMs = normalize404RetryTimeoutMs({
4203
4213
  timeoutMs: retry404TimeoutMs,
4204
4214
  operationLabel: "sealOutput",
@@ -4212,12 +4222,13 @@ async function tnSealOutputV2(params) {
4212
4222
  acp,
4213
4223
  overallStartTime,
4214
4224
  normalized404RetryTimeoutMs,
4225
+ timeoutMs,
4215
4226
  onPoll
4216
4227
  );
4217
4228
  if (submitResult.kind === "completed") {
4218
4229
  return submitResult.sealed;
4219
4230
  }
4220
- return await pollSealOutputStatus(thresholdNetworkUrl, submitResult.requestId, overallStartTime, onPoll);
4231
+ return await pollSealOutputStatus(thresholdNetworkUrl, submitResult.requestId, overallStartTime, timeoutMs, onPoll);
4221
4232
  }
4222
4233
 
4223
4234
  // core/decrypt/decryptForViewBuilder.ts
@@ -4229,6 +4240,7 @@ var DecryptForViewBuilder = class extends BaseBuilder {
4229
4240
  acp;
4230
4241
  pollCallback;
4231
4242
  retry404TimeoutMs = DEFAULT_404_RETRY_TIMEOUT_MS2;
4243
+ timeoutMs;
4232
4244
  constructor(params) {
4233
4245
  super({
4234
4246
  config: params.config,
@@ -4302,6 +4314,16 @@ var DecryptForViewBuilder = class extends BaseBuilder {
4302
4314
  this.retry404TimeoutMs = timeoutMs;
4303
4315
  return this;
4304
4316
  }
4317
+ /**
4318
+ * The whole budget of this decrypt in milliseconds, submit retries and status polling together
4319
+ * (5 minutes by default). Past it, `execute()` rejects with `SealOutputFailed`; a request still
4320
+ * processing on the threshold network is not cancelled.
4321
+ */
4322
+ setTimeout(timeoutMs) {
4323
+ assertDecryptTimeoutMs(timeoutMs, "decryptForView");
4324
+ this.timeoutMs = timeoutMs;
4325
+ return this;
4326
+ }
4305
4327
  withACP(acpOrACPHash) {
4306
4328
  if (typeof acpOrACPHash === "string") {
4307
4329
  this.acpHash = acpOrACPHash;
@@ -4431,6 +4453,7 @@ var DecryptForViewBuilder = class extends BaseBuilder {
4431
4453
  acp: wireAcp,
4432
4454
  thresholdNetworkUrl,
4433
4455
  retry404TimeoutMs: this.retry404TimeoutMs,
4456
+ timeoutMs: this.timeoutMs,
4434
4457
  onPoll: this.pollCallback
4435
4458
  });
4436
4459
  return ACPUtils.unseal(acp, sealed);
@@ -4533,7 +4556,6 @@ async function cofheMocksDecryptForTx(ctHash, utype, acp, publicClient) {
4533
4556
  // core/decrypt/tnDecryptV2.ts
4534
4557
  var POLL_INTERVAL_MS2 = 1e3;
4535
4558
  var POLL_MAX_INTERVAL_MS2 = 1e4;
4536
- var DECRYPT_TIMEOUT_MS = 5 * 60 * 1e3;
4537
4559
  var SUBMIT_RETRY_INTERVAL_MS2 = 1e3;
4538
4560
  function assertDecryptSubmitResponseV2(value) {
4539
4561
  if (value == null || typeof value !== "object") {
@@ -4650,7 +4672,7 @@ function assertDecryptStatusResponseV2(value) {
4650
4672
  }
4651
4673
  return value;
4652
4674
  }
4653
- async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, acp, overallStartTime, retry404TimeoutMs, onPoll) {
4675
+ async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, acp, overallStartTime, retry404TimeoutMs, timeoutMs, onPoll) {
4654
4676
  const body = {
4655
4677
  ct_tempkey: BigInt(ctHash).toString(16).padStart(64, "0"),
4656
4678
  host_chain_id: chainId
@@ -4757,7 +4779,7 @@ async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, acp,
4757
4779
  status: responseClassification.status,
4758
4780
  elapsedMs,
4759
4781
  retry404TimeoutMs,
4760
- overallTimeoutMs: DECRYPT_TIMEOUT_MS,
4782
+ overallTimeoutMs: timeoutMs,
4761
4783
  thresholdNetworkUrl,
4762
4784
  body,
4763
4785
  attemptIndex,
@@ -4769,13 +4791,13 @@ async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, acp,
4769
4791
  attemptIndex,
4770
4792
  elapsedMs,
4771
4793
  intervalMs: SUBMIT_RETRY_INTERVAL_MS2,
4772
- timeoutMs: DECRYPT_TIMEOUT_MS
4794
+ timeoutMs
4773
4795
  });
4774
4796
  await new Promise((resolve) => setTimeout(resolve, SUBMIT_RETRY_INTERVAL_MS2));
4775
4797
  attemptIndex += 1;
4776
4798
  }
4777
4799
  }
4778
- async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartTime, onPoll) {
4800
+ async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartTime, timeoutMs, onPoll) {
4779
4801
  let attemptIndex = 0;
4780
4802
  while (true) {
4781
4803
  const elapsedMs = Date.now() - overallStartTime;
@@ -4789,17 +4811,17 @@ async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartT
4789
4811
  attemptIndex,
4790
4812
  elapsedMs,
4791
4813
  intervalMs,
4792
- timeoutMs: DECRYPT_TIMEOUT_MS
4814
+ timeoutMs
4793
4815
  });
4794
- if (elapsedMs > DECRYPT_TIMEOUT_MS) {
4816
+ if (elapsedMs > timeoutMs) {
4795
4817
  throw new CofheError({
4796
4818
  code: "DECRYPT_FAILED" /* DecryptFailed */,
4797
- message: `decrypt polling timed out after ${DECRYPT_TIMEOUT_MS}ms`,
4819
+ message: `decrypt polling timed out after ${timeoutMs}ms`,
4798
4820
  hint: "The request may still be processing. Try again later.",
4799
4821
  context: {
4800
4822
  thresholdNetworkUrl,
4801
4823
  requestId,
4802
- timeoutMs: DECRYPT_TIMEOUT_MS
4824
+ timeoutMs
4803
4825
  }
4804
4826
  });
4805
4827
  }
@@ -4888,6 +4910,7 @@ async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartT
4888
4910
  }
4889
4911
  async function tnDecryptV2(params) {
4890
4912
  const { thresholdNetworkUrl, ctHash, chainId, acp, retry404TimeoutMs, onPoll } = params;
4913
+ const timeoutMs = params.timeoutMs ?? DEFAULT_DECRYPT_TIMEOUT_MS;
4891
4914
  const normalized404RetryTimeoutMs = normalize404RetryTimeoutMs({
4892
4915
  timeoutMs: retry404TimeoutMs,
4893
4916
  operationLabel: "decrypt",
@@ -4901,12 +4924,13 @@ async function tnDecryptV2(params) {
4901
4924
  acp,
4902
4925
  overallStartTime,
4903
4926
  normalized404RetryTimeoutMs,
4927
+ timeoutMs,
4904
4928
  onPoll
4905
4929
  );
4906
4930
  if (submitResult.kind === "completed") {
4907
4931
  return submitResult;
4908
4932
  }
4909
- return await pollDecryptStatusV2(thresholdNetworkUrl, submitResult.requestId, overallStartTime, onPoll);
4933
+ return await pollDecryptStatusV2(thresholdNetworkUrl, submitResult.requestId, overallStartTime, timeoutMs, onPoll);
4910
4934
  }
4911
4935
 
4912
4936
  // core/decrypt/decryptForTxBuilder.ts
@@ -4918,6 +4942,7 @@ var DecryptForTxBuilder = class extends BaseBuilder {
4918
4942
  acpSelection = "unset";
4919
4943
  pollCallback;
4920
4944
  retry404TimeoutMs = DEFAULT_404_RETRY_TIMEOUT_MS3;
4945
+ timeoutMs;
4921
4946
  constructor(params) {
4922
4947
  super({
4923
4948
  config: params.config,
@@ -4960,6 +4985,11 @@ var DecryptForTxBuilder = class extends BaseBuilder {
4960
4985
  this.retry404TimeoutMs = timeoutMs;
4961
4986
  return this;
4962
4987
  }
4988
+ setTimeout(timeoutMs) {
4989
+ assertDecryptTimeoutMs(timeoutMs, "decryptForTx");
4990
+ this.timeoutMs = timeoutMs;
4991
+ return this;
4992
+ }
4963
4993
  withACP(acpOrACPHash) {
4964
4994
  if (this.acpSelection === "with-acp") {
4965
4995
  throw new CofheError({
@@ -5093,6 +5123,7 @@ var DecryptForTxBuilder = class extends BaseBuilder {
5093
5123
  acp: wireAcp,
5094
5124
  thresholdNetworkUrl,
5095
5125
  retry404TimeoutMs: this.retry404TimeoutMs,
5126
+ timeoutMs: this.timeoutMs,
5096
5127
  onPoll: this.pollCallback
5097
5128
  });
5098
5129
  return {
package/dist/node.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as CofheInputConfig, a as CofheConfig, b as CofheClient } from './clientTypes-RXwLVWou.cjs';
1
+ import { C as CofheInputConfig, a as CofheConfig, b as CofheClient } from './clientTypes-D2djRDoH.cjs';
2
2
  import 'viem';
3
3
  import './types-C07FK-cL.cjs';
4
4
  import 'zod';
package/dist/node.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as CofheInputConfig, a as CofheConfig, b as CofheClient } from './clientTypes-CnslFzxB.js';
1
+ import { C as CofheInputConfig, a as CofheConfig, b as CofheClient } from './clientTypes-B-qOZCx0.js';
2
2
  import 'viem';
3
3
  import './types-C07FK-cL.js';
4
4
  import 'zod';
package/dist/node.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createCofheConfigBase, createCofheClientBase } from './chunk-2EO4JSR7.js';
1
+ import { createCofheConfigBase, createCofheClientBase } from './chunk-VE7DKXSF.js';
2
2
  import './chunk-UKQAJK4N.js';
3
3
  import './chunk-3L2IVPMI.js';
4
4
  import { fromHexString } from './chunk-WJGTPW7K.js';