@cofhe/sdk 0.2.0 → 0.3.0

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 (83) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/chains/defineChain.ts +2 -2
  3. package/chains/types.ts +3 -3
  4. package/core/baseBuilder.ts +18 -18
  5. package/core/client.test.ts +155 -41
  6. package/core/client.ts +72 -32
  7. package/core/clientTypes.ts +28 -18
  8. package/core/config.test.ts +40 -33
  9. package/core/config.ts +56 -51
  10. package/core/consts.ts +22 -0
  11. package/core/decrypt/{MockQueryDecrypterAbi.ts → MockThresholdNetworkAbi.ts} +71 -21
  12. package/core/decrypt/cofheMocksDecryptForTx.ts +142 -0
  13. package/core/decrypt/{cofheMocksSealOutput.ts → cofheMocksDecryptForView.ts} +12 -14
  14. package/core/decrypt/decryptForTxBuilder.ts +340 -0
  15. package/core/decrypt/{decryptHandleBuilder.ts → decryptForViewBuilder.ts} +75 -42
  16. package/core/decrypt/tnDecrypt.ts +232 -0
  17. package/core/decrypt/tnSealOutputV1.ts +5 -5
  18. package/core/decrypt/tnSealOutputV2.ts +27 -27
  19. package/core/encrypt/cofheMocksZkVerifySign.ts +19 -26
  20. package/core/encrypt/encryptInputsBuilder.test.ts +57 -61
  21. package/core/encrypt/encryptInputsBuilder.ts +65 -42
  22. package/core/encrypt/zkPackProveVerify.ts +11 -11
  23. package/core/error.ts +18 -18
  24. package/core/fetchKeys.test.ts +3 -3
  25. package/core/fetchKeys.ts +3 -3
  26. package/core/index.ts +22 -11
  27. package/core/permits.test.ts +5 -6
  28. package/core/permits.ts +5 -4
  29. package/core/utils.ts +10 -10
  30. package/dist/chains.cjs +4 -7
  31. package/dist/chains.d.cts +12 -12
  32. package/dist/chains.d.ts +12 -12
  33. package/dist/chains.js +1 -1
  34. package/dist/{chunk-WGCRJCBR.js → chunk-2TPSCOW3.js} +820 -224
  35. package/dist/{chunk-UGBVZNRT.js → chunk-NWDKXBIP.js} +309 -189
  36. package/dist/{chunk-WEAZ25JO.js → chunk-TBLR7NNE.js} +4 -7
  37. package/dist/{clientTypes-5_1nwtUe.d.cts → clientTypes-6aTZPQ_4.d.ts} +233 -173
  38. package/dist/{clientTypes-Es7fyi65.d.ts → clientTypes-Bhq7pCSA.d.cts} +233 -173
  39. package/dist/core.cjs +1138 -418
  40. package/dist/core.d.cts +37 -24
  41. package/dist/core.d.ts +37 -24
  42. package/dist/core.js +3 -3
  43. package/dist/node.cjs +1082 -370
  44. package/dist/node.d.cts +12 -12
  45. package/dist/node.d.ts +12 -12
  46. package/dist/node.js +8 -8
  47. package/dist/{permit-fUSe6KKq.d.cts → permit-MZ502UBl.d.cts} +30 -33
  48. package/dist/{permit-fUSe6KKq.d.ts → permit-MZ502UBl.d.ts} +30 -33
  49. package/dist/permits.cjs +305 -187
  50. package/dist/permits.d.cts +111 -812
  51. package/dist/permits.d.ts +111 -812
  52. package/dist/permits.js +1 -1
  53. package/dist/types-YiAC4gig.d.cts +33 -0
  54. package/dist/types-YiAC4gig.d.ts +33 -0
  55. package/dist/web.cjs +1085 -373
  56. package/dist/web.d.cts +13 -13
  57. package/dist/web.d.ts +13 -13
  58. package/dist/web.js +10 -10
  59. package/node/client.test.ts +34 -34
  60. package/node/config.test.ts +11 -11
  61. package/node/encryptInputs.test.ts +29 -29
  62. package/node/index.ts +15 -15
  63. package/package.json +3 -3
  64. package/permits/localstorage.test.ts +9 -13
  65. package/permits/onchain-utils.ts +221 -0
  66. package/permits/permit.test.ts +51 -5
  67. package/permits/permit.ts +28 -74
  68. package/permits/store.test.ts +10 -50
  69. package/permits/store.ts +4 -14
  70. package/permits/test-utils.ts +10 -2
  71. package/permits/types.ts +22 -9
  72. package/permits/utils.ts +0 -4
  73. package/permits/validation.test.ts +29 -32
  74. package/permits/validation.ts +112 -194
  75. package/web/client.web.test.ts +34 -34
  76. package/web/config.web.test.ts +11 -11
  77. package/web/encryptInputs.web.test.ts +29 -29
  78. package/web/index.ts +19 -19
  79. package/web/worker.builder.web.test.ts +28 -28
  80. package/web/worker.config.web.test.ts +47 -47
  81. package/web/worker.output.web.test.ts +10 -10
  82. package/dist/types-KImPrEIe.d.cts +0 -48
  83. package/dist/types-KImPrEIe.d.ts +0 -48
