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

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.
@@ -1,9 +1,9 @@
1
1
  import { hardhat as hardhat$1 } from './chunk-UKQAJK4N.js';
2
- import { acpStore, clearAclServedAddresses, getAclServedAddresses, computeShareId, ACP_SHARE_REGISTRY_ABI, ACPUtils, getTaskManagerAddress, verifyShareLabels, decodeShareMetadata, shareAppKey, readShare, readSharesFor, toChainShare, ACP_REVOKER_ABI, decodeShareAppKey, encodeShareMetadata } from './chunk-3L2IVPMI.js';
3
- import { sleep, getPublicClientChainID, getWalletClientAccount, validateBigIntInRange, toBigIntOrThrow, hexToBytes, toHexString, FheUintUTypes } from './chunk-WJGTPW7K.js';
4
- import { TFHE_RS_KEY_VERSION, CofheError, TFHE_RS_ZK_MAX_BITS, TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT, MOCKS_THRESHOLD_NETWORK_ADDRESS, MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY, MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY, MOCKS_ZK_VERIFIER_ADDRESS } from './chunk-J23FYAI2.js';
2
+ import { acpStore, clearAclServedAddresses, getAclServedAddresses, computeShareId, ACP_SHARE_REGISTRY_ABI, ACPUtils, getTaskManagerAddress, verifyShareLabels, decodeShareMetadata, shareAppKey, readShare, readSharesFor, toChainShare, ACP_REVOKER_ABI, decodeShareAppKey, encodeShareMetadata } from './chunk-WAA2U7CT.js';
3
+ import { sleep, getPublicClientChainID, getWalletClientAccount, validateBigIntInRange, toBigIntOrThrow, hexToBytes, toHexString, FheUintUTypes } from './chunk-3SD2UCRE.js';
4
+ import { TFHE_RS_KEY_VERSION, CofheError, TFHE_RS_ZK_MAX_BITS, TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT, MOCKS_THRESHOLD_NETWORK_ADDRESS, MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY, MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY, MOCKS_ZK_VERIFIER_ADDRESS } from './chunk-OC5TGQGG.js';
5
5
  import { createStore } from 'zustand/vanilla';
6
- import { parseAbi, isAddressEqual, zeroAddress, recoverAddress, encodePacked, keccak256, createWalletClient, http, getAddress, parseSignature, serializeSignature } from 'viem';
6
+ import { parseAbi, isAddress, isAddressEqual, zeroAddress, recoverAddress, encodePacked, keccak256, createWalletClient, http, getAddress, parseSignature, serializeSignature } from 'viem';
7
7
  import { hardhat } from 'viem/chains';
8
8
  import { sign, privateKeyToAccount } from 'viem/accounts';
9
9
  import { z } from 'zod';
@@ -110,19 +110,22 @@ var zkProve = async (builder, crs, metadata) => {
110
110
  }, 0);
111
111
  });
112
112
  };
