@cofhe/sdk 0.2.0 → 0.2.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 +8 -0
- package/chains/defineChain.ts +2 -2
- package/chains/types.ts +3 -3
- package/core/client.test.ts +111 -0
- package/core/client.ts +22 -2
- package/core/clientTypes.ts +7 -1
- package/core/config.test.ts +8 -0
- package/core/config.ts +10 -4
- package/core/consts.ts +18 -0
- package/core/decrypt/cofheMocksSealOutput.ts +2 -4
- package/core/encrypt/cofheMocksZkVerifySign.ts +4 -11
- package/core/index.ts +9 -1
- package/core/permits.test.ts +5 -6
- package/core/permits.ts +5 -4
- package/dist/chains.cjs +4 -7
- package/dist/chains.d.cts +12 -12
- package/dist/chains.d.ts +12 -12
- package/dist/chains.js +1 -1
- package/dist/{chunk-WGCRJCBR.js → chunk-I5WFEYXX.js} +33 -19
- package/dist/{chunk-UGBVZNRT.js → chunk-R3B5TMVX.js} +308 -189
- package/dist/{chunk-WEAZ25JO.js → chunk-TBLR7NNE.js} +4 -7
- package/dist/{clientTypes-Es7fyi65.d.ts → clientTypes-RqkgkV2i.d.ts} +34 -93
- package/dist/{clientTypes-5_1nwtUe.d.cts → clientTypes-e4filDzK.d.cts} +34 -93
- package/dist/core.cjs +343 -208
- package/dist/core.d.cts +17 -6
- package/dist/core.d.ts +17 -6
- package/dist/core.js +3 -3
- package/dist/node.cjs +337 -208
- package/dist/node.d.cts +3 -3
- package/dist/node.d.ts +3 -3
- package/dist/node.js +3 -3
- package/dist/{permit-fUSe6KKq.d.cts → permit-MZ502UBl.d.cts} +30 -33
- package/dist/{permit-fUSe6KKq.d.ts → permit-MZ502UBl.d.ts} +30 -33
- package/dist/permits.cjs +305 -187
- package/dist/permits.d.cts +111 -812
- package/dist/permits.d.ts +111 -812
- package/dist/permits.js +1 -1
- package/dist/types-YiAC4gig.d.cts +33 -0
- package/dist/types-YiAC4gig.d.ts +33 -0
- package/dist/web.cjs +337 -208
- package/dist/web.d.cts +3 -3
- package/dist/web.d.ts +3 -3
- package/dist/web.js +3 -3
- package/package.json +3 -3
- package/permits/localstorage.test.ts +9 -13
- package/permits/onchain-utils.ts +221 -0
- package/permits/permit.test.ts +51 -5
- package/permits/permit.ts +28 -74
- package/permits/store.test.ts +10 -50
- package/permits/store.ts +4 -14
- package/permits/test-utils.ts +10 -2
- package/permits/types.ts +22 -9
- package/permits/utils.ts +0 -4
- package/permits/validation.test.ts +29 -32
- package/permits/validation.ts +112 -194
- package/dist/types-KImPrEIe.d.cts +0 -48
- package/dist/types-KImPrEIe.d.ts +0 -48
package/dist/chains.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { C as CofheChain } from './types-
|
|
2
|
-
export { E as Environment } from './types-
|
|
1
|
+
import { C as CofheChain } from './types-YiAC4gig.js';
|
|
2
|
+
export { E as Environment } from './types-YiAC4gig.js';
|
|
3
3
|
import 'zod';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Sepolia testnet chain configuration
|
|
7
7
|
*/
|
|
8
8
|
declare const sepolia: {
|
|
9
|
-
name: string;
|
|
10
9
|
id: number;
|
|
10
|
+
name: string;
|
|
11
11
|
network: string;
|
|
12
12
|
coFheUrl: string;
|
|
13
13
|
verifierUrl: string;
|
|
@@ -19,8 +19,8 @@ declare const sepolia: {
|
|
|
19
19
|
* Arbitrum Sepolia testnet chain configuration
|
|
20
20
|
*/
|
|
21
21
|
declare const arbSepolia: {
|
|
22
|
-
name: string;
|
|
23
22
|
id: number;
|
|
23
|
+
name: string;
|
|
24
24
|
network: string;
|
|
25
25
|
coFheUrl: string;
|
|
26
26
|
verifierUrl: string;
|
|
@@ -32,8 +32,8 @@ declare const arbSepolia: {
|
|
|
32
32
|
* Base Sepolia testnet chain configuration
|
|
33
33
|
*/
|
|
34
34
|
declare const baseSepolia: {
|
|
35
|
-
name: string;
|
|
36
35
|
id: number;
|
|
36
|
+
name: string;
|
|
37
37
|
network: string;
|
|
38
38
|
coFheUrl: string;
|
|
39
39
|
verifierUrl: string;
|
|
@@ -45,8 +45,8 @@ declare const baseSepolia: {
|
|
|
45
45
|
* Hardhat local development chain configuration
|
|
46
46
|
*/
|
|
47
47
|
declare const hardhat: {
|
|
48
|
-
name: string;
|
|
49
48
|
id: number;
|
|
49
|
+
name: string;
|
|
50
50
|
network: string;
|
|
51
51
|
coFheUrl: string;
|
|
52
52
|
verifierUrl: string;
|
|
@@ -58,8 +58,8 @@ declare const hardhat: {
|
|
|
58
58
|
* Localcofhe chain configuration
|
|
59
59
|
*/
|
|
60
60
|
declare const localcofhe: {
|
|
61
|
-
name: string;
|
|
62
61
|
id: number;
|
|
62
|
+
name: string;
|
|
63
63
|
network: string;
|
|
64
64
|
coFheUrl: string;
|
|
65
65
|
verifierUrl: string;
|
|
@@ -69,8 +69,8 @@ declare const localcofhe: {
|
|
|
69
69
|
|
|
70
70
|
declare const chains: {
|
|
71
71
|
readonly sepolia: {
|
|
72
|
-
name: string;
|
|
73
72
|
id: number;
|
|
73
|
+
name: string;
|
|
74
74
|
network: string;
|
|
75
75
|
coFheUrl: string;
|
|
76
76
|
verifierUrl: string;
|
|
@@ -78,8 +78,8 @@ declare const chains: {
|
|
|
78
78
|
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
79
79
|
};
|
|
80
80
|
readonly arbSepolia: {
|
|
81
|
-
name: string;
|
|
82
81
|
id: number;
|
|
82
|
+
name: string;
|
|
83
83
|
network: string;
|
|
84
84
|
coFheUrl: string;
|
|
85
85
|
verifierUrl: string;
|
|
@@ -87,8 +87,8 @@ declare const chains: {
|
|
|
87
87
|
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
88
88
|
};
|
|
89
89
|
readonly baseSepolia: {
|
|
90
|
-
name: string;
|
|
91
90
|
id: number;
|
|
91
|
+
name: string;
|
|
92
92
|
network: string;
|
|
93
93
|
coFheUrl: string;
|
|
94
94
|
verifierUrl: string;
|
|
@@ -96,8 +96,8 @@ declare const chains: {
|
|
|
96
96
|
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
97
97
|
};
|
|
98
98
|
readonly hardhat: {
|
|
99
|
-
name: string;
|
|
100
99
|
id: number;
|
|
100
|
+
name: string;
|
|
101
101
|
network: string;
|
|
102
102
|
coFheUrl: string;
|
|
103
103
|
verifierUrl: string;
|
|
@@ -105,8 +105,8 @@ declare const chains: {
|
|
|
105
105
|
environment: "MOCK" | "TESTNET" | "MAINNET";
|
|
106
106
|
};
|
|
107
107
|
readonly localcofhe: {
|
|
108
|
-
name: string;
|
|
109
108
|
id: number;
|
|
109
|
+
name: string;
|
|
110
110
|
network: string;
|
|
111
111
|
coFheUrl: string;
|
|
112
112
|
verifierUrl: string;
|
package/dist/chains.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { arbSepolia, baseSepolia, chains, getChainById, getChainByName, hardhat, localcofhe, sepolia } from './chunk-
|
|
1
|
+
export { arbSepolia, baseSepolia, chains, getChainById, getChainByName, hardhat, localcofhe, sepolia } from './chunk-TBLR7NNE.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { hardhat as hardhat$1 } from './chunk-
|
|
2
|
-
import { permitStore, PermitUtils } from './chunk-
|
|
1
|
+
import { hardhat as hardhat$1 } from './chunk-TBLR7NNE.js';
|
|
2
|
+
import { permitStore, PermitUtils, MOCKS_QUERY_DECRYPTER_ADDRESS, MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY, MOCKS_ZK_VERIFIER_ADDRESS } from './chunk-R3B5TMVX.js';
|
|
3
3
|
import { createStore } from 'zustand/vanilla';
|
|
4
4
|
import { createWalletClient, http, encodePacked, keccak256, toBytes, hashMessage, getAddress } from 'viem';
|
|
5
5
|
import { hardhat } from 'viem/chains';
|
|
@@ -638,9 +638,6 @@ var MockZkVerifierAbi = [
|
|
|
638
638
|
},
|
|
639
639
|
{ type: "error", name: "InvalidInputs", inputs: [] }
|
|
640
640
|
];
|
|
641
|
-
var MocksZkVerifierAddress = "0x0000000000000000000000000000000000000100";
|
|
642
|
-
var MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY = "0x6C8D7F768A6BB4AAFE85E8A2F5A9680355239C7E14646ED62B044E39DE154512";
|
|
643
|
-
var MOCKS_ZK_VERIFIER_SIGNER_ADDRESS = "0x6E12D8C87503D4287c294f2Fdef96ACd9DFf6bd2";
|
|
644
641
|
function createMockZkVerifierSigner() {
|
|
645
642
|
return createWalletClient({
|
|
646
643
|
chain: hardhat,
|
|
@@ -706,7 +703,7 @@ async function calcCtHashes(items, account, securityZone, publicClient) {
|
|
|
706
703
|
let ctHashes;
|
|
707
704
|
try {
|
|
708
705
|
ctHashes = await publicClient.readContract({
|
|
709
|
-
address:
|
|
706
|
+
address: MOCKS_ZK_VERIFIER_ADDRESS,
|
|
710
707
|
abi: MockZkVerifierAbi,
|
|
711
708
|
functionName: "zkVerifyCalcCtHashesPacked",
|
|
712
709
|
args: calcCtHashesArgs
|
|
@@ -717,7 +714,7 @@ async function calcCtHashes(items, account, securityZone, publicClient) {
|
|
|
717
714
|
message: `mockZkVerifySign calcCtHashes failed while calling zkVerifyCalcCtHashesPacked`,
|
|
718
715
|
cause: err instanceof Error ? err : void 0,
|
|
719
716
|
context: {
|
|
720
|
-
address:
|
|
717
|
+
address: MOCKS_ZK_VERIFIER_ADDRESS,
|
|
721
718
|
items,
|
|
722
719
|
account,
|
|
723
720
|
securityZone,
|
|
@@ -750,7 +747,7 @@ async function insertCtHashes(items, walletClient) {
|
|
|
750
747
|
try {
|
|
751
748
|
const account = walletClient.account;
|
|
752
749
|
await walletClient.writeContract({
|
|
753
|
-
address:
|
|
750
|
+
address: MOCKS_ZK_VERIFIER_ADDRESS,
|
|
754
751
|
abi: MockZkVerifierAbi,
|
|
755
752
|
functionName: "insertPackedCtHashes",
|
|
756
753
|
args: insertPackedCtHashesArgs,
|
|
@@ -840,9 +837,15 @@ var CofhesdkConfigSchema = z.object({
|
|
|
840
837
|
defaultPermitExpiration: z.number().optional().default(60 * 60 * 24 * 30),
|
|
841
838
|
/** Storage method for fhe keys (defaults to indexedDB on web, filesystem on node) */
|
|
842
839
|
fheKeyStorage: z.object({
|
|
843
|
-
getItem: z.
|
|
844
|
-
|
|
845
|
-
|
|
840
|
+
getItem: z.custom((val) => typeof val === "function", {
|
|
841
|
+
message: "getItem must be a function"
|
|
842
|
+
}),
|
|
843
|
+
setItem: z.custom((val) => typeof val === "function", {
|
|
844
|
+
message: "setItem must be a function"
|
|
845
|
+
}),
|
|
846
|
+
removeItem: z.custom((val) => typeof val === "function", {
|
|
847
|
+
message: "removeItem must be a function"
|
|
848
|
+
})
|
|
846
849
|
}).or(z.null()).default(null),
|
|
847
850
|
/** Whether to use Web Workers for ZK proof generation (web platform only) */
|
|
848
851
|
useWorkers: z.boolean().optional().default(true),
|
|
@@ -858,7 +861,7 @@ var CofhesdkConfigSchema = z.object({
|
|
|
858
861
|
function createCofhesdkConfigBase(config) {
|
|
859
862
|
const result = CofhesdkConfigSchema.safeParse(config);
|
|
860
863
|
if (!result.success) {
|
|
861
|
-
throw new Error(`Invalid cofhesdk configuration: ${result.error.
|
|
864
|
+
throw new Error(`Invalid cofhesdk configuration: ${z.prettifyError(result.error)}`, { cause: result.error });
|
|
862
865
|
}
|
|
863
866
|
return result.data;
|
|
864
867
|
}
|
|
@@ -1627,7 +1630,7 @@ var storeActivePermit = async (permit, publicClient, walletClient) => {
|
|
|
1627
1630
|
const chainId = await publicClient.getChainId();
|
|
1628
1631
|
const account = walletClient.account.address;
|
|
1629
1632
|
permitStore.setPermit(chainId, account, permit);
|
|
1630
|
-
permitStore.setActivePermitHash(chainId, account,
|
|
1633
|
+
permitStore.setActivePermitHash(chainId, account, permit.hash);
|
|
1631
1634
|
};
|
|
1632
1635
|
var createPermitWithSign = async (options, publicClient, walletClient, permitMethod) => {
|
|
1633
1636
|
const permit = await permitMethod(options, publicClient, walletClient);
|
|
@@ -1685,7 +1688,7 @@ var getOrCreateSharingPermit = async (publicClient, walletClient, options, chain
|
|
|
1685
1688
|
}
|
|
1686
1689
|
return createSharing(options, publicClient, walletClient);
|
|
1687
1690
|
};
|
|
1688
|
-
var removePermit = async (chainId, account, hash
|
|
1691
|
+
var removePermit = async (chainId, account, hash) => permitStore.removePermit(chainId, account, hash);
|
|
1689
1692
|
var removeActivePermit = async (chainId, account) => permitStore.removeActivePermitHash(chainId, account);
|
|
1690
1693
|
var permits = {
|
|
1691
1694
|
getSnapshot: permitStore.store.getState,
|
|
@@ -1857,7 +1860,6 @@ var MockQueryDecrypterAbi = [
|
|
|
1857
1860
|
];
|
|
1858
1861
|
|
|
1859
1862
|
// core/decrypt/cofheMocksSealOutput.ts
|
|
1860
|
-
var MockQueryDecrypterAddress = "0x0000000000000000000000000000000000000200";
|
|
1861
1863
|
async function cofheMocksSealOutput(ctHash, utype, permit, publicClient, mocksSealOutputDelay) {
|
|
1862
1864
|
if (mocksSealOutputDelay > 0)
|
|
1863
1865
|
await sleep(mocksSealOutputDelay);
|
|
@@ -1868,7 +1870,7 @@ async function cofheMocksSealOutput(ctHash, utype, permit, publicClient, mocksSe
|
|
|
1868
1870
|
validatorId: BigInt(permission.validatorId)
|
|
1869
1871
|
};
|
|
1870
1872
|
const [allowed, error, result] = await publicClient.readContract({
|
|
1871
|
-
address:
|
|
1873
|
+
address: MOCKS_QUERY_DECRYPTER_ADDRESS,
|
|
1872
1874
|
abi: MockQueryDecrypterAbi,
|
|
1873
1875
|
functionName: "querySealOutput",
|
|
1874
1876
|
args: [ctHash, BigInt(utype), permissionWithBigInts]
|
|
@@ -2328,6 +2330,7 @@ var InitialConnectStore = {
|
|
|
2328
2330
|
function createCofhesdkClientBase(opts) {
|
|
2329
2331
|
const keysStorage = createKeysStore(opts.config.fheKeyStorage);
|
|
2330
2332
|
const connectStore = createStore(() => InitialConnectStore);
|
|
2333
|
+
let connectAttemptId = 0;
|
|
2331
2334
|
const updateConnectState = (partial) => {
|
|
2332
2335
|
connectStore.setState((state) => ({ ...state, ...partial }));
|
|
2333
2336
|
};
|
|
@@ -2353,6 +2356,8 @@ function createCofhesdkClientBase(opts) {
|
|
|
2353
2356
|
const state = connectStore.getState();
|
|
2354
2357
|
if (state.connected && state.publicClient === publicClient && state.walletClient === walletClient)
|
|
2355
2358
|
return;
|
|
2359
|
+
connectAttemptId += 1;
|
|
2360
|
+
const localAttemptId = connectAttemptId;
|
|
2356
2361
|
updateConnectState({
|
|
2357
2362
|
...InitialConnectStore,
|
|
2358
2363
|
connecting: true
|
|
@@ -2360,6 +2365,8 @@ function createCofhesdkClientBase(opts) {
|
|
|
2360
2365
|
try {
|
|
2361
2366
|
const chainId = await getPublicClientChainID(publicClient);
|
|
2362
2367
|
const account = await getWalletClientAccount(walletClient);
|
|
2368
|
+
if (localAttemptId !== connectAttemptId)
|
|
2369
|
+
return;
|
|
2363
2370
|
updateConnectState({
|
|
2364
2371
|
connected: true,
|
|
2365
2372
|
connecting: false,
|
|
@@ -2370,6 +2377,8 @@ function createCofhesdkClientBase(opts) {
|
|
|
2370
2377
|
walletClient
|
|
2371
2378
|
});
|
|
2372
2379
|
} catch (e) {
|
|
2380
|
+
if (localAttemptId !== connectAttemptId)
|
|
2381
|
+
return;
|
|
2373
2382
|
updateConnectState({
|
|
2374
2383
|
...InitialConnectStore,
|
|
2375
2384
|
connectError: e
|
|
@@ -2377,6 +2386,10 @@ function createCofhesdkClientBase(opts) {
|
|
|
2377
2386
|
throw e;
|
|
2378
2387
|
}
|
|
2379
2388
|
}
|
|
2389
|
+
function disconnect() {
|
|
2390
|
+
connectAttemptId += 1;
|
|
2391
|
+
updateConnectState({ ...InitialConnectStore });
|
|
2392
|
+
}
|
|
2380
2393
|
function encryptInputs(inputs) {
|
|
2381
2394
|
const state = connectStore.getState();
|
|
2382
2395
|
return new EncryptInputsBuilder({
|
|
@@ -2481,9 +2494,9 @@ function createCofhesdkClientBase(opts) {
|
|
|
2481
2494
|
const { chainId: _chainId, account: _account } = _getChainIdAndAccount(chainId, account);
|
|
2482
2495
|
return permits.selectActivePermit(_chainId, _account, hash);
|
|
2483
2496
|
},
|
|
2484
|
-
removePermit: async (hash, chainId, account
|
|
2497
|
+
removePermit: async (hash, chainId, account) => {
|
|
2485
2498
|
const { chainId: _chainId, account: _account } = _getChainIdAndAccount(chainId, account);
|
|
2486
|
-
return permits.removePermit(_chainId, _account, hash
|
|
2499
|
+
return permits.removePermit(_chainId, _account, hash);
|
|
2487
2500
|
},
|
|
2488
2501
|
removeActivePermit: async (chainId, account) => {
|
|
2489
2502
|
const { chainId: _chainId, account: _account } = _getChainIdAndAccount(chainId, account);
|
|
@@ -2508,6 +2521,7 @@ function createCofhesdkClientBase(opts) {
|
|
|
2508
2521
|
// config & platform-specific (read-only)
|
|
2509
2522
|
config: opts.config,
|
|
2510
2523
|
connect,
|
|
2524
|
+
disconnect,
|
|
2511
2525
|
encryptInputs,
|
|
2512
2526
|
decryptHandle,
|
|
2513
2527
|
permits: clientPermits
|
|
@@ -2520,4 +2534,4 @@ function createCofhesdkClientBase(opts) {
|
|
|
2520
2534
|
};
|
|
2521
2535
|
}
|
|
2522
2536
|
|
|
2523
|
-
export { CofhesdkError, CofhesdkErrorCode, DecryptHandlesBuilder, EncryptInputsBuilder, EncryptStep, Encryptable, FheAllUTypes, FheTypes, FheUintUTypes, InitialConnectStore,
|
|
2537
|
+
export { CofhesdkError, CofhesdkErrorCode, DecryptHandlesBuilder, EncryptInputsBuilder, EncryptStep, Encryptable, FheAllUTypes, FheTypes, FheUintUTypes, InitialConnectStore, assertCorrectEncryptedItemInput, createCofhesdkClientBase, createCofhesdkConfigBase, createKeysStore, fetchKeys, fheTypeToString, getCofhesdkConfigItem, isCofhesdkError, isEncryptableItem, isLastEncryptionStep, zkProveWithWorker };
|