@zentity/fhevm-contracts 0.1.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.
Files changed (83) hide show
  1. package/README.md +160 -0
  2. package/abi/ComplianceRules.json +352 -0
  3. package/abi/CompliantERC20.json +493 -0
  4. package/abi/IdentityRegistry.json +712 -0
  5. package/abi/index.d.ts +3 -0
  6. package/abi/index.js +9 -0
  7. package/contracts/ARCHITECTURE.md +66 -0
  8. package/contracts/ARCHITECTURE_EXPLAINER.md +77 -0
  9. package/contracts/compliance/ComplianceRules.sol +255 -0
  10. package/contracts/core/IdentityRegistry.sol +352 -0
  11. package/contracts/interfaces/IIdentityRegistry.sol +226 -0
  12. package/contracts/mocks/.gitkeep +0 -0
  13. package/contracts/tokens/CompliantERC20.sol +379 -0
  14. package/deployments/hardhat/addresses.json +20 -0
  15. package/deployments/localhost/.chainId +1 -0
  16. package/deployments/localhost/ComplianceRules.json +662 -0
  17. package/deployments/localhost/CompliantERC20.json +888 -0
  18. package/deployments/localhost/IdentityRegistry.json +1093 -0
  19. package/deployments/localhost/solcInputs/e36969353329df673b4fae03d39e01c4.json +60 -0
  20. package/deployments/sepolia/.chainId +1 -0
  21. package/deployments/sepolia/.gitkeep +0 -0
  22. package/deployments/sepolia/ComplianceRules.json +662 -0
  23. package/deployments/sepolia/CompliantERC20.json +888 -0
  24. package/deployments/sepolia/IdentityRegistry.json +1093 -0
  25. package/deployments/sepolia/solcInputs/93d280ff0d4e798a18947a9ed6015031.json +60 -0
  26. package/dist/index.d.ts +459 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +135 -0
  29. package/package.json +110 -0
  30. package/typechain-types/@fhevm/index.ts +5 -0
  31. package/typechain-types/@fhevm/solidity/config/ZamaConfig.sol/ZamaConfig.ts +69 -0
  32. package/typechain-types/@fhevm/solidity/config/ZamaConfig.sol/ZamaEthereumConfig.ts +90 -0
  33. package/typechain-types/@fhevm/solidity/config/ZamaConfig.sol/index.ts +5 -0
  34. package/typechain-types/@fhevm/solidity/config/index.ts +5 -0
  35. package/typechain-types/@fhevm/solidity/index.ts +7 -0
  36. package/typechain-types/@fhevm/solidity/lib/FHE.sol/FHE.ts +112 -0
  37. package/typechain-types/@fhevm/solidity/lib/FHE.sol/IKMSVerifier.ts +108 -0
  38. package/typechain-types/@fhevm/solidity/lib/FHE.sol/index.ts +5 -0
  39. package/typechain-types/@fhevm/solidity/lib/Impl.sol/IACL.ts +190 -0
  40. package/typechain-types/@fhevm/solidity/lib/Impl.sol/IFHEVMExecutor.ts +623 -0
  41. package/typechain-types/@fhevm/solidity/lib/Impl.sol/IInputVerifier.ts +90 -0
  42. package/typechain-types/@fhevm/solidity/lib/Impl.sol/index.ts +6 -0
  43. package/typechain-types/@fhevm/solidity/lib/index.ts +7 -0
  44. package/typechain-types/common.ts +131 -0
  45. package/typechain-types/contracts/compliance/ComplianceRules.ts +479 -0
  46. package/typechain-types/contracts/compliance/index.ts +4 -0
  47. package/typechain-types/contracts/core/IdentityRegistry.ts +874 -0
  48. package/typechain-types/contracts/core/index.ts +4 -0
  49. package/typechain-types/contracts/index.ts +11 -0
  50. package/typechain-types/contracts/interfaces/IIdentityRegistry.ts +798 -0
  51. package/typechain-types/contracts/interfaces/index.ts +4 -0
  52. package/typechain-types/contracts/tokens/CompliantERC20.sol/CompliantERC20.ts +572 -0
  53. package/typechain-types/contracts/tokens/CompliantERC20.sol/IComplianceChecker.ts +95 -0
  54. package/typechain-types/contracts/tokens/CompliantERC20.sol/index.ts +5 -0
  55. package/typechain-types/contracts/tokens/index.ts +5 -0
  56. package/typechain-types/factories/@fhevm/index.ts +4 -0
  57. package/typechain-types/factories/@fhevm/solidity/config/ZamaConfig.sol/ZamaConfig__factory.ts +69 -0
  58. package/typechain-types/factories/@fhevm/solidity/config/ZamaConfig.sol/ZamaEthereumConfig__factory.ts +43 -0
  59. package/typechain-types/factories/@fhevm/solidity/config/ZamaConfig.sol/index.ts +5 -0
  60. package/typechain-types/factories/@fhevm/solidity/config/index.ts +4 -0
  61. package/typechain-types/factories/@fhevm/solidity/index.ts +5 -0
  62. package/typechain-types/factories/@fhevm/solidity/lib/FHE.sol/FHE__factory.ts +88 -0
  63. package/typechain-types/factories/@fhevm/solidity/lib/FHE.sol/IKMSVerifier__factory.ts +54 -0
  64. package/typechain-types/factories/@fhevm/solidity/lib/FHE.sol/index.ts +5 -0
  65. package/typechain-types/factories/@fhevm/solidity/lib/Impl.sol/IACL__factory.ts +121 -0
  66. package/typechain-types/factories/@fhevm/solidity/lib/Impl.sol/IFHEVMExecutor__factory.ts +810 -0
  67. package/typechain-types/factories/@fhevm/solidity/lib/Impl.sol/IInputVerifier__factory.ts +32 -0
  68. package/typechain-types/factories/@fhevm/solidity/lib/Impl.sol/index.ts +6 -0
  69. package/typechain-types/factories/@fhevm/solidity/lib/index.ts +5 -0
  70. package/typechain-types/factories/contracts/compliance/ComplianceRules__factory.ts +437 -0
  71. package/typechain-types/factories/contracts/compliance/index.ts +4 -0
  72. package/typechain-types/factories/contracts/core/IdentityRegistry__factory.ts +777 -0
  73. package/typechain-types/factories/contracts/core/index.ts +4 -0
  74. package/typechain-types/factories/contracts/index.ts +7 -0
  75. package/typechain-types/factories/contracts/interfaces/IIdentityRegistry__factory.ts +640 -0
  76. package/typechain-types/factories/contracts/interfaces/index.ts +4 -0
  77. package/typechain-types/factories/contracts/tokens/CompliantERC20.sol/CompliantERC20__factory.ts +581 -0
  78. package/typechain-types/factories/contracts/tokens/CompliantERC20.sol/IComplianceChecker__factory.ts +44 -0
  79. package/typechain-types/factories/contracts/tokens/CompliantERC20.sol/index.ts +5 -0
  80. package/typechain-types/factories/contracts/tokens/index.ts +4 -0
  81. package/typechain-types/factories/index.ts +5 -0
  82. package/typechain-types/hardhat.d.ts +261 -0
  83. package/typechain-types/index.ts +32 -0
