@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.
- package/CHANGELOG.md +34 -0
- package/core/baseBuilder.ts +18 -18
- package/core/client.test.ts +58 -55
- package/core/client.ts +50 -30
- package/core/clientTypes.ts +21 -17
- package/core/config.test.ts +32 -33
- package/core/config.ts +47 -48
- package/core/consts.ts +6 -2
- package/core/decrypt/{MockQueryDecrypterAbi.ts → MockThresholdNetworkAbi.ts} +71 -21
- package/core/decrypt/cofheMocksDecryptForTx.ts +142 -0
- package/core/decrypt/{cofheMocksSealOutput.ts → cofheMocksDecryptForView.ts} +12 -12
- package/core/decrypt/decryptForTxBuilder.ts +340 -0
- package/core/decrypt/{decryptHandleBuilder.ts → decryptForViewBuilder.ts} +75 -42
- package/core/decrypt/tnDecrypt.ts +232 -0
- package/core/decrypt/tnSealOutputV1.ts +5 -5
- package/core/decrypt/tnSealOutputV2.ts +27 -27
- package/core/encrypt/cofheMocksZkVerifySign.ts +15 -15
- package/core/encrypt/encryptInputsBuilder.test.ts +57 -61
- package/core/encrypt/encryptInputsBuilder.ts +65 -42
- package/core/encrypt/zkPackProveVerify.ts +11 -11
- package/core/error.ts +18 -18
- package/core/fetchKeys.test.ts +3 -3
- package/core/fetchKeys.ts +3 -3
- package/core/index.ts +14 -11
- package/core/utils.ts +10 -10
- package/dist/{chunk-I5WFEYXX.js → chunk-2TPSCOW3.js} +791 -209
- package/dist/{chunk-R3B5TMVX.js → chunk-NWDKXBIP.js} +3 -2
- package/dist/{clientTypes-RqkgkV2i.d.ts → clientTypes-6aTZPQ_4.d.ts} +204 -85
- package/dist/{clientTypes-e4filDzK.d.cts → clientTypes-Bhq7pCSA.d.cts} +204 -85
- package/dist/core.cjs +799 -214
- package/dist/core.d.cts +25 -23
- package/dist/core.d.ts +25 -23
- package/dist/core.js +2 -2
- package/dist/node.cjs +748 -165
- package/dist/node.d.cts +10 -10
- package/dist/node.d.ts +10 -10
- package/dist/node.js +7 -7
- package/dist/permits.js +1 -1
- package/dist/web.cjs +751 -168
- package/dist/web.d.cts +11 -11
- package/dist/web.d.ts +11 -11
- package/dist/web.js +9 -9
- package/node/client.test.ts +34 -34
- package/node/config.test.ts +11 -11
- package/node/encryptInputs.test.ts +29 -29
- package/node/index.ts +15 -15
- package/package.json +3 -3
- package/web/client.web.test.ts +34 -34
- package/web/config.web.test.ts +11 -11
- package/web/encryptInputs.web.test.ts +29 -29
- package/web/index.ts +19 -19
- package/web/worker.builder.web.test.ts +28 -28
- package/web/worker.config.web.test.ts +47 -47
- package/web/worker.output.web.test.ts +10 -10
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { arbSepolia as
|
|
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 {
|
|
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 =
|
|
34
|
-
supportedChains: [
|
|
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 =
|
|
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
|
-
.
|
|
47
|
+
.onStep((step, context) => {
|
|
48
48
|
if (step === 'prove' && context?.isEnd) {
|
|
49
49
|
proveContext = context;
|
|
50
50
|
}
|
|
51
51
|
})
|
|
52
|
-
.
|
|
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 =
|
|
75
|
-
supportedChains: [
|
|
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 =
|
|
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
|
-
.
|
|
88
|
+
.onStep((step, context) => {
|
|
89
89
|
if (step === 'prove' && context?.isEnd) {
|
|
90
90
|
proveContext = context;
|
|
91
91
|
}
|
|
92
92
|
})
|
|
93
|
-
.
|
|
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 =
|
|
107
|
-
supportedChains: [
|
|
106
|
+
const config = createCofheConfig({
|
|
107
|
+
supportedChains: [cofheArbSepolia],
|
|
108
108
|
useWorkers: true, // Config says true
|
|
109
109
|
});
|
|
110
110
|
|
|
111
|
-
const client =
|
|
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
|
-
.
|
|
119
|
+
.onStep((step, context) => {
|
|
120
120
|
if (step === 'prove' && context?.isEnd) {
|
|
121
121
|
proveContext = context;
|
|
122
122
|
}
|
|
123
123
|
})
|
|
124
|
-
.
|
|
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 =
|
|
135
|
-
supportedChains: [
|
|
134
|
+
const config = createCofheConfig({
|
|
135
|
+
supportedChains: [cofheArbSepolia],
|
|
136
136
|
useWorkers: false, // Config says false
|
|
137
137
|
});
|
|
138
138
|
|
|
139
|
-
const client =
|
|
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
|
-
.
|
|
147
|
+
.onStep((step, context) => {
|
|
148
148
|
if (step === 'prove' && context?.isEnd) {
|
|
149
149
|
proveContext = context;
|
|
150
150
|
}
|
|
151
151
|
})
|
|
152
|
-
.
|
|
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 =
|
|
164
|
-
supportedChains: [
|
|
163
|
+
const config = createCofheConfig({
|
|
164
|
+
supportedChains: [cofheArbSepolia],
|
|
165
165
|
});
|
|
166
166
|
|
|
167
|
-
const client =
|
|
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
|
-
.
|
|
173
|
+
.onStep((step, context) => {
|
|
174
174
|
if (step === 'prove' && context?.isEnd) {
|
|
175
175
|
proveContext = context;
|
|
176
176
|
}
|
|
177
177
|
})
|
|
178
|
-
.
|
|
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 =
|
|
200
|
-
supportedChains: [
|
|
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 =
|
|
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
|
-
.
|
|
217
|
+
.onStep((step, context) => {
|
|
218
218
|
if (step === 'prove' && context?.isEnd) {
|
|
219
219
|
proveContext = context;
|
|
220
220
|
}
|
|
221
221
|
})
|
|
222
|
-
.
|
|
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 =
|
|
237
|
-
supportedChains: [
|
|
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 =
|
|
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
|
-
.
|
|
252
|
+
.onStep((step, context) => {
|
|
253
253
|
if (step === 'prove' && context?.isEnd) {
|
|
254
254
|
proveContext = context;
|
|
255
255
|
}
|
|
256
256
|
})
|
|
257
|
-
.
|
|
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 =
|
|
271
|
-
supportedChains: [
|
|
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 =
|
|
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
|
-
.
|
|
287
|
+
.onStep((step, context) => {
|
|
288
288
|
if (step === 'prove' && context?.isEnd) {
|
|
289
289
|
proveContext = context;
|
|
290
290
|
}
|
|
291
291
|
})
|
|
292
|
-
.
|
|
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 =
|
|
303
|
-
supportedChains: [
|
|
302
|
+
const config = createCofheConfig({
|
|
303
|
+
supportedChains: [cofheArbSepolia],
|
|
304
304
|
useWorkers: true, // Config says use workers
|
|
305
305
|
});
|
|
306
306
|
|
|
307
|
-
const client =
|
|
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
|
-
.
|
|
314
|
+
.onStep((step, context) => {
|
|
315
315
|
if (step === 'prove' && context?.isEnd) {
|
|
316
316
|
proveContext = context;
|
|
317
317
|
}
|
|
318
318
|
})
|
|
319
|
-
.
|
|
319
|
+
.execute();
|
|
320
320
|
|
|
321
321
|
expect(result).toBeDefined();
|
|
322
322
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { arbSepolia as
|
|
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 {
|
|
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 =
|
|
34
|
-
supportedChains: [
|
|
33
|
+
const configWithWorker = createCofheConfig({
|
|
34
|
+
supportedChains: [cofheArbSepolia],
|
|
35
35
|
useWorkers: true,
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
-
const configWithoutWorker =
|
|
39
|
-
supportedChains: [
|
|
38
|
+
const configWithoutWorker = createCofheConfig({
|
|
39
|
+
supportedChains: [cofheArbSepolia],
|
|
40
40
|
useWorkers: false,
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
const clientWithWorker =
|
|
44
|
-
const clientWithoutWorker =
|
|
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]).
|
|
53
|
-
clientWithoutWorker.encryptInputs([value]).
|
|
52
|
+
clientWithWorker.encryptInputs([value]).execute(),
|
|
53
|
+
clientWithoutWorker.encryptInputs([value]).execute(),
|
|
54
54
|
]);
|
|
55
55
|
|
|
56
56
|
// Both should succeed
|