@cofhe/sdk 0.0.0-alpha-20260409113701

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 (132) hide show
  1. package/CHANGELOG.md +146 -0
  2. package/adapters/ethers5.test.ts +174 -0
  3. package/adapters/ethers5.ts +36 -0
  4. package/adapters/ethers6.test.ts +169 -0
  5. package/adapters/ethers6.ts +36 -0
  6. package/adapters/hardhat-node.ts +167 -0
  7. package/adapters/hardhat.hh2.test.ts +159 -0
  8. package/adapters/hardhat.ts +36 -0
  9. package/adapters/index.test.ts +20 -0
  10. package/adapters/index.ts +5 -0
  11. package/adapters/smartWallet.ts +99 -0
  12. package/adapters/test-utils.ts +53 -0
  13. package/adapters/types.ts +6 -0
  14. package/adapters/wagmi.test.ts +156 -0
  15. package/adapters/wagmi.ts +17 -0
  16. package/chains/chains/arbSepolia.ts +14 -0
  17. package/chains/chains/baseSepolia.ts +14 -0
  18. package/chains/chains/hardhat.ts +15 -0
  19. package/chains/chains/localcofhe.ts +14 -0
  20. package/chains/chains/sepolia.ts +14 -0
  21. package/chains/chains.test.ts +50 -0
  22. package/chains/defineChain.ts +18 -0
  23. package/chains/index.ts +35 -0
  24. package/chains/types.ts +32 -0
  25. package/core/baseBuilder.ts +119 -0
  26. package/core/client.test.ts +429 -0
  27. package/core/client.ts +341 -0
  28. package/core/clientTypes.ts +119 -0
  29. package/core/config.test.ts +242 -0
  30. package/core/config.ts +225 -0
  31. package/core/consts.ts +22 -0
  32. package/core/decrypt/MockThresholdNetworkAbi.ts +179 -0
  33. package/core/decrypt/cofheMocksDecryptForTx.ts +84 -0
  34. package/core/decrypt/cofheMocksDecryptForView.ts +48 -0
  35. package/core/decrypt/decryptForTxBuilder.ts +359 -0
  36. package/core/decrypt/decryptForViewBuilder.ts +332 -0
  37. package/core/decrypt/decryptUtils.ts +28 -0
  38. package/core/decrypt/pollCallbacks.test.ts +194 -0
  39. package/core/decrypt/polling.ts +14 -0
  40. package/core/decrypt/tnDecryptUtils.ts +65 -0
  41. package/core/decrypt/tnDecryptV1.ts +171 -0
  42. package/core/decrypt/tnDecryptV2.ts +365 -0
  43. package/core/decrypt/tnSealOutputV1.ts +59 -0
  44. package/core/decrypt/tnSealOutputV2.ts +324 -0
  45. package/core/decrypt/verifyDecryptResult.ts +52 -0
  46. package/core/encrypt/MockZkVerifierAbi.ts +106 -0
  47. package/core/encrypt/cofheMocksZkVerifySign.ts +281 -0
  48. package/core/encrypt/encryptInputsBuilder.test.ts +747 -0
  49. package/core/encrypt/encryptInputsBuilder.ts +583 -0
  50. package/core/encrypt/encryptUtils.ts +67 -0
  51. package/core/encrypt/zkPackProveVerify.ts +335 -0
  52. package/core/error.ts +168 -0
  53. package/core/fetchKeys.test.ts +195 -0
  54. package/core/fetchKeys.ts +144 -0
  55. package/core/index.ts +106 -0
  56. package/core/keyStore.test.ts +226 -0
  57. package/core/keyStore.ts +154 -0
  58. package/core/permits.test.ts +493 -0
  59. package/core/permits.ts +201 -0
  60. package/core/types.ts +419 -0
  61. package/core/utils.ts +130 -0
  62. package/dist/adapters.cjs +88 -0
  63. package/dist/adapters.d.cts +14576 -0
  64. package/dist/adapters.d.ts +14576 -0
  65. package/dist/adapters.js +83 -0
  66. package/dist/chains.cjs +111 -0
  67. package/dist/chains.d.cts +121 -0
  68. package/dist/chains.d.ts +121 -0
  69. package/dist/chains.js +1 -0
  70. package/dist/chunk-36FBWLUS.js +3310 -0
  71. package/dist/chunk-7HLGHV67.js +990 -0
  72. package/dist/chunk-TBLR7NNE.js +102 -0
  73. package/dist/clientTypes-AVSCBet7.d.cts +998 -0
  74. package/dist/clientTypes-flH1ju82.d.ts +998 -0
  75. package/dist/core.cjs +4362 -0
  76. package/dist/core.d.cts +138 -0
  77. package/dist/core.d.ts +138 -0
  78. package/dist/core.js +3 -0
  79. package/dist/node.cjs +4225 -0
  80. package/dist/node.d.cts +22 -0
  81. package/dist/node.d.ts +22 -0
  82. package/dist/node.js +91 -0
  83. package/dist/permit-jRirYqFt.d.cts +376 -0
  84. package/dist/permit-jRirYqFt.d.ts +376 -0
  85. package/dist/permits.cjs +1025 -0
  86. package/dist/permits.d.cts +353 -0
  87. package/dist/permits.d.ts +353 -0
  88. package/dist/permits.js +1 -0
  89. package/dist/types-YiAC4gig.d.cts +33 -0
  90. package/dist/types-YiAC4gig.d.ts +33 -0
  91. package/dist/web.cjs +4434 -0
  92. package/dist/web.d.cts +42 -0
  93. package/dist/web.d.ts +42 -0
  94. package/dist/web.js +256 -0
  95. package/dist/zkProve.worker.cjs +93 -0
  96. package/dist/zkProve.worker.d.cts +2 -0
  97. package/dist/zkProve.worker.d.ts +2 -0
  98. package/dist/zkProve.worker.js +91 -0
  99. package/node/client.test.ts +159 -0
  100. package/node/config.test.ts +68 -0
  101. package/node/encryptInputs.test.ts +155 -0
  102. package/node/index.ts +97 -0
  103. package/node/storage.ts +51 -0
  104. package/package.json +121 -0
  105. package/permits/index.ts +68 -0
  106. package/permits/localstorage.test.ts +113 -0
  107. package/permits/onchain-utils.ts +221 -0
  108. package/permits/permit.test.ts +534 -0
  109. package/permits/permit.ts +386 -0
  110. package/permits/sealing.test.ts +84 -0
  111. package/permits/sealing.ts +131 -0
  112. package/permits/signature.ts +79 -0
  113. package/permits/store.test.ts +88 -0
  114. package/permits/store.ts +156 -0
  115. package/permits/test-utils.ts +28 -0
  116. package/permits/types.ts +204 -0
  117. package/permits/utils.ts +58 -0
  118. package/permits/validation.test.ts +361 -0
  119. package/permits/validation.ts +327 -0
  120. package/web/client.web.test.ts +159 -0
  121. package/web/config.web.test.ts +69 -0
  122. package/web/const.ts +2 -0
  123. package/web/encryptInputs.web.test.ts +172 -0
  124. package/web/index.ts +166 -0
  125. package/web/storage.ts +49 -0
  126. package/web/worker.builder.web.test.ts +148 -0
  127. package/web/worker.config.web.test.ts +329 -0
  128. package/web/worker.output.web.test.ts +84 -0
  129. package/web/workerManager.test.ts +80 -0
  130. package/web/workerManager.ts +214 -0
  131. package/web/workerManager.web.test.ts +114 -0
  132. package/web/zkProve.worker.ts +133 -0
