@cofhe/sdk 1.0.1 → 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.
Files changed (41) hide show
  1. package/CHANGELOG.md +0 -8
  2. package/core/acps.ts +64 -23
  3. package/core/client.ts +32 -1
  4. package/core/clientTypes.ts +22 -1
  5. package/core/decrypt/decryptForTxBuilder.ts +16 -0
  6. package/core/decrypt/decryptForViewBuilder.ts +14 -0
  7. package/core/decrypt/submitRetry.ts +16 -0
  8. package/core/decrypt/tnDecryptV2.ts +19 -9
  9. package/core/decrypt/tnSealOutputV2.ts +19 -9
  10. package/core/encrypt/encryptInputsBuilder.ts +13 -31
  11. package/core/encrypt/zkPackProveVerify.ts +4 -16
  12. package/core/error.ts +0 -1
  13. package/core/test/acpsPrepare.test.ts +77 -0
  14. package/core/test/decryptBuilders.test.ts +51 -0
  15. package/core/test/encryptInputsBuilder.test.ts +4 -56
  16. package/dist/acps.d.cts +4 -358
  17. package/dist/acps.d.ts +4 -358
  18. package/dist/acps.js +2 -2
  19. package/dist/{chunk-WAA2U7CT.js → chunk-3L2IVPMI.js} +1 -1
  20. package/dist/{chunk-OC5TGQGG.js → chunk-J23FYAI2.js} +0 -1
  21. package/dist/{chunk-GKEJHZ52.js → chunk-VE7DKXSF.js} +132 -75
  22. package/dist/{chunk-3SD2UCRE.js → chunk-WJGTPW7K.js} +1 -1
  23. package/dist/{clientTypes-DEKYh0cw.d.ts → clientTypes-B-qOZCx0.d.ts} +55 -7
  24. package/dist/{clientTypes-C2b_qub5.d.cts → clientTypes-D2djRDoH.d.cts} +55 -7
  25. package/dist/core.cjs +128 -72
  26. package/dist/core.d.cts +3 -4
  27. package/dist/core.d.ts +3 -4
  28. package/dist/core.js +4 -4
  29. package/dist/node.cjs +128 -71
  30. package/dist/node.d.cts +2 -2
  31. package/dist/node.d.ts +2 -2
  32. package/dist/node.js +4 -4
  33. package/dist/{onchain-utils-CgOslubH.d.ts → onchain-utils-Ns56cBm0.d.cts} +356 -2
  34. package/dist/{onchain-utils-CgOslubH.d.cts → onchain-utils-Ns56cBm0.d.ts} +356 -2
  35. package/dist/web.cjs +128 -71
  36. package/dist/web.d.cts +2 -2
  37. package/dist/web.d.ts +2 -2
  38. package/dist/web.js +4 -4
  39. package/dist/zkProve.worker.js +2 -2
  40. package/package.json +1 -1
  41. package/core/test/zkPoKMetadata.test.ts +0 -27
package/dist/core.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { a as CofheConfig, c as CofheClientParams, b as CofheClient, d as CofheClientConnectionState, F as FheTypes } from './clientTypes-DEKYh0cw.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-DEKYh0cw.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';
6
- import './onchain-utils-CgOslubH.js';
6
+ import './onchain-utils-Ns56cBm0.js';
7
7
  import 'zustand/vanilla';
8
8
 
9
9
  declare const InitialConnectStore: CofheClientConnectionState;
