@cofhe/sdk 0.2.1 → 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 (54) hide show
  1. package/CHANGELOG.md +28 -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 +1 -1
  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
@@ -1,4 +1,4 @@
1
- import { arbSepolia as cofhesdkArbSepolia } from '@/chains';
1
+ import { arbSepolia as cofheArbSepolia } from '@/chains';
2
2
  import { Encryptable } from '@/core';
3
3
 
4
4
  import { describe, it, expect, beforeAll } from 'vitest';
@@ -6,7 +6,7 @@ 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, createCofhesdkClientWithCustomWorker } from './index.js';
9
+ import { createCofheClient, createCofheConfig, createCofheClientWithCustomWorker } from './index.js';
10
10
 
11
11
  const TEST_PRIVATE_KEY = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80';
12
12
 
@@ -30,26 +30,26 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => {
30
30
 
31
31
  describe('useWorkers config flag', () => {
32
32
  it('should use workers by default (useWorkers: true)', async () => {
33
- const config = createCofhesdkConfig({
34
- supportedChains: [cofhesdkArbSepolia],
33
+ const config = createCofheConfig({
34
+ supportedChains: [cofheArbSepolia],
35
35
  // useWorkers defaults to true
36
36
  });
37
37
 
38
38
  expect(config.useWorkers).toBe(true);
39
39
 
40
- const client = createCofhesdkClient(config);
40
+ const client = createCofheClient(config);
41
41
  await client.connect(publicClient, walletClient);
42
42
 
43
43
  // Track step callbacks to see worker usage
44
44
  let proveContext: any;
45
45
  const result = await client
46
46
  .encryptInputs([Encryptable.uint128(100n)])
47
- .setStepCallback((step, context) => {
47
+ .onStep((step, context) => {
48
48
  if (step === 'prove' && context?.isEnd) {
49
49
  proveContext = context;
50
50
  }
51
51
  })
52
- .encrypt();
52
+ .execute();
53
53
 
54
54
  expect(result).toBeDefined();
55
55
 
@@ -71,26 +71,26 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => {
71
71
  }, 60000);
72
72
 
73
73
  it('should disable workers when useWorkers: false', async () => {
74
- const config = createCofhesdkConfig({
75
- supportedChains: [cofhesdkArbSepolia],
74
+ const config = createCofheConfig({
75
+ supportedChains: [cofheArbSepolia],
76
76
  useWorkers: false,
77
77
  });
78
78
 
79
79
  expect(config.useWorkers).toBe(false);
80
80
 
81
- const client = createCofhesdkClient(config);
81
+ const client = createCofheClient(config);
82
82
  await client.connect(publicClient, walletClient);
83
83
 
84
84
  // Track step callbacks
85
85
  let proveContext: any;
86
86
  const result = await client
87
87
  .encryptInputs([Encryptable.uint128(100n)])
88
- .setStepCallback((step, context) => {
88
+ .onStep((step, context) => {
89
89
  if (step === 'prove' && context?.isEnd) {
90
90
  proveContext = context;
91
91
  }
92
92
  })
93
- .encrypt();
93
+ .execute();
94
94
 
95
95
  expect(result).toBeDefined();
96
96
 
@@ -103,12 +103,12 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => {
103
103
 
104
104
  describe('setUseWorker() method', () => {
105
105
  it('should override config with setUseWorker(false)', async () => {
106
- const config = createCofhesdkConfig({
107
- supportedChains: [cofhesdkArbSepolia],
106
+ const config = createCofheConfig({
107
+ supportedChains: [cofheArbSepolia],
108
108
  useWorkers: true, // Config says true
109
109
  });
110
110
 
111
- const client = createCofhesdkClient(config);
111
+ const client = createCofheClient(config);
112
112
  await client.connect(publicClient, walletClient);
113
113
 
114
114
  // Track step callbacks
@@ -116,12 +116,12 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => {
116
116
  const result = await client
117
117
  .encryptInputs([Encryptable.uint128(100n)])
118
118
  .setUseWorker(false) // Override to false
119
- .setStepCallback((step, context) => {
119
+ .onStep((step, context) => {
120
120
  if (step === 'prove' && context?.isEnd) {
121
121
  proveContext = context;
122
122
  }
123
123
  })
124
- .encrypt();
124
+ .execute();
125
125
 
126
126
  expect(result).toBeDefined();
127
127
 
@@ -131,12 +131,12 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => {
131
131
  }, 60000);
132
132
 
133
133
  it('should override config with setUseWorker(true)', async () => {
134
- const config = createCofhesdkConfig({
135
- supportedChains: [cofhesdkArbSepolia],
134
+ const config = createCofheConfig({
135
+ supportedChains: [cofheArbSepolia],
136
136
  useWorkers: false, // Config says false
137
137
  });
138
138
 
139
- const client = createCofhesdkClient(config);
139
+ const client = createCofheClient(config);
140
140
  await client.connect(publicClient, walletClient);
141
141
 
142
142
  // Track step callbacks
@@ -144,12 +144,12 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => {
144
144
  const result = await client
145
145
  .encryptInputs([Encryptable.uint128(100n)])
146
146
  .setUseWorker(true) // Override to true
147
- .setStepCallback((step, context) => {
147
+ .onStep((step, context) => {
148
148
  if (step === 'prove' && context?.isEnd) {
149
149
  proveContext = context;
150
150
  }
151
151
  })
152
- .encrypt();
152
+ .execute();
153
153
 
154
154
  expect(result).toBeDefined();
155
155
 
@@ -160,22 +160,22 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => {
160
160
 
161
161
  describe('Step callback worker context', () => {
162
162
  it('should include worker debug info in prove step', async () => {
163
- const config = createCofhesdkConfig({
164
- supportedChains: [cofhesdkArbSepolia],
163
+ const config = createCofheConfig({
164
+ supportedChains: [cofheArbSepolia],
165
165
  });
166
166
 
167
- const client = createCofhesdkClient(config);
167
+ const client = createCofheClient(config);
168
168
  await client.connect(publicClient, walletClient);
169
169
 
170
170
  let proveContext: any;
171
171
  const result = await client
172
172
  .encryptInputs([Encryptable.uint128(100n)])
173
- .setStepCallback((step, context) => {
173
+ .onStep((step, context) => {
174
174
  if (step === 'prove' && context?.isEnd) {
175
175
  proveContext = context;
176
176
  }
177
177
  })
178
- .encrypt();
178
+ .execute();
179
179
 
180
180
  expect(result).toBeDefined();
181
181
 
@@ -196,8 +196,8 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => {
196
196
 
197
197
  describe('Worker fallback behavior', () => {
198
198
  it('should fallback to main thread when worker fails', async () => {
199
- const config = createCofhesdkConfig({
200
- supportedChains: [cofhesdkArbSepolia],
199
+ const config = createCofheConfig({
200
+ supportedChains: [cofheArbSepolia],
201
201
  useWorkers: true,
202
202
  });
203
203
 
@@ -207,19 +207,19 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => {
207
207
  };
208
208
 
209
209
  // Inject the failing worker into the client
210
- const client = createCofhesdkClientWithCustomWorker(config, failingWorkerFn);
210
+ const client = createCofheClientWithCustomWorker(config, failingWorkerFn);
211
211
  await client.connect(publicClient, walletClient);
212
212
 
213
213
  // Track step callbacks to verify fallback
214
214
  let proveContext: any;
215
215
  const result = await client
216
216
  .encryptInputs([Encryptable.uint128(100n)])
217
- .setStepCallback((step, context) => {
217
+ .onStep((step, context) => {
218
218
  if (step === 'prove' && context?.isEnd) {
219
219
  proveContext = context;
220
220
  }
221
221
  })
222
- .encrypt();
222
+ .execute();
223
223
 
224
224
  // Verify encryption succeeded via fallback to main thread
225
225
  expect(result).toBeDefined();
@@ -233,8 +233,8 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => {
233
233
  }, 60000);
234
234
 
235
235
  it('should fallback when encrypting multiple values', async () => {
236
- const config = createCofhesdkConfig({
237
- supportedChains: [cofhesdkArbSepolia],
236
+ const config = createCofheConfig({
237
+ supportedChains: [cofheArbSepolia],
238
238
  useWorkers: true,
239
239
  });
240
240
 
@@ -243,18 +243,18 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => {
243
243
  throw new Error('Worker unavailable');
244
244
  };
245
245
 
246
- const client = createCofhesdkClientWithCustomWorker(config, failingWorkerFn);
246
+ const client = createCofheClientWithCustomWorker(config, failingWorkerFn);
247
247
  await client.connect(publicClient, walletClient);
248
248
 
249
249
  let proveContext: any;
250
250
  const result = await client
251
251
  .encryptInputs([Encryptable.uint128(100n), Encryptable.uint64(50n), Encryptable.bool(true)])
252
- .setStepCallback((step, context) => {
252
+ .onStep((step, context) => {
253
253
  if (step === 'prove' && context?.isEnd) {
254
254
  proveContext = context;
255
255
  }
256
256
  })
257
- .encrypt();
257
+ .execute();
258
258
 
259
259
  // All values should encrypt successfully via fallback
260
260
  expect(result).toBeDefined();
@@ -267,8 +267,8 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => {
267
267
  }, 60000);
268
268
 
269
269
  it('should handle async worker errors gracefully', async () => {
270
- const config = createCofhesdkConfig({
271
- supportedChains: [cofhesdkArbSepolia],
270
+ const config = createCofheConfig({
271
+ supportedChains: [cofheArbSepolia],
272
272
  useWorkers: true,
273
273
  });
274
274
 
@@ -278,18 +278,18 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => {
278
278
  throw new Error('Async worker failure');
279
279
  };
280
280
 
281
- const client = createCofhesdkClientWithCustomWorker(config, asyncFailingWorkerFn);
281
+ const client = createCofheClientWithCustomWorker(config, asyncFailingWorkerFn);
282
282
  await client.connect(publicClient, walletClient);
283
283
 
284
284
  let proveContext: any;
285
285
  const result = await client
286
286
  .encryptInputs([Encryptable.uint8(42n)])
287
- .setStepCallback((step, context) => {
287
+ .onStep((step, context) => {
288
288
  if (step === 'prove' && context?.isEnd) {
289
289
  proveContext = context;
290
290
  }
291
291
  })
292
- .encrypt();
292
+ .execute();
293
293
 
294
294
  expect(result).toBeDefined();
295
295
 
@@ -299,24 +299,24 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => {
299
299
  }, 60000);
300
300
 
301
301
  it('should work without worker when explicitly disabled', async () => {
302
- const config = createCofhesdkConfig({
303
- supportedChains: [cofhesdkArbSepolia],
302
+ const config = createCofheConfig({
303
+ supportedChains: [cofheArbSepolia],
304
304
  useWorkers: true, // Config says use workers
305
305
  });
306
306
 
307
- const client = createCofhesdkClient(config);
307
+ const client = createCofheClient(config);
308
308
  await client.connect(publicClient, walletClient);
309
309
 
310
310
  let proveContext: any;
311
311
  const result = await client
312
312
  .encryptInputs([Encryptable.uint8(42n)])
313
313
  .setUseWorker(false) // But override to disable worker
314
- .setStepCallback((step, context) => {
314
+ .onStep((step, context) => {
315
315
  if (step === 'prove' && context?.isEnd) {
316
316
  proveContext = context;
317
317
  }
318
318
  })
319
- .encrypt();
319
+ .execute();
320
320
 
321
321
  expect(result).toBeDefined();
322
322
 
@@ -1,4 +1,4 @@
1
- import { arbSepolia as cofhesdkArbSepolia } from '@/chains';
1
+ import { arbSepolia as cofheArbSepolia } from '@/chains';
2
2
  import { Encryptable } from '@/core';
3
3
 
4
4
  import { describe, it, expect, beforeAll } from 'vitest';
@@ -6,7 +6,7 @@ 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
  const TEST_PRIVATE_KEY = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80';
12
12
 
@@ -30,18 +30,18 @@ describe('@cofhe/sdk/web - Worker vs Main Thread Output Validation', () => {
30
30
 
31
31
  it('should produce consistent output format regardless of worker usage', async () => {
32
32
  // Create two clients - one with workers, one without
33
- const configWithWorker = createCofhesdkConfig({
34
- supportedChains: [cofhesdkArbSepolia],
33
+ const configWithWorker = createCofheConfig({
34
+ supportedChains: [cofheArbSepolia],
35
35
  useWorkers: true,
36
36
  });
37
37
 
38
- const configWithoutWorker = createCofhesdkConfig({
39
- supportedChains: [cofhesdkArbSepolia],
38
+ const configWithoutWorker = createCofheConfig({
39
+ supportedChains: [cofheArbSepolia],
40
40
  useWorkers: false,
41
41
  });
42
42
 
43
- const clientWithWorker = createCofhesdkClient(configWithWorker);
44
- const clientWithoutWorker = createCofhesdkClient(configWithoutWorker);
43
+ const clientWithWorker = createCofheClient(configWithWorker);
44
+ const clientWithoutWorker = createCofheClient(configWithoutWorker);
45
45
 
46
46
  await clientWithWorker.connect(publicClient, walletClient);
47
47
  await clientWithoutWorker.connect(publicClient, walletClient);
@@ -49,8 +49,8 @@ describe('@cofhe/sdk/web - Worker vs Main Thread Output Validation', () => {
49
49
  const value = Encryptable.uint128(12345n);
50
50
 
51
51
  const [resultWithWorker, resultWithoutWorker] = await Promise.all([
52
- clientWithWorker.encryptInputs([value]).encrypt(),
53
- clientWithoutWorker.encryptInputs([value]).encrypt(),
52
+ clientWithWorker.encryptInputs([value]).execute(),
53
+ clientWithoutWorker.encryptInputs([value]).execute(),
54
54
  ]);
55
55
 
56
56
  // Both should succeed