@primuslabs/fhetransform-sdk 0.4.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 (302) hide show
  1. package/README.md +198 -0
  2. package/dist/abis/acl.abi.d.ts +379 -0
  3. package/dist/abis/acl.abi.js +495 -0
  4. package/dist/abis/acl.abi.js.map +1 -0
  5. package/dist/abis/alphatrion_reward.abi.d.ts +407 -0
  6. package/dist/abis/alphatrion_reward.abi.js +532 -0
  7. package/dist/abis/alphatrion_reward.abi.js.map +1 -0
  8. package/dist/abis/ciphertext_digests.abi.d.ts +336 -0
  9. package/dist/abis/ciphertext_digests.abi.js +444 -0
  10. package/dist/abis/ciphertext_digests.abi.js.map +1 -0
  11. package/dist/abis/ciphertext_verification.abi.d.ts +637 -0
  12. package/dist/abis/ciphertext_verification.abi.js +830 -0
  13. package/dist/abis/ciphertext_verification.abi.js.map +1 -0
  14. package/dist/abis/convert_token.abi.d.ts +922 -0
  15. package/dist/abis/convert_token.abi.js +1208 -0
  16. package/dist/abis/convert_token.abi.js.map +1 -0
  17. package/dist/abis/decryption.abi.d.ts +956 -0
  18. package/dist/abis/decryption.abi.js +1244 -0
  19. package/dist/abis/decryption.abi.js.map +1 -0
  20. package/dist/abis/erc20.abi.d.ts +265 -0
  21. package/dist/abis/erc20.abi.js +350 -0
  22. package/dist/abis/erc20.abi.js.map +1 -0
  23. package/dist/abis/fhe_executor.abi.d.ts +1535 -0
  24. package/dist/abis/fhe_executor.abi.js +1962 -0
  25. package/dist/abis/fhe_executor.abi.js.map +1 -0
  26. package/dist/abis/space_bridge_config.abi.d.ts +792 -0
  27. package/dist/abis/space_bridge_config.abi.js +1032 -0
  28. package/dist/abis/space_bridge_config.abi.js.map +1 -0
  29. package/dist/abis/token.abi.d.ts +630 -0
  30. package/dist/abis/token.abi.js +828 -0
  31. package/dist/abis/token.abi.js.map +1 -0
  32. package/dist/cli/eusdc.d.ts +2 -0
  33. package/dist/cli/eusdc.js +41 -0
  34. package/dist/cli/eusdc.js.map +1 -0
  35. package/dist/contract/callbacks.d.ts +59 -0
  36. package/dist/contract/callbacks.js +2 -0
  37. package/dist/contract/callbacks.js.map +1 -0
  38. package/dist/contract/convert-token.d.ts +107 -0
  39. package/dist/contract/convert-token.js +249 -0
  40. package/dist/contract/convert-token.js.map +1 -0
  41. package/dist/contract/token.d.ts +167 -0
  42. package/dist/contract/token.js +404 -0
  43. package/dist/contract/token.js.map +1 -0
  44. package/dist/contract/transaction.d.ts +29 -0
  45. package/dist/contract/transaction.js +2 -0
  46. package/dist/contract/transaction.js.map +1 -0
  47. package/dist/core/address.d.ts +118 -0
  48. package/dist/core/address.js +200 -0
  49. package/dist/core/address.js.map +1 -0
  50. package/dist/core/auth.d.ts +68 -0
  51. package/dist/core/auth.js +58 -0
  52. package/dist/core/auth.js.map +1 -0
  53. package/dist/core/bytes.d.ts +48 -0
  54. package/dist/core/bytes.js +117 -0
  55. package/dist/core/bytes.js.map +1 -0
  56. package/dist/core/cache-manager.d.ts +138 -0
  57. package/dist/core/cache-manager.js +440 -0
  58. package/dist/core/cache-manager.js.map +1 -0
  59. package/dist/core/chain.d.ts +41 -0
  60. package/dist/core/chain.js +59 -0
  61. package/dist/core/chain.js.map +1 -0
  62. package/dist/core/constants.d.ts +24 -0
  63. package/dist/core/constants.js +25 -0
  64. package/dist/core/constants.js.map +1 -0
  65. package/dist/core/error.d.ts +2 -0
  66. package/dist/core/error.js +14 -0
  67. package/dist/core/error.js.map +1 -0
  68. package/dist/core/errors/error-catalog.d.ts +29 -0
  69. package/dist/core/errors/error-catalog.js +84 -0
  70. package/dist/core/errors/error-catalog.js.map +1 -0
  71. package/dist/core/errors/error-codes.d.ts +52 -0
  72. package/dist/core/errors/error-codes.js +61 -0
  73. package/dist/core/errors/error-codes.js.map +1 -0
  74. package/dist/core/errors/error-utils.d.ts +27 -0
  75. package/dist/core/errors/error-utils.js +110 -0
  76. package/dist/core/errors/error-utils.js.map +1 -0
  77. package/dist/core/errors/fhe-error.d.ts +98 -0
  78. package/dist/core/errors/fhe-error.js +190 -0
  79. package/dist/core/errors/fhe-error.js.map +1 -0
  80. package/dist/core/errors/index.d.ts +4 -0
  81. package/dist/core/errors/index.js +5 -0
  82. package/dist/core/errors/index.js.map +1 -0
  83. package/dist/core/estimate.d.ts +39 -0
  84. package/dist/core/estimate.js +111 -0
  85. package/dist/core/estimate.js.map +1 -0
  86. package/dist/core/event.d.ts +212 -0
  87. package/dist/core/event.js +42 -0
  88. package/dist/core/event.js.map +1 -0
  89. package/dist/core/fhe-type.d.ts +75 -0
  90. package/dist/core/fhe-type.js +115 -0
  91. package/dist/core/fhe-type.js.map +1 -0
  92. package/dist/core/fhe.d.ts +11 -0
  93. package/dist/core/fhe.js +23 -0
  94. package/dist/core/fhe.js.map +1 -0
  95. package/dist/core/handle.d.ts +42 -0
  96. package/dist/core/handle.js +99 -0
  97. package/dist/core/handle.js.map +1 -0
  98. package/dist/core/json-utils.d.ts +18 -0
  99. package/dist/core/json-utils.js +37 -0
  100. package/dist/core/json-utils.js.map +1 -0
  101. package/dist/core/kms.d.ts +42 -0
  102. package/dist/core/kms.js +70 -0
  103. package/dist/core/kms.js.map +1 -0
  104. package/dist/core/logger.d.ts +3 -0
  105. package/dist/core/logger.js +11 -0
  106. package/dist/core/logger.js.map +1 -0
  107. package/dist/core/pretty-print.d.ts +18 -0
  108. package/dist/core/pretty-print.js +84 -0
  109. package/dist/core/pretty-print.js.map +1 -0
  110. package/dist/core/primitives.d.ts +22 -0
  111. package/dist/core/primitives.js +2 -0
  112. package/dist/core/primitives.js.map +1 -0
  113. package/dist/core/retryable-handler.d.ts +74 -0
  114. package/dist/core/retryable-handler.js +227 -0
  115. package/dist/core/retryable-handler.js.map +1 -0
  116. package/dist/core/signer-address-info.d.ts +15 -0
  117. package/dist/core/signer-address-info.js +33 -0
  118. package/dist/core/signer-address-info.js.map +1 -0
  119. package/dist/core/string.d.ts +28 -0
  120. package/dist/core/string.js +33 -0
  121. package/dist/core/string.js.map +1 -0
  122. package/dist/core/swallow.d.ts +23 -0
  123. package/dist/core/swallow.js +37 -0
  124. package/dist/core/swallow.js.map +1 -0
  125. package/dist/core/system-contract-info.d.ts +17 -0
  126. package/dist/core/system-contract-info.js +41 -0
  127. package/dist/core/system-contract-info.js.map +1 -0
  128. package/dist/core/ttl-cache.d.ts +81 -0
  129. package/dist/core/ttl-cache.js +113 -0
  130. package/dist/core/ttl-cache.js.map +1 -0
  131. package/dist/core/tx-error-parser.d.ts +40 -0
  132. package/dist/core/tx-error-parser.js +83 -0
  133. package/dist/core/tx-error-parser.js.map +1 -0
  134. package/dist/core/utils.d.ts +62 -0
  135. package/dist/core/utils.js +143 -0
  136. package/dist/core/utils.js.map +1 -0
  137. package/dist/index.d.ts +40 -0
  138. package/dist/index.js +48 -0
  139. package/dist/index.js.map +1 -0
  140. package/dist/jazz/encrypt-key-p.d.ts +65 -0
  141. package/dist/jazz/encrypt-key-p.js +283 -0
  142. package/dist/jazz/encrypt-key-p.js.map +1 -0
  143. package/dist/jazz/encrypt-p.d.ts +82 -0
  144. package/dist/jazz/encrypt-p.js +139 -0
  145. package/dist/jazz/encrypt-p.js.map +1 -0
  146. package/dist/jazz/encrypt.d.ts +58 -0
  147. package/dist/jazz/encrypt.js +155 -0
  148. package/dist/jazz/encrypt.js.map +1 -0
  149. package/dist/jazz/input-proof-p.d.ts +122 -0
  150. package/dist/jazz/input-proof-p.js +265 -0
  151. package/dist/jazz/input-proof-p.js.map +1 -0
  152. package/dist/jazz/jazz-client-i.d.ts +16 -0
  153. package/dist/jazz/jazz-client-i.js +2 -0
  154. package/dist/jazz/jazz-client-i.js.map +1 -0
  155. package/dist/jazz/jazz-client.d.ts +18 -0
  156. package/dist/jazz/jazz-client.js +24 -0
  157. package/dist/jazz/jazz-client.js.map +1 -0
  158. package/dist/jazz/key-pair.d.ts +50 -0
  159. package/dist/jazz/key-pair.js +166 -0
  160. package/dist/jazz/key-pair.js.map +1 -0
  161. package/dist/jazz/mock/fake.d.ts +3 -0
  162. package/dist/jazz/mock/fake.js +23 -0
  163. package/dist/jazz/mock/fake.js.map +1 -0
  164. package/dist/jazz/mock/fetch-input-proof.d.ts +4 -0
  165. package/dist/jazz/mock/fetch-input-proof.js +63 -0
  166. package/dist/jazz/mock/fetch-input-proof.js.map +1 -0
  167. package/dist/jazz/mock/fetch-key-url.d.ts +3 -0
  168. package/dist/jazz/mock/fetch-key-url.js +15 -0
  169. package/dist/jazz/mock/fetch-key-url.js.map +1 -0
  170. package/dist/jazz/mock/fetch-public-decrypt.d.ts +3 -0
  171. package/dist/jazz/mock/fetch-public-decrypt.js +81 -0
  172. package/dist/jazz/mock/fetch-public-decrypt.js.map +1 -0
  173. package/dist/jazz/mock/fetch-user-decrypt.d.ts +4 -0
  174. package/dist/jazz/mock/fetch-user-decrypt.js +174 -0
  175. package/dist/jazz/mock/fetch-user-decrypt.js.map +1 -0
  176. package/dist/jazz/module/fetch-input-proof.d.ts +19 -0
  177. package/dist/jazz/module/fetch-input-proof.js +72 -0
  178. package/dist/jazz/module/fetch-input-proof.js.map +1 -0
  179. package/dist/jazz/module/fetch-key-url.d.ts +17 -0
  180. package/dist/jazz/module/fetch-key-url.js +46 -0
  181. package/dist/jazz/module/fetch-key-url.js.map +1 -0
  182. package/dist/jazz/module/fetch-public-decrypt.d.ts +19 -0
  183. package/dist/jazz/module/fetch-public-decrypt.js +65 -0
  184. package/dist/jazz/module/fetch-public-decrypt.js.map +1 -0
  185. package/dist/jazz/module/fetch-user-decrypt.d.ts +19 -0
  186. package/dist/jazz/module/fetch-user-decrypt.js +109 -0
  187. package/dist/jazz/module/fetch-user-decrypt.js.map +1 -0
  188. package/dist/jazz/module/jazz-async-request.d.ts +102 -0
  189. package/dist/jazz/module/jazz-async-request.js +515 -0
  190. package/dist/jazz/module/jazz-async-request.js.map +1 -0
  191. package/dist/jazz/module/jazz-p.d.ts +61 -0
  192. package/dist/jazz/module/jazz-p.js +33 -0
  193. package/dist/jazz/module/jazz-p.js.map +1 -0
  194. package/dist/jazz/module/s3-download.d.ts +85 -0
  195. package/dist/jazz/module/s3-download.js +293 -0
  196. package/dist/jazz/module/s3-download.js.map +1 -0
  197. package/dist/jazz/permit.d.ts +200 -0
  198. package/dist/jazz/permit.js +319 -0
  199. package/dist/jazz/permit.js.map +1 -0
  200. package/dist/jazz/public-decrypt-p.d.ts +96 -0
  201. package/dist/jazz/public-decrypt-p.js +258 -0
  202. package/dist/jazz/public-decrypt-p.js.map +1 -0
  203. package/dist/jazz/public-decrypt.d.ts +48 -0
  204. package/dist/jazz/public-decrypt.js +156 -0
  205. package/dist/jazz/public-decrypt.js.map +1 -0
  206. package/dist/jazz/read-contract.d.ts +81 -0
  207. package/dist/jazz/read-contract.js +125 -0
  208. package/dist/jazz/read-contract.js.map +1 -0
  209. package/dist/jazz/types/common.d.ts +17 -0
  210. package/dist/jazz/types/common.js +2 -0
  211. package/dist/jazz/types/common.js.map +1 -0
  212. package/dist/jazz/types/input-proof.d.ts +76 -0
  213. package/dist/jazz/types/input-proof.js +2 -0
  214. package/dist/jazz/types/input-proof.js.map +1 -0
  215. package/dist/jazz/types/key-url.d.ts +68 -0
  216. package/dist/jazz/types/key-url.js +5 -0
  217. package/dist/jazz/types/key-url.js.map +1 -0
  218. package/dist/jazz/types/public-decrypt.d.ts +61 -0
  219. package/dist/jazz/types/public-decrypt.js +2 -0
  220. package/dist/jazz/types/public-decrypt.js.map +1 -0
  221. package/dist/jazz/types/user-decrypt.d.ts +123 -0
  222. package/dist/jazz/types/user-decrypt.js +2 -0
  223. package/dist/jazz/types/user-decrypt.js.map +1 -0
  224. package/dist/jazz/user-decrypt-p.d.ts +111 -0
  225. package/dist/jazz/user-decrypt-p.js +280 -0
  226. package/dist/jazz/user-decrypt-p.js.map +1 -0
  227. package/dist/jazz/user-decrypt.d.ts +74 -0
  228. package/dist/jazz/user-decrypt.js +143 -0
  229. package/dist/jazz/user-decrypt.js.map +1 -0
  230. package/dist/native/fhe-api.js +5959 -0
  231. package/dist/native/fhe-api.node.cjs +6167 -0
  232. package/dist/native/fhe-api.node.worker.cjs +210 -0
  233. package/dist/native/fhe-api.wasm +0 -0
  234. package/dist/native/fhe-api.worker.js +164 -0
  235. package/dist/native/kms/node/kms_lib.d.ts +38 -0
  236. package/dist/native/kms/node/kms_lib.js +356 -0
  237. package/dist/native/kms/node/kms_lib_bg.wasm +0 -0
  238. package/dist/native/kms/node/kms_lib_bg.wasm.d.ts +21 -0
  239. package/dist/native/kms/node/package.json +11 -0
  240. package/dist/native/kms/web/kms_lib.d.ts +84 -0
  241. package/dist/native/kms/web/kms_lib.js +443 -0
  242. package/dist/native/kms/web/kms_lib_bg.wasm +0 -0
  243. package/dist/native/kms/web/kms_lib_bg.wasm.d.ts +21 -0
  244. package/dist/native/kms/web/package.json +15 -0
  245. package/dist/runtime/browser.d.ts +36 -0
  246. package/dist/runtime/browser.js +115 -0
  247. package/dist/runtime/browser.js.map +1 -0
  248. package/dist/runtime/node.d.ts +30 -0
  249. package/dist/runtime/node.js +95 -0
  250. package/dist/runtime/node.js.map +1 -0
  251. package/dist/sdk/fhetransform-sdk-b.d.ts +102 -0
  252. package/dist/sdk/fhetransform-sdk-b.js +294 -0
  253. package/dist/sdk/fhetransform-sdk-b.js.map +1 -0
  254. package/dist/sdk/fhetransform-sdk.d.ts +87 -0
  255. package/dist/sdk/fhetransform-sdk.js +135 -0
  256. package/dist/sdk/fhetransform-sdk.js.map +1 -0
  257. package/dist/sdk/jazz-service.d.ts +13 -0
  258. package/dist/sdk/jazz-service.js +58 -0
  259. package/dist/sdk/jazz-service.js.map +1 -0
  260. package/dist/sdk/permit-service.d.ts +45 -0
  261. package/dist/sdk/permit-service.js +144 -0
  262. package/dist/sdk/permit-service.js.map +1 -0
  263. package/dist/wasm/fhe-wasm-client.d.ts +19 -0
  264. package/dist/wasm/fhe-wasm-client.js +23 -0
  265. package/dist/wasm/fhe-wasm-client.js.map +1 -0
  266. package/dist/wasm/fhe-wasm-module.d.ts +24 -0
  267. package/dist/wasm/fhe-wasm-module.js +141 -0
  268. package/dist/wasm/fhe-wasm-module.js.map +1 -0
  269. package/dist/wasm/fhe-wasm-type.d.ts +59 -0
  270. package/dist/wasm/fhe-wasm-type.js +244 -0
  271. package/dist/wasm/fhe-wasm-type.js.map +1 -0
  272. package/dist/wasm/wasm-loader.browser.d.ts +21 -0
  273. package/dist/wasm/wasm-loader.browser.js +143 -0
  274. package/dist/wasm/wasm-loader.browser.js.map +1 -0
  275. package/dist/wasm/wasm-loader.node.d.ts +24 -0
  276. package/dist/wasm/wasm-loader.node.js +114 -0
  277. package/dist/wasm/wasm-loader.node.js.map +1 -0
  278. package/dist/wasm/worker-client.browser.d.ts +6 -0
  279. package/dist/wasm/worker-client.browser.js +21 -0
  280. package/dist/wasm/worker-client.browser.js.map +1 -0
  281. package/dist/wasm/worker-client.d.ts +34 -0
  282. package/dist/wasm/worker-client.js +160 -0
  283. package/dist/wasm/worker-client.js.map +1 -0
  284. package/dist/wasm/worker-client.node.d.ts +6 -0
  285. package/dist/wasm/worker-client.node.js +20 -0
  286. package/dist/wasm/worker-client.node.js.map +1 -0
  287. package/dist/wasm/worker-message.d.ts +61 -0
  288. package/dist/wasm/worker-message.js +2 -0
  289. package/dist/wasm/worker-message.js.map +1 -0
  290. package/dist/wasm/worker-transport.browser.d.ts +15 -0
  291. package/dist/wasm/worker-transport.browser.js +35 -0
  292. package/dist/wasm/worker-transport.browser.js.map +1 -0
  293. package/dist/wasm/worker-transport.d.ts +6 -0
  294. package/dist/wasm/worker-transport.js +2 -0
  295. package/dist/wasm/worker-transport.js.map +1 -0
  296. package/dist/wasm/worker-transport.node.d.ts +17 -0
  297. package/dist/wasm/worker-transport.node.js +39 -0
  298. package/dist/wasm/worker-transport.node.js.map +1 -0
  299. package/dist/wasm/worker.d.ts +1 -0
  300. package/dist/wasm/worker.js +69 -0
  301. package/dist/wasm/worker.js.map +1 -0
  302. package/package.json +81 -0
