@cofhe/sdk 0.0.0-alpha-20260409113701

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 (132) hide show
  1. package/CHANGELOG.md +146 -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 +36 -0
  9. package/adapters/index.test.ts +20 -0
  10. package/adapters/index.ts +5 -0
  11. package/adapters/smartWallet.ts +99 -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/localcofhe.ts +14 -0
  20. package/chains/chains/sepolia.ts +14 -0
  21. package/chains/chains.test.ts +50 -0
  22. package/chains/defineChain.ts +18 -0
  23. package/chains/index.ts +35 -0
  24. package/chains/types.ts +32 -0
  25. package/core/baseBuilder.ts +119 -0
  26. package/core/client.test.ts +429 -0
  27. package/core/client.ts +341 -0
  28. package/core/clientTypes.ts +119 -0
  29. package/core/config.test.ts +242 -0
  30. package/core/config.ts +225 -0
  31. package/core/consts.ts +22 -0
  32. package/core/decrypt/MockThresholdNetworkAbi.ts +179 -0
  33. package/core/decrypt/cofheMocksDecryptForTx.ts +84 -0
  34. package/core/decrypt/cofheMocksDecryptForView.ts +48 -0
  35. package/core/decrypt/decryptForTxBuilder.ts +359 -0
  36. package/core/decrypt/decryptForViewBuilder.ts +332 -0
  37. package/core/decrypt/decryptUtils.ts +28 -0
  38. package/core/decrypt/pollCallbacks.test.ts +194 -0
  39. package/core/decrypt/polling.ts +14 -0
  40. package/core/decrypt/tnDecryptUtils.ts +65 -0
  41. package/core/decrypt/tnDecryptV1.ts +171 -0
  42. package/core/decrypt/tnDecryptV2.ts +365 -0
  43. package/core/decrypt/tnSealOutputV1.ts +59 -0
  44. package/core/decrypt/tnSealOutputV2.ts +324 -0
  45. package/core/decrypt/verifyDecryptResult.ts +52 -0
  46. package/core/encrypt/MockZkVerifierAbi.ts +106 -0
  47. package/core/encrypt/cofheMocksZkVerifySign.ts +281 -0
  48. package/core/encrypt/encryptInputsBuilder.test.ts +747 -0
  49. package/core/encrypt/encryptInputsBuilder.ts +583 -0
  50. package/core/encrypt/encryptUtils.ts +67 -0
  51. package/core/encrypt/zkPackProveVerify.ts +335 -0
  52. package/core/error.ts +168 -0
  53. package/core/fetchKeys.test.ts +195 -0
  54. package/core/fetchKeys.ts +144 -0
  55. package/core/index.ts +106 -0
  56. package/core/keyStore.test.ts +226 -0
  57. package/core/keyStore.ts +154 -0
  58. package/core/permits.test.ts +493 -0
  59. package/core/permits.ts +201 -0
  60. package/core/types.ts +419 -0
  61. package/core/utils.ts +130 -0
  62. package/dist/adapters.cjs +88 -0
  63. package/dist/adapters.d.cts +14576 -0
  64. package/dist/adapters.d.ts +14576 -0
  65. package/dist/adapters.js +83 -0
  66. package/dist/chains.cjs +111 -0
  67. package/dist/chains.d.cts +121 -0
  68. package/dist/chains.d.ts +121 -0
  69. package/dist/chains.js +1 -0
  70. package/dist/chunk-36FBWLUS.js +3310 -0
  71. package/dist/chunk-7HLGHV67.js +990 -0
  72. package/dist/chunk-TBLR7NNE.js +102 -0
  73. package/dist/clientTypes-AVSCBet7.d.cts +998 -0
  74. package/dist/clientTypes-flH1ju82.d.ts +998 -0
  75. package/dist/core.cjs +4362 -0
  76. package/dist/core.d.cts +138 -0
  77. package/dist/core.d.ts +138 -0
  78. package/dist/core.js +3 -0
  79. package/dist/node.cjs +4225 -0
  80. package/dist/node.d.cts +22 -0
  81. package/dist/node.d.ts +22 -0
  82. package/dist/node.js +91 -0
  83. package/dist/permit-jRirYqFt.d.cts +376 -0
  84. package/dist/permit-jRirYqFt.d.ts +376 -0
  85. package/dist/permits.cjs +1025 -0
  86. package/dist/permits.d.cts +353 -0
  87. package/dist/permits.d.ts +353 -0
  88. package/dist/permits.js +1 -0
  89. package/dist/types-YiAC4gig.d.cts +33 -0
  90. package/dist/types-YiAC4gig.d.ts +33 -0
  91. package/dist/web.cjs +4434 -0
  92. package/dist/web.d.cts +42 -0
  93. package/dist/web.d.ts +42 -0
  94. package/dist/web.js +256 -0
  95. package/dist/zkProve.worker.cjs +93 -0
  96. package/dist/zkProve.worker.d.cts +2 -0
  97. package/dist/zkProve.worker.d.ts +2 -0
  98. package/dist/zkProve.worker.js +91 -0
  99. package/node/client.test.ts +159 -0
  100. package/node/config.test.ts +68 -0
  101. package/node/encryptInputs.test.ts +155 -0
  102. package/node/index.ts +97 -0
  103. package/node/storage.ts +51 -0
  104. package/package.json +121 -0
  105. package/permits/index.ts +68 -0
  106. package/permits/localstorage.test.ts +113 -0
  107. package/permits/onchain-utils.ts +221 -0
  108. package/permits/permit.test.ts +534 -0
  109. package/permits/permit.ts +386 -0
  110. package/permits/sealing.test.ts +84 -0
  111. package/permits/sealing.ts +131 -0
  112. package/permits/signature.ts +79 -0
  113. package/permits/store.test.ts +88 -0
  114. package/permits/store.ts +156 -0
  115. package/permits/test-utils.ts +28 -0
  116. package/permits/types.ts +204 -0
  117. package/permits/utils.ts +58 -0
  118. package/permits/validation.test.ts +361 -0
  119. package/permits/validation.ts +327 -0
  120. package/web/client.web.test.ts +159 -0
  121. package/web/config.web.test.ts +69 -0
  122. package/web/const.ts +2 -0
  123. package/web/encryptInputs.web.test.ts +172 -0
  124. package/web/index.ts +166 -0
  125. package/web/storage.ts +49 -0
  126. package/web/worker.builder.web.test.ts +148 -0
  127. package/web/worker.config.web.test.ts +329 -0
  128. package/web/worker.output.web.test.ts +84 -0
  129. package/web/workerManager.test.ts +80 -0
  130. package/web/workerManager.ts +214 -0
  131. package/web/workerManager.web.test.ts +114 -0
  132. package/web/zkProve.worker.ts +133 -0
