@opendatalabs/vana-sdk 0.1.0-alpha.fd33fc9 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (351) hide show
  1. package/dist/browser.cjs.map +1 -1
  2. package/dist/browser.d.ts +33 -1
  3. package/dist/browser.js.map +1 -1
  4. package/dist/chains/index.cjs.map +1 -1
  5. package/dist/chains/index.d.ts +30 -1
  6. package/dist/chains/index.js.map +1 -1
  7. package/dist/client/__tests__/enhancedResponse.test.d.ts +1 -0
  8. package/dist/client/enhancedResponse.cjs +164 -0
  9. package/dist/client/enhancedResponse.cjs.map +1 -0
  10. package/dist/client/enhancedResponse.d.ts +120 -0
  11. package/dist/client/enhancedResponse.js +138 -0
  12. package/dist/client/enhancedResponse.js.map +1 -0
  13. package/dist/config/chains.cjs.map +1 -1
  14. package/dist/config/chains.d.ts +99 -0
  15. package/dist/config/chains.js.map +1 -1
  16. package/dist/contracts/contractController.cjs.map +1 -1
  17. package/dist/contracts/contractController.d.ts +66 -10
  18. package/dist/contracts/contractController.js.map +1 -1
  19. package/dist/controllers/__tests__/data-consistency-integration.test.d.ts +7 -0
  20. package/dist/controllers/__tests__/operations.processQueue.test.d.ts +1 -0
  21. package/dist/controllers/base.cjs +33 -0
  22. package/dist/controllers/base.cjs.map +1 -1
  23. package/dist/controllers/base.d.ts +10 -0
  24. package/dist/controllers/base.js +33 -0
  25. package/dist/controllers/base.js.map +1 -1
  26. package/dist/controllers/data.cjs +417 -276
  27. package/dist/controllers/data.cjs.map +1 -1
  28. package/dist/controllers/data.d.ts +246 -193
  29. package/dist/controllers/data.js +430 -279
  30. package/dist/controllers/data.js.map +1 -1
  31. package/dist/controllers/operations.cjs +430 -0
  32. package/dist/controllers/operations.cjs.map +1 -0
  33. package/dist/controllers/operations.d.ts +229 -0
  34. package/dist/controllers/operations.js +406 -0
  35. package/dist/controllers/operations.js.map +1 -0
  36. package/dist/controllers/permissions.cjs +690 -209
  37. package/dist/controllers/permissions.cjs.map +1 -1
  38. package/dist/controllers/permissions.d.ts +196 -68
  39. package/dist/controllers/permissions.js +690 -209
  40. package/dist/controllers/permissions.js.map +1 -1
  41. package/dist/controllers/protocol.cjs.map +1 -1
  42. package/dist/controllers/protocol.d.ts +27 -28
  43. package/dist/controllers/protocol.js.map +1 -1
  44. package/dist/controllers/schemas.cjs +104 -25
  45. package/dist/controllers/schemas.cjs.map +1 -1
  46. package/dist/controllers/schemas.d.ts +88 -40
  47. package/dist/controllers/schemas.js +104 -25
  48. package/dist/controllers/schemas.js.map +1 -1
  49. package/dist/controllers/server.cjs +269 -58
  50. package/dist/controllers/server.cjs.map +1 -1
  51. package/dist/controllers/server.d.ts +157 -52
  52. package/dist/controllers/server.js +269 -58
  53. package/dist/controllers/server.js.map +1 -1
  54. package/dist/core/__tests__/health.test.d.ts +1 -0
  55. package/dist/core/__tests__/inMemoryNonceManager.test.d.ts +1 -0
  56. package/dist/core/__tests__/nonceManager.test.d.ts +1 -0
  57. package/dist/core/__tests__/pollingManager.test.d.ts +4 -0
  58. package/dist/core/apiClient.cjs +53 -3
  59. package/dist/core/apiClient.cjs.map +1 -1
  60. package/dist/core/apiClient.d.ts +132 -7
  61. package/dist/core/apiClient.js +53 -3
  62. package/dist/core/apiClient.js.map +1 -1
  63. package/dist/core/generics.cjs +30 -3
  64. package/dist/core/generics.cjs.map +1 -1
  65. package/dist/core/generics.d.ts +95 -6
  66. package/dist/core/generics.js +30 -3
  67. package/dist/core/generics.js.map +1 -1
  68. package/dist/core/health.cjs +289 -0
  69. package/dist/core/health.cjs.map +1 -0
  70. package/dist/core/health.d.ts +143 -0
  71. package/dist/core/health.js +265 -0
  72. package/dist/core/health.js.map +1 -0
  73. package/dist/core/inMemoryNonceManager.cjs +138 -0
  74. package/dist/core/inMemoryNonceManager.cjs.map +1 -0
  75. package/dist/core/inMemoryNonceManager.d.ts +69 -0
  76. package/dist/core/inMemoryNonceManager.js +114 -0
  77. package/dist/core/inMemoryNonceManager.js.map +1 -0
  78. package/dist/core/nonceManager.cjs +304 -0
  79. package/dist/core/nonceManager.cjs.map +1 -0
  80. package/dist/core/nonceManager.d.ts +116 -0
  81. package/dist/core/nonceManager.js +280 -0
  82. package/dist/core/nonceManager.js.map +1 -0
  83. package/dist/core/pollingManager.cjs +292 -0
  84. package/dist/core/pollingManager.cjs.map +1 -0
  85. package/dist/core/pollingManager.d.ts +120 -0
  86. package/dist/core/pollingManager.js +268 -0
  87. package/dist/core/pollingManager.js.map +1 -0
  88. package/dist/core.cjs +55 -1
  89. package/dist/core.cjs.map +1 -1
  90. package/dist/core.d.ts +54 -3
  91. package/dist/core.js +55 -1
  92. package/dist/core.js.map +1 -1
  93. package/dist/crypto/ecies/base.cjs +16 -3
  94. package/dist/crypto/ecies/base.cjs.map +1 -1
  95. package/dist/crypto/ecies/base.js +16 -3
  96. package/dist/crypto/ecies/base.js.map +1 -1
  97. package/dist/errors.cjs +29 -0
  98. package/dist/errors.cjs.map +1 -1
  99. package/dist/errors.d.ts +64 -0
  100. package/dist/errors.js +28 -0
  101. package/dist/errors.js.map +1 -1
  102. package/dist/generated/abi/ComputeInstructionRegistryImplementation.cjs.map +1 -1
  103. package/dist/generated/abi/ComputeInstructionRegistryImplementation.js.map +1 -1
  104. package/dist/generated/abi/DLPPerformanceImplementation.cjs +42 -0
  105. package/dist/generated/abi/DLPPerformanceImplementation.cjs.map +1 -1
  106. package/dist/generated/abi/DLPPerformanceImplementation.d.ts +32 -0
  107. package/dist/generated/abi/DLPPerformanceImplementation.js +42 -0
  108. package/dist/generated/abi/DLPPerformanceImplementation.js.map +1 -1
  109. package/dist/generated/abi/DLPRegistryImplementation.cjs +5 -5
  110. package/dist/generated/abi/DLPRegistryImplementation.cjs.map +1 -1
  111. package/dist/generated/abi/DLPRegistryImplementation.d.ts +4 -4
  112. package/dist/generated/abi/DLPRegistryImplementation.js +5 -5
  113. package/dist/generated/abi/DLPRegistryImplementation.js.map +1 -1
  114. package/dist/generated/abi/DLPRewardDeployerImplementation.cjs +166 -2
  115. package/dist/generated/abi/DLPRewardDeployerImplementation.cjs.map +1 -1
  116. package/dist/generated/abi/DLPRewardDeployerImplementation.d.ts +129 -2
  117. package/dist/generated/abi/DLPRewardDeployerImplementation.js +166 -2
  118. package/dist/generated/abi/DLPRewardDeployerImplementation.js.map +1 -1
  119. package/dist/generated/abi/DataPortabilityGranteesImplementation.cjs +167 -19
  120. package/dist/generated/abi/DataPortabilityGranteesImplementation.cjs.map +1 -1
  121. package/dist/generated/abi/DataPortabilityGranteesImplementation.d.ts +127 -14
  122. package/dist/generated/abi/DataPortabilityGranteesImplementation.js +167 -19
  123. package/dist/generated/abi/DataPortabilityGranteesImplementation.js.map +1 -1
  124. package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs +0 -19
  125. package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs.map +1 -1
  126. package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.ts +0 -14
  127. package/dist/generated/abi/DataPortabilityPermissionsImplementation.js +0 -19
  128. package/dist/generated/abi/DataPortabilityPermissionsImplementation.js.map +1 -1
  129. package/dist/generated/abi/DataPortabilityServersImplementation.cjs +0 -19
  130. package/dist/generated/abi/DataPortabilityServersImplementation.cjs.map +1 -1
  131. package/dist/generated/abi/DataPortabilityServersImplementation.d.ts +0 -14
  132. package/dist/generated/abi/DataPortabilityServersImplementation.js +0 -19
  133. package/dist/generated/abi/DataPortabilityServersImplementation.js.map +1 -1
  134. package/dist/generated/abi/DataRegistryImplementation.cjs +0 -13
  135. package/dist/generated/abi/DataRegistryImplementation.cjs.map +1 -1
  136. package/dist/generated/abi/DataRegistryImplementation.d.ts +0 -10
  137. package/dist/generated/abi/DataRegistryImplementation.js +0 -13
  138. package/dist/generated/abi/DataRegistryImplementation.js.map +1 -1
  139. package/dist/generated/abi/SwapHelperImplementation.cjs +0 -43
  140. package/dist/generated/abi/SwapHelperImplementation.cjs.map +1 -1
  141. package/dist/generated/abi/SwapHelperImplementation.d.ts +0 -35
  142. package/dist/generated/abi/SwapHelperImplementation.js +0 -43
  143. package/dist/generated/abi/SwapHelperImplementation.js.map +1 -1
  144. package/dist/generated/abi/VanaEpochImplementation.cjs +195 -0
  145. package/dist/generated/abi/VanaEpochImplementation.cjs.map +1 -1
  146. package/dist/generated/abi/VanaEpochImplementation.d.ts +151 -0
  147. package/dist/generated/abi/VanaEpochImplementation.js +195 -0
  148. package/dist/generated/abi/VanaEpochImplementation.js.map +1 -1
  149. package/dist/generated/abi/VanaPoolEntityImplementation.cjs +22 -65
  150. package/dist/generated/abi/VanaPoolEntityImplementation.cjs.map +1 -1
  151. package/dist/generated/abi/VanaPoolEntityImplementation.d.ts +17 -51
  152. package/dist/generated/abi/VanaPoolEntityImplementation.js +22 -65
  153. package/dist/generated/abi/VanaPoolEntityImplementation.js.map +1 -1
  154. package/dist/generated/abi/VanaPoolStakingImplementation.cjs +113 -1
  155. package/dist/generated/abi/VanaPoolStakingImplementation.cjs.map +1 -1
  156. package/dist/generated/abi/VanaPoolStakingImplementation.d.ts +85 -1
  157. package/dist/generated/abi/VanaPoolStakingImplementation.js +113 -1
  158. package/dist/generated/abi/VanaPoolStakingImplementation.js.map +1 -1
  159. package/dist/generated/abi/index.d.ts +546 -146
  160. package/dist/generated/event-types.cjs.map +1 -1
  161. package/dist/generated/event-types.d.ts +14 -8
  162. package/dist/generated/eventRegistry.cjs +42 -18
  163. package/dist/generated/eventRegistry.cjs.map +1 -1
  164. package/dist/generated/eventRegistry.js +42 -18
  165. package/dist/generated/eventRegistry.js.map +1 -1
  166. package/dist/generated/server/server-exports.cjs +22 -0
  167. package/dist/generated/server/server-exports.cjs.map +1 -1
  168. package/dist/generated/server/server-exports.d.ts +27 -10
  169. package/dist/generated/server/server-exports.js +17 -0
  170. package/dist/generated/server/server-exports.js.map +1 -1
  171. package/dist/generated/server/server.cjs.map +1 -1
  172. package/dist/generated/server/server.d.ts +771 -402
  173. package/dist/generated/subgraph.cjs +797 -32
  174. package/dist/generated/subgraph.cjs.map +1 -1
  175. package/dist/generated/subgraph.d.ts +135 -0
  176. package/dist/generated/subgraph.js +792 -32
  177. package/dist/generated/subgraph.js.map +1 -1
  178. package/dist/index.browser.d.ts +2 -0
  179. package/dist/index.browser.js +10 -0
  180. package/dist/index.browser.js.map +1 -1
  181. package/dist/index.cjs.map +1 -1
  182. package/dist/index.js.map +1 -1
  183. package/dist/index.node.cjs +26 -0
  184. package/dist/index.node.cjs.map +1 -1
  185. package/dist/index.node.d.ts +49 -5
  186. package/dist/index.node.js +25 -1
  187. package/dist/index.node.js.map +1 -1
  188. package/dist/lib/__tests__/redisAtomicStore.test.d.ts +1 -0
  189. package/dist/lib/redisAtomicStore.cjs +201 -0
  190. package/dist/lib/redisAtomicStore.cjs.map +1 -0
  191. package/dist/lib/redisAtomicStore.d.ts +120 -0
  192. package/dist/lib/redisAtomicStore.js +177 -0
  193. package/dist/lib/redisAtomicStore.js.map +1 -0
  194. package/dist/node.cjs.map +1 -1
  195. package/dist/node.d.ts +39 -1
  196. package/dist/node.js.map +1 -1
  197. package/dist/platform/browser.cjs +160 -2
  198. package/dist/platform/browser.cjs.map +1 -1
  199. package/dist/platform/browser.d.ts +232 -12
  200. package/dist/platform/browser.js +160 -2
  201. package/dist/platform/browser.js.map +1 -1
  202. package/dist/platform/interface.cjs.map +1 -1
  203. package/dist/platform/interface.d.ts +283 -90
  204. package/dist/platform/node.cjs +163 -2
  205. package/dist/platform/node.cjs.map +1 -1
  206. package/dist/platform/node.d.ts +69 -6
  207. package/dist/platform/node.js +163 -2
  208. package/dist/platform/node.js.map +1 -1
  209. package/dist/server/relayerHandler.cjs +315 -81
  210. package/dist/server/relayerHandler.cjs.map +1 -1
  211. package/dist/server/relayerHandler.d.ts +35 -2
  212. package/dist/server/relayerHandler.js +315 -81
  213. package/dist/server/relayerHandler.js.map +1 -1
  214. package/dist/storage/index.cjs +3 -0
  215. package/dist/storage/index.cjs.map +1 -1
  216. package/dist/storage/index.d.ts +1 -0
  217. package/dist/storage/index.js +2 -0
  218. package/dist/storage/index.js.map +1 -1
  219. package/dist/storage/manager.cjs +108 -25
  220. package/dist/storage/manager.cjs.map +1 -1
  221. package/dist/storage/manager.d.ts +119 -25
  222. package/dist/storage/manager.js +108 -25
  223. package/dist/storage/manager.js.map +1 -1
  224. package/dist/storage/providers/callback-storage.cjs +86 -15
  225. package/dist/storage/providers/callback-storage.cjs.map +1 -1
  226. package/dist/storage/providers/callback-storage.d.ts +109 -20
  227. package/dist/storage/providers/callback-storage.js +86 -15
  228. package/dist/storage/providers/callback-storage.js.map +1 -1
  229. package/dist/storage/providers/dropbox.cjs +237 -0
  230. package/dist/storage/providers/dropbox.cjs.map +1 -0
  231. package/dist/storage/providers/dropbox.d.ts +39 -0
  232. package/dist/storage/providers/dropbox.js +215 -0
  233. package/dist/storage/providers/dropbox.js.map +1 -0
  234. package/dist/storage/providers/dropbox.test.d.ts +1 -0
  235. package/dist/storage/providers/pinata.cjs.map +1 -1
  236. package/dist/storage/providers/pinata.d.ts +12 -14
  237. package/dist/storage/providers/pinata.js.map +1 -1
  238. package/dist/tests/data-upload-owner-validation.test.d.ts +1 -0
  239. package/dist/tests/permissions-transaction-options.test.d.ts +1 -0
  240. package/dist/types/atomicStore.cjs +31 -0
  241. package/dist/types/atomicStore.cjs.map +1 -0
  242. package/dist/types/atomicStore.d.ts +236 -0
  243. package/dist/types/atomicStore.js +7 -0
  244. package/dist/types/atomicStore.js.map +1 -0
  245. package/dist/types/blockchain.cjs.map +1 -1
  246. package/dist/types/blockchain.d.ts +39 -11
  247. package/dist/types/chains.cjs.map +1 -1
  248. package/dist/types/chains.d.ts +74 -7
  249. package/dist/types/chains.js.map +1 -1
  250. package/dist/types/config.cjs.map +1 -1
  251. package/dist/types/config.d.ts +38 -4
  252. package/dist/types/config.js.map +1 -1
  253. package/dist/types/contracts.cjs.map +1 -1
  254. package/dist/types/contracts.d.ts +71 -7
  255. package/dist/types/controller-context.cjs.map +1 -1
  256. package/dist/types/controller-context.d.ts +4 -1
  257. package/dist/types/data.cjs.map +1 -1
  258. package/dist/types/data.d.ts +11 -10
  259. package/dist/types/generics.cjs.map +1 -1
  260. package/dist/types/generics.d.ts +81 -10
  261. package/dist/types/index.cjs.map +1 -1
  262. package/dist/types/index.d.ts +31 -3
  263. package/dist/types/index.js.map +1 -1
  264. package/dist/types/operationStore.cjs +17 -0
  265. package/dist/types/operationStore.cjs.map +1 -0
  266. package/dist/types/operationStore.d.ts +171 -0
  267. package/dist/types/operationStore.js +1 -0
  268. package/dist/types/operationStore.js.map +1 -0
  269. package/dist/types/operations.cjs +3 -15
  270. package/dist/types/operations.cjs.map +1 -1
  271. package/dist/types/operations.d.ts +131 -39
  272. package/dist/types/operations.js +2 -13
  273. package/dist/types/operations.js.map +1 -1
  274. package/dist/types/options.cjs +17 -0
  275. package/dist/types/options.cjs.map +1 -0
  276. package/dist/types/options.d.ts +308 -0
  277. package/dist/types/options.js +1 -0
  278. package/dist/types/options.js.map +1 -0
  279. package/dist/types/permissions.cjs.map +1 -1
  280. package/dist/types/permissions.d.ts +19 -20
  281. package/dist/types/personal.cjs.map +1 -1
  282. package/dist/types/personal.d.ts +150 -14
  283. package/dist/types/relayer.cjs.map +1 -1
  284. package/dist/types/relayer.d.ts +145 -24
  285. package/dist/types/storage.cjs.map +1 -1
  286. package/dist/types/storage.d.ts +9 -21
  287. package/dist/types/storage.js.map +1 -1
  288. package/dist/types/utils.cjs.map +1 -1
  289. package/dist/types/utils.d.ts +0 -45
  290. package/dist/utils/__tests__/chainQuery.test.d.ts +1 -0
  291. package/dist/utils/__tests__/subgraphConsistency.test.d.ts +4 -0
  292. package/dist/utils/__tests__/subgraphPagination.test.d.ts +4 -0
  293. package/dist/utils/chainQuery.cjs +107 -0
  294. package/dist/utils/chainQuery.cjs.map +1 -0
  295. package/dist/utils/chainQuery.d.ts +31 -0
  296. package/dist/utils/chainQuery.js +82 -0
  297. package/dist/utils/chainQuery.js.map +1 -0
  298. package/dist/utils/grantFiles.cjs +4 -1
  299. package/dist/utils/grantFiles.cjs.map +1 -1
  300. package/dist/utils/grantFiles.d.ts +10 -20
  301. package/dist/utils/grantFiles.js +4 -1
  302. package/dist/utils/grantFiles.js.map +1 -1
  303. package/dist/utils/grantValidation.cjs.map +1 -1
  304. package/dist/utils/grantValidation.d.ts +95 -16
  305. package/dist/utils/grantValidation.js.map +1 -1
  306. package/dist/utils/grants.cjs.map +1 -1
  307. package/dist/utils/grants.d.ts +93 -12
  308. package/dist/utils/grants.js.map +1 -1
  309. package/dist/utils/ipfs.cjs +2 -4
  310. package/dist/utils/ipfs.cjs.map +1 -1
  311. package/dist/utils/ipfs.d.ts +1 -1
  312. package/dist/utils/ipfs.js +2 -4
  313. package/dist/utils/ipfs.js.map +1 -1
  314. package/dist/utils/lazy-import.cjs.map +1 -1
  315. package/dist/utils/lazy-import.d.ts +32 -7
  316. package/dist/utils/lazy-import.js.map +1 -1
  317. package/dist/utils/signatureCache.cjs +8 -2
  318. package/dist/utils/signatureCache.cjs.map +1 -1
  319. package/dist/utils/signatureCache.d.ts +49 -8
  320. package/dist/utils/signatureCache.js +8 -2
  321. package/dist/utils/signatureCache.js.map +1 -1
  322. package/dist/utils/subgraphConsistency.cjs +184 -0
  323. package/dist/utils/subgraphConsistency.cjs.map +1 -0
  324. package/dist/utils/subgraphConsistency.d.ts +65 -0
  325. package/dist/utils/subgraphConsistency.js +155 -0
  326. package/dist/utils/subgraphConsistency.js.map +1 -0
  327. package/dist/utils/subgraphMetaCache.cjs +101 -0
  328. package/dist/utils/subgraphMetaCache.cjs.map +1 -0
  329. package/dist/utils/subgraphMetaCache.d.ts +56 -0
  330. package/dist/utils/subgraphMetaCache.js +76 -0
  331. package/dist/utils/subgraphMetaCache.js.map +1 -0
  332. package/dist/utils/subgraphPagination.cjs +104 -0
  333. package/dist/utils/subgraphPagination.cjs.map +1 -0
  334. package/dist/utils/subgraphPagination.d.ts +78 -0
  335. package/dist/utils/subgraphPagination.js +78 -0
  336. package/dist/utils/subgraphPagination.js.map +1 -0
  337. package/dist/utils/transactionHelpers.cjs.map +1 -1
  338. package/dist/utils/transactionHelpers.d.ts +12 -12
  339. package/dist/utils/transactionHelpers.js.map +1 -1
  340. package/dist/utils/typedDataConverter.cjs.map +1 -1
  341. package/dist/utils/typedDataConverter.d.ts +39 -3
  342. package/dist/utils/typedDataConverter.js.map +1 -1
  343. package/dist/utils/urlResolver.cjs +7 -0
  344. package/dist/utils/urlResolver.cjs.map +1 -1
  345. package/dist/utils/urlResolver.d.ts +22 -4
  346. package/dist/utils/urlResolver.js +7 -0
  347. package/dist/utils/urlResolver.js.map +1 -1
  348. package/dist/utils/wallet.cjs.map +1 -1
  349. package/dist/utils/wallet.d.ts +78 -16
  350. package/dist/utils/wallet.js.map +1 -1
  351. package/package.json +3 -1
