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