@cofhe/sdk 0.1.0 → 0.1.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 (110) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/adapters/ethers5.test.ts +174 -0
  3. package/adapters/ethers5.ts +36 -0
  4. package/adapters/ethers6.test.ts +169 -0
  5. package/adapters/ethers6.ts +36 -0
  6. package/adapters/hardhat-node.ts +167 -0
  7. package/adapters/hardhat.hh2.test.ts +159 -0
  8. package/adapters/hardhat.ts +37 -0
  9. package/adapters/index.test.ts +25 -0
  10. package/adapters/index.ts +5 -0
  11. package/adapters/smartWallet.ts +91 -0
  12. package/adapters/test-utils.ts +53 -0
  13. package/adapters/types.ts +6 -0
  14. package/adapters/wagmi.test.ts +156 -0
  15. package/adapters/wagmi.ts +17 -0
  16. package/chains/chains/arbSepolia.ts +14 -0
  17. package/chains/chains/baseSepolia.ts +14 -0
  18. package/chains/chains/hardhat.ts +15 -0
  19. package/chains/chains/sepolia.ts +14 -0
  20. package/chains/chains.test.ts +49 -0
  21. package/chains/defineChain.ts +18 -0
  22. package/chains/index.ts +33 -0
  23. package/chains/types.ts +32 -0
  24. package/core/baseBuilder.ts +138 -0
  25. package/core/client.test.ts +298 -0
  26. package/core/client.ts +308 -0
  27. package/core/config.test.ts +224 -0
  28. package/core/config.ts +213 -0
  29. package/core/decrypt/MockQueryDecrypterAbi.ts +129 -0
  30. package/core/decrypt/cofheMocksSealOutput.ts +57 -0
  31. package/core/decrypt/decryptHandleBuilder.ts +281 -0
  32. package/core/decrypt/decryptUtils.ts +28 -0
  33. package/core/decrypt/tnSealOutput.ts +59 -0
  34. package/core/encrypt/MockZkVerifierAbi.ts +106 -0
  35. package/core/encrypt/cofheMocksZkVerifySign.ts +278 -0
  36. package/core/encrypt/encryptInputsBuilder.test.ts +735 -0
  37. package/core/encrypt/encryptInputsBuilder.ts +512 -0
  38. package/core/encrypt/encryptUtils.ts +64 -0
  39. package/core/encrypt/zkPackProveVerify.ts +273 -0
  40. package/core/error.ts +170 -0
  41. package/core/fetchKeys.test.ts +212 -0
  42. package/core/fetchKeys.ts +170 -0
  43. package/core/index.ts +77 -0
  44. package/core/keyStore.test.ts +226 -0
  45. package/core/keyStore.ts +127 -0
  46. package/core/permits.test.ts +242 -0
  47. package/core/permits.ts +136 -0
  48. package/core/result.test.ts +180 -0
  49. package/core/result.ts +67 -0
  50. package/core/test-utils.ts +45 -0
  51. package/core/types.ts +352 -0
  52. package/core/utils.ts +88 -0
  53. package/dist/adapters.cjs +88 -0
  54. package/dist/adapters.d.cts +14558 -0
  55. package/dist/adapters.d.ts +14558 -0
  56. package/dist/adapters.js +83 -0
  57. package/dist/chains.cjs +101 -0
  58. package/dist/chains.d.cts +99 -0
  59. package/dist/chains.d.ts +99 -0
  60. package/dist/chains.js +1 -0
  61. package/dist/chunk-GZCQQYVI.js +93 -0
  62. package/dist/chunk-KFGPTJ6X.js +2295 -0
  63. package/dist/chunk-LU7BMUUT.js +804 -0
  64. package/dist/core.cjs +3174 -0
  65. package/dist/core.d.cts +16 -0
  66. package/dist/core.d.ts +16 -0
  67. package/dist/core.js +3 -0
  68. package/dist/node.cjs +3090 -0
  69. package/dist/node.d.cts +22 -0
  70. package/dist/node.d.ts +22 -0
  71. package/dist/node.js +90 -0
  72. package/dist/permit-S9CnI6MF.d.cts +333 -0
  73. package/dist/permit-S9CnI6MF.d.ts +333 -0
  74. package/dist/permits.cjs +856 -0
  75. package/dist/permits.d.cts +1056 -0
  76. package/dist/permits.d.ts +1056 -0
  77. package/dist/permits.js +1 -0
  78. package/dist/types-KImPrEIe.d.cts +48 -0
  79. package/dist/types-KImPrEIe.d.ts +48 -0
  80. package/dist/types-PhwGgQvs.d.ts +953 -0
  81. package/dist/types-bB7wLj0q.d.cts +953 -0
  82. package/dist/web.cjs +3067 -0
  83. package/dist/web.d.cts +22 -0
  84. package/dist/web.d.ts +22 -0
  85. package/dist/web.js +64 -0
  86. package/node/client.test.ts +152 -0
  87. package/node/config.test.ts +68 -0
  88. package/node/encryptInputs.test.ts +175 -0
  89. package/node/index.ts +96 -0
  90. package/node/storage.ts +51 -0
  91. package/package.json +15 -3
  92. package/permits/index.ts +67 -0
  93. package/permits/localstorage.test.ts +118 -0
  94. package/permits/permit.test.ts +474 -0
  95. package/permits/permit.ts +396 -0
  96. package/permits/sealing.test.ts +84 -0
  97. package/permits/sealing.ts +131 -0
  98. package/permits/signature.ts +79 -0
  99. package/permits/store.test.ts +128 -0
  100. package/permits/store.ts +168 -0
  101. package/permits/test-utils.ts +20 -0
  102. package/permits/types.ts +174 -0
  103. package/permits/utils.ts +63 -0
  104. package/permits/validation.test.ts +288 -0
  105. package/permits/validation.ts +349 -0
  106. package/web/client.web.test.ts +152 -0
  107. package/web/config.web.test.ts +71 -0
  108. package/web/encryptInputs.web.test.ts +195 -0
  109. package/web/index.ts +97 -0
  110. package/web/storage.ts +20 -0