@@ -55,7 +55,6 @@ declare enum CofheErrorCode {
55
55
  AccountUninitialized = "ACCOUNT_UNINITIALIZED",
56
56
  ChainIdUninitialized = "CHAIN_ID_UNINITIALIZED",
57
57
  ConsumingContractUninitialized = "CONSUMING_CONTRACT_UNINITIALIZED",
58
- ConsumingContractInvalid = "CONSUMING_CONTRACT_INVALID",
59
58
  SealOutputFailed = "SEAL_OUTPUT_FAILED",
60
59
  SealOutputReturnedNull = "SEAL_OUTPUT_RETURNED_NULL",
61
60
  InvalidUtype = "INVALID_UTYPE",
package/dist/core.js CHANGED
@@ -1,5 +1,5 @@
1
- export { InitialConnectStore as CONNECT_STORE_DEFAULTS, DecryptForTxBuilder, DecryptForViewBuilder, EncryptInputsBuilder, assertNoRenamedConfigKeys, cofheFetch, createCofheClientBase, createCofheConfigBase, createKeysStore, fetchKeys, getCofheConfigItem, getCofheDebugInterceptors, setCofheDebugInterceptors, verifyDecryptResult, zkProveWithWorker } from './chunk-GKEJHZ52.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
- export { getTaskManagerAddress } from './chunk-WAA2U7CT.js';
4
- export { EncryptStep, Encryptable, FheAllUTypes, FheTypes, FheUintUTypes, fheTypeToString, isEncryptableItem, isLastEncryptionStep } from './chunk-3SD2UCRE.js';
5
- export { COFHE_ADDRESS_BOOK_ADDRESS, CofheError, CofheErrorCode, MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY, MOCKS_TASK_MANAGER_ADDRESS, MOCKS_THRESHOLD_NETWORK_ADDRESS, MOCKS_ZK_VERIFIER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY, TASK_MANAGER_ID, TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT, TFHE_RS_ZK_MAX_BITS, isCofheError } from './chunk-OC5TGQGG.js';
3
+ export { getTaskManagerAddress } from './chunk-3L2IVPMI.js';
4
+ export { EncryptStep, Encryptable, FheAllUTypes, FheTypes, FheUintUTypes, fheTypeToString, isEncryptableItem, isLastEncryptionStep } from './chunk-WJGTPW7K.js';
5
+ export { COFHE_ADDRESS_BOOK_ADDRESS, CofheError, CofheErrorCode, MOCKS_DECRYPT_RESULT_SIGNER_PRIVATE_KEY, MOCKS_TASK_MANAGER_ADDRESS, MOCKS_THRESHOLD_NETWORK_ADDRESS, MOCKS_ZK_VERIFIER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY, TASK_MANAGER_ID, TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT, TFHE_RS_ZK_MAX_BITS, isCofheError } from './chunk-J23FYAI2.js';
package/dist/node.cjs CHANGED
@@ -1925,22 +1925,19 @@ var zkProve = async (builder, crs, metadata) => {
1925
1925
  }, 0);
1926
1926
  });
1927
1927
  };