package/README.md ADDED
@@ -0,0 +1,160 @@
1
+ # @zentity/fhevm-contracts
2
+
3
+ fhEVM smart contracts for privacy-preserving identity attestations.
4
+
5
+ ## Overview
6
+
7
+ This package provides Solidity contracts using Zama's fhEVM:
8
+
9
+ - **IdentityRegistry** — encrypted identity attributes (birth year offset, country, KYC, blacklist)
10
+ - **ComplianceRules** — encrypted compliance checks with cached results
11
+ - **CompliantERC20** — demo token enforcing compliance on transfers
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @zentity/fhevm-contracts
17
+ ```
18
+
19
+ ## Quickstart (local)
20
+
21
+ ```bash
22
+ bun install
23
+ bun run compile
24
+ bun run test:mocked
25
+
26
+ # terminal 1
27
+ bunx hardhat node
28
+
29
+ # terminal 2
30
+ bun run deploy:local
31
+ bun run print:deployments localhost --env
32
+ ```
33
+
34
+ ## Quickstart (Sepolia)
35
+
36
+ 1) Set env values in `.env.local`:
37
+
38
+ ```
39
+ FHEVM_RPC_URL=...
40
+ FHEVM_PROVIDER_ID=zama # zama = Zama relayer SDK
41
+ PRIVATE_KEY=0x...
42
+ ```
43
+
44
+ Tip: keep shared defaults in `.env` and secrets in `.env.local`.
45
+ See `docs/deployment.md` for the full env-file behavior.
46
+
47
+ 2) Deploy and print addresses:
48
+
49
+ ```bash
50
+ bun run deploy:sepolia
51
+ bun run print:deployments sepolia --env
52
+ ```
53
+
54
+ 3) Run integration smoke tests:
55
+
56
+ ```bash
57
+ bun run test:sepolia
58
+ ```
59
+
60
+ ## Usage
61
+
62
+ Minimal setup (addresses + ABI):
63
+
64
+ ```typescript
65
+ import {
66
+ getContractAddresses,
67
+ getAbi,
68
+ } from "@zentity/fhevm-contracts";
69
+
70
+ const addresses = getContractAddresses("hardhat");
71
+ const identityRegistry = new ethers.Contract(
72
+ addresses.IdentityRegistry,
73
+ getAbi("IdentityRegistry"),
74
+ signer
75
+ );
76
+ ```
77
+
78
+ Direct ABI imports:
79
+
80
+ ```typescript
81
+ import { IdentityRegistryABI } from "@zentity/fhevm-contracts";
82
+ // or
83
+ import { IdentityRegistryABI } from "@zentity/fhevm-contracts/abi";
84
+ ```
85
+
86
+ Address helpers:
87
+
88
+ ```typescript
89
+ import {
90
+ getContractAddresses,
91
+ resolveContractAddresses,
92
+ getNetworkName,
93
+ hasDeployment,
94
+ CHAIN_ID_BY_NETWORK,
95
+ } from "@zentity/fhevm-contracts";
96
+
97
+ const network = getNetworkName(31337, "hardhat");
98
+ if (!hasDeployment(network)) throw new Error("Missing deployments");
99
+
100
+ const addresses = getContractAddresses(network, {
101
+ overrides: { ComplianceRules: "0x..." },
102
+ });
103
+
104
+ // Sepolia or other networks without bundled deployments:
105
+ const sepoliaAddresses = resolveContractAddresses("sepolia", {
106
+ overrides: {
107
+ IdentityRegistry: "0x...",
108
+ ComplianceRules: "0x...",
109
+ CompliantERC20: "0x...",
110
+ },
111
+ });
112
+ ```
113
+
114
+ ## Addresses & deployments
115
+
116
+ Deployments are stored in `deployments/<network>`. Use the helper script to
117
+ print them as JSON or env-style output:
118
+
119
+ ```bash
120
+ bun run print:deployments
121
+ bun run print:deployments sepolia --env
122
+ ```
123
+
124
+ ## Networks
125
+
126
+ | Network | Chain ID | RPC |
127
+ |---------|----------|-----|
128
+ | Sepolia | 11155111 | https://ethereum-sepolia-rpc.publicnode.com |
129
+ | Localhost | 31337 | http://127.0.0.1:8545 |
130
+
131
+ Note: only networks with a deployment manifest in `deployments/<network>` are
132
+ available via `getContractAddresses()` out of the box.
133
+
134
+ ## Ownership & admin safety
135
+
136
+ Admin-managed contracts use **two-step ownership transfer**:
137
+ `transferOwnership(newOwner)` → `acceptOwnership()`.
138
+
139
+ See `docs/guide.md` for details and best practices.
140
+
141
+ ## Documentation
142
+
143
+ - `docs/guide.md` (deployment, testing, faucets, ownership)
144
+ - `docs/architecture.md` (contract flow overview)
145
+
146
+ ## Development
147
+
148
+ This repo uses Bun by default. If you prefer npm, replace `bun run <script>`
149
+ with `npm run <script>`.
150
+
151
+ Common scripts:
152
+ - `bun run compile`
153
+ - `bun run test:mocked`
154
+ - `bun run test`
155
+ - `bun run deploy:local`
156
+ - `bun run deploy:sepolia`
157
+
158
+ ## License
159
+
160
+ MIT
@@ -0,0 +1,352 @@
1
+ [
2
+ {
3
+ "inputs": [
4
+ {
5
+ "internalType": "address",
6
+ "name": "registry",
7
+ "type": "address"
8
+ },
9
+ {
10
+ "internalType": "uint8",
11
+ "name": "initialMinKycLevel",
12
+ "type": "uint8"
13
+ }
14
+ ],
15
+ "stateMutability": "nonpayable",
16
+ "type": "constructor"
17
+ },
18
+ {
19
+ "inputs": [],
20
+ "name": "AccessProhibited",
21
+ "type": "error"
22
+ },
23
+ {
24
+ "inputs": [],
25
+ "name": "CallerNotAuthorized",
26
+ "type": "error"
27
+ },
28
+ {
29
+ "inputs": [],
30
+ "name": "InvalidOwner",
31
+ "type": "error"
32
+ },
33
+ {
34
+ "inputs": [],
35
+ "name": "OnlyOwner",
36
+ "type": "error"
37
+ },
38
+ {
39
+ "inputs": [],
40
+ "name": "OnlyPendingOwner",
41
+ "type": "error"
42
+ },
43
+ {
44
+ "inputs": [],
45
+ "name": "RegistryNotSet",
46
+ "type": "error"
47
+ },
48
+ {
49
+ "inputs": [],
50
+ "name": "ZamaProtocolUnsupported",
51
+ "type": "error"
52
+ },
53
+ {
54
+ "anonymous": false,
55
+ "inputs": [
56
+ {
57
+ "indexed": true,
58
+ "internalType": "address",
59
+ "name": "caller",
60
+ "type": "address"
61
+ },
62
+ {
63
+ "indexed": false,
64
+ "internalType": "bool",
65
+ "name": "allowed",
66
+ "type": "bool"
67
+ }
68
+ ],
69
+ "name": "AuthorizedCallerUpdated",
70
+ "type": "event"
71
+ },
72
+ {
73
+ "anonymous": false,
74
+ "inputs": [
75
+ {
76
+ "indexed": true,
77
+ "internalType": "address",
78
+ "name": "user",
79
+ "type": "address"
80
+ }
81
+ ],
82
+ "name": "ComplianceChecked",
83
+ "type": "event"
84
+ },
85
+ {
86
+ "anonymous": false,
87
+ "inputs": [
88
+ {
89
+ "indexed": true,
90
+ "internalType": "uint8",
91
+ "name": "newLevel",
92
+ "type": "uint8"
93
+ }
94
+ ],
95
+ "name": "MinKycLevelUpdated",
96
+ "type": "event"
97
+ },
98
+ {
99
+ "anonymous": false,
100
+ "inputs": [
101
+ {
102
+ "indexed": true,
103
+ "internalType": "address",
104
+ "name": "currentOwner",
105
+ "type": "address"
106
+ },
107
+ {
108
+ "indexed": true,
109
+ "internalType": "address",
110
+ "name": "pendingOwner",
111
+ "type": "address"
112
+ }
113
+ ],
114
+ "name": "OwnershipTransferStarted",
115
+ "type": "event"
116
+ },
117
+ {
118
+ "anonymous": false,
119
+ "inputs": [
120
+ {
121
+ "indexed": true,
122
+ "internalType": "address",
123
+ "name": "previousOwner",
124
+ "type": "address"
125
+ },
126
+ {
127
+ "indexed": true,
128
+ "internalType": "address",
129
+ "name": "newOwner",
130
+ "type": "address"
131
+ }
132
+ ],
133
+ "name": "OwnershipTransferred",
134
+ "type": "event"
135
+ },
136
+ {
137
+ "inputs": [],
138
+ "name": "acceptOwnership",
139
+ "outputs": [],
140
+ "stateMutability": "nonpayable",
141
+ "type": "function"
142
+ },
143
+ {
144
+ "inputs": [
145
+ {
146
+ "internalType": "address",
147
+ "name": "caller",
148
+ "type": "address"
149
+ }
150
+ ],
151
+ "name": "authorizedCallers",
152
+ "outputs": [
153
+ {
154
+ "internalType": "bool",
155
+ "name": "authorized",
156
+ "type": "bool"
157
+ }
158
+ ],
159
+ "stateMutability": "view",
160
+ "type": "function"
161
+ },
162
+ {
163
+ "inputs": [
164
+ {
165
+ "internalType": "address",
166
+ "name": "user",
167
+ "type": "address"
168
+ }
169
+ ],
170
+ "name": "checkCompliance",
171
+ "outputs": [
172
+ {
173
+ "internalType": "ebool",
174
+ "name": "",
175
+ "type": "bytes32"
176
+ }
177
+ ],
178
+ "stateMutability": "nonpayable",
179
+ "type": "function"
180
+ },
181
+ {
182
+ "inputs": [
183
+ {
184
+ "internalType": "address",
185
+ "name": "user",
186
+ "type": "address"
187
+ },
188
+ {
189
+ "internalType": "uint16",
190
+ "name": "allowedCountry",
191
+ "type": "uint16"
192
+ }
193
+ ],
194
+ "name": "checkComplianceWithCountry",
195
+ "outputs": [
196
+ {
197
+ "internalType": "ebool",
198
+ "name": "",
199
+ "type": "bytes32"
200
+ }
201
+ ],
202
+ "stateMutability": "nonpayable",
203
+ "type": "function"
204
+ },
205
+ {
206
+ "inputs": [],
207
+ "name": "confidentialProtocolId",
208
+ "outputs": [
209
+ {
210
+ "internalType": "uint256",
211
+ "name": "",
212
+ "type": "uint256"
213
+ }
214
+ ],
215
+ "stateMutability": "view",
216
+ "type": "function"
217
+ },
218
+ {
219
+ "inputs": [
220
+ {
221
+ "internalType": "address",
222
+ "name": "user",
223
+ "type": "address"
224
+ }
225
+ ],
226
+ "name": "getComplianceResult",
227
+ "outputs": [
228
+ {
229
+ "internalType": "ebool",
230
+ "name": "",
231
+ "type": "bytes32"
232
+ }
233
+ ],
234
+ "stateMutability": "view",
235
+ "type": "function"
236
+ },
237
+ {
238
+ "inputs": [
239
+ {
240
+ "internalType": "address",
241
+ "name": "user",
242
+ "type": "address"
243
+ }
244
+ ],
245
+ "name": "hasComplianceResult",
246
+ "outputs": [
247
+ {
248
+ "internalType": "bool",
249
+ "name": "",
250
+ "type": "bool"
251
+ }
252
+ ],
253
+ "stateMutability": "view",
254
+ "type": "function"
255
+ },
256
+ {
257
+ "inputs": [],
258
+ "name": "identityRegistry",
259
+ "outputs": [
260
+ {
261
+ "internalType": "contract IIdentityRegistry",
262
+ "name": "",
263
+ "type": "address"
264
+ }
265
+ ],
266
+ "stateMutability": "view",
267
+ "type": "function"
268
+ },
269
+ {
270
+ "inputs": [],
271
+ "name": "minKycLevel",
272
+ "outputs": [
273
+ {
274
+ "internalType": "uint8",
275
+ "name": "",
276
+ "type": "uint8"
277
+ }
278
+ ],
279
+ "stateMutability": "view",
280
+ "type": "function"
281
+ },
282
+ {
283
+ "inputs": [],
284
+ "name": "owner",
285
+ "outputs": [
286
+ {
287
+ "internalType": "address",
288
+ "name": "",
289
+ "type": "address"
290
+ }
291
+ ],
292
+ "stateMutability": "view",
293
+ "type": "function"
294
+ },
295
+ {
296
+ "inputs": [],
297
+ "name": "pendingOwner",
298
+ "outputs": [
299
+ {
300
+ "internalType": "address",
301
+ "name": "",
302
+ "type": "address"
303
+ }
304
+ ],
305
+ "stateMutability": "view",
306
+ "type": "function"
307
+ },
308
+ {
309
+ "inputs": [
310
+ {
311
+ "internalType": "address",
312
+ "name": "caller",
313
+ "type": "address"
314
+ },
315
+ {
316
+ "internalType": "bool",
317
+ "name": "allowed",
318
+ "type": "bool"
319
+ }
320
+ ],
321
+ "name": "setAuthorizedCaller",
322
+ "outputs": [],
323
+ "stateMutability": "nonpayable",
324
+ "type": "function"
325
+ },
326
+ {
327
+ "inputs": [
328
+ {
329
+ "internalType": "uint8",
330
+ "name": "newLevel",
331
+ "type": "uint8"
332
+ }
333
+ ],
334
+ "name": "setMinKycLevel",
335
+ "outputs": [],
336
+ "stateMutability": "nonpayable",
337
+ "type": "function"
338
+ },
339
+ {
340
+ "inputs": [
341
+ {
342
+ "internalType": "address",
343
+ "name": "newOwner",
344
+ "type": "address"
345
+ }
346
+ ],
347
+ "name": "transferOwnership",
348
+ "outputs": [],
349
+ "stateMutability": "nonpayable",
350
+ "type": "function"
351
+ }
352
+ ]