@cofhe/sdk 0.2.1 → 0.3.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 (54) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/core/baseBuilder.ts +18 -18
  3. package/core/client.test.ts +58 -55
  4. package/core/client.ts +50 -30
  5. package/core/clientTypes.ts +21 -17
  6. package/core/config.test.ts +32 -33
  7. package/core/config.ts +47 -48
  8. package/core/consts.ts +6 -2
  9. package/core/decrypt/{MockQueryDecrypterAbi.ts → MockThresholdNetworkAbi.ts} +71 -21
  10. package/core/decrypt/cofheMocksDecryptForTx.ts +142 -0
  11. package/core/decrypt/{cofheMocksSealOutput.ts → cofheMocksDecryptForView.ts} +12 -12
  12. package/core/decrypt/decryptForTxBuilder.ts +340 -0
  13. package/core/decrypt/{decryptHandleBuilder.ts → decryptForViewBuilder.ts} +75 -42
  14. package/core/decrypt/tnDecrypt.ts +232 -0
  15. package/core/decrypt/tnSealOutputV1.ts +5 -5
  16. package/core/decrypt/tnSealOutputV2.ts +27 -27
  17. package/core/encrypt/cofheMocksZkVerifySign.ts +15 -15
  18. package/core/encrypt/encryptInputsBuilder.test.ts +57 -61
  19. package/core/encrypt/encryptInputsBuilder.ts +65 -42
  20. package/core/encrypt/zkPackProveVerify.ts +11 -11
  21. package/core/error.ts +18 -18
  22. package/core/fetchKeys.test.ts +3 -3
  23. package/core/fetchKeys.ts +3 -3
  24. package/core/index.ts +14 -11
  25. package/core/utils.ts +10 -10
  26. package/dist/{chunk-I5WFEYXX.js → chunk-2TPSCOW3.js} +791 -209
  27. package/dist/{chunk-R3B5TMVX.js → chunk-NWDKXBIP.js} +3 -2
  28. package/dist/{clientTypes-RqkgkV2i.d.ts → clientTypes-6aTZPQ_4.d.ts} +204 -85
  29. package/dist/{clientTypes-e4filDzK.d.cts → clientTypes-Bhq7pCSA.d.cts} +204 -85
  30. package/dist/core.cjs +799 -214
  31. package/dist/core.d.cts +25 -23
  32. package/dist/core.d.ts +25 -23
  33. package/dist/core.js +2 -2
  34. package/dist/node.cjs +748 -165
  35. package/dist/node.d.cts +10 -10
  36. package/dist/node.d.ts +10 -10
  37. package/dist/node.js +7 -7
  38. package/dist/permits.js +1 -1
  39. package/dist/web.cjs +751 -168
  40. package/dist/web.d.cts +11 -11
  41. package/dist/web.d.ts +11 -11
  42. package/dist/web.js +9 -9
  43. package/node/client.test.ts +34 -34
  44. package/node/config.test.ts +11 -11
  45. package/node/encryptInputs.test.ts +29 -29
  46. package/node/index.ts +15 -15
  47. package/package.json +3 -3
  48. package/web/client.web.test.ts +34 -34
  49. package/web/config.web.test.ts +11 -11
  50. package/web/encryptInputs.web.test.ts +29 -29
  51. package/web/index.ts +19 -19
  52. package/web/worker.builder.web.test.ts +28 -28
  53. package/web/worker.config.web.test.ts +47 -47
  54. package/web/worker.output.web.test.ts +10 -10
@@ -170,18 +170,11 @@ type UnsealedItem<U extends FheTypes> = U extends FheTypes.Bool ? boolean : U ex
170
170
  /**
171
171
  * Usable config type inferred from the schema
172
172
  */
173
- type CofhesdkConfig = {
173
+ type CofheConfig = {
174
174
  /** Environment that the SDK is running in */
175
175
  environment: 'node' | 'hardhat' | 'web' | 'react';
176
176
  /** List of supported chains */
177
177
  supportedChains: CofheChain[];
178
- /**
179
- * How permits are generated
180
- * - ON_CONNECT: Generate a permit when client.connect() is called
181
- * - ON_DECRYPT_HANDLES: Generate a permit when client.decryptHandles() is called
182
- * - MANUAL: Generate a permit manually using client.generatePermit()
183
- */
184
- permitGeneration: 'ON_CONNECT' | 'ON_DECRYPT_HANDLES' | 'MANUAL';
185
178
  /** Default permit expiration in seconds, default is 30 days */
186
179
  defaultPermitExpiration: number;
187
180
  /**
@@ -203,17 +196,24 @@ type CofhesdkConfig = {
203
196
  * Default 1000ms on web
204
197
  * Default 0ms on hardhat (will be called during tests no need for fake delay)
205
198
  */
206
- sealOutputDelay: number;
199
+ decryptDelay: number;
200
+ /**
201
+ * Simulated delay(s) in milliseconds for each step of encryptInputs in mock mode.
202
+ * A single number applies the same delay to all five steps (InitTfhe, FetchKeys, Pack, Prove, Verify).
203
+ * A tuple of five numbers applies a per-step delay: [InitTfhe, FetchKeys, Pack, Prove, Verify].
204
+ * Default: [100, 100, 100, 500, 500]
205
+ */
206
+ encryptDelay: number | [number, number, number, number, number];
207
207
  };
208
- _internal?: CofhesdkInternalConfig;
208
+ _internal?: CofheInternalConfig;
209
209
  };
