@opendatalabs/vana-sdk 0.1.0-alpha.eebb656 → 0.1.0-alpha.ef15099

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 (545) hide show
  1. package/README.md +67 -351
  2. package/dist/browser.cjs.map +1 -1
  3. package/dist/browser.d.ts +33 -1
  4. package/dist/browser.js.map +1 -1
  5. package/dist/chains/definitions.cjs +9 -6
  6. package/dist/chains/definitions.cjs.map +1 -1
  7. package/dist/chains/definitions.d.ts +2 -0
  8. package/dist/chains/definitions.js +9 -6
  9. package/dist/chains/definitions.js.map +1 -1
  10. package/dist/chains/index.cjs.map +1 -1
  11. package/dist/chains/index.d.ts +30 -1
  12. package/dist/chains/index.js.map +1 -1
  13. package/dist/client/enhancedResponse.cjs +164 -0
  14. package/dist/client/enhancedResponse.cjs.map +1 -0
  15. package/dist/client/enhancedResponse.d.ts +120 -0
  16. package/dist/client/enhancedResponse.js +138 -0
  17. package/dist/client/enhancedResponse.js.map +1 -0
  18. package/dist/config/chains.cjs.map +1 -1
  19. package/dist/config/chains.d.ts +99 -0
  20. package/dist/config/chains.js.map +1 -1
  21. package/dist/config/contracts.config.cjs +400 -0
  22. package/dist/config/contracts.config.cjs.map +1 -0
  23. package/dist/config/contracts.config.d.ts +84 -0
  24. package/dist/config/contracts.config.js +375 -0
  25. package/dist/config/contracts.config.js.map +1 -0
  26. package/dist/config/default-services.cjs +60 -0
  27. package/dist/config/default-services.cjs.map +1 -0
  28. package/dist/config/default-services.d.ts +46 -0
  29. package/dist/config/default-services.js +33 -0
  30. package/dist/config/default-services.js.map +1 -0
  31. package/dist/config/default-services.test.d.ts +1 -0
  32. package/dist/contracts/contractController.cjs +1 -1
  33. package/dist/contracts/contractController.cjs.map +1 -1
  34. package/dist/contracts/contractController.d.ts +66 -10
  35. package/dist/contracts/contractController.js +1 -1
  36. package/dist/contracts/contractController.js.map +1 -1
  37. package/dist/controllers/__tests__/data-consistency-integration.test.d.ts +7 -0
  38. package/dist/controllers/__tests__/operations.processQueue.test.d.ts +1 -0
  39. package/dist/controllers/accessSettlement.cjs +289 -0
  40. package/dist/controllers/accessSettlement.cjs.map +1 -0
  41. package/dist/controllers/accessSettlement.d.ts +157 -0
  42. package/dist/controllers/accessSettlement.js +265 -0
  43. package/dist/controllers/accessSettlement.js.map +1 -0
  44. package/dist/controllers/accessSettlement.test.d.ts +1 -0
  45. package/dist/controllers/base.cjs +116 -0
  46. package/dist/controllers/base.cjs.map +1 -0
  47. package/dist/controllers/base.d.ts +94 -0
  48. package/dist/controllers/base.js +92 -0
  49. package/dist/controllers/base.js.map +1 -0
  50. package/dist/controllers/data.cjs +634 -352
  51. package/dist/controllers/data.cjs.map +1 -1
  52. package/dist/controllers/data.d.ts +348 -213
  53. package/dist/controllers/data.js +647 -355
  54. package/dist/controllers/data.js.map +1 -1
  55. package/dist/controllers/operations.cjs +430 -0
  56. package/dist/controllers/operations.cjs.map +1 -0
  57. package/dist/controllers/operations.d.ts +229 -0
  58. package/dist/controllers/operations.js +406 -0
  59. package/dist/controllers/operations.js.map +1 -0
  60. package/dist/controllers/permissions.cjs +943 -443
  61. package/dist/controllers/permissions.cjs.map +1 -1
  62. package/dist/controllers/permissions.d.ts +201 -120
  63. package/dist/controllers/permissions.js +943 -443
  64. package/dist/controllers/permissions.js.map +1 -1
  65. package/dist/controllers/protocol.cjs +14 -10
  66. package/dist/controllers/protocol.cjs.map +1 -1
  67. package/dist/controllers/protocol.d.ts +30 -31
  68. package/dist/controllers/protocol.js +14 -10
  69. package/dist/controllers/protocol.js.map +1 -1
  70. package/dist/controllers/runtimePermissions.cjs +272 -0
  71. package/dist/controllers/runtimePermissions.cjs.map +1 -0
  72. package/dist/controllers/runtimePermissions.d.ts +152 -0
  73. package/dist/controllers/runtimePermissions.js +251 -0
  74. package/dist/controllers/runtimePermissions.js.map +1 -0
  75. package/dist/controllers/runtimePermissions.test.d.ts +1 -0
  76. package/dist/controllers/schemas.cjs +113 -43
  77. package/dist/controllers/schemas.cjs.map +1 -1
  78. package/dist/controllers/schemas.d.ts +90 -43
  79. package/dist/controllers/schemas.js +113 -43
  80. package/dist/controllers/schemas.js.map +1 -1
  81. package/dist/controllers/server.cjs +276 -60
  82. package/dist/controllers/server.cjs.map +1 -1
  83. package/dist/controllers/server.d.ts +159 -54
  84. package/dist/controllers/server.js +276 -60
  85. package/dist/controllers/server.js.map +1 -1
  86. package/dist/core/__tests__/health.test.d.ts +1 -0
  87. package/dist/core/__tests__/inMemoryNonceManager.test.d.ts +1 -0
  88. package/dist/core/__tests__/nonceManager.test.d.ts +1 -0
  89. package/dist/core/__tests__/pollingManager.test.d.ts +4 -0
  90. package/dist/core/apiClient.cjs +53 -3
  91. package/dist/core/apiClient.cjs.map +1 -1
  92. package/dist/core/apiClient.d.ts +132 -7
  93. package/dist/core/apiClient.js +53 -3
  94. package/dist/core/apiClient.js.map +1 -1
  95. package/dist/core/generics.cjs +30 -3
  96. package/dist/core/generics.cjs.map +1 -1
  97. package/dist/core/generics.d.ts +95 -6
  98. package/dist/core/generics.js +30 -3
  99. package/dist/core/generics.js.map +1 -1
  100. package/dist/core/health.cjs +289 -0
  101. package/dist/core/health.cjs.map +1 -0
  102. package/dist/core/health.d.ts +143 -0
  103. package/dist/core/health.js +265 -0
  104. package/dist/core/health.js.map +1 -0
  105. package/dist/core/inMemoryNonceManager.cjs +138 -0
  106. package/dist/core/inMemoryNonceManager.cjs.map +1 -0
  107. package/dist/core/inMemoryNonceManager.d.ts +69 -0
  108. package/dist/core/inMemoryNonceManager.js +114 -0
  109. package/dist/core/inMemoryNonceManager.js.map +1 -0
  110. package/dist/core/nonceManager.cjs +304 -0
  111. package/dist/core/nonceManager.cjs.map +1 -0
  112. package/dist/core/nonceManager.d.ts +116 -0
  113. package/dist/core/nonceManager.js +280 -0
  114. package/dist/core/nonceManager.js.map +1 -0
  115. package/dist/core/pollingManager.cjs +292 -0
  116. package/dist/core/pollingManager.cjs.map +1 -0
  117. package/dist/core/pollingManager.d.ts +120 -0
  118. package/dist/core/pollingManager.js +268 -0
  119. package/dist/core/pollingManager.js.map +1 -0
  120. package/dist/core.cjs +164 -36
  121. package/dist/core.cjs.map +1 -1
  122. package/dist/core.d.ts +69 -10
  123. package/dist/core.js +167 -37
  124. package/dist/core.js.map +1 -1
  125. package/dist/crypto/ecies/__tests__/constants.test.d.ts +1 -1
  126. package/dist/crypto/ecies/__tests__/interface.test.d.ts +1 -0
  127. package/dist/crypto/ecies/__tests__/serialization.test.d.ts +8 -0
  128. package/dist/crypto/ecies/__tests__/utils.test.d.ts +1 -0
  129. package/dist/crypto/ecies/base.cjs +59 -23
  130. package/dist/crypto/ecies/base.cjs.map +1 -1
  131. package/dist/crypto/ecies/base.js +59 -23
  132. package/dist/crypto/ecies/base.js.map +1 -1
  133. package/dist/crypto/ecies/constants.cjs +2 -10
  134. package/dist/crypto/ecies/constants.cjs.map +1 -1
  135. package/dist/crypto/ecies/constants.d.ts +0 -9
  136. package/dist/crypto/ecies/constants.js +1 -8
  137. package/dist/crypto/ecies/constants.js.map +1 -1
  138. package/dist/crypto/ecies/interface.cjs +19 -2
  139. package/dist/crypto/ecies/interface.cjs.map +1 -1
  140. package/dist/crypto/ecies/interface.js +19 -2
  141. package/dist/crypto/ecies/interface.js.map +1 -1
  142. package/dist/errors.cjs +45 -0
  143. package/dist/errors.cjs.map +1 -1
  144. package/dist/errors.d.ts +104 -0
  145. package/dist/errors.js +43 -0
  146. package/dist/errors.js.map +1 -1
  147. package/dist/generated/abi/AccessSettlementImplementation.cjs +635 -0
  148. package/dist/generated/abi/AccessSettlementImplementation.cjs.map +1 -0
  149. package/dist/generated/abi/AccessSettlementImplementation.d.ts +468 -0
  150. package/dist/generated/abi/AccessSettlementImplementation.js +611 -0
  151. package/dist/generated/abi/AccessSettlementImplementation.js.map +1 -0
  152. package/dist/generated/abi/AttestationPolicyImplementation.cjs +614 -0
  153. package/dist/generated/abi/AttestationPolicyImplementation.cjs.map +1 -0
  154. package/dist/generated/abi/AttestationPolicyImplementation.d.ts +449 -0
  155. package/dist/generated/abi/AttestationPolicyImplementation.js +590 -0
  156. package/dist/generated/abi/AttestationPolicyImplementation.js.map +1 -0
  157. package/dist/generated/abi/ComputeEngineImplementation.cjs.map +1 -1
  158. package/dist/generated/abi/ComputeEngineImplementation.js.map +1 -1
  159. package/dist/generated/abi/{DLPTreasuryImplementation.cjs → ComputeEngineTreasuryImplementation.cjs} +16 -92
  160. package/dist/generated/abi/ComputeEngineTreasuryImplementation.cjs.map +1 -0
  161. package/dist/generated/abi/{DLPTreasuryImplementation.d.ts → ComputeEngineTreasuryImplementation.d.ts} +9 -67
  162. package/dist/generated/abi/{DLPTreasuryImplementation.js → ComputeEngineTreasuryImplementation.js} +12 -88
  163. package/dist/generated/abi/ComputeEngineTreasuryImplementation.js.map +1 -0
  164. package/dist/generated/abi/ComputeInstructionRegistryImplementation.cjs.map +1 -1
  165. package/dist/generated/abi/ComputeInstructionRegistryImplementation.js.map +1 -1
  166. package/dist/generated/abi/DATFactoryImplementation.cjs.map +1 -1
  167. package/dist/generated/abi/DATFactoryImplementation.js.map +1 -1
  168. package/dist/generated/abi/DATImplementation.cjs.map +1 -1
  169. package/dist/generated/abi/DATImplementation.js.map +1 -1
  170. package/dist/generated/abi/DATPausableImplementation.cjs.map +1 -1
  171. package/dist/generated/abi/DATPausableImplementation.js.map +1 -1
  172. package/dist/generated/abi/DATVotesImplementation.cjs.map +1 -1
  173. package/dist/generated/abi/DATVotesImplementation.js.map +1 -1
  174. package/dist/generated/abi/DLPPerformanceImplementation.cjs +42 -0
  175. package/dist/generated/abi/DLPPerformanceImplementation.cjs.map +1 -1
  176. package/dist/generated/abi/DLPPerformanceImplementation.d.ts +32 -0
  177. package/dist/generated/abi/DLPPerformanceImplementation.js +42 -0
  178. package/dist/generated/abi/DLPPerformanceImplementation.js.map +1 -1
  179. package/dist/generated/abi/DLPRegistryImplementation.cjs +5 -5
  180. package/dist/generated/abi/DLPRegistryImplementation.cjs.map +1 -1
  181. package/dist/generated/abi/DLPRegistryImplementation.d.ts +4 -4
  182. package/dist/generated/abi/DLPRegistryImplementation.js +5 -5
  183. package/dist/generated/abi/DLPRegistryImplementation.js.map +1 -1
  184. package/dist/generated/abi/DLPRegistryTreasuryImplementation.cjs.map +1 -1
  185. package/dist/generated/abi/DLPRegistryTreasuryImplementation.js.map +1 -1
  186. package/dist/generated/abi/DLPRewardDeployerImplementation.cjs +166 -2
  187. package/dist/generated/abi/DLPRewardDeployerImplementation.cjs.map +1 -1
  188. package/dist/generated/abi/DLPRewardDeployerImplementation.d.ts +129 -2
  189. package/dist/generated/abi/DLPRewardDeployerImplementation.js +166 -2
  190. package/dist/generated/abi/DLPRewardDeployerImplementation.js.map +1 -1
  191. package/dist/generated/abi/DLPRewardSwapImplementation.cjs.map +1 -1
  192. package/dist/generated/abi/DLPRewardSwapImplementation.js.map +1 -1
  193. package/dist/generated/abi/DataLiquidityPoolImplementation.cjs +282 -100
  194. package/dist/generated/abi/DataLiquidityPoolImplementation.cjs.map +1 -1
  195. package/dist/generated/abi/DataLiquidityPoolImplementation.d.ts +218 -79
  196. package/dist/generated/abi/DataLiquidityPoolImplementation.js +281 -99
  197. package/dist/generated/abi/DataLiquidityPoolImplementation.js.map +1 -1
  198. package/dist/generated/abi/DataPortabilityGranteesImplementation.cjs +167 -19
  199. package/dist/generated/abi/DataPortabilityGranteesImplementation.cjs.map +1 -1
  200. package/dist/generated/abi/DataPortabilityGranteesImplementation.d.ts +127 -14
  201. package/dist/generated/abi/DataPortabilityGranteesImplementation.js +167 -19
  202. package/dist/generated/abi/DataPortabilityGranteesImplementation.js.map +1 -1
  203. package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs +0 -19
  204. package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs.map +1 -1
  205. package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.ts +0 -14
  206. package/dist/generated/abi/DataPortabilityPermissionsImplementation.js +0 -19
  207. package/dist/generated/abi/DataPortabilityPermissionsImplementation.js.map +1 -1
  208. package/dist/generated/abi/DataPortabilityServersImplementation.cjs +0 -19
  209. package/dist/generated/abi/DataPortabilityServersImplementation.cjs.map +1 -1
  210. package/dist/generated/abi/DataPortabilityServersImplementation.d.ts +0 -14
  211. package/dist/generated/abi/DataPortabilityServersImplementation.js +0 -19
  212. package/dist/generated/abi/DataPortabilityServersImplementation.js.map +1 -1
  213. package/dist/generated/abi/DataRefinerRegistryImplementation.cjs.map +1 -1
  214. package/dist/generated/abi/DataRefinerRegistryImplementation.js.map +1 -1
  215. package/dist/generated/abi/DataRegistryImplementation.cjs +0 -13
  216. package/dist/generated/abi/DataRegistryImplementation.cjs.map +1 -1
  217. package/dist/generated/abi/DataRegistryImplementation.d.ts +0 -10
  218. package/dist/generated/abi/DataRegistryImplementation.js +0 -13
  219. package/dist/generated/abi/DataRegistryImplementation.js.map +1 -1
  220. package/dist/generated/abi/DatasetRegistryImplementation.cjs +751 -0
  221. package/dist/generated/abi/DatasetRegistryImplementation.cjs.map +1 -0
  222. package/dist/generated/abi/DatasetRegistryImplementation.d.ts +557 -0
  223. package/dist/generated/abi/DatasetRegistryImplementation.js +727 -0
  224. package/dist/generated/abi/DatasetRegistryImplementation.js.map +1 -0
  225. package/dist/generated/abi/ProtocolConfigImplementation.cjs +578 -0
  226. package/dist/generated/abi/ProtocolConfigImplementation.cjs.map +1 -0
  227. package/dist/generated/abi/ProtocolConfigImplementation.d.ts +423 -0
  228. package/dist/generated/abi/ProtocolConfigImplementation.js +554 -0
  229. package/dist/generated/abi/ProtocolConfigImplementation.js.map +1 -0
  230. package/dist/generated/abi/QueryEngineImplementation.cjs.map +1 -1
  231. package/dist/generated/abi/QueryEngineImplementation.js.map +1 -1
  232. package/dist/generated/abi/SwapHelperImplementation.cjs +0 -43
  233. package/dist/generated/abi/SwapHelperImplementation.cjs.map +1 -1
  234. package/dist/generated/abi/SwapHelperImplementation.d.ts +0 -35
  235. package/dist/generated/abi/SwapHelperImplementation.js +0 -43
  236. package/dist/generated/abi/SwapHelperImplementation.js.map +1 -1
  237. package/dist/generated/abi/TeePoolDedicatedGpuImplementation.cjs.map +1 -1
  238. package/dist/generated/abi/TeePoolDedicatedGpuImplementation.js.map +1 -1
  239. package/dist/generated/abi/TeePoolDedicatedStandardImplementation.cjs.map +1 -1
  240. package/dist/generated/abi/TeePoolDedicatedStandardImplementation.js.map +1 -1
  241. package/dist/generated/abi/TeePoolEphemeralStandardImplementation.cjs.map +1 -1
  242. package/dist/generated/abi/TeePoolEphemeralStandardImplementation.js.map +1 -1
  243. package/dist/generated/abi/TeePoolPersistentGpuImplementation.cjs.map +1 -1
  244. package/dist/generated/abi/TeePoolPersistentGpuImplementation.js.map +1 -1
  245. package/dist/generated/abi/TeePoolPersistentStandardImplementation.cjs.map +1 -1
  246. package/dist/generated/abi/TeePoolPersistentStandardImplementation.js.map +1 -1
  247. package/dist/generated/abi/TeePoolPhalaImplementation.cjs.map +1 -1
  248. package/dist/generated/abi/TeePoolPhalaImplementation.js.map +1 -1
  249. package/dist/generated/abi/UniswapV3NonfungiblePositionManagerImplementation.cjs +1251 -0
  250. package/dist/generated/abi/UniswapV3NonfungiblePositionManagerImplementation.cjs.map +1 -0
  251. package/dist/generated/abi/UniswapV3NonfungiblePositionManagerImplementation.d.ts +948 -0
  252. package/dist/generated/abi/UniswapV3NonfungiblePositionManagerImplementation.js +1227 -0
  253. package/dist/generated/abi/UniswapV3NonfungiblePositionManagerImplementation.js.map +1 -0
  254. package/dist/generated/abi/UniswapV3QuoterV2Implementation.cjs +297 -0
  255. package/dist/generated/abi/UniswapV3QuoterV2Implementation.cjs.map +1 -0
  256. package/dist/generated/abi/UniswapV3QuoterV2Implementation.d.ts +206 -0
  257. package/dist/generated/abi/UniswapV3QuoterV2Implementation.js +273 -0
  258. package/dist/generated/abi/UniswapV3QuoterV2Implementation.js.map +1 -0
  259. package/dist/generated/abi/VanaEpochImplementation.cjs +195 -0
  260. package/dist/generated/abi/VanaEpochImplementation.cjs.map +1 -1
  261. package/dist/generated/abi/VanaEpochImplementation.d.ts +151 -0
  262. package/dist/generated/abi/VanaEpochImplementation.js +195 -0
  263. package/dist/generated/abi/VanaEpochImplementation.js.map +1 -1
  264. package/dist/generated/abi/VanaPoolEntityImplementation.cjs +22 -65
  265. package/dist/generated/abi/VanaPoolEntityImplementation.cjs.map +1 -1
  266. package/dist/generated/abi/VanaPoolEntityImplementation.d.ts +17 -51
  267. package/dist/generated/abi/VanaPoolEntityImplementation.js +22 -65
  268. package/dist/generated/abi/VanaPoolEntityImplementation.js.map +1 -1
  269. package/dist/generated/abi/VanaPoolStakingImplementation.cjs +113 -1
  270. package/dist/generated/abi/VanaPoolStakingImplementation.cjs.map +1 -1
  271. package/dist/generated/abi/VanaPoolStakingImplementation.d.ts +85 -1
  272. package/dist/generated/abi/VanaPoolStakingImplementation.js +113 -1
  273. package/dist/generated/abi/VanaPoolStakingImplementation.js.map +1 -1
  274. package/dist/generated/abi/VanaPoolTreasuryImplementation.cjs.map +1 -1
  275. package/dist/generated/abi/VanaPoolTreasuryImplementation.js.map +1 -1
  276. package/dist/generated/abi/VanaRuntimePermissionsImplementation.cjs +759 -0
  277. package/dist/generated/abi/VanaRuntimePermissionsImplementation.cjs.map +1 -0
  278. package/dist/generated/abi/VanaRuntimePermissionsImplementation.d.ts +563 -0
  279. package/dist/generated/abi/VanaRuntimePermissionsImplementation.js +735 -0
  280. package/dist/generated/abi/VanaRuntimePermissionsImplementation.js.map +1 -0
  281. package/dist/generated/abi/VanaRuntimeServersImplementation.cjs +820 -0
  282. package/dist/generated/abi/VanaRuntimeServersImplementation.cjs.map +1 -0
  283. package/dist/generated/abi/VanaRuntimeServersImplementation.d.ts +609 -0
  284. package/dist/generated/abi/VanaRuntimeServersImplementation.js +796 -0
  285. package/dist/generated/abi/VanaRuntimeServersImplementation.js.map +1 -0
  286. package/dist/generated/abi/VanaTreasuryImplementation.cjs +536 -0
  287. package/dist/generated/abi/VanaTreasuryImplementation.cjs.map +1 -0
  288. package/dist/generated/abi/VanaTreasuryImplementation.d.ts +393 -0
  289. package/dist/generated/abi/VanaTreasuryImplementation.js +512 -0
  290. package/dist/generated/abi/VanaTreasuryImplementation.js.map +1 -0
  291. package/dist/generated/abi/WVANAImplementation.cjs +339 -0
  292. package/dist/generated/abi/WVANAImplementation.cjs.map +1 -0
  293. package/dist/generated/abi/WVANAImplementation.d.ts +244 -0
  294. package/dist/generated/abi/WVANAImplementation.js +315 -0
  295. package/dist/generated/abi/WVANAImplementation.js.map +1 -0
  296. package/dist/generated/abi/index.cjs +79 -47
  297. package/dist/generated/abi/index.cjs.map +1 -1
  298. package/dist/generated/abi/index.d.ts +15783 -10449
  299. package/dist/generated/abi/index.js +65 -43
  300. package/dist/generated/abi/index.js.map +1 -1
  301. package/dist/{config → generated}/addresses.cjs +174 -75
  302. package/dist/generated/addresses.cjs.map +1 -0
  303. package/dist/{config → generated}/addresses.d.ts +174 -165
  304. package/dist/{config → generated}/addresses.js +174 -75
  305. package/dist/generated/addresses.js.map +1 -0
  306. package/dist/generated/event-types.cjs.map +1 -1
  307. package/dist/generated/event-types.d.ts +482 -399
  308. package/dist/generated/eventRegistry.cjs +2601 -724
  309. package/dist/generated/eventRegistry.cjs.map +1 -1
  310. package/dist/generated/eventRegistry.d.ts +2 -2
  311. package/dist/generated/eventRegistry.js +2601 -724
  312. package/dist/generated/eventRegistry.js.map +1 -1
  313. package/dist/generated/server/server-exports.cjs +22 -0
  314. package/dist/generated/server/server-exports.cjs.map +1 -1
  315. package/dist/generated/server/server-exports.d.ts +31 -11
  316. package/dist/generated/server/server-exports.js +17 -0
  317. package/dist/generated/server/server-exports.js.map +1 -1
  318. package/dist/generated/server/server.cjs.map +1 -1
  319. package/dist/generated/server/server.d.ts +771 -402
  320. package/dist/generated/subgraph.cjs +797 -32
  321. package/dist/generated/subgraph.cjs.map +1 -1
  322. package/dist/generated/subgraph.d.ts +135 -0
  323. package/dist/generated/subgraph.js +792 -32
  324. package/dist/generated/subgraph.js.map +1 -1
  325. package/dist/index.browser.d.ts +6 -1
  326. package/dist/index.browser.js +26 -1
  327. package/dist/index.browser.js.map +1 -1
  328. package/dist/index.cjs.map +1 -1
  329. package/dist/index.js.map +1 -1
  330. package/dist/index.node.cjs +47 -4
  331. package/dist/index.node.cjs.map +1 -1
  332. package/dist/index.node.d.ts +60 -14
  333. package/dist/index.node.js +42 -3
  334. package/dist/index.node.js.map +1 -1
  335. package/dist/lib/__tests__/redisAtomicStore.test.d.ts +1 -0
  336. package/dist/lib/redisAtomicStore.cjs +201 -0
  337. package/dist/lib/redisAtomicStore.cjs.map +1 -0
  338. package/dist/lib/redisAtomicStore.d.ts +120 -0
  339. package/dist/lib/redisAtomicStore.js +177 -0
  340. package/dist/lib/redisAtomicStore.js.map +1 -0
  341. package/dist/node.cjs.map +1 -1
  342. package/dist/node.d.ts +39 -1
  343. package/dist/node.js.map +1 -1
  344. package/dist/platform/browser.cjs +160 -2
  345. package/dist/platform/browser.cjs.map +1 -1
  346. package/dist/platform/browser.d.ts +232 -12
  347. package/dist/platform/browser.js +160 -2
  348. package/dist/platform/browser.js.map +1 -1
  349. package/dist/platform/interface.cjs.map +1 -1
  350. package/dist/platform/interface.d.ts +283 -90
  351. package/dist/platform/node.cjs +163 -2
  352. package/dist/platform/node.cjs.map +1 -1
  353. package/dist/platform/node.d.ts +69 -6
  354. package/dist/platform/node.js +163 -2
  355. package/dist/platform/node.js.map +1 -1
  356. package/dist/server/relayerHandler.cjs +452 -0
  357. package/dist/server/relayerHandler.cjs.map +1 -0
  358. package/dist/server/relayerHandler.d.ts +69 -0
  359. package/dist/server/relayerHandler.js +428 -0
  360. package/dist/server/relayerHandler.js.map +1 -0
  361. package/dist/storage/index.cjs +3 -0
  362. package/dist/storage/index.cjs.map +1 -1
  363. package/dist/storage/index.d.ts +1 -0
  364. package/dist/storage/index.js +2 -0
  365. package/dist/storage/index.js.map +1 -1
  366. package/dist/storage/manager.cjs +108 -25
  367. package/dist/storage/manager.cjs.map +1 -1
  368. package/dist/storage/manager.d.ts +119 -25
  369. package/dist/storage/manager.js +108 -25
  370. package/dist/storage/manager.js.map +1 -1
  371. package/dist/storage/providers/callback-storage.cjs +86 -15
  372. package/dist/storage/providers/callback-storage.cjs.map +1 -1
  373. package/dist/storage/providers/callback-storage.d.ts +109 -20
  374. package/dist/storage/providers/callback-storage.js +86 -15
  375. package/dist/storage/providers/callback-storage.js.map +1 -1
  376. package/dist/storage/providers/dropbox.cjs +237 -0
  377. package/dist/storage/providers/dropbox.cjs.map +1 -0
  378. package/dist/storage/providers/dropbox.d.ts +39 -0
  379. package/dist/storage/providers/dropbox.js +215 -0
  380. package/dist/storage/providers/dropbox.js.map +1 -0
  381. package/dist/storage/providers/dropbox.test.d.ts +1 -0
  382. package/dist/storage/providers/pinata.cjs.map +1 -1
  383. package/dist/storage/providers/pinata.d.ts +12 -14
  384. package/dist/storage/providers/pinata.js.map +1 -1
  385. package/dist/tests/data-upload-owner-validation.test.d.ts +1 -0
  386. package/dist/tests/factories/mockFactory.d.ts +6 -6
  387. package/dist/tests/fakes/FakeWaitForTransactionEvents.d.ts +2 -2
  388. package/dist/tests/permissions-revoke-relayer.test.d.ts +1 -0
  389. package/dist/tests/permissions-transaction-options.test.d.ts +1 -0
  390. package/dist/tests/read-only-mode.test.d.ts +1 -0
  391. package/dist/tests/relayer-integration.test.d.ts +1 -0
  392. package/dist/tests/relayer-unified.test.d.ts +1 -0
  393. package/dist/tests/server-relayer-handler.test.d.ts +1 -0
  394. package/dist/types/accessSettlement.cjs +17 -0
  395. package/dist/types/accessSettlement.cjs.map +1 -0
  396. package/dist/types/accessSettlement.d.ts +66 -0
  397. package/dist/types/accessSettlement.js +1 -0
  398. package/dist/types/accessSettlement.js.map +1 -0
  399. package/dist/types/atomicStore.cjs +31 -0
  400. package/dist/types/atomicStore.cjs.map +1 -0
  401. package/dist/types/atomicStore.d.ts +236 -0
  402. package/dist/types/atomicStore.js +7 -0
  403. package/dist/types/atomicStore.js.map +1 -0
  404. package/dist/types/blockchain.cjs.map +1 -1
  405. package/dist/types/blockchain.d.ts +39 -11
  406. package/dist/types/chains.cjs.map +1 -1
  407. package/dist/types/chains.d.ts +74 -7
  408. package/dist/types/chains.js.map +1 -1
  409. package/dist/types/config.cjs +10 -0
  410. package/dist/types/config.cjs.map +1 -1
  411. package/dist/types/config.d.ts +217 -220
  412. package/dist/types/config.js +8 -0
  413. package/dist/types/config.js.map +1 -1
  414. package/dist/types/contracts.cjs.map +1 -1
  415. package/dist/types/contracts.d.ts +71 -7
  416. package/dist/types/controller-context.cjs.map +1 -1
  417. package/dist/types/controller-context.d.ts +12 -6
  418. package/dist/types/data.cjs.map +1 -1
  419. package/dist/types/data.d.ts +82 -10
  420. package/dist/types/generics.cjs.map +1 -1
  421. package/dist/types/generics.d.ts +81 -10
  422. package/dist/types/index.cjs +4 -0
  423. package/dist/types/index.cjs.map +1 -1
  424. package/dist/types/index.d.ts +36 -6
  425. package/dist/types/index.js +9 -1
  426. package/dist/types/index.js.map +1 -1
  427. package/dist/types/operationStore.cjs +17 -0
  428. package/dist/types/operationStore.cjs.map +1 -0
  429. package/dist/types/operationStore.d.ts +171 -0
  430. package/dist/types/operationStore.js +1 -0
  431. package/dist/types/operationStore.js.map +1 -0
  432. package/dist/types/operations.cjs +3 -15
  433. package/dist/types/operations.cjs.map +1 -1
  434. package/dist/types/operations.d.ts +131 -39
  435. package/dist/types/operations.js +2 -13
  436. package/dist/types/operations.js.map +1 -1
  437. package/dist/types/options.cjs +17 -0
  438. package/dist/types/options.cjs.map +1 -0
  439. package/dist/types/options.d.ts +308 -0
  440. package/dist/types/options.js +1 -0
  441. package/dist/types/options.js.map +1 -0
  442. package/dist/types/permissions.cjs.map +1 -1
  443. package/dist/types/permissions.d.ts +19 -20
  444. package/dist/types/personal.cjs.map +1 -1
  445. package/dist/types/personal.d.ts +150 -14
  446. package/dist/types/relayer.cjs.map +1 -1
  447. package/dist/types/relayer.d.ts +307 -35
  448. package/dist/types/runtimePermissions.cjs +17 -0
  449. package/dist/types/runtimePermissions.cjs.map +1 -0
  450. package/dist/types/runtimePermissions.d.ts +122 -0
  451. package/dist/types/runtimePermissions.js +1 -0
  452. package/dist/types/runtimePermissions.js.map +1 -0
  453. package/dist/types/storage.cjs.map +1 -1
  454. package/dist/types/storage.d.ts +9 -21
  455. package/dist/types/storage.js.map +1 -1
  456. package/dist/types/utils.cjs.map +1 -1
  457. package/dist/types/utils.d.ts +0 -45
  458. package/dist/utils/__tests__/chainQuery.test.d.ts +1 -0
  459. package/dist/utils/__tests__/subgraphConsistency.test.d.ts +4 -0
  460. package/dist/utils/__tests__/subgraphPagination.test.d.ts +4 -0
  461. package/dist/utils/blockchain/registry.cjs +3 -3
  462. package/dist/utils/blockchain/registry.cjs.map +1 -1
  463. package/dist/utils/blockchain/registry.d.ts +1 -1
  464. package/dist/utils/blockchain/registry.js +3 -3
  465. package/dist/utils/blockchain/registry.js.map +1 -1
  466. package/dist/utils/chainQuery.cjs +107 -0
  467. package/dist/utils/chainQuery.cjs.map +1 -0
  468. package/dist/utils/chainQuery.d.ts +31 -0
  469. package/dist/utils/chainQuery.js +82 -0
  470. package/dist/utils/chainQuery.js.map +1 -0
  471. package/dist/utils/grantFiles.cjs +4 -1
  472. package/dist/utils/grantFiles.cjs.map +1 -1
  473. package/dist/utils/grantFiles.d.ts +10 -20
  474. package/dist/utils/grantFiles.js +4 -1
  475. package/dist/utils/grantFiles.js.map +1 -1
  476. package/dist/utils/grantValidation.cjs.map +1 -1
  477. package/dist/utils/grantValidation.d.ts +95 -16
  478. package/dist/utils/grantValidation.js.map +1 -1
  479. package/dist/utils/grants.cjs.map +1 -1
  480. package/dist/utils/grants.d.ts +93 -12
  481. package/dist/utils/grants.js.map +1 -1
  482. package/dist/utils/ipfs.cjs +2 -4
  483. package/dist/utils/ipfs.cjs.map +1 -1
  484. package/dist/utils/ipfs.d.ts +1 -1
  485. package/dist/utils/ipfs.js +2 -4
  486. package/dist/utils/ipfs.js.map +1 -1
  487. package/dist/utils/lazy-import.cjs.map +1 -1
  488. package/dist/utils/lazy-import.d.ts +32 -7
  489. package/dist/utils/lazy-import.js.map +1 -1
  490. package/dist/utils/multicall.cjs +1 -1
  491. package/dist/utils/multicall.cjs.map +1 -1
  492. package/dist/utils/multicall.js +1 -1
  493. package/dist/utils/multicall.js.map +1 -1
  494. package/dist/utils/runtimeGrantFiles.cjs +84 -0
  495. package/dist/utils/runtimeGrantFiles.cjs.map +1 -0
  496. package/dist/utils/runtimeGrantFiles.d.ts +66 -0
  497. package/dist/utils/runtimeGrantFiles.js +58 -0
  498. package/dist/utils/runtimeGrantFiles.js.map +1 -0
  499. package/dist/utils/signatureCache.cjs +8 -2
  500. package/dist/utils/signatureCache.cjs.map +1 -1
  501. package/dist/utils/signatureCache.d.ts +49 -8
  502. package/dist/utils/signatureCache.js +8 -2
  503. package/dist/utils/signatureCache.js.map +1 -1
  504. package/dist/utils/subgraphConsistency.cjs +184 -0
  505. package/dist/utils/subgraphConsistency.cjs.map +1 -0
  506. package/dist/utils/subgraphConsistency.d.ts +65 -0
  507. package/dist/utils/subgraphConsistency.js +155 -0
  508. package/dist/utils/subgraphConsistency.js.map +1 -0
  509. package/dist/utils/subgraphMetaCache.cjs +101 -0
  510. package/dist/utils/subgraphMetaCache.cjs.map +1 -0
  511. package/dist/utils/subgraphMetaCache.d.ts +56 -0
  512. package/dist/utils/subgraphMetaCache.js +76 -0
  513. package/dist/utils/subgraphMetaCache.js.map +1 -0
  514. package/dist/utils/subgraphPagination.cjs +104 -0
  515. package/dist/utils/subgraphPagination.cjs.map +1 -0
  516. package/dist/utils/subgraphPagination.d.ts +78 -0
  517. package/dist/utils/subgraphPagination.js +78 -0
  518. package/dist/utils/subgraphPagination.js.map +1 -0
  519. package/dist/utils/transactionHelpers.cjs.map +1 -1
  520. package/dist/utils/transactionHelpers.d.ts +12 -12
  521. package/dist/utils/transactionHelpers.js.map +1 -1
  522. package/dist/utils/typedDataConverter.cjs.map +1 -1
  523. package/dist/utils/typedDataConverter.d.ts +39 -3
  524. package/dist/utils/typedDataConverter.js.map +1 -1
  525. package/dist/utils/urlResolver.cjs +7 -0
  526. package/dist/utils/urlResolver.cjs.map +1 -1
  527. package/dist/utils/urlResolver.d.ts +22 -4
  528. package/dist/utils/urlResolver.js +7 -0
  529. package/dist/utils/urlResolver.js.map +1 -1
  530. package/dist/utils/wallet.cjs +63 -0
  531. package/dist/utils/wallet.cjs.map +1 -0
  532. package/dist/utils/wallet.d.ts +94 -0
  533. package/dist/utils/wallet.js +37 -0
  534. package/dist/utils/wallet.js.map +1 -0
  535. package/package.json +7 -2
  536. package/dist/config/addresses.cjs.map +0 -1
  537. package/dist/config/addresses.js.map +0 -1
  538. package/dist/generated/abi/DLPTreasuryImplementation.cjs.map +0 -1
  539. package/dist/generated/abi/DLPTreasuryImplementation.js.map +0 -1
  540. package/dist/server/handler.cjs +0 -101
  541. package/dist/server/handler.cjs.map +0 -1
  542. package/dist/server/handler.d.ts +0 -87
  543. package/dist/server/handler.js +0 -77
  544. package/dist/server/handler.js.map +0 -1
  545. /package/dist/{tests/server-handler.test.d.ts → client/__tests__/enhancedResponse.test.d.ts} +0 -0