@@ -0,0 +1,953 @@
1
+ import { P as Permit, S as SerializedPermit, C as CreateSelfPermitOptions, d as CreateSharingPermitOptions, I as ImportSharedPermitOptions, g as PermitUtils } from './permit-S9CnI6MF.cjs';
2
+ import { WalletClient, PublicClient } from 'viem';
3
+ import { C as CofheChain } from './types-KImPrEIe.cjs';
4
+ import { z } from 'zod';
5
+ import { StoreApi } from 'zustand/vanilla';
6
+
7
+ /**
8
+ * Usable config type inferred from the schema
9
+ */
10
+ type CofhesdkConfig = {
11
+ supportedChains: CofheChain[];
12
+ /**
13
+ * Strategy for fetching FHE keys
14
+ * - CONNECTED_CHAIN: Fetch keys for the connected chain (provided by the publicClient)
15
+ * - SUPPORTED_CHAINS: Fetch keys for all supported chains (provided by the supportedChains config)
16
+ * - OFF: Do not fetch keys (fetching occurs during encryptInputs)
17
+ * */
18
+ fheKeysPrefetching: 'CONNECTED_CHAIN' | 'SUPPORTED_CHAINS' | 'OFF';
19
+ /**
20
+ * How permits are generated
21
+ * - ON_CONNECT: Generate a permit when client.connect() is called
22
+ * - ON_DECRYPT_HANDLES: Generate a permit when client.decryptHandles() is called
23
+ * - MANUAL: Generate a permit manually using client.generatePermit()
24
+ */
25
+ permitGeneration: 'ON_CONNECT' | 'ON_DECRYPT_HANDLES' | 'MANUAL';
26
+ /** Default permit expiration in seconds, default is 30 days */
27
+ defaultPermitExpiration: number;
28
+ /**
29
+ * Storage scheme for the fetched fhe keys
30
+ * FHE keys are large, and caching prevents re-fetching them on each encryptInputs call
31
+ * (defaults to indexedDB on web, filesystem on node)
32
+ */
33
+ fheKeyStorage: IStorage | null;
34
+ /** Mocks configs */
35
+ mocks: {
36
+ /**
37
+ * Length of the simulated seal output delay in milliseconds
38
+ * Default 1000ms on web
39
+ * Default 0ms on hardhat (will be called during tests no need for fake delay)
40
+ */
41
+ sealOutputDelay: number;
42
+ };
43
+ _internal?: CofhesdkInternalConfig;
44
+ };
45
+ type CofhesdkInternalConfig = {
46
+ zkvWalletClient?: WalletClient;
47
+ };
48
+ /**
49
+ * Zod schema for configuration validation
50
+ */
51
+ declare const CofhesdkConfigSchema: z.ZodObject<{
52
+ /** List of supported chain configurations */
53
+ supportedChains: z.ZodArray<z.ZodType<{
54
+ name: string;
55
+ id: number;
56
+ network: string;
57
+ coFheUrl: string;
58
+ verifierUrl: string;
59
+ thresholdNetworkUrl: string;
60
+ environment: "MOCK" | "TESTNET" | "MAINNET";
61
+ }, z.ZodTypeDef, {
62
+ name: string;
63
+ id: number;
64
+ network: string;
65
+ coFheUrl: string;
66
+ verifierUrl: string;
67
+ thresholdNetworkUrl: string;
68
+ environment: "MOCK" | "TESTNET" | "MAINNET";
69
+ }>, "many">;
70
+ /** Strategy for fetching FHE keys */
71
+ fheKeysPrefetching: z.ZodDefault<z.ZodOptional<z.ZodEnum<["CONNECTED_CHAIN", "SUPPORTED_CHAINS", "OFF"]>>>;
72
+ /** How permits are generated */
73
+ permitGeneration: z.ZodDefault<z.ZodOptional<z.ZodEnum<["ON_CONNECT", "ON_DECRYPT_HANDLES", "MANUAL"]>>>;
74
+ /** Default permit expiration in seconds, default is 30 days */
75
+ defaultPermitExpiration: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
76
+ /** Storage method for fhe keys (defaults to indexedDB on web, filesystem on node) */
77
+ fheKeyStorage: z.ZodDefault<z.ZodUnion<[z.ZodObject<{
78
+ getItem: z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodPromise<z.ZodAny>>;
79
+ setItem: z.ZodFunction<z.ZodTuple<[z.ZodString, z.ZodAny], z.ZodUnknown>, z.ZodPromise<z.ZodVoid>>;
80
+ removeItem: z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodPromise<z.ZodVoid>>;
81
+ }, "strip", z.ZodTypeAny, {
82
+ getItem: (args_0: string, ...args_1: unknown[]) => Promise<any>;
83
+ setItem: (args_0: string, args_1: any, ...args_2: unknown[]) => Promise<void>;
84
+ removeItem: (args_0: string, ...args_1: unknown[]) => Promise<void>;
85
+ }, {
86
+ getItem: (args_0: string, ...args_1: unknown[]) => Promise<any>;
87
+ setItem: (args_0: string, args_1: any, ...args_2: unknown[]) => Promise<void>;
88
+ removeItem: (args_0: string, ...args_1: unknown[]) => Promise<void>;
89
+ }>, z.ZodNull]>>;
90
+ /** Mocks configs */
91
+ mocks: z.ZodDefault<z.ZodOptional<z.ZodObject<{
92
+ sealOutputDelay: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
93
+ }, "strip", z.ZodTypeAny, {
94
+ sealOutputDelay: number;
95
+ }, {
96
+ sealOutputDelay?: number | undefined;
97
+ }>>>;
98
+ /** Internal configuration */
99
+ _internal: z.ZodOptional<z.ZodObject<{
100
+ zkvWalletClient: z.ZodOptional<z.ZodAny>;
101
+ }, "strip", z.ZodTypeAny, {
102
+ zkvWalletClient?: any;
103
+ }, {
104
+ zkvWalletClient?: any;
105
+ }>>;
106
+ }, "strip", z.ZodTypeAny, {
107
+ supportedChains: {
108
+ name: string;
109
+ id: number;
110
+ network: string;
111
+ coFheUrl: string;
112
+ verifierUrl: string;
113
+ thresholdNetworkUrl: string;
114
+ environment: "MOCK" | "TESTNET" | "MAINNET";
115
+ }[];
116
+ fheKeysPrefetching: "CONNECTED_CHAIN" | "SUPPORTED_CHAINS" | "OFF";
117
+ permitGeneration: "ON_CONNECT" | "ON_DECRYPT_HANDLES" | "MANUAL";
118
+ defaultPermitExpiration: number;
119
+ fheKeyStorage: {
120
+ getItem: (args_0: string, ...args_1: unknown[]) => Promise<any>;
121
+ setItem: (args_0: string, args_1: any, ...args_2: unknown[]) => Promise<void>;
122
+ removeItem: (args_0: string, ...args_1: unknown[]) => Promise<void>;
123
+ } | null;
124
+ mocks: {
125
+ sealOutputDelay: number;
126
+ };
127
+ _internal?: {
128
+ zkvWalletClient?: any;
129
+ } | undefined;
130
+ }, {
131
+ supportedChains: {
132
+ name: string;
133
+ id: number;
134
+ network: string;
135
+ coFheUrl: string;
136
+ verifierUrl: string;
137
+ thresholdNetworkUrl: string;
138
+ environment: "MOCK" | "TESTNET" | "MAINNET";
139
+ }[];
140
+ fheKeysPrefetching?: "CONNECTED_CHAIN" | "SUPPORTED_CHAINS" | "OFF" | undefined;
141
+ permitGeneration?: "ON_CONNECT" | "ON_DECRYPT_HANDLES" | "MANUAL" | undefined;
142
+ defaultPermitExpiration?: number | undefined;
143
+ fheKeyStorage?: {
144
+ getItem: (args_0: string, ...args_1: unknown[]) => Promise<any>;
145
+ setItem: (args_0: string, args_1: any, ...args_2: unknown[]) => Promise<void>;
146
+ removeItem: (args_0: string, ...args_1: unknown[]) => Promise<void>;
147
+ } | null | undefined;
148
+ mocks?: {
149
+ sealOutputDelay?: number | undefined;
150
+ } | undefined;
151
+ _internal?: {
152
+ zkvWalletClient?: any;
153
+ } | undefined;
154
+ }>;
155
+ /**
156
+ * Input config type inferred from the schema
157
+ */
158
+ type CofhesdkInputConfig = z.input<typeof CofhesdkConfigSchema>;
159
+ /**
160
+ * Creates and validates a cofhesdk configuration (base implementation)
161
+ * @param config - The configuration object to validate
162
+ * @returns The validated configuration
163
+ * @throws {Error} If the configuration is invalid
164
+ */
165
+ declare function createCofhesdkConfigBase(config: CofhesdkInputConfig): CofhesdkConfig;
166
+ /**
167
+ * Access the CofhesdkConfig object directly by providing the key.
168
+ * This is powerful when you use OnchainKit utilities outside of the React context.
169
+ */
170
+ declare const getCofhesdkConfigItem: <K extends keyof CofhesdkConfig>(config: CofhesdkConfig, key: K) => CofhesdkConfig[K];
171
+
172
+ declare enum CofhesdkErrorCode {
173
+ InternalError = "INTERNAL_ERROR",
174
+ UnknownEnvironment = "UNKNOWN_ENVIRONMENT",
175
+ InitTfheFailed = "INIT_TFHE_FAILED",
176
+ InitViemFailed = "INIT_VIEM_FAILED",
177
+ InitEthersFailed = "INIT_ETHERS_FAILED",
178
+ NotConnected = "NOT_CONNECTED",
179
+ MissingPublicClient = "MISSING_PUBLIC_CLIENT",
180
+ MissingWalletClient = "MISSING_WALLET_CLIENT",
181
+ MissingProviderParam = "MISSING_PROVIDER_PARAM",
182
+ EmptySecurityZonesParam = "EMPTY_SECURITY_ZONES_PARAM",
183
+ InvalidPermitData = "INVALID_PERMIT_DATA",
184
+ InvalidPermitDomain = "INVALID_PERMIT_DOMAIN",
185
+ PermitNotFound = "PERMIT_NOT_FOUND",
186
+ CannotRemoveLastPermit = "CANNOT_REMOVE_LAST_PERMIT",
187
+ AccountUninitialized = "ACCOUNT_UNINITIALIZED",
188
+ ChainIdUninitialized = "CHAIN_ID_UNINITIALIZED",
189
+ SealOutputFailed = "SEAL_OUTPUT_FAILED",
190
+ SealOutputReturnedNull = "SEAL_OUTPUT_RETURNED_NULL",
191
+ InvalidUtype = "INVALID_UTYPE",
192
+ DecryptFailed = "DECRYPT_FAILED",
193
+ DecryptReturnedNull = "DECRYPT_RETURNED_NULL",
194
+ ZkMocksInsertCtHashesFailed = "ZK_MOCKS_INSERT_CT_HASHES_FAILED",
195
+ ZkMocksCalcCtHashesFailed = "ZK_MOCKS_CALC_CT_HASHES_FAILED",
196
+ ZkMocksVerifySignFailed = "ZK_MOCKS_VERIFY_SIGN_FAILED",
197
+ ZkMocksCreateProofSignatureFailed = "ZK_MOCKS_CREATE_PROOF_SIGNATURE_FAILED",
198
+ ZkVerifyFailed = "ZK_VERIFY_FAILED",
199
+ ZkPackFailed = "ZK_PACK_FAILED",
200
+ ZkProveFailed = "ZK_PROVE_FAILED",
201
+ EncryptRemainingInItems = "ENCRYPT_REMAINING_IN_ITEMS",
202
+ ZkUninitialized = "ZK_UNINITIALIZED",
203
+ ZkVerifierUrlUninitialized = "ZK_VERIFIER_URL_UNINITIALIZED",
204
+ ThresholdNetworkUrlUninitialized = "THRESHOLD_NETWORK_URL_UNINITIALIZED",
205
+ MissingConfig = "MISSING_CONFIG",
206
+ UnsupportedChain = "UNSUPPORTED_CHAIN",
207
+ MissingZkBuilderAndCrsGenerator = "MISSING_ZK_BUILDER_AND_CRS_GENERATOR",
208
+ MissingTfhePublicKeyDeserializer = "MISSING_TFHE_PUBLIC_KEY_DESERIALIZER",
209
+ MissingCompactPkeCrsDeserializer = "MISSING_COMPACT_PKE_CRS_DESERIALIZER",
210
+ MissingFheKey = "MISSING_FHE_KEY",
211
+ MissingCrs = "MISSING_CRS",
212
+ FetchKeysFailed = "FETCH_KEYS_FAILED",
213
+ PublicWalletGetChainIdFailed = "PUBLIC_WALLET_GET_CHAIN_ID_FAILED",
214
+ PublicWalletGetAddressesFailed = "PUBLIC_WALLET_GET_ADDRESSES_FAILED",
215
+ RehydrateKeysStoreFailed = "REHYDRATE_KEYS_STORE_FAILED"
216
+ }
217
+ type CofhesdkErrorParams = {
218
+ code: CofhesdkErrorCode;
219
+ message: string;
220
+ cause?: Error;
221
+ hint?: string;
222
+ context?: Record<string, unknown>;
223
+ };
224
+ /**
225
+ * CofhesdkError class
226
+ * This class is used to create errors that are specific to the CoFHE SDK
227
+ * It extends the Error class and adds a code, cause, hint, and context
228
+ * The code is used to identify the type of error
229
+ * The cause is used to indicate the inner error that caused the CofhesdkError
230
+ * The hint is used to provide a hint about how to fix the error
231
+ * The context is used to provide additional context about the state that caused the error
232
+ * The serialize method is used to serialize the error to a JSON string
233
+ * The toString method is used to provide a human-readable string representation of the error
234
+ */
235
+ declare class CofhesdkError extends Error {
236
+ readonly code: CofhesdkErrorCode;
237
+ readonly cause?: Error;
238
+ readonly hint?: string;
239
+ readonly context?: Record<string, unknown>;
240
+ constructor({ code, message, cause, hint, context }: CofhesdkErrorParams);
241
+ /**
242
+ * Creates a CofhesdkError from an unknown error
243
+ * If the error is a CofhesdkError, it is returned unchanged, else a new CofhesdkError is created
244
+ * If a wrapperError is provided, it is used to create the new CofhesdkError, else a default is used
245
+ */
246
+ static fromError(error: unknown, wrapperError?: CofhesdkErrorParams): CofhesdkError;
247
+ /**
248
+ * Serializes the error to JSON string with proper handling of Error objects
249
+ */
250
+ serialize(): string;
251
+ /**
252
+ * Returns a human-readable string representation of the error
253
+ */
254
+ toString(): string;
255
+ }
256
+ declare const isCofhesdkError: (error: unknown) => error is CofhesdkError;
257
+
258
+ type Result<T> = {
259
+ success: true;
260
+ data: T;
261
+ error: null;
262
+ } | {
263
+ success: false;
264
+ data: null;
265
+ error: CofhesdkError;
266
+ };
267
+ declare const ResultErr: <T>(error: CofhesdkError) => Result<T>;
268
+ declare const ResultOk: <T>(data: T) => Result<T>;
269
+ declare const ResultErrOrInternal: <T>(error: unknown) => Result<T>;
270
+ declare const ResultHttpError: (error: unknown, url: string, status?: number) => CofhesdkError;
271
+ declare const ResultValidationError: (message: string) => CofhesdkError;
272
+ declare const resultWrapper: <T>(tryFn: () => Promise<T>, catchFn?: (error: CofhesdkError) => void, finallyFn?: () => void) => Promise<Result<T>>;
273
+ declare const resultWrapperSync: <T>(fn: () => T) => Result<T>;
274
+
275
+ /**
276
+ * Base parameters that all builders need
277
+ */
278
+ type BaseBuilderParams = {
279
+ config: CofhesdkConfig | undefined;
280
+ publicClient: PublicClient | undefined;
281
+ walletClient: WalletClient | undefined;
282
+ chainId: number | undefined;
283
+ account: string | undefined;
284
+ requireConnected: (() => void) | undefined;
285
+ };
286
+ /**
287
+ * Abstract base class for builders that provides common functionality
288
+ * for working with clients, config, and chain IDs
289
+ */
290
+ declare abstract class BaseBuilder {
291
+ protected config: CofhesdkConfig | undefined;
292
+ protected publicClient: PublicClient | undefined;
293
+ protected walletClient: WalletClient | undefined;
294
+ protected chainId: number | undefined;
295
+ protected account: string | undefined;
296
+ protected requireConnected: (() => void) | undefined;
297
+ constructor(params: BaseBuilderParams);
298
+ /**
299
+ * Gets the chain ID from the instance or fetches it from the public client
300
+ * @returns The chain ID
301
+ * @throws {CofhesdkError} If chainId is not set and publicClient is not available
302
+ */
303
+ protected getChainIdOrThrow(): Promise<number>;
304
+ /**
305
+ * Gets the account address from the instance or fetches it from the wallet client
306
+ * @returns The account address
307
+ * @throws {CofhesdkError} If account is not set and walletClient is not available
308
+ */
309
+ protected getAccountOrThrow(): Promise<string>;
310
+ /**
311
+ * Gets the config or throws an error if not available
312
+ * @returns The config
313
+ * @throws {CofhesdkError} If config is not set
314
+ */
315
+ protected getConfigOrThrow(): CofhesdkConfig;
316
+ /**
317
+ * Gets the public client or throws an error if not available
318
+ * @returns The public client
319
+ * @throws {CofhesdkError} If publicClient is not set
320
+ */
321
+ protected getPublicClientOrThrow(): PublicClient;
322
+ /**
323
+ * Gets the wallet client or throws an error if not available
324
+ * @returns The wallet client
325
+ * @throws {CofhesdkError} If walletClient is not set
326
+ */
327
+ protected getWalletClientOrThrow(): WalletClient;
328
+ /**
329
+ * Requires the client to be connected
330
+ * @throws {CofhesdkError} If client is not connected
331
+ */
332
+ protected requireConnectedOrThrow(): void;
333
+ }
334
+
335
+ /**
336
+ * API
337
+ *
338
+ * await client.decryptHandle(ctHash, utype)
339
+ * .setChainId(chainId)
340
+ * .setAccount(account)
341
+ * .setPermitHash(permitHash)
342
+ * .setPermit(permit)
343
+ * .decrypt()
344
+ *
345
+ * If chainId not set, uses client's chainId
346
+ * If account not set, uses client's account
347
+ * If permitHash not set, uses chainId and account to get active permit
348
+ * If permit is set, uses permit to decrypt regardless of chainId, account, or permitHash
349
+ *
350
+ * Returns a Result<UnsealedItem<U>>
351
+ */
352
+ type DecryptHandlesBuilderParams<U extends FheTypes> = BaseBuilderParams & {
353
+ ctHash: bigint;
354
+ utype: U;
355
+ permitHash?: string;
356
+ permit?: Permit;
357
+ };
358
+ declare class DecryptHandlesBuilder<U extends FheTypes> extends BaseBuilder {
359
+ private ctHash;
360
+ private utype;
361
+ private permitHash?;
362
+ private permit?;
363
+ constructor(params: DecryptHandlesBuilderParams<U>);
364
+ /**
365
+ * @param chainId - Chain to decrypt values from. Used to fetch the threshold network URL and use the correct permit.
366
+ *
367
+ * If not provided, the chainId will be fetched from the connected publicClient.
368
+ *
369
+ * Example:
370
+ * ```typescript
371
+ * const unsealed = await decryptHandle(ctHash, utype)
372
+ * .setChainId(11155111)
373
+ * .decrypt();
374
+ * ```
375
+ *
376
+ * @returns The chainable DecryptHandlesBuilder instance.
377
+ */
378
+ setChainId(chainId: number): DecryptHandlesBuilder<U>;
379
+ getChainId(): number | undefined;
380
+ /**
381
+ * @param account - Account to decrypt values from. Used to fetch the correct permit.
382
+ *
383
+ * If not provided, the account will be fetched from the connected walletClient.
384
+ *
385
+ * Example:
386
+ * ```typescript
387
+ * const unsealed = await decryptHandle(ctHash, utype)
388
+ * .setAccount('0x1234567890123456789012345678901234567890')
389
+ * .decrypt();
390
+ * ```
391
+ *
392
+ * @returns The chainable DecryptHandlesBuilder instance.
393
+ */
394
+ setAccount(account: string): DecryptHandlesBuilder<U>;
395
+ getAccount(): string | undefined;
396
+ /**
397
+ * @param permitHash - Permit hash to decrypt values from. Used to fetch the correct permit.
398
+ *
399
+ * If not provided, the active permit for the chainId and account will be used.
400
+ * If `setPermit()` is called, it will be used regardless of chainId, account, or permitHash.
401
+ *
402
+ * Example:
403
+ * ```typescript
404
+ * const unsealed = await decryptHandle(ctHash, utype)
405
+ * .setPermitHash('0x1234567890123456789012345678901234567890')
406
+ * .decrypt();
407
+ * ```
408
+ *
409
+ * @returns The chainable DecryptHandlesBuilder instance.
410
+ */
411
+ setPermitHash(permitHash: string): DecryptHandlesBuilder<U>;
412
+ getPermitHash(): string | undefined;
413
+ /**
414
+ * @param permit - Permit to decrypt values with. If provided, it will be used regardless of chainId, account, or permitHash.
415
+ *
416
+ * If not provided, the permit will be determined by chainId, account, and permitHash.
417
+ *
418
+ * Example:
419
+ * ```typescript
420
+ * const unsealed = await decryptHandle(ctHash, utype)
421
+ * .setPermit(permit)
422
+ * .decrypt();
423
+ * ```
424
+ *
425
+ * @returns The chainable DecryptHandlesBuilder instance.
426
+ */
427
+ setPermit(permit: Permit): DecryptHandlesBuilder<U>;
428
+ getPermit(): Permit | undefined;
429
+ private getThresholdNetworkUrl;
430
+ private validateUtypeOrThrow;
431
+ private getResolvedPermit;
432
+ /**
433
+ * On hardhat, interact with MockZkVerifier contract instead of CoFHE
434
+ */
435
+ private mocksSealOutput;
436
+ /**
437
+ * In the production context, perform a true decryption with the CoFHE coprocessor.
438
+ */
439
+ private productionSealOutput;
440
+ /**
441
+ * Final step of the decryption process. MUST BE CALLED LAST IN THE CHAIN.
442
+ *
443
+ * This will:
444
+ * - Use a permit based on provided permit OR chainId + account + permitHash
445
+ * - Check permit validity
446
+ * - Call CoFHE `/sealoutput` with the permit, which returns a sealed (encrypted) item
447
+ * - Unseal the sealed item with the permit
448
+ * - Return the unsealed item
449
+ *
450
+ * Example:
451
+ * ```typescript
452
+ * const unsealed = await decryptHandle(ctHash, utype)
453
+ * .setChainId(11155111) // optional
454
+ * .setAccount('0x123...890') // optional
455
+ * .decrypt(); // execute
456
+ * ```
457
+ *
458
+ * @returns The unsealed item.
459
+ */
460
+ decrypt(): Promise<Result<UnsealedItem<U>>>;
461
+ }
462
+
463
+ type ZkProvenCiphertextList = {
464
+ serialize(): Uint8Array;
465
+ };
466
+ type ZkCompactPkeCrs = {
467
+ free(): void;
468
+ serialize(compress: boolean): Uint8Array;
469
+ safe_serialize(serialized_size_limit: bigint): Uint8Array;
470
+ };
471
+ type ZkCiphertextListBuilder = {
472
+ push_boolean(data: boolean): void;
473
+ push_u8(data: number): void;
474
+ push_u16(data: number): void;
475
+ push_u32(data: number): void;
476
+ push_u64(data: bigint): void;
477
+ push_u128(data: bigint): void;
478
+ push_u160(data: bigint): void;
479
+ build_with_proof_packed(crs: ZkCompactPkeCrs, metadata: Uint8Array, computeLoad: 1): ZkProvenCiphertextList;
480
+ };
481
+ type ZkBuilderAndCrsGenerator = (fhe: string, crs: string) => {
482
+ zkBuilder: ZkCiphertextListBuilder;
483
+ zkCrs: ZkCompactPkeCrs;
484
+ };
485
+
486
+ type ChainRecord<T> = Record<string, T>;
487
+ type SecurityZoneRecord<T> = Record<number, T>;
488
+ type KeysStore = {
489
+ fhe: ChainRecord<SecurityZoneRecord<string | undefined>>;
490
+ crs: ChainRecord<string | undefined>;
491
+ };
492
+ type KeysStorage = {
493
+ store: StoreApi<KeysStore>;
494
+ getFheKey: (chainId: number | undefined, securityZone?: number) => string | undefined;
495
+ getCrs: (chainId: number | undefined) => string | undefined;
496
+ setFheKey: (chainId: number, securityZone: number, key: string) => void;
497
+ setCrs: (chainId: number, crs: string) => void;
498
+ clearKeysStorage: () => Promise<void>;
499
+ rehydrateKeysStore: () => Promise<void>;
500
+ };
501
+ /**
502
+ * Creates a keys storage instance using the provided storage implementation
503
+ * @param storage - The storage implementation to use (IStorage interface), or null for non-persisted store
504
+ * @returns A KeysStorage instance with all utility methods
505
+ */
506
+ declare function createKeysStore(storage: IStorage | null): KeysStorage;
507
+
508
+ type FheKeyDeserializer = (buff: string) => void;
509
+ /**
510
+ * Retrieves the FHE public key and the CRS from the provider.
511
+ * If the key/crs already exists in the store it is returned, else it is fetched, stored, and returned
512
+ * @param {CofhesdkConfig} config - The configuration object for the CoFHE SDK
513
+ * @param {number} chainId - The chain to fetch the FHE key for, if no chainId provided, undefined is returned
514
+ * @param securityZone - The security zone for which to retrieve the key (default 0).
515
+ * @param tfhePublicKeyDeserializer - The serializer for the FHE public key (used for validation).
516
+ * @param compactPkeCrsDeserializer - The serializer for the CRS (used for validation).
517
+ * @param keysStorage - The keys storage instance to use (optional)
518
+ * @returns {Promise<[[string, boolean], [string, boolean]]>} - A promise that resolves to [[fheKey, fheKeyFetchedFromCoFHE], [crs, crsFetchedFromCoFHE]]
519
+ */
520
+ declare const fetchKeys: (config: CofhesdkConfig, chainId: number, securityZone: number | undefined, tfhePublicKeyDeserializer: FheKeyDeserializer, compactPkeCrsDeserializer: FheKeyDeserializer, keysStorage?: KeysStorage | null) => Promise<[[string, boolean], [string, boolean]]>;
521
+ /**
522
+ * Fetches the FHE public key and the CRS for all chains in the config
523
+ * @param {CofhesdkConfig} config - The configuration object for the CoFHE SDK
524
+ * @param {number} securityZone - The security zone for which to retrieve the key (default 0).
525
+ * @param tfhePublicKeyDeserializer - The serializer for the FHE public key (used for validation).
526
+ * @param compactPkeCrsDeserializer - The serializer for the CRS (used for validation).
527
+ * @param keysStorage - The keys storage instance to use (optional)
528
+ * @returns {Promise<void>} - A promise that resolves when the keys are fetched and stored.
529
+ */
530
+ declare const fetchMultichainKeys: (config: CofhesdkConfig, securityZone: number | undefined, tfhePublicKeyDeserializer: FheKeyDeserializer, compactPkeCrsDeserializer: FheKeyDeserializer, keysStorage?: KeysStorage | null) => Promise<void>;
531
+
532
+ type EncryptInputsBuilderParams<T extends EncryptableItem[]> = BaseBuilderParams & {
533
+ inputs: [...T];
534
+ securityZone?: number;
535
+ zkvWalletClient?: WalletClient | undefined;
536
+ tfhePublicKeyDeserializer: FheKeyDeserializer | undefined;
537
+ compactPkeCrsDeserializer: FheKeyDeserializer | undefined;
538
+ zkBuilderAndCrsGenerator: ZkBuilderAndCrsGenerator | undefined;
539
+ initTfhe: TfheInitializer | undefined;
540
+ keysStorage: KeysStorage | undefined;
541
+ };
542
+ /**
543
+ * EncryptInputsBuilder exposes a builder pattern for encrypting inputs.
544
+ * account, securityZone, and chainId can be overridden in the builder.
545
+ * config, tfhePublicKeyDeserializer, compactPkeCrsDeserializer, and zkBuilderAndCrsGenerator are required to be set in the builder.
546
+ *
547
+ * @dev All errors must be throw in `encrypt`, which wraps them in a Result.
548
+ * Do not throw errors in the constructor or in the builder methods.
549
+ */
550
+ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuilder {
551
+ private securityZone;
552
+ private stepCallback?;
553
+ private inputItems;
554
+ private zkvWalletClient;
555
+ private tfhePublicKeyDeserializer;
556
+ private compactPkeCrsDeserializer;
557
+ private zkBuilderAndCrsGenerator;
558
+ private initTfhe;
559
+ private keysStorage;
560
+ private stepTimestamps;
561
+ constructor(params: EncryptInputsBuilderParams<T>);
562
+ /**
563
+ * @param account - Account that will create the tx using the encrypted inputs.
564
+ *
565
+ * If not provided, the account will be fetched from the connected walletClient.
566
+ *
567
+ * Example:
568
+ * ```typescript
569
+ * const encrypted = await encryptInputs([Encryptable.uint128(10n)])
570
+ * .setAccount("0x123")
571
+ * .encrypt();
572
+ * ```
573
+ *
574
+ * @returns The chainable EncryptInputsBuilder instance.
575
+ */
576
+ setAccount(account: string): EncryptInputsBuilder<T>;
577
+ getAccount(): string | undefined;
578
+ /**
579
+ * @param chainId - Chain that will consume the encrypted inputs.
580
+ *
581
+ * If not provided, the chainId will be fetched from the connected publicClient.
582
+ *
583
+ * Example:
584
+ * ```typescript
585
+ * const encrypted = await encryptInputs([Encryptable.uint128(10n)])
586
+ * .setChainId(11155111)
587
+ * .encrypt();
588
+ * ```
589
+ *
590
+ * @returns The chainable EncryptInputsBuilder instance.
591
+ */
592
+ setChainId(chainId: number): EncryptInputsBuilder<T>;
593
+ getChainId(): number | undefined;
594
+ /**
595
+ * @param securityZone - Security zone to encrypt the inputs for.
596
+ *
597
+ * If not provided, the default securityZone 0 will be used.
598
+ *
599
+ * Example:
600
+ * ```typescript
601
+ * const encrypted = await encryptInputs([Encryptable.uint128(10n)])
602
+ * .setSecurityZone(1)
603
+ * .encrypt();
604
+ * ```
605
+ *
606
+ * @returns The chainable EncryptInputsBuilder instance.
607
+ */
608
+ setSecurityZone(securityZone: number): EncryptInputsBuilder<T>;
609
+ getSecurityZone(): number;
610
+ /**
611
+ * @param callback - Function to be called with the encryption step.
612
+ *
613
+ * Useful for debugging and tracking the progress of the encryption process.
614
+ * Useful for a UI element that shows the progress of the encryption process.
615
+ *
616
+ * Example:
617
+ * ```typescript
618
+ * const encrypted = await encryptInputs([Encryptable.uint128(10n)])
619
+ * .setStepCallback((step: EncryptStep) => console.log(step))
620
+ * .encrypt();
621
+ * ```
622
+ *
623
+ * @returns The EncryptInputsBuilder instance.
624
+ */
625
+ setStepCallback(callback: EncryptStepCallbackFunction): EncryptInputsBuilder<T>;
626
+ getStepCallback(): EncryptStepCallbackFunction | undefined;
627
+ /**
628
+ * Fires the step callback if set
629
+ */
630
+ private fireStepStart;
631
+ private fireStepEnd;
632
+ /**
633
+ * tfhePublicKeyDeserializer is a platform-specific dependency injected into core/createCofhesdkClientBase by web/createCofhesdkClient and node/createCofhesdkClient
634
+ * web/ uses zama "tfhe"
635
+ * node/ uses zama "node-tfhe"
636
+ * Users should not set this manually.
637
+ */
638
+ private getTfhePublicKeyDeserializerOrThrow;
639
+ /**
640
+ * compactPkeCrsDeserializer is a platform-specific dependency injected into core/createCofhesdkClientBase by web/createCofhesdkClient and node/createCofhesdkClient
641
+ * web/ uses zama "tfhe"
642
+ * node/ uses zama "node-tfhe"
643
+ * Users should not set this manually.
644
+ */
645
+ private getCompactPkeCrsDeserializerOrThrow;
646
+ /**
647
+ * zkVerifierUrl is included in the chains exported from cofhesdk/chains for use in CofhesdkConfig.supportedChains
648
+ * Users should generally not set this manually.
649
+ */
650
+ private getZkVerifierUrl;
651
+ /**
652
+ * initTfhe is a platform-specific dependency injected into core/createCofhesdkClientBase by web/createCofhesdkClient and node/createCofhesdkClient
653
+ * web/ uses zama "tfhe"
654
+ * node/ uses zama "node-tfhe"
655
+ * Users should not set this manually.
656
+ */
657
+ private initTfheOrThrow;
658
+ /**
659
+ * Fetches the FHE key and CRS from the CoFHE API
660
+ * If the key/crs already exists in the store it is returned, else it is fetched, stored, and returned
661
+ */
662
+ private fetchFheKeyAndCrs;
663
+ /**
664
+ * zkBuilderAndCrsGenerator is a platform-specific dependency injected into core/createCofhesdkClientBase by web/createCofhesdkClient and node/createCofhesdkClient
665
+ * web/ uses zama "tfhe"
666
+ * node/ uses zama "node-tfhe"
667
+ * Users should not set this manually.
668
+ *
669
+ * Generates the zkBuilder and zkCrs from the fheKey and crs
670
+ */
671
+ private generateZkBuilderAndCrs;
672
+ /**
673
+ * @dev Encrypt against the cofheMocks instead of CoFHE
674
+ *
675
+ * In the cofheMocks, the MockZkVerifier contract is deployed on hardhat to a fixed address, this contract handles mocking the zk verifying.
676
+ * cofheMocksInsertPackedHashes - stores the ctHashes and their plaintext values for on-chain mocking of FHE operations.
677
+ * cofheMocksZkCreateProofSignatures - creates signatures to be included in the encrypted inputs. The signers address is known and verified in the mock contracts.
678
+ */
679
+ private mocksEncrypt;
680
+ /**
681
+ * In the production context, perform a true encryption with the CoFHE coprocessor.
682
+ */
683
+ private productionEncrypt;
684
+ /**
685
+ * Final step of the encryption process. MUST BE CALLED LAST IN THE CHAIN.
686
+ *
687
+ * This will:
688
+ * - Pack the encryptable items into a zk proof
689
+ * - Prove the zk proof
690
+ * - Verify the zk proof with CoFHE
691
+ * - Package and return the encrypted inputs
692
+ *
693
+ * Example:
694
+ * ```typescript
695
+ * const encrypted = await encryptInputs([Encryptable.uint128(10n)])
696
+ * .setAccount('0x123...890') // optional
697
+ * .setChainId(11155111) // optional
698
+ * .encrypt(); // execute
699
+ * ```
700
+ *
701
+ * @returns The encrypted inputs.
702
+ */
703
+ encrypt(): Promise<Result<[...EncryptedItemInputs<T>]>>;
704
+ }
705
+
706
+ declare const permits: {
707
+ getSnapshot: () => {
708
+ permits: {
709
+ [x: number]: {
710
+ [x: string]: {
711
+ [x: string]: SerializedPermit | undefined;
712
+ };
713
+ };
714
+ };
715
+ activePermitHash: {
716
+ [x: number]: {
717
+ [x: string]: string | undefined;
718
+ };
719
+ };
720
+ };
721
+ subscribe: (listener: (state: {
722
+ permits: {
723
+ [x: number]: {
724
+ [x: string]: {
725
+ [x: string]: SerializedPermit | undefined;
726
+ };
727
+ };
728
+ };
729
+ activePermitHash: {
730
+ [x: number]: {
731
+ [x: string]: string | undefined;
732
+ };
733
+ };
734
+ }, prevState: {
735
+ permits: {
736
+ [x: number]: {
737
+ [x: string]: {
738
+ [x: string]: SerializedPermit | undefined;
739
+ };
740
+ };
741
+ };
742
+ activePermitHash: {
743
+ [x: number]: {
744
+ [x: string]: string | undefined;
745
+ };
746
+ };
747
+ }) => void) => () => void;
748
+ createSelf: (options: CreateSelfPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<Permit>;
749
+ createSharing: (options: CreateSharingPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<Permit>;
750
+ importShared: (options: ImportSharedPermitOptions | any | string, publicClient: PublicClient, walletClient: WalletClient) => Promise<Permit>;
751
+ getHash: (permit: Permit) => string;
752
+ serialize: (permit: Permit) => SerializedPermit;
753
+ deserialize: (serialized: SerializedPermit) => Permit;
754
+ getPermit: (chainId: number, account: string, hash: string) => Promise<Permit | undefined>;
755
+ getPermits: (chainId: number, account: string) => Promise<Record<string, Permit>>;
756
+ getActivePermit: (chainId: number, account: string) => Promise<Permit | undefined>;
757
+ getActivePermitHash: (chainId: number, account: string) => Promise<string | undefined>;
758
+ removePermit: (chainId: number, account: string, hash: string) => Promise<void>;
759
+ selectActivePermit: (chainId: number, account: string, hash: string) => Promise<void>;
760
+ removeActivePermit: (chainId: number, account: string) => Promise<void>;
761
+ };
762
+
763
+ type Primitive = null | undefined | string | number | boolean | symbol | bigint;
764
+ type LiteralToPrimitive<T> = T extends number ? number : T extends bigint ? bigint : T extends string ? string : T extends boolean ? boolean : T extends symbol ? symbol : T extends null ? null : T extends undefined ? undefined : never;
765
+ type CofhesdkClient = {
766
+ getSnapshot(): CofhesdkClientConnectionState;
767
+ subscribe(listener: Listener): () => void;
768
+ readonly initializationResults: {
769
+ keyFetchResult: Promise<Result<boolean>>;
770
+ };
771
+ readonly connected: boolean;
772
+ readonly connecting: boolean;
773
+ readonly config: CofhesdkConfig;
774
+ connect(publicClient: PublicClient, walletClient: WalletClient): Promise<Result<boolean>>;
775
+ /**
776
+ * Types docstring
777
+ */
778
+ encryptInputs<T extends EncryptableItem[]>(inputs: [...T]): EncryptInputsBuilder<[...T]>;
779
+ decryptHandle<U extends FheTypes>(ctHash: bigint, utype: U): DecryptHandlesBuilder<U>;
780
+ permits: CofhesdkClientPermits;
781
+ };
782
+ type CofhesdkClientConnectionState = {
783
+ connected: boolean;
784
+ connecting: boolean;
785
+ connectError: unknown | undefined;
786
+ chainId: number | undefined;
787
+ account: string | undefined;
788
+ };
789
+ type Listener = (snapshot: CofhesdkClientConnectionState) => void;
790
+ type CofhesdkClientPermits = {
791
+ getSnapshot: typeof permits.getSnapshot;
792
+ subscribe: typeof permits.subscribe;
793
+ createSelf: (options: CreateSelfPermitOptions) => Promise<Result<Permit>>;
794
+ createSharing: (options: CreateSharingPermitOptions) => Promise<Result<Permit>>;
795
+ importShared: (options: ImportSharedPermitOptions | any | string) => Promise<Result<Permit>>;
796
+ getPermit: (hash: string, chainId?: number, account?: string) => Promise<Result<Permit | undefined>>;
797
+ getPermits: (chainId?: number, account?: string) => Promise<Result<Record<string, Permit>>>;
798
+ getActivePermit: (chainId?: number, account?: string) => Promise<Result<Permit | undefined>>;
799
+ getActivePermitHash: (chainId?: number, account?: string) => Promise<Result<string | undefined>>;
800
+ selectActivePermit: (hash: string, chainId?: number, account?: string) => Promise<Result<void>>;
801
+ removePermit: (hash: string, chainId?: number, account?: string) => Promise<Result<void>>;
802
+ removeActivePermit: (chainId?: number, account?: string) => Promise<Result<void>>;
803
+ getHash: typeof PermitUtils.getHash;
804
+ serialize: typeof PermitUtils.serialize;
805
+ deserialize: typeof PermitUtils.deserialize;
806
+ };
807
+ type TfheInitializer = () => Promise<boolean>;
808
+ type CofhesdkClientParams = {
809
+ config: CofhesdkConfig;
810
+ zkBuilderAndCrsGenerator: ZkBuilderAndCrsGenerator;
811
+ tfhePublicKeyDeserializer: FheKeyDeserializer;
812
+ compactPkeCrsDeserializer: FheKeyDeserializer;
813
+ initTfhe: TfheInitializer;
814
+ };
815
+ interface IStorage {
816
+ getItem: (name: string) => Promise<any>;
817
+ setItem: (name: string, value: any) => Promise<void>;
818
+ removeItem: (name: string) => Promise<void>;
819
+ }
820
+ declare enum FheTypes {
821
+ Bool = 0,
822
+ Uint4 = 1,
823
+ Uint8 = 2,
824
+ Uint16 = 3,
825
+ Uint32 = 4,
826
+ Uint64 = 5,
827
+ Uint128 = 6,
828
+ Uint160 = 7,
829
+ Uint256 = 8,
830
+ Uint512 = 9,
831
+ Uint1024 = 10,
832
+ Uint2048 = 11,
833
+ Uint2 = 12,
834
+ Uint6 = 13,
835
+ Uint10 = 14,
836
+ Uint12 = 15,
837
+ Uint14 = 16,
838
+ Int2 = 17,
839
+ Int4 = 18,
840
+ Int6 = 19,
841
+ Int8 = 20,
842
+ Int10 = 21,
843
+ Int12 = 22,
844
+ Int14 = 23,
845
+ Int16 = 24,
846
+ Int32 = 25,
847
+ Int64 = 26,
848
+ Int128 = 27,
849
+ Int160 = 28,
850
+ Int256 = 29
851
+ }
852
+ /**
853
+ * List of All FHE uint types (excludes bool and address)
854
+ */
855
+ declare const FheUintUTypes: readonly [FheTypes.Uint8, FheTypes.Uint16, FheTypes.Uint32, FheTypes.Uint64, FheTypes.Uint128];
856
+ type FheUintUTypesType = (typeof FheUintUTypes)[number];
857
+ /**
858
+ * List of All FHE types (uints, bool, and address)
859
+ */
860
+ declare const FheAllUTypes: readonly [FheTypes.Bool, FheTypes.Uint8, FheTypes.Uint16, FheTypes.Uint32, FheTypes.Uint64, FheTypes.Uint128, FheTypes.Uint160];
861
+ type EncryptedNumber = {
862
+ data: Uint8Array;
863
+ securityZone: number;
864
+ };
865
+ type EncryptedItemInput = {
866
+ ctHash: bigint;
867
+ securityZone: number;
868
+ utype: FheTypes;
869
+ signature: string;
870
+ };
871
+ type EncryptedBoolInput = EncryptedItemInput & {
872
+ utype: FheTypes.Bool;
873
+ };
874
+ type EncryptedUint8Input = EncryptedItemInput & {
875
+ utype: FheTypes.Uint8;
876
+ };
877
+ type EncryptedUint16Input = EncryptedItemInput & {
878
+ utype: FheTypes.Uint16;
879
+ };
880
+ type EncryptedUint32Input = EncryptedItemInput & {
881
+ utype: FheTypes.Uint32;
882
+ };
883
+ type EncryptedUint64Input = EncryptedItemInput & {
884
+ utype: FheTypes.Uint64;
885
+ };
886
+ type EncryptedUint128Input = EncryptedItemInput & {
887
+ utype: FheTypes.Uint128;
888
+ };
889
+ type EncryptedUint256Input = EncryptedItemInput & {
890
+ utype: FheTypes.Uint256;
891
+ };
892
+ type EncryptedAddressInput = EncryptedItemInput & {
893
+ utype: FheTypes.Uint160;
894
+ };
895
+ type EncryptableBool = {
896
+ data: boolean;
897
+ utype: FheTypes.Bool;
898
+ };
899
+ type EncryptableUint8 = {
900
+ data: string | bigint;
901
+ utype: FheTypes.Uint8;
902
+ };
903
+ type EncryptableUint16 = {
904
+ data: string | bigint;
905
+ utype: FheTypes.Uint16;
906
+ };
907
+ type EncryptableUint32 = {
908
+ data: string | bigint;
909
+ utype: FheTypes.Uint32;
910
+ };
911
+ type EncryptableUint64 = {
912
+ data: string | bigint;
913
+ utype: FheTypes.Uint64;
914
+ };
915
+ type EncryptableUint128 = {
916
+ data: string | bigint;
917
+ utype: FheTypes.Uint128;
918
+ };
919
+ type EncryptableAddress = {
920
+ data: string | bigint;
921
+ utype: FheTypes.Uint160;
922
+ };
923
+ declare const Encryptable: {
924
+ readonly bool: (data: EncryptableBool["data"], securityZone?: number) => EncryptableBool;
925
+ readonly address: (data: EncryptableAddress["data"], securityZone?: number) => EncryptableAddress;
926
+ readonly uint8: (data: EncryptableUint8["data"], securityZone?: number) => EncryptableUint8;
927
+ readonly uint16: (data: EncryptableUint16["data"], securityZone?: number) => EncryptableUint16;
928
+ readonly uint32: (data: EncryptableUint32["data"], securityZone?: number) => EncryptableUint32;
929
+ readonly uint64: (data: EncryptableUint64["data"], securityZone?: number) => EncryptableUint64;
930
+ readonly uint128: (data: EncryptableUint128["data"], securityZone?: number) => EncryptableUint128;
931
+ };
932
+ type EncryptableItem = EncryptableBool | EncryptableUint8 | EncryptableUint16 | EncryptableUint32 | EncryptableUint64 | EncryptableUint128 | EncryptableAddress;
933
+ type EncryptableToEncryptedItemInputMap<E extends EncryptableItem> = E extends EncryptableBool ? EncryptedBoolInput : E extends EncryptableUint8 ? EncryptedUint8Input : E extends EncryptableUint16 ? EncryptedUint16Input : E extends EncryptableUint32 ? EncryptedUint32Input : E extends EncryptableUint64 ? EncryptedUint64Input : E extends EncryptableUint128 ? EncryptedUint128Input : E extends EncryptableAddress ? EncryptedAddressInput : never;
934
+ type EncryptedItemInputs<T> = T extends Primitive ? LiteralToPrimitive<T> : T extends EncryptableItem ? EncryptableToEncryptedItemInputMap<T> : {
935
+ [K in keyof T]: EncryptedItemInputs<T[K]>;
936
+ };
937
+ declare function isEncryptableItem(value: unknown): value is EncryptableItem;
938
+ declare enum EncryptStep {
939
+ InitTfhe = "initTfhe",
940
+ FetchKeys = "fetchKeys",
941
+ Pack = "pack",
942
+ Prove = "prove",
943
+ Verify = "verify"
944
+ }
945
+ type EncryptStepCallbackContext = Record<string, any> & {
946
+ isStart: boolean;
947
+ isEnd: boolean;
948
+ duration: number;
949
+ };
950
+ type EncryptStepCallbackFunction = (state: EncryptStep, context?: EncryptStepCallbackContext) => void;
951
+ type UnsealedItem<U extends FheTypes> = U extends FheTypes.Bool ? boolean : U extends FheTypes.Uint160 ? string : U extends FheUintUTypesType ? bigint : never;
952
+
953
+ export { fetchMultichainKeys as $, type EncryptableToEncryptedItemInputMap as A, type EncryptStepCallbackFunction as B, type CofhesdkClientParams as C, FheUintUTypes as D, type EncryptableItem as E, FheTypes as F, FheAllUTypes as G, Encryptable as H, type IStorage as I, isEncryptableItem as J, EncryptStep as K, type LiteralToPrimitive as L, CofhesdkError as M, CofhesdkErrorCode as N, isCofhesdkError as O, type Primitive as P, type CofhesdkErrorParams as Q, ResultErr as R, ResultOk as S, ResultErrOrInternal as T, type UnsealedItem as U, ResultHttpError as V, ResultValidationError as W, resultWrapper as X, resultWrapperSync as Y, type Result as Z, fetchKeys as _, type CofhesdkClient as a, type FheKeyDeserializer as a0, createKeysStore as a1, type KeysStorage as a2, type KeysStore as a3, EncryptInputsBuilder as a4, DecryptHandlesBuilder as a5, type ZkBuilderAndCrsGenerator as a6, type CofhesdkConfig as b, createCofhesdkConfigBase as c, type CofhesdkInputConfig as d, type CofhesdkInternalConfig as e, type CofhesdkClientConnectionState as f, getCofhesdkConfigItem as g, type CofhesdkClientPermits as h, type EncryptableBool as i, type EncryptableUint8 as j, type EncryptableUint16 as k, type EncryptableUint32 as l, type EncryptableUint64 as m, type EncryptableUint128 as n, type EncryptableAddress as o, type EncryptedNumber as p, type EncryptedItemInput as q, type EncryptedBoolInput as r, type EncryptedUint8Input as s, type EncryptedUint16Input as t, type EncryptedUint32Input as u, type EncryptedUint64Input as v, type EncryptedUint128Input as w, type EncryptedUint256Input as x, type EncryptedAddressInput as y, type EncryptedItemInputs as z };