@@ -0,0 +1,102 @@
1
+ import { z } from 'zod';
2
+
3
+ // chains/types.ts
4
+ var EnvironmentSchema = z.enum(["MOCK", "TESTNET", "MAINNET"]);
5
+ var CofheChainSchema = z.object({
6
+ /** Chain ID */
7
+ id: z.number().int().positive(),
8
+ /** Human-readable chain name */
9
+ name: z.string().min(1),
10
+ /** Network identifier */
11
+ network: z.string().min(1),
12
+ /** coFhe service URL */
13
+ coFheUrl: z.url(),
14
+ /** Verifier service URL */
15
+ verifierUrl: z.url(),
16
+ /** Threshold network service URL */
17
+ thresholdNetworkUrl: z.url(),
18
+ /** Environment type */
19
+ environment: EnvironmentSchema
20
+ });
21
+ function defineChain(chainConfig) {
22
+ const result = CofheChainSchema.safeParse(chainConfig);
23
+ if (!result.success) {
24
+ throw new Error(`Invalid chain configuration: ${z.prettifyError(result.error)}`, { cause: result.error });
25
+ }
26
+ return result.data;
27
+ }
28
+
29
+ // chains/chains/sepolia.ts
30
+ var sepolia = defineChain({
31
+ id: 11155111,
32
+ name: "Sepolia",
33
+ network: "sepolia",
34
+ coFheUrl: "https://testnet-cofhe.fhenix.zone",
35
+ verifierUrl: "https://testnet-cofhe-vrf.fhenix.zone",
36
+ thresholdNetworkUrl: "https://testnet-cofhe-tn.fhenix.zone",
37
+ environment: "TESTNET"
38
+ });
39
+
40
+ // chains/chains/arbSepolia.ts
41
+ var arbSepolia = defineChain({
42
+ id: 421614,
43
+ name: "Arbitrum Sepolia",
44
+ network: "arb-sepolia",
45
+ coFheUrl: "https://testnet-cofhe.fhenix.zone",
46
+ verifierUrl: "https://testnet-cofhe-vrf.fhenix.zone",
47
+ thresholdNetworkUrl: "https://testnet-cofhe-tn.fhenix.zone",
48
+ environment: "TESTNET"
49
+ });
50
+
51
+ // chains/chains/baseSepolia.ts
52
+ var baseSepolia = defineChain({
53
+ id: 84532,
54
+ name: "Base Sepolia",
55
+ network: "base-sepolia",
56
+ coFheUrl: "https://testnet-cofhe.fhenix.zone",
57
+ verifierUrl: "https://testnet-cofhe-vrf.fhenix.zone",
58
+ thresholdNetworkUrl: "https://testnet-cofhe-tn.fhenix.zone",
59
+ environment: "TESTNET"
60
+ });
61
+
62
+ // chains/chains/hardhat.ts
63
+ var hardhat = defineChain({
64
+ id: 31337,
65
+ name: "Hardhat",
66
+ network: "localhost",
67
+ // These are unused in the mock environment
68
+ coFheUrl: "http://127.0.0.1:8448",
69
+ verifierUrl: "http://127.0.0.1:3001",
70
+ thresholdNetworkUrl: "http://127.0.0.1:3000",
71
+ environment: "MOCK"
72
+ });
73
+
74
+ // chains/chains/localcofhe.ts
75
+ var localcofhe = defineChain({
76
+ id: 420105,
77
+ name: "Local Cofhe",
78
+ network: "localhost",
79
+ coFheUrl: "http://127.0.0.1:9448",
80
+ verifierUrl: "http://127.0.0.1:3001",
81
+ thresholdNetworkUrl: "http://127.0.0.1:3000",
82
+ environment: "TESTNET"
83
+ });
84
+
85
+ // chains/index.ts
86
+ var chains = {
87
+ sepolia,
88
+ arbSepolia,
89
+ baseSepolia,
90
+ hardhat,
91
+ localcofhe
92
+ };
93
+ var getChainById = (chainId) => {
94
+ return Object.values(chains).find((chain) => chain.id === chainId);
95
+ };
96
+ var getChainByName = (name) => {
97
+ return Object.values(chains).find(
98
+ (chain) => chain.name.toLowerCase() === name.toLowerCase() || chain.network.toLowerCase() === name.toLowerCase()
99
+ );
100
+ };
101
+
102
+ export { arbSepolia, baseSepolia, chains, getChainById, getChainByName, hardhat, localcofhe, sepolia };