1928
- var constructZkPoKMetadata = (accountAddr, securityZone, chainId, consumingContract) => {
1928
+ var constructZkPoKMetadata = (accountAddr, securityZone, chainId) => {
1929
1929
  const accountAddrNoPrefix = accountAddr.startsWith("0x") ? accountAddr.slice(2) : accountAddr;
1930
1930
  const accountBytes = hexToBytes(accountAddrNoPrefix);
1931
- const contractNoPrefix = consumingContract.startsWith("0x") ? consumingContract.slice(2) : consumingContract;
1932
- const contractBytes = hexToBytes(contractNoPrefix);
1933
1931
  const chainIdBytes = new Uint8Array(32);
1934
1932
  let value = chainId;
1935
1933
  for (let i = 31; i >= 0 && value > 0; i--) {
1936
1934
  chainIdBytes[i] = value & 255;
1937
1935
  value = value >>> 8;
1938
1936
  }
1939
- const metadata = new Uint8Array(1 + accountBytes.length + 32 + contractBytes.length);
1937
+ const metadata = new Uint8Array(1 + accountBytes.length + 32);
1940
1938
  metadata[0] = securityZone;
1941
1939
  metadata.set(accountBytes, 1);
1942
1940
  metadata.set(chainIdBytes, 1 + accountBytes.length);
1943
- metadata.set(contractBytes, 1 + accountBytes.length + 32);
1944
1941
  return metadata;
1945
1942
  };
1946
1943
  var zkVerifyBatch = async (verifierUrl, serializedBytes, address, securityZone, chainId, consumingContract) => {
@@ -2853,33 +2850,20 @@ var EncryptInputsBuilder = class extends BaseBuilder {
2853
2850
  return this.consumingContract;
2854
2851
  }
2855
2852
  /**
2856
- * Asserts that this.consumingContract is populated and is an address.
2857
- * Runs before TFHE init, key fetching and proving, so a bad address costs
2858
- * nothing: the contract is bound into the proof, and a proof built for a
2859
- * non-address could only fail at the verifier, after the expensive step.
2860
- * @throws {CofheError} If consumingContract is not set or is not an address
2853
+ * Asserts that this.consumingContract is populated
2854
+ * @throws {CofheError} If consumingContract is not set
2861
2855
  */
2862
2856
  assertConsumingContract() {
2863
- if (!this.consumingContract) {
2864
- throw new CofheError({
2865
- code: "CONSUMING_CONTRACT_UNINITIALIZED" /* ConsumingContractUninitialized */,
2866
- message: "Consuming contract is not set",
2867
- hint: "Use setConsumingContract(...) to set the contract that will consume the encrypted inputs.",
2868
- context: {
2869
- consumingContract: this.consumingContract
2870
- }
2871
- });
2872
- }
2873
- if (!viem.isAddress(this.consumingContract, { strict: false })) {
2874
- throw new CofheError({
2875
- code: "CONSUMING_CONTRACT_INVALID" /* ConsumingContractInvalid */,
2876
- message: "Consuming contract is not an address",
2877
- hint: "setConsumingContract(...) takes the 20-byte address of the contract that will consume the encrypted inputs.",
2878
- context: {
2879
- consumingContract: this.consumingContract
2880
- }
2881
- });
2882
- }
2857
+ if (this.consumingContract)
2858
+ return;
2859
+ throw new CofheError({
2860
+ code: "CONSUMING_CONTRACT_UNINITIALIZED" /* ConsumingContractUninitialized */,
2861
+ message: "Consuming contract is not set",
2862
+ hint: "Use setConsumingContract(...) to set the contract that will consume the encrypted inputs.",
2863
+ context: {
2864
+ consumingContract: this.consumingContract
2865
+ }
2866
+ });
2883
2867
  }
2884
2868
  setUseWorker(useWorker) {
2885
2869
  this.useWorker = useWorker;
@@ -3095,7 +3079,7 @@ var EncryptInputsBuilder = class extends BaseBuilder {
3095
3079
  zkBuilder = zkPack(this.inputItems, zkBuilder);
3096
3080
  this.fireStepEnd("pack" /* Pack */);
3097
3081
  this.fireStepStart("prove" /* Prove */);
3098
- const metadata = constructZkPoKMetadata(this.account, this.securityZone, this.chainId, this.consumingContract);
3082
+ const metadata = constructZkPoKMetadata(this.account, this.securityZone, this.chainId);
3099
3083
  let proof = null;
3100
3084
  let usedWorker = false;
3101
3085
  let workerFailedError;
@@ -3273,23 +3257,25 @@ var getBlockRevokerData = async (publicClient) => {
3273
3257
  }
3274
3258
  return revokerData;
3275
3259
  };
3276
- var revokeACP = async (acp, walletClient) => {
3260
+ var prepareRevokeACP = (acp) => {
3277
3261
  if (acp.revokerContract === viem.zeroAddress || acp.revokerData === 0) {
3278
3262
  throw new Error("ACP is not revocable: it has no revoker (revokerContract/revokerData unset)");
3279
3263
  }
3264
+ return {
3265
+ address: acp.revokerContract,
3266
+ abi: ACP_REVOKER_ABI,
3267
+ functionName: "revokeSingle",
3268
+ args: [BigInt(acp.revokerData)]
3269
+ };
3270
+ };
3271
+ var revokeACP = async (acp, walletClient) => {
3272
+ const write = prepareRevokeACP(acp);
3280
3273
  if (walletClient.account == null)
3281
3274
  throw new Error("Missing walletClient account");
3282
3275
  if (walletClient.account.address.toLowerCase() !== acp.issuer.toLowerCase()) {
3283
3276
  throw new Error("Only the acp issuer can revoke it");
3284
3277
  }
3285
- return walletClient.writeContract({
3286
- address: acp.revokerContract,
3287
- abi: ACP_REVOKER_ABI,
3288
- functionName: "revokeSingle",
3289
- args: [BigInt(acp.revokerData)],
3290
- account: walletClient.account,
3291
- chain: walletClient.chain
3292
- });
3278
+ return walletClient.writeContract({ ...write, account: walletClient.account, chain: walletClient.chain });
3293
3279
  };
3294
3280
  var revokeAllACPs = async (walletClient, publicClient, revokerContract) => {
3295
3281
  if (walletClient.account == null)
@@ -3340,28 +3326,36 @@ var metadataOf = (acp, { labels, metadata, appKey }) => {
3340
3326
  }
3341
3327
  return encodeShareMetadata(labels, { issuer: acp.issuer, appKey });
3342
3328
  };
3343
- var shareOnChain = async (acp, walletClient, registry, options = {}) => {
3329
+ var prepareShareOnChain = (acp, registry, options = {}) => {
3344
3330
  if (acp.type !== "sharing") {
3345
3331
  throw new Error(`Cannot share a '${acp.type}' ACP on-chain \u2014 only 'sharing' ACPs are shareable.`);
3346
3332
  }
3347
3333
  if (acp.issuerSignature === "0x") {
3348
3334
  throw new Error("Cannot share an unsigned sharing ACP \u2014 sign it first.");
3349
3335
  }
3336
+ return {
3337
+ write: {
3338
+ address: registry,
3339
+ abi: ACP_SHARE_REGISTRY_ABI,
3340
+ functionName: "share",
3341
+ args: [toChainShare(acp), metadataOf(acp, options)]
3342
+ },
3343
+ shareId: computeShareId(acp)
3344
+ };
3345
+ };
3346
+ var shareOnChain = async (acp, walletClient, registry, options = {}) => {
3347
+ const { write, shareId } = prepareShareOnChain(acp, registry, options);
3350
3348
  if (walletClient.account == null)
3351
3349
  throw new Error("Missing walletClient account");
3352
3350
  if (walletClient.account.address.toLowerCase() !== acp.issuer.toLowerCase()) {
3353
3351
  throw new Error("Only the ACP issuer can share it on-chain");
3354
3352
  }
3355
- const metadata = metadataOf(acp, options);
3356
3353
  const txHash = await walletClient.writeContract({
3357
- address: registry,
3358
- abi: ACP_SHARE_REGISTRY_ABI,
3359
- functionName: "share",
3360
- args: [toChainShare(acp), metadata],
3354
+ ...write,
3361
3355
  account: walletClient.account,
3362
3356
  chain: walletClient.chain ?? null
3363
3357
  });
3364
- return { txHash, shareId: computeShareId(acp) };
3358
+ return { txHash, shareId };
3365
3359
  };
3366
3360
  var toIncomingShare = ({ shareId, share: s, metadata }) => ({
3367
3361
  shareId,
@@ -3396,14 +3390,17 @@ var importFromChain = async (share, publicClient, walletClient, importOptions =
3396
3390
  const { shareId: _shareId, appKey: _appKey, ...options } = share;
3397
3391
  return importShared({ ...options, type: "sharing" }, publicClient, walletClient, importOptions);
3398
3392
  };
3393
+ var prepareRemoveShare = (shareId, registry) => ({
3394
+ address: registry,
3395
+ abi: ACP_SHARE_REGISTRY_ABI,
3396
+ functionName: "removeShare",
3397
+ args: [shareId]
3398
+ });
3399
3399
  var removeShareOnChain = async (shareId, walletClient, registry) => {
3400
3400
  if (walletClient.account == null)
3401
3401
  throw new Error("Missing walletClient account");
3402
3402
  return walletClient.writeContract({
3403
- address: registry,
3404
- abi: ACP_SHARE_REGISTRY_ABI,
3405
- functionName: "removeShare",
3406
- args: [shareId],
3403
+ ...prepareRemoveShare(shareId, registry),
3407
3404
  account: walletClient.account,
3408
3405
  chain: walletClient.chain ?? null
3409
3406
  });
@@ -3430,14 +3427,17 @@ var acps = {
3430
3427
  selectActiveACP,
3431
3428
  removeActiveACP,
3432
3429
  revokeACP,
3430
+ prepareRevokeACP,
3433
3431
  revokeAllACPs,
3434
3432
  isACPRevoked,
3435
3433
  checkAccess,
3436
3434
  shareOnChain,
3435
+ prepareShareOnChain,
3437
3436
  getIncomingShares,
3438
3437
  getShareFromChain,
3439
3438
  importFromChain,
3440
3439
  removeShareOnChain,
3440
+ prepareRemoveShare,
3441
3441
  computeShareId,
3442
3442
  applyACPDefaultsFromChain,
3443
3443
  getAclServedAddresses,
@@ -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 {
@@ -5213,6 +5244,12 @@ function createCofheClientBase(opts) {
5213
5244
  });
5214
5245
  }
5215
5246
  };
5247
+ const _requireIssuer = (acp, what) => {
5248
+ const sender = connectStore.getState().walletClient?.account?.address;
5249
+ if (sender == null || sender.toLowerCase() !== acp.issuer.toLowerCase()) {
5250
+ throw new Error(`Only the acp issuer can ${what}`);
5251
+ }
5252
+ };
5216
5253
  async function connect(publicClient, walletClient) {
5217
5254
  const state = connectStore.getState();
5218
5255
  if (state.connected && state.publicClient === publicClient && state.walletClient === walletClient)
@@ -5380,6 +5417,11 @@ function createCofheClientBase(opts) {
5380
5417
  const { walletClient } = connectStore.getState();
5381
5418
  return acps.revokeACP(acp, walletClient);
5382
5419
  },
5420
+ prepareRevokeACP: (acp) => {
5421
+ _requireConnected();
5422
+ _requireIssuer(acp, "revoke it");
5423
+ return acps.prepareRevokeACP(acp);
5424
+ },
5383
5425
  revokeAllACPs: async (revokerContract) => {
5384
5426
  _requireConnected();
5385
5427
  const { publicClient, walletClient } = connectStore.getState();
@@ -5403,6 +5445,21 @@ function createCofheClientBase(opts) {
5403
5445
  const sharingRegistry = await _resolveSharingRegistry(publicClient, chainId);
5404
5446
  return acps.shareOnChain(acp, walletClient, sharingRegistry, { ...withAppKey(), ...options });
5405
5447
  },
5448
+ prepareShareOnChain: async (acp, options) => {
5449
+ _requireConnected();
5450
+ _requireIssuer(acp, "share it on-chain");
5451
+ const { publicClient } = connectStore.getState();
5452
+ const chainId = await publicClient.getChainId();
5453
+ const sharingRegistry = await _resolveSharingRegistry(publicClient, chainId);
5454
+ return acps.prepareShareOnChain(acp, sharingRegistry, { ...withAppKey(), ...options });
5455
+ },
5456
+ prepareRemoveShare: async (shareId) => {
5457
+ _requireConnected();
5458
+ const { publicClient } = connectStore.getState();
5459
+ const chainId = await publicClient.getChainId();
5460
+ const sharingRegistry = await _resolveSharingRegistry(publicClient, chainId);
5461
+ return acps.prepareRemoveShare(shareId, sharingRegistry);
5462
+ },
5406
5463
  getIncomingShares: async () => {
5407
5464
  _requireConnected();
5408
5465
  const { publicClient, walletClient } = connectStore.getState();
package/dist/node.d.cts CHANGED
@@ -1,8 +1,8 @@
1
- import { C as CofheInputConfig, a as CofheConfig, b as CofheClient } from './clientTypes-C2b_qub5.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';
5
- import './onchain-utils-CgOslubH.cjs';
5
+ import './onchain-utils-Ns56cBm0.cjs';
6
6
  import 'zustand/vanilla';
7
7
 
8
8
  /**
package/dist/node.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { C as CofheInputConfig, a as CofheConfig, b as CofheClient } from './clientTypes-DEKYh0cw.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';
5
- import './onchain-utils-CgOslubH.js';
5
+ import './onchain-utils-Ns56cBm0.js';
6
6
  import 'zustand/vanilla';
7
7
 
8
8
  /**
package/dist/node.js CHANGED
@@ -1,8 +1,8 @@
1
- import { createCofheConfigBase, createCofheClientBase } from './chunk-GKEJHZ52.js';
1
+ import { createCofheConfigBase, createCofheClientBase } from './chunk-VE7DKXSF.js';
2
2
  import './chunk-UKQAJK4N.js';
3
- import './chunk-WAA2U7CT.js';
4
- import { fromHexString } from './chunk-3SD2UCRE.js';
5
- import { TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT } from './chunk-OC5TGQGG.js';
3
+ import './chunk-3L2IVPMI.js';
4
+ import { fromHexString } from './chunk-WJGTPW7K.js';
5
+ import { TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT } from './chunk-J23FYAI2.js';
6
6
  import { promises } from 'fs';
7
7
  import { join } from 'path';
8
8
  import { init_panic_hook, ProvenCompactCiphertextList, CompactPkeCrs, TfheCompactPublicKey } from 'node-tfhe';