@opendatalabs/vana-sdk 0.1.0-alpha.d6bebb0 → 0.1.0-alpha.d7fc764

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 (765) hide show
  1. package/README.md +98 -36
  2. package/dist/browser.cjs +29 -0
  3. package/dist/browser.cjs.map +1 -0
  4. package/dist/browser.d.cts +2 -0
  5. package/dist/browser.d.ts +2 -0
  6. package/dist/browser.js +5 -0
  7. package/dist/browser.js.map +1 -0
  8. package/dist/chains/definitions.cjs +92 -0
  9. package/dist/chains/definitions.cjs.map +1 -0
  10. package/dist/chains/definitions.d.cts +53 -0
  11. package/dist/chains/definitions.d.ts +53 -0
  12. package/dist/chains/definitions.js +64 -0
  13. package/dist/chains/definitions.js.map +1 -0
  14. package/dist/chains/index.cjs +37 -0
  15. package/dist/chains/index.cjs.map +1 -0
  16. package/dist/chains/index.d.cts +2 -0
  17. package/dist/chains/index.d.ts +2 -0
  18. package/dist/chains/index.js +15 -0
  19. package/dist/chains/index.js.map +1 -0
  20. package/dist/chains.browser.cjs +6 -65
  21. package/dist/chains.browser.cjs.map +1 -1
  22. package/dist/chains.browser.d.cts +2 -53
  23. package/dist/chains.browser.d.ts +2 -53
  24. package/dist/chains.browser.js +7 -57
  25. package/dist/chains.browser.js.map +1 -1
  26. package/dist/chains.cjs +6 -65
  27. package/dist/chains.cjs.map +1 -1
  28. package/dist/chains.d.cts +1 -1
  29. package/dist/chains.d.ts +1 -1
  30. package/dist/chains.js +7 -57
  31. package/dist/chains.js.map +1 -1
  32. package/dist/chains.node.cjs +6 -65
  33. package/dist/chains.node.cjs.map +1 -1
  34. package/dist/chains.node.d.cts +1 -1
  35. package/dist/chains.node.d.ts +1 -1
  36. package/dist/chains.node.js +7 -57
  37. package/dist/chains.node.js.map +1 -1
  38. package/dist/config/addresses.cjs +325 -0
  39. package/dist/config/addresses.cjs.map +1 -0
  40. package/dist/config/addresses.d.cts +380 -0
  41. package/dist/config/addresses.d.ts +380 -0
  42. package/dist/config/addresses.js +295 -0
  43. package/dist/config/addresses.js.map +1 -0
  44. package/dist/config/chains.cjs +93 -0
  45. package/dist/config/chains.cjs.map +1 -0
  46. package/dist/config/chains.d.cts +85 -0
  47. package/dist/config/chains.d.ts +85 -0
  48. package/dist/config/chains.js +67 -0
  49. package/dist/config/chains.js.map +1 -0
  50. package/dist/config/eventMappings.cjs +114 -0
  51. package/dist/config/eventMappings.cjs.map +1 -0
  52. package/dist/config/eventMappings.d.cts +108 -0
  53. package/dist/config/eventMappings.d.ts +108 -0
  54. package/dist/config/eventMappings.js +90 -0
  55. package/dist/config/eventMappings.js.map +1 -0
  56. package/dist/config/features.cjs +52 -0
  57. package/dist/config/features.cjs.map +1 -0
  58. package/dist/config/features.d.cts +64 -0
  59. package/dist/config/features.d.ts +64 -0
  60. package/dist/config/features.js +28 -0
  61. package/dist/config/features.js.map +1 -0
  62. package/dist/contracts/contractController.cjs +126 -0
  63. package/dist/contracts/contractController.cjs.map +1 -0
  64. package/dist/contracts/contractController.d.cts +96 -0
  65. package/dist/contracts/contractController.d.ts +96 -0
  66. package/dist/contracts/contractController.js +103 -0
  67. package/dist/contracts/contractController.js.map +1 -0
  68. package/dist/controllers/data.cjs +2239 -0
  69. package/dist/controllers/data.cjs.map +1 -0
  70. package/dist/controllers/data.d.cts +941 -0
  71. package/dist/controllers/data.d.ts +941 -0
  72. package/dist/controllers/data.js +2222 -0
  73. package/dist/controllers/data.js.map +1 -0
  74. package/dist/controllers/permissions.cjs +3726 -0
  75. package/dist/controllers/permissions.cjs.map +1 -0
  76. package/dist/controllers/permissions.d.cts +25 -0
  77. package/dist/controllers/permissions.d.ts +25 -0
  78. package/dist/controllers/permissions.js +3702 -0
  79. package/dist/controllers/permissions.js.map +1 -0
  80. package/dist/controllers/protocol.cjs +179 -0
  81. package/dist/controllers/protocol.cjs.map +1 -0
  82. package/dist/controllers/protocol.d.cts +167 -0
  83. package/dist/controllers/protocol.d.ts +167 -0
  84. package/dist/controllers/protocol.js +162 -0
  85. package/dist/controllers/protocol.js.map +1 -0
  86. package/dist/controllers/schemas.cjs +584 -0
  87. package/dist/controllers/schemas.cjs.map +1 -0
  88. package/dist/controllers/schemas.d.cts +272 -0
  89. package/dist/controllers/schemas.d.ts +272 -0
  90. package/dist/controllers/schemas.js +560 -0
  91. package/dist/controllers/schemas.js.map +1 -0
  92. package/dist/controllers/server.cjs +427 -0
  93. package/dist/controllers/server.cjs.map +1 -0
  94. package/dist/controllers/server.d.cts +243 -0
  95. package/dist/controllers/server.d.ts +243 -0
  96. package/dist/controllers/server.js +408 -0
  97. package/dist/controllers/server.js.map +1 -0
  98. package/dist/core/apiClient.cjs +325 -0
  99. package/dist/core/apiClient.cjs.map +1 -0
  100. package/dist/core/apiClient.d.cts +165 -0
  101. package/dist/core/apiClient.d.ts +165 -0
  102. package/dist/core/apiClient.js +309 -0
  103. package/dist/core/apiClient.js.map +1 -0
  104. package/dist/core/client.cjs +70 -0
  105. package/dist/core/client.cjs.map +1 -0
  106. package/dist/core/client.d.cts +92 -0
  107. package/dist/core/client.d.ts +92 -0
  108. package/dist/core/client.js +47 -0
  109. package/dist/core/client.js.map +1 -0
  110. package/dist/core/generics.cjs +388 -0
  111. package/dist/core/generics.cjs.map +1 -0
  112. package/dist/core/generics.d.cts +120 -0
  113. package/dist/core/generics.d.ts +120 -0
  114. package/dist/core/generics.js +366 -0
  115. package/dist/core/generics.js.map +1 -0
  116. package/dist/core.cjs +640 -0
  117. package/dist/core.cjs.map +1 -0
  118. package/dist/core.d.cts +466 -0
  119. package/dist/core.d.ts +466 -0
  120. package/dist/core.js +628 -0
  121. package/dist/core.js.map +1 -0
  122. package/dist/crypto/ecies/__tests__/test-vectors.cjs +102 -0
  123. package/dist/crypto/ecies/__tests__/test-vectors.cjs.map +1 -0
  124. package/dist/crypto/ecies/__tests__/test-vectors.d.cts +40 -0
  125. package/dist/crypto/ecies/__tests__/test-vectors.d.ts +40 -0
  126. package/dist/crypto/ecies/__tests__/test-vectors.js +77 -0
  127. package/dist/crypto/ecies/__tests__/test-vectors.js.map +1 -0
  128. package/dist/crypto/ecies/base.cjs +231 -0
  129. package/dist/crypto/ecies/base.cjs.map +1 -0
  130. package/dist/crypto/ecies/base.d.cts +143 -0
  131. package/dist/crypto/ecies/base.d.ts +143 -0
  132. package/dist/crypto/ecies/base.js +211 -0
  133. package/dist/crypto/ecies/base.js.map +1 -0
  134. package/dist/crypto/ecies/browser.cjs +164 -0
  135. package/dist/crypto/ecies/browser.cjs.map +1 -0
  136. package/dist/crypto/ecies/browser.d.cts +48 -0
  137. package/dist/crypto/ecies/browser.d.ts +48 -0
  138. package/dist/crypto/ecies/browser.js +130 -0
  139. package/dist/crypto/ecies/browser.js.map +1 -0
  140. package/dist/crypto/ecies/constants.cjs +131 -0
  141. package/dist/crypto/ecies/constants.cjs.map +1 -0
  142. package/dist/crypto/ecies/constants.d.cts +122 -0
  143. package/dist/crypto/ecies/constants.d.ts +122 -0
  144. package/dist/crypto/ecies/constants.js +101 -0
  145. package/dist/crypto/ecies/constants.js.map +1 -0
  146. package/dist/crypto/ecies/index.cjs +35 -0
  147. package/dist/crypto/ecies/index.cjs.map +1 -0
  148. package/dist/crypto/ecies/index.d.cts +1 -0
  149. package/dist/crypto/ecies/index.d.ts +1 -0
  150. package/dist/crypto/ecies/index.js +13 -0
  151. package/dist/crypto/ecies/index.js.map +1 -0
  152. package/dist/crypto/ecies/interface.cjs +88 -0
  153. package/dist/crypto/ecies/interface.cjs.map +1 -0
  154. package/dist/crypto/ecies/interface.d.cts +176 -0
  155. package/dist/crypto/ecies/interface.d.ts +176 -0
  156. package/dist/crypto/ecies/interface.js +61 -0
  157. package/dist/crypto/ecies/interface.js.map +1 -0
  158. package/dist/crypto/ecies/node.cjs +166 -0
  159. package/dist/crypto/ecies/node.cjs.map +1 -0
  160. package/dist/crypto/ecies/node.d.cts +50 -0
  161. package/dist/crypto/ecies/node.d.ts +50 -0
  162. package/dist/crypto/ecies/node.js +144 -0
  163. package/dist/crypto/ecies/node.js.map +1 -0
  164. package/dist/crypto/ecies/utils.cjs +91 -0
  165. package/dist/crypto/ecies/utils.cjs.map +1 -0
  166. package/dist/crypto/ecies/utils.d.cts +67 -0
  167. package/dist/crypto/ecies/utils.d.ts +67 -0
  168. package/dist/crypto/ecies/utils.js +60 -0
  169. package/dist/crypto/ecies/utils.js.map +1 -0
  170. package/dist/crypto/services/WalletKeyEncryptionService.cjs +128 -0
  171. package/dist/crypto/services/WalletKeyEncryptionService.cjs.map +1 -0
  172. package/dist/crypto/services/WalletKeyEncryptionService.d.cts +92 -0
  173. package/dist/crypto/services/WalletKeyEncryptionService.d.ts +92 -0
  174. package/dist/crypto/services/WalletKeyEncryptionService.js +112 -0
  175. package/dist/crypto/services/WalletKeyEncryptionService.js.map +1 -0
  176. package/dist/diagnostics.cjs +37 -0
  177. package/dist/diagnostics.cjs.map +1 -0
  178. package/dist/diagnostics.d.cts +26 -0
  179. package/dist/diagnostics.d.ts +26 -0
  180. package/dist/diagnostics.js +13 -0
  181. package/dist/diagnostics.js.map +1 -0
  182. package/dist/errors.cjs +141 -0
  183. package/dist/errors.cjs.map +1 -0
  184. package/dist/errors.d.cts +350 -0
  185. package/dist/errors.d.ts +350 -0
  186. package/dist/errors.js +108 -0
  187. package/dist/errors.js.map +1 -0
  188. package/dist/generated/abi/ComputeEngineImplementation.cjs +1313 -0
  189. package/dist/generated/abi/ComputeEngineImplementation.cjs.map +1 -0
  190. package/dist/generated/abi/ComputeEngineImplementation.d.cts +996 -0
  191. package/dist/generated/abi/ComputeEngineImplementation.d.ts +996 -0
  192. package/dist/generated/abi/ComputeEngineImplementation.js +1289 -0
  193. package/dist/generated/abi/ComputeEngineImplementation.js.map +1 -0
  194. package/dist/generated/abi/ComputeInstructionRegistryImplementation.cjs +734 -0
  195. package/dist/generated/abi/ComputeInstructionRegistryImplementation.cjs.map +1 -0
  196. package/dist/generated/abi/ComputeInstructionRegistryImplementation.d.cts +545 -0
  197. package/dist/generated/abi/ComputeInstructionRegistryImplementation.d.ts +545 -0
  198. package/dist/generated/abi/ComputeInstructionRegistryImplementation.js +710 -0
  199. package/dist/generated/abi/ComputeInstructionRegistryImplementation.js.map +1 -0
  200. package/dist/generated/abi/DATFactoryImplementation.cjs +882 -0
  201. package/dist/generated/abi/DATFactoryImplementation.cjs.map +1 -0
  202. package/dist/generated/abi/DATFactoryImplementation.d.cts +661 -0
  203. package/dist/generated/abi/DATFactoryImplementation.d.ts +661 -0
  204. package/dist/generated/abi/DATFactoryImplementation.js +858 -0
  205. package/dist/generated/abi/DATFactoryImplementation.js.map +1 -0
  206. package/dist/generated/abi/DATImplementation.cjs +934 -0
  207. package/dist/generated/abi/DATImplementation.cjs.map +1 -0
  208. package/dist/generated/abi/DATImplementation.d.cts +693 -0
  209. package/dist/generated/abi/DATImplementation.d.ts +693 -0
  210. package/dist/generated/abi/DATImplementation.js +910 -0
  211. package/dist/generated/abi/DATImplementation.js.map +1 -0
  212. package/dist/generated/abi/DATPausableImplementation.cjs +1523 -0
  213. package/dist/generated/abi/DATPausableImplementation.cjs.map +1 -0
  214. package/dist/generated/abi/DATPausableImplementation.d.cts +1145 -0
  215. package/dist/generated/abi/DATPausableImplementation.d.ts +1145 -0
  216. package/dist/generated/abi/DATPausableImplementation.js +1499 -0
  217. package/dist/generated/abi/DATPausableImplementation.js.map +1 -0
  218. package/dist/generated/abi/DATVotesImplementation.cjs +1460 -0
  219. package/dist/generated/abi/DATVotesImplementation.cjs.map +1 -0
  220. package/dist/generated/abi/DATVotesImplementation.d.cts +1095 -0
  221. package/dist/generated/abi/DATVotesImplementation.d.ts +1095 -0
  222. package/dist/generated/abi/DATVotesImplementation.js +1436 -0
  223. package/dist/generated/abi/DATVotesImplementation.js.map +1 -0
  224. package/dist/generated/abi/DLPPerformanceImplementation.cjs +1160 -0
  225. package/dist/generated/abi/DLPPerformanceImplementation.cjs.map +1 -0
  226. package/dist/generated/abi/DLPPerformanceImplementation.d.cts +883 -0
  227. package/dist/generated/abi/DLPPerformanceImplementation.d.ts +883 -0
  228. package/dist/generated/abi/DLPPerformanceImplementation.js +1136 -0
  229. package/dist/generated/abi/DLPPerformanceImplementation.js.map +1 -0
  230. package/dist/generated/abi/DLPRegistryImplementation.cjs +1469 -0
  231. package/dist/generated/abi/DLPRegistryImplementation.cjs.map +1 -0
  232. package/dist/generated/abi/DLPRegistryImplementation.d.cts +1123 -0
  233. package/dist/generated/abi/DLPRegistryImplementation.d.ts +1123 -0
  234. package/dist/generated/abi/DLPRegistryImplementation.js +1445 -0
  235. package/dist/generated/abi/DLPRegistryImplementation.js.map +1 -0
  236. package/dist/generated/abi/DLPRegistryTreasuryImplementation.cjs +612 -0
  237. package/dist/generated/abi/DLPRegistryTreasuryImplementation.cjs.map +1 -0
  238. package/dist/generated/abi/DLPRegistryTreasuryImplementation.d.cts +452 -0
  239. package/dist/generated/abi/DLPRegistryTreasuryImplementation.d.ts +452 -0
  240. package/dist/generated/abi/DLPRegistryTreasuryImplementation.js +588 -0
  241. package/dist/generated/abi/DLPRegistryTreasuryImplementation.js.map +1 -0
  242. package/dist/generated/abi/DLPRewardDeployerImplementation.cjs +948 -0
  243. package/dist/generated/abi/DLPRewardDeployerImplementation.cjs.map +1 -0
  244. package/dist/generated/abi/DLPRewardDeployerImplementation.d.cts +714 -0
  245. package/dist/generated/abi/DLPRewardDeployerImplementation.d.ts +714 -0
  246. package/dist/generated/abi/DLPRewardDeployerImplementation.js +924 -0
  247. package/dist/generated/abi/DLPRewardDeployerImplementation.js.map +1 -0
  248. package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.cjs +612 -0
  249. package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.cjs.map +1 -0
  250. package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.d.cts +452 -0
  251. package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.d.ts +452 -0
  252. package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.js +588 -0
  253. package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.js.map +1 -0
  254. package/dist/generated/abi/DLPRewardSwapImplementation.cjs +939 -0
  255. package/dist/generated/abi/DLPRewardSwapImplementation.cjs.map +1 -0
  256. package/dist/generated/abi/DLPRewardSwapImplementation.d.cts +706 -0
  257. package/dist/generated/abi/DLPRewardSwapImplementation.d.ts +706 -0
  258. package/dist/generated/abi/DLPRewardSwapImplementation.js +915 -0
  259. package/dist/generated/abi/DLPRewardSwapImplementation.js.map +1 -0
  260. package/dist/generated/abi/DLPRootImplementation.cjs +1644 -0
  261. package/dist/generated/abi/DLPRootImplementation.cjs.map +1 -0
  262. package/dist/generated/abi/DLPRootImplementation.d.cts +1248 -0
  263. package/dist/generated/abi/DLPRootImplementation.d.ts +1248 -0
  264. package/dist/generated/abi/DLPRootImplementation.js +1620 -0
  265. package/dist/generated/abi/DLPRootImplementation.js.map +1 -0
  266. package/dist/generated/abi/DLPTreasuryImplementation.cjs +612 -0
  267. package/dist/generated/abi/DLPTreasuryImplementation.cjs.map +1 -0
  268. package/dist/generated/abi/DLPTreasuryImplementation.d.cts +452 -0
  269. package/dist/generated/abi/DLPTreasuryImplementation.d.ts +452 -0
  270. package/dist/generated/abi/DLPTreasuryImplementation.js +588 -0
  271. package/dist/generated/abi/DLPTreasuryImplementation.js.map +1 -0
  272. package/dist/generated/abi/DataLiquidityPoolImplementation.cjs +985 -0
  273. package/dist/generated/abi/DataLiquidityPoolImplementation.cjs.map +1 -0
  274. package/dist/generated/abi/DataLiquidityPoolImplementation.d.cts +737 -0
  275. package/dist/generated/abi/DataLiquidityPoolImplementation.d.ts +737 -0
  276. package/dist/generated/abi/DataLiquidityPoolImplementation.js +961 -0
  277. package/dist/generated/abi/DataLiquidityPoolImplementation.js.map +1 -0
  278. package/dist/generated/abi/DataPortabilityGranteesImplementation.cjs +888 -0
  279. package/dist/generated/abi/DataPortabilityGranteesImplementation.cjs.map +1 -0
  280. package/dist/generated/abi/DataPortabilityGranteesImplementation.d.cts +661 -0
  281. package/dist/generated/abi/DataPortabilityGranteesImplementation.d.ts +661 -0
  282. package/dist/generated/abi/DataPortabilityGranteesImplementation.js +864 -0
  283. package/dist/generated/abi/DataPortabilityGranteesImplementation.js.map +1 -0
  284. package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs +1317 -0
  285. package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs.map +1 -0
  286. package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.cts +989 -0
  287. package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.ts +989 -0
  288. package/dist/generated/abi/DataPortabilityPermissionsImplementation.js +1293 -0
  289. package/dist/generated/abi/DataPortabilityPermissionsImplementation.js.map +1 -0
  290. package/dist/generated/abi/DataPortabilityServersImplementation.cjs +1438 -0
  291. package/dist/generated/abi/DataPortabilityServersImplementation.cjs.map +1 -0
  292. package/dist/generated/abi/DataPortabilityServersImplementation.d.cts +1086 -0
  293. package/dist/generated/abi/DataPortabilityServersImplementation.d.ts +1086 -0
  294. package/dist/generated/abi/DataPortabilityServersImplementation.js +1414 -0
  295. package/dist/generated/abi/DataPortabilityServersImplementation.js.map +1 -0
  296. package/dist/generated/abi/DataRefinerRegistryImplementation.cjs +984 -0
  297. package/dist/generated/abi/DataRefinerRegistryImplementation.cjs.map +1 -0
  298. package/dist/generated/abi/DataRefinerRegistryImplementation.d.cts +737 -0
  299. package/dist/generated/abi/DataRefinerRegistryImplementation.d.ts +737 -0
  300. package/dist/generated/abi/DataRefinerRegistryImplementation.js +960 -0
  301. package/dist/generated/abi/DataRefinerRegistryImplementation.js.map +1 -0
  302. package/dist/generated/abi/DataRegistryImplementation.cjs +1328 -0
  303. package/dist/generated/abi/DataRegistryImplementation.cjs.map +1 -0
  304. package/dist/generated/abi/DataRegistryImplementation.d.cts +1004 -0
  305. package/dist/generated/abi/DataRegistryImplementation.d.ts +1004 -0
  306. package/dist/generated/abi/DataRegistryImplementation.js +1304 -0
  307. package/dist/generated/abi/DataRegistryImplementation.js.map +1 -0
  308. package/dist/generated/abi/QueryEngineImplementation.cjs +1319 -0
  309. package/dist/generated/abi/QueryEngineImplementation.cjs.map +1 -0
  310. package/dist/generated/abi/QueryEngineImplementation.d.cts +1001 -0
  311. package/dist/generated/abi/QueryEngineImplementation.d.ts +1001 -0
  312. package/dist/generated/abi/QueryEngineImplementation.js +1295 -0
  313. package/dist/generated/abi/QueryEngineImplementation.js.map +1 -0
  314. package/dist/generated/abi/SwapHelperImplementation.cjs +1019 -0
  315. package/dist/generated/abi/SwapHelperImplementation.cjs.map +1 -0
  316. package/dist/generated/abi/SwapHelperImplementation.d.cts +764 -0
  317. package/dist/generated/abi/SwapHelperImplementation.d.ts +764 -0
  318. package/dist/generated/abi/SwapHelperImplementation.js +995 -0
  319. package/dist/generated/abi/SwapHelperImplementation.js.map +1 -0
  320. package/dist/generated/abi/TeePoolDedicatedGpuImplementation.cjs +936 -0
  321. package/dist/generated/abi/TeePoolDedicatedGpuImplementation.cjs.map +1 -0
  322. package/dist/generated/abi/TeePoolDedicatedGpuImplementation.d.cts +701 -0
  323. package/dist/generated/abi/TeePoolDedicatedGpuImplementation.d.ts +701 -0
  324. package/dist/generated/abi/TeePoolDedicatedGpuImplementation.js +912 -0
  325. package/dist/generated/abi/TeePoolDedicatedGpuImplementation.js.map +1 -0
  326. package/dist/generated/abi/TeePoolDedicatedStandardImplementation.cjs +936 -0
  327. package/dist/generated/abi/TeePoolDedicatedStandardImplementation.cjs.map +1 -0
  328. package/dist/generated/abi/TeePoolDedicatedStandardImplementation.d.cts +701 -0
  329. package/dist/generated/abi/TeePoolDedicatedStandardImplementation.d.ts +701 -0
  330. package/dist/generated/abi/TeePoolDedicatedStandardImplementation.js +912 -0
  331. package/dist/generated/abi/TeePoolDedicatedStandardImplementation.js.map +1 -0
  332. package/dist/generated/abi/TeePoolEphemeralStandardImplementation.cjs +936 -0
  333. package/dist/generated/abi/TeePoolEphemeralStandardImplementation.cjs.map +1 -0
  334. package/dist/generated/abi/TeePoolEphemeralStandardImplementation.d.cts +701 -0
  335. package/dist/generated/abi/TeePoolEphemeralStandardImplementation.d.ts +701 -0
  336. package/dist/generated/abi/TeePoolEphemeralStandardImplementation.js +912 -0
  337. package/dist/generated/abi/TeePoolEphemeralStandardImplementation.js.map +1 -0
  338. package/dist/generated/abi/TeePoolImplementation.cjs +1313 -0
  339. package/dist/generated/abi/TeePoolImplementation.cjs.map +1 -0
  340. package/dist/generated/abi/TeePoolImplementation.d.cts +993 -0
  341. package/dist/generated/abi/TeePoolImplementation.d.ts +993 -0
  342. package/dist/generated/abi/TeePoolImplementation.js +1289 -0
  343. package/dist/generated/abi/TeePoolImplementation.js.map +1 -0
  344. package/dist/generated/abi/TeePoolPersistentGpuImplementation.cjs +936 -0
  345. package/dist/generated/abi/TeePoolPersistentGpuImplementation.cjs.map +1 -0
  346. package/dist/generated/abi/TeePoolPersistentGpuImplementation.d.cts +701 -0
  347. package/dist/generated/abi/TeePoolPersistentGpuImplementation.d.ts +701 -0
  348. package/dist/generated/abi/TeePoolPersistentGpuImplementation.js +912 -0
  349. package/dist/generated/abi/TeePoolPersistentGpuImplementation.js.map +1 -0
  350. package/dist/generated/abi/TeePoolPersistentStandardImplementation.cjs +936 -0
  351. package/dist/generated/abi/TeePoolPersistentStandardImplementation.cjs.map +1 -0
  352. package/dist/generated/abi/TeePoolPersistentStandardImplementation.d.cts +701 -0
  353. package/dist/generated/abi/TeePoolPersistentStandardImplementation.d.ts +701 -0
  354. package/dist/generated/abi/TeePoolPersistentStandardImplementation.js +912 -0
  355. package/dist/generated/abi/TeePoolPersistentStandardImplementation.js.map +1 -0
  356. package/dist/generated/abi/TeePoolPhalaImplementation.cjs +1313 -0
  357. package/dist/generated/abi/TeePoolPhalaImplementation.cjs.map +1 -0
  358. package/dist/generated/abi/TeePoolPhalaImplementation.d.cts +993 -0
  359. package/dist/generated/abi/TeePoolPhalaImplementation.d.ts +993 -0
  360. package/dist/generated/abi/TeePoolPhalaImplementation.js +1289 -0
  361. package/dist/generated/abi/TeePoolPhalaImplementation.js.map +1 -0
  362. package/dist/generated/abi/VanaEpochImplementation.cjs +1188 -0
  363. package/dist/generated/abi/VanaEpochImplementation.cjs.map +1 -0
  364. package/dist/generated/abi/VanaEpochImplementation.d.cts +900 -0
  365. package/dist/generated/abi/VanaEpochImplementation.d.ts +900 -0
  366. package/dist/generated/abi/VanaEpochImplementation.js +1164 -0
  367. package/dist/generated/abi/VanaEpochImplementation.js.map +1 -0
  368. package/dist/generated/abi/VanaPoolEntityImplementation.cjs +1234 -0
  369. package/dist/generated/abi/VanaPoolEntityImplementation.cjs.map +1 -0
  370. package/dist/generated/abi/VanaPoolEntityImplementation.d.cts +934 -0
  371. package/dist/generated/abi/VanaPoolEntityImplementation.d.ts +934 -0
  372. package/dist/generated/abi/VanaPoolEntityImplementation.js +1210 -0
  373. package/dist/generated/abi/VanaPoolEntityImplementation.js.map +1 -0
  374. package/dist/generated/abi/VanaPoolStakingImplementation.cjs +921 -0
  375. package/dist/generated/abi/VanaPoolStakingImplementation.cjs.map +1 -0
  376. package/dist/generated/abi/VanaPoolStakingImplementation.d.cts +693 -0
  377. package/dist/generated/abi/VanaPoolStakingImplementation.d.ts +693 -0
  378. package/dist/generated/abi/VanaPoolStakingImplementation.js +897 -0
  379. package/dist/generated/abi/VanaPoolStakingImplementation.js.map +1 -0
  380. package/dist/generated/abi/VanaPoolTreasuryImplementation.cjs +538 -0
  381. package/dist/generated/abi/VanaPoolTreasuryImplementation.cjs.map +1 -0
  382. package/dist/generated/abi/VanaPoolTreasuryImplementation.d.cts +394 -0
  383. package/dist/generated/abi/VanaPoolTreasuryImplementation.d.ts +394 -0
  384. package/dist/generated/abi/VanaPoolTreasuryImplementation.js +514 -0
  385. package/dist/generated/abi/VanaPoolTreasuryImplementation.js.map +1 -0
  386. package/dist/generated/abi/index.cjs +135 -0
  387. package/dist/generated/abi/index.cjs.map +1 -0
  388. package/dist/generated/abi/index.d.cts +26516 -0
  389. package/dist/generated/abi/index.d.ts +26516 -0
  390. package/dist/generated/abi/index.js +99 -0
  391. package/dist/generated/abi/index.js.map +1 -0
  392. package/dist/generated/server/server-exports.cjs +23 -0
  393. package/dist/generated/server/server-exports.cjs.map +1 -0
  394. package/dist/generated/server/server-exports.d.cts +21 -0
  395. package/dist/generated/server/server-exports.d.ts +21 -0
  396. package/dist/generated/server/server-exports.js +2 -0
  397. package/dist/generated/server/server-exports.js.map +1 -0
  398. package/dist/generated/server/server.cjs +17 -0
  399. package/dist/generated/server/server.cjs.map +1 -0
  400. package/dist/generated/server/server.d.cts +512 -0
  401. package/dist/generated/server/server.d.ts +512 -0
  402. package/dist/generated/server/server.js +1 -0
  403. package/dist/generated/server/server.js.map +1 -0
  404. package/dist/generated/subgraph.cjs +675 -0
  405. package/dist/generated/subgraph.cjs.map +1 -0
  406. package/dist/generated/subgraph.d.cts +5981 -0
  407. package/dist/generated/subgraph.d.ts +5981 -0
  408. package/dist/generated/subgraph.js +644 -0
  409. package/dist/generated/subgraph.js.map +1 -0
  410. package/dist/index.browser.cjs +151 -0
  411. package/dist/index.browser.cjs.map +1 -0
  412. package/dist/index.browser.d.cts +177 -0
  413. package/dist/index.browser.d.ts +67 -33072
  414. package/dist/index.browser.js +64 -41112
  415. package/dist/index.browser.js.map +1 -1
  416. package/dist/index.cjs +3 -0
  417. package/dist/index.cjs.map +1 -0
  418. package/dist/index.d.ts +2 -0
  419. package/dist/index.js +2 -0
  420. package/dist/index.js.map +1 -0
  421. package/dist/index.node.cjs +87 -41558
  422. package/dist/index.node.cjs.map +1 -1
  423. package/dist/index.node.d.cts +63 -33314
  424. package/dist/index.node.d.ts +63 -33314
  425. package/dist/index.node.js +68 -41448
  426. package/dist/index.node.js.map +1 -1
  427. package/dist/node.cjs +29 -0
  428. package/dist/node.cjs.map +1 -0
  429. package/dist/node.d.cts +2 -0
  430. package/dist/node.d.ts +2 -0
  431. package/dist/node.js +5 -0
  432. package/dist/node.js.map +1 -0
  433. package/dist/permissions-DNKPu_G0.d.cts +1666 -0
  434. package/dist/permissions-eo8YeLGf.d.ts +1666 -0
  435. package/dist/platform/browser-only.cjs +37 -0
  436. package/dist/platform/browser-only.cjs.map +1 -0
  437. package/dist/platform/browser-only.d.cts +25 -0
  438. package/dist/platform/browser-only.d.ts +25 -0
  439. package/dist/platform/browser-only.js +12 -0
  440. package/dist/platform/browser-only.js.map +1 -0
  441. package/dist/platform/browser-safe.cjs +57 -0
  442. package/dist/platform/browser-safe.cjs.map +1 -0
  443. package/dist/platform/browser-safe.d.cts +32 -0
  444. package/dist/platform/browser-safe.d.ts +32 -0
  445. package/dist/platform/browser-safe.js +31 -0
  446. package/dist/platform/browser-safe.js.map +1 -0
  447. package/dist/platform/browser.cjs +329 -0
  448. package/dist/platform/browser.cjs.map +1 -0
  449. package/dist/platform/browser.d.cts +74 -0
  450. package/dist/platform/browser.d.ts +74 -0
  451. package/dist/platform/browser.js +304 -0
  452. package/dist/platform/browser.js.map +1 -0
  453. package/dist/platform/index.cjs +50 -0
  454. package/dist/platform/index.cjs.map +1 -0
  455. package/dist/platform/index.d.cts +5 -0
  456. package/dist/platform/index.d.ts +5 -0
  457. package/dist/platform/index.js +27 -0
  458. package/dist/platform/index.js.map +1 -0
  459. package/dist/platform/interface.cjs +17 -0
  460. package/dist/platform/interface.cjs.map +1 -0
  461. package/dist/platform/interface.d.cts +218 -0
  462. package/dist/platform/interface.d.ts +218 -0
  463. package/dist/platform/interface.js +1 -0
  464. package/dist/platform/interface.js.map +1 -0
  465. package/dist/platform/node.cjs +351 -0
  466. package/dist/platform/node.cjs.map +1 -0
  467. package/dist/platform/node.d.cts +27 -0
  468. package/dist/platform/node.d.ts +27 -0
  469. package/dist/platform/node.js +327 -0
  470. package/dist/platform/node.js.map +1 -0
  471. package/dist/platform/shared/error-utils.cjs +43 -0
  472. package/dist/platform/shared/error-utils.cjs.map +1 -0
  473. package/dist/platform/shared/error-utils.d.cts +25 -0
  474. package/dist/platform/shared/error-utils.d.ts +25 -0
  475. package/dist/platform/shared/error-utils.js +18 -0
  476. package/dist/platform/shared/error-utils.js.map +1 -0
  477. package/dist/platform/shared/pgp-utils.cjs +55 -0
  478. package/dist/platform/shared/pgp-utils.cjs.map +1 -0
  479. package/dist/platform/shared/pgp-utils.d.cts +61 -0
  480. package/dist/platform/shared/pgp-utils.d.ts +61 -0
  481. package/dist/platform/shared/pgp-utils.js +29 -0
  482. package/dist/platform/shared/pgp-utils.js.map +1 -0
  483. package/dist/platform/shared/stream-utils.cjs +49 -0
  484. package/dist/platform/shared/stream-utils.cjs.map +1 -0
  485. package/dist/platform/shared/stream-utils.d.cts +16 -0
  486. package/dist/platform/shared/stream-utils.d.ts +16 -0
  487. package/dist/platform/shared/stream-utils.js +25 -0
  488. package/dist/platform/shared/stream-utils.js.map +1 -0
  489. package/dist/platform/utils.cjs +114 -0
  490. package/dist/platform/utils.cjs.map +1 -0
  491. package/dist/platform/utils.d.cts +53 -0
  492. package/dist/platform/utils.d.ts +53 -0
  493. package/dist/platform/utils.js +76 -0
  494. package/dist/platform/utils.js.map +1 -0
  495. package/dist/platform.browser.cjs +41 -0
  496. package/dist/platform.browser.cjs.map +1 -0
  497. package/dist/platform.browser.d.cts +4 -0
  498. package/dist/platform.browser.d.ts +4 -259
  499. package/dist/platform.browser.js +10 -309
  500. package/dist/platform.browser.js.map +1 -1
  501. package/dist/platform.cjs +14 -623
  502. package/dist/platform.cjs.map +1 -1
  503. package/dist/platform.d.cts +5 -1
  504. package/dist/platform.d.ts +5 -1
  505. package/dist/platform.js +14 -609
  506. package/dist/platform.js.map +1 -1
  507. package/dist/platform.node.cjs +14 -623
  508. package/dist/platform.node.cjs.map +1 -1
  509. package/dist/platform.node.d.cts +5 -299
  510. package/dist/platform.node.d.ts +5 -299
  511. package/dist/platform.node.js +14 -609
  512. package/dist/platform.node.js.map +1 -1
  513. package/dist/server/handler.cjs +101 -0
  514. package/dist/server/handler.cjs.map +1 -0
  515. package/dist/server/handler.d.cts +282 -0
  516. package/dist/server/handler.d.ts +282 -0
  517. package/dist/server/handler.js +77 -0
  518. package/dist/server/handler.js.map +1 -0
  519. package/dist/storage/index.cjs +44 -0
  520. package/dist/storage/index.cjs.map +1 -0
  521. package/dist/storage/index.d.cts +10 -0
  522. package/dist/storage/index.d.ts +10 -0
  523. package/dist/storage/index.js +15 -0
  524. package/dist/storage/index.js.map +1 -0
  525. package/dist/storage/manager.cjs +189 -0
  526. package/dist/storage/manager.cjs.map +1 -0
  527. package/dist/storage/manager.d.cts +150 -0
  528. package/dist/storage/manager.d.ts +150 -0
  529. package/dist/storage/manager.js +172 -0
  530. package/dist/storage/manager.js.map +1 -0
  531. package/dist/storage/providers/callback-storage.cjs +177 -0
  532. package/dist/storage/providers/callback-storage.cjs.map +1 -0
  533. package/dist/storage/providers/callback-storage.d.cts +100 -0
  534. package/dist/storage/providers/callback-storage.d.ts +100 -0
  535. package/dist/storage/providers/callback-storage.js +155 -0
  536. package/dist/storage/providers/callback-storage.js.map +1 -0
  537. package/dist/storage/providers/google-drive.cjs +516 -0
  538. package/dist/storage/providers/google-drive.cjs.map +1 -0
  539. package/dist/storage/providers/google-drive.d.cts +156 -0
  540. package/dist/storage/providers/google-drive.d.ts +156 -0
  541. package/dist/storage/providers/google-drive.js +497 -0
  542. package/dist/storage/providers/google-drive.js.map +1 -0
  543. package/dist/storage/providers/ipfs.cjs +283 -0
  544. package/dist/storage/providers/ipfs.cjs.map +1 -0
  545. package/dist/storage/providers/ipfs.d.cts +163 -0
  546. package/dist/storage/providers/ipfs.d.ts +163 -0
  547. package/dist/storage/providers/ipfs.js +264 -0
  548. package/dist/storage/providers/ipfs.js.map +1 -0
  549. package/dist/storage/providers/pinata.cjs +339 -0
  550. package/dist/storage/providers/pinata.cjs.map +1 -0
  551. package/dist/storage/providers/pinata.d.cts +173 -0
  552. package/dist/storage/providers/pinata.d.ts +173 -0
  553. package/dist/storage/providers/pinata.js +320 -0
  554. package/dist/storage/providers/pinata.js.map +1 -0
  555. package/dist/types/chains.cjs +36 -0
  556. package/dist/types/chains.cjs.map +1 -0
  557. package/dist/types/chains.d.cts +34 -0
  558. package/dist/types/chains.d.ts +34 -0
  559. package/dist/types/chains.js +11 -0
  560. package/dist/types/chains.js.map +1 -0
  561. package/dist/types/config.cjs +41 -0
  562. package/dist/types/config.cjs.map +1 -0
  563. package/dist/types/config.d.cts +726 -0
  564. package/dist/types/config.d.ts +726 -0
  565. package/dist/types/config.js +15 -0
  566. package/dist/types/config.js.map +1 -0
  567. package/dist/types/contracts.cjs +17 -0
  568. package/dist/types/contracts.cjs.map +1 -0
  569. package/dist/types/contracts.d.cts +68 -0
  570. package/dist/types/contracts.d.ts +68 -0
  571. package/dist/types/contracts.js +1 -0
  572. package/dist/types/contracts.js.map +1 -0
  573. package/dist/types/data.cjs +17 -0
  574. package/dist/types/data.cjs.map +1 -0
  575. package/dist/types/data.d.cts +694 -0
  576. package/dist/types/data.d.ts +694 -0
  577. package/dist/types/data.js +1 -0
  578. package/dist/types/data.js.map +1 -0
  579. package/dist/types/eccrypto-js.d.cjs +2 -0
  580. package/dist/types/eccrypto-js.d.cjs.map +1 -0
  581. package/dist/types/eccrypto-js.d.d.cts +13 -0
  582. package/dist/types/eccrypto-js.d.d.ts +13 -0
  583. package/dist/types/eccrypto-js.d.js +1 -0
  584. package/dist/types/eccrypto-js.d.js.map +1 -0
  585. package/dist/types/external-apis.cjs +61 -0
  586. package/dist/types/external-apis.cjs.map +1 -0
  587. package/dist/types/external-apis.d.cts +186 -0
  588. package/dist/types/external-apis.d.ts +186 -0
  589. package/dist/types/external-apis.js +34 -0
  590. package/dist/types/external-apis.js.map +1 -0
  591. package/dist/types/generics.cjs +17 -0
  592. package/dist/types/generics.cjs.map +1 -0
  593. package/dist/types/generics.d.cts +450 -0
  594. package/dist/types/generics.d.ts +450 -0
  595. package/dist/types/generics.js +1 -0
  596. package/dist/types/generics.js.map +1 -0
  597. package/dist/types/index.cjs +64 -0
  598. package/dist/types/index.cjs.map +1 -0
  599. package/dist/types/index.d.cts +34 -0
  600. package/dist/types/index.d.ts +34 -0
  601. package/dist/types/index.js +35 -0
  602. package/dist/types/index.js.map +1 -0
  603. package/dist/types/operations.cjs +65 -0
  604. package/dist/types/operations.cjs.map +1 -0
  605. package/dist/types/operations.d.cts +108 -0
  606. package/dist/types/operations.d.ts +108 -0
  607. package/dist/types/operations.js +37 -0
  608. package/dist/types/operations.js.map +1 -0
  609. package/dist/types/permissions.cjs +17 -0
  610. package/dist/types/permissions.cjs.map +1 -0
  611. package/dist/types/permissions.d.cts +957 -0
  612. package/dist/types/permissions.d.ts +957 -0
  613. package/dist/types/permissions.js +1 -0
  614. package/dist/types/permissions.js.map +1 -0
  615. package/dist/types/personal.cjs +17 -0
  616. package/dist/types/personal.cjs.map +1 -0
  617. package/dist/types/personal.d.cts +40 -0
  618. package/dist/types/personal.d.ts +40 -0
  619. package/dist/types/personal.js +1 -0
  620. package/dist/types/personal.js.map +1 -0
  621. package/dist/types/relayer.cjs +17 -0
  622. package/dist/types/relayer.cjs.map +1 -0
  623. package/dist/types/relayer.d.cts +284 -0
  624. package/dist/types/relayer.d.ts +284 -0
  625. package/dist/types/relayer.js +1 -0
  626. package/dist/types/relayer.js.map +1 -0
  627. package/dist/types/storage.cjs +39 -0
  628. package/dist/types/storage.cjs.map +1 -0
  629. package/dist/types/storage.d.cts +131 -0
  630. package/dist/types/storage.d.ts +131 -0
  631. package/dist/types/storage.js +18 -0
  632. package/dist/types/storage.js.map +1 -0
  633. package/dist/types/transactionResults.cjs +17 -0
  634. package/dist/types/transactionResults.cjs.map +1 -0
  635. package/dist/types/transactionResults.d.cts +25 -0
  636. package/dist/types/transactionResults.d.ts +25 -0
  637. package/dist/types/transactionResults.js +1 -0
  638. package/dist/types/transactionResults.js.map +1 -0
  639. package/dist/types/utils.cjs +17 -0
  640. package/dist/types/utils.cjs.map +1 -0
  641. package/dist/types/utils.d.cts +819 -0
  642. package/dist/types/utils.d.ts +819 -0
  643. package/dist/types/utils.js +1 -0
  644. package/dist/types/utils.js.map +1 -0
  645. package/dist/types.cjs +23 -0
  646. package/dist/types.cjs.map +1 -0
  647. package/dist/types.d.cts +66 -0
  648. package/dist/types.d.ts +66 -0
  649. package/dist/types.js +2 -0
  650. package/dist/types.js.map +1 -0
  651. package/dist/utils/blockchain/registry.cjs +81 -0
  652. package/dist/utils/blockchain/registry.cjs.map +1 -0
  653. package/dist/utils/blockchain/registry.d.cts +34 -0
  654. package/dist/utils/blockchain/registry.d.ts +34 -0
  655. package/dist/utils/blockchain/registry.js +56 -0
  656. package/dist/utils/blockchain/registry.js.map +1 -0
  657. package/dist/utils/crypto-utils.cjs +120 -0
  658. package/dist/utils/crypto-utils.cjs.map +1 -0
  659. package/dist/utils/crypto-utils.d.cts +118 -0
  660. package/dist/utils/crypto-utils.d.ts +118 -0
  661. package/dist/utils/crypto-utils.js +87 -0
  662. package/dist/utils/crypto-utils.js.map +1 -0
  663. package/dist/utils/download.cjs +69 -0
  664. package/dist/utils/download.cjs.map +1 -0
  665. package/dist/utils/download.d.cts +41 -0
  666. package/dist/utils/download.d.ts +41 -0
  667. package/dist/utils/download.js +45 -0
  668. package/dist/utils/download.js.map +1 -0
  669. package/dist/utils/encoding.cjs +66 -0
  670. package/dist/utils/encoding.cjs.map +1 -0
  671. package/dist/utils/encoding.d.cts +54 -0
  672. package/dist/utils/encoding.d.ts +54 -0
  673. package/dist/utils/encoding.js +39 -0
  674. package/dist/utils/encoding.js.map +1 -0
  675. package/dist/utils/encryption.cjs +170 -0
  676. package/dist/utils/encryption.cjs.map +1 -0
  677. package/dist/utils/encryption.d.cts +275 -0
  678. package/dist/utils/encryption.d.ts +275 -0
  679. package/dist/utils/encryption.js +136 -0
  680. package/dist/utils/encryption.js.map +1 -0
  681. package/dist/utils/eventParsing.cjs +111 -0
  682. package/dist/utils/eventParsing.cjs.map +1 -0
  683. package/dist/utils/eventParsing.d.cts +60 -0
  684. package/dist/utils/eventParsing.d.ts +60 -0
  685. package/dist/utils/eventParsing.js +86 -0
  686. package/dist/utils/eventParsing.js.map +1 -0
  687. package/dist/utils/formatters.cjs +53 -0
  688. package/dist/utils/formatters.cjs.map +1 -0
  689. package/dist/utils/formatters.d.cts +120 -0
  690. package/dist/utils/formatters.d.ts +120 -0
  691. package/dist/utils/formatters.js +26 -0
  692. package/dist/utils/formatters.js.map +1 -0
  693. package/dist/utils/grantFiles.cjs +175 -0
  694. package/dist/utils/grantFiles.cjs.map +1 -0
  695. package/dist/utils/grantFiles.d.cts +186 -0
  696. package/dist/utils/grantFiles.d.ts +186 -0
  697. package/dist/utils/grantFiles.js +137 -0
  698. package/dist/utils/grantFiles.js.map +1 -0
  699. package/dist/utils/grantValidation.cjs +243 -0
  700. package/dist/utils/grantValidation.cjs.map +1 -0
  701. package/dist/utils/grantValidation.d.cts +150 -0
  702. package/dist/utils/grantValidation.d.ts +150 -0
  703. package/dist/utils/grantValidation.js +201 -0
  704. package/dist/utils/grantValidation.js.map +1 -0
  705. package/dist/utils/grants.cjs +108 -0
  706. package/dist/utils/grants.cjs.map +1 -0
  707. package/dist/utils/grants.d.cts +70 -0
  708. package/dist/utils/grants.d.ts +70 -0
  709. package/dist/utils/grants.js +82 -0
  710. package/dist/utils/grants.js.map +1 -0
  711. package/dist/utils/ipfs.cjs +130 -0
  712. package/dist/utils/ipfs.cjs.map +1 -0
  713. package/dist/utils/ipfs.d.cts +90 -0
  714. package/dist/utils/ipfs.d.ts +90 -0
  715. package/dist/utils/ipfs.js +99 -0
  716. package/dist/utils/ipfs.js.map +1 -0
  717. package/dist/utils/lazy-import.cjs +40 -0
  718. package/dist/utils/lazy-import.cjs.map +1 -0
  719. package/dist/utils/lazy-import.d.cts +20 -0
  720. package/dist/utils/lazy-import.d.ts +20 -0
  721. package/dist/utils/lazy-import.js +16 -0
  722. package/dist/utils/lazy-import.js.map +1 -0
  723. package/dist/utils/multicall.cjs +231 -0
  724. package/dist/utils/multicall.cjs.map +1 -0
  725. package/dist/utils/multicall.d.cts +129 -0
  726. package/dist/utils/multicall.d.ts +129 -0
  727. package/dist/utils/multicall.js +206 -0
  728. package/dist/utils/multicall.js.map +1 -0
  729. package/dist/utils/schemaValidation.cjs +258 -0
  730. package/dist/utils/schemaValidation.cjs.map +1 -0
  731. package/dist/utils/schemaValidation.d.cts +172 -0
  732. package/dist/utils/schemaValidation.d.ts +172 -0
  733. package/dist/utils/schemaValidation.js +222 -0
  734. package/dist/utils/schemaValidation.js.map +1 -0
  735. package/dist/utils/signatureCache.cjs +187 -0
  736. package/dist/utils/signatureCache.cjs.map +1 -0
  737. package/dist/utils/signatureCache.d.cts +134 -0
  738. package/dist/utils/signatureCache.d.ts +134 -0
  739. package/dist/utils/signatureCache.js +165 -0
  740. package/dist/utils/signatureCache.js.map +1 -0
  741. package/dist/utils/signatureFormatter.cjs +45 -0
  742. package/dist/utils/signatureFormatter.cjs.map +1 -0
  743. package/dist/utils/signatureFormatter.d.cts +39 -0
  744. package/dist/utils/signatureFormatter.d.ts +39 -0
  745. package/dist/utils/signatureFormatter.js +21 -0
  746. package/dist/utils/signatureFormatter.js.map +1 -0
  747. package/dist/utils/transactionParsing.cjs +84 -0
  748. package/dist/utils/transactionParsing.cjs.map +1 -0
  749. package/dist/utils/transactionParsing.d.cts +25 -0
  750. package/dist/utils/transactionParsing.d.ts +25 -0
  751. package/dist/utils/transactionParsing.js +62 -0
  752. package/dist/utils/transactionParsing.js.map +1 -0
  753. package/dist/utils/typedDataConverter.cjs +43 -0
  754. package/dist/utils/typedDataConverter.cjs.map +1 -0
  755. package/dist/utils/typedDataConverter.d.cts +13 -0
  756. package/dist/utils/typedDataConverter.d.ts +13 -0
  757. package/dist/utils/typedDataConverter.js +19 -0
  758. package/dist/utils/typedDataConverter.js.map +1 -0
  759. package/dist/utils/urlResolver.cjs +55 -0
  760. package/dist/utils/urlResolver.cjs.map +1 -0
  761. package/dist/utils/urlResolver.d.cts +40 -0
  762. package/dist/utils/urlResolver.d.ts +40 -0
  763. package/dist/utils/urlResolver.js +30 -0
  764. package/dist/utils/urlResolver.js.map +1 -0
  765. package/package.json +54 -27
