@opendatalabs/vana-sdk 0.1.0-alpha.db07fe1 → 0.1.0-alpha.dc68f39

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