@@ -0,0 +1,998 @@
1
+ import { WalletClient, PublicClient, Hex } from 'viem';
2
+ import { C as CofheChain } from './types-YiAC4gig.js';
3
+ import { z } from 'zod';
4
+ import { P as Permit, S as SerializedPermit, C as CreateSelfPermitOptions, m as SelfPermit, d as CreateSharingPermitOptions, n as SharingPermit, I as ImportSharedPermitOptions, R as RecipientPermit, o as PermitHashFields, g as PermitUtils } from './permit-jRirYqFt.js';
5
+ import { StoreApi } from 'zustand/vanilla';
6
+
7
+ type TfheInitializer = () => Promise<boolean>;
8
+ interface IStorage {
9
+ getItem: (name: string) => Promise<any>;
10
+ setItem: (name: string, value: any) => Promise<void>;
11
+ removeItem: (name: string) => Promise<void>;
12
+ }
13
+ type Primitive = null | undefined | string | number | boolean | symbol | bigint;
14
+ 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;
15
+ declare const FheTypeValues: readonly ["bool", "uint8", "uint16", "uint32", "uint64", "uint128", "address"];
16
+ type FheTypeValue = (typeof FheTypeValues)[number];
17
+ declare enum FheTypes {
18
+ Bool = 0,
19
+ Uint4 = 1,
20
+ Uint8 = 2,
21
+ Uint16 = 3,
22
+ Uint32 = 4,
23
+ Uint64 = 5,
24
+ Uint128 = 6,
25
+ Uint160 = 7,
26
+ Uint256 = 8,
27
+ Uint512 = 9,
28
+ Uint1024 = 10,
29
+ Uint2048 = 11,
30
+ Uint2 = 12,
31
+ Uint6 = 13,
32
+ Uint10 = 14,
33
+ Uint12 = 15,
34
+ Uint14 = 16,
35
+ Int2 = 17,
36
+ Int4 = 18,
37
+ Int6 = 19,
38
+ Int8 = 20,
39
+ Int10 = 21,
40
+ Int12 = 22,
41
+ Int14 = 23,
42
+ Int16 = 24,
43
+ Int32 = 25,
44
+ Int64 = 26,
45
+ Int128 = 27,
46
+ Int160 = 28,
47
+ Int256 = 29
48
+ }
49
+ /**
50
+ * List of All FHE uint types (excludes bool and address)
51
+ */
52
+ declare const FheUintUTypes: readonly [FheTypes.Uint8, FheTypes.Uint16, FheTypes.Uint32, FheTypes.Uint64, FheTypes.Uint128];
53
+ type FheUintUTypesType = (typeof FheUintUTypes)[number];
54
+ /**
55
+ * List of All FHE types (uints, bool, and address)
56
+ */
57
+ declare const FheAllUTypes: readonly [FheTypes.Bool, FheTypes.Uint8, FheTypes.Uint16, FheTypes.Uint32, FheTypes.Uint64, FheTypes.Uint128, FheTypes.Uint160];
58
+ type EncryptedNumber = {
59
+ data: Uint8Array;
60
+ securityZone: number;
61
+ };
62
+ type EncryptedItemInput<TSignature = string> = {
63
+ ctHash: bigint;
64
+ securityZone: number;
65
+ utype: FheTypes;
66
+ signature: TSignature;
67
+ };
68
+ declare function assertCorrectEncryptedItemInput(input: EncryptedItemInput): asserts input is EncryptedItemInput<`0x${string}`>;
69
+ type EncryptedBoolInput = EncryptedItemInput & {
70
+ utype: FheTypes.Bool;
71
+ };
72
+ type EncryptedUint8Input = EncryptedItemInput & {
73
+ utype: FheTypes.Uint8;
74
+ };
75
+ type EncryptedUint16Input = EncryptedItemInput & {
76
+ utype: FheTypes.Uint16;
77
+ };
78
+ type EncryptedUint32Input = EncryptedItemInput & {
79
+ utype: FheTypes.Uint32;
80
+ };
81
+ type EncryptedUint64Input = EncryptedItemInput & {
82
+ utype: FheTypes.Uint64;
83
+ };
84
+ type EncryptedUint128Input = EncryptedItemInput & {
85
+ utype: FheTypes.Uint128;
86
+ };
87
+ type EncryptedAddressInput = EncryptedItemInput & {
88
+ utype: FheTypes.Uint160;
89
+ };
90
+ type EncryptableBase<U extends FheTypes, D> = {
91
+ data: D;
92
+ securityZone: number;
93
+ utype: U;
94
+ };
95
+ type EncryptableBool = EncryptableBase<FheTypes.Bool, boolean>;
96
+ type EncryptableUint8 = EncryptableBase<FheTypes.Uint8, string | bigint>;
97
+ type EncryptableUint16 = EncryptableBase<FheTypes.Uint16, string | bigint>;
98
+ type EncryptableUint32 = EncryptableBase<FheTypes.Uint32, string | bigint>;
99
+ type EncryptableUint64 = EncryptableBase<FheTypes.Uint64, string | bigint>;
100
+ type EncryptableUint128 = EncryptableBase<FheTypes.Uint128, string | bigint>;
101
+ type EncryptableAddress = EncryptableBase<FheTypes.Uint160, string | bigint>;
102
+ declare function createEncryptableByLiteral(type: 'bool', data: EncryptableBool['data'], securityZone?: number): EncryptableBool;
103
+ declare function createEncryptableByLiteral(type: 'address', data: EncryptableAddress['data'], securityZone?: number): EncryptableAddress;
104
+ declare function createEncryptableByLiteral(type: 'uint8', data: EncryptableUint8['data'], securityZone?: number): EncryptableUint8;
105
+ declare function createEncryptableByLiteral(type: 'uint16', data: EncryptableUint16['data'], securityZone?: number): EncryptableUint16;
106
+ declare function createEncryptableByLiteral(type: 'uint32', data: EncryptableUint32['data'], securityZone?: number): EncryptableUint32;
107
+ declare function createEncryptableByLiteral(type: 'uint64', data: EncryptableUint64['data'], securityZone?: number): EncryptableUint64;
108
+ declare function createEncryptableByLiteral(type: 'uint128', data: EncryptableUint128['data'], securityZone?: number): EncryptableUint128;
109
+ declare function createEncryptableByLiteral(type: FheTypeValue, data: EncryptableItem['data'], securityZone?: number): EncryptableItem;
110
+ declare const Encryptable: {
111
+ create: typeof createEncryptableByLiteral;
112
+ bool: (data: EncryptableBool["data"], securityZone?: number | undefined) => {
113
+ data: boolean;
114
+ securityZone: number;
115
+ utype: FheTypes.Bool;
116
+ };
117
+ address: (data: EncryptableAddress["data"], securityZone?: number | undefined) => {
118
+ data: string | bigint;
119
+ securityZone: number;
120
+ utype: FheTypes.Uint160;
121
+ };
122
+ uint8: (data: EncryptableUint8["data"], securityZone?: number | undefined) => {
123
+ data: string | bigint;
124
+ securityZone: number;
125
+ utype: FheTypes.Uint8;
126
+ };
127
+ uint16: (data: EncryptableUint16["data"], securityZone?: number | undefined) => {
128
+ data: string | bigint;
129
+ securityZone: number;
130
+ utype: FheTypes.Uint16;
131
+ };
132
+ uint32: (data: EncryptableUint32["data"], securityZone?: number | undefined) => {
133
+ data: string | bigint;
134
+ securityZone: number;
135
+ utype: FheTypes.Uint32;
136
+ };
137
+ uint64: (data: EncryptableUint64["data"], securityZone?: number | undefined) => {
138
+ data: string | bigint;
139
+ securityZone: number;
140
+ utype: FheTypes.Uint64;
141
+ };
142
+ uint128: (data: EncryptableUint128["data"], securityZone?: number | undefined) => {
143
+ data: string | bigint;
144
+ securityZone: number;
145
+ utype: FheTypes.Uint128;
146
+ };
147
+ };
148
+ type EncryptableItem = EncryptableBool | EncryptableUint8 | EncryptableUint16 | EncryptableUint32 | EncryptableUint64 | EncryptableUint128 | EncryptableAddress;
149
+ 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;
150
+ type EncryptedItemInputs<T> = T extends Primitive ? LiteralToPrimitive<T> : T extends EncryptableItem ? EncryptableToEncryptedItemInputMap<T> : {
151
+ [K in keyof T]: EncryptedItemInputs<T[K]>;
152
+ };
153
+ declare function isEncryptableItem(value: unknown): value is EncryptableItem;
154
+ declare enum EncryptStep {
155
+ InitTfhe = "initTfhe",
156
+ FetchKeys = "fetchKeys",
157
+ Pack = "pack",
158
+ Prove = "prove",
159
+ Verify = "verify"
160
+ }
161
+ declare function isLastEncryptionStep(step: EncryptStep): boolean;
162
+ type EncryptStepCallbackContext = Record<string, any> & {
163
+ isStart: boolean;
164
+ isEnd: boolean;
165
+ duration: number;
166
+ };
167
+ type EncryptStepCallbackFunction = (state: EncryptStep, context?: EncryptStepCallbackContext) => void;
168
+ type DecryptEndpoint = 'decrypt' | 'sealoutput';
169
+ type DecryptPollCallbackContext = {
170
+ operation: DecryptEndpoint;
171
+ requestId: string;
172
+ attemptIndex: number;
173
+ elapsedMs: number;
174
+ intervalMs: number;
175
+ timeoutMs: number;
176
+ };
177
+ type DecryptPollCallbackFunction = (context: DecryptPollCallbackContext) => void;
178
+ /**
179
+ * Decrypted plaintext value returned by view-decryption helpers.
180
+ *
181
+ * This is a scalar JS value (not a wrapper object):
182
+ * - `boolean` for `FheTypes.Bool`
183
+ * - checksummed address `string` for `FheTypes.Uint160`
184
+ * - `bigint` for supported integer utypes
185
+ */
186
+ type UnsealedItem<U extends FheTypes> = U extends FheTypes.Bool ? boolean : U extends FheTypes.Uint160 ? string : U extends FheUintUTypesType ? bigint : never;
187
+
188
+ /**
189
+ * Usable config type inferred from the schema
190
+ */
191
+ type CofheConfig = {
192
+ /** Environment that the SDK is running in */
193
+ environment: 'node' | 'hardhat' | 'web' | 'react';
194
+ /** List of supported chains */
195
+ supportedChains: CofheChain[];
196
+ /** Default permit expiration in seconds, default is 30 days */
197
+ defaultPermitExpiration: number;
198
+ /**
199
+ * Storage scheme for the fetched fhe keys
200
+ * FHE keys are large, and caching prevents re-fetching them on each encryptInputs call
201
+ * (defaults to indexedDB on web, filesystem on node)
202
+ */
203
+ fheKeyStorage: IStorage | null;
204
+ /**
205
+ * Whether to use Web Workers for ZK proof generation (web platform only)
206
+ * When enabled, heavy WASM computation is offloaded to prevent UI freezing
207
+ * Default: true
208
+ */
209
+ useWorkers: boolean;
210
+ /** Mocks configs */
211
+ mocks: {
212
+ /**
213
+ * Length of the simulated seal output delay in milliseconds
214
+ * Default 1000ms on web
215
+ * Default 0ms on hardhat (will be called during tests no need for fake delay)
216
+ */
217
+ decryptDelay: number;
218
+ /**
219
+ * Simulated delay(s) in milliseconds for each step of encryptInputs in mock mode.
220
+ * A single number applies the same delay to all five steps (InitTfhe, FetchKeys, Pack, Prove, Verify).
221
+ * A tuple of five numbers applies a per-step delay: [InitTfhe, FetchKeys, Pack, Prove, Verify].
222
+ * Default: [100, 100, 100, 500, 500]
223
+ */
224
+ encryptDelay: number | [number, number, number, number, number];
225
+ };
226
+ _internal?: CofheInternalConfig;
227
+ };
228
+ type CofheInternalConfig = {
229
+ zkvWalletClient?: WalletClient;
230
+ };
231
+ /**
232
+ * Zod schema for configuration validation
233
+ */
234
+ declare const CofheConfigSchema: z.ZodObject<{
235
+ environment: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
236
+ hardhat: "hardhat";
237
+ node: "node";
238
+ web: "web";
239
+ react: "react";
240
+ }>>>;
241
+ supportedChains: z.ZodArray<z.ZodCustom<{
242
+ id: number;
243
+ name: string;
244
+ network: string;
245
+ coFheUrl: string;
246
+ verifierUrl: string;
247
+ thresholdNetworkUrl: string;
248
+ environment: "MOCK" | "TESTNET" | "MAINNET";
249
+ }, {
250
+ id: number;
251
+ name: string;
252
+ network: string;
253
+ coFheUrl: string;
254
+ verifierUrl: string;
255
+ thresholdNetworkUrl: string;
256
+ environment: "MOCK" | "TESTNET" | "MAINNET";
257
+ }>>;
258
+ defaultPermitExpiration: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
259
+ fheKeyStorage: z.ZodDefault<z.ZodUnion<[z.ZodObject<{
260
+ getItem: z.ZodCustom<(name: string) => Promise<any>, (name: string) => Promise<any>>;
261
+ setItem: z.ZodCustom<(name: string, value: any) => Promise<void>, (name: string, value: any) => Promise<void>>;
262
+ removeItem: z.ZodCustom<(name: string) => Promise<void>, (name: string) => Promise<void>>;
263
+ }, z.core.$strip>, z.ZodNull]>>;
264
+ useWorkers: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
265
+ mocks: z.ZodDefault<z.ZodOptional<z.ZodObject<{
266
+ decryptDelay: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
267
+ encryptDelay: z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber], null>]>>>;
268
+ }, z.core.$strip>>>;
269
+ _internal: z.ZodOptional<z.ZodObject<{
270
+ zkvWalletClient: z.ZodOptional<z.ZodAny>;
271
+ }, z.core.$strip>>;
272
+ }, z.core.$strip>;
273
+ /**
274
+ * Input config type inferred from the schema
275
+ */
276
+ type CofheInputConfig = z.input<typeof CofheConfigSchema>;
277
+ /**
278
+ * Creates and validates a cofhe configuration (base implementation)
279
+ * @param config - The configuration object to validate
280
+ * @returns The validated configuration
281
+ * @throws {Error} If the configuration is invalid
282
+ */
283
+ declare function createCofheConfigBase(config: CofheInputConfig): CofheConfig;
284
+ /**
285
+ * Access the CofheConfig object directly by providing the key.
286
+ * This is powerful when you use OnchainKit utilities outside of the React context.
287
+ */
288
+ declare const getCofheConfigItem: <K extends keyof CofheConfig>(config: CofheConfig, key: K) => CofheConfig[K];
289
+
290
+ /**
291
+ * Base parameters that all builders need
292
+ */
293
+ type BaseBuilderParams = {
294
+ config: CofheConfig | undefined;
295
+ publicClient: PublicClient | undefined;
296
+ walletClient: WalletClient | undefined;
297
+ chainId: number | undefined;
298
+ account: string | undefined;
299
+ requireConnected: (() => void) | undefined;
300
+ };
301
+ /**
302
+ * Abstract base class for builders that provides common functionality
303
+ * for working with clients, config, and chain IDs
304
+ */
305
+ declare abstract class BaseBuilder {
306
+ protected config: CofheConfig;
307
+ protected publicClient: PublicClient | undefined;
308
+ protected walletClient: WalletClient | undefined;
309
+ protected chainId: number | undefined;
310
+ protected account: string | undefined;
311
+ constructor(params: BaseBuilderParams);
312
+ /**
313
+ * Asserts that this.chainId is populated
314
+ * @throws {CofheError} If chainId is not set
315
+ */
316
+ protected assertChainId(): asserts this is this & {
317
+ chainId: number;
318
+ };
319
+ /**
320
+ * Asserts that this.account is populated
321
+ * @throws {CofheError} If account is not set
322
+ */
323
+ protected assertAccount(): asserts this is this & {
324
+ account: string;
325
+ };
326
+ /**
327
+ * Asserts that this.publicClient is populated
328
+ * @throws {CofheError} If publicClient is not set
329
+ */
330
+ protected assertPublicClient(): asserts this is this & {
331
+ publicClient: PublicClient;
332
+ };
333
+ /**
334
+ * Asserts that this.walletClient is populated
335
+ * @throws {CofheError} If walletClient is not set
336
+ */
337
+ protected assertWalletClient(): asserts this is this & {
338
+ walletClient: WalletClient;
339
+ };
340
+ }
341
+
342
+ /**
343
+ * API
344
+ *
345
+ * await client.decryptForView(ctHash, utype)
346
+ * .setChainId(chainId)
347
+ * .setAccount(account)
348
+ * .withPermit() // optional (active permit)
349
+ * // or .withPermit(permitHash) / .withPermit(permit)
350
+ * .execute()
351
+ *
352
+ * If chainId not set, uses client's chainId
353
+ * If account not set, uses client's account
354
+ * withPermit() uses chainId + account to get the active permit.
355
+ * withPermit(permitHash) fetches that permit using chainId + account.
356
+ * withPermit(permit) uses the provided permit regardless of chainId/account.
357
+ *
358
+ * Note: decryptForView always requires a permit (no global-allowance mode).
359
+ *
360
+ * Returns the unsealed item.
361
+ */
362
+ type DecryptForViewBuilderParams<U extends FheTypes> = BaseBuilderParams & {
363
+ ctHash: bigint | string;
364
+ utype: U;
365
+ permitHash?: string;
366
+ permit?: Permit;
367
+ };
368
+ declare class DecryptForViewBuilder<U extends FheTypes> extends BaseBuilder {
369
+ private ctHash;
370
+ private utype;
371
+ private permitHash?;
372
+ private permit?;
373
+ private pollCallback?;
374
+ constructor(params: DecryptForViewBuilderParams<U>);
375
+ /**
376
+ * @param chainId - Chain to decrypt values from. Used to fetch the threshold network URL and use the correct permit.
377
+ *
378
+ * If not provided, the chainId will be fetched from the connected publicClient.
379
+ *
380
+ * Example:
381
+ * ```typescript
382
+ * const unsealed = await client.decryptForView(ctHash, utype)
383
+ * .setChainId(11155111)
384
+ * .execute();
385
+ * ```
386
+ *
387
+ * @returns The chainable DecryptForViewBuilder instance.
388
+ */
389
+ setChainId(chainId: number): DecryptForViewBuilder<U>;
390
+ getChainId(): number | undefined;
391
+ /**
392
+ * @param account - Account to decrypt values from. Used to fetch the correct permit.
393
+ *
394
+ * If not provided, the account will be fetched from the connected walletClient.
395
+ *
396
+ * Example:
397
+ * ```typescript
398
+ * const unsealed = await client.decryptForView(ctHash, utype)
399
+ * .setAccount('0x1234567890123456789012345678901234567890')
400
+ * .execute();
401
+ * ```
402
+ *
403
+ * @returns The chainable DecryptForViewBuilder instance.
404
+ */
405
+ setAccount(account: string): DecryptForViewBuilder<U>;
406
+ getAccount(): string | undefined;
407
+ onPoll(callback: DecryptPollCallbackFunction): DecryptForViewBuilder<U>;
408
+ /**
409
+ * Select "use permit" mode (optional).
410
+ *
411
+ * - `withPermit(permit)` uses the provided permit.
412
+ * - `withPermit(permitHash)` fetches that permit.
413
+ * - `withPermit()` uses the active permit for the resolved `chainId + account`.
414
+ */
415
+ withPermit(): DecryptForViewBuilder<U>;
416
+ withPermit(permitHash: string): DecryptForViewBuilder<U>;
417
+ withPermit(permit: Permit): DecryptForViewBuilder<U>;
418
+ /**
419
+ * @param permitHash - Permit hash to decrypt values from. Used to fetch the correct permit.
420
+ *
421
+ * If not provided, the active permit for the chainId and account will be used.
422
+ * If `setPermit()` is called, it will be used regardless of chainId, account, or permitHash.
423
+ *
424
+ * Example:
425
+ * ```typescript
426
+ * const unsealed = await client.decryptForView(ctHash, utype)
427
+ * .setPermitHash('0x1234567890123456789012345678901234567890')
428
+ * .execute();
429
+ * ```
430
+ *
431
+ * @returns The chainable DecryptForViewBuilder instance.
432
+ */
433
+ /** @deprecated Use `withPermit(permitHash)` instead. */
434
+ setPermitHash(permitHash: string): DecryptForViewBuilder<U>;
435
+ getPermitHash(): string | undefined;
436
+ /**
437
+ * @param permit - Permit to decrypt values with. If provided, it will be used regardless of chainId, account, or permitHash.
438
+ *
439
+ * If not provided, the permit will be determined by chainId, account, and permitHash.
440
+ *
441
+ * Example:
442
+ * ```typescript
443
+ * const unsealed = await client.decryptForView(ctHash, utype)
444
+ * .setPermit(permit)
445
+ * .execute();
446
+ * ```
447
+ *
448
+ * @returns The chainable DecryptForViewBuilder instance.
449
+ */
450
+ /** @deprecated Use `withPermit(permit)` instead. */
451
+ setPermit(permit: Permit): DecryptForViewBuilder<U>;
452
+ getPermit(): Permit | undefined;
453
+ private getThresholdNetworkUrl;
454
+ private validateUtypeOrThrow;
455
+ private getResolvedPermit;
456
+ /**
457
+ * On hardhat, interact with MockZkVerifier contract instead of CoFHE
458
+ */
459
+ private mocksSealOutput;
460
+ /**
461
+ * In the production context, perform a true decryption with the CoFHE coprocessor.
462
+ */
463
+ private productionSealOutput;
464
+ /**
465
+ * Final step of the decryption process. MUST BE CALLED LAST IN THE CHAIN.
466
+ *
467
+ * This will:
468
+ * - Use a permit based on provided permit OR chainId + account + permitHash
469
+ * - Check permit validity
470
+ * - Call CoFHE `/sealoutput` with the permit, which returns a sealed (encrypted) item
471
+ * - Unseal the sealed item with the permit
472
+ * - Return the unsealed item
473
+ *
474
+ * Example:
475
+ * ```typescript
476
+ * const unsealed = await client.decryptForView(ctHash, utype)
477
+ * .setChainId(11155111) // optional
478
+ * .setAccount('0x123...890') // optional
479
+ * .withPermit() // optional
480
+ * .execute(); // execute
481
+ * ```
482
+ *
483
+ * @returns The unsealed item.
484
+ */
485
+ execute(): Promise<UnsealedItem<U>>;
486
+ }
487
+
488
+ type DecryptForTxBuilderParams = BaseBuilderParams & {
489
+ ctHash: bigint | string;
490
+ };
491
+ type DecryptForTxResult = {
492
+ ctHash: bigint | string;
493
+ decryptedValue: bigint;
494
+ signature: `0x${string}`;
495
+ };
496
+ /**
497
+ * Type-level gating:
498
+ * - The initial builder returned from `client.decryptForTx(...)` intentionally does not expose `execute()`.
499
+ * - Calling `withPermit(...)` or `withoutPermit()` returns a builder that *does* expose `execute()`, but no longer
500
+ * exposes `withPermit/withoutPermit` (so you can't select twice, or switch modes).
501
+ */
502
+ type DecryptForTxBuilderUnset = Omit<DecryptForTxBuilder, 'execute'>;
503
+ type DecryptForTxBuilderSelected = Omit<DecryptForTxBuilder, 'withPermit' | 'withoutPermit'>;
504
+ declare class DecryptForTxBuilder extends BaseBuilder {
505
+ private ctHash;
506
+ private permitHash?;
507
+ private permit?;
508
+ private permitSelection;
509
+ private pollCallback?;
510
+ constructor(params: DecryptForTxBuilderParams);
511
+ /**
512
+ * @param chainId - Chain to decrypt values from. Used to fetch the threshold network URL and use the correct permit.
513
+ *
514
+ * If not provided, the chainId will be fetched from the connected publicClient.
515
+ *
516
+ * Example:
517
+ * ```typescript
518
+ * const result = await decryptForTx(ctHash)
519
+ * .setChainId(11155111)
520
+ * .execute();
521
+ * ```
522
+ *
523
+ * @returns The chainable DecryptForTxBuilder instance.
524
+ */
525
+ setChainId(this: DecryptForTxBuilderUnset, chainId: number): DecryptForTxBuilderUnset;
526
+ setChainId(this: DecryptForTxBuilderSelected, chainId: number): DecryptForTxBuilderSelected;
527
+ getChainId(): number | undefined;
528
+ /**
529
+ * @param account - Account to decrypt values from. Used to fetch the correct permit.
530
+ *
531
+ * If not provided, the account will be fetched from the connected walletClient.
532
+ *
533
+ * Example:
534
+ * ```typescript
535
+ * const result = await decryptForTx(ctHash)
536
+ * .setAccount('0x1234567890123456789012345678901234567890')
537
+ * .execute();
538
+ * ```
539
+ *
540
+ * @returns The chainable DecryptForTxBuilder instance.
541
+ */
542
+ setAccount(this: DecryptForTxBuilderUnset, account: string): DecryptForTxBuilderUnset;
543
+ setAccount(this: DecryptForTxBuilderSelected, account: string): DecryptForTxBuilderSelected;
544
+ getAccount(): string | undefined;
545
+ onPoll(this: DecryptForTxBuilderUnset, callback: DecryptPollCallbackFunction): DecryptForTxBuilderUnset;
546
+ onPoll(this: DecryptForTxBuilderSelected, callback: DecryptPollCallbackFunction): DecryptForTxBuilderSelected;
547
+ /**
548
+ * Select "use permit" mode.
549
+ *
550
+ * - `withPermit(permit)` uses the provided permit.
551
+ * - `withPermit(permitHash)` fetches that permit.
552
+ * - `withPermit()` uses the active permit for the resolved `chainId + account`.
553
+ *
554
+ * Note: "global allowance" (no permit) is ONLY available via `withoutPermit()`.
555
+ */
556
+ withPermit(): DecryptForTxBuilderSelected;
557
+ withPermit(permitHash: string): DecryptForTxBuilderSelected;
558
+ withPermit(permit: Permit): DecryptForTxBuilderSelected;
559
+ /**
560
+ * Select "no permit" mode.
561
+ *
562
+ * This uses global allowance (no permit required) and sends an empty permission payload to `/decrypt`.
563
+ */
564
+ withoutPermit(): DecryptForTxBuilderSelected;
565
+ getPermit(): Permit | undefined;
566
+ getPermitHash(): string | undefined;
567
+ private getThresholdNetworkUrl;
568
+ private getResolvedPermit;
569
+ /**
570
+ * On hardhat, interact with MockThresholdNetwork contract
571
+ */
572
+ private mocksDecryptForTx;
573
+ /**
574
+ * In the production context, perform a true decryption with the CoFHE coprocessor.
575
+ */
576
+ private productionDecryptForTx;
577
+ /**
578
+ * Final step of the decryptForTx process. MUST BE CALLED LAST IN THE CHAIN.
579
+ *
580
+ * You must explicitly choose one permit mode before calling `execute()`:
581
+ * - `withPermit(permit)` / `withPermit(permitHash)` / `withPermit()` (active permit)
582
+ * - `withoutPermit()` (global allowance)
583
+ */
584
+ execute(): Promise<DecryptForTxResult>;
585
+ }
586
+
587
+ /**
588
+ * Worker function type for ZK proof generation
589
+ * Platform-specific implementations (web) can provide this to enable worker-based proofs
590
+ */
591
+ type ZkProveWorkerFunction = (fheKeyHex: string, crsHex: string, items: EncryptableItem[], metadata: Uint8Array) => Promise<Uint8Array>;
592
+ /**
593
+ * Message sent from main thread to worker to request proof generation
594
+ */
595
+ interface ZkProveWorkerRequest {
596
+ id: string;
597
+ type: 'zkProve';
598
+ fheKeyHex: string;
599
+ crsHex: string;
600
+ items: Array<{
601
+ utype: string;
602
+ data: any;
603
+ }>;
604
+ metadata: number[];
605
+ }
606
+ /**
607
+ * Message sent from worker back to main thread with proof result
608
+ */
609
+ interface ZkProveWorkerResponse {
610
+ id: string;
611
+ type: 'success' | 'error' | 'ready';
612
+ result?: number[];
613
+ error?: string;
614
+ }
615
+ type ZkProvenCiphertextList = {
616
+ serialize(): Uint8Array;
617
+ };
618
+ type ZkCompactPkeCrs = {
619
+ free(): void;
620
+ serialize(compress: boolean): Uint8Array;
621
+ safe_serialize(serialized_size_limit: bigint): Uint8Array;
622
+ };
623
+ type ZkCiphertextListBuilder = {
624
+ push_boolean(data: boolean): void;
625
+ push_u8(data: number): void;
626
+ push_u16(data: number): void;
627
+ push_u32(data: number): void;
628
+ push_u64(data: bigint): void;
629
+ push_u128(data: bigint): void;
630
+ push_u160(data: bigint): void;
631
+ build_with_proof_packed(crs: ZkCompactPkeCrs, metadata: Uint8Array, computeLoad: 1): ZkProvenCiphertextList;
632
+ };
633
+ type ZkBuilderAndCrsGenerator = (fhe: string, crs: string) => {
634
+ zkBuilder: ZkCiphertextListBuilder;
635
+ zkCrs: ZkCompactPkeCrs;
636
+ };
637
+ /**
638
+ * Generates ZK proof using Web Worker (offloads heavy WASM computation)
639
+ * Serializes items and calls the platform-specific worker function
640
+ * @param workerFn - Platform-specific worker function (provided by web/index.ts)
641
+ * @param fheKeyHex - Hex-encoded FHE public key for worker deserialization
642
+ * @param crsHex - Hex-encoded CRS for worker deserialization
643
+ * @param items - Encryptable items to pack in the worker
644
+ * @param metadata - Pre-constructed ZK PoK metadata
645
+ * @returns The serialized proven ciphertext list
646
+ */
647
+ declare const zkProveWithWorker: (workerFn: ZkProveWorkerFunction, fheKeyHex: string, crsHex: string, items: EncryptableItem[], metadata: Uint8Array) => Promise<Uint8Array>;
648
+
649
+ type ChainRecord<T> = Record<string, T>;
650
+ type SecurityZoneRecord<T> = Record<number, T>;
651
+ type KeysStore = {
652
+ fhe: ChainRecord<SecurityZoneRecord<string | undefined>>;
653
+ crs: ChainRecord<string | undefined>;
654
+ };
655
+ type KeysStorage = {
656
+ store: StoreApi<KeysStore>;
657
+ getFheKey: (chainId: number | undefined, securityZone?: number) => string | undefined;
658
+ getCrs: (chainId: number | undefined) => string | undefined;
659
+ setFheKey: (chainId: number, securityZone: number, key: string) => void;
660
+ setCrs: (chainId: number, crs: string) => void;
661
+ clearKeysStorage: () => Promise<void>;
662
+ rehydrateKeysStore: () => Promise<void>;
663
+ };
664
+ /**
665
+ * Creates a keys storage instance using the provided storage implementation
666
+ * @param storage - The storage implementation to use (IStorage interface), or null for non-persisted store
667
+ * @returns A KeysStorage instance with all utility methods
668
+ */
669
+ declare function createKeysStore(storage: IStorage | null): KeysStorage;
670
+
671
+ type FheKeyDeserializer = (buff: string) => void;
672
+ /**
673
+ * Retrieves the FHE public key and the CRS from the provider.
674
+ * If the key/crs already exists in the store it is returned, else it is fetched, stored, and returned
675
+ * @param {CofheConfig} config - The configuration object for the CoFHE client
676
+ * @param {number} chainId - The chain to fetch the FHE key for, if no chainId provided, undefined is returned
677
+ * @param securityZone - The security zone for which to retrieve the key (default 0).
678
+ * @param tfhePublicKeyDeserializer - The serializer for the FHE public key (used for validation).
679
+ * @param compactPkeCrsDeserializer - The serializer for the CRS (used for validation).
680
+ * @param keysStorage - The keys storage instance to use (optional)
681
+ * @returns {Promise<[[string, boolean], [string, boolean]]>} - A promise that resolves to [[fheKey, fheKeyFetchedFromCoFHE], [crs, crsFetchedFromCoFHE]]
682
+ */
683
+ declare const fetchKeys: (config: CofheConfig, chainId: number, securityZone: number | undefined, tfhePublicKeyDeserializer: FheKeyDeserializer, compactPkeCrsDeserializer: FheKeyDeserializer, keysStorage?: KeysStorage | null) => Promise<[[string, boolean], [string, boolean]]>;
684
+
685
+ type EncryptInputsBuilderParams<T extends EncryptableItem[]> = BaseBuilderParams & {
686
+ inputs: [...T];
687
+ securityZone?: number;
688
+ zkvWalletClient?: WalletClient | undefined;
689
+ tfhePublicKeyDeserializer: FheKeyDeserializer | undefined;
690
+ compactPkeCrsDeserializer: FheKeyDeserializer | undefined;
691
+ zkBuilderAndCrsGenerator: ZkBuilderAndCrsGenerator | undefined;
692
+ initTfhe: TfheInitializer | undefined;
693
+ zkProveWorkerFn: ZkProveWorkerFunction | undefined;
694
+ keysStorage: KeysStorage | undefined;
695
+ };
696
+ /**
697
+ * EncryptInputsBuilder exposes a builder pattern for encrypting inputs.
698
+ * account, securityZone, and chainId can be overridden in the builder.
699
+ * config, tfhePublicKeyDeserializer, compactPkeCrsDeserializer, and zkBuilderAndCrsGenerator are required to be set in the builder.
700
+ */
701
+ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuilder {
702
+ private securityZone;
703
+ private stepCallback?;
704
+ private inputItems;
705
+ private zkvWalletClient;
706
+ private tfhePublicKeyDeserializer;
707
+ private compactPkeCrsDeserializer;
708
+ private zkBuilderAndCrsGenerator;
709
+ private initTfhe;
710
+ private zkProveWorkerFn;
711
+ private keysStorage;
712
+ private useWorker;
713
+ private stepTimestamps;
714
+ constructor(params: EncryptInputsBuilderParams<T>);
715
+ /**
716
+ * @param account - Account that will create the tx using the encrypted inputs.
717
+ *
718
+ * If not provided, the account will be fetched from the connected walletClient.
719
+ *
720
+ * Example:
721
+ * ```typescript
722
+ * const encrypted = await encryptInputs([Encryptable.uint128(10n)])
723
+ * .setAccount("0x123")
724
+ * .execute();
725
+ * ```
726
+ *
727
+ * @returns The chainable EncryptInputsBuilder instance.
728
+ */
729
+ setAccount(account: string): EncryptInputsBuilder<T>;
730
+ getAccount(): string | undefined;
731
+ /**
732
+ * @param chainId - Chain that will consume the encrypted inputs.
733
+ *
734
+ * If not provided, the chainId will be fetched from the connected publicClient.
735
+ *
736
+ * Example:
737
+ * ```typescript
738
+ * const encrypted = await encryptInputs([Encryptable.uint128(10n)])
739
+ * .setChainId(11155111)
740
+ * .execute();
741
+ * ```
742
+ *
743
+ * @returns The chainable EncryptInputsBuilder instance.
744
+ */
745
+ setChainId(chainId: number): EncryptInputsBuilder<T>;
746
+ getChainId(): number | undefined;
747
+ /**
748
+ * @param securityZone - Security zone to encrypt the inputs for.
749
+ *
750
+ * If not provided, the default securityZone 0 will be used.
751
+ *
752
+ * Example:
753
+ * ```typescript
754
+ * const encrypted = await encryptInputs([Encryptable.uint128(10n)])
755
+ * .setSecurityZone(1)
756
+ * .execute();
757
+ * ```
758
+ *
759
+ * @returns The chainable EncryptInputsBuilder instance.
760
+ */
761
+ setSecurityZone(securityZone: number): EncryptInputsBuilder<T>;
762
+ getSecurityZone(): number;
763
+ /**
764
+ * @param useWorker - Whether to use Web Workers for ZK proof generation.
765
+ *
766
+ * Overrides the config-level useWorkers setting for this specific encryption.
767
+ *
768
+ * Example:
769
+ * ```typescript
770
+ * const encrypted = await encryptInputs([Encryptable.uint128(10n)])
771
+ * .setUseWorker(false)
772
+ * .execute();
773
+ * ```
774
+ *
775
+ * @returns The chainable EncryptInputsBuilder instance.
776
+ */
777
+ setUseWorker(useWorker: boolean): EncryptInputsBuilder<T>;
778
+ /**
779
+ * Gets the current worker configuration.
780
+ *
781
+ * @returns Whether Web Workers are enabled for this encryption.
782
+ *
783
+ * Example:
784
+ * ```typescript
785
+ * const builder = encryptInputs([Encryptable.uint128(10n)]);
786
+ * console.log(builder.getUseWorker()); // true (from config)
787
+ * builder.setUseWorker(false);
788
+ * console.log(builder.getUseWorker()); // false (overridden)
789
+ * ```
790
+ */
791
+ getUseWorker(): boolean;
792
+ /**
793
+ * @param callback - Function to be called with the encryption step.
794
+ *
795
+ * Useful for debugging and tracking the progress of the encryption process.
796
+ * Useful for a UI element that shows the progress of the encryption process.
797
+ *
798
+ * Example:
799
+ * ```typescript
800
+ * const encrypted = await encryptInputs([Encryptable.uint128(10n)])
801
+ * .onStep((step: EncryptStep) => console.log(step))
802
+ * .execute();
803
+ * ```
804
+ *
805
+ * @returns The EncryptInputsBuilder instance.
806
+ */
807
+ onStep(callback: EncryptStepCallbackFunction): EncryptInputsBuilder<T>;
808
+ getStepCallback(): EncryptStepCallbackFunction | undefined;
809
+ /**
810
+ * Fires the step callback if set
811
+ */
812
+ private fireStepStart;
813
+ private fireStepEnd;
814
+ /**
815
+ * zkVerifierUrl is included in the chains exported from @cofhe/sdk/chains for use in CofheConfig.supportedChains
816
+ * Users should generally not set this manually.
817
+ */
818
+ private getZkVerifierUrl;
819
+ /**
820
+ * initTfhe is a platform-specific dependency injected into core/createCofheClientBase by web/createCofheClient and node/createCofheClient
821
+ * web/ uses zama "tfhe"
822
+ * node/ uses zama "node-tfhe"
823
+ * Users should not set this manually.
824
+ */
825
+ private initTfheOrThrow;
826
+ /**
827
+ * Fetches the FHE key and CRS from the CoFHE API
828
+ * If the key/crs already exists in the store it is returned, else it is fetched, stored, and returned
829
+ */
830
+ private fetchFheKeyAndCrs;
831
+ /**
832
+ * Resolves the encryptDelay config into an array of 5 per-step delays.
833
+ * A single number is broadcast to all steps; a tuple is used as-is.
834
+ */
835
+ private resolveEncryptDelays;
836
+ /**
837
+ * @dev Encrypt against the cofheMocks instead of CoFHE
838
+ *
839
+ * In the cofheMocks, the MockZkVerifier contract is deployed on hardhat to a fixed address, this contract handles mocking the zk verifying.
840
+ * cofheMocksInsertPackedHashes - stores the ctHashes and their plaintext values for on-chain mocking of FHE operations.
841
+ * cofheMocksZkCreateProofSignatures - creates signatures to be included in the encrypted inputs. The signers address is known and verified in the mock contracts.
842
+ */
843
+ private mocksExecute;
844
+ /**
845
+ * In the production context, perform a true encryption with the CoFHE coprocessor.
846
+ */
847
+ private productionExecute;
848
+ /**
849
+ * Final step of the encryption process. MUST BE CALLED LAST IN THE CHAIN.
850
+ *
851
+ * This will:
852
+ * - Pack the encryptable items into a zk proof
853
+ * - Prove the zk proof
854
+ * - Verify the zk proof with CoFHE
855
+ * - Package and return the encrypted inputs
856
+ *
857
+ * Example:
858
+ * ```typescript
859
+ * const encrypted = await encryptInputs([Encryptable.uint128(10n)])
860
+ * .setAccount('0x123...890') // optional
861
+ * .setChainId(11155111) // optional
862
+ * .execute(); // execute
863
+ * ```
864
+ *
865
+ * @returns The encrypted inputs.
866
+ */
867
+ execute(): Promise<[...EncryptedItemInputs<T>]>;
868
+ }
869
+
870
+ declare const permits: {
871
+ getSnapshot: () => {
872
+ permits: {
873
+ [x: number]: {
874
+ [x: string]: {
875
+ [x: string]: SerializedPermit | undefined;
876
+ };
877
+ };
878
+ };
879
+ activePermitHash: {
880
+ [x: number]: {
881
+ [x: string]: string | undefined;
882
+ };
883
+ };
884
+ };
885
+ subscribe: (listener: (state: {
886
+ permits: {
887
+ [x: number]: {
888
+ [x: string]: {
889
+ [x: string]: SerializedPermit | undefined;
890
+ };
891
+ };
892
+ };
893
+ activePermitHash: {
894
+ [x: number]: {
895
+ [x: string]: string | undefined;
896
+ };
897
+ };
898
+ }, prevState: {
899
+ permits: {
900
+ [x: number]: {
901
+ [x: string]: {
902
+ [x: string]: SerializedPermit | undefined;
903
+ };
904
+ };
905
+ };
906
+ activePermitHash: {
907
+ [x: number]: {
908
+ [x: string]: string | undefined;
909
+ };
910
+ };
911
+ }) => void) => () => void;
912
+ createSelf: (options: CreateSelfPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SelfPermit>;
913
+ createSharing: (options: CreateSharingPermitOptions, publicClient: PublicClient, walletClient: WalletClient) => Promise<SharingPermit>;
914
+ importShared: (options: ImportSharedPermitOptions | string, publicClient: PublicClient, walletClient: WalletClient) => Promise<RecipientPermit>;
915
+ getOrCreateSelfPermit: (publicClient: PublicClient, walletClient: WalletClient, chainId?: number, account?: string, options?: CreateSelfPermitOptions) => Promise<Permit>;
916
+ getOrCreateSharingPermit: (publicClient: PublicClient, walletClient: WalletClient, options: CreateSharingPermitOptions, chainId?: number, account?: string) => Promise<Permit>;
917
+ getHash: (permit: PermitHashFields) => string;
918
+ serialize: (permit: Permit) => SerializedPermit;
919
+ deserialize: (serialized: SerializedPermit) => Permit;
920
+ getPermit: (chainId: number, account: string, hash: string) => Permit | undefined;
921
+ getPermits: (chainId: number, account: string) => Record<string, Permit>;
922
+ getActivePermit: (chainId: number, account: string) => Permit | undefined;
923
+ getActivePermitHash: (chainId: number, account: string) => string | undefined;
924
+ removePermit: (chainId: number, account: string, hash: string) => Promise<void>;
925
+ selectActivePermit: (chainId: number, account: string, hash: string) => void;
926
+ removeActivePermit: (chainId: number, account: string) => Promise<void>;
927
+ };
928
+
929
+ type CofheClient<TConfig extends CofheConfig = CofheConfig> = {
930
+ getSnapshot(): CofheClientConnectionState;
931
+ subscribe(listener: Listener): () => void;
932
+ readonly connection: CofheClientConnectionState;
933
+ readonly connected: boolean;
934
+ readonly connecting: boolean;
935
+ readonly config: TConfig;
936
+ connect(publicClient: PublicClient, walletClient: WalletClient): Promise<void>;
937
+ /**
938
+ * Clears the current connection state (account/chainId/clients) and marks the client as disconnected.
939
+ *
940
+ * This does not delete persisted permits or stored FHE keys; it only resets the in-memory connection.
941
+ */
942
+ disconnect(): void;
943
+ /**
944
+ * Types docstring
945
+ */
946
+ encryptInputs<T extends EncryptableItem[]>(inputs: [...T]): EncryptInputsBuilder<[...T]>;
947
+ /**
948
+ * @deprecated Use `decryptForView` instead. Kept for backward compatibility.
949
+ */
950
+ decryptHandle<U extends FheTypes>(ctHash: bigint | string, utype: U): DecryptForViewBuilder<U>;
951
+ decryptForView<U extends FheTypes>(ctHash: bigint | string, utype: U): DecryptForViewBuilder<U>;
952
+ decryptForTx(ctHash: bigint | string): DecryptForTxBuilderUnset;
953
+ verifyDecryptResult(handle: bigint | string, cleartext: bigint, signature: Hex): Promise<boolean>;
954
+ permits: CofheClientPermits;
955
+ };
956
+ type CofheClientConnectionState = {
957
+ connected: boolean;
958
+ connecting: boolean;
959
+ connectError: unknown | undefined;
960
+ chainId: number | undefined;
961
+ account: `0x${string}` | undefined;
962
+ publicClient: PublicClient | undefined;
963
+ walletClient: WalletClient | undefined;
964
+ };
965
+ type Listener = (snapshot: CofheClientConnectionState) => void;
966
+ type CofheClientPermitsClients = {
967
+ publicClient: PublicClient;
968
+ walletClient: WalletClient;
969
+ };
970
+ type CofheClientPermits = {
971
+ getSnapshot: typeof permits.getSnapshot;
972
+ subscribe: typeof permits.subscribe;
973
+ createSelf: (options: CreateSelfPermitOptions, clients?: CofheClientPermitsClients) => Promise<SelfPermit>;
974
+ createSharing: (options: CreateSharingPermitOptions, clients?: CofheClientPermitsClients) => Promise<SharingPermit>;
975
+ importShared: (options: ImportSharedPermitOptions | string, clients?: CofheClientPermitsClients) => Promise<RecipientPermit>;
976
+ getPermit: (hash: string, chainId?: number, account?: string) => Permit | undefined;
977
+ getPermits: (chainId?: number, account?: string) => Record<string, Permit>;
978
+ getActivePermit: (chainId?: number, account?: string) => Permit | undefined;
979
+ getActivePermitHash: (chainId?: number, account?: string) => string | undefined;
980
+ getOrCreateSelfPermit: (chainId?: number, account?: string, options?: CreateSelfPermitOptions) => Promise<Permit>;
981
+ getOrCreateSharingPermit: (options: CreateSharingPermitOptions, chainId?: number, account?: string) => Promise<Permit>;
982
+ selectActivePermit: (hash: string, chainId?: number, account?: string) => void;
983
+ removePermit: (hash: string, chainId?: number, account?: string) => void;
984
+ removeActivePermit: (chainId?: number, account?: string) => void;
985
+ getHash: typeof PermitUtils.getHash;
986
+ serialize: typeof PermitUtils.serialize;
987
+ deserialize: typeof PermitUtils.deserialize;
988
+ };
989
+ type CofheClientParams<TConfig extends CofheConfig> = {
990
+ config: TConfig;
991
+ zkBuilderAndCrsGenerator: ZkBuilderAndCrsGenerator;
992
+ tfhePublicKeyDeserializer: FheKeyDeserializer;
993
+ compactPkeCrsDeserializer: FheKeyDeserializer;
994
+ initTfhe: TfheInitializer;
995
+ zkProveWorkerFn?: ZkProveWorkerFunction;
996
+ };
997
+
998
+ export { DecryptForTxBuilder as $, type FheTypeValue as A, type DecryptPollCallbackContext as B, type CofheInputConfig as C, type DecryptPollCallbackFunction as D, type EncryptableItem as E, FheTypes as F, type DecryptEndpoint as G, type EncryptStepCallbackFunction as H, type IStorage as I, type EncryptStepCallbackContext as J, FheUintUTypes as K, type LiteralToPrimitive as L, FheAllUTypes as M, Encryptable as N, isEncryptableItem as O, type Primitive as P, EncryptStep as Q, isLastEncryptionStep as R, assertCorrectEncryptedItemInput as S, fetchKeys as T, type UnsealedItem as U, type FheKeyDeserializer as V, createKeysStore as W, type KeysStorage as X, type KeysStore as Y, EncryptInputsBuilder as Z, DecryptForViewBuilder as _, type CofheConfig as a, type DecryptForTxResult as a0, type ZkBuilderAndCrsGenerator as a1, type ZkProveWorkerFunction as a2, type ZkProveWorkerRequest as a3, type ZkProveWorkerResponse as a4, zkProveWithWorker as a5, type CofheClient as b, type CofheClientConnectionState as c, type CofheClientParams as d, createCofheConfigBase as e, type CofheInternalConfig as f, getCofheConfigItem as g, type CofheClientPermits 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 EncryptedAddressInput as x, type EncryptedItemInputs as y, type EncryptableToEncryptedItemInputMap as z };