@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/dist/web.d.cts CHANGED
@@ -1,8 +1,8 @@
1
- import { C as CofhesdkInputConfig, a as CofhesdkConfig, b as CofhesdkClient, E as EncryptableItem } from './clientTypes-5_1nwtUe.cjs';
1
+ import { C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-Bhq7pCSA.cjs';
2
2
  import 'viem';
3
- import './types-KImPrEIe.cjs';
3
+ import './types-YiAC4gig.cjs';
4
4
  import 'zod';
5
- import './permit-fUSe6KKq.cjs';
5
+ import './permit-MZ502UBl.cjs';
6
6
  import 'zustand/vanilla';
7
7
 
8
8
  /**
@@ -15,24 +15,24 @@ declare function terminateWorker(): void;
15
15
  declare function areWorkersAvailable(): boolean;
16
16
 
17
17
  /**
18
- * Creates a CoFHE SDK configuration for web with IndexedDB storage as default
19
- * @param config - The CoFHE SDK input configuration (fheKeyStorage will default to IndexedDB if not provided)
20
- * @returns The CoFHE SDK configuration with web defaults applied
18
+ * Creates a CoFHE configuration for web with IndexedDB storage as default
19
+ * @param config - The CoFHE input configuration (fheKeyStorage will default to IndexedDB if not provided)
20
+ * @returns The CoFHE configuration with web defaults applied
21
21
  */
22
- declare function createCofhesdkConfig(config: CofhesdkInputConfig): CofhesdkConfig;
22
+ declare function createCofheConfig(config: CofheInputConfig): CofheConfig;
23
23
  /**
24
- * Creates a CoFHE SDK client instance for web with TFHE automatically configured
24
+ * Creates a CoFHE client instance for web with TFHE automatically configured
25
25
  * TFHE will be initialized automatically on first encryption - no manual setup required
26
26
  * Workers are automatically enabled if available (can be disabled via config.useWorkers)
27
- * @param config - The CoFHE SDK configuration (use createCofhesdkConfig to create with web defaults)
28
- * @returns The CoFHE SDK client instance
27
+ * @param config - The CoFHE configuration (use createCofheConfig to create with web defaults)
28
+ * @returns The CoFHE client instance
29
29
  */
30
- declare function createCofhesdkClient<TConfig extends CofhesdkConfig>(config: TConfig): CofhesdkClient<TConfig>;
30
+ declare function createCofheClient<TConfig extends CofheConfig>(config: TConfig): CofheClient<TConfig>;
31
31
 
32
32
  /**
33
33
  * Test helper: Create a client with custom worker function (for testing fallback behavior)
34
34
  * @internal - Only for testing purposes
35
35
  */
36
- declare function createCofhesdkClientWithCustomWorker(config: CofhesdkConfig, customZkProveWorkerFn: (fheKeyHex: string, crsHex: string, items: EncryptableItem[], metadata: Uint8Array) => Promise<Uint8Array>): CofhesdkClient;
36
+ declare function createCofheClientWithCustomWorker(config: CofheConfig, customZkProveWorkerFn: (fheKeyHex: string, crsHex: string, items: EncryptableItem[], metadata: Uint8Array) => Promise<Uint8Array>): CofheClient;
37
37
 
38
- export { areWorkersAvailable, createCofhesdkClient, createCofhesdkClientWithCustomWorker, createCofhesdkConfig, terminateWorker };
38
+ export { areWorkersAvailable, createCofheClient, createCofheClientWithCustomWorker, createCofheConfig, terminateWorker };
package/dist/web.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { C as CofhesdkInputConfig, a as CofhesdkConfig, b as CofhesdkClient, E as EncryptableItem } from './clientTypes-Es7fyi65.js';
1
+ import { C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-6aTZPQ_4.js';
2
2
  import 'viem';
3
- import './types-KImPrEIe.js';
3
+ import './types-YiAC4gig.js';
4
4
  import 'zod';
5
- import './permit-fUSe6KKq.js';
5
+ import './permit-MZ502UBl.js';
6
6
  import 'zustand/vanilla';
7
7
 
8
8
  /**
@@ -15,24 +15,24 @@ declare function terminateWorker(): void;
15
15
  declare function areWorkersAvailable(): boolean;
16
16
 
17
17
  /**
18
- * Creates a CoFHE SDK configuration for web with IndexedDB storage as default
19
- * @param config - The CoFHE SDK input configuration (fheKeyStorage will default to IndexedDB if not provided)
20
- * @returns The CoFHE SDK configuration with web defaults applied
18
+ * Creates a CoFHE configuration for web with IndexedDB storage as default
19
+ * @param config - The CoFHE input configuration (fheKeyStorage will default to IndexedDB if not provided)
20
+ * @returns The CoFHE configuration with web defaults applied
21
21
  */
22
- declare function createCofhesdkConfig(config: CofhesdkInputConfig): CofhesdkConfig;
22
+ declare function createCofheConfig(config: CofheInputConfig): CofheConfig;
23
23
  /**
24
- * Creates a CoFHE SDK client instance for web with TFHE automatically configured
24
+ * Creates a CoFHE client instance for web with TFHE automatically configured
25
25
  * TFHE will be initialized automatically on first encryption - no manual setup required
26
26
  * Workers are automatically enabled if available (can be disabled via config.useWorkers)
27
- * @param config - The CoFHE SDK configuration (use createCofhesdkConfig to create with web defaults)
28
- * @returns The CoFHE SDK client instance
27
+ * @param config - The CoFHE configuration (use createCofheConfig to create with web defaults)
28
+ * @returns The CoFHE client instance
29
29
  */
30
- declare function createCofhesdkClient<TConfig extends CofhesdkConfig>(config: TConfig): CofhesdkClient<TConfig>;
30
+ declare function createCofheClient<TConfig extends CofheConfig>(config: TConfig): CofheClient<TConfig>;
31
31
 
32
32
  /**
33
33
  * Test helper: Create a client with custom worker function (for testing fallback behavior)
34
34
  * @internal - Only for testing purposes
35
35
  */
36
- declare function createCofhesdkClientWithCustomWorker(config: CofhesdkConfig, customZkProveWorkerFn: (fheKeyHex: string, crsHex: string, items: EncryptableItem[], metadata: Uint8Array) => Promise<Uint8Array>): CofhesdkClient;
36
+ declare function createCofheClientWithCustomWorker(config: CofheConfig, customZkProveWorkerFn: (fheKeyHex: string, crsHex: string, items: EncryptableItem[], metadata: Uint8Array) => Promise<Uint8Array>): CofheClient;
37
37
 
38
- export { areWorkersAvailable, createCofhesdkClient, createCofhesdkClientWithCustomWorker, createCofhesdkConfig, terminateWorker };
38
+ export { areWorkersAvailable, createCofheClient, createCofheClientWithCustomWorker, createCofheConfig, terminateWorker };
package/dist/web.js CHANGED
@@ -1,6 +1,6 @@
1
- import { createCofhesdkConfigBase, createCofhesdkClientBase, fheTypeToString } from './chunk-WGCRJCBR.js';
2
- import './chunk-WEAZ25JO.js';
3
- import './chunk-UGBVZNRT.js';
1
+ import { createCofheConfigBase, createCofheClientBase, fheTypeToString } from './chunk-2TPSCOW3.js';
2
+ import './chunk-TBLR7NNE.js';
3
+ import './chunk-NWDKXBIP.js';
4
4
  import { constructClient } from 'iframe-shared-storage';
5
5
  import init, { init_panic_hook, TfheCompactPublicKey, CompactPkeCrs, ProvenCompactCiphertextList } from 'tfhe';
6
6
 
@@ -207,15 +207,15 @@ async function zkProveWithWorker(fheKeyHex, crsHex, items, metadata) {
207
207
  const workerManager2 = getWorkerManager();
208
208
  return await workerManager2.submitProof(fheKeyHex, crsHex, serializedItems, metadata);
209
209
  }
210
- function createCofhesdkConfig(config) {
211
- return createCofhesdkConfigBase({
210
+ function createCofheConfig(config) {
211
+ return createCofheConfigBase({
212
212
  environment: "web",
213
213
  ...config,
214
214
  fheKeyStorage: config.fheKeyStorage === null ? null : config.fheKeyStorage ?? createWebStorage()
215
215
  });
216
216
  }
217
- function createCofhesdkClient(config) {
218
- return createCofhesdkClientBase({
217
+ function createCofheClient(config) {
218
+ return createCofheClientBase({
219
219
  config,
220
220
  zkBuilderAndCrsGenerator,
221
221
  tfhePublicKeyDeserializer,
@@ -226,8 +226,8 @@ function createCofhesdkClient(config) {
226
226
  zkProveWorkerFn: areWorkersAvailable() ? zkProveWithWorker : void 0
227
227
  });
228
228
  }
229
- function createCofhesdkClientWithCustomWorker(config, customZkProveWorkerFn) {
230
- return createCofhesdkClientBase({
229
+ function createCofheClientWithCustomWorker(config, customZkProveWorkerFn) {
230
+ return createCofheClientBase({
231
231
  config,
232
232
  zkBuilderAndCrsGenerator,
233
233
  tfhePublicKeyDeserializer,
@@ -237,4 +237,4 @@ function createCofhesdkClientWithCustomWorker(config, customZkProveWorkerFn) {
237
237
  });
238
238
  }
239
239
 
240
- export { areWorkersAvailable, createCofhesdkClient, createCofhesdkClientWithCustomWorker, createCofhesdkConfig, terminateWorker };
240
+ export { areWorkersAvailable, createCofheClient, createCofheClientWithCustomWorker, createCofheConfig, terminateWorker };
@@ -1,19 +1,19 @@
1
- import { type CofhesdkClient, CofhesdkError, CofhesdkErrorCode } from '@/core';
2
- import { arbSepolia as cofhesdkArbSepolia } from '@/chains';
1
+ import { type CofheClient, CofheError, CofheErrorCode } from '@/core';
2
+ import { arbSepolia as cofheArbSepolia } from '@/chains';
3
3
 
4
4
  import { describe, it, expect, beforeAll, beforeEach, vi } from 'vitest';
5
5
  import type { PublicClient, WalletClient } from 'viem';
6
6
  import { createPublicClient, createWalletClient, http } from 'viem';
7
7
  import { privateKeyToAccount } from 'viem/accounts';
8
8
  import { arbitrumSepolia as viemArbitrumSepolia } from 'viem/chains';
9
- import { createCofhesdkClient, createCofhesdkConfig } from './index.js';
9
+ import { createCofheClient, createCofheConfig } from './index.js';
10
10
 
11
11
  // Real test setup - no mocks
12
12
  const TEST_PRIVATE_KEY = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80';
13
13
  const TEST_ACCOUNT = privateKeyToAccount(TEST_PRIVATE_KEY).address;
14
14
 
15
15
  describe('@cofhe/node - Client Integration Tests', () => {
16
- let cofhesdkClient: CofhesdkClient;
16
+ let cofheClient: CofheClient;
17
17
  let publicClient: PublicClient;
18
18
  let walletClient: WalletClient;
19
19
 
@@ -33,62 +33,62 @@ describe('@cofhe/node - Client Integration Tests', () => {
33
33
  });
34
34
 
35
35
  beforeEach(() => {
36
- const config = createCofhesdkConfig({
37
- supportedChains: [cofhesdkArbSepolia],
36
+ const config = createCofheConfig({
37
+ supportedChains: [cofheArbSepolia],
38
38
  });
39
- cofhesdkClient = createCofhesdkClient(config);
39
+ cofheClient = createCofheClient(config);
40
40
  });
41
41
 
42
42
  describe('Real Client Initialization', () => {
43
43
  it('should create a client with real node-tfhe', () => {
44
- expect(cofhesdkClient).toBeDefined();
45
- expect(cofhesdkClient.config).toBeDefined();
46
- expect(cofhesdkClient.connected).toBe(false);
44
+ expect(cofheClient).toBeDefined();
45
+ expect(cofheClient.config).toBeDefined();
46
+ expect(cofheClient.connected).toBe(false);
47
47
  });
48
48
 
49
49
  it('should automatically use filesystem storage as default', () => {
50
- expect(cofhesdkClient.config.fheKeyStorage).toBeDefined();
51
- expect(cofhesdkClient.config.fheKeyStorage).not.toBeNull();
50
+ expect(cofheClient.config.fheKeyStorage).toBeDefined();
51
+ expect(cofheClient.config.fheKeyStorage).not.toBeNull();
52
52
  });
53
53
 
54
54
  it('should have all expected methods', () => {
55
- expect(typeof cofhesdkClient.connect).toBe('function');
56
- expect(typeof cofhesdkClient.encryptInputs).toBe('function');
57
- expect(typeof cofhesdkClient.decryptHandle).toBe('function');
58
- expect(typeof cofhesdkClient.getSnapshot).toBe('function');
59
- expect(typeof cofhesdkClient.subscribe).toBe('function');
55
+ expect(typeof cofheClient.connect).toBe('function');
56
+ expect(typeof cofheClient.encryptInputs).toBe('function');
57
+ expect(typeof cofheClient.decryptForView).toBe('function');
58
+ expect(typeof cofheClient.getSnapshot).toBe('function');
59
+ expect(typeof cofheClient.subscribe).toBe('function');
60
60
  });
61
61
  });
62
62
 
63
63
  describe('Environment', () => {
64
64
  it('should have the correct environment', () => {
65
- expect(cofhesdkClient.config.environment).toBe('node');
65
+ expect(cofheClient.config.environment).toBe('node');
66
66
  });
67
67
  });
68
68
 
69
69
  describe('Real Connection', () => {
70
70
  it('should connect to real chain', async () => {
71
- await cofhesdkClient.connect(publicClient, walletClient);
71
+ await cofheClient.connect(publicClient, walletClient);
72
72
 
73
- expect(cofhesdkClient.connected).toBe(true);
73
+ expect(cofheClient.connected).toBe(true);
74
74
 
75
- const snapshot = cofhesdkClient.getSnapshot();
75
+ const snapshot = cofheClient.getSnapshot();
76
76
  expect(snapshot.connected).toBe(true);
77
- expect(snapshot.chainId).toBe(cofhesdkArbSepolia.id);
77
+ expect(snapshot.chainId).toBe(cofheArbSepolia.id);
78
78
  expect(snapshot.account).toBe(TEST_ACCOUNT);
79
79
  }, 30000);
80
80
 
81
81
  it('should handle real network errors', async () => {
82
82
  try {
83
- await cofhesdkClient.connect(
83
+ await cofheClient.connect(
84
84
  {
85
85
  getChainId: vi.fn().mockRejectedValue(new Error('Network error')),
86
86
  } as unknown as PublicClient,
87
87
  walletClient
88
88
  );
89
89
  } catch (error) {
90
- expect(error).toBeInstanceOf(CofhesdkError);
91
- expect((error as CofhesdkError).code).toBe(CofhesdkErrorCode.PublicWalletGetChainIdFailed);
90
+ expect(error).toBeInstanceOf(CofheError);
91
+ expect((error as CofheError).code).toBe(CofheErrorCode.PublicWalletGetChainIdFailed);
92
92
  }
93
93
  }, 30000);
94
94
  });
@@ -96,11 +96,11 @@ describe('@cofhe/node - Client Integration Tests', () => {
96
96
  describe('State Management', () => {
97
97
  it('should track connection state changes', async () => {
98
98
  const states: any[] = [];
99
- const unsubscribe = cofhesdkClient.subscribe((snapshot) => {
99
+ const unsubscribe = cofheClient.subscribe((snapshot) => {
100
100
  states.push({ ...snapshot });
101
101
  });
102
102
 
103
- await cofhesdkClient.connect(publicClient, walletClient);
103
+ await cofheClient.connect(publicClient, walletClient);
104
104
 
105
105
  unsubscribe();
106
106
 
@@ -116,32 +116,32 @@ describe('@cofhe/node - Client Integration Tests', () => {
116
116
  const lastState = states[states.length - 1];
117
117
  expect(lastState.connected).toBe(true);
118
118
  expect(lastState.connecting).toBe(false);
119
- expect(lastState.chainId).toBe(cofhesdkArbSepolia.id);
119
+ expect(lastState.chainId).toBe(cofheArbSepolia.id);
120
120
  }, 30000);
121
121
  });
122
122
 
123
123
  describe('Builder Creation', () => {
124
124
  it('should create encrypt builder after connection', async () => {
125
- await cofhesdkClient.connect(publicClient, walletClient);
125
+ await cofheClient.connect(publicClient, walletClient);
126
126
 
127
- const builder = cofhesdkClient.encryptInputs([{ data: 100n, utype: 2, securityZone: 0 }]);
127
+ const builder = cofheClient.encryptInputs([{ data: 100n, utype: 2, securityZone: 0 }]);
128
128
 
129
129
  expect(builder).toBeDefined();
130
130
  expect(typeof builder.setChainId).toBe('function');
131
131
  expect(typeof builder.setAccount).toBe('function');
132
132
  expect(typeof builder.setSecurityZone).toBe('function');
133
- expect(typeof builder.encrypt).toBe('function');
133
+ expect(typeof builder.execute).toBe('function');
134
134
  }, 30000);
135
135
 
136
136
  it('should create decrypt builder after connection', async () => {
137
- await cofhesdkClient.connect(publicClient, walletClient);
137
+ await cofheClient.connect(publicClient, walletClient);
138
138
 
139
- const builder = cofhesdkClient.decryptHandle(123n, 2);
139
+ const builder = cofheClient.decryptForView(123n, 2);
140
140
 
141
141
  expect(builder).toBeDefined();
142
142
  expect(typeof builder.setChainId).toBe('function');
143
143
  expect(typeof builder.setAccount).toBe('function');
144
- expect(typeof builder.decrypt).toBe('function');
144
+ expect(typeof builder.execute).toBe('function');
145
145
  }, 30000);
146
146
  });
147
147
  });
@@ -1,12 +1,12 @@
1
1
  import { arbSepolia } from '@/chains';
2
2
 
3
3
  import { describe, it, expect } from 'vitest';
4
- import { createCofhesdkConfig, createCofhesdkClient } from './index.js';
4
+ import { createCofheConfig, createCofheClient } from './index.js';
5
5
 
6
6
  describe('@cofhe/node - Config', () => {
7
- describe('createCofhesdkConfig', () => {
7
+ describe('createCofheConfig', () => {
8
8
  it('should automatically inject filesystem storage as default', () => {
9
- const config = createCofhesdkConfig({
9
+ const config = createCofheConfig({
10
10
  supportedChains: [arbSepolia],
11
11
  });
12
12
 
@@ -21,7 +21,7 @@ describe('@cofhe/node - Config', () => {
21
21
  setItem: () => Promise.resolve(),
22
22
  removeItem: () => Promise.resolve(),
23
23
  };
24
- const config = createCofhesdkConfig({
24
+ const config = createCofheConfig({
25
25
  supportedChains: [arbSepolia],
26
26
  fheKeyStorage: customStorage,
27
27
  });
@@ -30,7 +30,7 @@ describe('@cofhe/node - Config', () => {
30
30
  });
31
31
 
32
32
  it('should allow null storage', () => {
33
- const config = createCofhesdkConfig({
33
+ const config = createCofheConfig({
34
34
  supportedChains: [arbSepolia],
35
35
  fheKeyStorage: null,
36
36
  });
@@ -39,26 +39,26 @@ describe('@cofhe/node - Config', () => {
39
39
  });
40
40
 
41
41
  it('should preserve all other config options', () => {
42
- const config = createCofhesdkConfig({
42
+ const config = createCofheConfig({
43
43
  supportedChains: [arbSepolia],
44
44
  mocks: {
45
- sealOutputDelay: 0,
45
+ decryptDelay: 0,
46
46
  },
47
47
  });
48
48
 
49
49
  expect(config.supportedChains).toEqual([arbSepolia]);
50
- expect(config.mocks.sealOutputDelay).toBe(0);
50
+ expect(config.mocks.decryptDelay).toBe(0);
51
51
  expect(config.fheKeyStorage).toBeDefined();
52
52
  });
53
53
  });
54
54
 
55
- describe('createCofhesdkClient with config', () => {
55
+ describe('createCofheClient with config', () => {
56
56
  it('should create client with validated config', () => {
57
- const config = createCofhesdkConfig({
57
+ const config = createCofheConfig({
58
58
  supportedChains: [arbSepolia],
59
59
  });
60
60
 
61
- const client = createCofhesdkClient(config);
61
+ const client = createCofheClient(config);
62
62
 
63
63
  expect(client).toBeDefined();
64
64
  expect(client.config).toBe(config);
@@ -1,18 +1,18 @@
1
- import { Encryptable, FheTypes, type CofhesdkClient, CofhesdkErrorCode, CofhesdkError } from '@/core';
2
- import { arbSepolia as cofhesdkArbSepolia } from '@/chains';
1
+ import { Encryptable, FheTypes, type CofheClient, CofheErrorCode, CofheError } from '@/core';
2
+ import { arbSepolia as cofheArbSepolia } from '@/chains';
3
3
 
4
4
  import { describe, it, expect, beforeAll, beforeEach } from 'vitest';
5
5
  import type { PublicClient, WalletClient } from 'viem';
6
6
  import { createPublicClient, createWalletClient, http } from 'viem';
7
7
  import { privateKeyToAccount } from 'viem/accounts';
8
8
  import { arbitrumSepolia as viemArbitrumSepolia } from 'viem/chains';
9
- import { createCofhesdkClient, createCofhesdkConfig } from './index.js';
9
+ import { createCofheClient, createCofheConfig } from './index.js';
10
10
 
11
11
  // Real test setup - using actual node-tfhe
12
12
  const TEST_PRIVATE_KEY = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80';
13
13
 
14
14
  describe('@cofhe/node - Encrypt Inputs', () => {
15
- let cofhesdkClient: CofhesdkClient;
15
+ let cofheClient: CofheClient;
16
16
  let publicClient: PublicClient;
17
17
  let walletClient: WalletClient;
18
18
 
@@ -32,39 +32,39 @@ describe('@cofhe/node - Encrypt Inputs', () => {
32
32
  });
33
33
 
34
34
  beforeEach(() => {
35
- const config = createCofhesdkConfig({
36
- supportedChains: [cofhesdkArbSepolia],
35
+ const config = createCofheConfig({
36
+ supportedChains: [cofheArbSepolia],
37
37
  });
38
- cofhesdkClient = createCofhesdkClient(config);
38
+ cofheClient = createCofheClient(config);
39
39
  });
40
40
 
41
41
  describe('Real TFHE Initialization', () => {
42
42
  it('should initialize node-tfhe on first encryption', async () => {
43
- await cofhesdkClient.connect(publicClient, walletClient);
43
+ await cofheClient.connect(publicClient, walletClient);
44
44
 
45
45
  // This will trigger real TFHE initialization
46
- const encrypted = await cofhesdkClient.encryptInputs([Encryptable.uint128(100n)]).encrypt();
46
+ const encrypted = await cofheClient.encryptInputs([Encryptable.uint128(100n)]).execute();
47
47
 
48
48
  // If we get here, TFHE was initialized successfully
49
49
  expect(encrypted).toBeDefined();
50
50
  }, 60000); // Longer timeout for real operations
51
51
 
52
52
  it('should handle multiple encryptions without re-initializing', async () => {
53
- await cofhesdkClient.connect(publicClient, walletClient);
53
+ await cofheClient.connect(publicClient, walletClient);
54
54
 
55
55
  // First encryption
56
- await cofhesdkClient.encryptInputs([Encryptable.uint128(100n)]).encrypt();
56
+ await cofheClient.encryptInputs([Encryptable.uint128(100n)]).execute();
57
57
 
58
58
  // Second encryption should reuse initialization
59
- await cofhesdkClient.encryptInputs([Encryptable.uint64(50n)]).encrypt();
59
+ await cofheClient.encryptInputs([Encryptable.uint64(50n)]).execute();
60
60
  }, 120000);
61
61
  });
62
62
 
63
63
  describe('Real Encryption', () => {
64
64
  it('should encrypt a bool with real TFHE', async () => {
65
- await cofhesdkClient.connect(publicClient, walletClient);
65
+ await cofheClient.connect(publicClient, walletClient);
66
66
 
67
- const encrypted = await cofhesdkClient.encryptInputs([Encryptable.bool(true)]).encrypt();
67
+ const encrypted = await cofheClient.encryptInputs([Encryptable.bool(true)]).execute();
68
68
 
69
69
  expect(encrypted.length).toBe(1);
70
70
  expect(encrypted[0].utype).toBe(FheTypes.Bool);
@@ -76,7 +76,7 @@ describe('@cofhe/node - Encrypt Inputs', () => {
76
76
  }, 60000);
77
77
 
78
78
  it('should encrypt all supported types together', async () => {
79
- await cofhesdkClient.connect(publicClient, walletClient);
79
+ await cofheClient.connect(publicClient, walletClient);
80
80
 
81
81
  const inputs = [
82
82
  Encryptable.bool(false),
@@ -88,7 +88,7 @@ describe('@cofhe/node - Encrypt Inputs', () => {
88
88
  Encryptable.address('0x742d35Cc6634C0532925a3b844D16faC4c175E99'),
89
89
  ];
90
90
 
91
- const encrypted = await cofhesdkClient.encryptInputs(inputs).encrypt();
91
+ const encrypted = await cofheClient.encryptInputs(inputs).execute();
92
92
 
93
93
  expect(encrypted.length).toBe(7);
94
94
  // Verify each type
@@ -104,15 +104,15 @@ describe('@cofhe/node - Encrypt Inputs', () => {
104
104
 
105
105
  describe('Real Builder Pattern', () => {
106
106
  it('should support chaining builder methods with real encryption', async () => {
107
- await cofhesdkClient.connect(publicClient, walletClient);
107
+ await cofheClient.connect(publicClient, walletClient);
108
108
 
109
- const snapshot = cofhesdkClient.getSnapshot();
110
- const encrypted = await cofhesdkClient
109
+ const snapshot = cofheClient.getSnapshot();
110
+ const encrypted = await cofheClient
111
111
  .encryptInputs([Encryptable.uint128(100n)])
112
112
  .setChainId(snapshot.chainId!)
113
113
  .setAccount(snapshot.account!)
114
114
  .setSecurityZone(0)
115
- .encrypt();
115
+ .execute();
116
116
 
117
117
  expect(encrypted.length).toBe(1);
118
118
  expect(encrypted[0].utype).toBe(FheTypes.Uint128);
@@ -123,32 +123,32 @@ describe('@cofhe/node - Encrypt Inputs', () => {
123
123
  it('should fail gracefully when not connected', async () => {
124
124
  // Don't connect the client
125
125
  try {
126
- await cofhesdkClient.encryptInputs([Encryptable.uint128(100n)]).encrypt();
126
+ await cofheClient.encryptInputs([Encryptable.uint128(100n)]).execute();
127
127
  } catch (error) {
128
- expect(error).toBeInstanceOf(CofhesdkError);
129
- expect((error as CofhesdkError).code).toBe(CofhesdkErrorCode.NotConnected);
128
+ expect(error).toBeInstanceOf(CofheError);
129
+ expect((error as CofheError).code).toBe(CofheErrorCode.NotConnected);
130
130
  }
131
131
  }, 30000);
132
132
 
133
133
  it('should handle invalid CoFHE URL', async () => {
134
- const badConfig = createCofhesdkConfig({
134
+ const badConfig = createCofheConfig({
135
135
  supportedChains: [
136
136
  {
137
- ...cofhesdkArbSepolia,
137
+ ...cofheArbSepolia,
138
138
  coFheUrl: 'http://invalid-cofhe-url.local',
139
139
  verifierUrl: 'http://invalid-verifier-url.local',
140
140
  },
141
141
  ],
142
142
  });
143
143
 
144
- const badClient = createCofhesdkClient(badConfig);
144
+ const badClient = createCofheClient(badConfig);
145
145
  await badClient.connect(publicClient, walletClient);
146
146
 
147
147
  try {
148
- await badClient.encryptInputs([Encryptable.uint128(100n)]).encrypt();
148
+ await badClient.encryptInputs([Encryptable.uint128(100n)]).execute();
149
149
  } catch (error) {
150
- expect(error).toBeInstanceOf(CofhesdkError);
151
- expect((error as CofhesdkError).code).toBe(CofhesdkErrorCode.ZkVerifyFailed);
150
+ expect(error).toBeInstanceOf(CofheError);
151
+ expect((error as CofheError).code).toBe(CofheErrorCode.ZkVerifyFailed);
152
152
  }
153
153
  }, 60000);
154
154
  });
package/node/index.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  // Node.js specific functionality only
2
2
 
3
3
  import {
4
- createCofhesdkClientBase,
5
- createCofhesdkConfigBase,
6
- type CofhesdkClient,
7
- type CofhesdkConfig,
8
- type CofhesdkInputConfig,
4
+ createCofheClientBase,
5
+ createCofheConfigBase,
6
+ type CofheClient,
7
+ type CofheConfig,
8
+ type CofheInputConfig,
9
9
  type ZkBuilderAndCrsGenerator,
10
10
  type FheKeyDeserializer,
11
11
  } from '@/core';
@@ -68,12 +68,12 @@ const zkBuilderAndCrsGenerator: ZkBuilderAndCrsGenerator = (fhe: string, crs: st
68
68
  };
69
69
 
70
70
  /**
71
- * Creates a CoFHE SDK configuration for Node.js with filesystem storage as default
72
- * @param config - The CoFHE SDK input configuration (fheKeyStorage will default to filesystem if not provided)
73
- * @returns The CoFHE SDK configuration with Node.js defaults applied
71
+ * Creates a CoFHE configuration for Node.js with filesystem storage as default
72
+ * @param config - The CoFHE input configuration (fheKeyStorage will default to filesystem if not provided)
73
+ * @returns The CoFHE configuration with Node.js defaults applied
74
74
  */
75
- export function createCofhesdkConfig(config: CofhesdkInputConfig): CofhesdkConfig {
76
- return createCofhesdkConfigBase({
75
+ export function createCofheConfig(config: CofheInputConfig): CofheConfig {
76
+ return createCofheConfigBase({
77
77
  environment: 'node',
78
78
  ...config,
79
79
  fheKeyStorage: config.fheKeyStorage === null ? null : config.fheKeyStorage ?? createNodeStorage(),
@@ -81,13 +81,13 @@ export function createCofhesdkConfig(config: CofhesdkInputConfig): CofhesdkConfi
81
81
  }
82
82
 
83
83
  /**
84
- * Creates a CoFHE SDK client instance for Node.js with node-tfhe automatically configured
84
+ * Creates a CoFHE client instance for Node.js with node-tfhe automatically configured
85
85
  * TFHE will be initialized automatically on first encryption - no manual setup required
86
- * @param config - The CoFHE SDK configuration (use createCofhesdkConfig to create with Node.js defaults)
87
- * @returns The CoFHE SDK client instance
86
+ * @param config - The CoFHE configuration (use createCofheConfig to create with Node.js defaults)
87
+ * @returns The CoFHE client instance
88
88
  */
89
- export function createCofhesdkClient(config: CofhesdkConfig): CofhesdkClient {
90
- return createCofhesdkClientBase({
89
+ export function createCofheClient(config: CofheConfig): CofheClient {
90
+ return createCofheClientBase({
91
91
  config,
92
92
  zkBuilderAndCrsGenerator,
93
93
  tfhePublicKeyDeserializer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cofhe/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "description": "SDK for Fhenix COFHE coprocessor interaction",
6
6
  "main": "./dist/core.cjs",
@@ -63,7 +63,7 @@
63
63
  "tfhe": "0.11.1",
64
64
  "tweetnacl": "^1.0.3",
65
65
  "viem": "^2.38.6",
66
- "zod": "^3.22.0",
66
+ "zod": "^4.0.0",
67
67
  "zustand": "^5.0.1"
68
68
  },
69
69
  "peerDependencies": {
@@ -111,7 +111,7 @@
111
111
  "build": "tsup",
112
112
  "dev": "tsup --watch",
113
113
  "lint": "eslint \"**/*.ts*\"",
114
- "type-check": "tsc --noEmit",
114
+ "check:types": "tsc --noEmit",
115
115
  "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
116
116
  "test": "vitest run",
117
117
  "test:watch": "vitest",