@@ -1,15 +1,30 @@
1
1
  import { getContract } from "viem";
2
+ import { PollingManager } from "../core/pollingManager";
2
3
  import { BaseController } from "./base";
3
4
  import { getContractAddress } from "../config/addresses";
4
5
  import { getAbi } from "../generated/abi";
6
+ import { InvalidConfigurationError } from "../errors";
5
7
  import {
6
- GetUserFilesDocument,
8
+ GetUserFilesPaginatedDocument,
7
9
  GetFileProofsDocument,
8
10
  GetDlpDocument,
9
- GetUserPermissionsDocument,
10
- GetUserTrustedServersDocument
11
+ GetUserPermissionsPaginatedDocument,
12
+ GetUserTrustedServersPaginatedDocument
11
13
  } from "../generated/subgraph";
12
14
  import { print } from "graphql";
15
+ import {
16
+ checkSubgraphConsistency,
17
+ fetchSubgraphMeta
18
+ } from "../utils/subgraphConsistency";
19
+ import {
20
+ executePaginatedQuery,
21
+ mapOrderByToEnum,
22
+ mapOrderDirection
23
+ } from "../utils/subgraphPagination";
24
+ import {
25
+ getUserFilesFromChain,
26
+ determineDataSource
27
+ } from "../utils/chainQuery";
13
28
  import {
14
29
  generateEncryptionKey,
15
30
  decryptBlobWithSignedKey,
@@ -37,12 +52,18 @@ class DataController extends BaseController {
37
52
  permissions = [],
38
53
  encrypt = true,
39
54
  providerName,
40
- owner
55
+ owner,
56
+ schemaValidation = "strict"
41
57
  } = params;
58
+ if (encrypt && owner && owner.toLowerCase() !== this.context.userAddress.toLowerCase()) {
59
+ throw new InvalidConfigurationError(
60
+ "The 'owner' parameter cannot be different from the connected wallet's address when encryption is enabled. This would create an un-decryptable file."
61
+ );
62
+ }
42
63
  try {
43
64
  let isValid = true;
44
65
  let validationErrors = [];
45
- if (schemaId !== void 0) {
66
+ if (schemaId !== void 0 && schemaValidation !== "skip") {
46
67
  try {
47
68
  const { SchemaController } = await import("./schemas");
48
69
  const schemaController = new SchemaController(this.context);
@@ -66,15 +87,20 @@ class DataController extends BaseController {
66
87
  }
67
88
  validateDataAgainstSchema(parsedContent, schema);
68
89
  } catch (error) {
69
- isValid = false;
70
- if (error instanceof Error) {
71
- if (typeof error === "object" && "errors" in error && Array.isArray(error.errors)) {
72
- validationErrors = error.errors;
73
- } else {
74
- validationErrors = [error.message];
90
+ if (schemaValidation === "strict") {
91
+ throw error;
92
+ } else if (schemaValidation === "warn") {
93
+ console.warn(
94
+ '[Vana SDK] Schema validation failed, but continuing due to validation mode "warn"'
95
+ );
96
+ if (error instanceof Error) {
97
+ console.warn(" Validation error:", error.message);
98
+ if (typeof error === "object" && "errors" in error && Array.isArray(error.errors)) {
99
+ console.warn(" Detailed errors:", error.errors);
100
+ }
75
101
  }
76
- } else {
77
- validationErrors = ["Schema validation failed"];
102
+ isValid = false;
103
+ validationErrors = error instanceof Error ? [error.message] : ["Schema validation failed"];
78
104
  }
79
105
  }
80
106
  }
@@ -124,10 +150,17 @@ class DataController extends BaseController {
124
150
  if (response.type === "error") {
125
151
  throw new Error(response.error);
126
152
  }
127
- if (response.type !== "direct" || !("fileId" in response.result)) {
153
+ if (response.type === "pending") {
154
+ result = await this.pollRelayerForConfirmation(
155
+ response.operationId,
156
+ void 0
157
+ // TODO: Add TransactionOptions to upload method signature
158
+ );
159
+ } else if (response.type === "direct" && typeof response.result === "object" && response.result !== null && "fileId" in response.result) {
160
+ result = response.result;
161
+ } else {
128
162
  throw new Error("Invalid response from relayer");
129
163
  }
130
- result = response.result;
131
164
  } else {
132
165
  const txResult = await this.addFileWithEncryptedPermissionsAndSchema(
133
166
  uploadResult.url,
@@ -242,35 +275,33 @@ class DataController extends BaseController {
242
275
  }
243
276
  }
244
277
  /**
245
- * Decrypts a file owned by the user using their wallet signature.
278
+ * Decrypts a file using wallet-derived decryption key.
246
279
  *
247
280
  * @remarks
248
- * This is the high-level convenience method for decrypting user files, serving as the
249
- * symmetrical counterpart to the `upload` method. It handles the complete decryption
250
- * workflow including key generation, URL protocol detection, content fetching, and
251
- * decryption.
281
+ * Counterpart to `upload()` for decrypting user files. Automatically
282
+ * generates decryption key from wallet, fetches encrypted content,
283
+ * and decrypts. Supports IPFS (with gateway fallback) and HTTP URLs.
284
+ *
285
+ * @param file - UserFile object from `getUserFiles()`
286
+ * @param options - Decryption options
287
+ * @param options.seed - Custom encryption seed.
288
+ * Defaults to standard Vana seed.
289
+ *
290
+ * @returns Decrypted content as Blob
291
+ *
292
+ * @throws {Error} No wallet connected.
293
+ * Connect wallet before decrypting.
294
+ * @throws {Error} Network error accessing file.
295
+ * Check CORS settings or server availability.
296
+ * @throws {Error} File not found (404).
297
+ * File no longer available at stored URL.
298
+ * @throws {Error} Access denied (403).
299
+ * No permission to access file.
300
+ * @throws {Error} Invalid file format.
301
+ * File not encrypted with Vana protocol.
302
+ * @throws {Error} Wrong encryption key.
303
+ * Verify seed matches upload or use default.
252
304
  *
253
- * The method automatically:
254
- * - Generates the decryption key from the user's wallet signature
255
- * - Determines the appropriate fetch method based on the file URL protocol
256
- * - Fetches the encrypted content from IPFS or standard HTTP URLs
257
- * - Decrypts the content using the generated key
258
- *
259
- * For IPFS URLs, the method uses gateway fallback for improved reliability. For
260
- * standard HTTP URLs, it uses a simple fetch. If you need custom authentication
261
- * headers or specific gateway configurations, use the low-level primitives directly.
262
- *
263
- * @param file - The user file to decrypt (typically from getUserFiles)
264
- * @param encryptionSeed - Optional custom encryption seed (defaults to Vana standard)
265
- * @returns Promise resolving to the decrypted file content as a Blob
266
- * @throws {Error} "No addresses available in wallet client" - When wallet is not connected
267
- * @throws {Error} "Network error: Cannot access the file URL" - When file URL is inaccessible (CORS, server down)
268
- * @throws {Error} "File not found: The encrypted file is no longer available" - When file returns 404
269
- * @throws {Error} "Access denied" - When file returns 403 (no permission)
270
- * @throws {Error} "File is empty or could not be retrieved" - When file has no content
271
- * @throws {Error} "Invalid file format: This file doesn't appear to be encrypted with the Vana protocol" - When file is not properly encrypted
272
- * @throws {Error} "Wrong encryption key" - When decryption fails due to incorrect key/seed
273
- * @throws {Error} "Failed to decrypt file: {error}" - General decryption failures
274
305
  * @example
275
306
  * ```typescript
276
307
  * // Basic file decryption
@@ -386,99 +417,126 @@ class DataController extends BaseController {
386
417
  }
387
418
  }
388
419
  /**
389
- * Retrieves all data files owned by a specific user address.
420
+ * Retrieves all files owned by a specific user address.
390
421
  *
391
422
  * @remarks
392
- * This method queries the Vana subgraph to find files directly owned by the user.
393
- * It efficiently handles large datasets by using the File entity's owner field
394
- * and returns complete file metadata without additional contract calls.
395
- *
396
- * **Deduplication Behavior:**
397
- * The method automatically deduplicates files by ID, keeping only the latest version
398
- * (highest timestamp) when duplicate file IDs are found. This handles cases where
399
- * the subgraph may contain multiple entries for the same file due to re-indexing
400
- * or blockchain reorganizations.
401
- * @param params - The query parameters object
402
- * @param params.owner - The wallet address of the file owner to query
403
- * @param params.subgraphUrl - Optional subgraph URL to override the default endpoint
404
- * @returns A Promise that resolves to an array of UserFile objects with metadata, sorted by latest timestamp first
405
- * @throws {Error} When subgraphUrl is not provided and not configured - "subgraphUrl is required"
406
- * @throws {Error} When subgraph request fails - "Subgraph request failed: {status} {statusText}"
407
- * @throws {Error} When subgraph returns errors - "Subgraph errors: {error messages}"
408
- * @throws {Error} When JSON parsing fails - "Failed to fetch user files from subgraph: {error}"
423
+ * Queries the Vana subgraph for files owned by the specified address.
424
+ * Automatically deduplicates by file ID, keeping the latest version
425
+ * when duplicates exist from re-indexing or chain reorganizations.
426
+ * Enriches results with DLP proof data when available.
427
+ *
428
+ * @param params - Query configuration
429
+ * @param params.owner - Wallet address of the file owner
430
+ * @param params.subgraphUrl - Subgraph endpoint override.
431
+ * Defaults to context configuration.
432
+ *
433
+ * @returns Array of UserFile objects sorted by timestamp (newest first)
434
+ *
435
+ * @throws {Error} Subgraph URL not configured.
436
+ * Provide `subgraphUrl` parameter or configure in Vana constructor.
437
+ * @throws {Error} Subgraph request failed.
438
+ * Check network connectivity and subgraph availability.
439
+ * @throws {Error} Subgraph returned errors.
440
+ * Review query parameters and subgraph logs.
441
+ *
409
442
  * @example
410
443
  * ```typescript
411
- * // Query files for a specific user
412
444
  * const files = await vana.data.getUserFiles({
413
- * owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
445
+ * owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
414
446
  * });
415
447
  *
416
448
  * files.forEach(file => {
417
- * console.log(`File ${file.id}: ${file.url} (Schema: ${file.schemaId})`);
449
+ * console.log(`File ${file.id}: ${file.url}`);
450
+ * console.log(` Schema: ${file.schemaId}`);
451
+ * console.log(` DLPs: ${file.dlpIds?.join(", ") || "none"}`);
418
452
  * });
419
453
  * ```
420
454
  */
421
- async getUserFiles(params) {
455
+ async getUserFiles(params, options) {
422
456
  const { owner, subgraphUrl } = params;
457
+ let dataSource = options?.source === "chain" ? "chain" : "subgraph";
458
+ if (options?.source === "auto" || !options?.source && options?.minBlock) {
459
+ const endpoint2 = subgraphUrl ?? this.context.subgraphUrl;
460
+ const currentBlock = await this.context.publicClient.getBlockNumber();
461
+ let subgraphBlock;
462
+ if (endpoint2) {
463
+ try {
464
+ const meta = await fetchSubgraphMeta(endpoint2);
465
+ subgraphBlock = meta.blockNumber;
466
+ } catch {
467
+ subgraphBlock = void 0;
468
+ }
469
+ }
470
+ dataSource = determineDataSource(
471
+ options?.source,
472
+ options?.minBlock,
473
+ currentBlock,
474
+ subgraphBlock
475
+ );
476
+ }
477
+ if (dataSource === "chain") {
478
+ const publicClient = this.context.publicClient;
479
+ const chainId = await publicClient.getChainId();
480
+ const contractAddress = getContractAddress(chainId, "DataRegistry");
481
+ const files = await getUserFilesFromChain(
482
+ publicClient,
483
+ contractAddress,
484
+ owner,
485
+ options?.minBlock ? BigInt(options.minBlock) : void 0
486
+ );
487
+ const limit = options?.fetchAll ? files.length : options?.limit ?? 100;
488
+ const offset = options?.offset ?? 0;
489
+ return files.slice(offset, offset + limit);
490
+ }
423
491
  const endpoint = subgraphUrl ?? this.context.subgraphUrl;
424
492
  if (!endpoint) {
425
493
  throw new Error(
426
494
  "subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor."
427
495
  );
428
496
  }
497
+ if (options?.minBlock || options?.waitForSync) {
498
+ await checkSubgraphConsistency(endpoint, options);
499
+ }
429
500
  try {
430
- const response = await fetch(endpoint, {
431
- method: "POST",
432
- headers: {
433
- "Content-Type": "application/json"
501
+ const orderByMap = {
502
+ id: "id",
503
+ addedAtBlock: "addedAtBlock",
504
+ addedAtTimestamp: "addedAtTimestamp",
505
+ url: "url",
506
+ schemaId: "schemaId"
507
+ };
508
+ const allFiles = await executePaginatedQuery({
509
+ endpoint,
510
+ document: GetUserFilesPaginatedDocument,
511
+ baseVariables: {
512
+ userId: owner.toLowerCase(),
513
+ // Subgraph requires lowercase addresses
514
+ orderBy: mapOrderByToEnum(
515
+ options?.orderBy,
516
+ orderByMap,
517
+ "addedAtBlock"
518
+ ),
519
+ orderDirection: mapOrderDirection(
520
+ options?.orderDirection,
521
+ "asc",
522
+ "desc"
523
+ )
434
524
  },
435
- body: JSON.stringify({
436
- query: print(GetUserFilesDocument),
437
- variables: {
438
- userId: owner.toLowerCase()
439
- // Subgraph requires lowercase addresses
440
- }
441
- })
442
- });
443
- if (!response.ok) {
444
- throw new Error(
445
- `Subgraph request failed: ${response.status} ${response.statusText}`
446
- );
447
- }
448
- const result = await response.json();
449
- if (result.errors) {
450
- throw new Error(
451
- `Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
452
- );
453
- }
454
- const user = result.data?.user;
455
- if (!user?.files?.length) {
456
- console.warn("No files found for user:", owner);
457
- return [];
458
- }
459
- const fileMap = /* @__PURE__ */ new Map();
460
- user.files.forEach((file) => {
461
- const fileId = parseInt(file.id);
462
- const userFile = {
463
- id: fileId,
525
+ options,
526
+ extractItems: (data) => data?.user?.files,
527
+ transformItem: (file) => ({
528
+ id: parseInt(file.id),
464
529
  url: file.url,
465
530
  ownerAddress: file.owner.id,
466
531
  addedAtBlock: BigInt(file.addedAtBlock),
467
532
  schemaId: parseInt(file.schemaId),
468
533
  addedAtTimestamp: BigInt(file.addedAtTimestamp),
469
534
  transactionHash: file.transactionHash
470
- };
471
- const existing = fileMap.get(fileId);
472
- if (!existing || userFile.addedAtTimestamp && existing.addedAtTimestamp && userFile.addedAtTimestamp > existing.addedAtTimestamp) {
473
- fileMap.set(fileId, userFile);
474
- }
535
+ })
475
536
  });
476
- const userFiles = Array.from(fileMap.values()).sort(
477
- (a, b) => Number((b.addedAtTimestamp ?? 0n) - (a.addedAtTimestamp ?? 0n))
478
- );
479
- if (userFiles.length > 0) {
537
+ if (allFiles.length > 0) {
480
538
  try {
481
- const fileIds = userFiles.map((f) => f.id);
539
+ const fileIds = allFiles.map((f) => f.id);
482
540
  let proofMap;
483
541
  try {
484
542
  proofMap = await this._fetchProofsFromSubgraph(fileIds, endpoint);
@@ -489,7 +547,7 @@ class DataController extends BaseController {
489
547
  );
490
548
  proofMap = await this._fetchProofsFromChain(fileIds);
491
549
  }
492
- for (const file of userFiles) {
550
+ for (const file of allFiles) {
493
551
  const dlpIds = proofMap.get(file.id);
494
552
  if (dlpIds && dlpIds.length > 0) {
495
553
  file.dlpIds = dlpIds;
@@ -499,7 +557,7 @@ class DataController extends BaseController {
499
557
  console.warn("Failed to fetch proof data for files:", error);
500
558
  }
501
559
  }
502
- return userFiles;
560
+ return allFiles;
503
561
  } catch (error) {
504
562
  console.error("Failed to fetch user files from subgraph:", error);
505
563
  throw new Error(
@@ -625,6 +683,9 @@ class DataController extends BaseController {
625
683
  */
626
684
  async getDLP(dlpId, options = {}) {
627
685
  const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
686
+ if (subgraphUrl && (options.minBlock || options.waitForSync)) {
687
+ await checkSubgraphConsistency(subgraphUrl, options);
688
+ }
628
689
  if (subgraphUrl) {
629
690
  try {
630
691
  const response = await fetch(subgraphUrl, {
@@ -843,21 +904,33 @@ class DataController extends BaseController {
843
904
  * @returns Promise resolving to an array of permission objects
844
905
  * @throws Error if both subgraph and RPC queries fail
845
906
  */
846
- async getUserPermissions(params) {
907
+ async getUserPermissions(params, options) {
847
908
  const { user, subgraphUrl } = params;
848
909
  const endpoint = subgraphUrl ?? this.context.subgraphUrl;
910
+ if (endpoint && (options?.minBlock || options?.waitForSync)) {
911
+ await checkSubgraphConsistency(endpoint, options);
912
+ }
849
913
  if (endpoint) {
850
914
  try {
851
- const permissions = await this._getUserPermissionsViaSubgraph({
852
- user,
853
- subgraphUrl: endpoint
854
- });
915
+ const permissions = await this._getUserPermissionsViaSubgraph(
916
+ {
917
+ user,
918
+ subgraphUrl: endpoint
919
+ },
920
+ options
921
+ );
855
922
  return permissions;
856
923
  } catch (error) {
857
924
  console.warn("Subgraph query failed, falling back to RPC:", error);
858
925
  }
859
926
  }
860
- return await this._getUserPermissionsViaRpc({ user });
927
+ const allPermissions = await this._getUserPermissionsViaRpc({ user });
928
+ if (options && !options.fetchAll) {
929
+ const limit = options.limit ?? 100;
930
+ const offset = options.offset ?? 0;
931
+ return allPermissions.slice(offset, offset + limit);
932
+ }
933
+ return allPermissions;
861
934
  }
862
935
  /**
863
936
  * Internal method: Query user permissions via subgraph
@@ -867,46 +940,48 @@ class DataController extends BaseController {
867
940
  * @param params.subgraphUrl - The subgraph URL endpoint to query
868
941
  * @returns Promise resolving to an array of permission objects
869
942
  */
870
- async _getUserPermissionsViaSubgraph(params) {
943
+ async _getUserPermissionsViaSubgraph(params, options) {
871
944
  const { user, subgraphUrl } = params;
872
945
  try {
873
- const response = await fetch(subgraphUrl, {
874
- method: "POST",
875
- headers: {
876
- "Content-Type": "application/json"
946
+ const orderByMap = {
947
+ id: "id",
948
+ addedAtBlock: "addedAtBlock",
949
+ addedAtTimestamp: "addedAtTimestamp",
950
+ grant: "grant",
951
+ nonce: "nonce",
952
+ startBlock: "startBlock",
953
+ endBlock: "endBlock"
954
+ };
955
+ const permissions = await executePaginatedQuery({
956
+ endpoint: subgraphUrl,
957
+ document: GetUserPermissionsPaginatedDocument,
958
+ baseVariables: {
959
+ userId: user.toLowerCase(),
960
+ orderBy: mapOrderByToEnum(
961
+ options?.orderBy,
962
+ orderByMap,
963
+ "addedAtTimestamp"
964
+ ),
965
+ orderDirection: mapOrderDirection(
966
+ options?.orderDirection,
967
+ "desc",
968
+ "asc"
969
+ )
877
970
  },
878
- body: JSON.stringify({
879
- query: print(GetUserPermissionsDocument),
880
- variables: {
881
- userId: user.toLowerCase()
882
- }
971
+ options,
972
+ extractItems: (data) => data?.user?.permissions,
973
+ transformItem: (permission) => ({
974
+ id: permission.id,
975
+ grant: permission.grant,
976
+ nonce: BigInt(permission.nonce),
977
+ signature: permission.signature,
978
+ addedAtBlock: BigInt(permission.addedAtBlock),
979
+ addedAtTimestamp: BigInt(permission.addedAtTimestamp),
980
+ transactionHash: permission.transactionHash,
981
+ user
883
982
  })
884
983
  });
885
- if (!response.ok) {
886
- throw new Error(
887
- `Subgraph request failed: ${response.status} ${response.statusText}`
888
- );
889
- }
890
- const result = await response.json();
891
- if (result.errors) {
892
- throw new Error(
893
- `Subgraph query errors: ${result.errors.map((e) => e.message).join(", ")}`
894
- );
895
- }
896
- const userData = result.data?.user;
897
- if (!userData?.permissions?.length) {
898
- return [];
899
- }
900
- return userData.permissions.map((permission) => ({
901
- id: permission.id,
902
- grant: permission.grant,
903
- nonce: BigInt(permission.nonce),
904
- signature: permission.signature,
905
- addedAtBlock: BigInt(permission.addedAtBlock),
906
- addedAtTimestamp: BigInt(permission.addedAtTimestamp),
907
- transactionHash: permission.transactionHash,
908
- user
909
- })).sort((a, b) => Number(b.addedAtTimestamp - a.addedAtTimestamp));
984
+ return permissions;
910
985
  } catch (error) {
911
986
  console.error("Failed to query user permissions from subgraph:", error);
912
987
  throw error;
@@ -1039,20 +1114,28 @@ class DataController extends BaseController {
1039
1114
  * });
1040
1115
  * ```
1041
1116
  */
1042
- async getUserTrustedServers(params) {
1043
- const { user, limit = 50, offset = 0 } = params;
1117
+ async getUserTrustedServers(params, options) {
1118
+ const { user } = params;
1044
1119
  const subgraphUrl = params.subgraphUrl ?? this.context.subgraphUrl;
1120
+ if (subgraphUrl && (options?.minBlock || options?.waitForSync)) {
1121
+ await checkSubgraphConsistency(subgraphUrl, options);
1122
+ }
1045
1123
  if (subgraphUrl) {
1046
1124
  try {
1047
- const servers = await this._getUserTrustedServersViaSubgraph({
1048
- user,
1049
- subgraphUrl
1050
- });
1051
- return limit ? servers.slice(offset, offset + limit) : servers;
1125
+ const servers = await this._getUserTrustedServersViaSubgraph(
1126
+ {
1127
+ user,
1128
+ subgraphUrl
1129
+ },
1130
+ options
1131
+ );
1132
+ return servers;
1052
1133
  } catch (error) {
1053
1134
  console.warn("Subgraph query failed, falling back to RPC:", error);
1054
1135
  }
1055
1136
  }
1137
+ const limit = options?.fetchAll ? Number.MAX_SAFE_INTEGER : options?.limit ?? 100;
1138
+ const offset = options?.offset ?? 0;
1056
1139
  const rpcResult = await this._getUserTrustedServersViaRpc({
1057
1140
  user,
1058
1141
  limit,
@@ -1068,7 +1151,7 @@ class DataController extends BaseController {
1068
1151
  * @param params.subgraphUrl - The subgraph URL endpoint to query
1069
1152
  * @returns Promise resolving to an array of trusted server objects
1070
1153
  */
1071
- async _getUserTrustedServersViaSubgraph(params) {
1154
+ async _getUserTrustedServersViaSubgraph(params, options) {
1072
1155
  const { user, subgraphUrl } = params;
1073
1156
  const graphqlEndpoint = subgraphUrl;
1074
1157
  if (!graphqlEndpoint) {
@@ -1077,42 +1160,46 @@ class DataController extends BaseController {
1077
1160
  );
1078
1161
  }
1079
1162
  try {
1080
- const response = await fetch(graphqlEndpoint, {
1081
- method: "POST",
1082
- headers: {
1083
- "Content-Type": "application/json"
1163
+ const orderByMap = {
1164
+ id: "id",
1165
+ trustedAt: "trustedAt",
1166
+ trustedAtBlock: "trustedAtBlock",
1167
+ server: "server",
1168
+ user: "user"
1169
+ };
1170
+ const serverTrusts = await executePaginatedQuery({
1171
+ endpoint: graphqlEndpoint,
1172
+ document: GetUserTrustedServersPaginatedDocument,
1173
+ baseVariables: {
1174
+ userId: user.toLowerCase(),
1175
+ // Subgraph requires lowercase addresses
1176
+ orderBy: mapOrderByToEnum(
1177
+ options?.orderBy,
1178
+ orderByMap,
1179
+ "trustedAtBlock"
1180
+ ),
1181
+ orderDirection: mapOrderDirection(
1182
+ options?.orderDirection,
1183
+ "desc",
1184
+ "asc"
1185
+ )
1084
1186
  },
1085
- body: JSON.stringify({
1086
- query: print(GetUserTrustedServersDocument),
1087
- variables: {
1088
- userId: user.toLowerCase()
1089
- // Subgraph requires lowercase addresses
1090
- }
1187
+ options,
1188
+ extractItems: (data) => {
1189
+ const trusts = data?.user?.serverTrusts ?? [];
1190
+ return trusts.filter((trust) => !trust.untrustedAtBlock);
1191
+ },
1192
+ transformItem: (trust) => ({
1193
+ id: trust.server.id,
1194
+ serverAddress: trust.server.serverAddress,
1195
+ serverUrl: trust.server.url,
1196
+ trustedAt: BigInt(trust.trustedAt),
1197
+ user,
1198
+ name: ""
1199
+ // Not available in new schema, will be empty
1091
1200
  })
1092
1201
  });
1093
- if (!response.ok) {
1094
- throw new Error(
1095
- `Subgraph request failed: ${response.status} ${response.statusText}`
1096
- );
1097
- }
1098
- const result = await response.json();
1099
- if (result.errors) {
1100
- throw new Error(
1101
- `Subgraph query errors: ${result.errors.map((e) => e.message).join(", ")}`
1102
- );
1103
- }
1104
- if (!result.data?.user) {
1105
- return [];
1106
- }
1107
- return (result.data.user.serverTrusts ?? []).filter((trust) => !trust.untrustedAtBlock).map((trust) => ({
1108
- id: trust.server.id,
1109
- serverAddress: trust.server.serverAddress,
1110
- serverUrl: trust.server.url,
1111
- trustedAt: BigInt(trust.trustedAt),
1112
- user,
1113
- name: ""
1114
- // Not available in new schema, will be empty
1115
- }));
1202
+ return serverTrusts;
1116
1203
  } catch (error) {
1117
1204
  console.error("Failed to query trusted servers from subgraph:", error);
1118
1205
  throw error;
@@ -1214,18 +1301,26 @@ class DataController extends BaseController {
1214
1301
  }
1215
1302
  }
1216
1303
  /**
1217
- * Gets the total number of files in the registry from the contract.
1304
+ * Retrieves total file count from Data Registry.
1305
+ *
1306
+ * @remarks
1307
+ * Queries blockchain for complete file count across all users.
1308
+ * Useful for pagination and network statistics.
1309
+ *
1310
+ * @returns Total number of registered files
1311
+ *
1312
+ * @throws {Error} Chain ID not available.
1313
+ * Ensure network connection.
1314
+ * @throws {Error} Contract read failed.
1315
+ * Check RPC availability.
1218
1316
  *
1219
- * @returns Promise resolving to the total file count
1220
1317
  * @example
1221
1318
  * ```typescript
1222
- * const totalFiles = await vana.data.getTotalFilesCount();
1223
- * console.log(`Total files in registry: ${totalFiles}`);
1319
+ * const total = await vana.data.getTotalFilesCount();
1320
+ * console.log(`Total files: ${total}`);
1224
1321
  *
1225
- * // Use for pagination calculations
1226
- * const filesPerPage = 20;
1227
- * const totalPages = Math.ceil(totalFiles / filesPerPage);
1228
- * console.log(`Total pages: ${totalPages}`);
1322
+ * // Calculate pagination
1323
+ * const pages = Math.ceil(total / 20);
1229
1324
  * ```
1230
1325
  */
1231
1326
  async getTotalFilesCount() {
@@ -1252,32 +1347,32 @@ class DataController extends BaseController {
1252
1347
  }
1253
1348
  }
1254
1349
  /**
1255
- * Retrieves details for a specific file by its ID.
1350
+ * Retrieves file metadata by ID from the blockchain.
1351
+ *
1352
+ * @remarks
1353
+ * Queries DataRegistry contract directly for file details.
1354
+ * Works for any file ID regardless of ownership, enabling
1355
+ * cross-user file discovery and verification.
1356
+ *
1357
+ * @param fileId - Numeric file ID to retrieve
1358
+ *
1359
+ * @returns UserFile object with metadata
1360
+ *
1361
+ * @throws {Error} Chain ID not available.
1362
+ * Ensure proper network connection.
1363
+ * @throws {Error} File not found.
1364
+ * Verify file ID exists on-chain.
1365
+ * @throws {Error} Contract call failed.
1366
+ * Check network and RPC availability.
1256
1367
  *
1257
- * @param fileId - The file ID to look up
1258
- * @returns Promise resolving to UserFile object
1259
- * @throws {Error} "Chain ID not available" - When wallet chain is not configured
1260
- * @throws {Error} "File not found" - When file ID doesn't exist or returns empty data
1261
- * @throws {Error} "Failed to fetch file {fileId}: {error}" - General contract read failures
1262
1368
  * @example
1263
1369
  * ```typescript
1264
- * try {
1265
- * const file = await vana.data.getFileById(123);
1266
- * console.log('File details:', {
1267
- * id: file.id,
1268
- * url: file.url,
1269
- * owner: file.ownerAddress,
1270
- * addedAt: file.addedAtBlock
1271
- * });
1272
- * } catch (error) {
1273
- * console.error('File not found or error retrieving file:', error);
1274
- * }
1370
+ * const file = await vana.data.getFileById(123);
1371
+ * console.log(`File ${file.id}:`);
1372
+ * console.log(` URL: ${file.url}`);
1373
+ * console.log(` Owner: ${file.ownerAddress}`);
1374
+ * console.log(` Block: ${file.addedAtBlock}`);
1275
1375
  * ```
1276
- *
1277
- * This method queries the DataRegistry contract directly
1278
- * to get file details for any file ID, regardless of user ownership.
1279
- * This is useful for file lookup functionality where users can search
1280
- * for specific files by ID.
1281
1376
  */
1282
1377
  async getFileById(fileId) {
1283
1378
  try {
@@ -1348,7 +1443,7 @@ class DataController extends BaseController {
1348
1443
  * console.log(`File ${fileId} registered with schema in tx ${transactionHash}`);
1349
1444
  * ```
1350
1445
  */
1351
- async registerFileWithSchema(url, schemaId) {
1446
+ async registerFileWithSchema(url, schemaId, options) {
1352
1447
  this.assertWallet();
1353
1448
  try {
1354
1449
  const chainId = this.context.publicClient.chain?.id;
@@ -1366,7 +1461,8 @@ class DataController extends BaseController {
1366
1461
  functionName: "addFileWithSchema",
1367
1462
  args: [url, BigInt(schemaId)],
1368
1463
  account,
1369
- chain: this.context.walletClient.chain ?? null
1464
+ chain: this.context.walletClient.chain ?? null,
1465
+ ...this.spreadTransactionOptions(options)
1370
1466
  });
1371
1467
  const { tx } = await import("../utils/transactionHelpers");
1372
1468
  return tx({
@@ -1404,7 +1500,7 @@ class DataController extends BaseController {
1404
1500
  * with specific permissions on the DataRegistry contract. It can be used
1405
1501
  * by both direct transactions and relayer services.
1406
1502
  */
1407
- async addFileWithPermissions(url, ownerAddress, permissions = []) {
1503
+ async addFileWithPermissions(url, ownerAddress, permissions = [], options) {
1408
1504
  this.assertWallet();
1409
1505
  try {
1410
1506
  const chainId = this.context.publicClient.chain?.id;
@@ -1422,7 +1518,8 @@ class DataController extends BaseController {
1422
1518
  functionName: "addFileWithPermissions",
1423
1519
  args: [url, ownerAddress, permissions],
1424
1520
  account,
1425
- chain: this.context.walletClient.chain ?? null
1521
+ chain: this.context.walletClient.chain ?? null,
1522
+ ...this.spreadTransactionOptions(options)
1426
1523
  });
1427
1524
  const { tx } = await import("../utils/transactionHelpers");
1428
1525
  return tx({
@@ -1477,7 +1574,7 @@ class DataController extends BaseController {
1477
1574
  * console.log(`File ${result.fileId} registered in tx ${result.hash}`);
1478
1575
  * ```
1479
1576
  */
1480
- async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
1577
+ async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
1481
1578
  this.assertWallet();
1482
1579
  try {
1483
1580
  let encryptedPermissions = [];
@@ -1511,7 +1608,8 @@ class DataController extends BaseController {
1511
1608
  url,
1512
1609
  ownerAddress,
1513
1610
  encryptedPermissions,
1514
- schemaId
1611
+ schemaId,
1612
+ options
1515
1613
  );
1516
1614
  } catch (error) {
1517
1615
  console.error("Failed to add file with permissions and schema:", error);
@@ -1558,7 +1656,7 @@ class DataController extends BaseController {
1558
1656
  * console.log(`File registered in tx ${result.hash}`);
1559
1657
  * ```
1560
1658
  */
1561
- async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
1659
+ async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
1562
1660
  try {
1563
1661
  const chainId = this.context.publicClient.chain?.id;
1564
1662
  if (!chainId) {
@@ -1575,7 +1673,8 @@ class DataController extends BaseController {
1575
1673
  functionName: "addFileWithPermissionsAndSchema",
1576
1674
  args: [url, ownerAddress, permissions, BigInt(schemaId)],
1577
1675
  account,
1578
- chain: this.context.walletClient.chain ?? null
1676
+ chain: this.context.walletClient.chain ?? null,
1677
+ ...this.spreadTransactionOptions(options)
1579
1678
  });
1580
1679
  const { tx } = await import("../utils/transactionHelpers");
1581
1680
  return tx({
@@ -1592,34 +1691,38 @@ class DataController extends BaseController {
1592
1691
  }
1593
1692
  }
1594
1693
  /**
1595
- * Adds a new refiner to the DataRefinerRegistry.
1694
+ * Registers a data refiner for processing templates.
1596
1695
  *
1597
1696
  * @remarks
1598
- * Refiners are data processing templates that define how raw data should be
1599
- * transformed into structured formats. Each refiner is associated with a DLP
1600
- * (Data Liquidity Pool), has a specific schema for output, and includes
1601
- * instructions for the refinement process.
1602
- *
1603
- * @param params - Refiner configuration parameters
1604
- * @param params.dlpId - The Data Liquidity Pool ID this refiner belongs to
1605
- * @param params.name - Human-readable name for the refiner
1606
- * @param params.schemaId - Schema ID that defines the output format
1607
- * @param params.refinementInstructionUrl - URL containing processing instructions
1608
- * @returns Promise resolving to the new refiner ID and transaction hash
1609
- * @throws {Error} When chain ID is not available - "Chain ID not available"
1610
- * @throws {Error} When transaction fails - "Failed to add refiner: {error}"
1697
+ * Refiners define data transformation rules for DLPs.
1698
+ * Associates schema, instructions, and processing logic.
1699
+ *
1700
+ * @param params - Refiner configuration
1701
+ * @param params.dlpId - Data Liquidity Pool ID
1702
+ * @param params.name - Refiner display name
1703
+ * @param params.schemaId - Output schema ID.
1704
+ * Obtain via `vana.schemas.list()`.
1705
+ * @param params.refinementInstructionUrl - Processing instructions URL
1706
+ *
1707
+ * @returns Refiner ID and transaction hash
1708
+ *
1709
+ * @throws {Error} Chain ID not available.
1710
+ * Ensure network connection.
1711
+ * @throws {Error} Transaction failed.
1712
+ * Check wallet balance and network status.
1713
+ *
1611
1714
  * @example
1612
1715
  * ```typescript
1613
1716
  * const result = await vana.data.addRefiner({
1614
1717
  * dlpId: 1,
1615
- * name: "Social Media Sentiment Analyzer",
1718
+ * name: "Sentiment Analyzer",
1616
1719
  * schemaId: 42,
1617
1720
  * refinementInstructionUrl: "ipfs://QmXxx..."
1618
1721
  * });
1619
- * console.log(`Created refiner ${result.refinerId} in tx ${result.transactionHash}`);
1722
+ * console.log(`Refiner ${result.refinerId} created`);
1620
1723
  * ```
1621
1724
  */
1622
- async addRefiner(params) {
1725
+ async addRefiner(params, options) {
1623
1726
  this.assertWallet();
1624
1727
  try {
1625
1728
  const chainId = this.context.publicClient.chain?.id;
@@ -1645,7 +1748,8 @@ class DataController extends BaseController {
1645
1748
  params.refinementInstructionUrl
1646
1749
  ],
1647
1750
  account,
1648
- chain: this.context.walletClient.chain ?? null
1751
+ chain: this.context.walletClient.chain ?? null,
1752
+ ...this.spreadTransactionOptions(options)
1649
1753
  });
1650
1754
  const { tx } = await import("../utils/transactionHelpers");
1651
1755
  const txResult = tx({
@@ -1674,26 +1778,29 @@ class DataController extends BaseController {
1674
1778
  }
1675
1779
  }
1676
1780
  /**
1677
- * Retrieves a refiner by its ID.
1781
+ * Retrieves refiner configuration by ID.
1678
1782
  *
1679
1783
  * @remarks
1680
- * Queries the DataRefinerRegistry contract to get complete information about
1681
- * a specific refiner including its DLP association, schema, and instructions.
1784
+ * Queries DataRefinerRegistry for refiner details.
1785
+ * Returns DLP association, schema, and processing instructions.
1786
+ *
1787
+ * @param refinerId - Numeric refiner ID
1788
+ *
1789
+ * @returns Refiner configuration object
1790
+ *
1791
+ * @throws {Error} Chain ID not available.
1792
+ * Ensure network connection.
1793
+ * @throws {Error} Refiner not found.
1794
+ * Verify refiner ID exists.
1795
+ * @throws {Error} Contract read failed.
1796
+ * Check network and RPC status.
1682
1797
  *
1683
- * @param refinerId - The numeric refiner ID to retrieve
1684
- * @returns Promise resolving to the refiner information object
1685
- * @throws {Error} When chain ID is not available - "Chain ID not available"
1686
- * @throws {Error} When refiner doesn't exist - "Refiner with ID {refinerId} does not exist"
1687
- * @throws {Error} When contract read fails - "Failed to fetch refiner: {error}"
1688
1798
  * @example
1689
1799
  * ```typescript
1690
1800
  * const refiner = await vana.data.getRefiner(1);
1691
- * console.log({
1692
- * name: refiner.name,
1693
- * dlp: refiner.dlpId,
1694
- * schema: refiner.schemaId,
1695
- * instructions: refiner.refinementInstructionUrl
1696
- * });
1801
+ * console.log(`Refiner: ${refiner.name}`);
1802
+ * console.log(`DLP: ${refiner.dlpId}`);
1803
+ * console.log(`Schema: ${refiner.schemaId}`);
1697
1804
  * ```
1698
1805
  */
1699
1806
  async getRefiner(refinerId) {
@@ -1734,21 +1841,27 @@ class DataController extends BaseController {
1734
1841
  }
1735
1842
  }
1736
1843
  /**
1737
- * Validates if a schema ID exists in the registry.
1844
+ * Validates schema ID existence.
1738
1845
  *
1739
1846
  * @remarks
1740
- * Checks the DataRefinerRegistry contract to determine if a given schema ID
1741
- * has been registered and is available for use.
1847
+ * Verifies schema registration in DataRegistry.
1848
+ * Check before using schemas for uploads.
1849
+ *
1850
+ * @param schemaId - Numeric schema ID to validate
1851
+ *
1852
+ * @returns True if schema exists, false otherwise
1853
+ *
1854
+ * @throws {Error} Chain ID not available.
1855
+ * Ensure network connection.
1856
+ * @throws {Error} Contract read failed.
1857
+ * Check RPC availability.
1742
1858
  *
1743
- * @param schemaId - The numeric schema ID to validate
1744
- * @returns Promise resolving to true if schema exists, false otherwise
1745
1859
  * @example
1746
1860
  * ```typescript
1747
- * const isValid = await vana.data.isValidSchemaId(42);
1748
- * if (isValid) {
1749
- * console.log('Schema 42 is available for use');
1750
- * } else {
1751
- * console.log('Schema 42 does not exist');
1861
+ * const valid = await vana.data.isValidSchemaId(42);
1862
+ * if (valid) {
1863
+ * // Safe to use schema 42
1864
+ * await vana.data.upload({ schemaId: 42, ... });
1752
1865
  * }
1753
1866
  * ```
1754
1867
  */
@@ -1836,7 +1949,7 @@ class DataController extends BaseController {
1836
1949
  * console.log(`Schema updated in tx ${result.transactionHash}`);
1837
1950
  * ```
1838
1951
  */
1839
- async updateSchemaId(params) {
1952
+ async updateSchemaId(params, options) {
1840
1953
  this.assertWallet();
1841
1954
  try {
1842
1955
  const chainId = this.context.publicClient.chain?.id;
@@ -1856,7 +1969,8 @@ class DataController extends BaseController {
1856
1969
  functionName: "updateSchemaId",
1857
1970
  args: [BigInt(params.refinerId), BigInt(params.newSchemaId)],
1858
1971
  account,
1859
- chain: this.context.walletClient.chain ?? null
1972
+ chain: this.context.walletClient.chain ?? null,
1973
+ ...this.spreadTransactionOptions(options)
1860
1974
  });
1861
1975
  await this.context.publicClient.waitForTransactionReceipt({ hash });
1862
1976
  return {
@@ -1925,10 +2039,18 @@ class DataController extends BaseController {
1925
2039
  if (response.type === "error") {
1926
2040
  throw new Error(response.error);
1927
2041
  }
1928
- if (response.type !== "direct" || !("fileId" in response.result)) {
2042
+ let result;
2043
+ if (response.type === "pending") {
2044
+ result = await this.pollRelayerForConfirmation(
2045
+ response.operationId,
2046
+ void 0
2047
+ // TODO: Add TransactionOptions to upload method signature
2048
+ );
2049
+ } else if (response.type === "direct" && typeof response.result === "object" && response.result !== null && "fileId" in response.result) {
2050
+ result = response.result;
2051
+ } else {
1929
2052
  throw new Error("Invalid response from relayer");
1930
2053
  }
1931
- const result = response.result;
1932
2054
  return {
1933
2055
  fileId: result.fileId,
1934
2056
  url: uploadResult.url,
@@ -2017,7 +2139,15 @@ class DataController extends BaseController {
2017
2139
  );
2018
2140
  }
2019
2141
  }
2020
- const finalFilename = filename ?? `upload-${Date.now()}.dat`;
2142
+ const finalFilename = (() => {
2143
+ if (filename) {
2144
+ if (encrypt && !filename.endsWith(".enc")) {
2145
+ return `${filename}.enc`;
2146
+ }
2147
+ return filename;
2148
+ }
2149
+ return encrypt ? `upload-${Date.now()}.enc` : `upload-${Date.now()}.dat`;
2150
+ })();
2021
2151
  const uploadResult = await this.context.storageManager.upload(
2022
2152
  finalBlob,
2023
2153
  finalFilename,
@@ -2062,10 +2192,10 @@ class DataController extends BaseController {
2062
2192
  * console.log(`Transaction: ${result.transactionHash}`);
2063
2193
  * ```
2064
2194
  */
2065
- async addPermissionToFile(params) {
2195
+ async addPermissionToFile(params, options) {
2066
2196
  this.assertWallet();
2067
2197
  const { fileId, account, publicKey } = params;
2068
- return await this.submitFilePermission(fileId, account, publicKey);
2198
+ return await this.submitFilePermission(fileId, account, publicKey, options);
2069
2199
  }
2070
2200
  /**
2071
2201
  * Submits a file permission transaction to the blockchain.
@@ -2095,7 +2225,7 @@ class DataController extends BaseController {
2095
2225
  * console.log(`Permission granted with ID: ${result.permissionId}`);
2096
2226
  * ```
2097
2227
  */
2098
- async submitFilePermission(fileId, account, publicKey) {
2228
+ async submitFilePermission(fileId, account, publicKey, options) {
2099
2229
  this.assertWallet();
2100
2230
  try {
2101
2231
  const userEncryptionKey = await generateEncryptionKey(
@@ -2122,7 +2252,8 @@ class DataController extends BaseController {
2122
2252
  functionName: "addFilePermission",
2123
2253
  args: [BigInt(fileId), account, encryptedKey],
2124
2254
  account: walletAccount,
2125
- chain: this.context.walletClient.chain ?? null
2255
+ chain: this.context.walletClient.chain ?? null,
2256
+ ...this.spreadTransactionOptions(options)
2126
2257
  });
2127
2258
  const { tx } = await import("../utils/transactionHelpers");
2128
2259
  return tx({
@@ -2468,6 +2599,26 @@ class DataController extends BaseController {
2468
2599
  async fetchAndValidateSchema(url) {
2469
2600
  return fetchAndValidateSchema(url);
2470
2601
  }
2602
+ /**
2603
+ * Polls for confirmation of a relayer operation.
2604
+ * @internal
2605
+ */
2606
+ async pollRelayerForConfirmation(operationId, options) {
2607
+ if (!this.context.relayer) {
2608
+ throw new Error("Relayer not configured for polling");
2609
+ }
2610
+ const pollingManager = new PollingManager(this.context.relayer);
2611
+ const result = await pollingManager.startPolling(operationId, {
2612
+ signal: options?.signal,
2613
+ onStatusUpdate: options?.onStatusUpdate,
2614
+ ...options?.pollingOptions
2615
+ });
2616
+ return {
2617
+ fileId: 0,
2618
+ // This would need to be extracted from transaction events
2619
+ transactionHash: result.hash
2620
+ };
2621
+ }
2471
2622
  }
2472
2623
  export {
2473
2624
  DataController