package/core/client.ts CHANGED
@@ -2,22 +2,18 @@ import type { CreateSelfPermitOptions, CreateSharingPermitOptions, ImportSharedP
2
2
 
3
3
  import { createStore } from 'zustand/vanilla';
4
4
  import { type PublicClient, type WalletClient } from 'viem';
5
- import { CofhesdkError, CofhesdkErrorCode } from './error.js';
5
+ import { CofheError, CofheErrorCode } from './error.js';
6
6
  import { EncryptInputsBuilder } from './encrypt/encryptInputsBuilder.js';
7
7
  import { createKeysStore } from './keyStore.js';
8
8
  import { permits } from './permits.js';
9
- import { DecryptHandlesBuilder } from './decrypt/decryptHandleBuilder.js';
9
+ import { DecryptForViewBuilder } from './decrypt/decryptForViewBuilder.js';
10
+ import { DecryptForTxBuilder, type DecryptForTxBuilderUnset } from './decrypt/decryptForTxBuilder.js';
10
11
  import { getPublicClientChainID, getWalletClientAccount } from './utils.js';
11
- import type {
12
- CofhesdkClientConnectionState,
13
- CofhesdkClientParams,
14
- CofhesdkClient,
15
- CofhesdkClientPermits,
16
- } from './clientTypes.js';
12
+ import type { CofheClientConnectionState, CofheClientParams, CofheClient, CofheClientPermits } from './clientTypes.js';
17
13
  import type { EncryptableItem, FheTypes } from './types.js';
18
- import type { CofhesdkConfig } from './config.js';
14
+ import type { CofheConfig } from './config.js';
19
15
 
20
- export const InitialConnectStore: CofhesdkClientConnectionState = {
16
+ export const InitialConnectStore: CofheClientConnectionState = {
21
17
  connected: false,
22
18
  connecting: false,
23
19
  connectError: undefined,
@@ -28,22 +24,26 @@ export const InitialConnectStore: CofhesdkClientConnectionState = {
28
24
  };
29
25
 
30
26
  /**
31
- * Creates a CoFHE SDK client instance (base implementation)
32
- * @param {CofhesdkClientParams} opts - Initialization options including config and platform-specific serializers
33
- * @returns {CofhesdkClient} - The CoFHE SDK client instance
27
+ * Creates a CoFHE client instance (base implementation)
28
+ * @param {CofheClientParams} opts - Initialization options including config and platform-specific serializers
29
+ * @returns {CofheClient} - The CoFHE client instance
34
30
  */
35
- export function createCofhesdkClientBase<TConfig extends CofhesdkConfig>(
36
- opts: CofhesdkClientParams<TConfig>
37
- ): CofhesdkClient<TConfig> {
31
+ export function createCofheClientBase<TConfig extends CofheConfig>(
32
+ opts: CofheClientParams<TConfig>
33
+ ): CofheClient<TConfig> {
38
34
  // Create keysStorage instance using configured storage
39
35
  const keysStorage = createKeysStore(opts.config.fheKeyStorage);
40
36
 
41
37
  // Zustand store for reactive state management
42
38
 
43
- const connectStore = createStore<CofhesdkClientConnectionState>(() => InitialConnectStore);
39
+ const connectStore = createStore<CofheClientConnectionState>(() => InitialConnectStore);
40
+
41
+ // Minimal cancellation mechanism: incremented on each connect/disconnect.
42
+ // If a connect finishes after a disconnect, it must not overwrite the disconnected state.
43
+ let connectAttemptId = 0;
44
44
 
45
45
  // Helper to update state
46
- const updateConnectState = (partial: Partial<CofhesdkClientConnectionState>) => {
46
+ const updateConnectState = (partial: Partial<CofheClientConnectionState>) => {
47
47
  connectStore.setState((state) => ({ ...state, ...partial }));
48
48
  };
49
49
 
@@ -53,8 +53,8 @@ export function createCofhesdkClientBase<TConfig extends CofhesdkConfig>(
53
53
  const notConnected =
54
54
  !state.connected || !state.account || !state.chainId || !state.publicClient || !state.walletClient;
55
55
  if (notConnected) {
56
- throw new CofhesdkError({
57
- code: CofhesdkErrorCode.NotConnected,
56
+ throw new CofheError({
57
+ code: CofheErrorCode.NotConnected,
58
58
  message: 'Client must be connected, account and chainId must be initialized',
59
59
  hint: 'Ensure client.connect() has been called and awaited.',
60
60
  context: {
@@ -76,6 +76,9 @@ export function createCofhesdkClientBase<TConfig extends CofhesdkConfig>(
76
76
  // Exit if already connected and clients are the same
77
77
  if (state.connected && state.publicClient === publicClient && state.walletClient === walletClient) return;
78
78
 
79
+ connectAttemptId += 1;
80
+ const localAttemptId = connectAttemptId;
81
+
79
82
  // Set connecting state
80
83
  updateConnectState({
81
84
  ...InitialConnectStore,
@@ -86,6 +89,10 @@ export function createCofhesdkClientBase<TConfig extends CofhesdkConfig>(
86
89
  try {
87
90
  const chainId = await getPublicClientChainID(publicClient);
88
91
  const account = await getWalletClientAccount(walletClient);
92
+
93
+ // If a disconnect (or a newer connect) happened while awaiting, ignore this completion.
94
+ if (localAttemptId !== connectAttemptId) return;
95
+
89
96
  updateConnectState({
90
97
  connected: true,
91
98
  connecting: false,
@@ -96,6 +103,9 @@ export function createCofhesdkClientBase<TConfig extends CofhesdkConfig>(
96
103
  walletClient,
97
104
  });
98
105
  } catch (e) {
106
+ // Ignore stale errors too.
107
+ if (localAttemptId !== connectAttemptId) return;
108
+
99
109
  updateConnectState({
100
110
  ...InitialConnectStore,
101
111
  connectError: e,
@@ -104,6 +114,11 @@ export function createCofhesdkClientBase<TConfig extends CofhesdkConfig>(
104
114
  }
105
115
  }
106
116
 
117
+ function disconnect() {
118
+ connectAttemptId += 1;
119
+ updateConnectState({ ...InitialConnectStore });
120
+ }
121
+
107
122
  // CLIENT OPERATIONS
108
123
 
109
124
  function encryptInputs<T extends EncryptableItem[]>(inputs: [...T]): EncryptInputsBuilder<[...T]> {
@@ -131,18 +146,34 @@ export function createCofhesdkClientBase<TConfig extends CofhesdkConfig>(
131
146
  });
132
147
  }
133
148
 
134
- function decryptHandle<U extends FheTypes>(ctHash: bigint, utype: U): DecryptHandlesBuilder<U> {
149
+ function decryptForView<U extends FheTypes>(ctHash: bigint, utype: U): DecryptForViewBuilder<U> {
135
150
  const state = connectStore.getState();
136
151
 
137
- return new DecryptHandlesBuilder({
152
+ return new DecryptForViewBuilder({
138
153
  ctHash,
139
154
  utype,
140
- chainId: state.chainId ?? undefined,
141
- account: state.account ?? undefined,
155
+ chainId: state.chainId,
156
+ account: state.account,
142
157
 
143
158
  config: opts.config,
144
- publicClient: state.publicClient ?? undefined,
145
- walletClient: state.walletClient ?? undefined,
159
+ publicClient: state.publicClient,
160
+ walletClient: state.walletClient,
161
+
162
+ requireConnected: _requireConnected,
163
+ });
164
+ }
165
+
166
+ function decryptForTx(ctHash: bigint): DecryptForTxBuilderUnset {
167
+ const state = connectStore.getState();
168
+
169
+ return new DecryptForTxBuilder({
170
+ ctHash,
171
+ chainId: state.chainId,
172
+ account: state.account,
173
+
174
+ config: opts.config,
175
+ publicClient: state.publicClient,
176
+ walletClient: state.walletClient,
146
177
 
147
178
  requireConnected: _requireConnected,
148
179
  });
@@ -156,8 +187,8 @@ export function createCofhesdkClientBase<TConfig extends CofhesdkConfig>(
156
187
  const _account = account ?? state.account;
157
188
 
158
189
  if (_chainId == null || _account == null) {
159
- throw new CofhesdkError({
160
- code: CofhesdkErrorCode.NotConnected,
190
+ throw new CofheError({
191
+ code: CofheErrorCode.NotConnected,
161
192
  message: 'ChainId or account not available.',
162
193
  hint: 'Ensure client.connect() has been called, or provide chainId and account explicitly.',
163
194
  context: {
@@ -170,7 +201,7 @@ export function createCofhesdkClientBase<TConfig extends CofhesdkConfig>(
170
201
  return { chainId: _chainId, account: _account };
171
202
  };
172
203
 
173
- const clientPermits: CofhesdkClientPermits = {
204
+ const clientPermits: CofheClientPermits = {
174
205
  // Pass through store access
175
206
  getSnapshot: permits.getSnapshot,
176
207
  subscribe: permits.subscribe,
@@ -245,9 +276,9 @@ export function createCofhesdkClientBase<TConfig extends CofhesdkConfig>(
245
276
  return permits.selectActivePermit(_chainId, _account, hash);
246
277
  },
247
278
 
248
- removePermit: async (hash: string, chainId?: number, account?: string, force?: boolean) => {
279
+ removePermit: async (hash: string, chainId?: number, account?: string) => {
249
280
  const { chainId: _chainId, account: _account } = _getChainIdAndAccount(chainId, account);
250
- return permits.removePermit(_chainId, _account, hash, force);
281
+ return permits.removePermit(_chainId, _account, hash);
251
282
  },
252
283
 
253
284
  removeActivePermit: async (chainId?: number, account?: string) => {
@@ -267,6 +298,9 @@ export function createCofhesdkClientBase<TConfig extends CofhesdkConfig>(
267
298
  subscribe: connectStore.subscribe,
268
299
 
269
300
  // flags (read-only: reflect snapshot)
301
+ get connection() {
302
+ return connectStore.getState();
303
+ },
270
304
  get connected() {
271
305
  return connectStore.getState().connected;
272
306
  },
@@ -278,8 +312,14 @@ export function createCofhesdkClientBase<TConfig extends CofhesdkConfig>(
278
312
  config: opts.config,
279
313
 
280
314
  connect,
315
+ disconnect,
281
316
  encryptInputs,
282
- decryptHandle,
317
+ decryptForView,
318
+ /**
319
+ * @deprecated Use `decryptForView` instead. Kept for backward compatibility.
320
+ */
321
+ decryptHandle: decryptForView,
322
+ decryptForTx,
283
323
  permits: clientPermits,
284
324
 
285
325
  // Add SDK-specific methods below that require connection
@@ -1,7 +1,8 @@
1
1
  // TODO: Extract client types to its own file, keep this one as primitives
2
2
  import { type PublicClient, type WalletClient } from 'viem';
3
- import { type CofhesdkConfig, type CofhesdkEnvironment } from './config.js';
4
- import { type DecryptHandlesBuilder } from './decrypt/decryptHandleBuilder.js';
3
+ import { type CofheConfig } from './config.js';
4
+ import { type DecryptForViewBuilder } from './decrypt/decryptForViewBuilder.js';
5
+ import { type DecryptForTxBuilderUnset } from './decrypt/decryptForTxBuilder.js';
5
6
  import { type EncryptInputsBuilder } from './encrypt/encryptInputsBuilder.js';
6
7
  import { type ZkBuilderAndCrsGenerator, type ZkProveWorkerFunction } from './encrypt/zkPackProveVerify.js';
7
8
  import { type FheKeyDeserializer } from './fetchKeys.js';
@@ -20,12 +21,13 @@ import type {
20
21
 
21
22
  // CLIENT
22
23
 
23
- export type CofhesdkClient<TConfig extends CofhesdkConfig = CofhesdkConfig> = {
24
+ export type CofheClient<TConfig extends CofheConfig = CofheConfig> = {
24
25
  // --- state access ---
25
- getSnapshot(): CofhesdkClientConnectionState;
26
+ getSnapshot(): CofheClientConnectionState;
26
27
  subscribe(listener: Listener): () => void;
27
28
 
28
29
  // --- convenience flags (read-only) ---
30
+ readonly connection: CofheClientConnectionState;
29
31
  readonly connected: boolean;
30
32
  readonly connecting: boolean;
31
33
 
@@ -33,15 +35,26 @@ export type CofhesdkClient<TConfig extends CofhesdkConfig = CofhesdkConfig> = {
33
35
  readonly config: TConfig;
34
36
 
35
37
  connect(publicClient: PublicClient, walletClient: WalletClient): Promise<void>;
38
+ /**
39
+ * Clears the current connection state (account/chainId/clients) and marks the client as disconnected.
40
+ *
41
+ * This does not delete persisted permits or stored FHE keys; it only resets the in-memory connection.
42
+ */
43
+ disconnect(): void;
36
44
  /**
37
45
  * Types docstring
38
46
  */
39
47
  encryptInputs<T extends EncryptableItem[]>(inputs: [...T]): EncryptInputsBuilder<[...T]>;
40
- decryptHandle<U extends FheTypes>(ctHash: bigint, utype: U): DecryptHandlesBuilder<U>;
41
- permits: CofhesdkClientPermits;
48
+ /**
49
+ * @deprecated Use `decryptForView` instead. Kept for backward compatibility.
50
+ */
51
+ decryptHandle<U extends FheTypes>(ctHash: bigint, utype: U): DecryptForViewBuilder<U>;
52
+ decryptForView<U extends FheTypes>(ctHash: bigint, utype: U): DecryptForViewBuilder<U>;
53
+ decryptForTx(ctHash: bigint): DecryptForTxBuilderUnset;
54
+ permits: CofheClientPermits;
42
55
  };
43
56
 
44
- export type CofhesdkClientConnectionState = {
57
+ export type CofheClientConnectionState = {
45
58
  connected: boolean;
46
59
  connecting: boolean;
47
60
  connectError: unknown | undefined;
@@ -51,26 +64,23 @@ export type CofhesdkClientConnectionState = {
51
64
  walletClient: WalletClient | undefined;
52
65
  };
53
66
 
54
- type Listener = (snapshot: CofhesdkClientConnectionState) => void;
67
+ type Listener = (snapshot: CofheClientConnectionState) => void;
55
68
 
56
- export type CofhesdkClientPermitsClients = {
69
+ export type CofheClientPermitsClients = {
57
70
  publicClient: PublicClient;
58
71
  walletClient: WalletClient;
59
72
  };
60
73
 
61
- export type CofhesdkClientPermits = {
74
+ export type CofheClientPermits = {
62
75
  getSnapshot: typeof permits.getSnapshot;
63
76
  subscribe: typeof permits.subscribe;
64
77
 
65
78
  // Creation methods (require connection, no params)
66
- createSelf: (options: CreateSelfPermitOptions, clients?: CofhesdkClientPermitsClients) => Promise<SelfPermit>;
67
- createSharing: (
68
- options: CreateSharingPermitOptions,
69
- clients?: CofhesdkClientPermitsClients
70
- ) => Promise<SharingPermit>;
79
+ createSelf: (options: CreateSelfPermitOptions, clients?: CofheClientPermitsClients) => Promise<SelfPermit>;
80
+ createSharing: (options: CreateSharingPermitOptions, clients?: CofheClientPermitsClients) => Promise<SharingPermit>;
71
81
  importShared: (
72
82
  options: ImportSharedPermitOptions | string,
73
- clients?: CofhesdkClientPermitsClients
83
+ clients?: CofheClientPermitsClients
74
84
  ) => Promise<RecipientPermit>;
75
85
 
76
86
  // Retrieval methods (chainId/account optional)
@@ -89,7 +99,7 @@ export type CofhesdkClientPermits = {
89
99
 
90
100
  // Mutation methods (chainId/account optional)
91
101
  selectActivePermit: (hash: string, chainId?: number, account?: string) => void;
92
- removePermit: (hash: string, chainId?: number, account?: string, force?: boolean) => void;
102
+ removePermit: (hash: string, chainId?: number, account?: string) => void;
93
103
  removeActivePermit: (chainId?: number, account?: string) => void;
94
104
 
95
105
  // Utils
@@ -98,7 +108,7 @@ export type CofhesdkClientPermits = {
98
108
  deserialize: typeof PermitUtils.deserialize;
99
109
  };
100
110
 
101
- export type CofhesdkClientParams<TConfig extends CofhesdkConfig> = {
111
+ export type CofheClientParams<TConfig extends CofheConfig> = {
102
112
  config: TConfig;
103
113
  zkBuilderAndCrsGenerator: ZkBuilderAndCrsGenerator;
104
114
  tfhePublicKeyDeserializer: FheKeyDeserializer;
@@ -2,17 +2,17 @@ import { sepolia, hardhat } from '@/chains';
2
2
 
3
3
  import { describe, it, expect, vi } from 'vitest';
4
4
  import {
5
- createCofhesdkConfigBase,
6
- getCofhesdkConfigItem,
7
- type CofhesdkInputConfig,
5
+ createCofheConfigBase,
6
+ getCofheConfigItem,
7
+ type CofheInputConfig,
8
8
  getSupportedChainOrThrow,
9
9
  getCoFheUrlOrThrow,
10
10
  getZkVerifierUrlOrThrow,
11
11
  getThresholdNetworkUrlOrThrow,
12
12
  } from './config.js';
13
13
 
14
- describe('createCofhesdkConfigBase', () => {
15
- const validBaseConfig: CofhesdkInputConfig = {
14
+ describe('createCofheConfigBase', () => {
15
+ const validBaseConfig: CofheInputConfig = {
16
16
  supportedChains: [],
17
17
  };
18
18
 
@@ -36,18 +36,18 @@ describe('createCofhesdkConfigBase', () => {
36
36
  if (log) {
37
37
  console.log('expect config invalid', path, value, config);
38
38
  try {
39
- createCofhesdkConfigBase(config as CofhesdkInputConfig);
39
+ createCofheConfigBase(config as CofheInputConfig);
40
40
  } catch (e) {
41
41
  console.log('expect config invalid', path, value, config, e);
42
42
  }
43
43
  }
44
- expect(() => createCofhesdkConfigBase(config as CofhesdkInputConfig)).toThrow('Invalid cofhesdk configuration:');
44
+ expect(() => createCofheConfigBase(config as CofheInputConfig)).toThrow('Invalid cofhe configuration:');
45
45
  };
46
46
 
47
47
  const expectValidConfigItem = (path: string, value: any, expectedValue: any): void => {
48
48
  const config = { ...validBaseConfig };
49
49
  setNestedValue(config, path, value);
50
- const result = createCofhesdkConfigBase(config);
50
+ const result = createCofheConfigBase(config);
51
51
  expect(getNestedValue(result, path)).toEqual(expectedValue);
52
52
  };
53
53
 
@@ -72,16 +72,6 @@ describe('createCofhesdkConfigBase', () => {
72
72
  expectValidConfigItem('supportedChains', [sepolia, hardhat], [sepolia, hardhat]);
73
73
  });
74
74
 
75
- it('permitGeneration', () => {
76
- expectInvalidConfigItem('permitGeneration', 'not-a-boolean');
77
- expectInvalidConfigItem('permitGeneration', null);
78
-
79
- expectValidConfigItem('permitGeneration', 'ON_CONNECT', 'ON_CONNECT');
80
- expectValidConfigItem('permitGeneration', 'ON_DECRYPT_HANDLES', 'ON_DECRYPT_HANDLES');
81
- expectValidConfigItem('permitGeneration', 'MANUAL', 'MANUAL');
82
- expectValidConfigItem('permitGeneration', undefined, 'ON_CONNECT');
83
- });
84
-
85
75
  it('defaultPermitExpiration', () => {
86
76
  expectInvalidConfigItem('defaultPermitExpiration', 'not-a-number');
87
77
  expectInvalidConfigItem('defaultPermitExpiration', null);
@@ -116,7 +106,7 @@ describe('createCofhesdkConfigBase', () => {
116
106
  };
117
107
 
118
108
  const config = { ...validBaseConfig, fheKeyStorage: fakeStorage };
119
- const result = createCofhesdkConfigBase(config);
109
+ const result = createCofheConfigBase(config);
120
110
 
121
111
  expect(result.fheKeyStorage).not.toBeNull();
122
112
  await result.fheKeyStorage!.getItem('test');
@@ -126,22 +116,39 @@ describe('createCofhesdkConfigBase', () => {
126
116
  expect(getItemCalled).toBe(true);
127
117
  expect(setItemCalled).toBe(true);
128
118
  expect(removeItemCalled).toBe(true);
119
+
120
+ const invalidStorageNotAFunction = {
121
+ getItem: 'not-a-function',
122
+ setItem: 'not-a-function',
123
+ removeItem: 'not-a-function',
124
+ };
125
+
126
+ expectInvalidConfigItem('fheKeyStorage', invalidStorageNotAFunction);
129
127
  });
130
128
 
131
129
  it('mocks', () => {
132
130
  expectInvalidConfigItem('mocks', 'not-an-object');
133
131
  expectInvalidConfigItem('mocks', null);
132
+ });
133
+
134
+ it('mocks.decryptDelay', () => {
135
+ expectInvalidConfigItem('mocks.decryptDelay', 'not-a-number');
136
+ expectInvalidConfigItem('mocks.decryptDelay', null);
134
137
 
135
- expectValidConfigItem('mocks', { sealOutputDelay: 1000 }, { sealOutputDelay: 1000 });
136
- expectValidConfigItem('mocks', undefined, { sealOutputDelay: 0 });
138
+ expectValidConfigItem('mocks.decryptDelay', undefined, 0);
139
+ expectValidConfigItem('mocks.decryptDelay', 1000, 1000);
137
140
  });
138
141
 
139
- it('mocks.sealOutputDelay', () => {
140
- expectInvalidConfigItem('mocks.sealOutputDelay', 'not-a-number');
141
- expectInvalidConfigItem('mocks.sealOutputDelay', null);
142
+ it('mocks.encryptDelay', () => {
143
+ expectInvalidConfigItem('mocks.encryptDelay', 'not-a-number');
144
+ expectInvalidConfigItem('mocks.encryptDelay', null);
145
+ expectInvalidConfigItem('mocks.encryptDelay', [100, 100, 100]); // wrong tuple length
146
+ expectInvalidConfigItem('mocks.encryptDelay', ['a', 'b', 'c', 'd', 'e']); // non-number elements
142
147
 
143
- expectValidConfigItem('mocks.sealOutputDelay', undefined, 0);
144
- expectValidConfigItem('mocks.sealOutputDelay', 1000, 1000);
148
+ expectValidConfigItem('mocks.encryptDelay', undefined, [100, 100, 100, 500, 500]);
149
+ expectValidConfigItem('mocks.encryptDelay', 200, 200);
150
+ expectValidConfigItem('mocks.encryptDelay', 0, 0);
151
+ expectValidConfigItem('mocks.encryptDelay', [10, 20, 30, 40, 50], [10, 20, 30, 40, 50]);
145
152
  });
146
153
 
147
154
  it('useWorkers', () => {
@@ -156,19 +163,19 @@ describe('createCofhesdkConfigBase', () => {
156
163
  });
157
164
 
158
165
  it('should get config item', () => {
159
- const config: CofhesdkInputConfig = {
166
+ const config: CofheInputConfig = {
160
167
  supportedChains: [sepolia],
161
168
  };
162
169
 
163
- const result = createCofhesdkConfigBase(config);
170
+ const result = createCofheConfigBase(config);
164
171
 
165
- const supportedChains = getCofhesdkConfigItem(result, 'supportedChains');
172
+ const supportedChains = getCofheConfigItem(result, 'supportedChains');
166
173
  expect(supportedChains).toEqual(config.supportedChains);
167
174
  });
168
175
  });
169
176
 
170
177
  describe('Config helper functions', () => {
171
- const config = createCofhesdkConfigBase({
178
+ const config = createCofheConfigBase({
172
179
  supportedChains: [sepolia, hardhat],
173
180
  });
174
181
 
@@ -192,7 +199,7 @@ describe('Config helper functions', () => {
192
199
  });
193
200
 
194
201
  it('should throw MissingConfig when url not set', () => {
195
- const configWithoutUrl = createCofhesdkConfigBase({
202
+ const configWithoutUrl = createCofheConfigBase({
196
203
  supportedChains: [{ ...sepolia, coFheUrl: undefined } as any],
197
204
  });
198
205
  expect(() => getCoFheUrlOrThrow(configWithoutUrl, sepolia.id)).toThrow();
@@ -209,7 +216,7 @@ describe('Config helper functions', () => {
209
216
  });
210
217
 
211
218
  it('should throw ZkVerifierUrlUninitialized when url not set', () => {
212
- const configWithoutUrl = createCofhesdkConfigBase({
219
+ const configWithoutUrl = createCofheConfigBase({
213
220
  supportedChains: [{ ...sepolia, verifierUrl: undefined } as any],
214
221
  });
215
222
  expect(() => getZkVerifierUrlOrThrow(configWithoutUrl, sepolia.id)).toThrow();
@@ -226,7 +233,7 @@ describe('Config helper functions', () => {
226
233
  });
227
234
 
228
235
  it('should throw ThresholdNetworkUrlUninitialized when url not set', () => {
229
- const configWithoutUrl = createCofhesdkConfigBase({
236
+ const configWithoutUrl = createCofheConfigBase({
230
237
  supportedChains: [{ ...sepolia, thresholdNetworkUrl: undefined } as any],
231
238
  });
232
239
  expect(() => getThresholdNetworkUrlOrThrow(configWithoutUrl, sepolia.id)).toThrow();