@@ -1,14 +1,30 @@
1
1
  import { getContract } from "viem";
2
- import { getContractAddress } from "../config/addresses";
2
+ import { PollingManager } from "../core/pollingManager";
3
+ import { BaseController } from "./base";
4
+ import { getContractAddress } from "../generated/addresses";
3
5
  import { getAbi } from "../generated/abi";
6
+ import { InvalidConfigurationError } from "../errors";
4
7
  import {
5
- GetUserFilesDocument,
8
+ GetUserFilesPaginatedDocument,
6
9
  GetFileProofsDocument,
7
10
  GetDlpDocument,
8
- GetUserPermissionsDocument,
9
- GetUserTrustedServersDocument
11
+ GetUserPermissionsPaginatedDocument,
12
+ GetUserTrustedServersPaginatedDocument
10
13
  } from "../generated/subgraph";
11
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";
12
28
  import {
13
29
  generateEncryptionKey,
14
30
  decryptBlobWithSignedKey,
@@ -23,11 +39,12 @@ import {
23
39
  fetchAndValidateSchema
24
40
  } from "../utils/schemaValidation";
25
41
  import { gasAwareMulticall } from "../utils/multicall";
26
- class DataController {
42
+ class DataController extends BaseController {
27
43
  constructor(context) {
28
- this.context = context;
44
+ super(context);
29
45
  }
30
46
  async upload(params) {
47
+ this.assertWallet();
31
48
  const {
32
49
  content,
33
50
  filename,
@@ -35,12 +52,18 @@ class DataController {
35
52
  permissions = [],
36
53
  encrypt = true,
37
54
  providerName,
38
- owner
55
+ owner,
56
+ schemaValidation = "strict"
39
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
+ }
40
63
  try {
41
64
  let isValid = true;
42
65
  let validationErrors = [];
43
- if (schemaId !== void 0) {
66
+ if (schemaId !== void 0 && schemaValidation !== "skip") {
44
67
  try {
45
68
  const { SchemaController } = await import("./schemas");
46
69
  const schemaController = new SchemaController(this.context);
@@ -64,16 +87,20 @@ class DataController {
64
87
  }
65
88
  validateDataAgainstSchema(parsedContent, schema);
66
89
  } catch (error) {
67
- isValid = false;
68
- if (error instanceof Error) {
69
- const errorDetails = error.errors;
70
- if (errorDetails && Array.isArray(errorDetails)) {
71
- validationErrors = errorDetails;
72
- } else {
73
- 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
+ }
74
101
  }
75
- } else {
76
- validationErrors = ["Schema validation failed"];
102
+ isValid = false;
103
+ validationErrors = error instanceof Error ? [error.message] : ["Schema validation failed"];
77
104
  }
78
105
  }
79
106
  }
@@ -83,9 +110,10 @@ class DataController {
83
110
  encrypt,
84
111
  providerName
85
112
  );
86
- const userAddress = owner ?? await this.getUserAddress();
113
+ const userAddress = owner ?? this.context.userAddress;
87
114
  let encryptedPermissions = [];
88
115
  if (permissions.length > 0 && encrypt) {
116
+ this.assertWallet();
89
117
  const userEncryptionKey = await generateEncryptionKey(
90
118
  this.context.walletClient,
91
119
  this.context.platform,
@@ -106,29 +134,35 @@ class DataController {
106
134
  );
107
135
  }
108
136
  let result;
109
- if (this.context.relayerCallbacks?.submitFileAdditionComplete) {
110
- result = await this.context.relayerCallbacks.submitFileAdditionComplete(
111
- {
137
+ if (this.context.relayer) {
138
+ const request = {
139
+ type: "direct",
140
+ operation: "submitFileAdditionComplete",
141
+ params: {
112
142
  url: uploadResult.url,
113
143
  userAddress,
114
144
  permissions: encryptedPermissions,
115
145
  schemaId: schemaId ?? 0,
116
146
  ownerAddress: owner
117
147
  }
118
- );
119
- } else if (this.context.relayerCallbacks?.submitFileAddition) {
120
- const needsComplexRegistration = schemaId !== void 0 || encryptedPermissions.length > 0;
121
- if (needsComplexRegistration) {
122
- throw new Error(
123
- "The configured relay callback does not support schemas or permissions. Please update your relay server implementation to provide the `submitFileAdditionComplete` callback."
148
+ };
149
+ const response = await this.context.relayer(request);
150
+ if (response.type === "error") {
151
+ throw new Error(response.error);
152
+ }
153
+ if (response.type === "pending") {
154
+ result = await this.pollRelayerForConfirmation(
155
+ response.operationId,
156
+ void 0
157
+ // TODO: Add TransactionOptions to upload method signature
124
158
  );
159
+ } else if (response.type === "direct" && typeof response.result === "object" && response.result !== null && "fileId" in response.result) {
160
+ result = response.result;
161
+ } else {
162
+ throw new Error("Invalid response from relayer");
125
163
  }
126
- result = await this.context.relayerCallbacks.submitFileAddition(
127
- uploadResult.url,
128
- userAddress
129
- );
130
164
  } else {
131
- const txResult = await this._addFileWithPermissionsAndSchemaInternal(
165
+ const txResult = await this.addFileWithEncryptedPermissionsAndSchema(
132
166
  uploadResult.url,
133
167
  userAddress,
134
168
  encryptedPermissions,
@@ -164,35 +198,110 @@ class DataController {
164
198
  }
165
199
  }
166
200
  /**
167
- * Decrypts a file owned by the user using their wallet signature.
201
+ * Encrypts data using wallet-derived encryption.
168
202
  *
169
203
  * @remarks
170
- * This is the high-level convenience method for decrypting user files, serving as the
171
- * symmetrical counterpart to the `upload` method. It handles the complete decryption
172
- * workflow including key generation, URL protocol detection, content fetching, and
173
- * decryption.
204
+ * This method provides secure, wallet-based encryption for data before uploading
205
+ * to the Vana network. It's the counterpart to decryptFile for preparing data
206
+ * for secure storage.
174
207
  *
175
208
  * The method automatically:
176
- * - Generates the decryption key from the user's wallet signature
177
- * - Determines the appropriate fetch method based on the file URL protocol
178
- * - Fetches the encrypted content from IPFS or standard HTTP URLs
179
- * - Decrypts the content using the generated key
180
- *
181
- * For IPFS URLs, the method uses gateway fallback for improved reliability. For
182
- * standard HTTP URLs, it uses a simple fetch. If you need custom authentication
183
- * headers or specific gateway configurations, use the low-level primitives directly.
184
- *
185
- * @param file - The user file to decrypt (typically from getUserFiles)
186
- * @param encryptionSeed - Optional custom encryption seed (defaults to Vana standard)
187
- * @returns Promise resolving to the decrypted file content as a Blob
188
- * @throws {Error} "No addresses available in wallet client" - When wallet is not connected
189
- * @throws {Error} "Network error: Cannot access the file URL" - When file URL is inaccessible (CORS, server down)
190
- * @throws {Error} "File not found: The encrypted file is no longer available" - When file returns 404
191
- * @throws {Error} "Access denied" - When file returns 403 (no permission)
192
- * @throws {Error} "File is empty or could not be retrieved" - When file has no content
193
- * @throws {Error} "Invalid file format: This file doesn't appear to be encrypted with the Vana protocol" - When file is not properly encrypted
194
- * @throws {Error} "Wrong encryption key" - When decryption fails due to incorrect key/seed
195
- * @throws {Error} "Failed to decrypt file: {error}" - General decryption failures
209
+ * - Generates an encryption key from the user's wallet signature
210
+ * - Converts the input data to a Blob if necessary
211
+ * - Encrypts the data using the generated key
212
+ * - Returns both the encrypted data and the encryption key
213
+ *
214
+ * The encryption key returned can be stored and later used for decryption,
215
+ * or shared with others to grant them decryption access.
216
+ *
217
+ * @param data - The data to encrypt (Blob, string, or object)
218
+ * @param options - Optional encryption configuration
219
+ * @returns Promise resolving to encrypted data and the encryption key used
220
+ * @throws {Error} When wallet is not connected or encryption fails
221
+ * @example
222
+ * ```typescript
223
+ * // Encrypt a string
224
+ * const { encryptedData, encryptionKey } = await vana.data.encryptFile(
225
+ * "My secret data"
226
+ * );
227
+ *
228
+ * // Encrypt JSON with custom MIME type
229
+ * const { encryptedData, encryptionKey } = await vana.data.encryptFile(
230
+ * { name: "Alice", age: 30 },
231
+ * { mimeType: "application/json" }
232
+ * );
233
+ *
234
+ * // With custom encryption seed
235
+ * const { encryptedData, encryptionKey } = await vana.data.encryptFile(
236
+ * "Secret message",
237
+ * { seed: "My custom encryption seed" }
238
+ * );
239
+ *
240
+ * // Upload the encrypted data
241
+ * const result = await vana.data.uploadToStorage(encryptedData);
242
+ * ```
243
+ */
244
+ async encryptFile(data, options) {
245
+ this.assertWallet();
246
+ try {
247
+ const encryptionKey = await generateEncryptionKey(
248
+ this.context.walletClient,
249
+ this.context.platform,
250
+ options?.seed ?? DEFAULT_ENCRYPTION_SEED
251
+ );
252
+ let blob;
253
+ if (data instanceof Blob) {
254
+ blob = data;
255
+ } else if (typeof data === "string") {
256
+ blob = new Blob([data], { type: options?.mimeType ?? "text/plain" });
257
+ } else {
258
+ blob = new Blob([JSON.stringify(data)], {
259
+ type: options?.mimeType ?? "application/json"
260
+ });
261
+ }
262
+ const encryptedData = await encryptBlobWithSignedKey(
263
+ blob,
264
+ encryptionKey,
265
+ this.context.platform
266
+ );
267
+ return {
268
+ encryptedData,
269
+ encryptionKey
270
+ };
271
+ } catch (error) {
272
+ throw new Error(
273
+ `Failed to encrypt file: ${error instanceof Error ? error.message : "Unknown error"}`
274
+ );
275
+ }
276
+ }
277
+ /**
278
+ * Decrypts a file using wallet-derived decryption key.
279
+ *
280
+ * @remarks
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.
304
+ *
196
305
  * @example
197
306
  * ```typescript
198
307
  * // Basic file decryption
@@ -218,12 +327,14 @@ class DataController {
218
327
  * fs.writeFileSync('decrypted-file.txt', Buffer.from(buffer));
219
328
  * ```
220
329
  */
221
- async decryptFile(file, encryptionSeed) {
330
+ async decryptFile(file, options) {
331
+ this.assertWallet();
222
332
  try {
333
+ this.assertWallet();
223
334
  const encryptionKey = await generateEncryptionKey(
224
335
  this.context.walletClient,
225
336
  this.context.platform,
226
- encryptionSeed ?? DEFAULT_ENCRYPTION_SEED
337
+ options?.seed ?? DEFAULT_ENCRYPTION_SEED
227
338
  );
228
339
  let encryptedBlob;
229
340
  try {
@@ -306,99 +417,126 @@ class DataController {
306
417
  }
307
418
  }
308
419
  /**
309
- * Retrieves all data files owned by a specific user address.
420
+ * Retrieves all files owned by a specific user address.
310
421
  *
311
422
  * @remarks
312
- * This method queries the Vana subgraph to find files directly owned by the user.
313
- * It efficiently handles large datasets by using the File entity's owner field
314
- * and returns complete file metadata without additional contract calls.
315
- *
316
- * **Deduplication Behavior:**
317
- * The method automatically deduplicates files by ID, keeping only the latest version
318
- * (highest timestamp) when duplicate file IDs are found. This handles cases where
319
- * the subgraph may contain multiple entries for the same file due to re-indexing
320
- * or blockchain reorganizations.
321
- * @param params - The query parameters object
322
- * @param params.owner - The wallet address of the file owner to query
323
- * @param params.subgraphUrl - Optional subgraph URL to override the default endpoint
324
- * @returns A Promise that resolves to an array of UserFile objects with metadata, sorted by latest timestamp first
325
- * @throws {Error} When subgraphUrl is not provided and not configured - "subgraphUrl is required"
326
- * @throws {Error} When subgraph request fails - "Subgraph request failed: {status} {statusText}"
327
- * @throws {Error} When subgraph returns errors - "Subgraph errors: {error messages}"
328
- * @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
+ *
329
442
  * @example
330
443
  * ```typescript
331
- * // Query files for a specific user
332
444
  * const files = await vana.data.getUserFiles({
333
- * owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
445
+ * owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
334
446
  * });
335
447
  *
336
448
  * files.forEach(file => {
337
- * 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"}`);
338
452
  * });
339
453
  * ```
340
454
  */
341
- async getUserFiles(params) {
455
+ async getUserFiles(params, options) {
342
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
+ }
343
491
  const endpoint = subgraphUrl ?? this.context.subgraphUrl;
344
492
  if (!endpoint) {
345
493
  throw new Error(
346
494
  "subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor."
347
495
  );
348
496
  }
497
+ if (options?.minBlock || options?.waitForSync) {
498
+ await checkSubgraphConsistency(endpoint, options);
499
+ }
349
500
  try {
350
- const response = await fetch(endpoint, {
351
- method: "POST",
352
- headers: {
353
- "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
+ )
354
524
  },
355
- body: JSON.stringify({
356
- query: print(GetUserFilesDocument),
357
- variables: {
358
- userId: owner.toLowerCase()
359
- // Subgraph requires lowercase addresses
360
- }
361
- })
362
- });
363
- if (!response.ok) {
364
- throw new Error(
365
- `Subgraph request failed: ${response.status} ${response.statusText}`
366
- );
367
- }
368
- const result = await response.json();
369
- if (result.errors) {
370
- throw new Error(
371
- `Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
372
- );
373
- }
374
- const user = result.data?.user;
375
- if (!user?.files?.length) {
376
- console.warn("No files found for user:", owner);
377
- return [];
378
- }
379
- const fileMap = /* @__PURE__ */ new Map();
380
- user.files.forEach((file) => {
381
- const fileId = parseInt(file.id);
382
- const userFile = {
383
- id: fileId,
525
+ options,
526
+ extractItems: (data) => data?.user?.files,
527
+ transformItem: (file) => ({
528
+ id: parseInt(file.id),
384
529
  url: file.url,
385
530
  ownerAddress: file.owner.id,
386
531
  addedAtBlock: BigInt(file.addedAtBlock),
387
532
  schemaId: parseInt(file.schemaId),
388
533
  addedAtTimestamp: BigInt(file.addedAtTimestamp),
389
534
  transactionHash: file.transactionHash
390
- };
391
- const existing = fileMap.get(fileId);
392
- if (!existing || userFile.addedAtTimestamp && existing.addedAtTimestamp && userFile.addedAtTimestamp > existing.addedAtTimestamp) {
393
- fileMap.set(fileId, userFile);
394
- }
535
+ })
395
536
  });
396
- const userFiles = Array.from(fileMap.values()).sort(
397
- (a, b) => Number((b.addedAtTimestamp ?? 0n) - (a.addedAtTimestamp ?? 0n))
398
- );
399
- if (userFiles.length > 0) {
537
+ if (allFiles.length > 0) {
400
538
  try {
401
- const fileIds = userFiles.map((f) => f.id);
539
+ const fileIds = allFiles.map((f) => f.id);
402
540
  let proofMap;
403
541
  try {
404
542
  proofMap = await this._fetchProofsFromSubgraph(fileIds, endpoint);
@@ -409,7 +547,7 @@ class DataController {
409
547
  );
410
548
  proofMap = await this._fetchProofsFromChain(fileIds);
411
549
  }
412
- for (const file of userFiles) {
550
+ for (const file of allFiles) {
413
551
  const dlpIds = proofMap.get(file.id);
414
552
  if (dlpIds && dlpIds.length > 0) {
415
553
  file.dlpIds = dlpIds;
@@ -419,7 +557,7 @@ class DataController {
419
557
  console.warn("Failed to fetch proof data for files:", error);
420
558
  }
421
559
  }
422
- return userFiles;
560
+ return allFiles;
423
561
  } catch (error) {
424
562
  console.error("Failed to fetch user files from subgraph:", error);
425
563
  throw new Error(
@@ -487,7 +625,7 @@ class DataController {
487
625
  * @returns Map of file IDs to their associated DLP IDs
488
626
  */
489
627
  async _fetchProofsFromChain(fileIds) {
490
- const chainId = this.context.walletClient.chain?.id;
628
+ const chainId = this.context.publicClient.chain?.id;
491
629
  if (!chainId) {
492
630
  throw new Error("Chain ID not available");
493
631
  }
@@ -545,6 +683,9 @@ class DataController {
545
683
  */
546
684
  async getDLP(dlpId, options = {}) {
547
685
  const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
686
+ if (subgraphUrl && (options.minBlock || options.waitForSync)) {
687
+ await checkSubgraphConsistency(subgraphUrl, options);
688
+ }
548
689
  if (subgraphUrl) {
549
690
  try {
550
691
  const response = await fetch(subgraphUrl, {
@@ -578,15 +719,15 @@ class DataController {
578
719
  name: result.data.dlp.name ?? "",
579
720
  metadata: result.data.dlp.metadata ?? void 0,
580
721
  status: result.data.dlp.status ? parseInt(result.data.dlp.status) : void 0,
581
- address: result.data.dlp.address,
582
- owner: result.data.dlp.owner
722
+ address: result.data.dlp.address ? result.data.dlp.address : void 0,
723
+ owner: result.data.dlp.owner ? result.data.dlp.owner : void 0
583
724
  };
584
725
  } catch (error) {
585
726
  console.debug("Subgraph query failed, falling back to chain:", error);
586
727
  }
587
728
  }
588
729
  try {
589
- const chainId = this.context.walletClient.chain?.id;
730
+ const chainId = this.context.publicClient.chain?.id;
590
731
  if (!chainId) {
591
732
  throw new Error("Chain ID not available");
592
733
  }
@@ -685,15 +826,15 @@ class DataController {
685
826
  name: dlp.name ?? "",
686
827
  metadata: dlp.metadata,
687
828
  status: dlp.status ? parseInt(dlp.status) : void 0,
688
- address: dlp.address,
689
- owner: dlp.owner
829
+ address: dlp.address ? dlp.address : void 0,
830
+ owner: dlp.owner ? dlp.owner : void 0
690
831
  }));
691
832
  } catch (error) {
692
833
  console.debug("Subgraph query failed, falling back to chain:", error);
693
834
  }
694
835
  }
695
836
  try {
696
- const chainId = this.context.walletClient.chain?.id;
837
+ const chainId = this.context.publicClient.chain?.id;
697
838
  if (!chainId) {
698
839
  throw new Error("Chain ID not available");
699
840
  }
@@ -763,21 +904,33 @@ class DataController {
763
904
  * @returns Promise resolving to an array of permission objects
764
905
  * @throws Error if both subgraph and RPC queries fail
765
906
  */
766
- async getUserPermissions(params) {
907
+ async getUserPermissions(params, options) {
767
908
  const { user, subgraphUrl } = params;
768
909
  const endpoint = subgraphUrl ?? this.context.subgraphUrl;
910
+ if (endpoint && (options?.minBlock || options?.waitForSync)) {
911
+ await checkSubgraphConsistency(endpoint, options);
912
+ }
769
913
  if (endpoint) {
770
914
  try {
771
- const permissions = await this._getUserPermissionsViaSubgraph({
772
- user,
773
- subgraphUrl: endpoint
774
- });
915
+ const permissions = await this._getUserPermissionsViaSubgraph(
916
+ {
917
+ user,
918
+ subgraphUrl: endpoint
919
+ },
920
+ options
921
+ );
775
922
  return permissions;
776
923
  } catch (error) {
777
924
  console.warn("Subgraph query failed, falling back to RPC:", error);
778
925
  }
779
926
  }
780
- 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;
781
934
  }
782
935
  /**
783
936
  * Internal method: Query user permissions via subgraph
@@ -787,46 +940,48 @@ class DataController {
787
940
  * @param params.subgraphUrl - The subgraph URL endpoint to query
788
941
  * @returns Promise resolving to an array of permission objects
789
942
  */
790
- async _getUserPermissionsViaSubgraph(params) {
943
+ async _getUserPermissionsViaSubgraph(params, options) {
791
944
  const { user, subgraphUrl } = params;
792
945
  try {
793
- const response = await fetch(subgraphUrl, {
794
- method: "POST",
795
- headers: {
796
- "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
+ )
797
970
  },
798
- body: JSON.stringify({
799
- query: print(GetUserPermissionsDocument),
800
- variables: {
801
- userId: user.toLowerCase()
802
- }
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
803
982
  })
804
983
  });
805
- if (!response.ok) {
806
- throw new Error(
807
- `Subgraph request failed: ${response.status} ${response.statusText}`
808
- );
809
- }
810
- const result = await response.json();
811
- if (result.errors) {
812
- throw new Error(
813
- `Subgraph query errors: ${result.errors.map((e) => e.message).join(", ")}`
814
- );
815
- }
816
- const userData = result.data?.user;
817
- if (!userData?.permissions?.length) {
818
- return [];
819
- }
820
- return userData.permissions.map((permission) => ({
821
- id: permission.id,
822
- grant: permission.grant,
823
- nonce: BigInt(permission.nonce),
824
- signature: permission.signature,
825
- addedAtBlock: BigInt(permission.addedAtBlock),
826
- addedAtTimestamp: BigInt(permission.addedAtTimestamp),
827
- transactionHash: permission.transactionHash,
828
- user
829
- })).sort((a, b) => Number(b.addedAtTimestamp - a.addedAtTimestamp));
984
+ return permissions;
830
985
  } catch (error) {
831
986
  console.error("Failed to query user permissions from subgraph:", error);
832
987
  throw error;
@@ -842,7 +997,7 @@ class DataController {
842
997
  async _getUserPermissionsViaRpc(params) {
843
998
  const { user } = params;
844
999
  try {
845
- const chainId = this.context.walletClient.chain?.id;
1000
+ const chainId = this.context.publicClient.chain?.id;
846
1001
  if (!chainId) {
847
1002
  throw new Error("Chain ID not available");
848
1003
  }
@@ -959,20 +1114,28 @@ class DataController {
959
1114
  * });
960
1115
  * ```
961
1116
  */
962
- async getUserTrustedServers(params) {
963
- const { user, limit = 50, offset = 0 } = params;
1117
+ async getUserTrustedServers(params, options) {
1118
+ const { user } = params;
964
1119
  const subgraphUrl = params.subgraphUrl ?? this.context.subgraphUrl;
1120
+ if (subgraphUrl && (options?.minBlock || options?.waitForSync)) {
1121
+ await checkSubgraphConsistency(subgraphUrl, options);
1122
+ }
965
1123
  if (subgraphUrl) {
966
1124
  try {
967
- const servers = await this._getUserTrustedServersViaSubgraph({
968
- user,
969
- subgraphUrl
970
- });
971
- 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;
972
1133
  } catch (error) {
973
1134
  console.warn("Subgraph query failed, falling back to RPC:", error);
974
1135
  }
975
1136
  }
1137
+ const limit = options?.fetchAll ? Number.MAX_SAFE_INTEGER : options?.limit ?? 100;
1138
+ const offset = options?.offset ?? 0;
976
1139
  const rpcResult = await this._getUserTrustedServersViaRpc({
977
1140
  user,
978
1141
  limit,
@@ -988,7 +1151,7 @@ class DataController {
988
1151
  * @param params.subgraphUrl - The subgraph URL endpoint to query
989
1152
  * @returns Promise resolving to an array of trusted server objects
990
1153
  */
991
- async _getUserTrustedServersViaSubgraph(params) {
1154
+ async _getUserTrustedServersViaSubgraph(params, options) {
992
1155
  const { user, subgraphUrl } = params;
993
1156
  const graphqlEndpoint = subgraphUrl;
994
1157
  if (!graphqlEndpoint) {
@@ -997,42 +1160,46 @@ class DataController {
997
1160
  );
998
1161
  }
999
1162
  try {
1000
- const response = await fetch(graphqlEndpoint, {
1001
- method: "POST",
1002
- headers: {
1003
- "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
+ )
1004
1186
  },
1005
- body: JSON.stringify({
1006
- query: print(GetUserTrustedServersDocument),
1007
- variables: {
1008
- userId: user.toLowerCase()
1009
- // Subgraph requires lowercase addresses
1010
- }
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
1011
1200
  })
1012
1201
  });
1013
- if (!response.ok) {
1014
- throw new Error(
1015
- `Subgraph request failed: ${response.status} ${response.statusText}`
1016
- );
1017
- }
1018
- const result = await response.json();
1019
- if (result.errors) {
1020
- throw new Error(
1021
- `Subgraph query errors: ${result.errors.map((e) => e.message).join(", ")}`
1022
- );
1023
- }
1024
- if (!result.data?.user) {
1025
- return [];
1026
- }
1027
- return (result.data.user.serverTrusts ?? []).filter((trust) => !trust.untrustedAtBlock).map((trust) => ({
1028
- id: trust.server.id,
1029
- serverAddress: trust.server.serverAddress,
1030
- serverUrl: trust.server.url,
1031
- trustedAt: BigInt(trust.trustedAt),
1032
- user,
1033
- name: ""
1034
- // Not available in new schema, will be empty
1035
- }));
1202
+ return serverTrusts;
1036
1203
  } catch (error) {
1037
1204
  console.error("Failed to query trusted servers from subgraph:", error);
1038
1205
  throw error;
@@ -1050,7 +1217,7 @@ class DataController {
1050
1217
  async _getUserTrustedServersViaRpc(params) {
1051
1218
  const { user, limit, offset } = params;
1052
1219
  try {
1053
- const chainId = this.context.walletClient.chain?.id;
1220
+ const chainId = this.context.publicClient.chain?.id;
1054
1221
  if (!chainId) {
1055
1222
  throw new Error("Chain ID not available");
1056
1223
  }
@@ -1134,23 +1301,31 @@ class DataController {
1134
1301
  }
1135
1302
  }
1136
1303
  /**
1137
- * 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.
1138
1316
  *
1139
- * @returns Promise resolving to the total file count
1140
1317
  * @example
1141
1318
  * ```typescript
1142
- * const totalFiles = await vana.data.getTotalFilesCount();
1143
- * console.log(`Total files in registry: ${totalFiles}`);
1319
+ * const total = await vana.data.getTotalFilesCount();
1320
+ * console.log(`Total files: ${total}`);
1144
1321
  *
1145
- * // Use for pagination calculations
1146
- * const filesPerPage = 20;
1147
- * const totalPages = Math.ceil(totalFiles / filesPerPage);
1148
- * console.log(`Total pages: ${totalPages}`);
1322
+ * // Calculate pagination
1323
+ * const pages = Math.ceil(total / 20);
1149
1324
  * ```
1150
1325
  */
1151
1326
  async getTotalFilesCount() {
1152
1327
  try {
1153
- const chainId = this.context.walletClient.chain?.id;
1328
+ const chainId = this.context.publicClient.chain?.id;
1154
1329
  if (!chainId) {
1155
1330
  throw new Error("Chain ID not available");
1156
1331
  }
@@ -1159,7 +1334,7 @@ class DataController {
1159
1334
  const dataRegistry = getContract({
1160
1335
  address: dataRegistryAddress,
1161
1336
  abi: dataRegistryAbi,
1162
- client: this.context.walletClient
1337
+ client: this.context.publicClient
1163
1338
  });
1164
1339
  const count = await dataRegistry.read.filesCount();
1165
1340
  return Number(count);
@@ -1172,36 +1347,36 @@ class DataController {
1172
1347
  }
1173
1348
  }
1174
1349
  /**
1175
- * 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.
1176
1367
  *
1177
- * @param fileId - The file ID to look up
1178
- * @returns Promise resolving to UserFile object
1179
- * @throws {Error} "Chain ID not available" - When wallet chain is not configured
1180
- * @throws {Error} "File not found" - When file ID doesn't exist or returns empty data
1181
- * @throws {Error} "Failed to fetch file {fileId}: {error}" - General contract read failures
1182
1368
  * @example
1183
1369
  * ```typescript
1184
- * try {
1185
- * const file = await vana.data.getFileById(123);
1186
- * console.log('File details:', {
1187
- * id: file.id,
1188
- * url: file.url,
1189
- * owner: file.ownerAddress,
1190
- * addedAt: file.addedAtBlock
1191
- * });
1192
- * } catch (error) {
1193
- * console.error('File not found or error retrieving file:', error);
1194
- * }
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}`);
1195
1375
  * ```
1196
- *
1197
- * This method queries the DataRegistry contract directly
1198
- * to get file details for any file ID, regardless of user ownership.
1199
- * This is useful for file lookup functionality where users can search
1200
- * for specific files by ID.
1201
1376
  */
1202
1377
  async getFileById(fileId) {
1203
1378
  try {
1204
- const chainId = this.context.walletClient.chain?.id;
1379
+ const chainId = this.context.publicClient.chain?.id;
1205
1380
  if (!chainId) {
1206
1381
  throw new Error("Chain ID not available");
1207
1382
  }
@@ -1210,7 +1385,7 @@ class DataController {
1210
1385
  const dataRegistry = getContract({
1211
1386
  address: dataRegistryAddress,
1212
1387
  abi: dataRegistryAbi,
1213
- client: this.context.walletClient
1388
+ client: this.context.publicClient
1214
1389
  });
1215
1390
  const fileDetails = await dataRegistry.read.files([BigInt(fileId)]);
1216
1391
  if (!fileDetails) {
@@ -1268,15 +1443,17 @@ class DataController {
1268
1443
  * console.log(`File ${fileId} registered with schema in tx ${transactionHash}`);
1269
1444
  * ```
1270
1445
  */
1271
- async registerFileWithSchema(url, schemaId) {
1446
+ async registerFileWithSchema(url, schemaId, options) {
1447
+ this.assertWallet();
1272
1448
  try {
1273
- const chainId = this.context.walletClient.chain?.id;
1449
+ const chainId = this.context.publicClient.chain?.id;
1274
1450
  if (!chainId) {
1275
1451
  throw new Error("Chain ID not available");
1276
1452
  }
1453
+ this.assertWallet();
1277
1454
  const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
1278
1455
  const dataRegistryAbi = getAbi("DataRegistry");
1279
- const account = this.context.walletClient.account ?? await this.getUserAddress();
1456
+ const account = this.context.walletClient.account ?? this.context.userAddress;
1280
1457
  const from = typeof account === "string" ? account : account.address;
1281
1458
  const hash = await this.context.walletClient.writeContract({
1282
1459
  address: dataRegistryAddress,
@@ -1284,7 +1461,8 @@ class DataController {
1284
1461
  functionName: "addFileWithSchema",
1285
1462
  args: [url, BigInt(schemaId)],
1286
1463
  account,
1287
- chain: this.context.walletClient.chain ?? null
1464
+ chain: this.context.walletClient.chain ?? null,
1465
+ ...this.spreadTransactionOptions(options)
1288
1466
  });
1289
1467
  const { tx } = await import("../utils/transactionHelpers");
1290
1468
  return tx({
@@ -1306,13 +1484,6 @@ class DataController {
1306
1484
  * @returns Promise resolving to the user's wallet address
1307
1485
  * @throws {Error} When no addresses are available in wallet client
1308
1486
  */
1309
- async getUserAddress() {
1310
- const addresses = await this.context.walletClient.getAddresses();
1311
- if (addresses.length === 0) {
1312
- throw new Error("No addresses available in wallet client");
1313
- }
1314
- return addresses[0];
1315
- }
1316
1487
  /**
1317
1488
  * Adds a file with permissions to the DataRegistry contract.
1318
1489
  *
@@ -1329,12 +1500,14 @@ class DataController {
1329
1500
  * with specific permissions on the DataRegistry contract. It can be used
1330
1501
  * by both direct transactions and relayer services.
1331
1502
  */
1332
- async addFileWithPermissions(url, ownerAddress, permissions = []) {
1503
+ async addFileWithPermissions(url, ownerAddress, permissions = [], options) {
1504
+ this.assertWallet();
1333
1505
  try {
1334
- const chainId = this.context.walletClient.chain?.id;
1506
+ const chainId = this.context.publicClient.chain?.id;
1335
1507
  if (!chainId) {
1336
1508
  throw new Error("Chain ID not available");
1337
1509
  }
1510
+ this.assertWallet();
1338
1511
  const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
1339
1512
  const dataRegistryAbi = getAbi("DataRegistry");
1340
1513
  const account = this.context.walletClient.account ?? ownerAddress;
@@ -1345,7 +1518,8 @@ class DataController {
1345
1518
  functionName: "addFileWithPermissions",
1346
1519
  args: [url, ownerAddress, permissions],
1347
1520
  account,
1348
- chain: this.context.walletClient.chain ?? null
1521
+ chain: this.context.walletClient.chain ?? null,
1522
+ ...this.spreadTransactionOptions(options)
1349
1523
  });
1350
1524
  const { tx } = await import("../utils/transactionHelpers");
1351
1525
  return tx({
@@ -1400,10 +1574,12 @@ class DataController {
1400
1574
  * console.log(`File ${result.fileId} registered in tx ${result.hash}`);
1401
1575
  * ```
1402
1576
  */
1403
- async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
1577
+ async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
1578
+ this.assertWallet();
1404
1579
  try {
1405
1580
  let encryptedPermissions = [];
1406
1581
  if (permissions.length > 0) {
1582
+ this.assertWallet();
1407
1583
  const userEncryptionKey = await generateEncryptionKey(
1408
1584
  this.context.walletClient,
1409
1585
  this.context.platform,
@@ -1428,11 +1604,12 @@ class DataController {
1428
1604
  })
1429
1605
  );
1430
1606
  }
1431
- return await this._addFileWithPermissionsAndSchemaInternal(
1607
+ return await this.addFileWithEncryptedPermissionsAndSchema(
1432
1608
  url,
1433
1609
  ownerAddress,
1434
1610
  encryptedPermissions,
1435
- schemaId
1611
+ schemaId,
1612
+ options
1436
1613
  );
1437
1614
  } catch (error) {
1438
1615
  console.error("Failed to add file with permissions and schema:", error);
@@ -1442,15 +1619,50 @@ class DataController {
1442
1619
  }
1443
1620
  }
1444
1621
  /**
1445
- * Internal method to add file with encrypted permissions and schema.
1446
- * @private
1622
+ * Adds a file with pre-encrypted permissions and schema to the DataRegistry.
1623
+ *
1624
+ * @remarks
1625
+ * This method is designed for relay services and advanced use cases where permissions
1626
+ * have already been encrypted client-side. Unlike `addFileWithPermissionsAndSchema()`,
1627
+ * this method expects permissions in the encrypted format with a 'key' field instead
1628
+ * of 'publicKey'.
1629
+ *
1630
+ * This is typically used by relay endpoints that receive pre-encrypted data from
1631
+ * the client SDK's `upload()` method, avoiding double encryption.
1632
+ *
1633
+ * @param url - The storage URL of the file (e.g., IPFS URL)
1634
+ * @param ownerAddress - The address that will own this file
1635
+ * @param permissions - Array of pre-encrypted permissions with 'account' and 'key' fields
1636
+ * @param schemaId - Optional schema ID for data validation (defaults to 0)
1637
+ * @returns Promise resolving to transaction result with hash and contract details
1638
+ * @throws {Error} When chain ID is not available
1639
+ * @throws {Error} When wallet is not connected
1640
+ * @throws {Error} When transaction fails
1641
+ * @example
1642
+ * ```typescript
1643
+ * // In a relay endpoint that receives pre-encrypted permissions
1644
+ * const result = await vana.data.addFileWithEncryptedPermissionsAndSchema(
1645
+ * "ipfs://QmXxx...",
1646
+ * ownerAddress,
1647
+ * [
1648
+ * {
1649
+ * account: "0xServerAddress...",
1650
+ * key: "encrypted_key_string" // Already encrypted by client
1651
+ * }
1652
+ * ],
1653
+ * schemaId
1654
+ * );
1655
+ *
1656
+ * console.log(`File registered in tx ${result.hash}`);
1657
+ * ```
1447
1658
  */
1448
- async _addFileWithPermissionsAndSchemaInternal(url, ownerAddress, permissions = [], schemaId = 0) {
1659
+ async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
1449
1660
  try {
1450
- const chainId = this.context.walletClient.chain?.id;
1661
+ const chainId = this.context.publicClient.chain?.id;
1451
1662
  if (!chainId) {
1452
1663
  throw new Error("Chain ID not available");
1453
1664
  }
1665
+ this.assertWallet();
1454
1666
  const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
1455
1667
  const dataRegistryAbi = getAbi("DataRegistry");
1456
1668
  const account = this.context.walletClient.account ?? ownerAddress;
@@ -1461,7 +1673,8 @@ class DataController {
1461
1673
  functionName: "addFileWithPermissionsAndSchema",
1462
1674
  args: [url, ownerAddress, permissions, BigInt(schemaId)],
1463
1675
  account,
1464
- chain: this.context.walletClient.chain ?? null
1676
+ chain: this.context.walletClient.chain ?? null,
1677
+ ...this.spreadTransactionOptions(options)
1465
1678
  });
1466
1679
  const { tx } = await import("../utils/transactionHelpers");
1467
1680
  return tx({
@@ -1478,36 +1691,41 @@ class DataController {
1478
1691
  }
1479
1692
  }
1480
1693
  /**
1481
- * Adds a new refiner to the DataRefinerRegistry.
1694
+ * Registers a data refiner for processing templates.
1482
1695
  *
1483
1696
  * @remarks
1484
- * Refiners are data processing templates that define how raw data should be
1485
- * transformed into structured formats. Each refiner is associated with a DLP
1486
- * (Data Liquidity Pool), has a specific schema for output, and includes
1487
- * instructions for the refinement process.
1488
- *
1489
- * @param params - Refiner configuration parameters
1490
- * @param params.dlpId - The Data Liquidity Pool ID this refiner belongs to
1491
- * @param params.name - Human-readable name for the refiner
1492
- * @param params.schemaId - Schema ID that defines the output format
1493
- * @param params.refinementInstructionUrl - URL containing processing instructions
1494
- * @returns Promise resolving to the new refiner ID and transaction hash
1495
- * @throws {Error} When chain ID is not available - "Chain ID not available"
1496
- * @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
+ *
1497
1714
  * @example
1498
1715
  * ```typescript
1499
1716
  * const result = await vana.data.addRefiner({
1500
1717
  * dlpId: 1,
1501
- * name: "Social Media Sentiment Analyzer",
1718
+ * name: "Sentiment Analyzer",
1502
1719
  * schemaId: 42,
1503
1720
  * refinementInstructionUrl: "ipfs://QmXxx..."
1504
1721
  * });
1505
- * console.log(`Created refiner ${result.refinerId} in tx ${result.transactionHash}`);
1722
+ * console.log(`Refiner ${result.refinerId} created`);
1506
1723
  * ```
1507
1724
  */
1508
- async addRefiner(params) {
1725
+ async addRefiner(params, options) {
1726
+ this.assertWallet();
1509
1727
  try {
1510
- const chainId = this.context.walletClient.chain?.id;
1728
+ const chainId = this.context.publicClient.chain?.id;
1511
1729
  if (!chainId) {
1512
1730
  throw new Error("Chain ID not available");
1513
1731
  }
@@ -1516,7 +1734,8 @@ class DataController {
1516
1734
  "DataRefinerRegistry"
1517
1735
  );
1518
1736
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
1519
- const account = this.context.walletClient.account ?? await this.getUserAddress();
1737
+ this.assertWallet();
1738
+ const account = this.context.walletClient.account ?? this.context.userAddress;
1520
1739
  const from = typeof account === "string" ? account : account.address;
1521
1740
  const hash = await this.context.walletClient.writeContract({
1522
1741
  address: dataRefinerRegistryAddress,
@@ -1529,7 +1748,8 @@ class DataController {
1529
1748
  params.refinementInstructionUrl
1530
1749
  ],
1531
1750
  account,
1532
- chain: this.context.walletClient.chain ?? null
1751
+ chain: this.context.walletClient.chain ?? null,
1752
+ ...this.spreadTransactionOptions(options)
1533
1753
  });
1534
1754
  const { tx } = await import("../utils/transactionHelpers");
1535
1755
  const txResult = tx({
@@ -1558,31 +1778,34 @@ class DataController {
1558
1778
  }
1559
1779
  }
1560
1780
  /**
1561
- * Retrieves a refiner by its ID.
1781
+ * Retrieves refiner configuration by ID.
1562
1782
  *
1563
1783
  * @remarks
1564
- * Queries the DataRefinerRegistry contract to get complete information about
1565
- * 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.
1566
1797
  *
1567
- * @param refinerId - The numeric refiner ID to retrieve
1568
- * @returns Promise resolving to the refiner information object
1569
- * @throws {Error} When chain ID is not available - "Chain ID not available"
1570
- * @throws {Error} When refiner doesn't exist - "Refiner with ID {refinerId} does not exist"
1571
- * @throws {Error} When contract read fails - "Failed to fetch refiner: {error}"
1572
1798
  * @example
1573
1799
  * ```typescript
1574
1800
  * const refiner = await vana.data.getRefiner(1);
1575
- * console.log({
1576
- * name: refiner.name,
1577
- * dlp: refiner.dlpId,
1578
- * schema: refiner.schemaId,
1579
- * instructions: refiner.refinementInstructionUrl
1580
- * });
1801
+ * console.log(`Refiner: ${refiner.name}`);
1802
+ * console.log(`DLP: ${refiner.dlpId}`);
1803
+ * console.log(`Schema: ${refiner.schemaId}`);
1581
1804
  * ```
1582
1805
  */
1583
1806
  async getRefiner(refinerId) {
1584
1807
  try {
1585
- const chainId = this.context.walletClient.chain?.id;
1808
+ const chainId = this.context.publicClient.chain?.id;
1586
1809
  if (!chainId) {
1587
1810
  throw new Error("Chain ID not available");
1588
1811
  }
@@ -1594,7 +1817,7 @@ class DataController {
1594
1817
  const dataRefinerRegistry = getContract({
1595
1818
  address: dataRefinerRegistryAddress,
1596
1819
  abi: dataRefinerRegistryAbi,
1597
- client: this.context.walletClient
1820
+ client: this.context.publicClient
1598
1821
  });
1599
1822
  const refinerData = await dataRefinerRegistry.read.refiners([
1600
1823
  BigInt(refinerId)
@@ -1618,27 +1841,33 @@ class DataController {
1618
1841
  }
1619
1842
  }
1620
1843
  /**
1621
- * Validates if a schema ID exists in the registry.
1844
+ * Validates schema ID existence.
1622
1845
  *
1623
1846
  * @remarks
1624
- * Checks the DataRefinerRegistry contract to determine if a given schema ID
1625
- * 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.
1626
1858
  *
1627
- * @param schemaId - The numeric schema ID to validate
1628
- * @returns Promise resolving to true if schema exists, false otherwise
1629
1859
  * @example
1630
1860
  * ```typescript
1631
- * const isValid = await vana.data.isValidSchemaId(42);
1632
- * if (isValid) {
1633
- * console.log('Schema 42 is available for use');
1634
- * } else {
1635
- * 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, ... });
1636
1865
  * }
1637
1866
  * ```
1638
1867
  */
1639
1868
  async isValidSchemaId(schemaId) {
1640
1869
  try {
1641
- const chainId = this.context.walletClient.chain?.id;
1870
+ const chainId = this.context.publicClient.chain?.id;
1642
1871
  if (!chainId) {
1643
1872
  throw new Error("Chain ID not available");
1644
1873
  }
@@ -1650,7 +1879,7 @@ class DataController {
1650
1879
  const dataRefinerRegistry = getContract({
1651
1880
  address: dataRefinerRegistryAddress,
1652
1881
  abi: dataRefinerRegistryAbi,
1653
- client: this.context.walletClient
1882
+ client: this.context.publicClient
1654
1883
  });
1655
1884
  const isValid = await dataRefinerRegistry.read.isValidSchemaId([
1656
1885
  BigInt(schemaId)
@@ -1677,7 +1906,7 @@ class DataController {
1677
1906
  */
1678
1907
  async getRefinersCount() {
1679
1908
  try {
1680
- const chainId = this.context.walletClient.chain?.id;
1909
+ const chainId = this.context.publicClient.chain?.id;
1681
1910
  if (!chainId) {
1682
1911
  throw new Error("Chain ID not available");
1683
1912
  }
@@ -1689,7 +1918,7 @@ class DataController {
1689
1918
  const dataRefinerRegistry = getContract({
1690
1919
  address: dataRefinerRegistryAddress,
1691
1920
  abi: dataRefinerRegistryAbi,
1692
- client: this.context.walletClient
1921
+ client: this.context.publicClient
1693
1922
  });
1694
1923
  const count = await dataRefinerRegistry.read.refinersCount();
1695
1924
  return Number(count);
@@ -1720,9 +1949,10 @@ class DataController {
1720
1949
  * console.log(`Schema updated in tx ${result.transactionHash}`);
1721
1950
  * ```
1722
1951
  */
1723
- async updateSchemaId(params) {
1952
+ async updateSchemaId(params, options) {
1953
+ this.assertWallet();
1724
1954
  try {
1725
- const chainId = this.context.walletClient.chain?.id;
1955
+ const chainId = this.context.publicClient.chain?.id;
1726
1956
  if (!chainId) {
1727
1957
  throw new Error("Chain ID not available");
1728
1958
  }
@@ -1731,14 +1961,16 @@ class DataController {
1731
1961
  "DataRefinerRegistry"
1732
1962
  );
1733
1963
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
1734
- const account = this.context.walletClient.account ?? await this.getUserAddress();
1964
+ this.assertWallet();
1965
+ const account = this.context.walletClient.account ?? this.context.userAddress;
1735
1966
  const hash = await this.context.walletClient.writeContract({
1736
1967
  address: dataRefinerRegistryAddress,
1737
1968
  abi: dataRefinerRegistryAbi,
1738
1969
  functionName: "updateSchemaId",
1739
1970
  args: [BigInt(params.refinerId), BigInt(params.newSchemaId)],
1740
1971
  account,
1741
- chain: this.context.walletClient.chain ?? null
1972
+ chain: this.context.walletClient.chain ?? null,
1973
+ ...this.spreadTransactionOptions(options)
1742
1974
  });
1743
1975
  await this.context.publicClient.waitForTransactionReceipt({ hash });
1744
1976
  return {
@@ -1760,13 +1992,12 @@ class DataController {
1760
1992
  * 3. Encrypts the user's encryption key with the provided public key
1761
1993
  * 4. Registers the file with permissions
1762
1994
  *
1763
- * @param data - The file data to encrypt and upload
1764
- * @param permissions - Array of permissions to grant, each with account address and public key
1765
- * @param filename - Optional filename for the upload
1766
- * @param providerName - Optional storage provider to use
1995
+ * @param params - Upload parameters including data, permissions, and options
1767
1996
  * @returns Promise resolving to upload result with file ID and storage URL
1768
1997
  */
1769
- async uploadFileWithPermissions(data, permissions, filename, providerName) {
1998
+ async uploadFileWithPermissions(params) {
1999
+ this.assertWallet();
2000
+ const { data, permissions, filename, providerName } = params;
1770
2001
  try {
1771
2002
  const uploadResult = await this.uploadToStorage(
1772
2003
  data,
@@ -1775,7 +2006,7 @@ class DataController {
1775
2006
  // Always encrypt for uploadFileWithPermissions
1776
2007
  providerName
1777
2008
  );
1778
- const userAddress = await this.getUserAddress();
2009
+ const userAddress = this.context.userAddress;
1779
2010
  const userEncryptionKey = await generateEncryptionKey(
1780
2011
  this.context.walletClient,
1781
2012
  this.context.platform,
@@ -1794,12 +2025,32 @@ class DataController {
1794
2025
  };
1795
2026
  })
1796
2027
  );
1797
- if (this.context.relayerCallbacks?.submitFileAdditionWithPermissions) {
1798
- const result = await this.context.relayerCallbacks.submitFileAdditionWithPermissions(
1799
- uploadResult.url,
1800
- userAddress,
1801
- encryptedPermissions
1802
- );
2028
+ if (this.context.relayer) {
2029
+ const request = {
2030
+ type: "direct",
2031
+ operation: "submitFileAdditionWithPermissions",
2032
+ params: {
2033
+ url: uploadResult.url,
2034
+ userAddress,
2035
+ permissions: encryptedPermissions
2036
+ }
2037
+ };
2038
+ const response = await this.context.relayer(request);
2039
+ if (response.type === "error") {
2040
+ throw new Error(response.error);
2041
+ }
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 {
2052
+ throw new Error("Invalid response from relayer");
2053
+ }
1803
2054
  return {
1804
2055
  fileId: result.fileId,
1805
2056
  url: uploadResult.url,
@@ -1866,6 +2117,7 @@ class DataController {
1866
2117
  }
1867
2118
  let finalBlob = blob;
1868
2119
  if (encrypt) {
2120
+ this.assertWallet();
1869
2121
  const encryptionKey = await generateEncryptionKey(
1870
2122
  this.context.walletClient,
1871
2123
  this.context.platform,
@@ -1887,7 +2139,15 @@ class DataController {
1887
2139
  );
1888
2140
  }
1889
2141
  }
1890
- 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
+ })();
1891
2151
  const uploadResult = await this.context.storageManager.upload(
1892
2152
  finalBlob,
1893
2153
  finalFilename,
@@ -1912,22 +2172,30 @@ class DataController {
1912
2172
  * For advanced users who need more control over transaction timing,
1913
2173
  * use `submitFilePermission()` instead.
1914
2174
  *
1915
- * @param fileId - The ID of the file to add permissions for
1916
- * @param account - The address of the account to grant permission to
1917
- * @param publicKey - The public key to encrypt the user's encryption key with (hex string with 0x prefix)
2175
+ * @param params - Parameters for adding file permission
2176
+ * @param params.fileId - The ID of the file to grant permission for
2177
+ * @param params.account - The recipient's wallet address that will access the file
2178
+ * @param params.publicKey - The recipient's public key for encryption.
2179
+ * Obtain via `vana.server.getIdentity(account).publicKey`
1918
2180
  * @returns Promise resolving to permission data from PermissionGranted event
1919
2181
  * @throws {Error} "No addresses available in wallet client" - When wallet is not connected
1920
2182
  * @throws {Error} "Chain ID not available" - When wallet chain is not configured
1921
2183
  * @throws {Error} "Failed to add permission to file: {error}" - When transaction fails or user doesn't own file
1922
2184
  * @example
1923
2185
  * ```typescript
1924
- * const result = await vana.data.addPermissionToFile(fileId, account, publicKey);
2186
+ * const result = await vana.data.addPermissionToFile({
2187
+ * fileId: 123,
2188
+ * account: "0xRecipientAddress...",
2189
+ * publicKey: "0xRecipientPublicKey..."
2190
+ * });
1925
2191
  * console.log(`Permission granted to ${result.account} for file ${result.fileId}`);
1926
2192
  * console.log(`Transaction: ${result.transactionHash}`);
1927
2193
  * ```
1928
2194
  */
1929
- async addPermissionToFile(fileId, account, publicKey) {
1930
- return await this.submitFilePermission(fileId, account, publicKey);
2195
+ async addPermissionToFile(params, options) {
2196
+ this.assertWallet();
2197
+ const { fileId, account, publicKey } = params;
2198
+ return await this.submitFilePermission(fileId, account, publicKey, options);
1931
2199
  }
1932
2200
  /**
1933
2201
  * Submits a file permission transaction to the blockchain.
@@ -1957,7 +2225,8 @@ class DataController {
1957
2225
  * console.log(`Permission granted with ID: ${result.permissionId}`);
1958
2226
  * ```
1959
2227
  */
1960
- async submitFilePermission(fileId, account, publicKey) {
2228
+ async submitFilePermission(fileId, account, publicKey, options) {
2229
+ this.assertWallet();
1961
2230
  try {
1962
2231
  const userEncryptionKey = await generateEncryptionKey(
1963
2232
  this.context.walletClient,
@@ -1969,20 +2238,22 @@ class DataController {
1969
2238
  publicKey,
1970
2239
  this.context.platform
1971
2240
  );
1972
- const chainId = this.context.walletClient.chain?.id;
2241
+ const chainId = this.context.publicClient.chain?.id;
1973
2242
  if (!chainId) {
1974
2243
  throw new Error("Chain ID not available");
1975
2244
  }
1976
2245
  const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
1977
2246
  const dataRegistryAbi = getAbi("DataRegistry");
1978
- const walletAccount = this.context.walletClient.account ?? await this.getUserAddress();
2247
+ this.assertWallet();
2248
+ const walletAccount = this.context.walletClient.account ?? this.context.userAddress;
1979
2249
  const txHash = await this.context.walletClient.writeContract({
1980
2250
  address: dataRegistryAddress,
1981
2251
  abi: dataRegistryAbi,
1982
2252
  functionName: "addFilePermission",
1983
2253
  args: [BigInt(fileId), account, encryptedKey],
1984
2254
  account: walletAccount,
1985
- chain: this.context.walletClient.chain ?? null
2255
+ chain: this.context.walletClient.chain ?? null,
2256
+ ...this.spreadTransactionOptions(options)
1986
2257
  });
1987
2258
  const { tx } = await import("../utils/transactionHelpers");
1988
2259
  return tx({
@@ -2007,7 +2278,7 @@ class DataController {
2007
2278
  */
2008
2279
  async getFilePermission(fileId, account) {
2009
2280
  try {
2010
- const chainId = this.context.walletClient.chain?.id;
2281
+ const chainId = this.context.publicClient.chain?.id;
2011
2282
  if (!chainId) {
2012
2283
  throw new Error("Chain ID not available");
2013
2284
  }
@@ -2016,7 +2287,7 @@ class DataController {
2016
2287
  const dataRegistry = getContract({
2017
2288
  address: dataRegistryAddress,
2018
2289
  abi: dataRegistryAbi,
2019
- client: this.context.walletClient
2290
+ client: this.context.publicClient
2020
2291
  });
2021
2292
  const encryptedKey = await dataRegistry.read.filePermissions([
2022
2293
  BigInt(fileId),
@@ -2040,12 +2311,13 @@ class DataController {
2040
2311
  *
2041
2312
  * @param file - The file to decrypt
2042
2313
  * @param privateKey - The private key to decrypt the user's encryption key
2043
- * @param account - The account address that has permission (defaults to current wallet account)
2314
+ * @param options - Optional decryption configuration
2315
+ * @param options.account - The account address that has permission (defaults to current wallet account)
2044
2316
  * @returns Promise resolving to the decrypted file data
2045
2317
  */
2046
- async decryptFileWithPermission(file, privateKey, account) {
2318
+ async decryptFileWithPermission(file, privateKey, options) {
2047
2319
  try {
2048
- const permissionAccount = account ?? await this.getUserAddress();
2320
+ const permissionAccount = options?.account ?? this.context.userAddress;
2049
2321
  const encryptedKey = await this.getFilePermission(
2050
2322
  file.id,
2051
2323
  permissionAccount
@@ -2327,6 +2599,26 @@ class DataController {
2327
2599
  async fetchAndValidateSchema(url) {
2328
2600
  return fetchAndValidateSchema(url);
2329
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
+ }
2330
2622
  }
2331
2623
  export {
2332
2624
  DataController