@cofhe/sdk 0.0.0-beta-20251027110729
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 +47 -0
- package/adapters/ethers5.test.ts +174 -0
- package/adapters/ethers5.ts +36 -0
- package/adapters/ethers6.test.ts +169 -0
- package/adapters/ethers6.ts +36 -0
- package/adapters/hardhat-node.ts +167 -0
- package/adapters/hardhat.hh2.test.ts +159 -0
- package/adapters/hardhat.ts +37 -0
- package/adapters/index.test.ts +25 -0
- package/adapters/index.ts +5 -0
- package/adapters/smartWallet.ts +91 -0
- package/adapters/test-utils.ts +53 -0
- package/adapters/types.ts +6 -0
- package/adapters/wagmi.test.ts +156 -0
- package/adapters/wagmi.ts +17 -0
- package/chains/chains/arbSepolia.ts +14 -0
- package/chains/chains/baseSepolia.ts +14 -0
- package/chains/chains/hardhat.ts +15 -0
- package/chains/chains/sepolia.ts +14 -0
- package/chains/chains.test.ts +49 -0
- package/chains/defineChain.ts +18 -0
- package/chains/index.ts +33 -0
- package/chains/types.ts +32 -0
- package/core/baseBuilder.ts +138 -0
- package/core/client.test.ts +298 -0
- package/core/client.ts +308 -0
- package/core/config.test.ts +224 -0
- package/core/config.ts +213 -0
- package/core/decrypt/MockQueryDecrypterAbi.ts +129 -0
- package/core/decrypt/cofheMocksSealOutput.ts +57 -0
- package/core/decrypt/decryptHandleBuilder.ts +281 -0
- package/core/decrypt/decryptUtils.ts +28 -0
- package/core/decrypt/tnSealOutput.ts +59 -0
- package/core/encrypt/MockZkVerifierAbi.ts +106 -0
- package/core/encrypt/cofheMocksZkVerifySign.ts +278 -0
- package/core/encrypt/encryptInputsBuilder.test.ts +735 -0
- package/core/encrypt/encryptInputsBuilder.ts +512 -0
- package/core/encrypt/encryptUtils.ts +64 -0
- package/core/encrypt/zkPackProveVerify.ts +273 -0
- package/core/error.ts +170 -0
- package/core/fetchKeys.test.ts +212 -0
- package/core/fetchKeys.ts +170 -0
- package/core/index.ts +77 -0
- package/core/keyStore.test.ts +226 -0
- package/core/keyStore.ts +127 -0
- package/core/permits.test.ts +242 -0
- package/core/permits.ts +136 -0
- package/core/result.test.ts +180 -0
- package/core/result.ts +67 -0
- package/core/test-utils.ts +45 -0
- package/core/types.ts +352 -0
- package/core/utils.ts +88 -0
- package/dist/adapters.cjs +88 -0
- package/dist/adapters.d.cts +14558 -0
- package/dist/adapters.d.ts +14558 -0
- package/dist/adapters.js +83 -0
- package/dist/chains.cjs +101 -0
- package/dist/chains.d.cts +99 -0
- package/dist/chains.d.ts +99 -0
- package/dist/chains.js +1 -0
- package/dist/chunk-GZCQQYVI.js +93 -0
- package/dist/chunk-KFGPTJ6X.js +2295 -0
- package/dist/chunk-LU7BMUUT.js +804 -0
- package/dist/core.cjs +3174 -0
- package/dist/core.d.cts +16 -0
- package/dist/core.d.ts +16 -0
- package/dist/core.js +3 -0
- package/dist/node.cjs +3090 -0
- package/dist/node.d.cts +22 -0
- package/dist/node.d.ts +22 -0
- package/dist/node.js +90 -0
- package/dist/permit-S9CnI6MF.d.cts +333 -0
- package/dist/permit-S9CnI6MF.d.ts +333 -0
- package/dist/permits.cjs +856 -0
- package/dist/permits.d.cts +1056 -0
- package/dist/permits.d.ts +1056 -0
- package/dist/permits.js +1 -0
- package/dist/types-KImPrEIe.d.cts +48 -0
- package/dist/types-KImPrEIe.d.ts +48 -0
- package/dist/types-PhwGgQvs.d.ts +953 -0
- package/dist/types-bB7wLj0q.d.cts +953 -0
- package/dist/web.cjs +3067 -0
- package/dist/web.d.cts +22 -0
- package/dist/web.d.ts +22 -0
- package/dist/web.js +64 -0
- package/node/client.test.ts +152 -0
- package/node/config.test.ts +68 -0
- package/node/encryptInputs.test.ts +175 -0
- package/node/index.ts +96 -0
- package/node/storage.ts +51 -0
- package/package.json +120 -0
- package/permits/index.ts +67 -0
- package/permits/localstorage.test.ts +118 -0
- package/permits/permit.test.ts +474 -0
- package/permits/permit.ts +396 -0
- package/permits/sealing.test.ts +84 -0
- package/permits/sealing.ts +131 -0
- package/permits/signature.ts +79 -0
- package/permits/store.test.ts +128 -0
- package/permits/store.ts +168 -0
- package/permits/test-utils.ts +20 -0
- package/permits/types.ts +174 -0
- package/permits/utils.ts +63 -0
- package/permits/validation.test.ts +288 -0
- package/permits/validation.ts +349 -0
- package/web/client.web.test.ts +152 -0
- package/web/config.web.test.ts +71 -0
- package/web/encryptInputs.web.test.ts +195 -0
- package/web/index.ts +97 -0
- package/web/storage.ts +20 -0
package/package.json
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cofhe/sdk",
|
|
3
|
+
"version": "0.0.0-beta-20251027110729",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "SDK for Fhenix COFHE coprocessor interaction",
|
|
6
|
+
"main": "./dist/core.cjs",
|
|
7
|
+
"module": "./dist/core.js",
|
|
8
|
+
"types": "./dist/core.d.ts",
|
|
9
|
+
"browser": "./dist/web.js",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/core.js",
|
|
13
|
+
"require": "./dist/core.cjs",
|
|
14
|
+
"types": "./dist/core.d.ts"
|
|
15
|
+
},
|
|
16
|
+
"./adapters": {
|
|
17
|
+
"import": "./dist/adapters.js",
|
|
18
|
+
"require": "./dist/adapters.cjs",
|
|
19
|
+
"types": "./dist/adapters.d.ts"
|
|
20
|
+
},
|
|
21
|
+
"./chains": {
|
|
22
|
+
"import": "./dist/chains.js",
|
|
23
|
+
"require": "./dist/chains.cjs",
|
|
24
|
+
"types": "./dist/chains.d.ts"
|
|
25
|
+
},
|
|
26
|
+
"./permits": {
|
|
27
|
+
"import": "./dist/permits.js",
|
|
28
|
+
"require": "./dist/permits.cjs",
|
|
29
|
+
"types": "./dist/permits.d.ts"
|
|
30
|
+
},
|
|
31
|
+
"./node": {
|
|
32
|
+
"import": "./dist/node.js",
|
|
33
|
+
"require": "./dist/node.cjs",
|
|
34
|
+
"types": "./dist/node.d.ts"
|
|
35
|
+
},
|
|
36
|
+
"./web": {
|
|
37
|
+
"import": "./dist/web.js",
|
|
38
|
+
"require": "./dist/web.cjs",
|
|
39
|
+
"types": "./dist/web.d.ts"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"sideEffects": false,
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "https://github.com/FhenixProtocol/cofhesdk.git",
|
|
47
|
+
"directory": "packages/sdk"
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"dist/**",
|
|
51
|
+
"core/**",
|
|
52
|
+
"adapters/**",
|
|
53
|
+
"chains/**",
|
|
54
|
+
"permits/**",
|
|
55
|
+
"node/**",
|
|
56
|
+
"web/**",
|
|
57
|
+
"CHANGELOG.md"
|
|
58
|
+
],
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"immer": "^10.1.1",
|
|
61
|
+
"zustand": "^5.0.1",
|
|
62
|
+
"zod": "^3.22.0",
|
|
63
|
+
"viem": "^2.0.0",
|
|
64
|
+
"node-tfhe": "0.11.1",
|
|
65
|
+
"idb-keyval": "^6.2.1",
|
|
66
|
+
"tfhe": "0.11.1",
|
|
67
|
+
"tweetnacl": "^1.0.3"
|
|
68
|
+
},
|
|
69
|
+
"peerDependencies": {
|
|
70
|
+
"viem": "^2.0.0",
|
|
71
|
+
"@wagmi/core": "^2.0.0",
|
|
72
|
+
"ethers": "^5.0.0 || ^6.0.0",
|
|
73
|
+
"hardhat": "^2.0.0",
|
|
74
|
+
"@nomicfoundation/hardhat-ethers": "^3.0.0"
|
|
75
|
+
},
|
|
76
|
+
"peerDependenciesMeta": {
|
|
77
|
+
"@wagmi/core": {
|
|
78
|
+
"optional": true
|
|
79
|
+
},
|
|
80
|
+
"ethers": {
|
|
81
|
+
"optional": true
|
|
82
|
+
},
|
|
83
|
+
"hardhat": {
|
|
84
|
+
"optional": true
|
|
85
|
+
},
|
|
86
|
+
"@nomicfoundation/hardhat-ethers": {
|
|
87
|
+
"optional": true
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"devDependencies": {
|
|
91
|
+
"@types/node": "^20.0.0",
|
|
92
|
+
"@vitest/browser": "^3.0.0",
|
|
93
|
+
"@vitest/coverage-v8": "^3.0.0",
|
|
94
|
+
"eslint": "^8.57.0",
|
|
95
|
+
"happy-dom": "^15.0.0",
|
|
96
|
+
"playwright": "^1.55.0",
|
|
97
|
+
"tsup": "^8.0.2",
|
|
98
|
+
"typescript": "5.5.4",
|
|
99
|
+
"vitest": "^3.0.0",
|
|
100
|
+
"ethers5": "npm:ethers@^5.7.2",
|
|
101
|
+
"ethers6": "npm:ethers@^6.13.0",
|
|
102
|
+
"hardhat": "^2.19.0",
|
|
103
|
+
"@nomicfoundation/hardhat-ethers": "^3.0.0",
|
|
104
|
+
"@cofhe/eslint-config": "0.1.0",
|
|
105
|
+
"@cofhe/tsconfig": "0.1.0"
|
|
106
|
+
},
|
|
107
|
+
"publishConfig": {
|
|
108
|
+
"access": "public"
|
|
109
|
+
},
|
|
110
|
+
"scripts": {
|
|
111
|
+
"build": "tsup",
|
|
112
|
+
"dev": "tsup --watch",
|
|
113
|
+
"lint": "eslint \"**/*.ts*\"",
|
|
114
|
+
"type-check": "tsc --noEmit",
|
|
115
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
116
|
+
"test": "vitest run",
|
|
117
|
+
"test:watch": "vitest",
|
|
118
|
+
"test:coverage": "vitest run --coverage"
|
|
119
|
+
}
|
|
120
|
+
}
|
package/permits/index.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Core types
|
|
2
|
+
export type {
|
|
3
|
+
Permit,
|
|
4
|
+
CreateSelfPermitOptions as SelfPermitOptions,
|
|
5
|
+
CreateSharingPermitOptions as SharingPermitOptions,
|
|
6
|
+
ImportSharedPermitOptions as ImportPermitOptions,
|
|
7
|
+
SerializedPermit,
|
|
8
|
+
PermitMetadata,
|
|
9
|
+
Permission,
|
|
10
|
+
EIP712Domain,
|
|
11
|
+
EIP712Types,
|
|
12
|
+
EIP712Message,
|
|
13
|
+
ValidationResult,
|
|
14
|
+
PermitSignaturePrimaryType,
|
|
15
|
+
} from './types.js';
|
|
16
|
+
|
|
17
|
+
// Main utilities
|
|
18
|
+
export { PermitUtils } from './permit.js';
|
|
19
|
+
|
|
20
|
+
// Validation utilities
|
|
21
|
+
export {
|
|
22
|
+
// Self permit validators
|
|
23
|
+
SelfPermitOptionsValidator,
|
|
24
|
+
SelfPermitValidator,
|
|
25
|
+
validateSelfPermitOptions,
|
|
26
|
+
validateSelfPermit,
|
|
27
|
+
// Sharing permit validators
|
|
28
|
+
SharingPermitOptionsValidator,
|
|
29
|
+
SharingPermitValidator,
|
|
30
|
+
validateSharingPermitOptions,
|
|
31
|
+
validateSharingPermit,
|
|
32
|
+
// Import permit validators
|
|
33
|
+
ImportPermitOptionsValidator,
|
|
34
|
+
ImportPermitValidator,
|
|
35
|
+
validateImportPermitOptions,
|
|
36
|
+
validateImportPermit,
|
|
37
|
+
// Common utilities
|
|
38
|
+
ValidationUtils,
|
|
39
|
+
} from './validation.js';
|
|
40
|
+
|
|
41
|
+
// Signature utilities
|
|
42
|
+
export { SignatureUtils, getSignatureTypesAndMessage, SignatureTypes } from './signature.js';
|
|
43
|
+
|
|
44
|
+
// Storage utilities
|
|
45
|
+
export {
|
|
46
|
+
permitStore,
|
|
47
|
+
getPermit,
|
|
48
|
+
getActivePermit,
|
|
49
|
+
getPermits,
|
|
50
|
+
setPermit,
|
|
51
|
+
removePermit,
|
|
52
|
+
getActivePermitHash,
|
|
53
|
+
setActivePermitHash,
|
|
54
|
+
removeActivePermitHash,
|
|
55
|
+
clearStaleStore,
|
|
56
|
+
} from './store.js';
|
|
57
|
+
|
|
58
|
+
// Sealing utilities
|
|
59
|
+
export { SealingKey, GenerateSealingKey } from './sealing.js';
|
|
60
|
+
export type { EthEncryptedData } from './sealing.js';
|
|
61
|
+
|
|
62
|
+
// Re-export everything for convenience
|
|
63
|
+
export * from './types.js';
|
|
64
|
+
export * from './permit.js';
|
|
65
|
+
export * from './validation.js';
|
|
66
|
+
export * from './signature.js';
|
|
67
|
+
export * from './store.js';
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment happy-dom
|
|
3
|
+
*/
|
|
4
|
+
/* eslint-disable no-unused-vars */
|
|
5
|
+
|
|
6
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
7
|
+
import {
|
|
8
|
+
getPermit,
|
|
9
|
+
setPermit,
|
|
10
|
+
removePermit,
|
|
11
|
+
getActivePermitHash,
|
|
12
|
+
setActivePermitHash,
|
|
13
|
+
PermitUtils,
|
|
14
|
+
permitStore,
|
|
15
|
+
} from './index.js';
|
|
16
|
+
import { createMockPermit } from './test-utils.js';
|
|
17
|
+
|
|
18
|
+
// Type declarations for happy-dom environment
|
|
19
|
+
declare const localStorage: {
|
|
20
|
+
clear: () => void;
|
|
21
|
+
getItem: (name: string) => string | null;
|
|
22
|
+
setItem: (name: string, value: string) => void;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
describe('Permits localStorage Tests', () => {
|
|
26
|
+
const chainId = 1;
|
|
27
|
+
const account = '0x1234567890123456789012345678901234567890';
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
// Clear localStorage and reset store state
|
|
31
|
+
localStorage.clear();
|
|
32
|
+
permitStore.resetStore();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
// Clean up after each test
|
|
37
|
+
localStorage.clear();
|
|
38
|
+
permitStore.resetStore();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should persist permits to localStorage', async () => {
|
|
42
|
+
const permit = await createMockPermit();
|
|
43
|
+
const hash = PermitUtils.getHash(permit);
|
|
44
|
+
|
|
45
|
+
setPermit(chainId, account, permit);
|
|
46
|
+
|
|
47
|
+
// Verify data is stored in localStorage
|
|
48
|
+
const storedData = localStorage.getItem('cofhesdk-permits');
|
|
49
|
+
expect(storedData).toBeDefined();
|
|
50
|
+
|
|
51
|
+
const parsedData = JSON.parse(storedData!);
|
|
52
|
+
expect(parsedData.state.permits[chainId][account][hash]).toBeDefined();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should persist active permit hash to localStorage', async () => {
|
|
56
|
+
const permit = await createMockPermit();
|
|
57
|
+
const hash = PermitUtils.getHash(permit);
|
|
58
|
+
|
|
59
|
+
setPermit(chainId, account, permit);
|
|
60
|
+
setActivePermitHash(chainId, account, hash);
|
|
61
|
+
|
|
62
|
+
// Verify active permit hash is stored
|
|
63
|
+
const storedData = localStorage.getItem('cofhesdk-permits');
|
|
64
|
+
expect(storedData).toBeDefined();
|
|
65
|
+
|
|
66
|
+
const parsedData = JSON.parse(storedData!);
|
|
67
|
+
expect(parsedData.state.activePermitHash[chainId][account]).toBe(hash);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should restore permits from localStorage', async () => {
|
|
71
|
+
const permit = await createMockPermit();
|
|
72
|
+
const hash = PermitUtils.getHash(permit);
|
|
73
|
+
|
|
74
|
+
// Add permit to localStorage
|
|
75
|
+
setPermit(chainId, account, permit);
|
|
76
|
+
setActivePermitHash(chainId, account, hash);
|
|
77
|
+
const serializedPermit = PermitUtils.serialize(permit);
|
|
78
|
+
|
|
79
|
+
// Verify data is restored
|
|
80
|
+
const retrievedPermit = getPermit(chainId, account, hash);
|
|
81
|
+
expect(retrievedPermit).toBeDefined();
|
|
82
|
+
expect(PermitUtils.serialize(retrievedPermit!)).toEqual(serializedPermit);
|
|
83
|
+
|
|
84
|
+
const activeHash = getActivePermitHash(chainId, account);
|
|
85
|
+
expect(activeHash).toBe(hash);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should handle corrupted localStorage data gracefully', () => {
|
|
89
|
+
// Set invalid JSON in localStorage
|
|
90
|
+
localStorage.setItem('cofhesdk-permits', 'invalid json');
|
|
91
|
+
|
|
92
|
+
// Store should handle this gracefully
|
|
93
|
+
expect(() => {
|
|
94
|
+
permitStore.store.getState();
|
|
95
|
+
}).not.toThrow();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('should clean up localStorage when permits are removed', async () => {
|
|
99
|
+
const permit = await createMockPermit();
|
|
100
|
+
const hash = PermitUtils.getHash(permit);
|
|
101
|
+
|
|
102
|
+
setPermit(chainId, account, permit);
|
|
103
|
+
setActivePermitHash(chainId, account, hash);
|
|
104
|
+
|
|
105
|
+
// Verify data exists
|
|
106
|
+
let storedData = localStorage.getItem('cofhesdk-permits');
|
|
107
|
+
expect(storedData).toBeDefined();
|
|
108
|
+
|
|
109
|
+
// Remove permit
|
|
110
|
+
removePermit(chainId, account, hash, true);
|
|
111
|
+
|
|
112
|
+
// Verify data is cleaned up
|
|
113
|
+
storedData = localStorage.getItem('cofhesdk-permits');
|
|
114
|
+
const parsedData = JSON.parse(storedData!);
|
|
115
|
+
expect(parsedData.state.permits[chainId][account][hash]).toBeUndefined();
|
|
116
|
+
expect(parsedData.state.activePermitHash[chainId][account]).toBeUndefined();
|
|
117
|
+
});
|
|
118
|
+
});
|