210
- type CofhesdkInternalConfig = {
210
+ type CofheInternalConfig = {
211
211
  zkvWalletClient?: WalletClient;
212
212
  };
213
213
  /**
214
214
  * Zod schema for configuration validation
215
215
  */
216
- declare const CofhesdkConfigSchema: z.ZodObject<{
216
+ declare const CofheConfigSchema: z.ZodObject<{
217
217
  environment: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
218
218
  hardhat: "hardhat";
219
219
  node: "node";
@@ -237,11 +237,6 @@ declare const CofhesdkConfigSchema: z.ZodObject<{
237
237
  thresholdNetworkUrl: string;
238
238
  environment: "MOCK" | "TESTNET" | "MAINNET";
239
239
  }>>;
240
- permitGeneration: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
241
- ON_CONNECT: "ON_CONNECT";
242
- ON_DECRYPT_HANDLES: "ON_DECRYPT_HANDLES";
243
- MANUAL: "MANUAL";
244
- }>>>;
245
240
  defaultPermitExpiration: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
246
241
  fheKeyStorage: z.ZodDefault<z.ZodUnion<[z.ZodObject<{
247
242
  getItem: z.ZodCustom<(name: string) => Promise<any>, (name: string) => Promise<any>>;
@@ -250,7 +245,8 @@ declare const CofhesdkConfigSchema: z.ZodObject<{
250
245
  }, z.core.$strip>, z.ZodNull]>>;
251
246
  useWorkers: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
252
247
  mocks: z.ZodDefault<z.ZodOptional<z.ZodObject<{
253
- sealOutputDelay: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
248
+ decryptDelay: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
249
+ encryptDelay: z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber], null>]>>>;
254
250
  }, z.core.$strip>>>;
255
251
  _internal: z.ZodOptional<z.ZodObject<{
256
252
  zkvWalletClient: z.ZodOptional<z.ZodAny>;
@@ -259,25 +255,25 @@ declare const CofhesdkConfigSchema: z.ZodObject<{
259
255
  /**
260
256
  * Input config type inferred from the schema
261
257
  */
262
- type CofhesdkInputConfig = z.input<typeof CofhesdkConfigSchema>;
258
+ type CofheInputConfig = z.input<typeof CofheConfigSchema>;
263
259
  /**
264
- * Creates and validates a cofhesdk configuration (base implementation)
260
+ * Creates and validates a cofhe configuration (base implementation)
265
261
  * @param config - The configuration object to validate
266
262
  * @returns The validated configuration
267
263
  * @throws {Error} If the configuration is invalid
268
264
  */
269
- declare function createCofhesdkConfigBase(config: CofhesdkInputConfig): CofhesdkConfig;
265
+ declare function createCofheConfigBase(config: CofheInputConfig): CofheConfig;
270
266
  /**
271
- * Access the CofhesdkConfig object directly by providing the key.
267
+ * Access the CofheConfig object directly by providing the key.
272
268
  * This is powerful when you use OnchainKit utilities outside of the React context.
273
269
  */
274
- declare const getCofhesdkConfigItem: <K extends keyof CofhesdkConfig>(config: CofhesdkConfig, key: K) => CofhesdkConfig[K];
270
+ declare const getCofheConfigItem: <K extends keyof CofheConfig>(config: CofheConfig, key: K) => CofheConfig[K];
275
271
 
276
272
  /**
277
273
  * Base parameters that all builders need
278
274
  */
279
275
  type BaseBuilderParams = {
280
- config: CofhesdkConfig | undefined;
276
+ config: CofheConfig | undefined;
281
277
  publicClient: PublicClient | undefined;
282
278
  walletClient: WalletClient | undefined;
283
279
  chainId: number | undefined;
@@ -289,7 +285,7 @@ type BaseBuilderParams = {
289
285
  * for working with clients, config, and chain IDs
290
286
  */
291
287
  declare abstract class BaseBuilder {
292
- protected config: CofhesdkConfig;
288
+ protected config: CofheConfig;
293
289
  protected publicClient: PublicClient | undefined;
294
290
  protected walletClient: WalletClient | undefined;
295
291
  protected chainId: number | undefined;
@@ -297,28 +293,28 @@ declare abstract class BaseBuilder {
297
293
  constructor(params: BaseBuilderParams);
298
294
  /**
299
295
  * Asserts that this.chainId is populated
300
- * @throws {CofhesdkError} If chainId is not set
296
+ * @throws {CofheError} If chainId is not set
301
297
  */
302
298
  protected assertChainId(): asserts this is this & {
303
299
  chainId: number;
304
300
  };
305
301
  /**
306
302
  * Asserts that this.account is populated
307
- * @throws {CofhesdkError} If account is not set
303
+ * @throws {CofheError} If account is not set
308
304
  */
309
305
  protected assertAccount(): asserts this is this & {
310
306
  account: string;
311
307
  };
312
308
  /**
313
309
  * Asserts that this.publicClient is populated
314
- * @throws {CofhesdkError} If publicClient is not set
310
+ * @throws {CofheError} If publicClient is not set
315
311
  */
316
312
  protected assertPublicClient(): asserts this is this & {
317
313
  publicClient: PublicClient;
318
314
  };
319
315
  /**
320
316
  * Asserts that this.walletClient is populated
321
- * @throws {CofhesdkError} If walletClient is not set
317
+ * @throws {CofheError} If walletClient is not set
322
318
  */
323
319
  protected assertWalletClient(): asserts this is this & {
324
320
  walletClient: WalletClient;
@@ -328,32 +324,35 @@ declare abstract class BaseBuilder {
328
324
  /**
329
325
  * API
330
326
  *
331
- * await client.decryptHandle(ctHash, utype)
327
+ * await client.decryptForView(ctHash, utype)
332
328
  * .setChainId(chainId)
333
329
  * .setAccount(account)
334
- * .setPermitHash(permitHash)
335
- * .setPermit(permit)
336
- * .decrypt()
330
+ * .withPermit() // optional (active permit)
331
+ * // or .withPermit(permitHash) / .withPermit(permit)
332
+ * .execute()
337
333
  *
338
334
  * If chainId not set, uses client's chainId
339
335
  * If account not set, uses client's account
340
- * If permitHash not set, uses chainId and account to get active permit
341
- * If permit is set, uses permit to decrypt regardless of chainId, account, or permitHash
336
+ * withPermit() uses chainId + account to get the active permit.
337
+ * withPermit(permitHash) fetches that permit using chainId + account.
338
+ * withPermit(permit) uses the provided permit regardless of chainId/account.
339
+ *
340
+ * Note: decryptForView always requires a permit (no global-allowance mode).
342
341
  *
343
342
  * Returns the unsealed item.
344
343
  */
345
- type DecryptHandlesBuilderParams<U extends FheTypes> = BaseBuilderParams & {
344
+ type DecryptForViewBuilderParams<U extends FheTypes> = BaseBuilderParams & {
346
345
  ctHash: bigint;
347
346
  utype: U;
348
347
  permitHash?: string;
349
348
  permit?: Permit;
350
349
  };
351
- declare class DecryptHandlesBuilder<U extends FheTypes> extends BaseBuilder {
350
+ declare class DecryptForViewBuilder<U extends FheTypes> extends BaseBuilder {
352
351
  private ctHash;
353
352
  private utype;
354
353
  private permitHash?;
355
354
  private permit?;
356
- constructor(params: DecryptHandlesBuilderParams<U>);
355
+ constructor(params: DecryptForViewBuilderParams<U>);
357
356
  /**
358
357
  * @param chainId - Chain to decrypt values from. Used to fetch the threshold network URL and use the correct permit.
359
358
  *
@@ -361,14 +360,14 @@ declare class DecryptHandlesBuilder<U extends FheTypes> extends BaseBuilder {
361
360
  *
362
361
  * Example:
363
362
  * ```typescript
364
- * const unsealed = await decryptHandle(ctHash, utype)
363
+ * const unsealed = await client.decryptForView(ctHash, utype)
365
364
  * .setChainId(11155111)
366
- * .decrypt();
365
+ * .execute();
367
366
  * ```
368
367
  *
369
- * @returns The chainable DecryptHandlesBuilder instance.
368
+ * @returns The chainable DecryptForViewBuilder instance.
370
369
  */
371
- setChainId(chainId: number): DecryptHandlesBuilder<U>;
370
+ setChainId(chainId: number): DecryptForViewBuilder<U>;
372
371
  getChainId(): number | undefined;
373
372
  /**
374
373
  * @param account - Account to decrypt values from. Used to fetch the correct permit.
@@ -377,15 +376,25 @@ declare class DecryptHandlesBuilder<U extends FheTypes> extends BaseBuilder {
377
376
  *
378
377
  * Example:
379
378
  * ```typescript
380
- * const unsealed = await decryptHandle(ctHash, utype)
379
+ * const unsealed = await client.decryptForView(ctHash, utype)
381
380
  * .setAccount('0x1234567890123456789012345678901234567890')
382
- * .decrypt();
381
+ * .execute();
383
382
  * ```
384
383
  *
385
- * @returns The chainable DecryptHandlesBuilder instance.
384
+ * @returns The chainable DecryptForViewBuilder instance.
386
385
  */
387
- setAccount(account: string): DecryptHandlesBuilder<U>;
386
+ setAccount(account: string): DecryptForViewBuilder<U>;
388
387
  getAccount(): string | undefined;
388
+ /**
389
+ * Select "use permit" mode (optional).
390
+ *
391
+ * - `withPermit(permit)` uses the provided permit.
392
+ * - `withPermit(permitHash)` fetches that permit.
393
+ * - `withPermit()` uses the active permit for the resolved `chainId + account`.
394
+ */
395
+ withPermit(): DecryptForViewBuilder<U>;
396
+ withPermit(permitHash: string): DecryptForViewBuilder<U>;
397
+ withPermit(permit: Permit): DecryptForViewBuilder<U>;
389
398
  /**
390
399
  * @param permitHash - Permit hash to decrypt values from. Used to fetch the correct permit.
391
400
  *
@@ -394,14 +403,15 @@ declare class DecryptHandlesBuilder<U extends FheTypes> extends BaseBuilder {
394
403
  *
395
404
  * Example:
396
405
  * ```typescript
397
- * const unsealed = await decryptHandle(ctHash, utype)
406
+ * const unsealed = await client.decryptForView(ctHash, utype)
398
407
  * .setPermitHash('0x1234567890123456789012345678901234567890')
399
- * .decrypt();
408
+ * .execute();
400
409
  * ```
401
410
  *
402
- * @returns The chainable DecryptHandlesBuilder instance.
411
+ * @returns The chainable DecryptForViewBuilder instance.
403
412
  */
404
- setPermitHash(permitHash: string): DecryptHandlesBuilder<U>;
413
+ /** @deprecated Use `withPermit(permitHash)` instead. */
414
+ setPermitHash(permitHash: string): DecryptForViewBuilder<U>;
405
415
  getPermitHash(): string | undefined;
406
416
  /**
407
417
  * @param permit - Permit to decrypt values with. If provided, it will be used regardless of chainId, account, or permitHash.
@@ -410,14 +420,15 @@ declare class DecryptHandlesBuilder<U extends FheTypes> extends BaseBuilder {
410
420
  *
411
421
  * Example:
412
422
  * ```typescript
413
- * const unsealed = await decryptHandle(ctHash, utype)
423
+ * const unsealed = await client.decryptForView(ctHash, utype)
414
424
  * .setPermit(permit)
415
- * .decrypt();
425
+ * .execute();
416
426
  * ```
417
427
  *
418
- * @returns The chainable DecryptHandlesBuilder instance.
428
+ * @returns The chainable DecryptForViewBuilder instance.
419
429
  */
420
- setPermit(permit: Permit): DecryptHandlesBuilder<U>;
430
+ /** @deprecated Use `withPermit(permit)` instead. */
431
+ setPermit(permit: Permit): DecryptForViewBuilder<U>;
421
432
  getPermit(): Permit | undefined;
422
433
  private getThresholdNetworkUrl;
423
434
  private validateUtypeOrThrow;
@@ -442,15 +453,112 @@ declare class DecryptHandlesBuilder<U extends FheTypes> extends BaseBuilder {
442
453
  *
443
454
  * Example:
444
455
  * ```typescript
445
- * const unsealed = await decryptHandle(ctHash, utype)
456
+ * const unsealed = await client.decryptForView(ctHash, utype)
446
457
  * .setChainId(11155111) // optional
447
458
  * .setAccount('0x123...890') // optional
448
- * .decrypt(); // execute
459
+ * .withPermit() // optional
460
+ * .execute(); // execute
449
461
  * ```
450
462
  *
451
463
  * @returns The unsealed item.
452
464
  */
453
- decrypt(): Promise<UnsealedItem<U>>;
465
+ execute(): Promise<UnsealedItem<U>>;
466
+ }
467
+
468
+ type DecryptForTxBuilderParams = BaseBuilderParams & {
469
+ ctHash: bigint;
470
+ };
471
+ type DecryptForTxResult = {
472
+ ctHash: bigint;
473
+ decryptedValue: bigint;
474
+ signature: string;
475
+ };
476
+ /**
477
+ * Type-level gating:
478
+ * - The initial builder returned from `client.decryptForTx(...)` intentionally does not expose `execute()`.
479
+ * - Calling `withPermit(...)` or `withoutPermit()` returns a builder that *does* expose `execute()`, but no longer
480
+ * exposes `withPermit/withoutPermit` (so you can't select twice, or switch modes).
481
+ */
482
+ type DecryptForTxBuilderUnset = Omit<DecryptForTxBuilder, 'execute'>;
483
+ type DecryptForTxBuilderSelected = Omit<DecryptForTxBuilder, 'withPermit' | 'withoutPermit'>;
484
+ declare class DecryptForTxBuilder extends BaseBuilder {
485
+ private ctHash;
486
+ private permitHash?;
487
+ private permit?;
488
+ private permitSelection;
489
+ constructor(params: DecryptForTxBuilderParams);
490
+ /**
491
+ * @param chainId - Chain to decrypt values from. Used to fetch the threshold network URL and use the correct permit.
492
+ *
493
+ * If not provided, the chainId will be fetched from the connected publicClient.
494
+ *
495
+ * Example:
496
+ * ```typescript
497
+ * const result = await decryptForTx(ctHash)
498
+ * .setChainId(11155111)
499
+ * .execute();
500
+ * ```
501
+ *
502
+ * @returns The chainable DecryptForTxBuilder instance.
503
+ */
504
+ setChainId(this: DecryptForTxBuilderUnset, chainId: number): DecryptForTxBuilderUnset;
505
+ setChainId(this: DecryptForTxBuilderSelected, chainId: number): DecryptForTxBuilderSelected;
506
+ getChainId(): number | undefined;
507
+ /**
508
+ * @param account - Account to decrypt values from. Used to fetch the correct permit.
509
+ *
510
+ * If not provided, the account will be fetched from the connected walletClient.
511
+ *
512
+ * Example:
513
+ * ```typescript
514
+ * const result = await decryptForTx(ctHash)
515
+ * .setAccount('0x1234567890123456789012345678901234567890')
516
+ * .execute();
517
+ * ```
518
+ *
519
+ * @returns The chainable DecryptForTxBuilder instance.
520
+ */
521
+ setAccount(this: DecryptForTxBuilderUnset, account: string): DecryptForTxBuilderUnset;
522
+ setAccount(this: DecryptForTxBuilderSelected, account: string): DecryptForTxBuilderSelected;
523
+ getAccount(): string | undefined;
524
+ /**
525
+ * Select "use permit" mode.
526
+ *
527
+ * - `withPermit(permit)` uses the provided permit.
528
+ * - `withPermit(permitHash)` fetches that permit.
529
+ * - `withPermit()` uses the active permit for the resolved `chainId + account`.
530
+ *
531
+ * Note: "global allowance" (no permit) is ONLY available via `withoutPermit()`.
532
+ */
533
+ withPermit(): DecryptForTxBuilderSelected;
534
+ withPermit(permitHash: string): DecryptForTxBuilderSelected;
535
+ withPermit(permit: Permit): DecryptForTxBuilderSelected;
536
+ /**
537
+ * Select "no permit" mode.
538
+ *
539
+ * This uses global allowance (no permit required) and sends an empty permission payload to `/decrypt`.
540
+ */
541
+ withoutPermit(): DecryptForTxBuilderSelected;
542
+ getPermit(): Permit | undefined;
543
+ getPermitHash(): string | undefined;
544
+ private getThresholdNetworkUrl;
545
+ private getResolvedPermit;
546
+ /**
547
+ * On hardhat, interact with MockThresholdNetwork contract
548
+ */
549
+ private mocksDecryptForTx;
550
+ /**
551
+ * In the production context, perform a true decryption with the CoFHE coprocessor.
552
+ */
553
+ private productionDecryptForTx;
554
+ /**
555
+ * Final step of the decryptForTx process. MUST BE CALLED LAST IN THE CHAIN.
556
+ *
557
+ * You must explicitly choose one permit mode before calling `execute()`:
558
+ * - `withPermit(permit)` / `withPermit(permitHash)` / `withPermit()` (active permit)
559
+ * - `withoutPermit()` (global allowance)
560
+ */
561
+ execute(): Promise<DecryptForTxResult>;
454
562
  }
455
563
 
456
564
  /**
@@ -541,7 +649,7 @@ type FheKeyDeserializer = (buff: string) => void;
541
649
  /**
542
650
  * Retrieves the FHE public key and the CRS from the provider.
543
651
  * If the key/crs already exists in the store it is returned, else it is fetched, stored, and returned
544
- * @param {CofhesdkConfig} config - The configuration object for the CoFHE SDK
652
+ * @param {CofheConfig} config - The configuration object for the CoFHE client
545
653
  * @param {number} chainId - The chain to fetch the FHE key for, if no chainId provided, undefined is returned
546
654
  * @param securityZone - The security zone for which to retrieve the key (default 0).
547
655
  * @param tfhePublicKeyDeserializer - The serializer for the FHE public key (used for validation).
@@ -549,7 +657,7 @@ type FheKeyDeserializer = (buff: string) => void;
549
657
  * @param keysStorage - The keys storage instance to use (optional)
550
658
  * @returns {Promise<[[string, boolean], [string, boolean]]>} - A promise that resolves to [[fheKey, fheKeyFetchedFromCoFHE], [crs, crsFetchedFromCoFHE]]
551
659
  */
552
- declare const fetchKeys: (config: CofhesdkConfig, chainId: number, securityZone: number | undefined, tfhePublicKeyDeserializer: FheKeyDeserializer, compactPkeCrsDeserializer: FheKeyDeserializer, keysStorage?: KeysStorage | null) => Promise<[[string, boolean], [string, boolean]]>;
660
+ declare const fetchKeys: (config: CofheConfig, chainId: number, securityZone: number | undefined, tfhePublicKeyDeserializer: FheKeyDeserializer, compactPkeCrsDeserializer: FheKeyDeserializer, keysStorage?: KeysStorage | null) => Promise<[[string, boolean], [string, boolean]]>;
553
661
 
554
662
  type EncryptInputsBuilderParams<T extends EncryptableItem[]> = BaseBuilderParams & {
555
663
  inputs: [...T];
@@ -590,7 +698,7 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
590
698
  * ```typescript
591
699
  * const encrypted = await encryptInputs([Encryptable.uint128(10n)])
592
700
  * .setAccount("0x123")
593
- * .encrypt();
701
+ * .execute();
594
702
  * ```
595
703
  *
596
704
  * @returns The chainable EncryptInputsBuilder instance.
@@ -606,7 +714,7 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
606
714
  * ```typescript
607
715
  * const encrypted = await encryptInputs([Encryptable.uint128(10n)])
608
716
  * .setChainId(11155111)
609
- * .encrypt();
717
+ * .execute();
610
718
  * ```
611
719
  *
612
720
  * @returns The chainable EncryptInputsBuilder instance.
@@ -622,7 +730,7 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
622
730
  * ```typescript
623
731
  * const encrypted = await encryptInputs([Encryptable.uint128(10n)])
624
732
  * .setSecurityZone(1)
625
- * .encrypt();
733
+ * .execute();
626
734
  * ```
627
735
  *
628
736
  * @returns The chainable EncryptInputsBuilder instance.
@@ -638,7 +746,7 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
638
746
  * ```typescript
639
747
  * const encrypted = await encryptInputs([Encryptable.uint128(10n)])
640
748
  * .setUseWorker(false)
641
- * .encrypt();
749
+ * .execute();
642
750
  * ```
643
751
  *
644
752
  * @returns The chainable EncryptInputsBuilder instance.
@@ -667,13 +775,13 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
667
775
  * Example:
668
776
  * ```typescript
669
777
  * const encrypted = await encryptInputs([Encryptable.uint128(10n)])
670
- * .setStepCallback((step: EncryptStep) => console.log(step))
671
- * .encrypt();
778
+ * .onStep((step: EncryptStep) => console.log(step))
779
+ * .execute();
672
780
  * ```
673
781
  *
674
782
  * @returns The EncryptInputsBuilder instance.
675
783
  */
676
- setStepCallback(callback: EncryptStepCallbackFunction): EncryptInputsBuilder<T>;
784
+ onStep(callback: EncryptStepCallbackFunction): EncryptInputsBuilder<T>;
677
785
  getStepCallback(): EncryptStepCallbackFunction | undefined;
678
786
  /**
679
787
  * Fires the step callback if set
@@ -681,12 +789,12 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
681
789
  private fireStepStart;
682
790
  private fireStepEnd;
683
791
  /**
684
- * zkVerifierUrl is included in the chains exported from cofhesdk/chains for use in CofhesdkConfig.supportedChains
792
+ * zkVerifierUrl is included in the chains exported from @cofhe/sdk/chains for use in CofheConfig.supportedChains
685
793
  * Users should generally not set this manually.
686
794
  */
687
795
  private getZkVerifierUrl;
688
796
  /**
689
- * initTfhe is a platform-specific dependency injected into core/createCofhesdkClientBase by web/createCofhesdkClient and node/createCofhesdkClient
797
+ * initTfhe is a platform-specific dependency injected into core/createCofheClientBase by web/createCofheClient and node/createCofheClient
690
798
  * web/ uses zama "tfhe"
691
799
  * node/ uses zama "node-tfhe"
692
800
  * Users should not set this manually.
@@ -697,6 +805,11 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
697
805
  * If the key/crs already exists in the store it is returned, else it is fetched, stored, and returned
698
806
  */
699
807
  private fetchFheKeyAndCrs;
808
+ /**
809
+ * Resolves the encryptDelay config into an array of 5 per-step delays.
810
+ * A single number is broadcast to all steps; a tuple is used as-is.
811
+ */
812
+ private resolveEncryptDelays;
700
813
  /**
701
814
  * @dev Encrypt against the cofheMocks instead of CoFHE
702
815
  *
@@ -704,11 +817,11 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
704
817
  * cofheMocksInsertPackedHashes - stores the ctHashes and their plaintext values for on-chain mocking of FHE operations.
705
818
  * cofheMocksZkCreateProofSignatures - creates signatures to be included in the encrypted inputs. The signers address is known and verified in the mock contracts.
706
819
  */
707
- private mocksEncrypt;
820
+ private mocksExecute;
708
821
  /**
709
822
  * In the production context, perform a true encryption with the CoFHE coprocessor.
710
823
  */
711
- private productionEncrypt;
824
+ private productionExecute;
712
825
  /**
713
826
  * Final step of the encryption process. MUST BE CALLED LAST IN THE CHAIN.
714
827
  *
@@ -723,12 +836,12 @@ declare class EncryptInputsBuilder<T extends EncryptableItem[]> extends BaseBuil
723
836
  * const encrypted = await encryptInputs([Encryptable.uint128(10n)])
724
837
  * .setAccount('0x123...890') // optional
725
838
  * .setChainId(11155111) // optional
726
- * .encrypt(); // execute
839
+ * .execute(); // execute
727
840
  * ```
728
841
  *
729
842
  * @returns The encrypted inputs.
730
843
  */
731
- encrypt(): Promise<[...EncryptedItemInputs<T>]>;
844
+ execute(): Promise<[...EncryptedItemInputs<T>]>;
732
845
  }
733
846
 
734
847
  declare const permits: {
@@ -790,9 +903,10 @@ declare const permits: {
790
903
  removeActivePermit: (chainId: number, account: string) => Promise<void>;
791
904
  };
792
905
 
793
- type CofhesdkClient<TConfig extends CofhesdkConfig = CofhesdkConfig> = {
794
- getSnapshot(): CofhesdkClientConnectionState;
906
+ type CofheClient<TConfig extends CofheConfig = CofheConfig> = {
907
+ getSnapshot(): CofheClientConnectionState;
795
908
  subscribe(listener: Listener): () => void;
909
+ readonly connection: CofheClientConnectionState;
796
910
  readonly connected: boolean;
797
911
  readonly connecting: boolean;
798
912
  readonly config: TConfig;
@@ -807,10 +921,15 @@ type CofhesdkClient<TConfig extends CofhesdkConfig = CofhesdkConfig> = {
807
921
  * Types docstring
808
922
  */
809
923
  encryptInputs<T extends EncryptableItem[]>(inputs: [...T]): EncryptInputsBuilder<[...T]>;
810
- decryptHandle<U extends FheTypes>(ctHash: bigint, utype: U): DecryptHandlesBuilder<U>;
811
- permits: CofhesdkClientPermits;
924
+ /**
925
+ * @deprecated Use `decryptForView` instead. Kept for backward compatibility.
926
+ */
927
+ decryptHandle<U extends FheTypes>(ctHash: bigint, utype: U): DecryptForViewBuilder<U>;
928
+ decryptForView<U extends FheTypes>(ctHash: bigint, utype: U): DecryptForViewBuilder<U>;
929
+ decryptForTx(ctHash: bigint): DecryptForTxBuilderUnset;
930
+ permits: CofheClientPermits;
812
931
  };
813
- type CofhesdkClientConnectionState = {
932
+ type CofheClientConnectionState = {
814
933
  connected: boolean;
815
934
  connecting: boolean;
816
935
  connectError: unknown | undefined;
@@ -819,17 +938,17 @@ type CofhesdkClientConnectionState = {
819
938
  publicClient: PublicClient | undefined;
820
939
  walletClient: WalletClient | undefined;
821
940
  };
822
- type Listener = (snapshot: CofhesdkClientConnectionState) => void;
823
- type CofhesdkClientPermitsClients = {
941
+ type Listener = (snapshot: CofheClientConnectionState) => void;
942
+ type CofheClientPermitsClients = {
824
943
  publicClient: PublicClient;
825
944
  walletClient: WalletClient;
826
945
  };
827
- type CofhesdkClientPermits = {
946
+ type CofheClientPermits = {
828
947
  getSnapshot: typeof permits.getSnapshot;
829
948
  subscribe: typeof permits.subscribe;
830
- createSelf: (options: CreateSelfPermitOptions, clients?: CofhesdkClientPermitsClients) => Promise<SelfPermit>;
831
- createSharing: (options: CreateSharingPermitOptions, clients?: CofhesdkClientPermitsClients) => Promise<SharingPermit>;
832
- importShared: (options: ImportSharedPermitOptions | string, clients?: CofhesdkClientPermitsClients) => Promise<RecipientPermit>;
949
+ createSelf: (options: CreateSelfPermitOptions, clients?: CofheClientPermitsClients) => Promise<SelfPermit>;
950
+ createSharing: (options: CreateSharingPermitOptions, clients?: CofheClientPermitsClients) => Promise<SharingPermit>;
951
+ importShared: (options: ImportSharedPermitOptions | string, clients?: CofheClientPermitsClients) => Promise<RecipientPermit>;
833
952
  getPermit: (hash: string, chainId?: number, account?: string) => Promise<Permit | undefined>;
834
953
  getPermits: (chainId?: number, account?: string) => Promise<Record<string, Permit>>;
835
954
  getActivePermit: (chainId?: number, account?: string) => Promise<Permit | undefined>;
@@ -843,7 +962,7 @@ type CofhesdkClientPermits = {
843
962
  serialize: typeof PermitUtils.serialize;
844
963
  deserialize: typeof PermitUtils.deserialize;
845
964
  };
846
- type CofhesdkClientParams<TConfig extends CofhesdkConfig> = {
965
+ type CofheClientParams<TConfig extends CofheConfig> = {
847
966
  config: TConfig;
848
967
  zkBuilderAndCrsGenerator: ZkBuilderAndCrsGenerator;
849
968
  tfhePublicKeyDeserializer: FheKeyDeserializer;
@@ -852,4 +971,4 @@ type CofhesdkClientParams<TConfig extends CofhesdkConfig> = {
852
971
  zkProveWorkerFn?: ZkProveWorkerFunction;
853
972
  };
854
973
 
855
- export { type ZkProveWorkerResponse as $, type FheTypeValue as A, type EncryptStepCallbackFunction as B, type CofhesdkInputConfig as C, type EncryptStepCallbackContext as D, type EncryptableItem as E, FheTypes as F, FheUintUTypes as G, FheAllUTypes as H, type IStorage as I, Encryptable as J, isEncryptableItem as K, type LiteralToPrimitive as L, EncryptStep as M, isLastEncryptionStep as N, assertCorrectEncryptedItemInput as O, type Primitive as P, fetchKeys as Q, type FheKeyDeserializer as R, createKeysStore as S, type KeysStorage as T, type UnsealedItem as U, type KeysStore as V, EncryptInputsBuilder as W, DecryptHandlesBuilder as X, type ZkProveWorkerFunction as Y, type ZkBuilderAndCrsGenerator as Z, type ZkProveWorkerRequest as _, type CofhesdkConfig as a, zkProveWithWorker as a0, type CofhesdkClient as b, type CofhesdkClientConnectionState as c, type CofhesdkClientParams as d, createCofhesdkConfigBase as e, type CofhesdkInternalConfig 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 EncryptedAddressInput as x, type EncryptedItemInputs as y, type EncryptableToEncryptedItemInputMap as z };
974
+ export { type ZkProveWorkerFunction as $, type FheTypeValue as A, type EncryptStepCallbackFunction as B, type CofheInputConfig as C, type EncryptStepCallbackContext as D, type EncryptableItem as E, FheTypes as F, FheUintUTypes as G, FheAllUTypes as H, type IStorage as I, Encryptable as J, isEncryptableItem as K, type LiteralToPrimitive as L, EncryptStep as M, isLastEncryptionStep as N, assertCorrectEncryptedItemInput as O, type Primitive as P, fetchKeys as Q, type FheKeyDeserializer as R, createKeysStore as S, type KeysStorage as T, type UnsealedItem as U, type KeysStore as V, EncryptInputsBuilder as W, DecryptForViewBuilder as X, DecryptForTxBuilder as Y, type DecryptForTxResult as Z, type ZkBuilderAndCrsGenerator as _, type CofheConfig as a, type ZkProveWorkerRequest as a0, type ZkProveWorkerResponse as a1, zkProveWithWorker as a2, 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 };