113
- var constructZkPoKMetadata = (accountAddr, securityZone, chainId) => {
113
+ var constructZkPoKMetadata = (accountAddr, securityZone, chainId, consumingContract) => {
114
114
  const accountAddrNoPrefix = accountAddr.startsWith("0x") ? accountAddr.slice(2) : accountAddr;
115
115
  const accountBytes = hexToBytes(accountAddrNoPrefix);
116
+ const contractNoPrefix = consumingContract.startsWith("0x") ? consumingContract.slice(2) : consumingContract;
117
+ const contractBytes = hexToBytes(contractNoPrefix);
116
118
  const chainIdBytes = new Uint8Array(32);
117
119
  let value = chainId;
118
120
  for (let i = 31; i >= 0 && value > 0; i--) {
119
121
  chainIdBytes[i] = value & 255;
120
122
  value = value >>> 8;
121
123
  }
122
- const metadata = new Uint8Array(1 + accountBytes.length + 32);
124
+ const metadata = new Uint8Array(1 + accountBytes.length + 32 + contractBytes.length);
123
125
  metadata[0] = securityZone;
124
126
  metadata.set(accountBytes, 1);
125
127
  metadata.set(chainIdBytes, 1 + accountBytes.length);
128
+ metadata.set(contractBytes, 1 + accountBytes.length + 32);
126
129
  return metadata;
127
130
  };
128
131
  var zkVerifyBatch = async (verifierUrl, serializedBytes, address, securityZone, chainId, consumingContract) => {
@@ -1002,20 +1005,33 @@ var EncryptInputsBuilder = class extends BaseBuilder {
1002
1005
  return this.consumingContract;
1003
1006
  }
1004
1007
  /**
1005
- * Asserts that this.consumingContract is populated
1006
- * @throws {CofheError} If consumingContract is not set
1008
+ * Asserts that this.consumingContract is populated and is an address.
1009
+ * Runs before TFHE init, key fetching and proving, so a bad address costs
1010
+ * nothing: the contract is bound into the proof, and a proof built for a
1011
+ * non-address could only fail at the verifier, after the expensive step.
1012
+ * @throws {CofheError} If consumingContract is not set or is not an address
1007
1013
  */
1008
1014
  assertConsumingContract() {
1009
- if (this.consumingContract)
1010
- return;
1011
- throw new CofheError({
1012
- code: "CONSUMING_CONTRACT_UNINITIALIZED" /* ConsumingContractUninitialized */,
1013
- message: "Consuming contract is not set",
1014
- hint: "Use setConsumingContract(...) to set the contract that will consume the encrypted inputs.",
1015
- context: {
1016
- consumingContract: this.consumingContract
1017
- }
1018
- });
1015
+ if (!this.consumingContract) {
1016
+ throw new CofheError({
1017
+ code: "CONSUMING_CONTRACT_UNINITIALIZED" /* ConsumingContractUninitialized */,
1018
+ message: "Consuming contract is not set",
1019
+ hint: "Use setConsumingContract(...) to set the contract that will consume the encrypted inputs.",
1020
+ context: {
1021
+ consumingContract: this.consumingContract
1022
+ }
1023
+ });
1024
+ }
1025
+ if (!isAddress(this.consumingContract, { strict: false })) {
1026
+ throw new CofheError({
1027
+ code: "CONSUMING_CONTRACT_INVALID" /* ConsumingContractInvalid */,
1028
+ message: "Consuming contract is not an address",
1029
+ hint: "setConsumingContract(...) takes the 20-byte address of the contract that will consume the encrypted inputs.",
1030
+ context: {
1031
+ consumingContract: this.consumingContract
1032
+ }
1033
+ });
1034
+ }
1019
1035
  }
1020
1036
  setUseWorker(useWorker) {
1021
1037
  this.useWorker = useWorker;
@@ -1231,7 +1247,7 @@ var EncryptInputsBuilder = class extends BaseBuilder {
1231
1247
  zkBuilder = zkPack(this.inputItems, zkBuilder);
1232
1248
  this.fireStepEnd("pack" /* Pack */);
1233
1249
  this.fireStepStart("prove" /* Prove */);
1234
- const metadata = constructZkPoKMetadata(this.account, this.securityZone, this.chainId);
1250
+ const metadata = constructZkPoKMetadata(this.account, this.securityZone, this.chainId, this.consumingContract);
1235
1251
  let proof = null;
1236
1252
  let usedWorker = false;
1237
1253
  let workerFailedError;
@@ -1929,6 +1945,16 @@ function mapApiErrorCodeToCofheErrorCode(apiErrorCode, fallback) {
1929
1945
 
1930
1946
  // core/decrypt/submitRetry.ts
1931
1947
  var DEFAULT_404_RETRY_TIMEOUT_MS = 1e4;
1948
+ var DEFAULT_DECRYPT_TIMEOUT_MS = 5 * 60 * 1e3;
1949
+ function assertDecryptTimeoutMs(timeoutMs, operationLabel) {
1950
+ if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
1951
+ throw new CofheError({
1952
+ code: "INTERNAL_ERROR" /* InternalError */,
1953
+ message: `${operationLabel}: setTimeout(timeoutMs) expects a finite number greater than 0.`,
1954
+ context: { timeoutMs }
1955
+ });
1956
+ }
1957
+ }
1932
1958
  function normalize404RetryTimeoutMs(params) {
1933
1959
  const { timeoutMs, operationLabel, errorCode } = params;
1934
1960
  if (timeoutMs === void 0)
@@ -2067,7 +2093,6 @@ function parseDecryptedBytesToBigInt(decrypted) {
2067
2093
  // core/decrypt/tnSealOutputV2.ts
2068
2094
  var POLL_INTERVAL_MS = 1e3;
2069
2095
  var POLL_MAX_INTERVAL_MS = 1e4;
2070
- var SEAL_OUTPUT_TIMEOUT_MS = 5 * 60 * 1e3;
2071
2096
  var SUBMIT_RETRY_INTERVAL_MS = 1e3;
2072
2097
  function numberArrayToUint8Array(arr) {
2073
2098
  return new Uint8Array(arr);
@@ -2125,7 +2150,7 @@ function parseCompletedSealOutputResponse(params) {
2125
2150
  }
2126
2151
  return convertSealedData(sealed);
2127
2152
  }
2128
- async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, acp, overallStartTime, retry404TimeoutMs, onPoll) {
2153
+ async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, acp, overallStartTime, retry404TimeoutMs, timeoutMs, onPoll) {
2129
2154
  const body = {
2130
2155
  ct_tempkey: BigInt(ctHash).toString(16).padStart(64, "0"),
2131
2156
  host_chain_id: chainId,
@@ -2228,7 +2253,7 @@ async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, acp
2228
2253
  status: responseClassification.status,
2229
2254
  elapsedMs,
2230
2255
  retry404TimeoutMs,
2231
- overallTimeoutMs: SEAL_OUTPUT_TIMEOUT_MS,
2256
+ overallTimeoutMs: timeoutMs,
2232
2257
  thresholdNetworkUrl,
2233
2258
  body,
2234
2259
  attemptIndex,
@@ -2240,13 +2265,13 @@ async function submitSealOutputRequest(thresholdNetworkUrl, ctHash, chainId, acp
2240
2265
  attemptIndex,
2241
2266
  elapsedMs,
2242
2267
  intervalMs: SUBMIT_RETRY_INTERVAL_MS,
2243
- timeoutMs: SEAL_OUTPUT_TIMEOUT_MS
2268
+ timeoutMs
2244
2269
  });
2245
2270
  await new Promise((resolve) => setTimeout(resolve, SUBMIT_RETRY_INTERVAL_MS));
2246
2271
  attemptIndex += 1;
2247
2272
  }
2248
2273
  }
2249
- async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStartTime, onPoll) {
2274
+ async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStartTime, timeoutMs, onPoll) {
2250
2275
  let attemptIndex = 0;
2251
2276
  while (true) {
2252
2277
  const elapsedMs = Date.now() - overallStartTime;
@@ -2260,17 +2285,17 @@ async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStart
2260
2285
  attemptIndex,
2261
2286
  elapsedMs,
2262
2287
  intervalMs,
2263
- timeoutMs: SEAL_OUTPUT_TIMEOUT_MS
2288
+ timeoutMs
2264
2289
  });
2265
- if (elapsedMs > SEAL_OUTPUT_TIMEOUT_MS) {
2290
+ if (elapsedMs > timeoutMs) {
2266
2291
  throw new CofheError({
2267
2292
  code: "SEAL_OUTPUT_FAILED" /* SealOutputFailed */,
2268
- message: `sealOutput polling timed out after ${SEAL_OUTPUT_TIMEOUT_MS}ms`,
2293
+ message: `sealOutput polling timed out after ${timeoutMs}ms`,
2269
2294
  hint: "The request may still be processing. Try again later.",
2270
2295
  context: {
2271
2296
  thresholdNetworkUrl,
2272
2297
  requestId,
2273
- timeoutMs: SEAL_OUTPUT_TIMEOUT_MS
2298
+ timeoutMs
2274
2299
  }
2275
2300
  });
2276
2301
  }
@@ -2358,6 +2383,7 @@ async function pollSealOutputStatus(thresholdNetworkUrl, requestId, overallStart
2358
2383
  }
2359
2384
  async function tnSealOutputV2(params) {
2360
2385
  const { thresholdNetworkUrl, ctHash, chainId, acp, retry404TimeoutMs, onPoll } = params;
2386
+ const timeoutMs = params.timeoutMs ?? DEFAULT_DECRYPT_TIMEOUT_MS;
2361
2387
  const normalized404RetryTimeoutMs = normalize404RetryTimeoutMs({
2362
2388
  timeoutMs: retry404TimeoutMs,
2363
2389
  operationLabel: "sealOutput",
@@ -2371,12 +2397,13 @@ async function tnSealOutputV2(params) {
2371
2397
  acp,
2372
2398
  overallStartTime,
2373
2399
  normalized404RetryTimeoutMs,
2400
+ timeoutMs,
2374
2401
  onPoll
2375
2402
  );
2376
2403
  if (submitResult.kind === "completed") {
2377
2404
  return submitResult.sealed;
2378
2405
  }
2379
- return await pollSealOutputStatus(thresholdNetworkUrl, submitResult.requestId, overallStartTime, onPoll);
2406
+ return await pollSealOutputStatus(thresholdNetworkUrl, submitResult.requestId, overallStartTime, timeoutMs, onPoll);
2380
2407
  }
2381
2408
 
2382
2409
  // core/decrypt/decryptForViewBuilder.ts
@@ -2388,6 +2415,7 @@ var DecryptForViewBuilder = class extends BaseBuilder {
2388
2415
  acp;
2389
2416
  pollCallback;
2390
2417
  retry404TimeoutMs = DEFAULT_404_RETRY_TIMEOUT_MS2;
2418
+ timeoutMs;
2391
2419
  constructor(params) {
2392
2420
  super({
2393
2421
  config: params.config,
@@ -2461,6 +2489,16 @@ var DecryptForViewBuilder = class extends BaseBuilder {
2461
2489
  this.retry404TimeoutMs = timeoutMs;
2462
2490
  return this;
2463
2491
  }
2492
+ /**
2493
+ * The whole budget of this decrypt in milliseconds, submit retries and status polling together
2494
+ * (5 minutes by default). Past it, `execute()` rejects with `SealOutputFailed`; a request still
2495
+ * processing on the threshold network is not cancelled.
2496
+ */
2497
+ setTimeout(timeoutMs) {
2498
+ assertDecryptTimeoutMs(timeoutMs, "decryptForView");
2499
+ this.timeoutMs = timeoutMs;
2500
+ return this;
2501
+ }
2464
2502
  withACP(acpOrACPHash) {
2465
2503
  if (typeof acpOrACPHash === "string") {
2466
2504
  this.acpHash = acpOrACPHash;
@@ -2590,6 +2628,7 @@ var DecryptForViewBuilder = class extends BaseBuilder {
2590
2628
  acp: wireAcp,
2591
2629
  thresholdNetworkUrl,
2592
2630
  retry404TimeoutMs: this.retry404TimeoutMs,
2631
+ timeoutMs: this.timeoutMs,
2593
2632
  onPoll: this.pollCallback
2594
2633
  });
2595
2634
  return ACPUtils.unseal(acp, sealed);
@@ -2692,7 +2731,6 @@ async function cofheMocksDecryptForTx(ctHash, utype, acp, publicClient) {
2692
2731
  // core/decrypt/tnDecryptV2.ts
2693
2732
  var POLL_INTERVAL_MS2 = 1e3;
2694
2733
  var POLL_MAX_INTERVAL_MS2 = 1e4;
2695
- var DECRYPT_TIMEOUT_MS = 5 * 60 * 1e3;
2696
2734
  var SUBMIT_RETRY_INTERVAL_MS2 = 1e3;
2697
2735
  function assertDecryptSubmitResponseV2(value) {
2698
2736
  if (value == null || typeof value !== "object") {
@@ -2809,7 +2847,7 @@ function assertDecryptStatusResponseV2(value) {
2809
2847
  }
2810
2848
  return value;
2811
2849
  }
2812
- async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, acp, overallStartTime, retry404TimeoutMs, onPoll) {
2850
+ async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, acp, overallStartTime, retry404TimeoutMs, timeoutMs, onPoll) {
2813
2851
  const body = {
2814
2852
  ct_tempkey: BigInt(ctHash).toString(16).padStart(64, "0"),
2815
2853
  host_chain_id: chainId
@@ -2916,7 +2954,7 @@ async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, acp,
2916
2954
  status: responseClassification.status,
2917
2955
  elapsedMs,
2918
2956
  retry404TimeoutMs,
2919
- overallTimeoutMs: DECRYPT_TIMEOUT_MS,
2957
+ overallTimeoutMs: timeoutMs,
2920
2958
  thresholdNetworkUrl,
2921
2959
  body,
2922
2960
  attemptIndex,
@@ -2928,13 +2966,13 @@ async function submitDecryptRequestV2(thresholdNetworkUrl, ctHash, chainId, acp,
2928
2966
  attemptIndex,
2929
2967
  elapsedMs,
2930
2968
  intervalMs: SUBMIT_RETRY_INTERVAL_MS2,
2931
- timeoutMs: DECRYPT_TIMEOUT_MS
2969
+ timeoutMs
2932
2970
  });
2933
2971
  await new Promise((resolve) => setTimeout(resolve, SUBMIT_RETRY_INTERVAL_MS2));
2934
2972
  attemptIndex += 1;
2935
2973
  }
2936
2974
  }
2937
- async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartTime, onPoll) {
2975
+ async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartTime, timeoutMs, onPoll) {
2938
2976
  let attemptIndex = 0;
2939
2977
  while (true) {
2940
2978
  const elapsedMs = Date.now() - overallStartTime;
@@ -2948,17 +2986,17 @@ async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartT
2948
2986
  attemptIndex,
2949
2987
  elapsedMs,
2950
2988
  intervalMs,
2951
- timeoutMs: DECRYPT_TIMEOUT_MS
2989
+ timeoutMs
2952
2990
  });
2953
- if (elapsedMs > DECRYPT_TIMEOUT_MS) {
2991
+ if (elapsedMs > timeoutMs) {
2954
2992
  throw new CofheError({
2955
2993
  code: "DECRYPT_FAILED" /* DecryptFailed */,
2956
- message: `decrypt polling timed out after ${DECRYPT_TIMEOUT_MS}ms`,
2994
+ message: `decrypt polling timed out after ${timeoutMs}ms`,
2957
2995
  hint: "The request may still be processing. Try again later.",
2958
2996
  context: {
2959
2997
  thresholdNetworkUrl,
2960
2998
  requestId,
2961
- timeoutMs: DECRYPT_TIMEOUT_MS
2999
+ timeoutMs
2962
3000
  }
2963
3001
  });
2964
3002
  }
@@ -3047,6 +3085,7 @@ async function pollDecryptStatusV2(thresholdNetworkUrl, requestId, overallStartT
3047
3085
  }
3048
3086
  async function tnDecryptV2(params) {
3049
3087
  const { thresholdNetworkUrl, ctHash, chainId, acp, retry404TimeoutMs, onPoll } = params;
3088
+ const timeoutMs = params.timeoutMs ?? DEFAULT_DECRYPT_TIMEOUT_MS;
3050
3089
  const normalized404RetryTimeoutMs = normalize404RetryTimeoutMs({
3051
3090
  timeoutMs: retry404TimeoutMs,
3052
3091
  operationLabel: "decrypt",
@@ -3060,12 +3099,13 @@ async function tnDecryptV2(params) {
3060
3099
  acp,
3061
3100
  overallStartTime,
3062
3101
  normalized404RetryTimeoutMs,
3102
+ timeoutMs,
3063
3103
  onPoll
3064
3104
  );
3065
3105
  if (submitResult.kind === "completed") {
3066
3106
  return submitResult;
3067
3107
  }
3068
- return await pollDecryptStatusV2(thresholdNetworkUrl, submitResult.requestId, overallStartTime, onPoll);
3108
+ return await pollDecryptStatusV2(thresholdNetworkUrl, submitResult.requestId, overallStartTime, timeoutMs, onPoll);
3069
3109
  }
3070
3110
 
3071
3111
  // core/decrypt/decryptForTxBuilder.ts
@@ -3077,6 +3117,7 @@ var DecryptForTxBuilder = class extends BaseBuilder {
3077
3117
  acpSelection = "unset";
3078
3118
  pollCallback;
3079
3119
  retry404TimeoutMs = DEFAULT_404_RETRY_TIMEOUT_MS3;
3120
+ timeoutMs;
3080
3121
  constructor(params) {
3081
3122
  super({
3082
3123
  config: params.config,
@@ -3119,6 +3160,11 @@ var DecryptForTxBuilder = class extends BaseBuilder {
3119
3160
  this.retry404TimeoutMs = timeoutMs;
3120
3161
  return this;
3121
3162
  }
3163
+ setTimeout(timeoutMs) {
3164
+ assertDecryptTimeoutMs(timeoutMs, "decryptForTx");
3165
+ this.timeoutMs = timeoutMs;
3166
+ return this;
3167
+ }
3122
3168
  withACP(acpOrACPHash) {
3123
3169
  if (this.acpSelection === "with-acp") {
3124
3170
  throw new CofheError({
@@ -3252,6 +3298,7 @@ var DecryptForTxBuilder = class extends BaseBuilder {
3252
3298
  acp: wireAcp,
3253
3299
  thresholdNetworkUrl,
3254
3300
  retry404TimeoutMs: this.retry404TimeoutMs,
3301
+ timeoutMs: this.timeoutMs,
3255
3302
  onPoll: this.pollCallback
3256
3303
  });
3257
3304
  return {
@@ -17,6 +17,7 @@ var CofheErrorCode = /* @__PURE__ */ ((CofheErrorCode2) => {
17
17
  CofheErrorCode2["AccountUninitialized"] = "ACCOUNT_UNINITIALIZED";
18
18
  CofheErrorCode2["ChainIdUninitialized"] = "CHAIN_ID_UNINITIALIZED";
19
19
  CofheErrorCode2["ConsumingContractUninitialized"] = "CONSUMING_CONTRACT_UNINITIALIZED";
20
+ CofheErrorCode2["ConsumingContractInvalid"] = "CONSUMING_CONTRACT_INVALID";
20
21
  CofheErrorCode2["SealOutputFailed"] = "SEAL_OUTPUT_FAILED";
21
22
  CofheErrorCode2["SealOutputReturnedNull"] = "SEAL_OUTPUT_RETURNED_NULL";
22
23
  CofheErrorCode2["InvalidUtype"] = "INVALID_UTYPE";
@@ -1,4 +1,4 @@
1
- import { CofheError, TASK_MANAGER_ID, COFHE_ADDRESS_BOOK_ADDRESS } from './chunk-J23FYAI2.js';
1
+ import { CofheError, TASK_MANAGER_ID, COFHE_ADDRESS_BOOK_ADDRESS } from './chunk-OC5TGQGG.js';
2
2
  import { isAddress, getAddress, zeroAddress, isHex, parseAbi, keccak256, padHex, numberToHex, concatHex, toFunctionSelector, size, sliceHex, toHex, encodeAbiParameters, hexToBigInt, stringToHex, hexToNumber, toEventSignature, toFunctionSignature, decodeErrorResult, toEventSelector, decodeAbiParameters } from 'viem';
3
3
  import nacl from 'tweetnacl';
4
4
  import { z } from 'zod';
@@ -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
  *
@@ -896,8 +911,11 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
896
911
  setConsumingContract(address: string): EncryptInputsBuilder<T>;
897
912
  getConsumingContract(): string | undefined;
898
913
  /**
899
- * Asserts that this.consumingContract is populated
900
- * @throws {CofheError} If consumingContract is not set
914
+ * Asserts that this.consumingContract is populated and is an address.
915
+ * Runs before TFHE init, key fetching and proving, so a bad address costs
916
+ * nothing: the contract is bound into the proof, and a proof built for a
917
+ * non-address could only fail at the verifier, after the expensive step.
918
+ * @throws {CofheError} If consumingContract is not set or is not an address
901
919
  */
902
920
  private assertConsumingContract;
903
921
  /**
@@ -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
  *
@@ -896,8 +911,11 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
896
911
  setConsumingContract(address: string): EncryptInputsBuilder<T>;
897
912
  getConsumingContract(): string | undefined;
898
913
  /**
899
- * Asserts that this.consumingContract is populated
900
- * @throws {CofheError} If consumingContract is not set
914
+ * Asserts that this.consumingContract is populated and is an address.
915
+ * Runs before TFHE init, key fetching and proving, so a bad address costs
916
+ * nothing: the contract is bound into the proof, and a proof built for a
917
+ * non-address could only fail at the verifier, after the expensive step.
918
+ * @throws {CofheError} If consumingContract is not set or is not an address
901
919
  */
902
920
  private assertConsumingContract;
903
921
  /**