@cofhe/sdk 0.4.0 → 0.5.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 +38 -0
- package/adapters/{ethers5.test.ts → test/ethers5.test.ts} +2 -2
- package/adapters/{ethers6.test.ts → test/ethers6.test.ts} +2 -2
- package/adapters/{hardhat.hh2.test.ts → test/hardhat.hh2.test.ts} +2 -2
- package/adapters/{index.test.ts → test/index.test.ts} +1 -1
- package/adapters/{wagmi.test.ts → test/wagmi.test.ts} +1 -1
- package/chains/{chains.test.ts → test/chains.test.ts} +1 -1
- package/core/client.ts +11 -1
- package/core/clientTypes.ts +3 -1
- package/core/consts.ts +9 -0
- package/core/decrypt/cofheMocksDecryptForTx.ts +14 -3
- package/core/decrypt/decryptForTxBuilder.ts +16 -2
- package/core/decrypt/decryptForViewBuilder.ts +14 -7
- package/core/decrypt/polling.ts +14 -0
- package/core/decrypt/tnDecryptV2.ts +250 -110
- package/core/decrypt/tnSealOutputV2.ts +245 -104
- package/core/decrypt/verifyDecryptResult.ts +65 -0
- package/core/encrypt/cofheMocksZkVerifySign.ts +6 -6
- package/core/encrypt/zkPackProveVerify.ts +10 -19
- package/core/fetchKeys.ts +0 -2
- package/core/index.ts +9 -1
- package/core/keyStore.ts +5 -2
- package/core/permits.ts +5 -0
- package/core/{client.test.ts → test/client.test.ts} +7 -7
- package/core/{config.test.ts → test/config.test.ts} +1 -1
- package/core/test/decrypt.test.ts +252 -0
- package/core/test/decryptBuilders.test.ts +390 -0
- package/core/{encrypt → test}/encryptInputsBuilder.test.ts +61 -6
- package/core/{fetchKeys.test.ts → test/fetchKeys.test.ts} +3 -3
- package/core/{keyStore.test.ts → test/keyStore.test.ts} +5 -3
- package/core/{permits.test.ts → test/permits.test.ts} +42 -1
- package/core/test/pollCallbacks.test.ts +563 -0
- package/core/types.ts +13 -0
- package/dist/chains.d.cts +2 -2
- package/dist/chains.d.ts +2 -2
- package/dist/chunk-4FP4V35O.js +13 -0
- package/dist/{chunk-NWDKXBIP.js → chunk-MRCKUMOS.js} +62 -22
- package/dist/{chunk-MXND5SVN.js → chunk-S7OKGLFD.js} +485 -207
- package/dist/{clientTypes-kkrRdawm.d.ts → clientTypes-BSbwairE.d.cts} +23 -6
- package/dist/{clientTypes-ACVWbrXL.d.cts → clientTypes-DDmcgZ0a.d.ts} +23 -6
- package/dist/core.cjs +561 -244
- package/dist/core.d.cts +24 -6
- package/dist/core.d.ts +24 -6
- package/dist/core.js +3 -2
- package/dist/node.cjs +566 -246
- package/dist/node.d.cts +3 -3
- package/dist/node.d.ts +3 -3
- package/dist/node.js +14 -7
- package/dist/{permit-MZ502UBl.d.cts → permit-DnVMDT5h.d.cts} +34 -4
- package/dist/{permit-MZ502UBl.d.ts → permit-DnVMDT5h.d.ts} +34 -4
- package/dist/permits.cjs +66 -29
- package/dist/permits.d.cts +18 -13
- package/dist/permits.d.ts +18 -13
- package/dist/permits.js +2 -1
- package/dist/web.cjs +604 -256
- package/dist/web.d.cts +8 -4
- package/dist/web.d.ts +8 -4
- package/dist/web.js +49 -14
- package/dist/zkProve.worker.cjs +72 -64
- package/dist/zkProve.worker.js +71 -64
- package/node/index.ts +13 -4
- package/node/test/client.test.ts +25 -0
- package/node/test/config.test.ts +16 -0
- package/node/test/inherited.test.ts +244 -0
- package/node/test/tfheinit.test.ts +56 -0
- package/package.json +24 -22
- package/permits/permit.ts +31 -5
- package/permits/sealing.ts +1 -1
- package/permits/{localstorage.test.ts → test/localstorage.test.ts} +2 -2
- package/permits/{permit.test.ts → test/permit.test.ts} +35 -1
- package/permits/{sealing.test.ts → test/sealing.test.ts} +1 -1
- package/permits/{store.test.ts → test/store.test.ts} +2 -2
- package/permits/{validation.test.ts → test/validation.test.ts} +82 -6
- package/permits/types.ts +1 -1
- package/permits/validation.ts +42 -2
- package/web/const.ts +2 -0
- package/web/index.ts +40 -11
- package/web/storage.ts +18 -3
- package/web/{client.web.test.ts → test/client.web.test.ts} +13 -1
- package/web/test/config.web.test.ts +16 -0
- package/web/test/inherited.web.test.ts +245 -0
- package/web/test/tfheinit.web.test.ts +62 -0
- package/web/{worker.config.web.test.ts → test/worker.config.web.test.ts} +1 -1
- package/web/{worker.output.web.test.ts → test/worker.output.web.test.ts} +1 -1
- package/web/{workerManager.test.ts → test/workerManager.test.ts} +1 -1
- package/web/{workerManager.web.test.ts → test/workerManager.web.test.ts} +1 -1
- package/web/zkProve.worker.ts +94 -84
- package/node/client.test.ts +0 -147
- package/node/config.test.ts +0 -68
- package/node/encryptInputs.test.ts +0 -155
- package/web/config.web.test.ts +0 -69
- package/web/encryptInputs.web.test.ts +0 -172
- package/web/worker.builder.web.test.ts +0 -148
- /package/dist/{types-YiAC4gig.d.cts → types-C07FK-cL.d.cts} +0 -0
- /package/dist/{types-YiAC4gig.d.ts → types-C07FK-cL.d.ts} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
import { EncryptInputsBuilder } from '
|
|
2
|
+
import { EncryptInputsBuilder } from '../encrypt/encryptInputsBuilder.js';
|
|
3
3
|
import {
|
|
4
4
|
type EncryptableItem,
|
|
5
5
|
FheTypes,
|
|
@@ -12,9 +12,9 @@ import { CofheError, CofheErrorCode } from '../error.js';
|
|
|
12
12
|
import { fromHexString, toHexString } from '../utils.js';
|
|
13
13
|
import { type PublicClient, createPublicClient, http, type WalletClient, createWalletClient } from 'viem';
|
|
14
14
|
import { privateKeyToAccount } from 'viem/accounts';
|
|
15
|
-
import { arbitrumSepolia
|
|
15
|
+
import { arbitrumSepolia } from 'viem/chains';
|
|
16
16
|
import { type CofheConfig, createCofheConfigBase } from '../config.js';
|
|
17
|
-
import { type ZkBuilderAndCrsGenerator } from '
|
|
17
|
+
import { type ZkBuilderAndCrsGenerator } from '../encrypt/zkPackProveVerify.js';
|
|
18
18
|
import { type KeysStorage, createKeysStore } from '../keyStore.js';
|
|
19
19
|
import { type FheKeyDeserializer } from '../fetchKeys.js';
|
|
20
20
|
|
|
@@ -122,8 +122,7 @@ class MockZkListBuilder {
|
|
|
122
122
|
|
|
123
123
|
const MockCrs = {
|
|
124
124
|
free: () => {},
|
|
125
|
-
|
|
126
|
-
safe_serialize: () => new Uint8Array(),
|
|
125
|
+
safe_serialize: (_serializedSizeLimit: bigint) => new Uint8Array(),
|
|
127
126
|
};
|
|
128
127
|
|
|
129
128
|
// Setup fetch mock for http://localhost:3001/verify
|
|
@@ -223,7 +222,7 @@ class MockZkProvenList {
|
|
|
223
222
|
this.metadata = metadata;
|
|
224
223
|
}
|
|
225
224
|
|
|
226
|
-
|
|
225
|
+
safe_serialize(_serializedSizeLimit: bigint): Uint8Array {
|
|
227
226
|
// Serialize this.items into JSON, then encode as Uint8Array (utf-8)
|
|
228
227
|
const json = stringifyWithBigInt({ items: this.items, metadata: this.metadata });
|
|
229
228
|
return new TextEncoder().encode(json);
|
|
@@ -744,4 +743,60 @@ describe('EncryptInputsBuilder', () => {
|
|
|
744
743
|
expect(encryptedMetadata2.chainId).toBe(defaultChainId);
|
|
745
744
|
});
|
|
746
745
|
});
|
|
746
|
+
|
|
747
|
+
describe('setUseWorker and getUseWorker', () => {
|
|
748
|
+
it('should have setUseWorker method', () => {
|
|
749
|
+
expect(builder).toHaveProperty('setUseWorker');
|
|
750
|
+
expect(typeof builder.setUseWorker).toBe('function');
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
it('should have getUseWorker method', () => {
|
|
754
|
+
expect(builder).toHaveProperty('getUseWorker');
|
|
755
|
+
expect(typeof builder.getUseWorker).toBe('function');
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
it('should return builder for method chaining', () => {
|
|
759
|
+
const returnedBuilder = builder.setUseWorker(false);
|
|
760
|
+
expect(returnedBuilder).toBe(builder);
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
it('should allow chaining with other builder methods', () => {
|
|
764
|
+
const chainedBuilder = builder.setUseWorker(false).onStep(() => {});
|
|
765
|
+
expect(chainedBuilder).toBeDefined();
|
|
766
|
+
expect(chainedBuilder).toHaveProperty('execute');
|
|
767
|
+
});
|
|
768
|
+
|
|
769
|
+
it('should accept true and false parameters without throwing', () => {
|
|
770
|
+
expect(() => builder.setUseWorker(true)).not.toThrow();
|
|
771
|
+
expect(() => builder.setUseWorker(false)).not.toThrow();
|
|
772
|
+
});
|
|
773
|
+
|
|
774
|
+
it('should return current useWorker value via getUseWorker', () => {
|
|
775
|
+
builder.setUseWorker(true);
|
|
776
|
+
expect(builder.getUseWorker()).toBe(true);
|
|
777
|
+
|
|
778
|
+
builder.setUseWorker(false);
|
|
779
|
+
expect(builder.getUseWorker()).toBe(false);
|
|
780
|
+
});
|
|
781
|
+
|
|
782
|
+
it('should reflect changes across multiple setUseWorker calls', () => {
|
|
783
|
+
builder.setUseWorker(true);
|
|
784
|
+
expect(builder.getUseWorker()).toBe(true);
|
|
785
|
+
|
|
786
|
+
builder.setUseWorker(false);
|
|
787
|
+
expect(builder.getUseWorker()).toBe(false);
|
|
788
|
+
|
|
789
|
+
builder.setUseWorker(true);
|
|
790
|
+
expect(builder.getUseWorker()).toBe(true);
|
|
791
|
+
});
|
|
792
|
+
|
|
793
|
+
it('should default useWorker based on config.useWorkers', () => {
|
|
794
|
+
const configWithWorkers = createMockCofheConfig(defaultChainId, MockZkVerifierUrl);
|
|
795
|
+
const builderWithWorkers = new EncryptInputsBuilder({
|
|
796
|
+
...createDefaultParams(),
|
|
797
|
+
config: configWithWorkers,
|
|
798
|
+
});
|
|
799
|
+
expect(builderWithWorkers.getUseWorker()).toBe(configWithWorkers.useWorkers);
|
|
800
|
+
});
|
|
801
|
+
});
|
|
747
802
|
});
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
import { sepolia, arbSepolia } from '@/chains';
|
|
5
5
|
|
|
6
6
|
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
7
|
-
import { fetchKeys } from '
|
|
8
|
-
import { type CofheConfig, createCofheConfigBase } from '
|
|
9
|
-
import { createKeysStore, type KeysStorage } from '
|
|
7
|
+
import { fetchKeys } from '../fetchKeys.js';
|
|
8
|
+
import { type CofheConfig, createCofheConfigBase } from '../config.js';
|
|
9
|
+
import { createKeysStore, type KeysStorage } from '../keyStore.js';
|
|
10
10
|
|
|
11
11
|
describe('fetchKeys', () => {
|
|
12
12
|
let config: CofheConfig;
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
/* eslint-disable no-undef */
|
|
3
3
|
|
|
4
4
|
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
import { createKeysStore, type KeysStore, type KeysStorage } from '../keyStore';
|
|
7
|
+
import { TFHE_RS_KEY_VERSION } from 'core/consts';
|
|
6
8
|
|
|
7
9
|
// Mock the storage module
|
|
8
10
|
const mockStorage = {
|
|
@@ -11,7 +13,7 @@ const mockStorage = {
|
|
|
11
13
|
removeItem: vi.fn(),
|
|
12
14
|
};
|
|
13
15
|
|
|
14
|
-
vi.mock('
|
|
16
|
+
vi.mock('../../src/storage', () => ({
|
|
15
17
|
getStorage: () => mockStorage,
|
|
16
18
|
}));
|
|
17
19
|
|
|
@@ -124,7 +126,7 @@ describe('KeyStore', () => {
|
|
|
124
126
|
it('should clear keys storage', async () => {
|
|
125
127
|
await keysStorage.clearKeysStorage();
|
|
126
128
|
|
|
127
|
-
expect(mockStorage.removeItem).toHaveBeenCalledWith(
|
|
129
|
+
expect(mockStorage.removeItem).toHaveBeenCalledWith(`cofhesdk-keys-v${TFHE_RS_KEY_VERSION}`);
|
|
128
130
|
});
|
|
129
131
|
|
|
130
132
|
it('should rehydrate keys store', async () => {
|
|
@@ -7,7 +7,7 @@ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
|
7
7
|
import { createPublicClient, createWalletClient, http, type PublicClient, type WalletClient } from 'viem';
|
|
8
8
|
import { arbitrumSepolia } from 'viem/chains';
|
|
9
9
|
import { privateKeyToAccount } from 'viem/accounts';
|
|
10
|
-
import { permits } from '
|
|
10
|
+
import { permits } from '../permits.js';
|
|
11
11
|
|
|
12
12
|
// Type declarations for happy-dom environment
|
|
13
13
|
declare const localStorage: {
|
|
@@ -435,6 +435,47 @@ describe('Core Permits Tests', () => {
|
|
|
435
435
|
});
|
|
436
436
|
});
|
|
437
437
|
|
|
438
|
+
describe('Export', () => {
|
|
439
|
+
it('should export self permit data without sensitive fields', async () => {
|
|
440
|
+
const permit = await permits.createSelf(
|
|
441
|
+
{ name: 'Test Self Permit', issuer: bobAddress },
|
|
442
|
+
publicClient,
|
|
443
|
+
bobWalletClient
|
|
444
|
+
);
|
|
445
|
+
|
|
446
|
+
const exported = permits.export(permit);
|
|
447
|
+
const parsed = JSON.parse(exported);
|
|
448
|
+
|
|
449
|
+
expect(parsed.name).toBe('Test Self Permit');
|
|
450
|
+
expect(parsed.issuer).toBe(bobAddress);
|
|
451
|
+
expect(parsed).not.toHaveProperty('sealingPair');
|
|
452
|
+
expect(parsed).not.toHaveProperty('issuerSignature');
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
it('should export sharing permit data with recipient and issuerSignature', async () => {
|
|
456
|
+
const permit = await permits.createSharing(
|
|
457
|
+
{
|
|
458
|
+
name: 'Test Sharing Permit',
|
|
459
|
+
issuer: bobAddress,
|
|
460
|
+
recipient: aliceAddress,
|
|
461
|
+
},
|
|
462
|
+
publicClient,
|
|
463
|
+
bobWalletClient
|
|
464
|
+
);
|
|
465
|
+
|
|
466
|
+
const exported = permits.export(permit);
|
|
467
|
+
const parsed = JSON.parse(exported);
|
|
468
|
+
|
|
469
|
+
expect(parsed.name).toBe('Test Sharing Permit');
|
|
470
|
+
expect(parsed.type).toBe('sharing');
|
|
471
|
+
expect(parsed.issuer).toBe(bobAddress);
|
|
472
|
+
expect(parsed.recipient).toBe(aliceAddress);
|
|
473
|
+
expect(parsed.issuerSignature).toBeDefined();
|
|
474
|
+
expect(parsed.issuerSignature).not.toBe('0x');
|
|
475
|
+
expect(parsed).not.toHaveProperty('sealingPair');
|
|
476
|
+
});
|
|
477
|
+
});
|
|
478
|
+
|
|
438
479
|
describe('getOrCreate - Multiple Types Scenarios', () => {
|
|
439
480
|
it('should handle switching between self and sharing permits', async () => {
|
|
440
481
|
// Create self permit
|