@cofhe/sdk 0.6.1 → 0.7.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.
- package/CHANGELOG.md +43 -0
- package/acps/acp.ts +411 -0
- package/acps/index.ts +70 -0
- package/{permits → acps}/onchain-utils.ts +49 -24
- package/acps/sealing.ts +90 -0
- package/acps/signature.ts +89 -0
- package/acps/store.ts +172 -0
- package/acps/test/acp.test.ts +615 -0
- package/acps/test/localstorage.test.ts +105 -0
- package/acps/test/sealing.test.ts +77 -0
- package/acps/test/store.test.ts +88 -0
- package/acps/test/validation.test.ts +361 -0
- package/acps/test-utils.ts +32 -0
- package/acps/types.ts +252 -0
- package/acps/validation.ts +392 -0
- package/adapters/test/ethers5.test.ts +4 -1
- package/adapters/test/ethers6.test.ts +4 -1
- package/adapters/test/wagmi.test.ts +5 -2
- package/chains/chains/stagingCofhe.ts +21 -0
- package/chains/index.ts +3 -1
- package/chains/test/chains.test.ts +2 -1
- package/core/acps.ts +625 -0
- package/core/client.ts +136 -39
- package/core/clientTypes.ts +52 -41
- package/core/config.ts +66 -5
- package/core/decrypt/MockThresholdNetworkAbi.ts +20 -11
- package/core/decrypt/apiError.ts +104 -0
- package/core/decrypt/cofheMocksDecryptForTx.ts +11 -11
- package/core/decrypt/cofheMocksDecryptForView.ts +7 -7
- package/core/decrypt/decryptForTxBuilder.ts +102 -102
- package/core/decrypt/decryptForViewBuilder.ts +90 -90
- package/core/decrypt/submitRetry.ts +38 -30
- package/core/decrypt/tnDecryptV1.ts +5 -5
- package/core/decrypt/tnDecryptV2.ts +25 -21
- package/core/decrypt/tnSealOutputV1.ts +4 -3
- package/core/decrypt/tnSealOutputV2.ts +24 -18
- package/core/encrypt/cofheMocksZkVerifySign.ts +59 -74
- package/core/encrypt/encryptInputsBuilder.ts +86 -52
- package/core/encrypt/zkPackProveVerify.ts +25 -18
- package/core/error.ts +34 -6
- package/core/index.ts +4 -14
- package/core/test/acpDefaults.test.ts +52 -0
- package/core/test/acps.test.ts +596 -0
- package/core/test/apiError.test.ts +130 -0
- package/core/test/client.test.ts +22 -19
- package/core/test/config.test.ts +25 -5
- package/core/test/decrypt.test.ts +40 -35
- package/core/test/decryptBuilders.test.ts +68 -68
- package/core/test/decryptErrorCodes.test.ts +217 -0
- package/core/test/encryptInputsBuilder.test.ts +72 -41
- package/core/test/pollCallbacks.test.ts +89 -18
- package/core/test/stagingRedirect.ts +18 -0
- package/core/test/submitRetry.test.ts +182 -0
- package/core/types.ts +9 -69
- package/dist/acp-Wi6isVQI.d.cts +407 -0
- package/dist/acp-Wi6isVQI.d.ts +407 -0
- package/dist/acps.cjs +1081 -0
- package/dist/acps.d.cts +480 -0
- package/dist/acps.d.ts +480 -0
- package/dist/acps.js +2 -0
- package/dist/chains.cjs +14 -1
- package/dist/chains.d.cts +30 -1
- package/dist/chains.d.ts +30 -1
- package/dist/chains.js +1 -1
- package/dist/{chunk-NOC3PYB7.js → chunk-43USWPEH.js} +930 -580
- package/dist/{chunk-MTRAXQXC.js → chunk-N6IDQRRU.js} +14 -2
- package/dist/chunk-Q7CBWGQX.js +1029 -0
- package/dist/{clientTypes-CyUvRRzA.d.ts → clientTypes-BN3nbzYM.d.ts} +342 -165
- package/dist/{clientTypes-BDy1qIBu.d.cts → clientTypes-CYZjFznO.d.cts} +342 -165
- package/dist/core.cjs +1358 -1002
- package/dist/core.d.cts +31 -9
- package/dist/core.d.ts +31 -9
- package/dist/core.js +3 -3
- package/dist/node.cjs +1293 -952
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.js +3 -3
- package/dist/web.cjs +1293 -952
- package/dist/web.d.cts +2 -2
- package/dist/web.d.ts +2 -2
- package/dist/web.js +3 -3
- package/node/test/inherited.test.ts +75 -65
- package/node/test/tfheinit.test.ts +23 -8
- package/package.json +6 -6
- package/web/test/client.web.test.ts +5 -1
- package/web/test/inherited.web.test.ts +75 -65
- package/web/test/tfheinit.web.test.ts +14 -5
- package/web/test/worker.config.web.test.ts +38 -23
- package/web/test/worker.output.web.test.ts +25 -24
- package/core/encrypt/encryptUtils.ts +0 -67
- package/core/permits.ts +0 -216
- package/core/test/permits.test.ts +0 -596
- package/dist/chunk-VB62WYPL.js +0 -978
- package/dist/permit-DnVMDT5h.d.cts +0 -376
- package/dist/permit-DnVMDT5h.d.ts +0 -376
- package/dist/permits.cjs +0 -1026
- package/dist/permits.d.cts +0 -353
- package/dist/permits.d.ts +0 -353
- package/dist/permits.js +0 -2
- package/permits/index.ts +0 -68
- package/permits/permit.ts +0 -385
- package/permits/sealing.ts +0 -131
- package/permits/signature.ts +0 -79
- package/permits/store.ts +0 -157
- package/permits/test/localstorage.test.ts +0 -113
- package/permits/test/permit.test.ts +0 -557
- package/permits/test/sealing.test.ts +0 -84
- package/permits/test/store.test.ts +0 -88
- package/permits/test/validation.test.ts +0 -361
- package/permits/test-utils.ts +0 -28
- package/permits/types.ts +0 -204
- package/permits/validation.ts +0 -327
- /package/{permits → acps}/utils.ts +0 -0
package/dist/web.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { I as IStorage, C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-
|
|
1
|
+
import { I as IStorage, C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-CYZjFznO.cjs';
|
|
2
2
|
import 'viem';
|
|
3
3
|
import './types-C07FK-cL.cjs';
|
|
4
4
|
import 'zod';
|
|
5
|
-
import './
|
|
5
|
+
import './acp-Wi6isVQI.cjs';
|
|
6
6
|
import 'zustand/vanilla';
|
|
7
7
|
|
|
8
8
|
declare function createSsrStorage(): IStorage;
|
package/dist/web.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { I as IStorage, C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-
|
|
1
|
+
import { I as IStorage, C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-BN3nbzYM.js';
|
|
2
2
|
import 'viem';
|
|
3
3
|
import './types-C07FK-cL.js';
|
|
4
4
|
import 'zod';
|
|
5
|
-
import './
|
|
5
|
+
import './acp-Wi6isVQI.js';
|
|
6
6
|
import 'zustand/vanilla';
|
|
7
7
|
|
|
8
8
|
declare function createSsrStorage(): IStorage;
|
package/dist/web.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createCofheConfigBase, createCofheClientBase, fheTypeToString } from './chunk-
|
|
2
|
-
import './chunk-
|
|
3
|
-
import './chunk-
|
|
1
|
+
import { createCofheConfigBase, createCofheClientBase, fheTypeToString } from './chunk-43USWPEH.js';
|
|
2
|
+
import './chunk-N6IDQRRU.js';
|
|
3
|
+
import './chunk-Q7CBWGQX.js';
|
|
4
4
|
import { TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT } from './chunk-ESMZCFJY.js';
|
|
5
5
|
import { constructClient } from 'iframe-shared-storage';
|
|
6
6
|
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { STAGING_TESTS, stagingViemChain } from '../../core/test/stagingRedirect';
|
|
1
2
|
import { Encryptable, FheTypes, type CofheClient } from '@/core';
|
|
2
|
-
import { arbSepolia as cofheArbSepolia, getChainById } from '@/chains';
|
|
3
|
+
import { arbSepolia as cofheArbSepolia, getChainById, stagingCofhe } from '@/chains';
|
|
3
4
|
import {
|
|
4
5
|
TEST_PRIVATE_KEY,
|
|
5
6
|
PRIMARY_TEST_CHAIN,
|
|
6
7
|
primaryTestChainRegistry,
|
|
8
|
+
stagingTestChainRegistry,
|
|
7
9
|
isPrimaryTestChainReady,
|
|
8
10
|
} from '@cofhe/test-setup';
|
|
9
11
|
|
|
@@ -27,6 +29,9 @@ const VIEM_CHAINS: Record<number, Chain> = {
|
|
|
27
29
|
11155111: sepolia,
|
|
28
30
|
};
|
|
29
31
|
|
|
32
|
+
const testViemChain = STAGING_TESTS ? stagingViemChain : arbitrumSepolia;
|
|
33
|
+
const testCofheChain = STAGING_TESTS ? stagingCofhe : cofheArbSepolia;
|
|
34
|
+
|
|
30
35
|
describe('@cofhe/node - Inherited Client Tests', () => {
|
|
31
36
|
let cofheClient: CofheClient;
|
|
32
37
|
let publicClient: PublicClient;
|
|
@@ -35,18 +40,18 @@ describe('@cofhe/node - Inherited Client Tests', () => {
|
|
|
35
40
|
|
|
36
41
|
beforeAll(() => {
|
|
37
42
|
publicClient = createPublicClient({
|
|
38
|
-
chain:
|
|
43
|
+
chain: testViemChain,
|
|
39
44
|
transport: http(),
|
|
40
45
|
});
|
|
41
46
|
|
|
42
47
|
bobWalletClient = createWalletClient({
|
|
43
|
-
chain:
|
|
48
|
+
chain: testViemChain,
|
|
44
49
|
transport: http(),
|
|
45
50
|
account: bobAccount,
|
|
46
51
|
});
|
|
47
52
|
|
|
48
53
|
aliceWalletClient = createWalletClient({
|
|
49
|
-
chain:
|
|
54
|
+
chain: testViemChain,
|
|
50
55
|
transport: http(),
|
|
51
56
|
account: aliceAccount,
|
|
52
57
|
});
|
|
@@ -54,7 +59,7 @@ describe('@cofhe/node - Inherited Client Tests', () => {
|
|
|
54
59
|
|
|
55
60
|
beforeEach(() => {
|
|
56
61
|
const config = createCofheConfig({
|
|
57
|
-
supportedChains: [
|
|
62
|
+
supportedChains: [testCofheChain],
|
|
58
63
|
});
|
|
59
64
|
cofheClient = createCofheClient(config);
|
|
60
65
|
});
|
|
@@ -71,7 +76,7 @@ describe('@cofhe/node - Inherited Client Tests', () => {
|
|
|
71
76
|
expect(typeof cofheClient.decryptForTx).toBe('function');
|
|
72
77
|
expect(typeof cofheClient.getSnapshot).toBe('function');
|
|
73
78
|
expect(typeof cofheClient.subscribe).toBe('function');
|
|
74
|
-
expect(cofheClient.
|
|
79
|
+
expect(cofheClient.acp).toBeDefined();
|
|
75
80
|
});
|
|
76
81
|
});
|
|
77
82
|
|
|
@@ -83,7 +88,7 @@ describe('@cofhe/node - Inherited Client Tests', () => {
|
|
|
83
88
|
|
|
84
89
|
const snapshot = cofheClient.getSnapshot();
|
|
85
90
|
expect(snapshot.connected).toBe(true);
|
|
86
|
-
expect(snapshot.chainId).toBe(
|
|
91
|
+
expect(snapshot.chainId).toBe(testCofheChain.id);
|
|
87
92
|
expect(snapshot.account).toBe(bobAccount.address);
|
|
88
93
|
}, 30000);
|
|
89
94
|
});
|
|
@@ -92,81 +97,85 @@ describe('@cofhe/node - Inherited Client Tests', () => {
|
|
|
92
97
|
it('should encrypt a uint128 value', async () => {
|
|
93
98
|
await cofheClient.connect(publicClient, bobWalletClient);
|
|
94
99
|
|
|
95
|
-
const encrypted = await cofheClient
|
|
100
|
+
const encrypted = await cofheClient
|
|
101
|
+
.encryptInputs([Encryptable.uint128(100n)])
|
|
102
|
+
.setConsumingContract(bobAccount.address)
|
|
103
|
+
.execute();
|
|
96
104
|
|
|
105
|
+
// [hash, signature] - one hash per input, followed by the shared batch signature.
|
|
97
106
|
expect(encrypted).toBeDefined();
|
|
98
|
-
expect(encrypted.length).toBe(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
expect(typeof
|
|
102
|
-
expect(
|
|
103
|
-
expect(typeof
|
|
104
|
-
expect(
|
|
105
|
-
},
|
|
107
|
+
expect(encrypted.length).toBe(2);
|
|
108
|
+
|
|
109
|
+
const [hash, signature] = encrypted;
|
|
110
|
+
expect(typeof hash).toBe('string');
|
|
111
|
+
expect(hash).toMatch(/^0x[0-9a-fA-F]+$/);
|
|
112
|
+
expect(typeof signature).toBe('string');
|
|
113
|
+
expect(signature).toMatch(/^0x[0-9a-fA-F]+$/);
|
|
114
|
+
}, 120000);
|
|
106
115
|
});
|
|
107
116
|
|
|
108
|
-
describe('Self
|
|
109
|
-
it('should create a self
|
|
117
|
+
describe('Self ACP', () => {
|
|
118
|
+
it('should create a self acp', async () => {
|
|
110
119
|
await cofheClient.connect(publicClient, bobWalletClient);
|
|
111
120
|
|
|
112
|
-
const
|
|
121
|
+
const acp = await cofheClient.acp.createSelf({
|
|
113
122
|
issuer: bobAccount.address,
|
|
114
|
-
name: 'Test Self
|
|
123
|
+
name: 'Test Self ACP',
|
|
115
124
|
});
|
|
116
125
|
|
|
117
|
-
expect(
|
|
118
|
-
expect(
|
|
119
|
-
expect(
|
|
120
|
-
expect(
|
|
121
|
-
expect(
|
|
122
|
-
expect(
|
|
123
|
-
expect(
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
expect(
|
|
127
|
-
expect(
|
|
126
|
+
expect(acp).toBeDefined();
|
|
127
|
+
expect(acp.type).toBe('self');
|
|
128
|
+
expect(acp.name).toBe('Test Self ACP');
|
|
129
|
+
expect(acp.issuer).toBe(bobAccount.address);
|
|
130
|
+
expect(acp.issuerSignature).not.toBe('0x');
|
|
131
|
+
expect(acp.sealingPrivateKey).toBeDefined();
|
|
132
|
+
expect(acp.sealingKey).toBeDefined();
|
|
133
|
+
|
|
134
|
+
const activeACP = cofheClient.acp.getActiveACP();
|
|
135
|
+
expect(activeACP).toBeDefined();
|
|
136
|
+
expect(activeACP!.hash).toBe(acp.hash);
|
|
128
137
|
}, 30000);
|
|
129
138
|
});
|
|
130
139
|
|
|
131
|
-
describe('Sharing
|
|
132
|
-
it('should create a sharing
|
|
140
|
+
describe('Sharing ACP', () => {
|
|
141
|
+
it('should create a sharing acp, export it, and import it as another user', async () => {
|
|
133
142
|
await cofheClient.connect(publicClient, bobWalletClient);
|
|
134
143
|
|
|
135
|
-
const
|
|
144
|
+
const sharingACP = await cofheClient.acp.createSharing({
|
|
136
145
|
issuer: bobAccount.address,
|
|
137
146
|
recipient: aliceAccount.address,
|
|
138
|
-
name: 'Test Sharing
|
|
147
|
+
name: 'Test Sharing ACP',
|
|
139
148
|
});
|
|
140
149
|
|
|
141
|
-
expect(
|
|
142
|
-
expect(
|
|
143
|
-
expect(
|
|
144
|
-
expect(
|
|
145
|
-
expect(
|
|
150
|
+
expect(sharingACP).toBeDefined();
|
|
151
|
+
expect(sharingACP.type).toBe('sharing');
|
|
152
|
+
expect(sharingACP.issuer).toBe(bobAccount.address);
|
|
153
|
+
expect(sharingACP.recipient).toBe(aliceAccount.address);
|
|
154
|
+
expect(sharingACP.issuerSignature).not.toBe('0x');
|
|
146
155
|
|
|
147
|
-
const exported = cofheClient.
|
|
156
|
+
const exported = cofheClient.acp.export(sharingACP);
|
|
148
157
|
expect(exported).toBeDefined();
|
|
149
158
|
const parsed = JSON.parse(exported);
|
|
150
159
|
expect(parsed.type).toBe('sharing');
|
|
151
160
|
expect(parsed.issuer).toBe(bobAccount.address);
|
|
152
161
|
expect(parsed.recipient).toBe(aliceAccount.address);
|
|
153
162
|
expect(parsed.issuerSignature).toBeDefined();
|
|
154
|
-
expect(parsed).not.toHaveProperty('
|
|
163
|
+
expect(parsed).not.toHaveProperty('sealingPrivateKey');
|
|
155
164
|
|
|
156
165
|
const aliceConfig = createCofheConfig({
|
|
157
|
-
supportedChains: [
|
|
166
|
+
supportedChains: [testCofheChain],
|
|
158
167
|
});
|
|
159
168
|
const aliceClient = createCofheClient(aliceConfig);
|
|
160
169
|
await aliceClient.connect(publicClient, aliceWalletClient);
|
|
161
170
|
|
|
162
|
-
const
|
|
171
|
+
const importedACP = await aliceClient.acp.importShared(exported);
|
|
163
172
|
|
|
164
|
-
expect(
|
|
165
|
-
expect(
|
|
166
|
-
expect(
|
|
167
|
-
expect(
|
|
168
|
-
expect(
|
|
169
|
-
expect(
|
|
173
|
+
expect(importedACP).toBeDefined();
|
|
174
|
+
expect(importedACP.type).toBe('recipient');
|
|
175
|
+
expect(importedACP.issuer).toBe(bobAccount.address);
|
|
176
|
+
expect(importedACP.recipient).toBe(aliceAccount.address);
|
|
177
|
+
expect(importedACP.recipientSignature).not.toBe('0x');
|
|
178
|
+
expect(importedACP.sealingPrivateKey).toBeDefined();
|
|
170
179
|
}, 30000);
|
|
171
180
|
});
|
|
172
181
|
|
|
@@ -181,15 +190,16 @@ describe('@cofhe/node - Inherited Client Tests', () => {
|
|
|
181
190
|
let publicValue: bigint;
|
|
182
191
|
|
|
183
192
|
beforeAll(() => {
|
|
184
|
-
|
|
185
|
-
|
|
193
|
+
const reg = STAGING_TESTS
|
|
194
|
+
? (stagingTestChainRegistry as typeof primaryTestChainRegistry)
|
|
195
|
+
: primaryTestChainRegistry;
|
|
196
|
+
if (!isPrimaryTestChainReady(reg)) {
|
|
197
|
+
throw new Error('Test chain registry not initialized. Run `pnpm test:setup` first.');
|
|
186
198
|
}
|
|
187
|
-
|
|
188
|
-
const reg = primaryTestChainRegistry;
|
|
189
|
-
const viemChain = VIEM_CHAINS[reg.chainId];
|
|
199
|
+
const viemChain = STAGING_TESTS ? stagingViemChain : VIEM_CHAINS[reg.chainId];
|
|
190
200
|
if (!viemChain) throw new Error(`No viem chain mapping for chain ${reg.chainId}`);
|
|
191
201
|
|
|
192
|
-
const cofheChain = getChainById(reg.chainId);
|
|
202
|
+
const cofheChain = STAGING_TESTS ? stagingCofhe : getChainById(reg.chainId);
|
|
193
203
|
if (!cofheChain) throw new Error(`No cofhe chain config for chain ${reg.chainId}`);
|
|
194
204
|
|
|
195
205
|
privateCtHash = reg.privateValue.ctHash as `0x${string}`;
|
|
@@ -204,37 +214,37 @@ describe('@cofhe/node - Inherited Client Tests', () => {
|
|
|
204
214
|
decryptClient = createCofheClient(config);
|
|
205
215
|
});
|
|
206
216
|
|
|
207
|
-
it('decryptForView — private value with
|
|
217
|
+
it('decryptForView — private value with acp', async () => {
|
|
208
218
|
await decryptClient.connect(decryptPublicClient, decryptWalletClient);
|
|
209
219
|
|
|
210
|
-
await decryptClient.
|
|
220
|
+
await decryptClient.acp.createSelf({
|
|
211
221
|
issuer: bobAccount.address,
|
|
212
|
-
name: 'Decrypt View
|
|
222
|
+
name: 'Decrypt View ACP',
|
|
213
223
|
});
|
|
214
224
|
|
|
215
225
|
const result = await decryptClient.decryptForView(privateCtHash, FheTypes.Uint32).execute();
|
|
216
226
|
expect(result).toBe(privateValue);
|
|
217
227
|
}, 180000);
|
|
218
228
|
|
|
219
|
-
it('decryptForTx — public value without
|
|
229
|
+
it('decryptForTx — public value without acp', async () => {
|
|
220
230
|
await decryptClient.connect(decryptPublicClient, decryptWalletClient);
|
|
221
231
|
|
|
222
|
-
const result = await decryptClient.decryptForTx(publicCtHash).
|
|
232
|
+
const result = await decryptClient.decryptForTx(publicCtHash).withoutACP().execute();
|
|
223
233
|
|
|
224
234
|
expect(BigInt(result.ctHash)).toBe(BigInt(publicCtHash));
|
|
225
235
|
expect(result.decryptedValue).toBe(publicValue);
|
|
226
236
|
expect(result.signature).toMatch(/^0x[0-9a-fA-F]+$/);
|
|
227
237
|
}, 180000);
|
|
228
238
|
|
|
229
|
-
it('decryptForTx — private value with
|
|
239
|
+
it('decryptForTx — private value with acp', async () => {
|
|
230
240
|
await decryptClient.connect(decryptPublicClient, decryptWalletClient);
|
|
231
241
|
|
|
232
|
-
const
|
|
242
|
+
const acp = await decryptClient.acp.createSelf({
|
|
233
243
|
issuer: bobAccount.address,
|
|
234
|
-
name: 'Decrypt Tx
|
|
244
|
+
name: 'Decrypt Tx ACP',
|
|
235
245
|
});
|
|
236
246
|
|
|
237
|
-
const result = await decryptClient.decryptForTx(privateCtHash).
|
|
247
|
+
const result = await decryptClient.decryptForTx(privateCtHash).withACP(acp).execute();
|
|
238
248
|
|
|
239
249
|
expect(BigInt(result.ctHash)).toBe(BigInt(privateCtHash));
|
|
240
250
|
expect(result.decryptedValue).toBe(privateValue);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { STAGING_TESTS, stagingViemChain } from '../../core/test/stagingRedirect';
|
|
1
2
|
import { Encryptable, type CofheClient } from '@/core';
|
|
2
|
-
import { arbSepolia as cofheArbSepolia } from '@/chains';
|
|
3
|
+
import { arbSepolia as cofheArbSepolia, stagingCofhe } from '@/chains';
|
|
3
4
|
|
|
4
5
|
import { describe, it, expect, beforeAll, beforeEach } from 'vitest';
|
|
5
6
|
import type { PublicClient, WalletClient } from 'viem';
|
|
@@ -10,28 +11,33 @@ import { createCofheClient, createCofheConfig } from '../index.js';
|
|
|
10
11
|
|
|
11
12
|
const TEST_PRIVATE_KEY = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80';
|
|
12
13
|
|
|
14
|
+
const testViemChain = STAGING_TESTS ? stagingViemChain : viemArbitrumSepolia;
|
|
15
|
+
const testCofheChain = STAGING_TESTS ? stagingCofhe : cofheArbSepolia;
|
|
16
|
+
|
|
13
17
|
describe('@cofhe/node - TFHE Initialization Tests', () => {
|
|
14
18
|
let cofheClient: CofheClient;
|
|
15
19
|
let publicClient: PublicClient;
|
|
16
20
|
let walletClient: WalletClient;
|
|
21
|
+
let consumingContract: `0x${string}`;
|
|
17
22
|
|
|
18
23
|
beforeAll(() => {
|
|
19
24
|
publicClient = createPublicClient({
|
|
20
|
-
chain:
|
|
25
|
+
chain: testViemChain,
|
|
21
26
|
transport: http(),
|
|
22
27
|
});
|
|
23
28
|
|
|
24
29
|
const account = privateKeyToAccount(TEST_PRIVATE_KEY);
|
|
25
30
|
walletClient = createWalletClient({
|
|
26
|
-
chain:
|
|
31
|
+
chain: testViemChain,
|
|
27
32
|
transport: http(),
|
|
28
33
|
account,
|
|
29
34
|
});
|
|
35
|
+
consumingContract = account.address;
|
|
30
36
|
});
|
|
31
37
|
|
|
32
38
|
beforeEach(() => {
|
|
33
39
|
const config = createCofheConfig({
|
|
34
|
-
supportedChains: [
|
|
40
|
+
supportedChains: [testCofheChain],
|
|
35
41
|
});
|
|
36
42
|
cofheClient = createCofheClient(config);
|
|
37
43
|
});
|
|
@@ -40,17 +46,26 @@ describe('@cofhe/node - TFHE Initialization Tests', () => {
|
|
|
40
46
|
it('should initialize node-tfhe on first encryption', async () => {
|
|
41
47
|
await cofheClient.connect(publicClient, walletClient);
|
|
42
48
|
|
|
43
|
-
const result = await cofheClient
|
|
49
|
+
const result = await cofheClient
|
|
50
|
+
.encryptInputs([Encryptable.uint128(100n)])
|
|
51
|
+
.setConsumingContract(consumingContract)
|
|
52
|
+
.execute();
|
|
44
53
|
|
|
45
54
|
expect(result).toBeDefined();
|
|
46
|
-
},
|
|
55
|
+
}, 120000);
|
|
47
56
|
|
|
48
57
|
it('should handle multiple encryptions without re-initializing', async () => {
|
|
49
58
|
await cofheClient.connect(publicClient, walletClient);
|
|
50
59
|
|
|
51
|
-
await cofheClient
|
|
60
|
+
await cofheClient
|
|
61
|
+
.encryptInputs([Encryptable.uint128(100n)])
|
|
62
|
+
.setConsumingContract(consumingContract)
|
|
63
|
+
.execute();
|
|
52
64
|
|
|
53
|
-
await cofheClient
|
|
65
|
+
await cofheClient
|
|
66
|
+
.encryptInputs([Encryptable.uint64(50n)])
|
|
67
|
+
.setConsumingContract(consumingContract)
|
|
68
|
+
.execute();
|
|
54
69
|
}, 120000);
|
|
55
70
|
});
|
|
56
71
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cofhe/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "SDK for Fhenix COFHE coprocessor interaction",
|
|
6
6
|
"main": "./dist/core.cjs",
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"require": "./dist/chains.cjs",
|
|
24
24
|
"types": "./dist/chains.d.ts"
|
|
25
25
|
},
|
|
26
|
-
"./
|
|
27
|
-
"import": "./dist/
|
|
28
|
-
"require": "./dist/
|
|
29
|
-
"types": "./dist/
|
|
26
|
+
"./acps": {
|
|
27
|
+
"import": "./dist/acps.js",
|
|
28
|
+
"require": "./dist/acps.cjs",
|
|
29
|
+
"types": "./dist/acps.d.ts"
|
|
30
30
|
},
|
|
31
31
|
"./node": {
|
|
32
32
|
"import": "./dist/node.js",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"core/**",
|
|
52
52
|
"adapters/**",
|
|
53
53
|
"chains/**",
|
|
54
|
-
"
|
|
54
|
+
"acps/**",
|
|
55
55
|
"node/**",
|
|
56
56
|
"web/**",
|
|
57
57
|
"CHANGELOG.md"
|
|
@@ -130,7 +130,11 @@ describe('@cofhe/web - Client', () => {
|
|
|
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.
|
|
133
|
+
expect(typeof builder.setConsumingContract).toBe('function');
|
|
134
|
+
// execute() only exists once a consuming contract has been committed to.
|
|
135
|
+
expect(typeof builder.setConsumingContract('0xbeefbeefbeefbeefbeefbeefbeefbeefbeefbeef').execute).toBe(
|
|
136
|
+
'function'
|
|
137
|
+
);
|
|
134
138
|
}, 30000);
|
|
135
139
|
|
|
136
140
|
it('should create decrypt builder after connection', async () => {
|