@@ -0,0 +1,2222 @@
1
+ import { getContract } from "viem";
2
+ import { getContractAddress } from "../config/addresses";
3
+ import { getAbi } from "../generated/abi";
4
+ import {
5
+ GetUserFilesDocument,
6
+ GetFileProofsDocument,
7
+ GetDlpDocument,
8
+ GetUserPermissionsDocument,
9
+ GetUserTrustedServersDocument
10
+ } from "../generated/subgraph";
11
+ import { print } from "graphql";
12
+ import {
13
+ generateEncryptionKey,
14
+ decryptBlobWithSignedKey,
15
+ DEFAULT_ENCRYPTION_SEED,
16
+ encryptBlobWithSignedKey,
17
+ encryptWithWalletPublicKey,
18
+ decryptWithWalletPrivateKey
19
+ } from "../utils/encryption";
20
+ import {
21
+ validateDataSchemaAgainstMetaSchema,
22
+ validateDataAgainstSchema,
23
+ fetchAndValidateSchema
24
+ } from "../utils/schemaValidation";
25
+ import { gasAwareMulticall } from "../utils/multicall";
26
+ class DataController {
27
+ constructor(context) {
28
+ this.context = context;
29
+ }
30
+ async upload(params) {
31
+ const {
32
+ content,
33
+ filename,
34
+ schemaId,
35
+ permissions = [],
36
+ encrypt = true,
37
+ providerName,
38
+ owner
39
+ } = params;
40
+ try {
41
+ let isValid = true;
42
+ let validationErrors = [];
43
+ if (schemaId !== void 0) {
44
+ try {
45
+ const { SchemaController } = await import("./schemas");
46
+ const schemaController = new SchemaController(this.context);
47
+ const schema = await schemaController.get(schemaId);
48
+ let parsedContent;
49
+ if (typeof content === "string") {
50
+ try {
51
+ parsedContent = JSON.parse(content);
52
+ } catch {
53
+ parsedContent = content;
54
+ }
55
+ } else {
56
+ parsedContent = content;
57
+ }
58
+ validateDataAgainstSchema(parsedContent, schema);
59
+ } catch (error) {
60
+ isValid = false;
61
+ validationErrors = [
62
+ error instanceof Error ? error.message : "Schema validation failed"
63
+ ];
64
+ }
65
+ }
66
+ const uploadResult = await this.uploadToStorage(
67
+ content,
68
+ filename,
69
+ encrypt,
70
+ providerName
71
+ );
72
+ const userAddress = owner || await this.getUserAddress();
73
+ let encryptedPermissions = [];
74
+ if (permissions.length > 0 && encrypt) {
75
+ const userEncryptionKey = await generateEncryptionKey(
76
+ this.context.walletClient,
77
+ this.context.platform,
78
+ DEFAULT_ENCRYPTION_SEED
79
+ );
80
+ encryptedPermissions = await Promise.all(
81
+ permissions.map(async (permission) => {
82
+ const encryptedKey = await encryptWithWalletPublicKey(
83
+ userEncryptionKey,
84
+ permission.publicKey,
85
+ this.context.platform
86
+ );
87
+ return {
88
+ account: permission.account,
89
+ key: encryptedKey
90
+ };
91
+ })
92
+ );
93
+ }
94
+ let result;
95
+ if (this.context.relayerCallbacks?.submitFileAdditionComplete) {
96
+ result = await this.context.relayerCallbacks.submitFileAdditionComplete(
97
+ {
98
+ url: uploadResult.url,
99
+ userAddress,
100
+ permissions: encryptedPermissions,
101
+ schemaId: schemaId || 0,
102
+ ownerAddress: owner
103
+ }
104
+ );
105
+ } else if (this.context.relayerCallbacks?.submitFileAddition) {
106
+ const needsComplexRegistration = schemaId !== void 0 || encryptedPermissions.length > 0;
107
+ if (needsComplexRegistration) {
108
+ throw new Error(
109
+ "The configured relay callback does not support schemas or permissions. Please update your relay server implementation to provide the `submitFileAdditionComplete` callback."
110
+ );
111
+ }
112
+ result = await this.context.relayerCallbacks.submitFileAddition(
113
+ uploadResult.url,
114
+ userAddress
115
+ );
116
+ } else {
117
+ result = await this.addFileWithPermissionsAndSchema(
118
+ uploadResult.url,
119
+ userAddress,
120
+ encryptedPermissions,
121
+ schemaId || 0
122
+ );
123
+ }
124
+ return {
125
+ fileId: result.fileId,
126
+ url: uploadResult.url,
127
+ transactionHash: result.transactionHash,
128
+ size: uploadResult.size,
129
+ isValid,
130
+ validationErrors: validationErrors.length > 0 ? validationErrors : void 0
131
+ };
132
+ } catch (error) {
133
+ throw new Error(
134
+ `Upload failed: ${error instanceof Error ? error.message : "Unknown error"}`
135
+ );
136
+ }
137
+ }
138
+ /**
139
+ * Decrypts a file owned by the user using their wallet signature.
140
+ *
141
+ * @remarks
142
+ * This is the high-level convenience method for decrypting user files, serving as the
143
+ * symmetrical counterpart to the `upload` method. It handles the complete decryption
144
+ * workflow including key generation, URL protocol detection, content fetching, and
145
+ * decryption.
146
+ *
147
+ * The method automatically:
148
+ * - Generates the decryption key from the user's wallet signature
149
+ * - Determines the appropriate fetch method based on the file URL protocol
150
+ * - Fetches the encrypted content from IPFS or standard HTTP URLs
151
+ * - Decrypts the content using the generated key
152
+ *
153
+ * For IPFS URLs, the method uses gateway fallback for improved reliability. For
154
+ * standard HTTP URLs, it uses a simple fetch. If you need custom authentication
155
+ * headers or specific gateway configurations, use the low-level primitives directly.
156
+ *
157
+ * @param file - The user file to decrypt (typically from getUserFiles)
158
+ * @param encryptionSeed - Optional custom encryption seed (defaults to Vana standard)
159
+ * @returns Promise resolving to the decrypted file content as a Blob
160
+ * @throws {Error} "No addresses available in wallet client" - When wallet is not connected
161
+ * @throws {Error} "Network error: Cannot access the file URL" - When file URL is inaccessible (CORS, server down)
162
+ * @throws {Error} "File not found: The encrypted file is no longer available" - When file returns 404
163
+ * @throws {Error} "Access denied" - When file returns 403 (no permission)
164
+ * @throws {Error} "File is empty or could not be retrieved" - When file has no content
165
+ * @throws {Error} "Invalid file format: This file doesn't appear to be encrypted with the Vana protocol" - When file is not properly encrypted
166
+ * @throws {Error} "Wrong encryption key" - When decryption fails due to incorrect key/seed
167
+ * @throws {Error} "Failed to decrypt file: {error}" - General decryption failures
168
+ * @example
169
+ * ```typescript
170
+ * // Basic file decryption
171
+ * const files = await vana.data.getUserFiles({ owner: userAddress });
172
+ * const decryptedBlob = await vana.data.decryptFile(files[0]);
173
+ *
174
+ * // Convert to text
175
+ * const text = await decryptedBlob.text();
176
+ * console.log('Decrypted content:', text);
177
+ *
178
+ * // Convert to JSON
179
+ * const json = JSON.parse(await decryptedBlob.text());
180
+ * console.log('Decrypted data:', json);
181
+ *
182
+ * // With custom encryption seed
183
+ * const decryptedBlob = await vana.data.decryptFile(
184
+ * files[0],
185
+ * "My custom encryption seed"
186
+ * );
187
+ *
188
+ * // Save to file (in Node.js)
189
+ * const buffer = await decryptedBlob.arrayBuffer();
190
+ * fs.writeFileSync('decrypted-file.txt', Buffer.from(buffer));
191
+ * ```
192
+ */
193
+ async decryptFile(file, encryptionSeed) {
194
+ try {
195
+ const encryptionKey = await generateEncryptionKey(
196
+ this.context.walletClient,
197
+ this.context.platform,
198
+ encryptionSeed || DEFAULT_ENCRYPTION_SEED
199
+ );
200
+ let encryptedBlob;
201
+ try {
202
+ if (file.url.startsWith("ipfs://")) {
203
+ encryptedBlob = await this.fetchFromIPFS(file.url);
204
+ } else {
205
+ encryptedBlob = await this.fetch(file.url);
206
+ }
207
+ } catch (fetchError) {
208
+ const errorMessage = fetchError instanceof Error ? fetchError.message : "Unknown error";
209
+ if (errorMessage.includes("Failed to fetch IPFS content") && errorMessage.includes("from all gateways")) {
210
+ throw new Error(
211
+ "Network error: Cannot access the file URL. The file may be stored on a server that's not accessible or has CORS restrictions."
212
+ );
213
+ } else if (errorMessage.includes("Empty response")) {
214
+ throw new Error("File is empty or could not be retrieved");
215
+ } else if (errorMessage.includes("Network error:") || errorMessage.includes("Failed to fetch")) {
216
+ throw new Error(
217
+ "Network error: Cannot access the file URL. The file may be stored on a server that's not accessible or has CORS restrictions."
218
+ );
219
+ } else if (errorMessage.includes("HTTP error!")) {
220
+ const statusMatch = errorMessage.match(/status: (\d+)/);
221
+ const status = statusMatch ? statusMatch[1] : "unknown";
222
+ if (status === "500") {
223
+ throw new Error(
224
+ "Network error: Cannot access the file URL. The file may be stored on a server that's not accessible or has CORS restrictions."
225
+ );
226
+ } else if (status === "403") {
227
+ throw new Error(
228
+ "Access denied. You may not have permission to access this file"
229
+ );
230
+ } else if (status === "404") {
231
+ throw new Error(
232
+ "File not found: The encrypted file is no longer available at the stored URL."
233
+ );
234
+ } else {
235
+ throw new Error(
236
+ "Network error: Cannot access the file URL. The file may be stored on a server that's not accessible or has CORS restrictions."
237
+ );
238
+ }
239
+ }
240
+ throw fetchError;
241
+ }
242
+ if (encryptedBlob.size === 0) {
243
+ throw new Error("File is empty or could not be retrieved");
244
+ }
245
+ let decryptedBlob;
246
+ try {
247
+ decryptedBlob = await decryptBlobWithSignedKey(
248
+ encryptedBlob,
249
+ encryptionKey,
250
+ this.context.platform
251
+ );
252
+ } catch (decryptError) {
253
+ const errorMessage = decryptError instanceof Error ? decryptError.message : "Unknown error";
254
+ if (errorMessage.includes("not a valid OpenPGP message")) {
255
+ throw new Error(
256
+ "Invalid file format: This file doesn't appear to be encrypted with the Vana protocol"
257
+ );
258
+ } else if (errorMessage.includes("Session key decryption failed")) {
259
+ throw new Error("Wrong encryption key");
260
+ } else if (errorMessage.includes("Error decrypting message")) {
261
+ throw new Error("Wrong encryption key");
262
+ } else if (errorMessage.includes("File not found")) {
263
+ throw new Error(
264
+ "File not found: The encrypted file is no longer available"
265
+ );
266
+ } else {
267
+ throw decryptError;
268
+ }
269
+ }
270
+ return decryptedBlob;
271
+ } catch (error) {
272
+ if (error instanceof Error && (error.message.includes("Network error:") || error.message.includes("Invalid file format:") || error.message.includes("Wrong encryption key") || error.message.includes("Access denied") || error.message.includes("File not found:") || error.message.includes("File is empty"))) {
273
+ throw error;
274
+ }
275
+ throw new Error(
276
+ `Failed to decrypt file: ${error instanceof Error ? error.message : "Unknown error"}`
277
+ );
278
+ }
279
+ }
280
+ /**
281
+ * Retrieves all data files owned by a specific user address.
282
+ *
283
+ * @remarks
284
+ * This method queries the Vana subgraph to find files directly owned by the user.
285
+ * It efficiently handles large datasets by using the File entity's owner field
286
+ * and returns complete file metadata without additional contract calls.
287
+ *
288
+ * **Deduplication Behavior:**
289
+ * The method automatically deduplicates files by ID, keeping only the latest version
290
+ * (highest timestamp) when duplicate file IDs are found. This handles cases where
291
+ * the subgraph may contain multiple entries for the same file due to re-indexing
292
+ * or blockchain reorganizations.
293
+ * @param params - The query parameters object
294
+ * @param params.owner - The wallet address of the file owner to query
295
+ * @param params.subgraphUrl - Optional subgraph URL to override the default endpoint
296
+ * @returns A Promise that resolves to an array of UserFile objects with metadata, sorted by latest timestamp first
297
+ * @throws {Error} When subgraphUrl is not provided and not configured - "subgraphUrl is required"
298
+ * @throws {Error} When subgraph request fails - "Subgraph request failed: {status} {statusText}"
299
+ * @throws {Error} When subgraph returns errors - "Subgraph errors: {error messages}"
300
+ * @throws {Error} When JSON parsing fails - "Failed to fetch user files from subgraph: {error}"
301
+ * @example
302
+ * ```typescript
303
+ * // Query files for a specific user
304
+ * const files = await vana.data.getUserFiles({
305
+ * owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
306
+ * });
307
+ *
308
+ * files.forEach(file => {
309
+ * console.log(`File ${file.id}: ${file.url} (Schema: ${file.schemaId})`);
310
+ * });
311
+ * ```
312
+ */
313
+ async getUserFiles(params) {
314
+ const { owner, subgraphUrl } = params;
315
+ const endpoint = subgraphUrl || this.context.subgraphUrl;
316
+ if (!endpoint) {
317
+ throw new Error(
318
+ "subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor."
319
+ );
320
+ }
321
+ try {
322
+ const response = await fetch(endpoint, {
323
+ method: "POST",
324
+ headers: {
325
+ "Content-Type": "application/json"
326
+ },
327
+ body: JSON.stringify({
328
+ query: print(GetUserFilesDocument),
329
+ variables: {
330
+ userId: owner.toLowerCase()
331
+ // Subgraph requires lowercase addresses
332
+ }
333
+ })
334
+ });
335
+ if (!response.ok) {
336
+ throw new Error(
337
+ `Subgraph request failed: ${response.status} ${response.statusText}`
338
+ );
339
+ }
340
+ const result = await response.json();
341
+ if (result.errors) {
342
+ throw new Error(
343
+ `Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
344
+ );
345
+ }
346
+ const user = result.data?.user;
347
+ if (!user || !user.files?.length) {
348
+ console.warn("No files found for user:", owner);
349
+ return [];
350
+ }
351
+ const fileMap = /* @__PURE__ */ new Map();
352
+ user.files.forEach((file) => {
353
+ const fileId = parseInt(file.id);
354
+ const userFile = {
355
+ id: fileId,
356
+ url: file.url,
357
+ ownerAddress: file.owner.id,
358
+ addedAtBlock: BigInt(file.addedAtBlock),
359
+ schemaId: parseInt(file.schemaId),
360
+ addedAtTimestamp: BigInt(file.addedAtTimestamp),
361
+ transactionHash: file.transactionHash
362
+ };
363
+ const existing = fileMap.get(fileId);
364
+ if (!existing || userFile.addedAtTimestamp && existing.addedAtTimestamp && userFile.addedAtTimestamp > existing.addedAtTimestamp) {
365
+ fileMap.set(fileId, userFile);
366
+ }
367
+ });
368
+ const userFiles = Array.from(fileMap.values()).sort(
369
+ (a, b) => Number((b.addedAtTimestamp || 0n) - (a.addedAtTimestamp || 0n))
370
+ );
371
+ if (userFiles.length > 0) {
372
+ try {
373
+ const fileIds = userFiles.map((f) => f.id);
374
+ let proofMap;
375
+ try {
376
+ proofMap = await this._fetchProofsFromSubgraph(fileIds, endpoint);
377
+ } catch (subgraphError) {
378
+ console.debug(
379
+ "Failed to fetch proofs from subgraph, trying chain:",
380
+ subgraphError
381
+ );
382
+ proofMap = await this._fetchProofsFromChain(fileIds);
383
+ }
384
+ for (const file of userFiles) {
385
+ const dlpIds = proofMap.get(file.id);
386
+ if (dlpIds && dlpIds.length > 0) {
387
+ file.dlpIds = dlpIds;
388
+ }
389
+ }
390
+ } catch (error) {
391
+ console.warn("Failed to fetch proof data for files:", error);
392
+ }
393
+ }
394
+ return userFiles;
395
+ } catch (error) {
396
+ console.error("Failed to fetch user files from subgraph:", error);
397
+ throw new Error(
398
+ `Failed to fetch user files from subgraph: ${error instanceof Error ? error.message : "Unknown error"}`
399
+ );
400
+ }
401
+ }
402
+ /**
403
+ * Fetches proof data for multiple files from the subgraph.
404
+ *
405
+ * @private
406
+ * @param fileIds - Array of file IDs to fetch proofs for
407
+ * @param subgraphUrl - The subgraph endpoint URL
408
+ * @returns Map of file IDs to their associated DLP IDs
409
+ */
410
+ async _fetchProofsFromSubgraph(fileIds, subgraphUrl) {
411
+ const response = await fetch(subgraphUrl, {
412
+ method: "POST",
413
+ headers: {
414
+ "Content-Type": "application/json"
415
+ },
416
+ body: JSON.stringify({
417
+ query: print(GetFileProofsDocument),
418
+ variables: {
419
+ fileIds: fileIds.map((id) => id.toString())
420
+ }
421
+ })
422
+ });
423
+ if (!response.ok) {
424
+ throw new Error(
425
+ `Subgraph request failed: ${response.status} ${response.statusText}`
426
+ );
427
+ }
428
+ const result = await response.json();
429
+ if (result.errors) {
430
+ throw new Error(
431
+ `Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
432
+ );
433
+ }
434
+ const proofMap = /* @__PURE__ */ new Map();
435
+ if (result.data?.dataRegistryProofs) {
436
+ for (const proof of result.data.dataRegistryProofs) {
437
+ if (proof.dlp?.id) {
438
+ const fileId = parseInt(proof.fileId);
439
+ const dlpId = parseInt(proof.dlp.id);
440
+ if (!proofMap.has(fileId)) {
441
+ proofMap.set(fileId, []);
442
+ }
443
+ const dlpIds = proofMap.get(fileId);
444
+ if (!dlpIds.includes(dlpId)) {
445
+ dlpIds.push(dlpId);
446
+ }
447
+ }
448
+ }
449
+ }
450
+ return proofMap;
451
+ }
452
+ /**
453
+ * Fetches proof data for multiple files from the blockchain.
454
+ * Falls back to this when subgraph is unavailable.
455
+ *
456
+ * @private
457
+ * @param fileIds - Array of file IDs to fetch proofs for
458
+ * @returns Map of file IDs to their associated DLP IDs
459
+ */
460
+ async _fetchProofsFromChain(fileIds) {
461
+ const chainId = this.context.walletClient.chain?.id;
462
+ if (!chainId) {
463
+ throw new Error("Chain ID not available");
464
+ }
465
+ const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
466
+ const dataRegistryAbi = getAbi("DataRegistry");
467
+ const proofMap = /* @__PURE__ */ new Map();
468
+ for (const fileId of fileIds) {
469
+ const dlpIds = [];
470
+ let proofIndex = 0;
471
+ let hasMoreProofs = true;
472
+ while (hasMoreProofs) {
473
+ try {
474
+ const proof = await this.context.publicClient.readContract({
475
+ address: dataRegistryAddress,
476
+ abi: dataRegistryAbi,
477
+ functionName: "fileProofs",
478
+ args: [BigInt(fileId), BigInt(proofIndex)]
479
+ });
480
+ if (proof?.data?.dlpId) {
481
+ const dlpId = Number(proof.data.dlpId);
482
+ if (!dlpIds.includes(dlpId)) {
483
+ dlpIds.push(dlpId);
484
+ }
485
+ }
486
+ proofIndex++;
487
+ } catch {
488
+ hasMoreProofs = false;
489
+ }
490
+ }
491
+ if (dlpIds.length > 0) {
492
+ proofMap.set(fileId, dlpIds);
493
+ }
494
+ }
495
+ return proofMap;
496
+ }
497
+ /**
498
+ * Retrieves information about a specific Data Liquidity Pool (DLP).
499
+ *
500
+ * @remarks
501
+ * DLPs are entities that process and verify data files in the Vana network.
502
+ * This method fetches DLP metadata including name, status, and performance rating.
503
+ * Uses subgraph first for efficiency, falls back to chain if unavailable.
504
+ *
505
+ * @param dlpId - The unique identifier of the DLP
506
+ * @param options - Optional parameters
507
+ * @param options.subgraphUrl - Custom subgraph URL to override default
508
+ * @returns Promise resolving to DLP information
509
+ * @throws {Error} When DLP cannot be found - "DLP not found: {dlpId}"
510
+ * @throws {Error} When query fails - "Failed to fetch DLP: {error}"
511
+ * @example
512
+ * ```typescript
513
+ * const dlp = await vana.data.getDLP(26);
514
+ * console.log(`DLP ${dlp.name}: ${dlp.status}`);
515
+ * ```
516
+ */
517
+ async getDLP(dlpId, options = {}) {
518
+ const subgraphUrl = options.subgraphUrl || this.context.subgraphUrl;
519
+ if (subgraphUrl) {
520
+ try {
521
+ const response = await fetch(subgraphUrl, {
522
+ method: "POST",
523
+ headers: {
524
+ "Content-Type": "application/json"
525
+ },
526
+ body: JSON.stringify({
527
+ query: print(GetDlpDocument),
528
+ variables: {
529
+ id: dlpId.toString()
530
+ }
531
+ })
532
+ });
533
+ if (!response.ok) {
534
+ throw new Error(
535
+ `Subgraph request failed: ${response.status} ${response.statusText}`
536
+ );
537
+ }
538
+ const result = await response.json();
539
+ if (result.errors) {
540
+ throw new Error(
541
+ `Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
542
+ );
543
+ }
544
+ if (!result.data?.dlp) {
545
+ throw new Error(`DLP not found: ${dlpId}`);
546
+ }
547
+ return {
548
+ id: parseInt(result.data.dlp.id),
549
+ name: result.data.dlp.name || "",
550
+ metadata: result.data.dlp.metadata || void 0,
551
+ status: result.data.dlp.status ? parseInt(result.data.dlp.status) : void 0,
552
+ address: result.data.dlp.address,
553
+ owner: result.data.dlp.owner
554
+ };
555
+ } catch (error) {
556
+ console.debug("Subgraph query failed, falling back to chain:", error);
557
+ }
558
+ }
559
+ try {
560
+ const chainId = this.context.walletClient.chain?.id;
561
+ if (!chainId) {
562
+ throw new Error("Chain ID not available");
563
+ }
564
+ const dlpRegistryAddress = getContractAddress(chainId, "DLPRegistry");
565
+ const dlpRegistryAbi = getAbi("DLPRegistry");
566
+ const dlpData = await this.context.publicClient.readContract({
567
+ address: dlpRegistryAddress,
568
+ abi: dlpRegistryAbi,
569
+ functionName: "dlps",
570
+ args: [BigInt(dlpId)]
571
+ });
572
+ if (!dlpData || !dlpData.name) {
573
+ throw new Error(`DLP not found: ${dlpId}`);
574
+ }
575
+ return {
576
+ id: dlpId,
577
+ name: dlpData.name,
578
+ metadata: dlpData.metadata,
579
+ status: dlpData.status,
580
+ address: dlpData.dlpAddress,
581
+ owner: dlpData.ownerAddress
582
+ };
583
+ } catch (error) {
584
+ throw new Error(
585
+ `Failed to fetch DLP: ${error instanceof Error ? error.message : "Unknown error"}`
586
+ );
587
+ }
588
+ }
589
+ /**
590
+ * Lists all Data Liquidity Pools (DLPs) with optional pagination.
591
+ *
592
+ * @remarks
593
+ * Fetches a paginated list of all DLPs registered in the network.
594
+ * Uses subgraph for efficient querying with fallback to chain multicall.
595
+ *
596
+ * @param options - Optional parameters for pagination and filtering
597
+ * @param options.limit - Maximum number of DLPs to return (default: 100)
598
+ * @param options.offset - Number of DLPs to skip (default: 0)
599
+ * @param options.subgraphUrl - Custom subgraph URL to override default
600
+ * @returns Promise resolving to array of DLP information
601
+ * @throws {Error} When query fails - "Failed to list DLPs: {error}"
602
+ * @example
603
+ * ```typescript
604
+ * // Get first 10 DLPs
605
+ * const dlps = await vana.data.listDLPs({ limit: 10 });
606
+ * dlps.forEach(dlp => console.log(`${dlp.id}: ${dlp.name}`));
607
+ *
608
+ * // Get next page
609
+ * const nextPage = await vana.data.listDLPs({ limit: 10, offset: 10 });
610
+ * ```
611
+ */
612
+ async listDLPs(options = {}) {
613
+ const { limit = 100, offset = 0 } = options;
614
+ const subgraphUrl = options.subgraphUrl || this.context.subgraphUrl;
615
+ if (subgraphUrl) {
616
+ try {
617
+ const query = `
618
+ query ListDLPs($first: Int!, $skip: Int!) {
619
+ dlps(first: $first, skip: $skip, orderBy: id) {
620
+ id
621
+ name
622
+ metadata
623
+ status
624
+ address
625
+ owner
626
+ }
627
+ }
628
+ `;
629
+ const response = await fetch(subgraphUrl, {
630
+ method: "POST",
631
+ headers: {
632
+ "Content-Type": "application/json"
633
+ },
634
+ body: JSON.stringify({
635
+ query,
636
+ variables: {
637
+ first: limit,
638
+ skip: offset
639
+ }
640
+ })
641
+ });
642
+ if (!response.ok) {
643
+ throw new Error(
644
+ `Subgraph request failed: ${response.status} ${response.statusText}`
645
+ );
646
+ }
647
+ const result = await response.json();
648
+ if (result.errors) {
649
+ throw new Error(
650
+ `Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
651
+ );
652
+ }
653
+ const dlps = result.data?.dlps || [];
654
+ return dlps.map((dlp) => ({
655
+ id: parseInt(dlp.id),
656
+ name: dlp.name || "",
657
+ metadata: dlp.metadata,
658
+ status: dlp.status ? parseInt(dlp.status) : void 0,
659
+ address: dlp.address,
660
+ owner: dlp.owner
661
+ }));
662
+ } catch (error) {
663
+ console.debug("Subgraph query failed, falling back to chain:", error);
664
+ }
665
+ }
666
+ try {
667
+ const chainId = this.context.walletClient.chain?.id;
668
+ if (!chainId) {
669
+ throw new Error("Chain ID not available");
670
+ }
671
+ const dlpRegistryAddress = getContractAddress(chainId, "DLPRegistry");
672
+ const dlpRegistryAbi = getAbi("DLPRegistry");
673
+ const dlpCount = await this.context.publicClient.readContract({
674
+ address: dlpRegistryAddress,
675
+ abi: dlpRegistryAbi,
676
+ functionName: "dlpsCount",
677
+ args: []
678
+ });
679
+ const totalCount = Number(dlpCount);
680
+ const start = offset;
681
+ const end = Math.min(start + limit, totalCount);
682
+ if (end <= start) {
683
+ return [];
684
+ }
685
+ const calls = [];
686
+ for (let i = start + 1; i <= end; i++) {
687
+ calls.push({
688
+ address: dlpRegistryAddress,
689
+ abi: dlpRegistryAbi,
690
+ functionName: "dlps",
691
+ args: [BigInt(i)]
692
+ });
693
+ }
694
+ const results = await gasAwareMulticall(this.context.publicClient, {
695
+ contracts: calls,
696
+ allowFailure: true,
697
+ batchSize: 50
698
+ });
699
+ const dlps = [];
700
+ for (let i = 0; i < results.length; i++) {
701
+ const result = results[i];
702
+ if (result.status === "success" && result.result) {
703
+ const dlpData = result.result;
704
+ if (dlpData.name) {
705
+ dlps.push({
706
+ id: start + i + 1,
707
+ name: dlpData.name,
708
+ metadata: dlpData.metadata,
709
+ status: dlpData.status,
710
+ address: dlpData.dlpAddress,
711
+ owner: dlpData.ownerAddress
712
+ });
713
+ }
714
+ }
715
+ }
716
+ return dlps;
717
+ } catch (error) {
718
+ throw new Error(
719
+ `Failed to list DLPs: ${error instanceof Error ? error.message : "Unknown error"}`
720
+ );
721
+ }
722
+ }
723
+ /**
724
+ * Retrieves a list of permissions granted by a user.
725
+ *
726
+ * This method supports automatic fallback between subgraph and RPC modes:
727
+ * - If subgraph URL is available, tries subgraph query first
728
+ * - Falls back to direct contract queries via RPC if subgraph fails
729
+ * - RPC mode uses gasAwareMulticall for efficient batch queries
730
+ *
731
+ * @param params - Object containing the user address and optional subgraph URL
732
+ * @param params.user - The wallet address of the user to query permissions for
733
+ * @param params.subgraphUrl - Optional subgraph URL to override the default
734
+ * @returns Promise resolving to an array of permission objects
735
+ * @throws Error if both subgraph and RPC queries fail
736
+ */
737
+ async getUserPermissions(params) {
738
+ const { user, subgraphUrl } = params;
739
+ const endpoint = subgraphUrl || this.context.subgraphUrl;
740
+ if (endpoint) {
741
+ try {
742
+ const permissions = await this._getUserPermissionsViaSubgraph({
743
+ user,
744
+ subgraphUrl: endpoint
745
+ });
746
+ return permissions;
747
+ } catch (error) {
748
+ console.warn("Subgraph query failed, falling back to RPC:", error);
749
+ }
750
+ }
751
+ return await this._getUserPermissionsViaRpc({ user });
752
+ }
753
+ /**
754
+ * Internal method: Query user permissions via subgraph
755
+ *
756
+ * @param params - Query parameters object
757
+ * @param params.user - The user address to query permissions for
758
+ * @param params.subgraphUrl - The subgraph URL endpoint to query
759
+ * @returns Promise resolving to an array of permission objects
760
+ */
761
+ async _getUserPermissionsViaSubgraph(params) {
762
+ const { user, subgraphUrl } = params;
763
+ try {
764
+ const response = await fetch(subgraphUrl, {
765
+ method: "POST",
766
+ headers: {
767
+ "Content-Type": "application/json"
768
+ },
769
+ body: JSON.stringify({
770
+ query: print(GetUserPermissionsDocument),
771
+ variables: {
772
+ userId: user.toLowerCase()
773
+ }
774
+ })
775
+ });
776
+ if (!response.ok) {
777
+ throw new Error(
778
+ `Subgraph request failed: ${response.status} ${response.statusText}`
779
+ );
780
+ }
781
+ const result = await response.json();
782
+ if (result.errors) {
783
+ throw new Error(
784
+ `Subgraph query errors: ${result.errors.map((e) => e.message).join(", ")}`
785
+ );
786
+ }
787
+ const userData = result.data?.user;
788
+ if (!userData || !userData.permissions?.length) {
789
+ return [];
790
+ }
791
+ return userData.permissions.map((permission) => ({
792
+ id: permission.id,
793
+ grant: permission.grant,
794
+ nonce: BigInt(permission.nonce),
795
+ signature: permission.signature,
796
+ addedAtBlock: BigInt(permission.addedAtBlock),
797
+ addedAtTimestamp: BigInt(permission.addedAtTimestamp),
798
+ transactionHash: permission.transactionHash,
799
+ user
800
+ })).sort((a, b) => Number(b.addedAtTimestamp - a.addedAtTimestamp));
801
+ } catch (error) {
802
+ console.error("Failed to query user permissions from subgraph:", error);
803
+ throw error;
804
+ }
805
+ }
806
+ /**
807
+ * Internal method: Query user permissions via direct RPC
808
+ *
809
+ * @param params - Query parameters object
810
+ * @param params.user - The user address to query permissions for
811
+ * @returns Promise resolving to an array of permission objects
812
+ */
813
+ async _getUserPermissionsViaRpc(params) {
814
+ const { user } = params;
815
+ try {
816
+ const chainId = this.context.walletClient.chain?.id;
817
+ if (!chainId) {
818
+ throw new Error("Chain ID not available");
819
+ }
820
+ const permissionsAddress = getContractAddress(
821
+ chainId,
822
+ "DataPortabilityPermissions"
823
+ );
824
+ const permissionsAbi = getAbi("DataPortabilityPermissions");
825
+ const totalCount = await this.context.publicClient.readContract({
826
+ address: permissionsAddress,
827
+ abi: permissionsAbi,
828
+ functionName: "userPermissionIdsLength",
829
+ args: [user]
830
+ });
831
+ const total = Number(totalCount);
832
+ if (total === 0) {
833
+ return [];
834
+ }
835
+ const permissionIdCalls = [];
836
+ for (let i = 0; i < total; i++) {
837
+ permissionIdCalls.push({
838
+ address: permissionsAddress,
839
+ abi: permissionsAbi,
840
+ functionName: "userPermissionIdsAt",
841
+ args: [user, BigInt(i)]
842
+ });
843
+ }
844
+ const permissionIdResults = await gasAwareMulticall(this.context.publicClient, {
845
+ contracts: permissionIdCalls
846
+ });
847
+ const permissionIds = permissionIdResults.map((result) => result).filter((id) => id && id > 0n);
848
+ const permissionInfoCalls = permissionIds.map(
849
+ (permissionId) => ({
850
+ address: permissionsAddress,
851
+ abi: permissionsAbi,
852
+ functionName: "permissions",
853
+ args: [permissionId]
854
+ })
855
+ );
856
+ const permissionInfoResults = await gasAwareMulticall(this.context.publicClient, {
857
+ contracts: permissionInfoCalls,
858
+ allowFailure: true
859
+ });
860
+ const permissions = permissionInfoResults.map((result, index) => {
861
+ const permissionId = permissionIds[index];
862
+ if (result.status === "success" && result.result) {
863
+ const permissionInfo = result.result;
864
+ return {
865
+ id: permissionId.toString(),
866
+ grant: permissionInfo.grant,
867
+ nonce: permissionInfo.nonce,
868
+ signature: "",
869
+ // Not available from RPC, will be empty
870
+ addedAtBlock: permissionInfo.startBlock,
871
+ addedAtTimestamp: BigInt(0),
872
+ // Not available from RPC
873
+ transactionHash: "0x0000000000000000000000000000000000000000",
874
+ // Not available from RPC
875
+ user
876
+ };
877
+ } else {
878
+ return {
879
+ id: permissionId.toString(),
880
+ grant: "",
881
+ nonce: BigInt(0),
882
+ signature: "",
883
+ addedAtBlock: BigInt(0),
884
+ addedAtTimestamp: BigInt(0),
885
+ transactionHash: "0x0000000000000000000000000000000000000000",
886
+ user
887
+ };
888
+ }
889
+ }).filter((permission) => permission.grant !== "");
890
+ return permissions;
891
+ } catch (error) {
892
+ throw new Error(
893
+ `RPC query failed: ${error instanceof Error ? error.message : "Unknown error"}`
894
+ );
895
+ }
896
+ }
897
+ /**
898
+ * Retrieves a list of trusted servers for a user.
899
+ *
900
+ * This method supports automatic fallback between subgraph and RPC modes:
901
+ * - If subgraph URL is available, tries subgraph query first for fast results
902
+ * - Falls back to direct contract queries via RPC if subgraph fails
903
+ * - RPC mode uses gasAwareMulticall for efficient batch queries
904
+ *
905
+ * @param params - Query parameters including user address and optional pagination
906
+ * @param params.user - The wallet address of the user to query trusted servers for
907
+ * @param params.subgraphUrl - Optional subgraph URL to override the default
908
+ * @param params.limit - Maximum number of results to return (default: 50)
909
+ * @param params.offset - Number of results to skip for pagination (default: 0)
910
+ * @returns Promise resolving to an array of trusted server objects
911
+ * @throws Error if both subgraph and RPC queries fail
912
+ * @example
913
+ * ```typescript
914
+ * // Basic usage with automatic fallback
915
+ * const servers = await vana.data.getUserTrustedServers({
916
+ * user: '0x...'
917
+ * });
918
+ *
919
+ * // With pagination
920
+ * const servers = await vana.data.getUserTrustedServers({
921
+ * user: '0x...',
922
+ * limit: 10,
923
+ * offset: 20
924
+ * });
925
+ *
926
+ * // With custom subgraph URL
927
+ * const servers = await vana.data.getUserTrustedServers({
928
+ * user: '0x...',
929
+ * subgraphUrl: 'https://custom-subgraph.com/graphql'
930
+ * });
931
+ * ```
932
+ */
933
+ async getUserTrustedServers(params) {
934
+ const { user, limit = 50, offset = 0 } = params;
935
+ const subgraphUrl = params.subgraphUrl || this.context.subgraphUrl;
936
+ if (subgraphUrl) {
937
+ try {
938
+ const servers = await this._getUserTrustedServersViaSubgraph({
939
+ user,
940
+ subgraphUrl
941
+ });
942
+ return limit ? servers.slice(offset, offset + limit) : servers;
943
+ } catch (error) {
944
+ console.warn("Subgraph query failed, falling back to RPC:", error);
945
+ }
946
+ }
947
+ const rpcResult = await this._getUserTrustedServersViaRpc({
948
+ user,
949
+ limit,
950
+ offset
951
+ });
952
+ return rpcResult.servers;
953
+ }
954
+ /**
955
+ * Internal method: Query trusted servers via subgraph
956
+ *
957
+ * @param params - Query parameters object
958
+ * @param params.user - The user address to query trusted servers for
959
+ * @param params.subgraphUrl - The subgraph URL endpoint to query
960
+ * @returns Promise resolving to an array of trusted server objects
961
+ */
962
+ async _getUserTrustedServersViaSubgraph(params) {
963
+ const { user, subgraphUrl } = params;
964
+ const graphqlEndpoint = subgraphUrl;
965
+ if (!graphqlEndpoint) {
966
+ throw new Error(
967
+ "subgraphUrl is required for subgraph mode. Please provide a valid subgraph endpoint or configure it in Vana constructor."
968
+ );
969
+ }
970
+ try {
971
+ const response = await fetch(graphqlEndpoint, {
972
+ method: "POST",
973
+ headers: {
974
+ "Content-Type": "application/json"
975
+ },
976
+ body: JSON.stringify({
977
+ query: print(GetUserTrustedServersDocument),
978
+ variables: {
979
+ userId: user.toLowerCase()
980
+ // Subgraph requires lowercase addresses
981
+ }
982
+ })
983
+ });
984
+ if (!response.ok) {
985
+ throw new Error(
986
+ `Subgraph request failed: ${response.status} ${response.statusText}`
987
+ );
988
+ }
989
+ const result = await response.json();
990
+ if (result.errors) {
991
+ throw new Error(
992
+ `Subgraph query errors: ${result.errors.map((e) => e.message).join(", ")}`
993
+ );
994
+ }
995
+ if (!result.data?.user) {
996
+ return [];
997
+ }
998
+ return (result.data.user.serverTrusts || []).filter((trust) => !trust.untrustedAtBlock).map((trust) => ({
999
+ id: trust.server.id,
1000
+ serverAddress: trust.server.serverAddress,
1001
+ serverUrl: trust.server.url,
1002
+ trustedAt: BigInt(trust.trustedAt),
1003
+ user,
1004
+ name: ""
1005
+ // Not available in new schema, will be empty
1006
+ }));
1007
+ } catch (error) {
1008
+ console.error("Failed to query trusted servers from subgraph:", error);
1009
+ throw error;
1010
+ }
1011
+ }
1012
+ /**
1013
+ * Internal method: Query trusted servers via direct RPC
1014
+ *
1015
+ * @param params - Query parameters object
1016
+ * @param params.user - The user address to query trusted servers for
1017
+ * @param params.limit - Maximum number of results to return
1018
+ * @param params.offset - Number of results to skip for pagination
1019
+ * @returns Promise resolving to pagination result with servers, total count, and hasMore flag
1020
+ */
1021
+ async _getUserTrustedServersViaRpc(params) {
1022
+ const { user, limit, offset } = params;
1023
+ try {
1024
+ const chainId = this.context.walletClient.chain?.id;
1025
+ if (!chainId) {
1026
+ throw new Error("Chain ID not available");
1027
+ }
1028
+ const DataPortabilityServersAddress = getContractAddress(
1029
+ chainId,
1030
+ "DataPortabilityServers"
1031
+ );
1032
+ const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
1033
+ const totalCount = await this.context.publicClient.readContract({
1034
+ address: DataPortabilityServersAddress,
1035
+ abi: DataPortabilityServersAbi,
1036
+ functionName: "userServerIdsLength",
1037
+ args: [user]
1038
+ });
1039
+ const total = Number(totalCount);
1040
+ if (total === 0 || offset >= total) {
1041
+ return {
1042
+ servers: [],
1043
+ total,
1044
+ hasMore: false
1045
+ };
1046
+ }
1047
+ const endIndex = Math.min(offset + limit, total);
1048
+ const serverIdCalls = [];
1049
+ for (let i = offset; i < endIndex; i++) {
1050
+ serverIdCalls.push({
1051
+ address: DataPortabilityServersAddress,
1052
+ abi: DataPortabilityServersAbi,
1053
+ functionName: "userServerIdsAt",
1054
+ args: [user, BigInt(i)]
1055
+ });
1056
+ }
1057
+ const serverIdResults = await gasAwareMulticall(this.context.publicClient, {
1058
+ contracts: serverIdCalls
1059
+ });
1060
+ const serverIds = serverIdResults.map((result) => result).filter((id) => id && id > 0n);
1061
+ const serverInfoCalls = serverIds.map(
1062
+ (serverId) => ({
1063
+ address: DataPortabilityServersAddress,
1064
+ abi: DataPortabilityServersAbi,
1065
+ functionName: "servers",
1066
+ args: [serverId]
1067
+ })
1068
+ );
1069
+ const serverInfoResults = await gasAwareMulticall(this.context.publicClient, {
1070
+ contracts: serverInfoCalls,
1071
+ allowFailure: true
1072
+ });
1073
+ const servers = serverInfoResults.map((result, index) => {
1074
+ const serverId = serverIds[index];
1075
+ if (result.status === "success" && result.result) {
1076
+ const serverInfo = result.result;
1077
+ return {
1078
+ id: `${user.toLowerCase()}-${serverId.toString()}`,
1079
+ serverAddress: serverInfo.serverAddress,
1080
+ serverUrl: serverInfo.url,
1081
+ trustedAt: BigInt(Date.now()),
1082
+ user,
1083
+ trustIndex: offset + index
1084
+ };
1085
+ } else {
1086
+ return {
1087
+ id: `${user.toLowerCase()}-${serverId.toString()}`,
1088
+ serverAddress: "0x0000000000000000000000000000000000000000",
1089
+ serverUrl: "",
1090
+ trustedAt: BigInt(Date.now()),
1091
+ user,
1092
+ trustIndex: offset + index
1093
+ };
1094
+ }
1095
+ });
1096
+ return {
1097
+ servers,
1098
+ total,
1099
+ hasMore: offset + limit < total
1100
+ };
1101
+ } catch (error) {
1102
+ throw new Error(
1103
+ `RPC query failed: ${error instanceof Error ? error.message : "Unknown error"}`
1104
+ );
1105
+ }
1106
+ }
1107
+ /**
1108
+ * Gets the total number of files in the registry from the contract.
1109
+ *
1110
+ * @returns Promise resolving to the total file count
1111
+ * @example
1112
+ * ```typescript
1113
+ * const totalFiles = await vana.data.getTotalFilesCount();
1114
+ * console.log(`Total files in registry: ${totalFiles}`);
1115
+ *
1116
+ * // Use for pagination calculations
1117
+ * const filesPerPage = 20;
1118
+ * const totalPages = Math.ceil(totalFiles / filesPerPage);
1119
+ * console.log(`Total pages: ${totalPages}`);
1120
+ * ```
1121
+ */
1122
+ async getTotalFilesCount() {
1123
+ try {
1124
+ const chainId = this.context.walletClient.chain?.id;
1125
+ if (!chainId) {
1126
+ throw new Error("Chain ID not available");
1127
+ }
1128
+ const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
1129
+ const dataRegistryAbi = getAbi("DataRegistry");
1130
+ const dataRegistry = getContract({
1131
+ address: dataRegistryAddress,
1132
+ abi: dataRegistryAbi,
1133
+ client: this.context.walletClient
1134
+ });
1135
+ const count = await dataRegistry.read.filesCount();
1136
+ return Number(count);
1137
+ } catch (error) {
1138
+ if (error instanceof Error && error.message === "Chain ID not available") {
1139
+ throw error;
1140
+ }
1141
+ console.error("Failed to fetch total files count:", error);
1142
+ return 0;
1143
+ }
1144
+ }
1145
+ /**
1146
+ * Retrieves details for a specific file by its ID.
1147
+ *
1148
+ * @param fileId - The file ID to look up
1149
+ * @returns Promise resolving to UserFile object
1150
+ * @throws {Error} "Chain ID not available" - When wallet chain is not configured
1151
+ * @throws {Error} "File not found" - When file ID doesn't exist or returns empty data
1152
+ * @throws {Error} "Failed to fetch file {fileId}: {error}" - General contract read failures
1153
+ * @example
1154
+ * ```typescript
1155
+ * try {
1156
+ * const file = await vana.data.getFileById(123);
1157
+ * console.log('File details:', {
1158
+ * id: file.id,
1159
+ * url: file.url,
1160
+ * owner: file.ownerAddress,
1161
+ * addedAt: file.addedAtBlock
1162
+ * });
1163
+ * } catch (error) {
1164
+ * console.error('File not found or error retrieving file:', error);
1165
+ * }
1166
+ * ```
1167
+ *
1168
+ * This method queries the DataRegistry contract directly
1169
+ * to get file details for any file ID, regardless of user ownership.
1170
+ * This is useful for file lookup functionality where users can search
1171
+ * for specific files by ID.
1172
+ */
1173
+ async getFileById(fileId) {
1174
+ try {
1175
+ const chainId = this.context.walletClient.chain?.id;
1176
+ if (!chainId) {
1177
+ throw new Error("Chain ID not available");
1178
+ }
1179
+ const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
1180
+ const dataRegistryAbi = getAbi("DataRegistry");
1181
+ const dataRegistry = getContract({
1182
+ address: dataRegistryAddress,
1183
+ abi: dataRegistryAbi,
1184
+ client: this.context.walletClient
1185
+ });
1186
+ const fileDetails = await dataRegistry.read.files([BigInt(fileId)]);
1187
+ if (!fileDetails) {
1188
+ throw new Error("File not found");
1189
+ }
1190
+ if (Array.isArray(fileDetails)) {
1191
+ const [id, url, ownerAddress, addedAtBlock] = fileDetails;
1192
+ if (id === BigInt(0)) {
1193
+ throw new Error("File not found");
1194
+ }
1195
+ return {
1196
+ id: Number(id),
1197
+ url,
1198
+ ownerAddress,
1199
+ addedAtBlock: BigInt(addedAtBlock)
1200
+ };
1201
+ } else {
1202
+ if (!fileDetails.id || fileDetails.id === BigInt(0)) {
1203
+ throw new Error("File not found");
1204
+ }
1205
+ return {
1206
+ id: Number(fileDetails.id),
1207
+ ownerAddress: fileDetails.ownerAddress,
1208
+ url: fileDetails.url,
1209
+ addedAtBlock: BigInt(fileDetails.addedAtBlock)
1210
+ };
1211
+ }
1212
+ } catch (error) {
1213
+ console.error("Failed to fetch file by ID:", error);
1214
+ throw new Error(
1215
+ `Failed to fetch file ${fileId}: ${error instanceof Error ? error.message : "Unknown error"}`
1216
+ );
1217
+ }
1218
+ }
1219
+ /**
1220
+ * Registers a file URL directly on the blockchain with a schema ID.
1221
+ *
1222
+ * @remarks
1223
+ * This method registers an existing file URL on the DataRegistry contract
1224
+ * with a schema ID, without uploading any data. Useful when you have already
1225
+ * uploaded content to storage and just need to register it on-chain.
1226
+ *
1227
+ * @param url - The URL of the file to register (IPFS or HTTP/HTTPS)
1228
+ * @param schemaId - The schema ID to associate with the file
1229
+ * @returns Promise resolving to the file ID and transaction hash
1230
+ * @throws {Error} When chain ID is not available - "Chain ID not available"
1231
+ * @throws {Error} When wallet address is unavailable - "No addresses available"
1232
+ * @throws {Error} When transaction fails - "Failed to register file with schema"
1233
+ * @example
1234
+ * ```typescript
1235
+ * const { fileId, transactionHash } = await vana.data.registerFileWithSchema(
1236
+ * "ipfs://QmXxx...",
1237
+ * 1
1238
+ * );
1239
+ * console.log(`File ${fileId} registered with schema in tx ${transactionHash}`);
1240
+ * ```
1241
+ */
1242
+ async registerFileWithSchema(url, schemaId) {
1243
+ try {
1244
+ const chainId = this.context.walletClient.chain?.id;
1245
+ if (!chainId) {
1246
+ throw new Error("Chain ID not available");
1247
+ }
1248
+ const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
1249
+ const dataRegistryAbi = getAbi("DataRegistry");
1250
+ const userAddress = await this.getUserAddress();
1251
+ const txHash = await this.context.walletClient.writeContract({
1252
+ address: dataRegistryAddress,
1253
+ abi: dataRegistryAbi,
1254
+ functionName: "addFileWithSchema",
1255
+ args: [url, BigInt(schemaId)],
1256
+ account: this.context.walletClient.account || userAddress,
1257
+ chain: this.context.walletClient.chain || null
1258
+ });
1259
+ const receipt = await this.context.publicClient.waitForTransactionReceipt(
1260
+ {
1261
+ hash: txHash,
1262
+ confirmations: 1
1263
+ }
1264
+ );
1265
+ const { parseFileAddedEvent } = await import("../utils/eventParsing");
1266
+ const eventData = parseFileAddedEvent(receipt);
1267
+ return {
1268
+ fileId: Number(eventData.fileId),
1269
+ transactionHash: txHash
1270
+ };
1271
+ } catch (error) {
1272
+ console.error("Failed to register file with schema:", error);
1273
+ throw new Error(
1274
+ `Registration failed: ${error instanceof Error ? error.message : "Unknown error"}`
1275
+ );
1276
+ }
1277
+ }
1278
+ /**
1279
+ * Gets the user's address from the wallet client.
1280
+ *
1281
+ * @returns Promise resolving to the user's wallet address
1282
+ * @throws {Error} When no addresses are available in wallet client
1283
+ */
1284
+ async getUserAddress() {
1285
+ const addresses = await this.context.walletClient.getAddresses();
1286
+ if (addresses.length === 0) {
1287
+ throw new Error("No addresses available in wallet client");
1288
+ }
1289
+ return addresses[0];
1290
+ }
1291
+ /**
1292
+ * Adds a file with permissions to the DataRegistry contract.
1293
+ *
1294
+ * @param url - The file URL to register
1295
+ * @param ownerAddress - The address of the file owner
1296
+ * @param permissions - Array of permissions to set for the file
1297
+ * @returns Promise resolving to file ID and transaction hash
1298
+ * @throws {Error} When chain ID is not available
1299
+ * @throws {ContractError} When contract execution fails
1300
+ * @throws {Error} When transaction receipt is not available
1301
+ * @throws {Error} When FileAdded event cannot be parsed
1302
+ *
1303
+ * This method handles the core logic of registering a file
1304
+ * with specific permissions on the DataRegistry contract. It can be used
1305
+ * by both direct transactions and relayer services.
1306
+ */
1307
+ async addFileWithPermissions(url, ownerAddress, permissions = []) {
1308
+ try {
1309
+ const chainId = this.context.walletClient.chain?.id;
1310
+ if (!chainId) {
1311
+ throw new Error("Chain ID not available");
1312
+ }
1313
+ const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
1314
+ const dataRegistryAbi = getAbi("DataRegistry");
1315
+ const txHash = await this.context.walletClient.writeContract({
1316
+ address: dataRegistryAddress,
1317
+ abi: dataRegistryAbi,
1318
+ functionName: "addFileWithPermissions",
1319
+ args: [url, ownerAddress, permissions],
1320
+ account: this.context.walletClient.account || ownerAddress,
1321
+ chain: this.context.walletClient.chain || null
1322
+ });
1323
+ const receipt = await this.context.publicClient.waitForTransactionReceipt(
1324
+ {
1325
+ hash: txHash,
1326
+ confirmations: 1
1327
+ }
1328
+ );
1329
+ const { parseFileAddedEvent } = await import("../utils/eventParsing");
1330
+ const eventData = parseFileAddedEvent(receipt);
1331
+ return {
1332
+ fileId: Number(eventData.fileId),
1333
+ transactionHash: txHash
1334
+ };
1335
+ } catch (error) {
1336
+ console.error("Failed to add file with permissions:", error);
1337
+ throw new Error(
1338
+ `Failed to add file with permissions: ${error instanceof Error ? error.message : "Unknown error"}`
1339
+ );
1340
+ }
1341
+ }
1342
+ /**
1343
+ * Adds a file to the registry with permissions and schema.
1344
+ * This combines the functionality of addFileWithPermissions and schema validation.
1345
+ *
1346
+ * @param url - The URL of the file to register
1347
+ * @param ownerAddress - The address of the file owner
1348
+ * @param permissions - Array of permissions to grant (account and encrypted key)
1349
+ * @param schemaId - The schema ID to associate with the file (0 for no schema)
1350
+ * @returns Promise resolving to object with fileId and transactionHash
1351
+ * @throws {Error} When chain ID is not available
1352
+ * @throws {ContractError} When contract execution fails
1353
+ * @throws {Error} When transaction receipt is not available
1354
+ * @throws {Error} When FileAdded event cannot be parsed
1355
+ */
1356
+ async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
1357
+ try {
1358
+ const chainId = this.context.walletClient.chain?.id;
1359
+ if (!chainId) {
1360
+ throw new Error("Chain ID not available");
1361
+ }
1362
+ const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
1363
+ const dataRegistryAbi = getAbi("DataRegistry");
1364
+ const txHash = await this.context.walletClient.writeContract({
1365
+ address: dataRegistryAddress,
1366
+ abi: dataRegistryAbi,
1367
+ functionName: "addFileWithPermissionsAndSchema",
1368
+ args: [url, ownerAddress, permissions, BigInt(schemaId)],
1369
+ account: this.context.walletClient.account || ownerAddress,
1370
+ chain: this.context.walletClient.chain || null
1371
+ });
1372
+ const receipt = await this.context.publicClient.waitForTransactionReceipt(
1373
+ {
1374
+ hash: txHash,
1375
+ confirmations: 1
1376
+ }
1377
+ );
1378
+ const { parseFileAddedEvent } = await import("../utils/eventParsing");
1379
+ const eventData = parseFileAddedEvent(receipt);
1380
+ return {
1381
+ fileId: Number(eventData.fileId),
1382
+ transactionHash: txHash
1383
+ };
1384
+ } catch (error) {
1385
+ console.error("Failed to add file with permissions and schema:", error);
1386
+ throw new Error(
1387
+ `Failed to add file with permissions and schema: ${error instanceof Error ? error.message : "Unknown error"}`
1388
+ );
1389
+ }
1390
+ }
1391
+ /**
1392
+ * Adds a new refiner to the DataRefinerRegistry.
1393
+ *
1394
+ * @remarks
1395
+ * Refiners are data processing templates that define how raw data should be
1396
+ * transformed into structured formats. Each refiner is associated with a DLP
1397
+ * (Data Liquidity Pool), has a specific schema for output, and includes
1398
+ * instructions for the refinement process.
1399
+ *
1400
+ * @param params - Refiner configuration parameters
1401
+ * @param params.dlpId - The Data Liquidity Pool ID this refiner belongs to
1402
+ * @param params.name - Human-readable name for the refiner
1403
+ * @param params.schemaId - Schema ID that defines the output format
1404
+ * @param params.refinementInstructionUrl - URL containing processing instructions
1405
+ * @returns Promise resolving to the new refiner ID and transaction hash
1406
+ * @throws {Error} When chain ID is not available - "Chain ID not available"
1407
+ * @throws {Error} When transaction fails - "Failed to add refiner: {error}"
1408
+ * @example
1409
+ * ```typescript
1410
+ * const result = await vana.data.addRefiner({
1411
+ * dlpId: 1,
1412
+ * name: "Social Media Sentiment Analyzer",
1413
+ * schemaId: 42,
1414
+ * refinementInstructionUrl: "ipfs://QmXxx..."
1415
+ * });
1416
+ * console.log(`Created refiner ${result.refinerId} in tx ${result.transactionHash}`);
1417
+ * ```
1418
+ */
1419
+ async addRefiner(params) {
1420
+ try {
1421
+ const chainId = this.context.walletClient.chain?.id;
1422
+ if (!chainId) {
1423
+ throw new Error("Chain ID not available");
1424
+ }
1425
+ const dataRefinerRegistryAddress = getContractAddress(
1426
+ chainId,
1427
+ "DataRefinerRegistry"
1428
+ );
1429
+ const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
1430
+ const txHash = await this.context.walletClient.writeContract({
1431
+ address: dataRefinerRegistryAddress,
1432
+ abi: dataRefinerRegistryAbi,
1433
+ functionName: "addRefinerWithSchemaId",
1434
+ args: [
1435
+ BigInt(params.dlpId),
1436
+ params.name,
1437
+ BigInt(params.schemaId),
1438
+ params.refinementInstructionUrl
1439
+ ],
1440
+ account: this.context.walletClient.account || await this.getUserAddress(),
1441
+ chain: this.context.walletClient.chain || null
1442
+ });
1443
+ const receipt = await this.context.publicClient.waitForTransactionReceipt(
1444
+ {
1445
+ hash: txHash,
1446
+ confirmations: 1
1447
+ }
1448
+ );
1449
+ const { parseRefinerAddedEvent } = await import("../utils/eventParsing");
1450
+ const eventData = parseRefinerAddedEvent(receipt);
1451
+ return {
1452
+ refinerId: Number(eventData.refinerId),
1453
+ transactionHash: txHash
1454
+ };
1455
+ } catch (error) {
1456
+ console.error("Failed to add refiner:", error);
1457
+ throw new Error(
1458
+ `Failed to add refiner: ${error instanceof Error ? error.message : "Unknown error"}`
1459
+ );
1460
+ }
1461
+ }
1462
+ /**
1463
+ * Retrieves a refiner by its ID.
1464
+ *
1465
+ * @remarks
1466
+ * Queries the DataRefinerRegistry contract to get complete information about
1467
+ * a specific refiner including its DLP association, schema, and instructions.
1468
+ *
1469
+ * @param refinerId - The numeric refiner ID to retrieve
1470
+ * @returns Promise resolving to the refiner information object
1471
+ * @throws {Error} When chain ID is not available - "Chain ID not available"
1472
+ * @throws {Error} When refiner doesn't exist - "Refiner with ID {refinerId} does not exist"
1473
+ * @throws {Error} When contract read fails - "Failed to fetch refiner: {error}"
1474
+ * @example
1475
+ * ```typescript
1476
+ * const refiner = await vana.data.getRefiner(1);
1477
+ * console.log({
1478
+ * name: refiner.name,
1479
+ * dlp: refiner.dlpId,
1480
+ * schema: refiner.schemaId,
1481
+ * instructions: refiner.refinementInstructionUrl
1482
+ * });
1483
+ * ```
1484
+ */
1485
+ async getRefiner(refinerId) {
1486
+ try {
1487
+ const chainId = this.context.walletClient.chain?.id;
1488
+ if (!chainId) {
1489
+ throw new Error("Chain ID not available");
1490
+ }
1491
+ const dataRefinerRegistryAddress = getContractAddress(
1492
+ chainId,
1493
+ "DataRefinerRegistry"
1494
+ );
1495
+ const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
1496
+ const dataRefinerRegistry = getContract({
1497
+ address: dataRefinerRegistryAddress,
1498
+ abi: dataRefinerRegistryAbi,
1499
+ client: this.context.walletClient
1500
+ });
1501
+ const refinerData = await dataRefinerRegistry.read.refiners([
1502
+ BigInt(refinerId)
1503
+ ]);
1504
+ if (!refinerData) {
1505
+ throw new Error("Refiner not found");
1506
+ }
1507
+ return {
1508
+ id: refinerId,
1509
+ dlpId: Number(refinerData.dlpId),
1510
+ owner: refinerData.owner,
1511
+ name: refinerData.name,
1512
+ schemaId: Number(refinerData.schemaId),
1513
+ refinementInstructionUrl: refinerData.refinementInstructionUrl
1514
+ };
1515
+ } catch (error) {
1516
+ console.error("Failed to get refiner:", error);
1517
+ throw new Error(
1518
+ `Failed to get refiner ${refinerId}: ${error instanceof Error ? error.message : "Unknown error"}`
1519
+ );
1520
+ }
1521
+ }
1522
+ /**
1523
+ * Validates if a schema ID exists in the registry.
1524
+ *
1525
+ * @remarks
1526
+ * Checks the DataRefinerRegistry contract to determine if a given schema ID
1527
+ * has been registered and is available for use.
1528
+ *
1529
+ * @param schemaId - The numeric schema ID to validate
1530
+ * @returns Promise resolving to true if schema exists, false otherwise
1531
+ * @example
1532
+ * ```typescript
1533
+ * const isValid = await vana.data.isValidSchemaId(42);
1534
+ * if (isValid) {
1535
+ * console.log('Schema 42 is available for use');
1536
+ * } else {
1537
+ * console.log('Schema 42 does not exist');
1538
+ * }
1539
+ * ```
1540
+ */
1541
+ async isValidSchemaId(schemaId) {
1542
+ try {
1543
+ const chainId = this.context.walletClient.chain?.id;
1544
+ if (!chainId) {
1545
+ throw new Error("Chain ID not available");
1546
+ }
1547
+ const dataRefinerRegistryAddress = getContractAddress(
1548
+ chainId,
1549
+ "DataRefinerRegistry"
1550
+ );
1551
+ const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
1552
+ const dataRefinerRegistry = getContract({
1553
+ address: dataRefinerRegistryAddress,
1554
+ abi: dataRefinerRegistryAbi,
1555
+ client: this.context.walletClient
1556
+ });
1557
+ const isValid = await dataRefinerRegistry.read.isValidSchemaId([
1558
+ BigInt(schemaId)
1559
+ ]);
1560
+ return isValid;
1561
+ } catch (error) {
1562
+ console.error("Failed to validate schema ID:", error);
1563
+ return false;
1564
+ }
1565
+ }
1566
+ /**
1567
+ * Gets the total number of refiners in the registry.
1568
+ *
1569
+ * @remarks
1570
+ * Queries the DataRefinerRegistry contract to get the total count of all
1571
+ * registered refiners across all DLPs.
1572
+ *
1573
+ * @returns Promise resolving to the total refiner count
1574
+ * @example
1575
+ * ```typescript
1576
+ * const count = await vana.data.getRefinersCount();
1577
+ * console.log(`Total refiners registered: ${count}`);
1578
+ * ```
1579
+ */
1580
+ async getRefinersCount() {
1581
+ try {
1582
+ const chainId = this.context.walletClient.chain?.id;
1583
+ if (!chainId) {
1584
+ throw new Error("Chain ID not available");
1585
+ }
1586
+ const dataRefinerRegistryAddress = getContractAddress(
1587
+ chainId,
1588
+ "DataRefinerRegistry"
1589
+ );
1590
+ const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
1591
+ const dataRefinerRegistry = getContract({
1592
+ address: dataRefinerRegistryAddress,
1593
+ abi: dataRefinerRegistryAbi,
1594
+ client: this.context.walletClient
1595
+ });
1596
+ const count = await dataRefinerRegistry.read.refinersCount();
1597
+ return Number(count);
1598
+ } catch (error) {
1599
+ console.error("Failed to get refiners count:", error);
1600
+ return 0;
1601
+ }
1602
+ }
1603
+ /**
1604
+ * Updates the schema ID for an existing refiner.
1605
+ *
1606
+ * @remarks
1607
+ * Allows the owner of a refiner to update its associated schema ID.
1608
+ * This is useful when refiner output format needs to change.
1609
+ *
1610
+ * @param params - Update parameters
1611
+ * @param params.refinerId - The refiner ID to update
1612
+ * @param params.newSchemaId - The new schema ID to set
1613
+ * @returns Promise resolving to the transaction hash
1614
+ * @throws {Error} When chain ID is not available - "Chain ID not available"
1615
+ * @throws {Error} When transaction fails - "Failed to update schema ID: {error}"
1616
+ * @example
1617
+ * ```typescript
1618
+ * const result = await vana.data.updateSchemaId({
1619
+ * refinerId: 1,
1620
+ * newSchemaId: 55
1621
+ * });
1622
+ * console.log(`Schema updated in tx ${result.transactionHash}`);
1623
+ * ```
1624
+ */
1625
+ async updateSchemaId(params) {
1626
+ try {
1627
+ const chainId = this.context.walletClient.chain?.id;
1628
+ if (!chainId) {
1629
+ throw new Error("Chain ID not available");
1630
+ }
1631
+ const dataRefinerRegistryAddress = getContractAddress(
1632
+ chainId,
1633
+ "DataRefinerRegistry"
1634
+ );
1635
+ const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
1636
+ const txHash = await this.context.walletClient.writeContract({
1637
+ address: dataRefinerRegistryAddress,
1638
+ abi: dataRefinerRegistryAbi,
1639
+ functionName: "updateSchemaId",
1640
+ args: [BigInt(params.refinerId), BigInt(params.newSchemaId)],
1641
+ account: this.context.walletClient.account || await this.getUserAddress(),
1642
+ chain: this.context.walletClient.chain || null
1643
+ });
1644
+ await this.context.publicClient.waitForTransactionReceipt({
1645
+ hash: txHash,
1646
+ timeout: 3e4
1647
+ });
1648
+ return {
1649
+ transactionHash: txHash
1650
+ };
1651
+ } catch (error) {
1652
+ console.error("Failed to update schema ID:", error);
1653
+ throw new Error(
1654
+ `Failed to update schema ID: ${error instanceof Error ? error.message : "Unknown error"}`
1655
+ );
1656
+ }
1657
+ }
1658
+ /**
1659
+ * Uploads an encrypted file and grants permission to a party with a public key.
1660
+ *
1661
+ * This method handles the complete workflow:
1662
+ * 1. Encrypts the file with the user's encryption key
1663
+ * 2. Uploads the encrypted file to storage
1664
+ * 3. Encrypts the user's encryption key with the provided public key
1665
+ * 4. Registers the file with permissions
1666
+ *
1667
+ * @param data - The file data to encrypt and upload
1668
+ * @param permissions - Array of permissions to grant, each with account address and public key
1669
+ * @param filename - Optional filename for the upload
1670
+ * @param providerName - Optional storage provider to use
1671
+ * @returns Promise resolving to upload result with file ID and storage URL
1672
+ */
1673
+ async uploadFileWithPermissions(data, permissions, filename, providerName) {
1674
+ try {
1675
+ const uploadResult = await this.uploadToStorage(
1676
+ data,
1677
+ filename,
1678
+ true,
1679
+ // Always encrypt for uploadFileWithPermissions
1680
+ providerName
1681
+ );
1682
+ const userAddress = await this.getUserAddress();
1683
+ const userEncryptionKey = await generateEncryptionKey(
1684
+ this.context.walletClient,
1685
+ this.context.platform,
1686
+ DEFAULT_ENCRYPTION_SEED
1687
+ );
1688
+ const encryptedPermissions = await Promise.all(
1689
+ permissions.map(async (permission) => {
1690
+ const encryptedKey = await encryptWithWalletPublicKey(
1691
+ userEncryptionKey,
1692
+ permission.publicKey,
1693
+ this.context.platform
1694
+ );
1695
+ return {
1696
+ account: permission.account,
1697
+ key: encryptedKey
1698
+ };
1699
+ })
1700
+ );
1701
+ let result;
1702
+ if (this.context.relayerCallbacks?.submitFileAdditionWithPermissions) {
1703
+ result = await this.context.relayerCallbacks.submitFileAdditionWithPermissions(
1704
+ uploadResult.url,
1705
+ userAddress,
1706
+ encryptedPermissions
1707
+ );
1708
+ } else {
1709
+ result = await this.addFileWithPermissions(
1710
+ uploadResult.url,
1711
+ userAddress,
1712
+ encryptedPermissions
1713
+ );
1714
+ }
1715
+ return {
1716
+ fileId: result.fileId,
1717
+ url: uploadResult.url,
1718
+ size: uploadResult.size,
1719
+ transactionHash: result.transactionHash
1720
+ };
1721
+ } catch (error) {
1722
+ console.error("Failed to upload file with permissions:", error);
1723
+ throw new Error(
1724
+ `Failed to upload file with permissions: ${error instanceof Error ? error.message : "Unknown error"}`
1725
+ );
1726
+ }
1727
+ }
1728
+ /**
1729
+ * Uploads content to storage without registering it on the blockchain.
1730
+ * This method only handles the storage upload and returns the file URL.
1731
+ *
1732
+ * @param content - The content to upload (string, Blob, Buffer, or object - objects will be JSON stringified)
1733
+ * @param filename - Optional filename for the uploaded file (defaults to timestamp-based name)
1734
+ * @param encrypt - Optional flag to encrypt the content before upload
1735
+ * @param providerName - Optional specific storage provider to use
1736
+ * @returns Promise resolving to the storage upload result with url, size, and contentType
1737
+ */
1738
+ async uploadToStorage(content, filename, encrypt = false, providerName) {
1739
+ try {
1740
+ let blob;
1741
+ if (content instanceof Blob) {
1742
+ blob = content;
1743
+ } else if (typeof content === "string") {
1744
+ blob = new Blob([content], { type: "text/plain" });
1745
+ } else if (content instanceof Buffer) {
1746
+ const arrayBuffer = content.buffer.slice(
1747
+ content.byteOffset,
1748
+ content.byteOffset + content.byteLength
1749
+ );
1750
+ blob = new Blob([arrayBuffer], { type: "application/octet-stream" });
1751
+ } else {
1752
+ blob = new Blob([JSON.stringify(content)], {
1753
+ type: "application/json"
1754
+ });
1755
+ }
1756
+ let finalBlob = blob;
1757
+ if (encrypt) {
1758
+ const encryptionKey = await generateEncryptionKey(
1759
+ this.context.walletClient,
1760
+ this.context.platform,
1761
+ DEFAULT_ENCRYPTION_SEED
1762
+ );
1763
+ finalBlob = await encryptBlobWithSignedKey(
1764
+ blob,
1765
+ encryptionKey,
1766
+ this.context.platform
1767
+ );
1768
+ }
1769
+ if (!this.context.storageManager) {
1770
+ if (this.context.validateStorageRequired) {
1771
+ this.context.validateStorageRequired();
1772
+ throw new Error("Storage validation failed");
1773
+ } else {
1774
+ throw new Error(
1775
+ "Storage manager not configured. Please provide storage providers in VanaConfig."
1776
+ );
1777
+ }
1778
+ }
1779
+ const finalFilename = filename || `upload-${Date.now()}.dat`;
1780
+ const uploadResult = await this.context.storageManager.upload(
1781
+ finalBlob,
1782
+ finalFilename,
1783
+ providerName
1784
+ );
1785
+ return uploadResult;
1786
+ } catch (error) {
1787
+ throw new Error(
1788
+ `Upload failed: ${error instanceof Error ? error.message : "Unknown error"}`
1789
+ );
1790
+ }
1791
+ }
1792
+ /**
1793
+ * Adds a permission for a party to access an existing file.
1794
+ *
1795
+ * This method handles the complete workflow:
1796
+ * 1. Gets the user's encryption key
1797
+ * 2. Encrypts the user's encryption key with the provided public key
1798
+ * 3. Adds the permission to the file
1799
+ * 4. Returns the permission data from the blockchain event
1800
+ *
1801
+ * For advanced users who need more control over transaction timing,
1802
+ * use `submitFilePermission()` instead.
1803
+ *
1804
+ * @param fileId - The ID of the file to add permissions for
1805
+ * @param account - The address of the account to grant permission to
1806
+ * @param publicKey - The public key to encrypt the user's encryption key with (hex string with 0x prefix)
1807
+ * @returns Promise resolving to permission data from PermissionGranted event
1808
+ * @throws {Error} "No addresses available in wallet client" - When wallet is not connected
1809
+ * @throws {Error} "Chain ID not available" - When wallet chain is not configured
1810
+ * @throws {Error} "Failed to add permission to file: {error}" - When transaction fails or user doesn't own file
1811
+ * @example
1812
+ * ```typescript
1813
+ * const result = await vana.data.addPermissionToFile(fileId, account, publicKey);
1814
+ * console.log(`Permission granted to ${result.account} for file ${result.fileId}`);
1815
+ * console.log(`Transaction: ${result.transactionHash}`);
1816
+ * ```
1817
+ */
1818
+ async addPermissionToFile(fileId, account, publicKey) {
1819
+ return await this.submitFilePermission(fileId, account, publicKey);
1820
+ }
1821
+ /**
1822
+ * Submits a file permission transaction to the blockchain.
1823
+ *
1824
+ * @remarks
1825
+ * This method supports gasless transactions via relayer callbacks when configured.
1826
+ * It encrypts the user's encryption key with the recipient's public key before submission.
1827
+ * Use this when you want to handle transaction confirmation and event parsing separately.
1828
+ *
1829
+ * @param fileId - The ID of the file to grant permission for
1830
+ * @param account - The recipient's wallet address that will access the file
1831
+ * @param publicKey - The recipient's public key for encryption.
1832
+ * Obtain via `vana.server.getIdentity(account).public_key`
1833
+ * @returns Promise resolving to TransactionResult for tracking the transaction
1834
+ * @throws {Error} When chain ID is not available
1835
+ * @throws {Error} When encryption key generation fails
1836
+ * @throws {Error} When public key encryption fails
1837
+ *
1838
+ * @example
1839
+ * ```typescript
1840
+ * const tx = await vana.data.submitFilePermission(
1841
+ * fileId,
1842
+ * "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
1843
+ * recipientPublicKey
1844
+ * );
1845
+ * const result = await tx.waitForEvents();
1846
+ * console.log(`Permission granted with ID: ${result.permissionId}`);
1847
+ * ```
1848
+ */
1849
+ async submitFilePermission(fileId, account, publicKey) {
1850
+ try {
1851
+ const userEncryptionKey = await generateEncryptionKey(
1852
+ this.context.walletClient,
1853
+ this.context.platform,
1854
+ DEFAULT_ENCRYPTION_SEED
1855
+ );
1856
+ const encryptedKey = await encryptWithWalletPublicKey(
1857
+ userEncryptionKey,
1858
+ publicKey,
1859
+ this.context.platform
1860
+ );
1861
+ const chainId = this.context.walletClient.chain?.id;
1862
+ if (!chainId) {
1863
+ throw new Error("Chain ID not available");
1864
+ }
1865
+ const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
1866
+ const dataRegistryAbi = getAbi("DataRegistry");
1867
+ const txHash = await this.context.walletClient.writeContract({
1868
+ address: dataRegistryAddress,
1869
+ abi: dataRegistryAbi,
1870
+ functionName: "addFilePermission",
1871
+ args: [BigInt(fileId), account, encryptedKey],
1872
+ account: this.context.walletClient.account || await this.getUserAddress(),
1873
+ chain: this.context.walletClient.chain || null
1874
+ });
1875
+ return {
1876
+ hash: txHash,
1877
+ from: this.context.walletClient.account?.address
1878
+ };
1879
+ } catch (error) {
1880
+ console.error("Failed to add permission to file:", error);
1881
+ throw new Error(
1882
+ `Failed to add permission to file: ${error instanceof Error ? error.message : "Unknown error"}`
1883
+ );
1884
+ }
1885
+ }
1886
+ /**
1887
+ * Gets the encrypted key for a specific account's permission to access a file.
1888
+ *
1889
+ * @param fileId - The ID of the file
1890
+ * @param account - The account address to get the permission for
1891
+ * @returns Promise resolving to the encrypted key for that account
1892
+ */
1893
+ async getFilePermission(fileId, account) {
1894
+ try {
1895
+ const chainId = this.context.walletClient.chain?.id;
1896
+ if (!chainId) {
1897
+ throw new Error("Chain ID not available");
1898
+ }
1899
+ const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
1900
+ const dataRegistryAbi = getAbi("DataRegistry");
1901
+ const dataRegistry = getContract({
1902
+ address: dataRegistryAddress,
1903
+ abi: dataRegistryAbi,
1904
+ client: this.context.walletClient
1905
+ });
1906
+ const encryptedKey = await dataRegistry.read.filePermissions([
1907
+ BigInt(fileId),
1908
+ account
1909
+ ]);
1910
+ return encryptedKey;
1911
+ } catch (error) {
1912
+ console.error("Failed to get file permission:", error);
1913
+ throw new Error(
1914
+ `Failed to get file permission: ${error instanceof Error ? error.message : "Unknown error"}`
1915
+ );
1916
+ }
1917
+ }
1918
+ /**
1919
+ * Decrypts a file that the user has permission to access using their private key.
1920
+ *
1921
+ * This method handles the complete workflow for servers or other permitted parties:
1922
+ * 1. Gets the encrypted encryption key from file permissions
1923
+ * 2. Decrypts the encryption key using the provided private key
1924
+ * 3. Downloads and decrypts the file data
1925
+ *
1926
+ * @param file - The file to decrypt
1927
+ * @param privateKey - The private key to decrypt the user's encryption key
1928
+ * @param account - The account address that has permission (defaults to current wallet account)
1929
+ * @returns Promise resolving to the decrypted file data
1930
+ */
1931
+ async decryptFileWithPermission(file, privateKey, account) {
1932
+ try {
1933
+ const permissionAccount = account || await this.getUserAddress();
1934
+ const encryptedKey = await this.getFilePermission(
1935
+ file.id,
1936
+ permissionAccount
1937
+ );
1938
+ if (!encryptedKey) {
1939
+ throw new Error(
1940
+ `No permission found for account ${permissionAccount} to access file ${file.id}`
1941
+ );
1942
+ }
1943
+ const userEncryptionKey = await decryptWithWalletPrivateKey(
1944
+ encryptedKey,
1945
+ privateKey,
1946
+ this.context.platform
1947
+ );
1948
+ let encryptedData;
1949
+ if (file.url.startsWith("ipfs://")) {
1950
+ encryptedData = await this.fetchFromIPFS(file.url);
1951
+ } else {
1952
+ encryptedData = await this.fetch(file.url);
1953
+ }
1954
+ const decryptedData = await decryptBlobWithSignedKey(
1955
+ encryptedData,
1956
+ userEncryptionKey,
1957
+ this.context.platform
1958
+ );
1959
+ return decryptedData;
1960
+ } catch (error) {
1961
+ console.error("Failed to decrypt file with permission:", error);
1962
+ throw new Error(
1963
+ `Failed to decrypt file with permission: ${error instanceof Error ? error.message : "Unknown error"}`
1964
+ );
1965
+ }
1966
+ }
1967
+ /**
1968
+ * Simple network-agnostic fetch utility for retrieving file content.
1969
+ *
1970
+ * @remarks
1971
+ * This is a thin wrapper around the global fetch API that returns the response as a Blob.
1972
+ * It provides a consistent interface for fetching encrypted content before decryption.
1973
+ * For IPFS URLs, consider using fetchFromIPFS for better reliability.
1974
+ *
1975
+ * @param url - The URL to fetch content from
1976
+ * @returns Promise resolving to the fetched content as a Blob
1977
+ * @throws {Error} "HTTP error! status: {status} {statusText}" - When server returns error status
1978
+ * @throws {Error} "Empty response" - When server returns no content
1979
+ * @throws {Error} "Network error: Failed to fetch from {url}" - When network request fails
1980
+ *
1981
+ * @example
1982
+ * ```typescript
1983
+ * // Fetch and decrypt a file
1984
+ * const encryptionKey = await generateEncryptionKey(walletClient);
1985
+ * const encryptedBlob = await vana.data.fetch(file.url);
1986
+ * const decryptedBlob = await decryptBlob(encryptedBlob, encryptionKey, platform);
1987
+ *
1988
+ * // With custom headers for authentication
1989
+ * const response = await fetch(file.url, {
1990
+ * headers: { 'Authorization': 'Bearer token' }
1991
+ * });
1992
+ * const encryptedBlob = await response.blob();
1993
+ * ```
1994
+ */
1995
+ async fetch(url) {
1996
+ try {
1997
+ const { fetchWithRelayer } = await import("../utils/download");
1998
+ const response = await fetchWithRelayer(
1999
+ url,
2000
+ this.context.downloadRelayer
2001
+ );
2002
+ if (!response.ok) {
2003
+ throw new Error(
2004
+ `HTTP error! status: ${response.status} ${response.statusText}`
2005
+ );
2006
+ }
2007
+ const blob = await response.blob();
2008
+ if (blob.size === 0) {
2009
+ throw new Error("Empty response");
2010
+ }
2011
+ return blob;
2012
+ } catch (error) {
2013
+ if (error instanceof TypeError && error.message.includes("fetch")) {
2014
+ throw new Error(
2015
+ `Network error: Failed to fetch from ${url}. The URL may be invalid or the server may not be accessible.`
2016
+ );
2017
+ }
2018
+ throw error;
2019
+ }
2020
+ }
2021
+ /**
2022
+ * Specialized IPFS fetcher with gateway fallback mechanism.
2023
+ *
2024
+ * @remarks
2025
+ * This method provides robust IPFS content fetching by trying multiple gateways
2026
+ * in sequence until one succeeds. It supports both ipfs:// URLs and raw CIDs.
2027
+ *
2028
+ * The default gateway list includes public gateways, but you should provide
2029
+ * your own gateways for production use to ensure reliability and privacy.
2030
+ *
2031
+ * @param url - The IPFS URL (ipfs://...) or CID to fetch
2032
+ * @param options - Optional configuration
2033
+ * @param options.gateways - Array of IPFS gateway URLs to try (must end with /)
2034
+ * @returns Promise resolving to the fetched content as a Blob
2035
+ * @throws {Error} "Invalid IPFS URL format" - When URL is not ipfs:// or valid CID
2036
+ * @throws {Error} "Empty response" - When gateway returns no content
2037
+ * @throws {Error} "HTTP error! status: {status}" - When gateway returns error status
2038
+ * @throws {Error} "Failed to fetch IPFS content {cid} from all gateways" - When all gateways fail
2039
+ *
2040
+ * @example
2041
+ * ```typescript
2042
+ * // Fetch from IPFS with custom gateways
2043
+ * const encryptedBlob = await vana.data.fetchFromIPFS(file.url, {
2044
+ * gateways: [
2045
+ * 'https://my-private-gateway.com/ipfs/',
2046
+ * 'https://dweb.link/ipfs/',
2047
+ * 'https://ipfs.io/ipfs/'
2048
+ * ]
2049
+ * });
2050
+ *
2051
+ * // Decrypt the fetched content
2052
+ * const encryptionKey = await generateEncryptionKey(walletClient);
2053
+ * const decryptedBlob = await decryptBlob(encryptedBlob, encryptionKey, platform);
2054
+ *
2055
+ * // With raw CID
2056
+ * const blob = await vana.data.fetchFromIPFS('QmXxx...', {
2057
+ * gateways: ['https://ipfs.io/ipfs/']
2058
+ * });
2059
+ * ```
2060
+ */
2061
+ async fetchFromIPFS(url, options) {
2062
+ const defaultGateways = [
2063
+ "https://dweb.link/ipfs/",
2064
+ "https://ipfs.io/ipfs/"
2065
+ ];
2066
+ const gateways = options?.gateways || this.context.ipfsGateways || defaultGateways;
2067
+ const { extractIpfsHash } = await import("../utils/ipfs");
2068
+ const cid = extractIpfsHash(url);
2069
+ if (!cid) {
2070
+ throw new Error(
2071
+ `Invalid IPFS URL format. Expected ipfs://... or a raw CID, got: ${url}`
2072
+ );
2073
+ }
2074
+ const errors = [];
2075
+ for (let i = 0; i < gateways.length; i++) {
2076
+ const gateway = gateways[i];
2077
+ const isLastGateway = i === gateways.length - 1;
2078
+ const gatewayUrl = gateway.endsWith("/") ? `${gateway}${cid}` : `${gateway}/${cid}`;
2079
+ try {
2080
+ console.debug(`Trying IPFS gateway: ${gatewayUrl}`);
2081
+ const response = await fetch(gatewayUrl);
2082
+ if (response.ok) {
2083
+ const blob = await response.blob();
2084
+ if (blob.size > 0) {
2085
+ console.debug(`Successfully fetched from gateway: ${gateway}`);
2086
+ return blob;
2087
+ } else {
2088
+ if (isLastGateway) {
2089
+ throw new Error("Empty response");
2090
+ }
2091
+ errors.push({
2092
+ gateway,
2093
+ error: "Empty response"
2094
+ });
2095
+ }
2096
+ } else {
2097
+ if (isLastGateway) {
2098
+ if (response.status === 403) {
2099
+ throw new Error(`HTTP error! status: 403 ${response.statusText}`);
2100
+ } else if (response.status === 404) {
2101
+ throw new Error(`HTTP error! status: 404 ${response.statusText}`);
2102
+ } else {
2103
+ throw new Error(
2104
+ `HTTP error! status: ${response.status} ${response.statusText}`
2105
+ );
2106
+ }
2107
+ }
2108
+ errors.push({
2109
+ gateway,
2110
+ error: `HTTP ${response.status} ${response.statusText}`
2111
+ });
2112
+ }
2113
+ } catch (error) {
2114
+ if (isLastGateway && error instanceof Error && (error.message.includes("Empty response") || error.message.includes("HTTP error!"))) {
2115
+ throw error;
2116
+ }
2117
+ errors.push({
2118
+ gateway,
2119
+ error: error instanceof Error ? error.message : "Unknown error"
2120
+ });
2121
+ }
2122
+ }
2123
+ if (this.context.downloadRelayer && gateways.length > 0) {
2124
+ try {
2125
+ const relayerUrl = gateways[0].endsWith("/") ? `${gateways[0]}${cid}` : `${gateways[0]}/${cid}`;
2126
+ return await this.context.downloadRelayer.proxyDownload(relayerUrl);
2127
+ } catch (relayerError) {
2128
+ errors.push({
2129
+ gateway: "download-relayer",
2130
+ error: `Proxy failed: ${relayerError instanceof Error ? relayerError.message : "Unknown error"}`
2131
+ });
2132
+ }
2133
+ }
2134
+ const errorDetails = errors.map((e) => `${e.gateway}: ${e.error}`).join("\n ");
2135
+ throw new Error(
2136
+ `Failed to fetch IPFS content ${cid} from all gateways:
2137
+ ${errorDetails}`
2138
+ );
2139
+ }
2140
+ /**
2141
+ * Validates a data schema definition against the Vana meta-schema.
2142
+ *
2143
+ * @param schema - The data schema definition to validate
2144
+ * @returns The validated DataSchema
2145
+ * @throws SchemaValidationError if invalid
2146
+ * @example
2147
+ * ```typescript
2148
+ * const schema = {
2149
+ * name: "User Profile",
2150
+ * version: "1.0.0",
2151
+ * dialect: "json",
2152
+ * schema: {
2153
+ * type: "object",
2154
+ * properties: {
2155
+ * name: { type: "string" },
2156
+ * age: { type: "number" }
2157
+ * }
2158
+ * }
2159
+ * };
2160
+ *
2161
+ * const validatedSchema = vana.data.validateDataSchemaAgainstMetaSchema(schema);
2162
+ * ```
2163
+ */
2164
+ validateDataSchemaAgainstMetaSchema(schema) {
2165
+ return validateDataSchemaAgainstMetaSchema(schema);
2166
+ }
2167
+ /**
2168
+ * Validates data against a JSON Schema from a data schema.
2169
+ *
2170
+ * @param data - The data to validate
2171
+ * @param schema - The data schema containing the schema
2172
+ * @returns Void (throws if validation fails)
2173
+ * @throws SchemaValidationError if invalid
2174
+ * @example
2175
+ * ```typescript
2176
+ * const schema = {
2177
+ * name: "User Profile",
2178
+ * version: "1.0.0",
2179
+ * dialect: "json",
2180
+ * schema: {
2181
+ * type: "object",
2182
+ * properties: {
2183
+ * name: { type: "string" },
2184
+ * age: { type: "number" }
2185
+ * },
2186
+ * required: ["name"]
2187
+ * }
2188
+ * };
2189
+ *
2190
+ * const userData = { name: "Alice", age: 30 };
2191
+ * vana.data.validateDataAgainstSchema(userData, schema);
2192
+ * ```
2193
+ */
2194
+ validateDataAgainstSchema(data, schema) {
2195
+ return validateDataAgainstSchema(data, schema);
2196
+ }
2197
+ /**
2198
+ * Fetches and validates a data schema from a URL, then returns the parsed data schema.
2199
+ *
2200
+ * @param url - The URL to fetch the data schema from
2201
+ * @returns The validated data schema
2202
+ * @throws SchemaValidationError if invalid or fetch fails
2203
+ * @example
2204
+ * ```typescript
2205
+ * // Fetch and validate a schema from IPFS or HTTP
2206
+ * const schema = await vana.data.fetchAndValidateSchema("https://example.com/schema.json");
2207
+ * console.log(schema.name, schema.dialect);
2208
+ *
2209
+ * // Use the schema to validate user data
2210
+ * if (schema.dialect === "json") {
2211
+ * vana.data.validateDataAgainstSchema(userData, schema);
2212
+ * }
2213
+ * ```
2214
+ */
2215
+ async fetchAndValidateSchema(url) {
2216
+ return fetchAndValidateSchema(url);
2217
+ }
2218
+ }
2219
+ export {
2220
+ DataController
2221
+ };
2222
+ //# sourceMappingURL=data.js.map