@@ -0,0 +1,41 @@
1
+ import { FheErrorCode } from "./errors/error-codes.js";
2
+ import { FheError } from "./errors/fhe-error.js";
3
+ /**
4
+ * Returns the system contract addresses for a given blockchain chain ID.
5
+ * @param chainId - The blockchain chain ID
6
+ * @returns SystemContractInfo containing all required contract addresses
7
+ * @throws Error if the chain ID is not supported
8
+ */
9
+ export function getSystemContractInfo(chainId) {
10
+ let info;
11
+ switch (chainId) {
12
+ case 31337n: // Anvil / Hardhat local development
13
+ info = {
14
+ aclContractAddress: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
15
+ spaceBridgeConfigAddress: "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318",
16
+ decryptionContractAddress: "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82",
17
+ ciphertextVerificationAddress: "0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE",
18
+ };
19
+ break;
20
+ case 56n: // BNB Smart Chain Mainnet
21
+ info = {
22
+ aclContractAddress: "0x3fE3B494Ae2d54fdee94C9fe60365024a44742AE",
23
+ spaceBridgeConfigAddress: "0x8914af6Bb24Cbff797Be208aBE388927C0FC0396",
24
+ decryptionContractAddress: "0x29873f805e66B39c28D394B213f712B7b2B52ba1",
25
+ ciphertextVerificationAddress: "0x9313191E3Eadc4C365d2043E8b7c03d73193D99A",
26
+ };
27
+ break;
28
+ case 97n: // BNB Smart Chain Testnet
29
+ info = {
30
+ aclContractAddress: "0x73d8e6Aa72DFD64ADcdF388411A6EE3F3CFa98B5",
31
+ spaceBridgeConfigAddress: "0xaF2e46a68AfBdf75026643f0ecFa4f355A3F22Ca",
32
+ decryptionContractAddress: "0x979A0Ccee4546dCDd0234db28cFf1A06DE2eb4d7",
33
+ ciphertextVerificationAddress: "0x26123D7a7406c3a1D54C15C8A129f2bdB55C4dec",
34
+ };
35
+ break;
36
+ default:
37
+ throw new FheError({ code: FheErrorCode.UnsupportedChain, message: `Unsupported system contract info for chainId: ${chainId.toString()}` });
38
+ }
39
+ return info;
40
+ }
41
+ //# sourceMappingURL=system-contract-info.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-contract-info.js","sourceRoot":"","sources":["../../src/core/system-contract-info.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAYjD;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAe;IACnD,IAAI,IAAwB,CAAC;IAE7B,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,MAAM,EAAE,oCAAoC;YAC/C,IAAI,GAAG;gBACL,kBAAkB,EAAE,4CAAuD;gBAC3E,wBAAwB,EAAE,4CAAuD;gBACjF,yBAAyB,EAAE,4CAAuD;gBAClF,6BAA6B,EAAE,4CAAuD;aACvF,CAAC;YACF,MAAM;QAER,KAAK,GAAG,EAAE,0BAA0B;YAClC,IAAI,GAAG;gBACL,kBAAkB,EAAE,4CAAuD;gBAC3E,wBAAwB,EAAE,4CAAuD;gBACjF,yBAAyB,EAAE,4CAAuD;gBAClF,6BAA6B,EAAE,4CAAuD;aACvF,CAAC;YACF,MAAM;QAER,KAAK,GAAG,EAAE,0BAA0B;YAClC,IAAI,GAAG;gBACL,kBAAkB,EAAE,4CAAuD;gBAC3E,wBAAwB,EAAE,4CAAuD;gBACjF,yBAAyB,EAAE,4CAAuD;gBAClF,6BAA6B,EAAE,4CAAuD;aACvF,CAAC;YACF,MAAM;QAER;YACE,MAAM,IAAI,QAAQ,CAAC,EAAE,IAAI,EAAE,YAAY,CAAC,gBAAgB,EAAE,OAAO,EAAE,iDAAiD,OAAO,CAAC,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;IAChJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * A generic Time-To-Live (TTL) cache implementation.
3
+ * Caches data for a specified duration before automatically refreshing it.
4
+ *
5
+ * @template T - The type of data to be cached
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const cache = new TTLCache<string[]>(5 * 60 * 1000); // 5 minutes TTL
10
+ * const data = await cache.get(async () => {
11
+ * return await fetchDataFromSource();
12
+ * });
13
+ * ```
14
+ */
15
+ export declare class TTLCache<T> {
16
+ /** Cached data, null if no data is cached or cache has been cleared */
17
+ private data;
18
+ /** Timestamp (in milliseconds) when the cache was last updated */
19
+ private timestamp;
20
+ /** Time-To-Live duration in milliseconds */
21
+ private readonly ttl;
22
+ /**
23
+ * Creates a new TTL cache instance.
24
+ *
25
+ * @param ttlMs - Time-To-Live in milliseconds. Defaults to 24 hours.
26
+ */
27
+ constructor(ttlMs?: number);
28
+ /**
29
+ * Retrieves cached data if it's still valid (within TTL), otherwise fetches fresh data.
30
+ *
31
+ * @param fetchFn - Async function that fetches fresh data when cache expires
32
+ * @param forceRefresh - If true, bypasses cache and forces a fresh fetch
33
+ * @returns The cached or freshly fetched data
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * // Normal usage - returns cached data if valid
38
+ * const result = await cache.get(() => fetchUserData());
39
+ *
40
+ * // Force refresh - bypasses cache
41
+ * const freshResult = await cache.get(() => fetchUserData(), true);
42
+ * ```
43
+ */
44
+ get(fetchFn: () => Promise<T>, forceRefresh?: boolean): Promise<T>;
45
+ /**
46
+ * Clears the cache, forcing the next `get()` call to fetch fresh data.
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * cache.clear(); // Next get() will fetch fresh data
51
+ * ```
52
+ */
53
+ clear(): void;
54
+ /**
55
+ * Checks if the cache has valid (non-expired) data.
56
+ *
57
+ * @returns True if cache contains valid data within TTL, false otherwise
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * if (cache.isValid()) {
62
+ * // Cache hit - use cached data
63
+ * } else {
64
+ * // Cache miss - need to fetch
65
+ * }
66
+ * ```
67
+ */
68
+ isValid(): boolean;
69
+ /**
70
+ * Gets the timestamp when the cache was last updated.
71
+ *
72
+ * @returns The timestamp in milliseconds, or 0 if cache is empty
73
+ */
74
+ getTimestamp(): number;
75
+ /**
76
+ * Gets the remaining time until cache expiration.
77
+ *
78
+ * @returns Milliseconds until cache expires, 0 if already expired or empty
79
+ */
80
+ getRemainingTTL(): number;
81
+ }
@@ -0,0 +1,113 @@
1
+ import { logger } from "./logger.js";
2
+ /** Default TTL (Time-To-Live) for cache entries: 24 hours in milliseconds */
3
+ const DEFAULT_TTL_CACHE_MS = 24 * 60 * 60 * 1000;
4
+ /**
5
+ * A generic Time-To-Live (TTL) cache implementation.
6
+ * Caches data for a specified duration before automatically refreshing it.
7
+ *
8
+ * @template T - The type of data to be cached
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const cache = new TTLCache<string[]>(5 * 60 * 1000); // 5 minutes TTL
13
+ * const data = await cache.get(async () => {
14
+ * return await fetchDataFromSource();
15
+ * });
16
+ * ```
17
+ */
18
+ export class TTLCache {
19
+ /** Cached data, null if no data is cached or cache has been cleared */
20
+ data = null;
21
+ /** Timestamp (in milliseconds) when the cache was last updated */
22
+ timestamp = 0;
23
+ /** Time-To-Live duration in milliseconds */
24
+ ttl;
25
+ /**
26
+ * Creates a new TTL cache instance.
27
+ *
28
+ * @param ttlMs - Time-To-Live in milliseconds. Defaults to 24 hours.
29
+ */
30
+ constructor(ttlMs = DEFAULT_TTL_CACHE_MS) {
31
+ this.ttl = ttlMs;
32
+ }
33
+ /**
34
+ * Retrieves cached data if it's still valid (within TTL), otherwise fetches fresh data.
35
+ *
36
+ * @param fetchFn - Async function that fetches fresh data when cache expires
37
+ * @param forceRefresh - If true, bypasses cache and forces a fresh fetch
38
+ * @returns The cached or freshly fetched data
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * // Normal usage - returns cached data if valid
43
+ * const result = await cache.get(() => fetchUserData());
44
+ *
45
+ * // Force refresh - bypasses cache
46
+ * const freshResult = await cache.get(() => fetchUserData(), true);
47
+ * ```
48
+ */
49
+ async get(fetchFn, forceRefresh = false) {
50
+ const now = Date.now();
51
+ // Check if cache is valid: not force refreshed, data exists, and within TTL
52
+ if (!forceRefresh && this.data !== null && (now - this.timestamp) < this.ttl) {
53
+ logger.debug("[TTLCache.get] Use cached:", this.data, this.timestamp);
54
+ return this.data;
55
+ }
56
+ // Cache expired or force refresh requested - fetch fresh data
57
+ this.data = await fetchFn();
58
+ this.timestamp = now;
59
+ logger.debug("[TTLCache.get] New fetched:", this.data, this.timestamp);
60
+ return this.data;
61
+ }
62
+ /**
63
+ * Clears the cache, forcing the next `get()` call to fetch fresh data.
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * cache.clear(); // Next get() will fetch fresh data
68
+ * ```
69
+ */
70
+ clear() {
71
+ this.data = null;
72
+ this.timestamp = 0;
73
+ }
74
+ /**
75
+ * Checks if the cache has valid (non-expired) data.
76
+ *
77
+ * @returns True if cache contains valid data within TTL, false otherwise
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * if (cache.isValid()) {
82
+ * // Cache hit - use cached data
83
+ * } else {
84
+ * // Cache miss - need to fetch
85
+ * }
86
+ * ```
87
+ */
88
+ isValid() {
89
+ const now = Date.now();
90
+ return this.data !== null && (now - this.timestamp) < this.ttl;
91
+ }
92
+ /**
93
+ * Gets the timestamp when the cache was last updated.
94
+ *
95
+ * @returns The timestamp in milliseconds, or 0 if cache is empty
96
+ */
97
+ getTimestamp() {
98
+ return this.timestamp;
99
+ }
100
+ /**
101
+ * Gets the remaining time until cache expiration.
102
+ *
103
+ * @returns Milliseconds until cache expires, 0 if already expired or empty
104
+ */
105
+ getRemainingTTL() {
106
+ if (this.data === null)
107
+ return 0;
108
+ const now = Date.now();
109
+ const remaining = this.ttl - (now - this.timestamp);
110
+ return Math.max(0, remaining);
111
+ }
112
+ }
113
+ //# sourceMappingURL=ttl-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ttl-cache.js","sourceRoot":"","sources":["../../src/core/ttl-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aA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IACH,OAAO;QACL,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC;IACjE,CAAC;IAED;;;;OAIG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACH,eAAe;QACb,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI;YAAE,OAAO,CAAC,CAAC;QACjC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;QACpD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;IAChC,CAAC;CACF"}
@@ -0,0 +1,40 @@
1
+ import { ethers } from "ethers";
2
+ /**
3
+ * Parses and extracts human-readable error messages from contract revert data.
4
+ * Supports multiple ABIs and provides fallback error handling.
5
+ */
6
+ export declare class ErrorParser {
7
+ private interfaces;
8
+ /**
9
+ * Adds an ABI to the parser for error decoding.
10
+ * @param abi - An ethers Interface or ABI definition
11
+ * @returns The current instance for method chaining
12
+ */
13
+ addAbi(abi: ethers.Interface | ethers.InterfaceAbi): this;
14
+ /**
15
+ * Attempts to parse an error from hex-encoded revert data.
16
+ * @param errorData - The hex string of the revert data (e.g., from error.data)
17
+ * @returns Parsed error name and formatted arguments, or null if no match
18
+ */
19
+ parseError(errorData: string): {
20
+ name: string;
21
+ args: string;
22
+ } | null;
23
+ /**
24
+ * Extracts a human-readable error message from an error object.
25
+ * Tries to parse revert data first, then falls back to error properties.
26
+ * @param error - The error object from a failed transaction
27
+ * @returns A formatted error message string
28
+ */
29
+ getMessage(error: any): string;
30
+ /**
31
+ * Wraps an error handler that logs the original error and throws a formatted message.
32
+ * Useful as a catch callback in promise chains.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * contract.function().catch(errorParser.catch);
37
+ * ```
38
+ */
39
+ catch: (error: any) => never;
40
+ }
@@ -0,0 +1,83 @@
1
+ import { Interface } from "ethers";
2
+ import { logger } from "./logger.js";
3
+ import { FheErrorCode } from "./errors/error-codes.js";
4
+ import { FheError } from "./errors/fhe-error.js";
5
+ /**
6
+ * Parses and extracts human-readable error messages from contract revert data.
7
+ * Supports multiple ABIs and provides fallback error handling.
8
+ */
9
+ export class ErrorParser {
10
+ interfaces = [];
11
+ /**
12
+ * Adds an ABI to the parser for error decoding.
13
+ * @param abi - An ethers Interface or ABI definition
14
+ * @returns The current instance for method chaining
15
+ */
16
+ addAbi(abi) {
17
+ this.interfaces.push(abi instanceof Interface ? abi : new Interface(abi));
18
+ return this;
19
+ }
20
+ /**
21
+ * Attempts to parse an error from hex-encoded revert data.
22
+ * @param errorData - The hex string of the revert data (e.g., from error.data)
23
+ * @returns Parsed error name and formatted arguments, or null if no match
24
+ */
25
+ parseError(errorData) {
26
+ for (const iface of this.interfaces) {
27
+ try {
28
+ const parsed = iface.parseError(errorData);
29
+ if (parsed) {
30
+ // Format arguments for display: bigints as strings, others as JSON
31
+ const argsStr = Object.values(parsed.args)
32
+ .map((v) => (typeof v === "bigint" ? v.toString() : JSON.stringify(v)))
33
+ .join(", ");
34
+ return { name: parsed.name, args: argsStr };
35
+ }
36
+ }
37
+ catch {
38
+ // Ignore parsing errors and try the next interface
39
+ continue;
40
+ }
41
+ }
42
+ return null;
43
+ }
44
+ /**
45
+ * Extracts a human-readable error message from an error object.
46
+ * Tries to parse revert data first, then falls back to error properties.
47
+ * @param error - The error object from a failed transaction
48
+ * @returns A formatted error message string
49
+ */
50
+ getMessage(error) {
51
+ // Attempt to parse custom error from revert data
52
+ if (error?.data && error.data !== "0x") {
53
+ const parsed = this.parseError(error.data);
54
+ if (parsed) {
55
+ return `${parsed.name}(${parsed.args})`;
56
+ }
57
+ }
58
+ // Fallback to standard error properties
59
+ return error?.reason || error?.shortMessage || error?.message || "Transaction failed";
60
+ }
61
+ /**
62
+ * Wraps an error handler that logs the original error and throws a formatted message.
63
+ * Useful as a catch callback in promise chains.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * contract.function().catch(errorParser.catch);
68
+ * ```
69
+ */
70
+ catch = (error) => {
71
+ logger.error("Original error:", error);
72
+ const message = this.getMessage(error);
73
+ const hasRevertData = typeof error?.data === "string" && error.data !== "0x";
74
+ const parsed = hasRevertData ? this.parseError(error.data) : null;
75
+ throw new FheError({
76
+ code: hasRevertData ? FheErrorCode.TransactionReverted : FheErrorCode.ContractCallFailed,
77
+ message,
78
+ context: parsed ? { details: parsed } : undefined,
79
+ cause: error,
80
+ });
81
+ };
82
+ }
83
+ //# sourceMappingURL=tx-error-parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tx-error-parser.js","sourceRoot":"","sources":["../../src/core/tx-error-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD;;;GAGG;AACH,MAAM,OAAO,WAAW;IACd,UAAU,GAAgB,EAAE,CAAC;IAErC;;;;OAIG;IACH,MAAM,CAAC,GAA2C;QAChD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,YAAY,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;QAC1E,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,UAAU,CAAC,SAAiB;QAC1B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpC,IAAI,CAAC;gBAC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AI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACvC,MAAM,aAAa,GAAG,OAAO,KAAK,EAAE,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;QAC7E,MAAM,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAElE,MAAM,IAAI,QAAQ,CAAC;YACjB,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAC,CAAC,YAAY,CAAC,kBAAkB;YACxF,OAAO;YACP,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS;YACjD,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC,CAAC;CACH"}
@@ -0,0 +1,62 @@
1
+ export declare function logErrorAndThrow(message: string): void;
2
+ /**
3
+ * Sleep for the specified number of milliseconds
4
+ *
5
+ * @param ms - Number of milliseconds to sleep
6
+ * @returns Promise that resolves after the specified delay
7
+ */
8
+ export declare function sleepMs(ms: number): Promise<void>;
9
+ /**
10
+ * Gets environment variable value (Node.js only)
11
+ * Supports only Node.js (process.env) and falls back gracefully in browser
12
+ *
13
+ * @param key - Environment variable name
14
+ * @returns Value or undefined if not found
15
+ *
16
+ * @example
17
+ * const rpcUrl = getEnv('RPC_URL');
18
+ */
19
+ export declare function getEnv(key: string): string | undefined;
20
+ /**
21
+ * Gets required environment variable, throws if not found
22
+ *
23
+ * @param key - Environment variable name
24
+ * @returns Value
25
+ * @throws Error if environment variable is not set
26
+ *
27
+ * @example
28
+ * const rpcUrl = requireEnv('RPC_URL');
29
+ */
30
+ export declare function requireEnv(key: string): string;
31
+ /**
32
+ * Creates a lazy-loaded value that initializes only once on first access
33
+ *
34
+ * @param factory - Async function that produces the value
35
+ * @returns A function that returns a Promise resolving to the cached value
36
+ *
37
+ * @example
38
+ * const getData = lazy(async () => {
39
+ * const result = await fetchData();
40
+ * return result;
41
+ * });
42
+ *
43
+ * const data = await getData(); // First call executes factory
44
+ * const cached = await getData(); // Returns cached value
45
+ */
46
+ export declare function lazy<T>(factory: () => Promise<T>): () => Promise<T>;
47
+ /**
48
+ * Concatenates multiple Uint8Array instances into a single Uint8Array
49
+ * Uses Buffer.concat in Node.js for better performance, falls back to manual
50
+ * concatenation in browser environments
51
+ *
52
+ * @param inputs - Array of Uint8Array instances to concatenate
53
+ * @returns A new Uint8Array containing all input data concatenated
54
+ */
55
+ export declare function concatUint8Arrays(inputs: Uint8Array[]): Uint8Array;
56
+ /**
57
+ * Asserts that a given string is a valid URL.
58
+ * Throws an error if the URL is invalid.
59
+ * @param url - The URL string to validate
60
+ * @throws Error if the URL is invalid
61
+ */
62
+ export declare function assertIsValidUrl(url: string): void;
@@ -0,0 +1,143 @@
1
+ import { logger } from "./logger.js";
2
+ import { FheErrorCode } from "./errors/error-codes.js";
3
+ import { FheError } from "./errors/fhe-error.js";
4
+ export function logErrorAndThrow(message) {
5
+ logger.error(message);
6
+ throw new FheError({ code: FheErrorCode.Internal, message });
7
+ }
8
+ /**
9
+ * Sleep for the specified number of milliseconds
10
+ *
11
+ * @param ms - Number of milliseconds to sleep
12
+ * @returns Promise that resolves after the specified delay
13
+ */
14
+ export function sleepMs(ms) {
15
+ return new Promise((resolve) => setTimeout(resolve, ms));
16
+ }
17
+ /**
18
+ * Gets environment variable value (Node.js only)
19
+ * Supports only Node.js (process.env) and falls back gracefully in browser
20
+ *
21
+ * @param key - Environment variable name
22
+ * @returns Value or undefined if not found
23
+ *
24
+ * @example
25
+ * const rpcUrl = getEnv('RPC_URL');
26
+ */
27
+ export function getEnv(key) {
28
+ // Check if running in Node.js environment
29
+ if (typeof process !== 'undefined' && process.env) {
30
+ return process.env[key];
31
+ }
32
+ return undefined;
33
+ }
34
+ /**
35
+ * Gets required environment variable, throws if not found
36
+ *
37
+ * @param key - Environment variable name
38
+ * @returns Value
39
+ * @throws Error if environment variable is not set
40
+ *
41
+ * @example
42
+ * const rpcUrl = requireEnv('RPC_URL');
43
+ */
44
+ export function requireEnv(key) {
45
+ const value = getEnv(key);
46
+ if (!value) {
47
+ logger.error(`Required environment variable not set: ${key}`);
48
+ throw new FheError({ code: FheErrorCode.InvalidConfig, message: `Environment variable ${key} is required but not set` });
49
+ }
50
+ return value;
51
+ }
52
+ /**
53
+ * Creates a lazy-loaded value that initializes only once on first access
54
+ *
55
+ * @param factory - Async function that produces the value
56
+ * @returns A function that returns a Promise resolving to the cached value
57
+ *
58
+ * @example
59
+ * const getData = lazy(async () => {
60
+ * const result = await fetchData();
61
+ * return result;
62
+ * });
63
+ *
64
+ * const data = await getData(); // First call executes factory
65
+ * const cached = await getData(); // Returns cached value
66
+ */
67
+ export function lazy(factory) {
68
+ let hasValue = false;
69
+ let value = undefined;
70
+ let promise = null;
71
+ return async () => {
72
+ if (hasValue) {
73
+ logger.trace('Lazy value already resolved, returning cached');
74
+ return value;
75
+ }
76
+ if (promise !== null) {
77
+ logger.trace('Lazy value currently being resolved, waiting for existing promise');
78
+ return promise;
79
+ }
80
+ logger.debug('Lazy value not resolved, executing factory');
81
+ promise = factory().then(result => {
82
+ value = result;
83
+ hasValue = true;
84
+ promise = null;
85
+ logger.debug('Lazy value resolved successfully');
86
+ return result;
87
+ }).catch((error) => {
88
+ logger.error('Lazy value resolution failed:', error);
89
+ promise = null;
90
+ throw error;
91
+ });
92
+ return promise;
93
+ };
94
+ }
95
+ /**
96
+ * Concatenates multiple Uint8Array instances into a single Uint8Array
97
+ * Uses Buffer.concat in Node.js for better performance, falls back to manual
98
+ * concatenation in browser environments
99
+ *
100
+ * @param inputs - Array of Uint8Array instances to concatenate
101
+ * @returns A new Uint8Array containing all input data concatenated
102
+ */
103
+ export function concatUint8Arrays(inputs) {
104
+ if (inputs.length === 0) {
105
+ logger.trace('concatUint8Arrays called with empty array');
106
+ return new Uint8Array(0);
107
+ }
108
+ const isNode = typeof Buffer !== 'undefined' && typeof Buffer.concat === 'function';
109
+ // Node.js environment - use native Buffer.concat for performance
110
+ if (isNode) {
111
+ logger.trace(`Concatenating ${inputs.length} arrays using Buffer.concat (Node.js)`);
112
+ const buffers = inputs.map(arr => Buffer.from(arr));
113
+ const result = new Uint8Array(Buffer.concat(buffers));
114
+ logger.trace(`Concatenated ${inputs.length} arrays into ${result.length} bytes`);
115
+ return result;
116
+ }
117
+ // Browser environment - manual concatenation
118
+ logger.trace(`Concatenating ${inputs.length} arrays manually (browser)`);
119
+ const totalLength = inputs.reduce((sum, arr) => sum + arr.length, 0);
120
+ const result = new Uint8Array(totalLength);
121
+ let offset = 0;
122
+ for (const arr of inputs) {
123
+ result.set(arr, offset);
124
+ offset += arr.length;
125
+ }
126
+ logger.trace(`Concatenated ${inputs.length} arrays into ${result.length} bytes`);
127
+ return result;
128
+ }
129
+ /**
130
+ * Asserts that a given string is a valid URL.
131
+ * Throws an error if the URL is invalid.
132
+ * @param url - The URL string to validate
133
+ * @throws Error if the URL is invalid
134
+ */
135
+ export function assertIsValidUrl(url) {
136
+ try {
137
+ new URL(url);
138
+ }
139
+ catch (error) {
140
+ throw new FheError({ code: FheErrorCode.InvalidArgument, message: `Invalid URL: "${url}"`, cause: error });
141
+ }
142
+ }
143
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/core/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC9C,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACtB,MAAM,IAAI,QAAQ,CAAC,EAAE,IAAI,EAAE,YAAY,CAA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export type { Address, Bytes, Bytes32Hex, Bytes65Hex, Bytes65HexNo0x, BytesHex, BytesHexNo0x, EvenLen, Hex0x, HexNo0x, } from "./core/primitives.js";
4
+ export { FheTransformSDK } from "./sdk/fhetransform-sdk.js";
5
+ export type { FheTransformConfig } from "./sdk/fhetransform-sdk-b.js";
6
+ export { PermitService } from "./sdk/permit-service.js";
7
+ export type { GetPermitOption, GetPermitResult } from "./sdk/permit-service.js";
8
+ export { ConvertToken } from "./contract/convert-token.js";
9
+ export type { FinalizeUnshieldOptions, FinalizeUnshieldResult, ShieldOptions, ShieldResult, UnshieldAndFinalizeOptions, UnshieldOptions, UnshieldResult, } from "./contract/convert-token.js";
10
+ export { Token, TokenBase } from "./contract/token.js";
11
+ export type { TransferOptions, TransferResult } from "./contract/token.js";
12
+ export type { ErrorCallbacks, FinalizeUnshieldCallbacks, ShieldCallbacks, TransferCallbacks, UnshieldAndFinalizeCallbacks, UnshieldCallbacks, } from "./contract/callbacks.js";
13
+ export type { RawLog, TransactionReceipt, TransactionResult } from "./contract/transaction.js";
14
+ export type { EncryptOptions, EncryptParameters, EncryptPayload, EncryptPayloadItem, EncryptResult, } from "./jazz/encrypt.js";
15
+ export type { PublicDecryptOptions, PublicDecryptParameters, PublicDecryptPayload, PublicDecryptResult, } from "./jazz/public-decrypt.js";
16
+ export type { UserDecryptInput, UserDecryptOptions, UserDecryptParameters, UserDecryptPayload, UserDecryptResult, } from "./jazz/user-decrypt.js";
17
+ export type { JazzOnProgressArgs, JazzProcessOptions } from "./jazz/types/common.js";
18
+ export type { SignedDecryptionPermit } from "./jazz/permit.js";
19
+ export { FheTransformSDKEvents } from "./core/event.js";
20
+ export type { FheTransformSDKEvent, FheTransformSDKEventListener, FheTransformSDKEventType, } from "./core/event.js";
21
+ export { ADDRESS_ZERO, areEqualAddresses, assertChecksumAddress, ChecksumAddressError, isChecksumAddress, isValidAddress, isZeroAddress, toChecksumAddress, toChecksumAddresses, toChecksumAddressesFiltered, toChecksumAddressesSafe, } from "./core/address.js";
22
+ export type { ChecksumAddress } from "./core/address.js";
23
+ export { buildSetChainKeysArgs, CHAINS, getChainKey } from "./core/chain.js";
24
+ export type { ChainInfo } from "./core/chain.js";
25
+ export { getSystemContractInfo } from "./core/system-contract-info.js";
26
+ export type { SystemContractInfo } from "./core/system-contract-info.js";
27
+ export { getSignerAddressInfo } from "./core/signer-address-info.js";
28
+ export type { SignerAddressInfo } from "./core/signer-address-info.js";
29
+ export { estimateFheFee } from "./core/estimate.js";
30
+ export type { FheFeeDetails, FheFeeEstimate } from "./core/estimate.js";
31
+ export { setAxiosAuth } from "./core/auth.js";
32
+ export type { Auth, AuthApiKeyCookie, AuthApiKeyHeader, AuthBearerToken, AuthType } from "./core/auth.js";
33
+ export { ErrorParser } from "./core/tx-error-parser.js";
34
+ export { FheError } from "./core/errors/fhe-error.js";
35
+ export type { FheErrorOptions, FheErrorPayload, SanitizedCause } from "./core/errors/fhe-error.js";
36
+ export { FheErrorCode } from "./core/errors/error-codes.js";
37
+ export type { FheErrorCatalogEntry, FheErrorContext } from "./core/errors/error-catalog.js";
38
+ export { formatMessage, getErrorCatalogEntry } from "./core/errors/error-catalog.js";
39
+ export { getErrorCode, getErrorMessage, getErrorRetryPolicy, isFheError, toFheError, withFheError, } from "./core/errors/error-utils.js";
40
+ export type { ErrorRetryPolicy } from "./core/errors/error-utils.js";