@opendatalabs/vana-sdk 0.1.0-alpha.f05a34e → 0.1.0-alpha.f2a82f7

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 (815) hide show
  1. package/README.md +98 -36
  2. package/dist/__tests__/waitForTransactionEvents.test.d.ts +1 -0
  3. package/dist/browser.cjs +29 -0
  4. package/dist/browser.cjs.map +1 -0
  5. package/dist/browser.d.ts +36 -0
  6. package/dist/browser.js +5 -0
  7. package/dist/browser.js.map +1 -0
  8. package/dist/{chains.browser.cjs → chains/definitions.cjs} +16 -17
  9. package/dist/chains/definitions.cjs.map +1 -0
  10. package/dist/{chains.browser.d.cts → chains/definitions.d.ts} +9 -11
  11. package/dist/chains/definitions.js +67 -0
  12. package/dist/chains/definitions.js.map +1 -0
  13. package/dist/chains/index.cjs +37 -0
  14. package/dist/chains/index.cjs.map +1 -0
  15. package/dist/chains/index.d.ts +34 -0
  16. package/dist/chains/index.js +15 -0
  17. package/dist/chains/index.js.map +1 -0
  18. package/dist/chains.browser.d.ts +5 -50
  19. package/dist/chains.browser.js +7 -57
  20. package/dist/chains.browser.js.map +1 -1
  21. package/dist/chains.cjs +6 -65
  22. package/dist/chains.cjs.map +1 -1
  23. package/dist/chains.d.ts +8 -2
  24. package/dist/chains.js +7 -57
  25. package/dist/chains.js.map +1 -1
  26. package/dist/chains.node.cjs +6 -65
  27. package/dist/chains.node.cjs.map +1 -1
  28. package/dist/chains.node.d.ts +8 -2
  29. package/dist/chains.node.js +7 -57
  30. package/dist/chains.node.js.map +1 -1
  31. package/dist/config/addresses.cjs +325 -0
  32. package/dist/config/addresses.cjs.map +1 -0
  33. package/dist/config/addresses.d.ts +364 -0
  34. package/dist/config/addresses.js +295 -0
  35. package/dist/config/addresses.js.map +1 -0
  36. package/dist/config/chains.cjs +93 -0
  37. package/dist/config/chains.cjs.map +1 -0
  38. package/dist/config/chains.d.ts +180 -0
  39. package/dist/config/chains.js +67 -0
  40. package/dist/config/chains.js.map +1 -0
  41. package/dist/config/default-services.cjs +60 -0
  42. package/dist/config/default-services.cjs.map +1 -0
  43. package/dist/config/default-services.d.ts +46 -0
  44. package/dist/config/default-services.js +33 -0
  45. package/dist/config/default-services.js.map +1 -0
  46. package/dist/config/default-services.test.d.ts +1 -0
  47. package/dist/config/features.cjs +52 -0
  48. package/dist/config/features.cjs.map +1 -0
  49. package/dist/config/features.d.ts +62 -0
  50. package/dist/config/features.js +28 -0
  51. package/dist/config/features.js.map +1 -0
  52. package/dist/config/tests/addresses.test.d.ts +1 -0
  53. package/dist/contracts/contractController.cjs +126 -0
  54. package/dist/contracts/contractController.cjs.map +1 -0
  55. package/dist/contracts/contractController.d.ts +135 -0
  56. package/dist/contracts/contractController.js +100 -0
  57. package/dist/contracts/contractController.js.map +1 -0
  58. package/dist/contracts/tests/contractController.test.d.ts +1 -0
  59. package/dist/controllers/__tests__/schemas-edge-cases.test.d.ts +1 -0
  60. package/dist/controllers/base.cjs +116 -0
  61. package/dist/controllers/base.cjs.map +1 -0
  62. package/dist/controllers/base.d.ts +94 -0
  63. package/dist/controllers/base.js +92 -0
  64. package/dist/controllers/base.js.map +1 -0
  65. package/dist/controllers/data-error-handling.test.d.ts +1 -0
  66. package/dist/controllers/data.cjs +2521 -0
  67. package/dist/controllers/data.cjs.map +1 -0
  68. package/dist/controllers/data.d.ts +1052 -0
  69. package/dist/controllers/data.js +2504 -0
  70. package/dist/controllers/data.js.map +1 -0
  71. package/dist/controllers/permissions.cjs +4030 -0
  72. package/dist/controllers/permissions.cjs.map +1 -0
  73. package/dist/controllers/permissions.d.ts +1313 -0
  74. package/dist/controllers/permissions.js +4006 -0
  75. package/dist/controllers/permissions.js.map +1 -0
  76. package/dist/controllers/protocol.cjs +183 -0
  77. package/dist/controllers/protocol.cjs.map +1 -0
  78. package/dist/controllers/protocol.d.ts +138 -0
  79. package/dist/controllers/protocol.js +163 -0
  80. package/dist/controllers/protocol.js.map +1 -0
  81. package/dist/controllers/schemas.cjs +601 -0
  82. package/dist/controllers/schemas.cjs.map +1 -0
  83. package/dist/controllers/schemas.d.ts +252 -0
  84. package/dist/controllers/schemas.js +577 -0
  85. package/dist/controllers/schemas.js.map +1 -0
  86. package/dist/controllers/server-additional.test.d.ts +1 -0
  87. package/dist/controllers/server.cjs +434 -0
  88. package/dist/controllers/server.cjs.map +1 -0
  89. package/dist/controllers/server.d.ts +225 -0
  90. package/dist/controllers/server.js +415 -0
  91. package/dist/controllers/server.js.map +1 -0
  92. package/dist/core/apiClient.cjs +378 -0
  93. package/dist/core/apiClient.cjs.map +1 -0
  94. package/dist/core/apiClient.d.ts +286 -0
  95. package/dist/core/apiClient.js +359 -0
  96. package/dist/core/apiClient.js.map +1 -0
  97. package/dist/core/client.cjs +70 -0
  98. package/dist/core/client.cjs.map +1 -0
  99. package/dist/core/client.d.ts +89 -0
  100. package/dist/core/client.js +47 -0
  101. package/dist/core/client.js.map +1 -0
  102. package/dist/core/core.test.d.ts +1 -0
  103. package/dist/core/generics.cjs +417 -0
  104. package/dist/core/generics.cjs.map +1 -0
  105. package/dist/core/generics.d.ts +205 -0
  106. package/dist/core/generics.js +386 -0
  107. package/dist/core/generics.js.map +1 -0
  108. package/dist/core/tests/apiClient.test.d.ts +1 -0
  109. package/dist/core/tests/client.test.d.ts +1 -0
  110. package/dist/core/tests/generics.test.d.ts +1 -0
  111. package/dist/core.cjs +726 -0
  112. package/dist/core.cjs.map +1 -0
  113. package/dist/core.d.ts +443 -0
  114. package/dist/core.js +701 -0
  115. package/dist/core.js.map +1 -0
  116. package/dist/crypto/ecies/__tests__/base.test.d.ts +4 -0
  117. package/dist/crypto/ecies/__tests__/compatibility.test.d.ts +8 -0
  118. package/dist/crypto/ecies/__tests__/constants.test.d.ts +4 -0
  119. package/dist/crypto/ecies/__tests__/native-parity.test.d.ts +7 -0
  120. package/dist/crypto/ecies/__tests__/normalization.test.d.ts +1 -0
  121. package/dist/crypto/ecies/__tests__/test-vectors.cjs +102 -0
  122. package/dist/crypto/ecies/__tests__/test-vectors.cjs.map +1 -0
  123. package/dist/crypto/ecies/__tests__/test-vectors.d.ts +38 -0
  124. package/dist/crypto/ecies/__tests__/test-vectors.js +77 -0
  125. package/dist/crypto/ecies/__tests__/test-vectors.js.map +1 -0
  126. package/dist/crypto/ecies/base.cjs +232 -0
  127. package/dist/crypto/ecies/base.cjs.map +1 -0
  128. package/dist/crypto/ecies/base.d.ts +140 -0
  129. package/dist/crypto/ecies/base.js +208 -0
  130. package/dist/crypto/ecies/base.js.map +1 -0
  131. package/dist/crypto/ecies/browser.cjs +165 -0
  132. package/dist/crypto/ecies/browser.cjs.map +1 -0
  133. package/dist/crypto/ecies/browser.d.ts +43 -0
  134. package/dist/crypto/ecies/browser.js +131 -0
  135. package/dist/crypto/ecies/browser.js.map +1 -0
  136. package/dist/crypto/ecies/constants.cjs +131 -0
  137. package/dist/crypto/ecies/constants.cjs.map +1 -0
  138. package/dist/crypto/ecies/constants.d.ts +120 -0
  139. package/dist/crypto/ecies/constants.js +101 -0
  140. package/dist/crypto/ecies/constants.js.map +1 -0
  141. package/dist/crypto/ecies/index.cjs +35 -0
  142. package/dist/crypto/ecies/index.cjs.map +1 -0
  143. package/dist/crypto/ecies/index.d.ts +8 -0
  144. package/dist/crypto/ecies/index.js +13 -0
  145. package/dist/crypto/ecies/index.js.map +1 -0
  146. package/dist/crypto/ecies/interface.cjs +87 -0
  147. package/dist/crypto/ecies/interface.cjs.map +1 -0
  148. package/dist/crypto/ecies/interface.d.ts +174 -0
  149. package/dist/crypto/ecies/interface.js +60 -0
  150. package/dist/crypto/ecies/interface.js.map +1 -0
  151. package/dist/crypto/ecies/node.cjs +167 -0
  152. package/dist/crypto/ecies/node.cjs.map +1 -0
  153. package/dist/crypto/ecies/node.d.ts +45 -0
  154. package/dist/crypto/ecies/node.js +139 -0
  155. package/dist/crypto/ecies/node.js.map +1 -0
  156. package/dist/crypto/ecies/test-vectors/eccrypto-vectors.json +72 -0
  157. package/dist/crypto/ecies/utils.cjs +52 -0
  158. package/dist/crypto/ecies/utils.cjs.map +1 -0
  159. package/dist/crypto/ecies/utils.d.ts +30 -0
  160. package/dist/crypto/ecies/utils.js +26 -0
  161. package/dist/crypto/ecies/utils.js.map +1 -0
  162. package/dist/crypto/services/WalletKeyEncryptionService.cjs +128 -0
  163. package/dist/crypto/services/WalletKeyEncryptionService.cjs.map +1 -0
  164. package/dist/crypto/services/WalletKeyEncryptionService.d.ts +88 -0
  165. package/dist/crypto/services/WalletKeyEncryptionService.js +108 -0
  166. package/dist/crypto/services/WalletKeyEncryptionService.js.map +1 -0
  167. package/dist/crypto/services/WalletKeyEncryptionService.test.d.ts +1 -0
  168. package/dist/diagnostics.cjs +37 -0
  169. package/dist/diagnostics.cjs.map +1 -0
  170. package/dist/diagnostics.d.ts +24 -0
  171. package/dist/diagnostics.js +13 -0
  172. package/dist/diagnostics.js.map +1 -0
  173. package/dist/diagnostics.test.d.ts +1 -0
  174. package/dist/errors.cjs +157 -0
  175. package/dist/errors.cjs.map +1 -0
  176. package/dist/errors.d.ts +388 -0
  177. package/dist/errors.js +120 -0
  178. package/dist/errors.js.map +1 -0
  179. package/dist/generated/abi/ComputeEngineImplementation.cjs +1313 -0
  180. package/dist/generated/abi/ComputeEngineImplementation.cjs.map +1 -0
  181. package/dist/generated/abi/ComputeEngineImplementation.d.ts +995 -0
  182. package/dist/generated/abi/ComputeEngineImplementation.js +1289 -0
  183. package/dist/generated/abi/ComputeEngineImplementation.js.map +1 -0
  184. package/dist/generated/abi/ComputeInstructionRegistryImplementation.cjs +734 -0
  185. package/dist/generated/abi/ComputeInstructionRegistryImplementation.cjs.map +1 -0
  186. package/dist/generated/abi/ComputeInstructionRegistryImplementation.d.ts +544 -0
  187. package/dist/generated/abi/ComputeInstructionRegistryImplementation.js +710 -0
  188. package/dist/generated/abi/ComputeInstructionRegistryImplementation.js.map +1 -0
  189. package/dist/generated/abi/DATFactoryImplementation.cjs +882 -0
  190. package/dist/generated/abi/DATFactoryImplementation.cjs.map +1 -0
  191. package/dist/generated/abi/DATFactoryImplementation.d.ts +660 -0
  192. package/dist/generated/abi/DATFactoryImplementation.js +858 -0
  193. package/dist/generated/abi/DATFactoryImplementation.js.map +1 -0
  194. package/dist/generated/abi/DATImplementation.cjs +934 -0
  195. package/dist/generated/abi/DATImplementation.cjs.map +1 -0
  196. package/dist/generated/abi/DATImplementation.d.ts +692 -0
  197. package/dist/generated/abi/DATImplementation.js +910 -0
  198. package/dist/generated/abi/DATImplementation.js.map +1 -0
  199. package/dist/generated/abi/DATPausableImplementation.cjs +1523 -0
  200. package/dist/generated/abi/DATPausableImplementation.cjs.map +1 -0
  201. package/dist/generated/abi/DATPausableImplementation.d.ts +1144 -0
  202. package/dist/generated/abi/DATPausableImplementation.js +1499 -0
  203. package/dist/generated/abi/DATPausableImplementation.js.map +1 -0
  204. package/dist/generated/abi/DATVotesImplementation.cjs +1460 -0
  205. package/dist/generated/abi/DATVotesImplementation.cjs.map +1 -0
  206. package/dist/generated/abi/DATVotesImplementation.d.ts +1094 -0
  207. package/dist/generated/abi/DATVotesImplementation.js +1436 -0
  208. package/dist/generated/abi/DATVotesImplementation.js.map +1 -0
  209. package/dist/generated/abi/DLPPerformanceImplementation.cjs +1160 -0
  210. package/dist/generated/abi/DLPPerformanceImplementation.cjs.map +1 -0
  211. package/dist/generated/abi/DLPPerformanceImplementation.d.ts +882 -0
  212. package/dist/generated/abi/DLPPerformanceImplementation.js +1136 -0
  213. package/dist/generated/abi/DLPPerformanceImplementation.js.map +1 -0
  214. package/dist/generated/abi/DLPRegistryImplementation.cjs +1469 -0
  215. package/dist/generated/abi/DLPRegistryImplementation.cjs.map +1 -0
  216. package/dist/generated/abi/DLPRegistryImplementation.d.ts +1122 -0
  217. package/dist/generated/abi/DLPRegistryImplementation.js +1445 -0
  218. package/dist/generated/abi/DLPRegistryImplementation.js.map +1 -0
  219. package/dist/generated/abi/DLPRegistryTreasuryImplementation.cjs +612 -0
  220. package/dist/generated/abi/DLPRegistryTreasuryImplementation.cjs.map +1 -0
  221. package/dist/generated/abi/DLPRegistryTreasuryImplementation.d.ts +451 -0
  222. package/dist/generated/abi/DLPRegistryTreasuryImplementation.js +588 -0
  223. package/dist/generated/abi/DLPRegistryTreasuryImplementation.js.map +1 -0
  224. package/dist/generated/abi/DLPRewardDeployerImplementation.cjs +948 -0
  225. package/dist/generated/abi/DLPRewardDeployerImplementation.cjs.map +1 -0
  226. package/dist/generated/abi/DLPRewardDeployerImplementation.d.ts +713 -0
  227. package/dist/generated/abi/DLPRewardDeployerImplementation.js +924 -0
  228. package/dist/generated/abi/DLPRewardDeployerImplementation.js.map +1 -0
  229. package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.cjs +612 -0
  230. package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.cjs.map +1 -0
  231. package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.d.ts +451 -0
  232. package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.js +588 -0
  233. package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.js.map +1 -0
  234. package/dist/generated/abi/DLPRewardSwapImplementation.cjs +939 -0
  235. package/dist/generated/abi/DLPRewardSwapImplementation.cjs.map +1 -0
  236. package/dist/generated/abi/DLPRewardSwapImplementation.d.ts +705 -0
  237. package/dist/generated/abi/DLPRewardSwapImplementation.js +915 -0
  238. package/dist/generated/abi/DLPRewardSwapImplementation.js.map +1 -0
  239. package/dist/generated/abi/DLPRootImplementation.cjs +1644 -0
  240. package/dist/generated/abi/DLPRootImplementation.cjs.map +1 -0
  241. package/dist/generated/abi/DLPRootImplementation.d.ts +1246 -0
  242. package/dist/generated/abi/DLPRootImplementation.js +1620 -0
  243. package/dist/generated/abi/DLPRootImplementation.js.map +1 -0
  244. package/dist/generated/abi/DLPTreasuryImplementation.cjs +612 -0
  245. package/dist/generated/abi/DLPTreasuryImplementation.cjs.map +1 -0
  246. package/dist/generated/abi/DLPTreasuryImplementation.d.ts +451 -0
  247. package/dist/generated/abi/DLPTreasuryImplementation.js +588 -0
  248. package/dist/generated/abi/DLPTreasuryImplementation.js.map +1 -0
  249. package/dist/generated/abi/DataLiquidityPoolImplementation.cjs +985 -0
  250. package/dist/generated/abi/DataLiquidityPoolImplementation.cjs.map +1 -0
  251. package/dist/generated/abi/DataLiquidityPoolImplementation.d.ts +735 -0
  252. package/dist/generated/abi/DataLiquidityPoolImplementation.js +961 -0
  253. package/dist/generated/abi/DataLiquidityPoolImplementation.js.map +1 -0
  254. package/dist/generated/abi/DataPortabilityGranteesImplementation.cjs +888 -0
  255. package/dist/generated/abi/DataPortabilityGranteesImplementation.cjs.map +1 -0
  256. package/dist/generated/abi/DataPortabilityGranteesImplementation.d.ts +660 -0
  257. package/dist/generated/abi/DataPortabilityGranteesImplementation.js +864 -0
  258. package/dist/generated/abi/DataPortabilityGranteesImplementation.js.map +1 -0
  259. package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs +1317 -0
  260. package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs.map +1 -0
  261. package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.ts +988 -0
  262. package/dist/generated/abi/DataPortabilityPermissionsImplementation.js +1293 -0
  263. package/dist/generated/abi/DataPortabilityPermissionsImplementation.js.map +1 -0
  264. package/dist/generated/abi/DataPortabilityServersImplementation.cjs +1438 -0
  265. package/dist/generated/abi/DataPortabilityServersImplementation.cjs.map +1 -0
  266. package/dist/generated/abi/DataPortabilityServersImplementation.d.ts +1085 -0
  267. package/dist/generated/abi/DataPortabilityServersImplementation.js +1414 -0
  268. package/dist/generated/abi/DataPortabilityServersImplementation.js.map +1 -0
  269. package/dist/generated/abi/DataRefinerRegistryImplementation.cjs +984 -0
  270. package/dist/generated/abi/DataRefinerRegistryImplementation.cjs.map +1 -0
  271. package/dist/generated/abi/DataRefinerRegistryImplementation.d.ts +736 -0
  272. package/dist/generated/abi/DataRefinerRegistryImplementation.js +960 -0
  273. package/dist/generated/abi/DataRefinerRegistryImplementation.js.map +1 -0
  274. package/dist/generated/abi/DataRegistryImplementation.cjs +1341 -0
  275. package/dist/generated/abi/DataRegistryImplementation.cjs.map +1 -0
  276. package/dist/generated/abi/DataRegistryImplementation.d.ts +1013 -0
  277. package/dist/generated/abi/DataRegistryImplementation.js +1317 -0
  278. package/dist/generated/abi/DataRegistryImplementation.js.map +1 -0
  279. package/dist/generated/abi/QueryEngineImplementation.cjs +1319 -0
  280. package/dist/generated/abi/QueryEngineImplementation.cjs.map +1 -0
  281. package/dist/generated/abi/QueryEngineImplementation.d.ts +1000 -0
  282. package/dist/generated/abi/QueryEngineImplementation.js +1295 -0
  283. package/dist/generated/abi/QueryEngineImplementation.js.map +1 -0
  284. package/dist/generated/abi/SwapHelperImplementation.cjs +1019 -0
  285. package/dist/generated/abi/SwapHelperImplementation.cjs.map +1 -0
  286. package/dist/generated/abi/SwapHelperImplementation.d.ts +763 -0
  287. package/dist/generated/abi/SwapHelperImplementation.js +995 -0
  288. package/dist/generated/abi/SwapHelperImplementation.js.map +1 -0
  289. package/dist/generated/abi/TeePoolDedicatedGpuImplementation.cjs +936 -0
  290. package/dist/generated/abi/TeePoolDedicatedGpuImplementation.cjs.map +1 -0
  291. package/dist/generated/abi/TeePoolDedicatedGpuImplementation.d.ts +700 -0
  292. package/dist/generated/abi/TeePoolDedicatedGpuImplementation.js +912 -0
  293. package/dist/generated/abi/TeePoolDedicatedGpuImplementation.js.map +1 -0
  294. package/dist/generated/abi/TeePoolDedicatedStandardImplementation.cjs +936 -0
  295. package/dist/generated/abi/TeePoolDedicatedStandardImplementation.cjs.map +1 -0
  296. package/dist/generated/abi/TeePoolDedicatedStandardImplementation.d.ts +700 -0
  297. package/dist/generated/abi/TeePoolDedicatedStandardImplementation.js +912 -0
  298. package/dist/generated/abi/TeePoolDedicatedStandardImplementation.js.map +1 -0
  299. package/dist/generated/abi/TeePoolEphemeralStandardImplementation.cjs +936 -0
  300. package/dist/generated/abi/TeePoolEphemeralStandardImplementation.cjs.map +1 -0
  301. package/dist/generated/abi/TeePoolEphemeralStandardImplementation.d.ts +700 -0
  302. package/dist/generated/abi/TeePoolEphemeralStandardImplementation.js +912 -0
  303. package/dist/generated/abi/TeePoolEphemeralStandardImplementation.js.map +1 -0
  304. package/dist/generated/abi/TeePoolImplementation.cjs +1313 -0
  305. package/dist/generated/abi/TeePoolImplementation.cjs.map +1 -0
  306. package/dist/generated/abi/TeePoolImplementation.d.ts +992 -0
  307. package/dist/generated/abi/TeePoolImplementation.js +1289 -0
  308. package/dist/generated/abi/TeePoolImplementation.js.map +1 -0
  309. package/dist/generated/abi/TeePoolPersistentGpuImplementation.cjs +936 -0
  310. package/dist/generated/abi/TeePoolPersistentGpuImplementation.cjs.map +1 -0
  311. package/dist/generated/abi/TeePoolPersistentGpuImplementation.d.ts +700 -0
  312. package/dist/generated/abi/TeePoolPersistentGpuImplementation.js +912 -0
  313. package/dist/generated/abi/TeePoolPersistentGpuImplementation.js.map +1 -0
  314. package/dist/generated/abi/TeePoolPersistentStandardImplementation.cjs +936 -0
  315. package/dist/generated/abi/TeePoolPersistentStandardImplementation.cjs.map +1 -0
  316. package/dist/generated/abi/TeePoolPersistentStandardImplementation.d.ts +700 -0
  317. package/dist/generated/abi/TeePoolPersistentStandardImplementation.js +912 -0
  318. package/dist/generated/abi/TeePoolPersistentStandardImplementation.js.map +1 -0
  319. package/dist/generated/abi/TeePoolPhalaImplementation.cjs +1313 -0
  320. package/dist/generated/abi/TeePoolPhalaImplementation.cjs.map +1 -0
  321. package/dist/generated/abi/TeePoolPhalaImplementation.d.ts +992 -0
  322. package/dist/generated/abi/TeePoolPhalaImplementation.js +1289 -0
  323. package/dist/generated/abi/TeePoolPhalaImplementation.js.map +1 -0
  324. package/dist/generated/abi/VanaEpochImplementation.cjs +1188 -0
  325. package/dist/generated/abi/VanaEpochImplementation.cjs.map +1 -0
  326. package/dist/generated/abi/VanaEpochImplementation.d.ts +899 -0
  327. package/dist/generated/abi/VanaEpochImplementation.js +1164 -0
  328. package/dist/generated/abi/VanaEpochImplementation.js.map +1 -0
  329. package/dist/generated/abi/VanaPoolEntityImplementation.cjs +1234 -0
  330. package/dist/generated/abi/VanaPoolEntityImplementation.cjs.map +1 -0
  331. package/dist/generated/abi/VanaPoolEntityImplementation.d.ts +933 -0
  332. package/dist/generated/abi/VanaPoolEntityImplementation.js +1210 -0
  333. package/dist/generated/abi/VanaPoolEntityImplementation.js.map +1 -0
  334. package/dist/generated/abi/VanaPoolStakingImplementation.cjs +921 -0
  335. package/dist/generated/abi/VanaPoolStakingImplementation.cjs.map +1 -0
  336. package/dist/generated/abi/VanaPoolStakingImplementation.d.ts +692 -0
  337. package/dist/generated/abi/VanaPoolStakingImplementation.js +897 -0
  338. package/dist/generated/abi/VanaPoolStakingImplementation.js.map +1 -0
  339. package/dist/generated/abi/VanaPoolTreasuryImplementation.cjs +538 -0
  340. package/dist/generated/abi/VanaPoolTreasuryImplementation.cjs.map +1 -0
  341. package/dist/generated/abi/VanaPoolTreasuryImplementation.d.ts +393 -0
  342. package/dist/generated/abi/VanaPoolTreasuryImplementation.js +514 -0
  343. package/dist/generated/abi/VanaPoolTreasuryImplementation.js.map +1 -0
  344. package/dist/generated/abi/index.cjs +177 -0
  345. package/dist/generated/abi/index.cjs.map +1 -0
  346. package/dist/{index.node.d.cts → generated/abi/index.d.ts} +26541 -32582
  347. package/dist/generated/abi/index.js +120 -0
  348. package/dist/generated/abi/index.js.map +1 -0
  349. package/dist/generated/event-types.cjs +17 -0
  350. package/dist/generated/event-types.cjs.map +1 -0
  351. package/dist/generated/event-types.d.ts +854 -0
  352. package/dist/generated/event-types.js +1 -0
  353. package/dist/generated/event-types.js.map +1 -0
  354. package/dist/generated/eventRegistry.cjs +3351 -0
  355. package/dist/generated/eventRegistry.cjs.map +1 -0
  356. package/dist/generated/eventRegistry.d.ts +14 -0
  357. package/dist/generated/eventRegistry.js +3326 -0
  358. package/dist/generated/eventRegistry.js.map +1 -0
  359. package/dist/generated/server/server-exports.cjs +23 -0
  360. package/dist/generated/server/server-exports.cjs.map +1 -0
  361. package/dist/generated/server/server-exports.d.ts +19 -0
  362. package/dist/generated/server/server-exports.js +2 -0
  363. package/dist/generated/server/server-exports.js.map +1 -0
  364. package/dist/generated/server/server.cjs +17 -0
  365. package/dist/generated/server/server.cjs.map +1 -0
  366. package/dist/generated/server/server.d.ts +538 -0
  367. package/dist/generated/server/server.js +1 -0
  368. package/dist/generated/server/server.js.map +1 -0
  369. package/dist/generated/subgraph.cjs +675 -0
  370. package/dist/generated/subgraph.cjs.map +1 -0
  371. package/dist/generated/subgraph.d.ts +5978 -0
  372. package/dist/generated/subgraph.js +644 -0
  373. package/dist/generated/subgraph.js.map +1 -0
  374. package/dist/index.browser.d.ts +116 -32444
  375. package/dist/index.browser.js +76 -40974
  376. package/dist/index.browser.js.map +1 -1
  377. package/dist/index.cjs +5 -0
  378. package/dist/index.cjs.map +1 -0
  379. package/dist/index.d.ts +0 -0
  380. package/dist/index.js +4 -0
  381. package/dist/index.js.map +1 -0
  382. package/dist/index.node.cjs +99 -41421
  383. package/dist/index.node.cjs.map +1 -1
  384. package/dist/index.node.d.ts +157 -32540
  385. package/dist/index.node.js +81 -41311
  386. package/dist/index.node.js.map +1 -1
  387. package/dist/node.cjs +29 -0
  388. package/dist/node.cjs.map +1 -0
  389. package/dist/node.d.ts +42 -0
  390. package/dist/node.js +5 -0
  391. package/dist/node.js.map +1 -0
  392. package/dist/platform/browser-only.cjs +37 -0
  393. package/dist/platform/browser-only.cjs.map +1 -0
  394. package/dist/platform/browser-only.d.ts +22 -0
  395. package/dist/platform/browser-only.js +12 -0
  396. package/dist/platform/browser-only.js.map +1 -0
  397. package/dist/platform/browser-only.test.d.ts +1 -0
  398. package/dist/platform/browser-safe.cjs +57 -0
  399. package/dist/platform/browser-safe.cjs.map +1 -0
  400. package/dist/platform/browser-safe.d.ts +29 -0
  401. package/dist/platform/browser-safe.js +31 -0
  402. package/dist/platform/browser-safe.js.map +1 -0
  403. package/dist/platform/browser-safe.test.d.ts +1 -0
  404. package/dist/platform/browser.cjs +488 -0
  405. package/dist/platform/browser.cjs.map +1 -0
  406. package/dist/platform/browser.d.ts +291 -0
  407. package/dist/platform/browser.js +454 -0
  408. package/dist/platform/browser.js.map +1 -0
  409. package/dist/platform/browser.test.d.ts +1 -0
  410. package/dist/platform/index.cjs +50 -0
  411. package/dist/platform/index.cjs.map +1 -0
  412. package/dist/platform/index.d.ts +11 -0
  413. package/dist/platform/index.js +27 -0
  414. package/dist/platform/index.js.map +1 -0
  415. package/dist/platform/interface.cjs +17 -0
  416. package/dist/platform/interface.cjs.map +1 -0
  417. package/dist/platform/interface.d.ts +409 -0
  418. package/dist/platform/interface.js +1 -0
  419. package/dist/platform/interface.js.map +1 -0
  420. package/dist/platform/node.cjs +512 -0
  421. package/dist/platform/node.cjs.map +1 -0
  422. package/dist/platform/node.d.ts +86 -0
  423. package/dist/platform/node.js +481 -0
  424. package/dist/platform/node.js.map +1 -0
  425. package/dist/platform/ports/openpgp-port.cjs +74 -0
  426. package/dist/platform/ports/openpgp-port.cjs.map +1 -0
  427. package/dist/platform/ports/openpgp-port.d.ts +13 -0
  428. package/dist/platform/ports/openpgp-port.js +59 -0
  429. package/dist/platform/ports/openpgp-port.js.map +1 -0
  430. package/dist/platform/ports/pgp-port.cjs +17 -0
  431. package/dist/platform/ports/pgp-port.cjs.map +1 -0
  432. package/dist/platform/ports/pgp-port.d.ts +35 -0
  433. package/dist/platform/ports/pgp-port.js +1 -0
  434. package/dist/platform/ports/pgp-port.js.map +1 -0
  435. package/dist/platform/shared/error-utils.cjs +43 -0
  436. package/dist/platform/shared/error-utils.cjs.map +1 -0
  437. package/dist/platform/shared/error-utils.d.ts +23 -0
  438. package/dist/platform/shared/error-utils.js +18 -0
  439. package/dist/platform/shared/error-utils.js.map +1 -0
  440. package/dist/platform/shared/pgp-utils.cjs +55 -0
  441. package/dist/platform/shared/pgp-utils.cjs.map +1 -0
  442. package/dist/platform/shared/pgp-utils.d.ts +59 -0
  443. package/dist/platform/shared/pgp-utils.js +29 -0
  444. package/dist/platform/shared/pgp-utils.js.map +1 -0
  445. package/dist/platform/shared/stream-utils.cjs +49 -0
  446. package/dist/platform/shared/stream-utils.cjs.map +1 -0
  447. package/dist/platform/shared/stream-utils.d.ts +14 -0
  448. package/dist/platform/shared/stream-utils.js +25 -0
  449. package/dist/platform/shared/stream-utils.js.map +1 -0
  450. package/dist/platform/utils.cjs +114 -0
  451. package/dist/platform/utils.cjs.map +1 -0
  452. package/dist/platform/utils.d.ts +49 -0
  453. package/dist/platform/utils.js +76 -0
  454. package/dist/platform/utils.js.map +1 -0
  455. package/dist/platform/utils.test.d.ts +1 -0
  456. package/dist/platform.browser.d.ts +6 -221
  457. package/dist/platform.browser.js +10 -309
  458. package/dist/platform.browser.js.map +1 -1
  459. package/dist/platform.cjs +14 -623
  460. package/dist/platform.cjs.map +1 -1
  461. package/dist/platform.d.ts +11 -1
  462. package/dist/platform.js +14 -609
  463. package/dist/platform.js.map +1 -1
  464. package/dist/platform.node.cjs +14 -623
  465. package/dist/platform.node.cjs.map +1 -1
  466. package/dist/platform.node.d.ts +7 -261
  467. package/dist/platform.node.js +14 -609
  468. package/dist/platform.node.js.map +1 -1
  469. package/dist/schemas/dataSchema.schema.json +53 -0
  470. package/dist/schemas/grantFile.schema.json +43 -0
  471. package/dist/server/relayerHandler.cjs +328 -0
  472. package/dist/server/relayerHandler.cjs.map +1 -0
  473. package/dist/server/relayerHandler.d.ts +38 -0
  474. package/dist/server/relayerHandler.js +304 -0
  475. package/dist/server/relayerHandler.js.map +1 -0
  476. package/dist/storage/index.cjs +44 -0
  477. package/dist/storage/index.cjs.map +1 -0
  478. package/dist/storage/index.d.ts +56 -0
  479. package/dist/storage/index.js +15 -0
  480. package/dist/storage/index.js.map +1 -0
  481. package/dist/storage/manager.cjs +272 -0
  482. package/dist/storage/manager.cjs.map +1 -0
  483. package/dist/storage/manager.d.ts +241 -0
  484. package/dist/storage/manager.js +248 -0
  485. package/dist/storage/manager.js.map +1 -0
  486. package/dist/storage/providers/callback-storage.cjs +248 -0
  487. package/dist/storage/providers/callback-storage.cjs.map +1 -0
  488. package/dist/storage/providers/callback-storage.d.ts +183 -0
  489. package/dist/storage/providers/callback-storage.js +226 -0
  490. package/dist/storage/providers/callback-storage.js.map +1 -0
  491. package/dist/storage/providers/google-drive.cjs +516 -0
  492. package/dist/storage/providers/google-drive.cjs.map +1 -0
  493. package/dist/storage/providers/google-drive.d.ts +152 -0
  494. package/dist/storage/providers/google-drive.js +494 -0
  495. package/dist/storage/providers/google-drive.js.map +1 -0
  496. package/dist/storage/providers/google-drive.test.d.ts +1 -0
  497. package/dist/storage/providers/ipfs.cjs +283 -0
  498. package/dist/storage/providers/ipfs.cjs.map +1 -0
  499. package/dist/storage/providers/ipfs.d.ts +160 -0
  500. package/dist/storage/providers/ipfs.js +261 -0
  501. package/dist/storage/providers/ipfs.js.map +1 -0
  502. package/dist/storage/providers/pinata.cjs +339 -0
  503. package/dist/storage/providers/pinata.cjs.map +1 -0
  504. package/dist/storage/providers/pinata.d.ts +168 -0
  505. package/dist/storage/providers/pinata.js +317 -0
  506. package/dist/storage/providers/pinata.js.map +1 -0
  507. package/dist/storage/tests/callbackStorage.test.d.ts +1 -0
  508. package/dist/storage/tests/googleDriveStorage.test.d.ts +1 -0
  509. package/dist/storage/tests/ipfsStorage.test.d.ts +1 -0
  510. package/dist/storage/tests/pinataStorage.test.d.ts +1 -0
  511. package/dist/storage/tests/storageManager.test.d.ts +1 -0
  512. package/dist/tests/abi.test.d.ts +1 -0
  513. package/dist/tests/chains-definitions.test.d.ts +1 -0
  514. package/dist/tests/core-encryption.test.d.ts +1 -0
  515. package/dist/tests/core-extended.test.d.ts +1 -0
  516. package/dist/tests/core-generics-coverage.test.d.ts +1 -0
  517. package/dist/tests/coverage-boost.test.d.ts +1 -0
  518. package/dist/tests/crypto-cross-platform-compatibility.test.d.ts +1 -0
  519. package/dist/tests/data-addfile-permissions-schema.test.d.ts +1 -0
  520. package/dist/tests/data-additional-methods.test.d.ts +1 -0
  521. package/dist/tests/data-controller-edge-cases.test.d.ts +1 -0
  522. package/dist/tests/data-ipfs-gateways.test.d.ts +1 -0
  523. package/dist/tests/data-relayer.test.d.ts +1 -0
  524. package/dist/tests/data-schema-validation.test.d.ts +1 -0
  525. package/dist/tests/data-simple-methods.test.d.ts +1 -0
  526. package/dist/tests/data.test.d.ts +1 -0
  527. package/dist/tests/demo-integration.test.d.ts +1 -0
  528. package/dist/tests/demo-trusted-server-integration.test.d.ts +1 -0
  529. package/dist/tests/download-relayer.test.d.ts +1 -0
  530. package/dist/tests/dual-mode-permissions.test.d.ts +1 -0
  531. package/dist/tests/dual-mode-trusted-servers.test.d.ts +1 -0
  532. package/dist/tests/encryption-correct-implementation.test.d.ts +1 -0
  533. package/dist/tests/encryption-coverage.test.d.ts +1 -0
  534. package/dist/tests/encryption-edge-cases.test.d.ts +1 -0
  535. package/dist/tests/encryption-utils-updated.test.d.ts +1 -0
  536. package/dist/tests/errors-coverage.test.d.ts +1 -0
  537. package/dist/tests/errors.test.d.ts +1 -0
  538. package/dist/tests/factories/mockFactory.d.ts +316 -0
  539. package/dist/tests/fakes/FakeStorageManager.d.ts +200 -0
  540. package/dist/tests/fakes/FakeStorageManager.test.d.ts +1 -0
  541. package/dist/tests/fakes/FakeWaitForTransactionEvents.d.ts +170 -0
  542. package/dist/tests/fakes/FakeWaitForTransactionEvents.test.d.ts +1 -0
  543. package/dist/tests/fakes/fake-pgp-port.d.ts +13 -0
  544. package/dist/tests/grantValidation-edge-cases.test.d.ts +1 -0
  545. package/dist/tests/grantValidation-unreachable-branch.test.d.ts +1 -0
  546. package/dist/tests/helper-methods.test.d.ts +1 -0
  547. package/dist/tests/helpers/platformTestHelpers.d.ts +106 -0
  548. package/dist/tests/helpers/typedMocks.d.ts +64 -0
  549. package/dist/tests/index-browser.test.d.ts +1 -0
  550. package/dist/tests/index-node.test.d.ts +1 -0
  551. package/dist/tests/index.test.d.ts +1 -0
  552. package/dist/tests/mocks/platformAdapter.d.ts +12 -0
  553. package/dist/tests/new-permissions-methods.test.d.ts +1 -0
  554. package/dist/tests/no-buffer-browser.test.d.ts +1 -0
  555. package/dist/tests/permissions-grantee.test.d.ts +1 -0
  556. package/dist/tests/permissions-revoke-relayer.test.d.ts +1 -0
  557. package/dist/tests/permissions-schema-validation.test.d.ts +1 -0
  558. package/dist/tests/permissions-server-files.test.d.ts +1 -0
  559. package/dist/tests/permissions-transaction-options.test.d.ts +1 -0
  560. package/dist/tests/permissions-trust-servers.test.d.ts +1 -0
  561. package/dist/tests/permissions.test.d.ts +1 -0
  562. package/dist/tests/personal.test.d.ts +1 -0
  563. package/dist/tests/platform-browser.test.d.ts +1 -0
  564. package/dist/tests/platform-crypto-expanded.test.d.ts +1 -0
  565. package/dist/tests/platform-crypto.test.d.ts +1 -0
  566. package/dist/tests/platform-index.test.d.ts +1 -0
  567. package/dist/tests/platform-node.test.d.ts +1 -0
  568. package/dist/tests/platform-shared-utils.test.d.ts +1 -0
  569. package/dist/tests/platform-updated.test.d.ts +1 -0
  570. package/dist/tests/protocol-additional-methods.test.d.ts +1 -0
  571. package/dist/tests/protocol.test.d.ts +1 -0
  572. package/dist/tests/read-only-mode.test.d.ts +1 -0
  573. package/dist/tests/relayer-integration.test.d.ts +1 -0
  574. package/dist/tests/relayer-unified.test.d.ts +1 -0
  575. package/dist/tests/schemas.test.d.ts +1 -0
  576. package/dist/tests/server-relayer-handler.test.d.ts +1 -0
  577. package/dist/tests/setup.d.ts +7 -0
  578. package/dist/tests/signatureFormatter.test.d.ts +1 -0
  579. package/dist/tests/trusted-server-queries.test.d.ts +1 -0
  580. package/dist/tests/typedDataConverter.test.d.ts +1 -0
  581. package/dist/tests/types-contracts.test.d.ts +1 -0
  582. package/dist/tests/types-data.test.d.ts +1 -0
  583. package/dist/tests/types-external-apis.test.d.ts +1 -0
  584. package/dist/tests/types-generics.test.d.ts +1 -0
  585. package/dist/tests/types-permissions.test.d.ts +1 -0
  586. package/dist/tests/types-upload-params.test.d.ts +1 -0
  587. package/dist/tests/types.test.d.ts +1 -0
  588. package/dist/tests/utils-formatters.test.d.ts +1 -0
  589. package/dist/tests/utils-grantFiles-edge-cases.test.d.ts +1 -0
  590. package/dist/tests/utils-grantFiles-validation.test.d.ts +1 -0
  591. package/dist/tests/utils-grantFiles.test.d.ts +1 -0
  592. package/dist/tests/utils-grantValidation-consolidated.test.d.ts +1 -0
  593. package/dist/tests/utils-grants.test.d.ts +1 -0
  594. package/dist/tests/utils-ipfs-additional.test.d.ts +1 -0
  595. package/dist/tests/utils-ipfs.test.d.ts +4 -0
  596. package/dist/tests/utils-schemaValidation.test.d.ts +1 -0
  597. package/dist/tests/vana.test.d.ts +1 -0
  598. package/dist/tests/wallet-crypto-compatibility.test.d.ts +1 -0
  599. package/dist/types/blockchain.cjs +17 -0
  600. package/dist/types/blockchain.cjs.map +1 -0
  601. package/dist/types/blockchain.d.ts +85 -0
  602. package/dist/types/blockchain.js +1 -0
  603. package/dist/types/blockchain.js.map +1 -0
  604. package/dist/types/chains-additional.test.d.ts +1 -0
  605. package/dist/types/chains.cjs +36 -0
  606. package/dist/types/chains.cjs.map +1 -0
  607. package/dist/types/chains.d.ts +98 -0
  608. package/dist/types/chains.js +11 -0
  609. package/dist/types/chains.js.map +1 -0
  610. package/dist/types/config.cjs +51 -0
  611. package/dist/types/config.cjs.map +1 -0
  612. package/dist/types/config.d.ts +720 -0
  613. package/dist/types/config.js +23 -0
  614. package/dist/types/config.js.map +1 -0
  615. package/dist/types/contracts.cjs +17 -0
  616. package/dist/types/contracts.cjs.map +1 -0
  617. package/dist/types/contracts.d.ts +129 -0
  618. package/dist/types/contracts.js +1 -0
  619. package/dist/types/contracts.js.map +1 -0
  620. package/dist/types/controller-context.cjs +17 -0
  621. package/dist/types/controller-context.cjs.map +1 -0
  622. package/dist/types/controller-context.d.ts +67 -0
  623. package/dist/types/controller-context.js +1 -0
  624. package/dist/types/controller-context.js.map +1 -0
  625. package/dist/types/data.cjs +17 -0
  626. package/dist/types/data.cjs.map +1 -0
  627. package/dist/types/data.d.ts +760 -0
  628. package/dist/types/data.js +1 -0
  629. package/dist/types/data.js.map +1 -0
  630. package/dist/types/eccrypto-js.d.cjs +2 -0
  631. package/dist/types/eccrypto-js.d.cjs.map +1 -0
  632. package/dist/types/eccrypto-js.d.js +1 -0
  633. package/dist/types/eccrypto-js.d.js.map +1 -0
  634. package/dist/types/external-apis.cjs +61 -0
  635. package/dist/types/external-apis.cjs.map +1 -0
  636. package/dist/types/external-apis.d.ts +184 -0
  637. package/dist/types/external-apis.js +34 -0
  638. package/dist/types/external-apis.js.map +1 -0
  639. package/dist/types/generics.cjs +17 -0
  640. package/dist/types/generics.cjs.map +1 -0
  641. package/dist/types/generics.d.ts +518 -0
  642. package/dist/types/generics.js +1 -0
  643. package/dist/types/generics.js.map +1 -0
  644. package/dist/types/index.cjs +65 -0
  645. package/dist/types/index.cjs.map +1 -0
  646. package/dist/types/index.d.ts +46 -0
  647. package/dist/types/index.js +42 -0
  648. package/dist/types/index.js.map +1 -0
  649. package/dist/types/operations.cjs +65 -0
  650. package/dist/types/operations.cjs.map +1 -0
  651. package/dist/types/operations.d.ts +275 -0
  652. package/dist/types/operations.js +37 -0
  653. package/dist/types/operations.js.map +1 -0
  654. package/dist/types/permissions.cjs +17 -0
  655. package/dist/types/permissions.cjs.map +1 -0
  656. package/dist/types/permissions.d.ts +949 -0
  657. package/dist/types/permissions.js +1 -0
  658. package/dist/types/permissions.js.map +1 -0
  659. package/dist/types/personal.cjs +17 -0
  660. package/dist/types/personal.cjs.map +1 -0
  661. package/dist/types/personal.d.ts +155 -0
  662. package/dist/types/personal.js +1 -0
  663. package/dist/types/personal.js.map +1 -0
  664. package/dist/types/relayer.cjs +17 -0
  665. package/dist/types/relayer.cjs.map +1 -0
  666. package/dist/types/relayer.d.ts +519 -0
  667. package/dist/types/relayer.js +1 -0
  668. package/dist/types/relayer.js.map +1 -0
  669. package/dist/types/storage.cjs +39 -0
  670. package/dist/types/storage.cjs.map +1 -0
  671. package/dist/types/storage.d.ts +117 -0
  672. package/dist/types/storage.js +15 -0
  673. package/dist/types/storage.js.map +1 -0
  674. package/dist/types/transactionResults.cjs +17 -0
  675. package/dist/types/transactionResults.cjs.map +1 -0
  676. package/dist/types/transactionResults.d.ts +193 -0
  677. package/dist/types/transactionResults.js +1 -0
  678. package/dist/types/transactionResults.js.map +1 -0
  679. package/dist/types/utils.cjs +17 -0
  680. package/dist/types/utils.cjs.map +1 -0
  681. package/dist/types/utils.d.ts +820 -0
  682. package/dist/types/utils.js +1 -0
  683. package/dist/types/utils.js.map +1 -0
  684. package/dist/types.cjs +23 -0
  685. package/dist/types.cjs.map +1 -0
  686. package/dist/types.d.ts +30 -0
  687. package/dist/types.js +2 -0
  688. package/dist/types.js.map +1 -0
  689. package/dist/utils/__tests__/parseTransaction.test.d.ts +1 -0
  690. package/dist/utils/__tests__/pojo-serialization.test.d.ts +1 -0
  691. package/dist/utils/__tests__/signatureCache.test.d.ts +1 -0
  692. package/dist/utils/__tests__/transaction-edge-cases.test.d.ts +1 -0
  693. package/dist/utils/__tests__/transactionHelpers.test.d.ts +1 -0
  694. package/dist/utils/__tests__/urlResolver.test.d.ts +4 -0
  695. package/dist/utils/blockchain/registry.cjs +81 -0
  696. package/dist/utils/blockchain/registry.cjs.map +1 -0
  697. package/dist/utils/blockchain/registry.d.ts +32 -0
  698. package/dist/utils/blockchain/registry.js +56 -0
  699. package/dist/utils/blockchain/registry.js.map +1 -0
  700. package/dist/utils/blockchain/registry.test.d.ts +1 -0
  701. package/dist/utils/crypto-utils.cjs +108 -0
  702. package/dist/utils/crypto-utils.cjs.map +1 -0
  703. package/dist/utils/crypto-utils.d.ts +100 -0
  704. package/dist/utils/crypto-utils.js +76 -0
  705. package/dist/utils/crypto-utils.js.map +1 -0
  706. package/dist/utils/crypto-utils.test.d.ts +1 -0
  707. package/dist/utils/download.cjs +69 -0
  708. package/dist/utils/download.cjs.map +1 -0
  709. package/dist/utils/download.d.ts +40 -0
  710. package/dist/utils/download.js +45 -0
  711. package/dist/utils/download.js.map +1 -0
  712. package/dist/utils/encoding.cjs +66 -0
  713. package/dist/utils/encoding.cjs.map +1 -0
  714. package/dist/utils/encoding.d.ts +52 -0
  715. package/dist/utils/encoding.js +39 -0
  716. package/dist/utils/encoding.js.map +1 -0
  717. package/dist/utils/encoding.test.d.ts +1 -0
  718. package/dist/utils/encryption.cjs +176 -0
  719. package/dist/utils/encryption.cjs.map +1 -0
  720. package/dist/utils/encryption.d.ts +271 -0
  721. package/dist/utils/encryption.js +142 -0
  722. package/dist/utils/encryption.js.map +1 -0
  723. package/dist/utils/formatters.cjs +55 -0
  724. package/dist/utils/formatters.cjs.map +1 -0
  725. package/dist/utils/formatters.d.ts +118 -0
  726. package/dist/utils/formatters.js +28 -0
  727. package/dist/utils/formatters.js.map +1 -0
  728. package/dist/utils/grantFiles.cjs +178 -0
  729. package/dist/utils/grantFiles.cjs.map +1 -0
  730. package/dist/utils/grantFiles.d.ts +172 -0
  731. package/dist/utils/grantFiles.js +140 -0
  732. package/dist/utils/grantFiles.js.map +1 -0
  733. package/dist/utils/grantValidation.cjs +243 -0
  734. package/dist/utils/grantValidation.cjs.map +1 -0
  735. package/dist/utils/grantValidation.d.ts +226 -0
  736. package/dist/utils/grantValidation.js +201 -0
  737. package/dist/utils/grantValidation.js.map +1 -0
  738. package/dist/utils/grants.cjs +108 -0
  739. package/dist/utils/grants.cjs.map +1 -0
  740. package/dist/utils/grants.d.ts +148 -0
  741. package/dist/utils/grants.js +82 -0
  742. package/dist/utils/grants.js.map +1 -0
  743. package/dist/utils/ipfs.cjs +128 -0
  744. package/dist/utils/ipfs.cjs.map +1 -0
  745. package/dist/utils/ipfs.d.ts +88 -0
  746. package/dist/utils/ipfs.js +97 -0
  747. package/dist/utils/ipfs.js.map +1 -0
  748. package/dist/utils/lazy-import.cjs +38 -0
  749. package/dist/utils/lazy-import.cjs.map +1 -0
  750. package/dist/utils/lazy-import.d.ts +43 -0
  751. package/dist/utils/lazy-import.js +14 -0
  752. package/dist/utils/lazy-import.js.map +1 -0
  753. package/dist/utils/multicall.cjs +233 -0
  754. package/dist/utils/multicall.cjs.map +1 -0
  755. package/dist/utils/multicall.d.ts +126 -0
  756. package/dist/utils/multicall.js +208 -0
  757. package/dist/utils/multicall.js.map +1 -0
  758. package/dist/utils/parseTransactionPojo.cjs +87 -0
  759. package/dist/utils/parseTransactionPojo.cjs.map +1 -0
  760. package/dist/utils/parseTransactionPojo.d.ts +31 -0
  761. package/dist/utils/parseTransactionPojo.js +63 -0
  762. package/dist/utils/parseTransactionPojo.js.map +1 -0
  763. package/dist/utils/schemaValidation.cjs +258 -0
  764. package/dist/utils/schemaValidation.cjs.map +1 -0
  765. package/dist/utils/schemaValidation.d.ts +168 -0
  766. package/dist/utils/schemaValidation.js +219 -0
  767. package/dist/utils/schemaValidation.js.map +1 -0
  768. package/dist/utils/signatureCache.cjs +192 -0
  769. package/dist/utils/signatureCache.cjs.map +1 -0
  770. package/dist/utils/signatureCache.d.ts +172 -0
  771. package/dist/utils/signatureCache.js +167 -0
  772. package/dist/utils/signatureCache.js.map +1 -0
  773. package/dist/utils/signatureFormatter.cjs +42 -0
  774. package/dist/utils/signatureFormatter.cjs.map +1 -0
  775. package/dist/utils/signatureFormatter.d.ts +36 -0
  776. package/dist/utils/signatureFormatter.js +18 -0
  777. package/dist/utils/signatureFormatter.js.map +1 -0
  778. package/dist/utils/tests/multicall.test.d.ts +1 -0
  779. package/dist/utils/transactionHelpers.cjs +54 -0
  780. package/dist/utils/transactionHelpers.cjs.map +1 -0
  781. package/dist/utils/transactionHelpers.d.ts +80 -0
  782. package/dist/utils/transactionHelpers.js +29 -0
  783. package/dist/utils/transactionHelpers.js.map +1 -0
  784. package/dist/utils/typeGuards.cjs +109 -0
  785. package/dist/utils/typeGuards.cjs.map +1 -0
  786. package/dist/utils/typeGuards.d.ts +138 -0
  787. package/dist/utils/typeGuards.js +74 -0
  788. package/dist/utils/typeGuards.js.map +1 -0
  789. package/dist/utils/typedDataConverter.cjs +43 -0
  790. package/dist/utils/typedDataConverter.cjs.map +1 -0
  791. package/dist/utils/typedDataConverter.d.ts +46 -0
  792. package/dist/utils/typedDataConverter.js +19 -0
  793. package/dist/utils/typedDataConverter.js.map +1 -0
  794. package/dist/utils/urlResolver.cjs +62 -0
  795. package/dist/utils/urlResolver.cjs.map +1 -0
  796. package/dist/utils/urlResolver.d.ts +56 -0
  797. package/dist/utils/urlResolver.js +37 -0
  798. package/dist/utils/urlResolver.js.map +1 -0
  799. package/dist/utils/wallet.cjs +63 -0
  800. package/dist/utils/wallet.cjs.map +1 -0
  801. package/dist/utils/wallet.d.ts +94 -0
  802. package/dist/utils/wallet.js +37 -0
  803. package/dist/utils/wallet.js.map +1 -0
  804. package/dist/utils/withEvents.cjs +44 -0
  805. package/dist/utils/withEvents.cjs.map +1 -0
  806. package/dist/utils/withEvents.d.ts +56 -0
  807. package/dist/utils/withEvents.js +18 -0
  808. package/dist/utils/withEvents.js.map +1 -0
  809. package/package.json +76 -37
  810. package/dist/chains.browser.cjs.map +0 -1
  811. package/dist/chains.d.cts +0 -2
  812. package/dist/chains.node.d.cts +0 -2
  813. package/dist/index.d.cts +0 -2
  814. package/dist/platform.d.cts +0 -1
  815. package/dist/platform.node.d.cts +0 -264
@@ -0,0 +1,4030 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var permissions_exports = {};
30
+ __export(permissions_exports, {
31
+ PermissionsController: () => PermissionsController
32
+ });
33
+ module.exports = __toCommonJS(permissions_exports);
34
+ var import_viem = require("viem");
35
+ var import_multicall = require("../utils/multicall");
36
+ var import_errors = require("../errors");
37
+ var import_addresses = require("../config/addresses");
38
+ var import_abi = require("../generated/abi");
39
+ var import_grantFiles = require("../utils/grantFiles");
40
+ var import_grantValidation = require("../utils/grantValidation");
41
+ var import_signatureCache = require("../utils/signatureCache");
42
+ var import_signatureFormatter = require("../utils/signatureFormatter");
43
+ var import_typedDataConverter = require("../utils/typedDataConverter");
44
+ var import_base = require("./base");
45
+ class PermissionsController extends import_base.BaseController {
46
+ constructor(context) {
47
+ super(context);
48
+ }
49
+ /**
50
+ * Grants permission for an application to access user data with gasless transactions.
51
+ *
52
+ * This method provides a complete end-to-end permission grant flow that returns
53
+ * the permission ID and other relevant data immediately after successful submission.
54
+ * For advanced users who need more control over the transaction lifecycle, use
55
+ * `submitPermissionGrant()` instead.
56
+ *
57
+ * @param params - The permission grant configuration object
58
+ * @returns Promise resolving to permission data from the PermissionAdded event
59
+ * @throws {RelayerError} When gasless transaction submission fails
60
+ * @throws {SignatureError} When user rejects the signature request
61
+ * @throws {SerializationError} When grant data cannot be serialized
62
+ * @throws {BlockchainError} When permission grant fails or event parsing fails
63
+ * @throws {NetworkError} When transaction confirmation times out
64
+ * @example
65
+ * ```typescript
66
+ * const result = await vana.permissions.grant({
67
+ * grantee: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
68
+ * operation: "llm_inference",
69
+ * parameters: {
70
+ * model: "gpt-4",
71
+ * maxTokens: 1000,
72
+ * temperature: 0.7,
73
+ * },
74
+ * });
75
+ *
76
+ * console.log(`Permission ${result.permissionId} granted to ${result.user}`);
77
+ * console.log(`Transaction: ${result.transactionHash}`);
78
+ *
79
+ * // Can immediately use the permission ID for other operations
80
+ * await vana.permissions.revoke({ permissionId: result.permissionId });
81
+ * ```
82
+ */
83
+ async grant(params, options) {
84
+ this.assertWallet();
85
+ const { typedData, signature } = await this.createAndSign(params);
86
+ const result = await this.submitSignedGrantWithEvents(
87
+ typedData,
88
+ signature,
89
+ options
90
+ );
91
+ return result;
92
+ }
93
+ /**
94
+ * Submits a permission grant transaction and returns a handle for flexible result access.
95
+ *
96
+ * @remarks
97
+ * This lower-level method provides maximum control over transaction timing.
98
+ * Returns a TransactionResult that can be serialized and passed across API boundaries.
99
+ * Use this when handling multiple transactions or when you need granular control.
100
+ *
101
+ * @param params - The permission grant configuration object
102
+ * @returns Promise resolving to TransactionResult with hash and event parsing capabilities
103
+ * @throws {RelayerError} When gasless transaction submission fails
104
+ * @throws {SignatureError} When user rejects the signature request
105
+ * @throws {SerializationError} When grant data cannot be serialized
106
+ * @throws {BlockchainError} When permission grant preparation fails
107
+ * @example
108
+ * ```typescript
109
+ * // Submit transaction and get immediate hash access
110
+ * const tx = await vana.permissions.submitPermissionGrant(params);
111
+ * console.log(`Transaction submitted: ${tx.hash}`);
112
+ *
113
+ * // To wait for events, use SDK's waitForTransactionEvents
114
+ * const eventData = await vana.waitForTransactionEvents(tx.hash);
115
+ * console.log(`Permission ID: ${eventData.permissionId}`);
116
+ * ```
117
+ */
118
+ async submitPermissionGrant(params, options) {
119
+ this.assertWallet();
120
+ const { typedData, signature } = await this.createAndSign(params);
121
+ return await this.submitSignedGrant(typedData, signature, options);
122
+ }
123
+ /**
124
+ * Prepares a permission grant with preview before signing.
125
+ *
126
+ * @remarks
127
+ * This method implements a two-phase commit workflow that allows applications
128
+ * to show users a preview of what they're authorizing before requesting a signature.
129
+ * Unlike `createAndSign()`, this method does NOT upload to IPFS or prompt for signatures
130
+ * until the returned `confirm()` function is called.
131
+ * @param params - The permission grant parameters
132
+ * @returns A promise resolving to a preview object and confirm function
133
+ * @throws {SerializationError} When grant parameters are invalid or cannot be serialized
134
+ * @throws {BlockchainError} When grant validation fails or preparation encounters an error
135
+ * @example
136
+ * ```typescript
137
+ * const { preview, confirm } = await vana.permissions.prepareGrant({
138
+ * grantee: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
139
+ * operation: "llm_inference",
140
+ * files: [1, 2, 3],
141
+ * parameters: { model: "gpt-4", prompt: "Analyze my social media data" }
142
+ * });
143
+ *
144
+ * console.log(`Granting ${preview.operation} access to ${preview.files?.length} files`);
145
+ * const transactionHash = await confirm();
146
+ * ```
147
+ */
148
+ async prepareGrant(params, options) {
149
+ this.assertWallet();
150
+ try {
151
+ const grantFile = (0, import_grantFiles.createGrantFile)(params);
152
+ (0, import_grantValidation.validateGrant)(grantFile);
153
+ return {
154
+ preview: grantFile,
155
+ confirm: async () => {
156
+ return await this.confirmGrantInternalWithEvents(
157
+ params,
158
+ grantFile,
159
+ options
160
+ );
161
+ }
162
+ };
163
+ } catch (error) {
164
+ if (error instanceof Error) {
165
+ if (error instanceof import_errors.RelayerError || error instanceof import_errors.UserRejectedRequestError || error instanceof import_errors.SerializationError || error instanceof import_errors.SignatureError || error instanceof import_errors.NetworkError || error instanceof import_errors.NonceError) {
166
+ throw error;
167
+ }
168
+ throw new import_errors.BlockchainError(
169
+ `Permission grant preparation failed: ${error.message}`,
170
+ error
171
+ );
172
+ }
173
+ throw new import_errors.BlockchainError(
174
+ "Permission grant preparation failed with unknown error"
175
+ );
176
+ }
177
+ }
178
+ /**
179
+ * Completes the grant process after user confirmation.
180
+ *
181
+ * @remarks
182
+ * This internal method is called by the confirm() function returned from prepareGrant().
183
+ * It handles IPFS upload, signature creation, and transaction submission.
184
+ *
185
+ * @param params - The permission grant parameters containing user and operation details
186
+ * @param grantFile - The prepared grant file with permissions and metadata
187
+ * @returns Promise resolving to TransactionResult for flexible result access
188
+ * @throws {BlockchainError} When permission grant confirmation fails
189
+ * @throws {NetworkError} When IPFS upload fails
190
+ * @throws {SignatureError} When user rejects the signature
191
+ */
192
+ async confirmGrantInternal(params, grantFile, options) {
193
+ try {
194
+ let { grantUrl } = params;
195
+ console.debug("\u{1F50D} Debug - Grant URL from params:", grantUrl);
196
+ if (!grantUrl) {
197
+ const canStoreViaRelayer = this.context.relayer !== void 0;
198
+ if (!canStoreViaRelayer && !this.context.storageManager) {
199
+ if (this.context.validateStorageRequired) {
200
+ this.context.validateStorageRequired();
201
+ } else {
202
+ throw new Error(
203
+ "No storage available. Provide a grantUrl, configure relayer, or storageManager."
204
+ );
205
+ }
206
+ }
207
+ if (canStoreViaRelayer && this.context.relayer) {
208
+ const request = {
209
+ type: "direct",
210
+ operation: "storeGrantFile",
211
+ params: grantFile
212
+ };
213
+ const response = await this.context.relayer(request);
214
+ if (response.type === "error") {
215
+ throw new Error(response.error);
216
+ }
217
+ if (response.type === "direct" && typeof response.result === "object" && response.result !== null && "url" in response.result) {
218
+ grantUrl = response.result.url;
219
+ } else {
220
+ throw new Error("Invalid response from relayer for grant storage");
221
+ }
222
+ } else if (this.context.storageManager) {
223
+ const blob = new Blob([JSON.stringify(grantFile)], {
224
+ type: "application/json"
225
+ });
226
+ const result = await this.context.storageManager.upload(
227
+ blob,
228
+ `grant-${Date.now()}.json`
229
+ );
230
+ grantUrl = result.url;
231
+ }
232
+ if (!grantUrl) {
233
+ throw new Error("Failed to store grant file - no URL returned");
234
+ }
235
+ }
236
+ const nonce = await this.getPermissionsUserNonce();
237
+ console.debug(
238
+ "\u{1F50D} Debug - Final grant URL being passed to compose:",
239
+ grantUrl
240
+ );
241
+ const typedData = await this.composePermissionGrantMessage({
242
+ grantee: params.grantee,
243
+ operation: params.operation,
244
+ // Placeholder - real data is in IPFS
245
+ files: params.files,
246
+ // Placeholder - real data is in IPFS
247
+ grantUrl,
248
+ serializedParameters: (0, import_grantFiles.getGrantFileHash)(grantFile),
249
+ // Hash as placeholder
250
+ nonce
251
+ });
252
+ const signature = await this.signTypedData(typedData);
253
+ return await this.submitSignedGrant(typedData, signature, options);
254
+ } catch (error) {
255
+ if (error instanceof Error) {
256
+ if (error instanceof import_errors.RelayerError || error instanceof import_errors.UserRejectedRequestError || error instanceof import_errors.SerializationError || error instanceof import_errors.SignatureError || error instanceof import_errors.NetworkError || error instanceof import_errors.NonceError) {
257
+ throw error;
258
+ }
259
+ throw new import_errors.BlockchainError(
260
+ `Permission grant confirmation failed: ${error.message}`,
261
+ error
262
+ );
263
+ }
264
+ throw new import_errors.BlockchainError(
265
+ "Permission grant confirmation failed with unknown error"
266
+ );
267
+ }
268
+ }
269
+ /**
270
+ * Creates typed data and signature for a permission grant without submitting.
271
+ *
272
+ * @remarks
273
+ * This method handles the first phase of permission granting: creating the grant file,
274
+ * storing it on IPFS, and generating the user's EIP-712 signature. Use this when you
275
+ * want to handle submission separately or batch multiple operations. The method validates
276
+ * the grant file against the JSON schema before creating the signature.
277
+ *
278
+ * For interactive user flows, consider using `prepareGrant()` instead,
279
+ * which allows showing a preview before signing.
280
+ * @param params - The permission grant configuration object
281
+ * @returns A promise resolving to the typed data structure and signature for gasless submission
282
+ * @throws {SignatureError} When the user rejects the signature request
283
+ * @throws {SerializationError} When grant data cannot be properly formatted
284
+ * @throws {BlockchainError} When permission grant preparation fails
285
+ * @throws {NetworkError} When storage operations fail
286
+ * @example
287
+ * ```typescript
288
+ * const { typedData, signature } = await vana.permissions.createAndSign({
289
+ * grantee: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
290
+ * operation: "data_analysis",
291
+ * parameters: { analysisType: "sentiment" },
292
+ * });
293
+ *
294
+ * const transactionHash = await vana.permissions.submitSignedGrant(typedData, signature);
295
+ * ```
296
+ */
297
+ async createAndSign(params) {
298
+ this.assertWallet();
299
+ try {
300
+ const grantFile = (0, import_grantFiles.createGrantFile)(params);
301
+ (0, import_grantValidation.validateGrant)(grantFile);
302
+ let { grantUrl } = params;
303
+ console.debug("\u{1F50D} Debug - Grant URL from params:", grantUrl);
304
+ if (!grantUrl) {
305
+ const canStoreViaRelayer = this.context.relayer !== void 0;
306
+ if (!canStoreViaRelayer && !this.context.storageManager) {
307
+ if (this.context.validateStorageRequired) {
308
+ this.context.validateStorageRequired();
309
+ } else {
310
+ throw new Error(
311
+ "No storage available. Provide a grantUrl, configure relayer, or storageManager."
312
+ );
313
+ }
314
+ }
315
+ if (canStoreViaRelayer && this.context.relayer) {
316
+ const request = {
317
+ type: "direct",
318
+ operation: "storeGrantFile",
319
+ params: grantFile
320
+ };
321
+ const response = await this.context.relayer(request);
322
+ if (response.type === "error") {
323
+ throw new Error(response.error);
324
+ }
325
+ if (response.type === "direct" && typeof response.result === "object" && response.result !== null && "url" in response.result) {
326
+ grantUrl = response.result.url;
327
+ } else {
328
+ throw new Error("Invalid response from relayer for grant storage");
329
+ }
330
+ } else if (this.context.storageManager) {
331
+ const blob = new Blob([JSON.stringify(grantFile)], {
332
+ type: "application/json"
333
+ });
334
+ const result = await this.context.storageManager.upload(
335
+ blob,
336
+ `grant-${Date.now()}.json`
337
+ );
338
+ grantUrl = result.url;
339
+ }
340
+ if (!grantUrl) {
341
+ throw new Error("Failed to store grant file - no URL returned");
342
+ }
343
+ }
344
+ const nonce = await this.getPermissionsUserNonce();
345
+ console.debug(
346
+ "\u{1F50D} Debug - Final grant URL being passed to compose:",
347
+ grantUrl
348
+ );
349
+ const typedData = await this.composePermissionGrantMessage({
350
+ grantee: params.grantee,
351
+ operation: params.operation,
352
+ // Placeholder - real data is in IPFS
353
+ files: params.files,
354
+ // Placeholder - real data is in IPFS
355
+ grantUrl,
356
+ serializedParameters: (0, import_grantFiles.getGrantFileHash)(grantFile),
357
+ // Hash as placeholder
358
+ nonce
359
+ });
360
+ const signature = await this.signTypedData(typedData);
361
+ return { typedData, signature };
362
+ } catch (error) {
363
+ if (error instanceof Error) {
364
+ if (error instanceof import_errors.RelayerError || error instanceof import_errors.UserRejectedRequestError || error instanceof import_errors.SerializationError || error instanceof import_errors.SignatureError || error instanceof import_errors.NetworkError || error instanceof import_errors.NonceError) {
365
+ throw error;
366
+ }
367
+ throw new import_errors.BlockchainError(
368
+ `Permission grant preparation failed: ${error.message}`,
369
+ error
370
+ );
371
+ }
372
+ throw new import_errors.BlockchainError(
373
+ "Permission grant preparation failed with unknown error"
374
+ );
375
+ }
376
+ }
377
+ /**
378
+ * Submits an already-signed permission grant to the blockchain.
379
+ *
380
+ * @remarks
381
+ * This method supports both relayer-based gasless transactions and direct transactions.
382
+ * It automatically converts `bigint` values to JSON-safe strings when using relayer
383
+ * callbacks and handles transaction submission with proper error handling and retry logic.
384
+ * @param typedData - The EIP-712 typed data structure for the permission grant
385
+ * @param signature - The user's signature as a hex string
386
+ * @returns A Promise that resolves to the transaction hash
387
+ * @throws {RelayerError} When gasless transaction submission fails
388
+ * @throws {BlockchainError} When permission submission fails
389
+ * @throws {NetworkError} When network communication fails
390
+ * @example
391
+ * ```typescript
392
+ * const txHash = await vana.permissions.submitSignedGrant(
393
+ * typedData,
394
+ * "0x1234..."
395
+ * );
396
+ * ```
397
+ */
398
+ async submitSignedGrant(typedData, signature, options) {
399
+ try {
400
+ console.debug(
401
+ "\u{1F50D} Debug - submitSignedGrant called with typed data:",
402
+ JSON.stringify(
403
+ typedData,
404
+ (_key, value) => typeof value === "bigint" ? value.toString() : value,
405
+ 2
406
+ )
407
+ );
408
+ if (this.context.relayer) {
409
+ const response = await this.context.relayer({
410
+ type: "signed",
411
+ operation: "submitAddPermission",
412
+ typedData,
413
+ signature,
414
+ expectedUserAddress: this.context.userAddress
415
+ });
416
+ if (response.type === "error") {
417
+ throw new Error(`Relayer error: ${response.error}`);
418
+ }
419
+ let finalHash;
420
+ if (response.type === "submitted") {
421
+ finalHash = response.hash;
422
+ } else if (response.type === "pending") {
423
+ const pollResult = await this.pollRelayerForConfirmation(
424
+ response.operationId
425
+ );
426
+ finalHash = pollResult.hash;
427
+ } else if (response.type === "confirmed") {
428
+ finalHash = response.hash;
429
+ } else if (response.type === "signed") {
430
+ finalHash = response.hash;
431
+ } else {
432
+ throw new Error(
433
+ "Invalid response from relayer: unexpected response type"
434
+ );
435
+ }
436
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
437
+ const { tx } = await import("../utils/transactionHelpers");
438
+ return tx({
439
+ hash: finalHash,
440
+ from: typeof account === "string" ? account : account.address,
441
+ contract: "DataPortabilityPermissions",
442
+ fn: "addPermission"
443
+ });
444
+ } else {
445
+ return await this.submitDirectTransaction(
446
+ typedData,
447
+ signature,
448
+ options
449
+ );
450
+ }
451
+ } catch (error) {
452
+ if (error instanceof import_errors.RelayerError || error instanceof import_errors.NetworkError || error instanceof import_errors.UserRejectedRequestError || error instanceof import_errors.SignatureError || error instanceof import_errors.NonceError) {
453
+ throw error;
454
+ }
455
+ throw new import_errors.BlockchainError(
456
+ `Permission submission failed: ${error instanceof Error ? error.message : "Unknown error"}`,
457
+ error
458
+ );
459
+ }
460
+ }
461
+ /**
462
+ * Submits an already-signed trust server transaction to the blockchain.
463
+ *
464
+ * @remarks
465
+ * This method extracts the trust server input from typed data and submits it directly.
466
+ * Used internally by trust server methods after signature collection.
467
+ *
468
+ * @param typedData - The EIP-712 typed data for TrustServer
469
+ * @param signature - The user's signature obtained via `signTypedData()`
470
+ * @returns Promise resolving to TransactionResult for transaction tracking
471
+ * @throws {BlockchainError} When contract submission fails
472
+ * @throws {NetworkError} When blockchain communication fails
473
+ * @example
474
+ * ```typescript
475
+ * const txHandle = await vana.permissions.submitSignedTrustServer(
476
+ * typedData,
477
+ * "0x1234..."
478
+ * );
479
+ * const result = await txHandle.waitForEvents();
480
+ * ```
481
+ */
482
+ async submitSignedTrustServer(typedData, signature, options) {
483
+ try {
484
+ const trustServerInput = {
485
+ nonce: BigInt(typedData.message.nonce),
486
+ serverId: typedData.message.serverId
487
+ };
488
+ const hash = await this.submitTrustServerTransaction(
489
+ trustServerInput,
490
+ signature,
491
+ options
492
+ );
493
+ const account = this.context.userAddress;
494
+ const { tx } = await import("../utils/transactionHelpers");
495
+ return tx({
496
+ hash,
497
+ from: account,
498
+ contract: "DataPortabilityServers",
499
+ fn: "trustServerWithSignature"
500
+ });
501
+ } catch (error) {
502
+ if (error instanceof import_errors.RelayerError || error instanceof import_errors.NetworkError || error instanceof import_errors.UserRejectedRequestError || error instanceof import_errors.SignatureError || error instanceof import_errors.NonceError) {
503
+ throw error;
504
+ }
505
+ if (error instanceof Error && error.message.includes("ServerUrlMismatch")) {
506
+ const match = error.message.match(
507
+ /ServerUrlMismatch\(string existingUrl, string providedUrl\)\s+\(([^,]+),\s*([^)]+)\)/
508
+ );
509
+ if (match) {
510
+ const existingUrl = match[1].trim();
511
+ const providedUrl = match[2].trim();
512
+ throw new import_errors.ServerUrlMismatchError(
513
+ existingUrl,
514
+ providedUrl,
515
+ typedData.message.serverId.toString()
516
+ );
517
+ }
518
+ }
519
+ throw new import_errors.BlockchainError(
520
+ `Trust server submission failed: ${error instanceof Error ? error.message : "Unknown error"}`,
521
+ error
522
+ );
523
+ }
524
+ }
525
+ /**
526
+ * Submits an already-signed add and trust server transaction to the blockchain.
527
+ *
528
+ * @remarks
529
+ * This method extracts the add and trust server input from typed data and submits it directly.
530
+ * Combines server registration and trust operations in a single transaction.
531
+ *
532
+ * @param typedData - The EIP-712 typed data for AddAndTrustServer
533
+ * @param signature - The user's signature obtained via `signTypedData()`
534
+ * @returns Promise resolving to TransactionResult for transaction tracking
535
+ * @throws {BlockchainError} When contract submission fails
536
+ * @throws {NetworkError} When blockchain communication fails
537
+ * @example
538
+ * ```typescript
539
+ * const txHandle = await vana.permissions.submitSignedAddAndTrustServer(
540
+ * typedData,
541
+ * "0x1234..."
542
+ * );
543
+ * const result = await txHandle.waitForEvents();
544
+ * ```
545
+ */
546
+ async submitSignedAddAndTrustServer(typedData, signature, _options) {
547
+ try {
548
+ const addAndTrustServerInput = {
549
+ nonce: BigInt(typedData.message.nonce),
550
+ serverAddress: typedData.message.serverAddress,
551
+ serverUrl: typedData.message.serverUrl,
552
+ publicKey: typedData.message.publicKey
553
+ };
554
+ const hash = await this.submitAddAndTrustServerTransaction(
555
+ addAndTrustServerInput,
556
+ signature
557
+ );
558
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
559
+ const { tx } = await import("../utils/transactionHelpers");
560
+ return tx({
561
+ hash,
562
+ from: typeof account === "string" ? account : account.address,
563
+ contract: "DataPortabilityServers",
564
+ fn: "addAndTrustServerWithSignature"
565
+ });
566
+ } catch (error) {
567
+ if (error instanceof import_errors.RelayerError || error instanceof import_errors.NetworkError || error instanceof import_errors.UserRejectedRequestError || error instanceof import_errors.SignatureError || error instanceof import_errors.NonceError) {
568
+ throw error;
569
+ }
570
+ throw new import_errors.BlockchainError(
571
+ `Add and trust server submission failed444444: ${error instanceof Error ? error.message : "Unknown error"}`,
572
+ error
573
+ );
574
+ }
575
+ }
576
+ /**
577
+ * Internal method to submit a signed grant and wait for events.
578
+ *
579
+ * @internal
580
+ * @param typedData - The EIP-712 typed data for the permission grant
581
+ * @param signature - The user's signature authorizing the transaction
582
+ * @returns Promise resolving to PermissionGrantResult with parsed events
583
+ */
584
+ async submitSignedGrantWithEvents(typedData, signature, options) {
585
+ const txResult = await this.submitSignedGrant(
586
+ typedData,
587
+ signature,
588
+ options
589
+ );
590
+ if (!this.context.waitForTransactionEvents) {
591
+ throw new import_errors.BlockchainError("waitForTransactionEvents not configured");
592
+ }
593
+ const result = await this.context.waitForTransactionEvents(txResult);
594
+ const event = result.expectedEvents.PermissionAdded;
595
+ if (!event) {
596
+ throw new import_errors.BlockchainError(
597
+ "PermissionAdded event not found in transaction"
598
+ );
599
+ }
600
+ const receipt = await this.context.publicClient.getTransactionReceipt({
601
+ hash: result.hash
602
+ });
603
+ return {
604
+ transactionHash: result.hash,
605
+ blockNumber: receipt.blockNumber,
606
+ gasUsed: receipt.gasUsed,
607
+ permissionId: event.permissionId,
608
+ user: event.user,
609
+ grant: event.grant,
610
+ fileIds: event.fileIds
611
+ };
612
+ }
613
+ /**
614
+ * Internal method for confirm grant with events.
615
+ *
616
+ * @internal
617
+ * @param params - The permission grant parameters
618
+ * @param grantFile - The pre-created grant file object
619
+ * @returns Promise resolving to PermissionGrantResult with parsed events
620
+ */
621
+ async confirmGrantInternalWithEvents(params, grantFile, options) {
622
+ const txResult = await this.confirmGrantInternal(
623
+ params,
624
+ grantFile,
625
+ options
626
+ );
627
+ if (!this.context.waitForTransactionEvents) {
628
+ throw new import_errors.BlockchainError("waitForTransactionEvents not configured");
629
+ }
630
+ const result = await this.context.waitForTransactionEvents(txResult);
631
+ const event = result.expectedEvents.PermissionAdded;
632
+ if (!event) {
633
+ throw new import_errors.BlockchainError(
634
+ "PermissionAdded event not found in transaction"
635
+ );
636
+ }
637
+ const receipt = await this.context.publicClient.getTransactionReceipt({
638
+ hash: result.hash
639
+ });
640
+ return {
641
+ transactionHash: result.hash,
642
+ blockNumber: receipt.blockNumber,
643
+ gasUsed: receipt.gasUsed,
644
+ permissionId: event.permissionId,
645
+ user: event.user,
646
+ grant: event.grant,
647
+ fileIds: event.fileIds
648
+ };
649
+ }
650
+ /**
651
+ * Polls the relayer for confirmation of a pending operation.
652
+ *
653
+ * @param operationId - The operation ID to poll
654
+ * @returns Promise resolving to the confirmed hash
655
+ * @throws {Error} When the operation fails or times out
656
+ * @internal
657
+ */
658
+ async pollRelayerForConfirmation(operationId, options = {}) {
659
+ const timeout = options.timeout ?? 3e4;
660
+ let interval = options.pollingInterval ?? 1e3;
661
+ const startTime = Date.now();
662
+ while (Date.now() - startTime < timeout) {
663
+ if (!this.context.relayer) {
664
+ throw new Error("Relayer not configured for polling");
665
+ }
666
+ const statusResponse = await this.context.relayer({
667
+ type: "status_check",
668
+ operationId
669
+ });
670
+ if (statusResponse.type === "confirmed") {
671
+ return { hash: statusResponse.hash };
672
+ }
673
+ if (statusResponse.type === "error") {
674
+ throw new Error(
675
+ `Operation ${operationId} failed: ${statusResponse.error}`
676
+ );
677
+ }
678
+ await new Promise((resolve) => setTimeout(resolve, interval));
679
+ interval = Math.min(interval * 1.5, 5e3);
680
+ }
681
+ throw new Error(`Operation ${operationId} timed out after ${timeout}ms`);
682
+ }
683
+ /**
684
+ * Submits an already-signed permission revoke transaction to the blockchain.
685
+ *
686
+ * @remarks
687
+ * This method handles the revocation of previously granted permissions.
688
+ * Used internally by revocation methods after signature collection.
689
+ *
690
+ * @param typedData - The EIP-712 typed data for PermissionRevoke
691
+ * @param signature - The user's signature obtained via `signTypedData()`
692
+ * @returns Promise resolving to TransactionResult for transaction tracking
693
+ * @throws {BlockchainError} When contract submission fails
694
+ * @throws {NetworkError} When blockchain communication fails
695
+ * @example
696
+ * ```typescript
697
+ * const txHandle = await vana.permissions.submitSignedRevoke(
698
+ * typedData,
699
+ * "0x1234..."
700
+ * );
701
+ * const result = await txHandle.waitForEvents();
702
+ * ```
703
+ */
704
+ async submitSignedRevoke(typedData, signature, _options) {
705
+ try {
706
+ let hash;
707
+ if (this.context.relayer) {
708
+ const response = await this.context.relayer({
709
+ type: "signed",
710
+ operation: "submitPermissionRevoke",
711
+ typedData,
712
+ signature,
713
+ expectedUserAddress: this.context.userAddress
714
+ });
715
+ if (response.type === "error") {
716
+ throw new Error(`Relayer error: ${response.error}`);
717
+ }
718
+ if (response.type === "submitted") {
719
+ hash = response.hash;
720
+ } else if (response.type === "pending") {
721
+ const pollResult = await this.pollRelayerForConfirmation(
722
+ response.operationId
723
+ );
724
+ hash = pollResult.hash;
725
+ } else if (response.type === "confirmed") {
726
+ hash = response.hash;
727
+ } else if (response.type === "signed") {
728
+ hash = response.hash;
729
+ } else {
730
+ throw new Error(
731
+ "Invalid response from relayer: unexpected response type"
732
+ );
733
+ }
734
+ } else {
735
+ hash = await this.submitDirectRevokeTransaction(
736
+ typedData,
737
+ signature
738
+ );
739
+ }
740
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
741
+ const { tx } = await import("../utils/transactionHelpers");
742
+ return tx({
743
+ hash,
744
+ from: typeof account === "string" ? account : account.address,
745
+ contract: "DataPortabilityPermissions",
746
+ fn: "revokePermissionWithSignature"
747
+ });
748
+ } catch (error) {
749
+ if (error instanceof import_errors.RelayerError || error instanceof import_errors.NetworkError || error instanceof import_errors.UserRejectedRequestError || error instanceof import_errors.SignatureError || error instanceof import_errors.NonceError) {
750
+ throw error;
751
+ }
752
+ throw new import_errors.BlockchainError(
753
+ `Permission revoke submission failed: ${error instanceof Error ? error.message : "Unknown error"}`,
754
+ error
755
+ );
756
+ }
757
+ }
758
+ /**
759
+ * Submits an already-signed untrust server transaction to the blockchain.
760
+ *
761
+ * @remarks
762
+ * This method handles the removal of trusted servers.
763
+ * Used internally by untrust server methods after signature collection.
764
+ *
765
+ * @param typedData - The EIP-712 typed data for UntrustServer
766
+ * @param signature - The user's signature obtained via `signTypedData()`
767
+ * @returns Promise resolving to TransactionResult for transaction tracking
768
+ * @throws {BlockchainError} When contract submission fails
769
+ * @throws {NetworkError} When blockchain communication fails
770
+ * @example
771
+ * ```typescript
772
+ * const txHandle = await vana.permissions.submitSignedUntrustServer(
773
+ * typedData,
774
+ * "0x1234..."
775
+ * );
776
+ * const result = await txHandle.waitForEvents();
777
+ * ```
778
+ */
779
+ async submitSignedUntrustServer(typedData, signature, _options) {
780
+ try {
781
+ let hash;
782
+ if (this.context.relayer) {
783
+ const response = await this.context.relayer({
784
+ type: "signed",
785
+ operation: "submitUntrustServer",
786
+ typedData,
787
+ signature,
788
+ expectedUserAddress: this.context.userAddress
789
+ });
790
+ if (response.type === "signed") {
791
+ hash = response.hash;
792
+ } else if (response.type === "error") {
793
+ throw new Error(`Relayer error: ${response.error}`);
794
+ } else {
795
+ throw new Error(
796
+ "Invalid response from relayer: expected signed transaction"
797
+ );
798
+ }
799
+ } else {
800
+ hash = await this.submitSignedUntrustTransaction(
801
+ typedData,
802
+ signature
803
+ );
804
+ }
805
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
806
+ const { tx } = await import("../utils/transactionHelpers");
807
+ return tx({
808
+ hash,
809
+ from: typeof account === "string" ? account : account.address,
810
+ contract: "DataPortabilityServers",
811
+ fn: "untrustServerWithSignature"
812
+ });
813
+ } catch (error) {
814
+ if (error instanceof import_errors.RelayerError || error instanceof import_errors.NetworkError || error instanceof import_errors.UserRejectedRequestError || error instanceof import_errors.SignatureError || error instanceof import_errors.NonceError) {
815
+ throw error;
816
+ }
817
+ throw new import_errors.BlockchainError(
818
+ `Untrust server submission failed: ${error instanceof Error ? error.message : "Unknown error"}`,
819
+ error
820
+ );
821
+ }
822
+ }
823
+ /**
824
+ * Submits a signed transaction directly to the blockchain.
825
+ *
826
+ * @remarks
827
+ * Internal method used when relayer callbacks are not available. Formats the signature
828
+ * and submits the permission grant directly to the smart contract.
829
+ *
830
+ * @param typedData - The typed data structure for the permission grant
831
+ * @param signature - The cryptographic signature authorizing the transaction
832
+ * @returns Promise resolving to the transaction hash
833
+ * @throws {BlockchainError} When contract submission fails
834
+ */
835
+ async submitDirectTransaction(typedData, signature, options) {
836
+ this.assertWallet();
837
+ const chainId = await this.context.publicClient.getChainId();
838
+ const DataPortabilityPermissionsAddress = (0, import_addresses.getContractAddress)(
839
+ chainId,
840
+ "DataPortabilityPermissions"
841
+ );
842
+ const DataPortabilityPermissionsAbi = (0, import_abi.getAbi)("DataPortabilityPermissions");
843
+ const permissionInput = {
844
+ nonce: typedData.message.nonce,
845
+ granteeId: typedData.message.granteeId,
846
+ grant: typedData.message.grant,
847
+ fileIds: typedData.message.fileIds
848
+ };
849
+ console.debug("\u{1F50D} Debug - Permission input being sent to contract:", {
850
+ nonce: permissionInput.nonce.toString(),
851
+ grant: permissionInput.grant,
852
+ fileIds: permissionInput.fileIds.map((id) => id.toString())
853
+ });
854
+ console.debug("\u{1F50D} Debug - Grant field value:", typedData.message.grant);
855
+ console.debug(
856
+ "\u{1F50D} Debug - Grant field length:",
857
+ typedData.message.grant?.length ?? 0
858
+ );
859
+ const formattedSignature = (0, import_signatureFormatter.formatSignatureForContract)(signature);
860
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
861
+ const txHash = await this.context.walletClient.writeContract({
862
+ address: DataPortabilityPermissionsAddress,
863
+ abi: DataPortabilityPermissionsAbi,
864
+ functionName: "addPermission",
865
+ args: [permissionInput, formattedSignature],
866
+ account,
867
+ chain: this.context.walletClient?.chain ?? null,
868
+ ...this.spreadTransactionOptions(options)
869
+ });
870
+ const { tx } = await import("../utils/transactionHelpers");
871
+ return tx({
872
+ hash: txHash,
873
+ from: typeof account === "string" ? account : account.address,
874
+ contract: "DataPortabilityPermissions",
875
+ fn: "addPermission"
876
+ });
877
+ }
878
+ /**
879
+ * Revokes a previously granted permission.
880
+ *
881
+ * This method provides complete revocation with automatic event parsing to confirm
882
+ * the permission was successfully revoked. For advanced users who need more control,
883
+ * use `submitPermissionRevoke()` instead.
884
+ *
885
+ * @param params - Parameters for revoking the permission
886
+ * @param params.permissionId - Permission identifier (accepts bigint, number, or string).
887
+ * Obtain from permission grants via `getUserPermissionGrantsOnChain()`.
888
+ * @returns Promise resolving to revocation data from PermissionRevoked event
889
+ * @throws {BlockchainError} When revocation fails or event parsing fails
890
+ * @throws {UserRejectedRequestError} When user rejects the transaction
891
+ * @throws {NetworkError} When transaction confirmation times out
892
+ * @example
893
+ * ```typescript
894
+ * // Revoke a permission and get confirmation
895
+ * const result = await vana.permissions.revoke({
896
+ * permissionId: 123n
897
+ * });
898
+ * console.log(`Permission ${result.permissionId} revoked in transaction ${result.transactionHash}`);
899
+ * console.log(`Revoked in block ${result.blockNumber}`);
900
+ * ```
901
+ */
902
+ async revoke(params) {
903
+ this.assertWallet();
904
+ const txResult = await this.submitPermissionRevoke(params);
905
+ if (!this.context.waitForTransactionEvents) {
906
+ throw new import_errors.BlockchainError("waitForTransactionEvents not configured");
907
+ }
908
+ const result = await this.context.waitForTransactionEvents(txResult);
909
+ const event = result.expectedEvents.PermissionRevoked;
910
+ if (!event) {
911
+ throw new import_errors.BlockchainError(
912
+ "PermissionRevoked event not found in transaction"
913
+ );
914
+ }
915
+ const receipt = await this.context.publicClient.getTransactionReceipt({
916
+ hash: result.hash
917
+ });
918
+ return {
919
+ transactionHash: result.hash,
920
+ blockNumber: receipt.blockNumber,
921
+ gasUsed: receipt.gasUsed,
922
+ permissionId: event.permissionId
923
+ };
924
+ }
925
+ /**
926
+ * Submits a permission revocation transaction and returns the transaction hash immediately.
927
+ *
928
+ * This is the lower-level method that provides maximum control over transaction timing.
929
+ * Use this when you want to handle transaction confirmation and event parsing separately.
930
+ *
931
+ * @param params - Parameters for revoking the permission
932
+ * @param options - Optional transaction options for gas parameters and timeout
933
+ * @returns Promise resolving to the transaction hash when successfully submitted
934
+ * @throws {BlockchainError} When revocation transaction fails
935
+ * @throws {UserRejectedRequestError} When user rejects the transaction
936
+ * @example
937
+ * ```typescript
938
+ * // Submit revocation and handle confirmation later
939
+ * const txHash = await vana.permissions.submitPermissionRevoke({
940
+ * permissionId: 123n
941
+ * });
942
+ * console.log(`Revocation submitted: ${txHash}`);
943
+ * ```
944
+ */
945
+ async submitPermissionRevoke(params, options) {
946
+ this.assertWallet();
947
+ try {
948
+ if (!this.context.walletClient?.chain?.id) {
949
+ throw new import_errors.BlockchainError("Chain ID not available");
950
+ }
951
+ const chainId = await this.context.publicClient.getChainId();
952
+ const DataPortabilityPermissionsAddress = (0, import_addresses.getContractAddress)(
953
+ chainId,
954
+ "DataPortabilityPermissions"
955
+ );
956
+ const DataPortabilityPermissionsAbi = (0, import_abi.getAbi)(
957
+ "DataPortabilityPermissions"
958
+ );
959
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
960
+ const txHash = await this.context.walletClient.writeContract({
961
+ address: DataPortabilityPermissionsAddress,
962
+ abi: DataPortabilityPermissionsAbi,
963
+ functionName: "revokePermission",
964
+ args: [params.permissionId],
965
+ account,
966
+ chain: this.context.walletClient?.chain ?? null,
967
+ ...options?.gas && { gas: options.gas },
968
+ ...options?.nonce && { nonce: options.nonce },
969
+ // Use EIP-1559 if available, otherwise fall back to legacy gasPrice
970
+ ...options?.maxFeePerGas || options?.maxPriorityFeePerGas ? {
971
+ ...options.maxFeePerGas && {
972
+ maxFeePerGas: options.maxFeePerGas
973
+ },
974
+ ...options.maxPriorityFeePerGas && {
975
+ maxPriorityFeePerGas: options.maxPriorityFeePerGas
976
+ }
977
+ } : options?.gasPrice && { gasPrice: options.gasPrice }
978
+ });
979
+ const { tx } = await import("../utils/transactionHelpers");
980
+ return tx({
981
+ hash: txHash,
982
+ from: typeof account === "string" ? account : account.address,
983
+ contract: "DataPortabilityPermissions",
984
+ fn: "revokePermission"
985
+ });
986
+ } catch (error) {
987
+ if (error instanceof Error) {
988
+ if (error instanceof import_errors.RelayerError || error instanceof import_errors.UserRejectedRequestError || error instanceof import_errors.SerializationError || error instanceof import_errors.SignatureError || error instanceof import_errors.NetworkError || error instanceof import_errors.NonceError) {
989
+ throw error;
990
+ }
991
+ throw new import_errors.BlockchainError(
992
+ `Permission revoke failed: ${error.message}`,
993
+ error
994
+ );
995
+ }
996
+ throw new import_errors.BlockchainError("Permission revoke failed with unknown error");
997
+ }
998
+ }
999
+ /**
1000
+ * Revokes a permission with a signature for gasless transactions.
1001
+ *
1002
+ * @remarks
1003
+ * This method creates an EIP-712 signature for permission revocation and submits
1004
+ * it either through relayer callbacks or directly to the blockchain. Provides
1005
+ * gasless revocation when relayer is configured.
1006
+ *
1007
+ * @param params - Parameters for revoking the permission
1008
+ * @param params.permissionId - Permission identifier to revoke (accepts bigint, number, or string)
1009
+ * @returns Promise resolving to TransactionResult for transaction tracking
1010
+ * @throws {BlockchainError} When chain ID is not available
1011
+ * @throws {NonceError} When retrieving user nonce fails
1012
+ * @throws {SignatureError} When user rejects the signature request
1013
+ * @throws {RelayerError} When gasless submission fails
1014
+ * @throws {PermissionError} When revocation fails for any other reason
1015
+ * @example
1016
+ * ```typescript
1017
+ * const txHandle = await vana.permissions.submitRevokeWithSignature({
1018
+ * permissionId: 123n
1019
+ * });
1020
+ * const result = await txHandle.waitForEvents();
1021
+ * console.log(`Permission ${result.permissionId} revoked`);
1022
+ * ```
1023
+ */
1024
+ async submitRevokeWithSignature(params) {
1025
+ this.assertWallet();
1026
+ try {
1027
+ if (!this.context.walletClient?.chain?.id) {
1028
+ throw new import_errors.BlockchainError("Chain ID not available");
1029
+ }
1030
+ const nonce = await this.getPermissionsUserNonce();
1031
+ const revokePermissionInput = {
1032
+ nonce,
1033
+ permissionId: params.permissionId
1034
+ };
1035
+ const typedData = {
1036
+ domain: await this.getPermissionDomain(),
1037
+ types: {
1038
+ RevokePermission: [
1039
+ { name: "nonce", type: "uint256" },
1040
+ { name: "permissionId", type: "uint256" }
1041
+ ]
1042
+ },
1043
+ primaryType: "RevokePermission",
1044
+ message: revokePermissionInput
1045
+ };
1046
+ const signature = await this.signTypedData(typedData);
1047
+ let hash;
1048
+ if (this.context.relayer) {
1049
+ const response = await this.context.relayer({
1050
+ type: "signed",
1051
+ operation: "submitPermissionRevoke",
1052
+ typedData,
1053
+ signature,
1054
+ expectedUserAddress: this.context.userAddress
1055
+ });
1056
+ if (response.type === "signed") {
1057
+ hash = response.hash;
1058
+ } else if (response.type === "error") {
1059
+ throw new Error(`Relayer error: ${response.error}`);
1060
+ } else {
1061
+ throw new Error(
1062
+ "Invalid response from relayer: expected signed transaction"
1063
+ );
1064
+ }
1065
+ } else {
1066
+ hash = await this.submitDirectRevokeTransaction(
1067
+ typedData,
1068
+ signature
1069
+ );
1070
+ }
1071
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
1072
+ const { tx } = await import("../utils/transactionHelpers");
1073
+ return tx({
1074
+ hash,
1075
+ from: typeof account === "string" ? account : account.address,
1076
+ contract: "DataPortabilityPermissions",
1077
+ fn: "revokePermissionWithSignature"
1078
+ });
1079
+ } catch (error) {
1080
+ throw new import_errors.PermissionError(
1081
+ `Failed to revoke permission with signature: ${error instanceof Error ? error.message : "Unknown error"}`,
1082
+ error
1083
+ );
1084
+ }
1085
+ }
1086
+ /**
1087
+ * Retrieves the user's current nonce from the DataPortabilityServers contract.
1088
+ * This nonce is used for server-related operations (AddAndTrustServer, TrustServer, UntrustServer).
1089
+ *
1090
+ * @returns Promise resolving to the current servers nonce
1091
+ * @throws {NonceError} When reading nonce from contract fails
1092
+ * @private
1093
+ *
1094
+ * @example
1095
+ * ```typescript
1096
+ * const nonce = await this.getServersUserNonce();
1097
+ * console.log(`Current servers nonce: ${nonce}`);
1098
+ * ```
1099
+ */
1100
+ /**
1101
+ * Retrieves the user's current nonce from the DataPortabilityServers contract.
1102
+ *
1103
+ * @remarks
1104
+ * Used for server-related operations (trust/untrust) to prevent replay attacks.
1105
+ * The nonce must be incremented with each server operation.
1106
+ *
1107
+ * @returns Promise resolving to the user's current nonce as a bigint
1108
+ * @throws {NonceError} When retrieving the nonce fails
1109
+ */
1110
+ async getServersUserNonce() {
1111
+ try {
1112
+ const userAddress = this.context.userAddress;
1113
+ const chainId = await this.context.publicClient.getChainId();
1114
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
1115
+ chainId,
1116
+ "DataPortabilityServers"
1117
+ );
1118
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
1119
+ const [nonce] = await this.context.publicClient.readContract({
1120
+ address: DataPortabilityServersAddress,
1121
+ abi: DataPortabilityServersAbi,
1122
+ functionName: "users",
1123
+ args: [userAddress]
1124
+ });
1125
+ return nonce;
1126
+ } catch (error) {
1127
+ throw new import_errors.NonceError(
1128
+ `Failed to retrieve server nonce: ${error instanceof Error ? error.message : "Unknown error"}`
1129
+ );
1130
+ }
1131
+ }
1132
+ /**
1133
+ * Retrieves the user's current nonce from the DataPortabilityPermissions contract.
1134
+ * This nonce is used for permission-related operations (addPermission, addServerFilesAndPermissions).
1135
+ *
1136
+ * @returns Promise resolving to the current permissions nonce
1137
+ * @throws {NonceError} When reading nonce from contract fails
1138
+ * @private
1139
+ *
1140
+ * @example
1141
+ * ```typescript
1142
+ * const nonce = await this.getPermissionsUserNonce();
1143
+ * console.log(`Current permissions nonce: ${nonce}`);
1144
+ * ```
1145
+ */
1146
+ /**
1147
+ * Retrieves the user's current nonce from the DataPortabilityPermissions contract.
1148
+ *
1149
+ * @remarks
1150
+ * Used for permission-related operations (grant/revoke) to prevent replay attacks.
1151
+ * The nonce must be incremented with each permission operation.
1152
+ *
1153
+ * @returns Promise resolving to the user's current nonce as a bigint
1154
+ * @throws {NonceError} When retrieving the nonce fails
1155
+ */
1156
+ async getPermissionsUserNonce() {
1157
+ try {
1158
+ const userAddress = this.context.userAddress;
1159
+ const chainId = await this.context.publicClient.getChainId();
1160
+ const DataPortabilityPermissionsAddress = (0, import_addresses.getContractAddress)(
1161
+ chainId,
1162
+ "DataPortabilityPermissions"
1163
+ );
1164
+ const DataPortabilityPermissionsAbi = (0, import_abi.getAbi)(
1165
+ "DataPortabilityPermissions"
1166
+ );
1167
+ const nonce = await this.context.publicClient.readContract({
1168
+ address: DataPortabilityPermissionsAddress,
1169
+ abi: DataPortabilityPermissionsAbi,
1170
+ functionName: "userNonce",
1171
+ args: [userAddress]
1172
+ });
1173
+ return nonce;
1174
+ } catch (error) {
1175
+ throw new import_errors.NonceError(
1176
+ `Failed to retrieve permissions nonce: ${error instanceof Error ? error.message : "Unknown error"}`
1177
+ );
1178
+ }
1179
+ }
1180
+ /**
1181
+ * Composes the EIP-712 typed data for PermissionGrant (new simplified format).
1182
+ *
1183
+ * @param params - The parameters for composing the permission grant message
1184
+ * @param params.grantee - The recipient address for the permission grant
1185
+ * @param params.operation - The type of operation being granted permission for
1186
+ * @param params.files - Array of file IDs that the permission applies to
1187
+ * @param params.grantUrl - URL where the grant details are stored
1188
+ * @param params.serializedParameters - Serialized parameters for the operation
1189
+ * @param params.nonce - Unique number to prevent replay attacks
1190
+ * @returns Promise resolving to the typed data structure
1191
+ */
1192
+ async composePermissionGrantMessage(params) {
1193
+ const domain = await this.getPermissionDomain();
1194
+ console.debug(
1195
+ "\u{1F50D} Debug - Composing permission message with grantUrl:",
1196
+ params.grantUrl
1197
+ );
1198
+ const chainId = await this.context.publicClient.getChainId();
1199
+ const DataPortabilityGranteesAddress = (0, import_addresses.getContractAddress)(
1200
+ chainId,
1201
+ "DataPortabilityGrantees"
1202
+ );
1203
+ const DataPortabilityGranteesAbi = (0, import_abi.getAbi)("DataPortabilityGrantees");
1204
+ const granteeId = await this.context.publicClient.readContract({
1205
+ address: DataPortabilityGranteesAddress,
1206
+ abi: DataPortabilityGranteesAbi,
1207
+ functionName: "granteeAddressToId",
1208
+ args: [params.grantee]
1209
+ });
1210
+ if (!params.grantUrl.startsWith("ipfs://") && params.grantUrl.includes("/ipfs/")) {
1211
+ const { extractIpfsHash } = await import("../utils/ipfs");
1212
+ const hash = extractIpfsHash(params.grantUrl);
1213
+ if (hash) {
1214
+ console.warn(
1215
+ `\u26A0\uFE0F Storing HTTP gateway URL on-chain instead of ipfs:// protocol. Found: ${params.grantUrl}. Consider using ipfs://${hash} for better protocol-agnostic on-chain storage.`
1216
+ );
1217
+ }
1218
+ }
1219
+ return {
1220
+ domain,
1221
+ types: {
1222
+ Permission: [
1223
+ { name: "nonce", type: "uint256" },
1224
+ { name: "granteeId", type: "uint256" },
1225
+ { name: "grant", type: "string" },
1226
+ { name: "fileIds", type: "uint256[]" }
1227
+ ]
1228
+ },
1229
+ primaryType: "Permission",
1230
+ message: {
1231
+ nonce: params.nonce,
1232
+ granteeId,
1233
+ grant: params.grantUrl,
1234
+ fileIds: params.files.map((fileId) => BigInt(fileId))
1235
+ }
1236
+ };
1237
+ }
1238
+ /**
1239
+ * Creates EIP-712 typed data structure for server files and permissions.
1240
+ *
1241
+ * @param params - Parameters for the server files and permissions message
1242
+ * @param params.granteeId - Grantee ID
1243
+ * @param params.grant - Grant URL or grant data
1244
+ * @param params.fileUrls - Array of file URLs
1245
+ * @param params.schemaIds - Schema IDs for each file
1246
+ * @param params.serverAddress - Server address
1247
+ * @param params.serverUrl - Server URL
1248
+ * @param params.serverPublicKey - Server public key
1249
+ * @param params.filePermissions - File permissions array
1250
+ * @param params.nonce - Unique number to prevent replay attacks
1251
+ * @returns Promise resolving to the typed data structure
1252
+ */
1253
+ async composeServerFilesAndPermissionMessage(params) {
1254
+ const domain = await this.getPermissionDomain();
1255
+ console.debug(
1256
+ "\u{1F50D} Debug - Composing server files and permission message with grant:",
1257
+ params.grant
1258
+ );
1259
+ if (!params.grant.startsWith("ipfs://") && params.grant.includes("/ipfs/")) {
1260
+ const { extractIpfsHash } = await import("../utils/ipfs");
1261
+ const hash = extractIpfsHash(params.grant);
1262
+ if (hash) {
1263
+ console.warn(
1264
+ `\u26A0\uFE0F Storing HTTP gateway URL on-chain instead of ipfs:// protocol. Found: ${params.grant}. Consider using ipfs://${hash} for better protocol-agnostic on-chain storage.`
1265
+ );
1266
+ }
1267
+ }
1268
+ return {
1269
+ domain,
1270
+ types: {
1271
+ Permission: [
1272
+ { name: "account", type: "address" },
1273
+ { name: "key", type: "string" }
1274
+ ],
1275
+ ServerFilesAndPermission: [
1276
+ { name: "nonce", type: "uint256" },
1277
+ { name: "granteeId", type: "uint256" },
1278
+ { name: "grant", type: "string" },
1279
+ { name: "fileUrls", type: "string[]" },
1280
+ { name: "schemaIds", type: "uint256[]" },
1281
+ { name: "serverAddress", type: "address" },
1282
+ { name: "serverUrl", type: "string" },
1283
+ { name: "serverPublicKey", type: "string" },
1284
+ { name: "filePermissions", type: "Permission[][]" }
1285
+ ]
1286
+ },
1287
+ primaryType: "ServerFilesAndPermission",
1288
+ message: {
1289
+ nonce: params.nonce,
1290
+ granteeId: params.granteeId,
1291
+ grant: params.grant,
1292
+ fileUrls: params.fileUrls,
1293
+ schemaIds: params.schemaIds.map((id) => BigInt(id)),
1294
+ serverAddress: params.serverAddress,
1295
+ serverUrl: params.serverUrl,
1296
+ serverPublicKey: params.serverPublicKey,
1297
+ filePermissions: params.filePermissions
1298
+ }
1299
+ };
1300
+ }
1301
+ /**
1302
+ * Gets the EIP-712 domain for PermissionGrant signatures.
1303
+ *
1304
+ * @returns Promise resolving to the EIP-712 domain configuration
1305
+ */
1306
+ async getPermissionDomain() {
1307
+ const chainId = await this.context.publicClient.getChainId();
1308
+ const DataPortabilityPermissionsAddress = (0, import_addresses.getContractAddress)(
1309
+ chainId,
1310
+ "DataPortabilityPermissions"
1311
+ );
1312
+ return {
1313
+ name: "VanaDataPortabilityPermissions",
1314
+ version: "1",
1315
+ chainId,
1316
+ verifyingContract: DataPortabilityPermissionsAddress
1317
+ };
1318
+ }
1319
+ /**
1320
+ * Signs typed data using the wallet client with signature caching.
1321
+ *
1322
+ * @param typedData - The EIP-712 typed data structure to sign
1323
+ * @returns Promise resolving to the cryptographic signature
1324
+ */
1325
+ async signTypedData(typedData) {
1326
+ this.assertWallet();
1327
+ try {
1328
+ const walletAddress = this.context.walletClient.account?.address ?? this.context.userAddress;
1329
+ return await (0, import_signatureCache.withSignatureCache)(
1330
+ this.context.platform.cache,
1331
+ walletAddress,
1332
+ typedData,
1333
+ async () => {
1334
+ const viemCompatibleTypedData = (0, import_typedDataConverter.toViemTypedDataDefinition)(typedData);
1335
+ return await this.context.walletClient.signTypedData({
1336
+ ...viemCompatibleTypedData,
1337
+ // Use the account if available, otherwise use the wallet address
1338
+ // This follows the same pattern used throughout this file
1339
+ account: this.context.walletClient.account ?? walletAddress
1340
+ });
1341
+ }
1342
+ );
1343
+ } catch (error) {
1344
+ if (error instanceof Error && error.message.includes("rejected")) {
1345
+ throw new import_errors.UserRejectedRequestError();
1346
+ }
1347
+ throw new import_errors.SignatureError(
1348
+ `Failed to sign typed data: ${error instanceof Error ? error.message : "Unknown error"}`,
1349
+ error
1350
+ );
1351
+ }
1352
+ }
1353
+ /**
1354
+ * Gets the user's address from the context.
1355
+ *
1356
+ * @returns The user's address
1357
+ */
1358
+ /**
1359
+ * Gets on-chain permission grant data without expensive off-chain resolution.
1360
+ *
1361
+ * @remarks
1362
+ * This method provides a fast, performance-focused way to retrieve permission grants
1363
+ * by querying only the subgraph without making expensive IPFS or individual contract calls.
1364
+ * It eliminates the N+1 query problem of the legacy `getUserPermissions()` method.
1365
+ *
1366
+ * The returned data contains all on-chain information but does NOT include resolved
1367
+ * operation details, parameters, or file IDs. Use `retrieveGrantFile()` separately
1368
+ * for specific grants when detailed data is needed.
1369
+ *
1370
+ * **Performance**: Completes in ~100-500ms regardless of permission count.
1371
+ * **Reliability**: Single point of failure (subgraph) with clear RPC fallback path.
1372
+ *
1373
+ * @param options - Options for retrieving permissions (limit, subgraph URL)
1374
+ * @returns A Promise that resolves to an array of `OnChainPermissionGrant` objects
1375
+ * @throws {BlockchainError} When subgraph query fails
1376
+ * @throws {NetworkError} When network requests fail
1377
+ * @example
1378
+ * ```typescript
1379
+ * // Fast: Get all on-chain permission data
1380
+ * const grants = await vana.permissions.getUserPermissionGrantsOnChain({ limit: 20 });
1381
+ *
1382
+ * // Display in UI immediately
1383
+ * grants.forEach(grant => {
1384
+ * console.log(`Permission ${grant.id}: ${grant.grantUrl}`);
1385
+ * });
1386
+ *
1387
+ * // Lazy load detailed data for specific permission when user clicks
1388
+ * const grantFile = await retrieveGrantFile(grants[0].grantUrl);
1389
+ * console.log(`Operation: ${grantFile.operation}`);
1390
+ * console.log(`Parameters:`, grantFile.parameters);
1391
+ * ```
1392
+ */
1393
+ async getUserPermissionGrantsOnChain(options = {}) {
1394
+ const { limit = 50, subgraphUrl } = options;
1395
+ try {
1396
+ const userAddress = this.context.userAddress;
1397
+ const graphqlEndpoint = subgraphUrl ?? this.context.subgraphUrl;
1398
+ if (!graphqlEndpoint) {
1399
+ throw new import_errors.BlockchainError(
1400
+ "subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor."
1401
+ );
1402
+ }
1403
+ const query = `
1404
+ query GetUserPermissions($userId: ID!) {
1405
+ user(id: $userId) {
1406
+ id
1407
+ permissions {
1408
+ id
1409
+ grant
1410
+ nonce
1411
+ signature
1412
+ startBlock
1413
+ endBlock
1414
+ addedAtBlock
1415
+ addedAtTimestamp
1416
+ transactionHash
1417
+ grantee {
1418
+ id
1419
+ address
1420
+ }
1421
+ }
1422
+ }
1423
+ }
1424
+ `;
1425
+ const response = await fetch(graphqlEndpoint, {
1426
+ method: "POST",
1427
+ headers: {
1428
+ "Content-Type": "application/json"
1429
+ },
1430
+ body: JSON.stringify({
1431
+ query,
1432
+ variables: {
1433
+ userId: userAddress.toLowerCase()
1434
+ }
1435
+ })
1436
+ });
1437
+ if (!response.ok) {
1438
+ throw new import_errors.BlockchainError(
1439
+ `Subgraph request failed: ${response.status} ${response.statusText}`
1440
+ );
1441
+ }
1442
+ const result = await response.json();
1443
+ if (result.errors) {
1444
+ throw new import_errors.BlockchainError(
1445
+ `Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
1446
+ );
1447
+ }
1448
+ const userData = result.data?.user;
1449
+ if (!userData?.permissions?.length) {
1450
+ return [];
1451
+ }
1452
+ const onChainGrants = userData.permissions.slice(0, limit).map(
1453
+ (permission) => ({
1454
+ id: BigInt(permission.id),
1455
+ grantUrl: permission.grant,
1456
+ grantSignature: permission.signature,
1457
+ nonce: BigInt(permission.nonce),
1458
+ startBlock: BigInt(permission.startBlock),
1459
+ addedAtBlock: BigInt(permission.addedAtBlock),
1460
+ addedAtTimestamp: BigInt(permission.addedAtTimestamp ?? "0"),
1461
+ transactionHash: permission.transactionHash ?? "",
1462
+ grantor: userAddress,
1463
+ grantee: permission.grantee,
1464
+ active: !permission.endBlock || BigInt(permission.endBlock) === 0n
1465
+ // Active if no end block or end block is 0
1466
+ })
1467
+ );
1468
+ return onChainGrants.sort((a, b) => {
1469
+ if (a.id < b.id) return 1;
1470
+ if (a.id > b.id) return -1;
1471
+ return 0;
1472
+ });
1473
+ } catch (error) {
1474
+ if (error instanceof import_errors.BlockchainError || error instanceof import_errors.NetworkError) {
1475
+ throw error;
1476
+ }
1477
+ throw new import_errors.BlockchainError(
1478
+ `Failed to fetch user permission grants: ${error instanceof Error ? error.message : "Unknown error"}`
1479
+ );
1480
+ }
1481
+ }
1482
+ /**
1483
+ * Registers a new server and immediately trusts it in the DataPortabilityServers contract.
1484
+ *
1485
+ * This is a combined operation that both registers a new data portability server
1486
+ * and adds it to the user's trusted servers list in a single transaction.
1487
+ * Trusted servers can handle data export and portability requests from the user.
1488
+ *
1489
+ * @param params - Parameters for adding and trusting the server
1490
+ * @param params.serverAddress - Ethereum address of the server
1491
+ * @param params.serverUrl - HTTPS URL where the server can be reached
1492
+ * @param params.publicKey - Server's public key for encryption (hex string)
1493
+ * @returns Promise resolving to transaction hash
1494
+ * @throws {UserRejectedRequestError} When user rejects the transaction
1495
+ * @throws {BlockchainError} When chain ID is unavailable or transaction fails
1496
+ * @throws {ServerAlreadyRegisteredError} When server address is already registered
1497
+ * @throws {Error} When wallet account is not available
1498
+ *
1499
+ * @example
1500
+ * ```typescript
1501
+ * // Add and trust a server by providing all required details
1502
+ * const txHash = await vana.permissions.addAndTrustServer({
1503
+ * owner: '0x1234567890abcdef1234567890abcdef12345678',
1504
+ * serverAddress: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
1505
+ * serverUrl: 'https://myserver.example.com',
1506
+ * publicKey: '0x456789abcdef456789abcdef456789abcdef456789abcdef'
1507
+ * });
1508
+ * console.log('Server added and trusted in transaction:', txHash);
1509
+ *
1510
+ * // Verify the server is now trusted
1511
+ * const trustedServers = await vana.permissions.getTrustedServers();
1512
+ * console.log('Now trusting servers:', trustedServers);
1513
+ * ```
1514
+ */
1515
+ async addAndTrustServer(params) {
1516
+ this.assertWallet();
1517
+ try {
1518
+ const chainId = await this.context.walletClient.getChainId();
1519
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
1520
+ chainId,
1521
+ "DataPortabilityServers"
1522
+ );
1523
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
1524
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
1525
+ const userAddress = typeof account === "string" ? account : account.address;
1526
+ const normalizedUserAddress = (0, import_viem.getAddress)(userAddress);
1527
+ const normalizedServerAddress = (0, import_viem.getAddress)(params.serverAddress);
1528
+ const txHash = await this.context.walletClient.writeContract({
1529
+ address: DataPortabilityServersAddress,
1530
+ abi: DataPortabilityServersAbi,
1531
+ functionName: "addAndTrustServerByManager",
1532
+ args: [
1533
+ normalizedUserAddress,
1534
+ {
1535
+ serverAddress: normalizedServerAddress,
1536
+ serverUrl: params.serverUrl,
1537
+ publicKey: params.publicKey
1538
+ }
1539
+ ],
1540
+ account,
1541
+ chain: this.context.walletClient?.chain ?? null
1542
+ });
1543
+ const { tx } = await import("../utils/transactionHelpers");
1544
+ const txResult = tx({
1545
+ hash: txHash,
1546
+ from: userAddress,
1547
+ contract: "DataPortabilityServers",
1548
+ fn: "addAndTrustServerByManager"
1549
+ });
1550
+ if (!this.context.waitForTransactionEvents) {
1551
+ throw new import_errors.BlockchainError("waitForTransactionEvents not configured");
1552
+ }
1553
+ const result = await this.context.waitForTransactionEvents(txResult);
1554
+ const event = result.expectedEvents.ServerTrusted;
1555
+ if (!event) {
1556
+ throw new import_errors.BlockchainError(
1557
+ "ServerTrusted event not found in transaction"
1558
+ );
1559
+ }
1560
+ const receipt = await this.context.publicClient.getTransactionReceipt({
1561
+ hash: txHash
1562
+ });
1563
+ return {
1564
+ transactionHash: txHash,
1565
+ blockNumber: receipt.blockNumber,
1566
+ gasUsed: receipt.gasUsed,
1567
+ user: event.user,
1568
+ serverId: event.serverId,
1569
+ // bigint from event
1570
+ serverAddress: normalizedServerAddress,
1571
+ // derived from params
1572
+ serverUrl: params.serverUrl
1573
+ // provided in params
1574
+ };
1575
+ } catch (error) {
1576
+ if (error instanceof Error && error.message.includes("rejected")) {
1577
+ throw new import_errors.UserRejectedRequestError();
1578
+ }
1579
+ throw new import_errors.BlockchainError(
1580
+ `Failed to add and trust server: ${error instanceof Error ? error.message : "Unknown error"}`,
1581
+ error
1582
+ );
1583
+ }
1584
+ }
1585
+ /**
1586
+ * Trusts a server for data processing (legacy method).
1587
+ *
1588
+ * @param params - Parameters for trusting the server
1589
+ * @returns Promise resolving to transaction hash
1590
+ * @deprecated Use addAndTrustServer instead
1591
+ */
1592
+ async submitTrustServer(params) {
1593
+ this.assertWallet();
1594
+ try {
1595
+ const chainId = await this.context.walletClient.getChainId();
1596
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
1597
+ chainId,
1598
+ "DataPortabilityServers"
1599
+ );
1600
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
1601
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
1602
+ const txHash = await this.context.walletClient.writeContract({
1603
+ address: DataPortabilityServersAddress,
1604
+ abi: DataPortabilityServersAbi,
1605
+ functionName: "trustServer",
1606
+ args: [BigInt(params.serverId)],
1607
+ account,
1608
+ chain: this.context.walletClient?.chain ?? null
1609
+ });
1610
+ const { tx } = await import("../utils/transactionHelpers");
1611
+ return tx({
1612
+ hash: txHash,
1613
+ from: typeof account === "string" ? account : account.address,
1614
+ contract: "DataPortabilityServers",
1615
+ fn: "trustServer"
1616
+ });
1617
+ } catch (error) {
1618
+ if (error instanceof Error && error.message.includes("rejected")) {
1619
+ throw new import_errors.UserRejectedRequestError();
1620
+ }
1621
+ throw new import_errors.BlockchainError(
1622
+ `Failed to trust server: ${error instanceof Error ? error.message : "Unknown error"}`,
1623
+ error
1624
+ );
1625
+ }
1626
+ }
1627
+ /**
1628
+ * Adds and trusts a server using a signature (gasless transaction).
1629
+ *
1630
+ * @param params - Parameters for adding and trusting the server
1631
+ * @returns Promise resolving to TransactionResult with ServerTrustResult event data
1632
+ */
1633
+ async submitAddAndTrustServerWithSignature(params) {
1634
+ this.assertWallet();
1635
+ try {
1636
+ const nonce = await this.getServersUserNonce();
1637
+ const serverAddress = (0, import_viem.getAddress)(params.serverAddress);
1638
+ const addAndTrustServerInput = {
1639
+ nonce,
1640
+ serverAddress,
1641
+ publicKey: params.publicKey,
1642
+ serverUrl: params.serverUrl
1643
+ };
1644
+ const typedData = await this.composeAddAndTrustServerMessage(
1645
+ addAndTrustServerInput
1646
+ );
1647
+ console.debug("\u{1F50D} AddAndTrustServer Debug Info:", {
1648
+ nonce: nonce.toString(),
1649
+ serverAddress: params.serverAddress,
1650
+ publicKey: params.publicKey,
1651
+ serverUrl: params.serverUrl,
1652
+ domain: typedData.domain,
1653
+ typedDataMessage: typedData.message
1654
+ });
1655
+ const signature = await this.signTypedData(typedData);
1656
+ console.debug("\u{1F50D} Generated signature:", signature);
1657
+ let hash;
1658
+ if (this.context.relayer) {
1659
+ const request = {
1660
+ type: "signed",
1661
+ operation: "submitAddAndTrustServer",
1662
+ typedData,
1663
+ signature
1664
+ };
1665
+ const response = await this.context.relayer(request);
1666
+ if (response.type === "error") {
1667
+ throw new import_errors.RelayerError(response.error);
1668
+ }
1669
+ if (response.type === "signed") {
1670
+ hash = response.hash;
1671
+ } else {
1672
+ throw new Error("Unexpected response type from relayer");
1673
+ }
1674
+ } else {
1675
+ hash = await this.submitAddAndTrustServerTransaction(
1676
+ addAndTrustServerInput,
1677
+ signature
1678
+ );
1679
+ }
1680
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
1681
+ const { tx } = await import("../utils/transactionHelpers");
1682
+ return tx({
1683
+ hash,
1684
+ from: typeof account === "string" ? account : account.address,
1685
+ contract: "DataPortabilityServers",
1686
+ fn: "addAndTrustServerWithSignature"
1687
+ });
1688
+ } catch (error) {
1689
+ if (error instanceof Error) {
1690
+ if (error instanceof import_errors.RelayerError || error instanceof import_errors.UserRejectedRequestError || error instanceof import_errors.SerializationError || error instanceof import_errors.SignatureError || error instanceof import_errors.NetworkError || error instanceof import_errors.NonceError) {
1691
+ throw error;
1692
+ }
1693
+ throw new import_errors.BlockchainError(
1694
+ `Add and trust server failed: ${error.message}`,
1695
+ error
1696
+ );
1697
+ }
1698
+ throw new import_errors.BlockchainError(
1699
+ "Add and trust server failed with unknown error"
1700
+ );
1701
+ }
1702
+ }
1703
+ /**
1704
+ * Trusts a server using a signature (gasless transaction - legacy method).
1705
+ *
1706
+ * @param params - Parameters for trusting the server
1707
+ * @returns Promise resolving to transaction hash
1708
+ * @deprecated Use addAndTrustServerWithSignature instead
1709
+ * @throws {BlockchainError} When chain ID is not available
1710
+ * @throws {NonceError} When retrieving user nonce fails
1711
+ * @throws {SignatureError} When user rejects the signature request
1712
+ * @throws {RelayerError} When gasless submission fails
1713
+ * @throws {ServerUrlMismatchError} When server URL doesn't match existing registration
1714
+ * @throws {BlockchainError} When trust operation fails for any other reason
1715
+ */
1716
+ async submitTrustServerWithSignature(params) {
1717
+ this.assertWallet();
1718
+ try {
1719
+ const nonce = await this.getServersUserNonce();
1720
+ const trustServerInput = {
1721
+ nonce,
1722
+ serverId: params.serverId
1723
+ };
1724
+ const typedData = await this.composeTrustServerMessage(trustServerInput);
1725
+ const signature = await this.signTypedData(typedData);
1726
+ let hash;
1727
+ if (this.context.relayer) {
1728
+ const request = {
1729
+ type: "signed",
1730
+ operation: "submitTrustServer",
1731
+ typedData,
1732
+ signature
1733
+ };
1734
+ const response = await this.context.relayer(request);
1735
+ if (response.type === "error") {
1736
+ throw new import_errors.RelayerError(response.error);
1737
+ }
1738
+ if (response.type === "signed") {
1739
+ hash = response.hash;
1740
+ } else {
1741
+ throw new Error("Unexpected response type from relayer");
1742
+ }
1743
+ } else {
1744
+ hash = await this.submitTrustServerTransaction(
1745
+ trustServerInput,
1746
+ signature
1747
+ );
1748
+ }
1749
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
1750
+ const { tx } = await import("../utils/transactionHelpers");
1751
+ return tx({
1752
+ hash,
1753
+ from: typeof account === "string" ? account : account.address,
1754
+ contract: "DataPortabilityServers",
1755
+ fn: "trustServerWithSignature"
1756
+ });
1757
+ } catch (error) {
1758
+ if (error instanceof Error) {
1759
+ if (error instanceof import_errors.RelayerError || error instanceof import_errors.UserRejectedRequestError || error instanceof import_errors.SerializationError || error instanceof import_errors.SignatureError || error instanceof import_errors.NetworkError || error instanceof import_errors.NonceError) {
1760
+ throw error;
1761
+ }
1762
+ throw new import_errors.BlockchainError(
1763
+ `Trust server failed: ${error.message}`,
1764
+ error
1765
+ );
1766
+ }
1767
+ throw new import_errors.BlockchainError("Trust server failed with unknown error");
1768
+ }
1769
+ }
1770
+ /**
1771
+ * Submits a direct untrust server transaction (without signature).
1772
+ *
1773
+ * @param params - The untrust server parameters containing server details
1774
+ * @returns Promise resolving to the transaction hash
1775
+ */
1776
+ /**
1777
+ * Submits an untrust server transaction directly to the blockchain.
1778
+ *
1779
+ * @remarks
1780
+ * Internal method used for direct blockchain submission of untrust server operations
1781
+ * when relayer callbacks are not available.
1782
+ *
1783
+ * @param params - The untrust server parameters
1784
+ * @returns Promise resolving to TransactionResult for transaction tracking
1785
+ * @throws {BlockchainError} When contract submission fails
1786
+ */
1787
+ async submitDirectUntrustTransaction(params, options) {
1788
+ this.assertWallet();
1789
+ try {
1790
+ const chainId = await this.context.walletClient.getChainId();
1791
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
1792
+ chainId,
1793
+ "DataPortabilityServers"
1794
+ );
1795
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
1796
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
1797
+ const txHash = await this.context.walletClient.writeContract({
1798
+ address: DataPortabilityServersAddress,
1799
+ abi: DataPortabilityServersAbi,
1800
+ functionName: "untrustServer",
1801
+ args: [BigInt(params.serverId)],
1802
+ account,
1803
+ chain: this.context.walletClient?.chain ?? null,
1804
+ ...options?.gas && { gas: options.gas },
1805
+ ...options?.nonce && { nonce: options.nonce },
1806
+ // Use EIP-1559 if available, otherwise fall back to legacy gasPrice
1807
+ ...options?.maxFeePerGas || options?.maxPriorityFeePerGas ? {
1808
+ ...options.maxFeePerGas && {
1809
+ maxFeePerGas: options.maxFeePerGas
1810
+ },
1811
+ ...options.maxPriorityFeePerGas && {
1812
+ maxPriorityFeePerGas: options.maxPriorityFeePerGas
1813
+ }
1814
+ } : options?.gasPrice && { gasPrice: options.gasPrice }
1815
+ });
1816
+ const { tx } = await import("../utils/transactionHelpers");
1817
+ return tx({
1818
+ hash: txHash,
1819
+ from: typeof account === "string" ? account : account.address,
1820
+ contract: "DataPortabilityServers",
1821
+ fn: "untrustServer"
1822
+ });
1823
+ } catch (error) {
1824
+ if (error instanceof Error && error.message.includes("rejected")) {
1825
+ throw new import_errors.UserRejectedRequestError();
1826
+ }
1827
+ throw new import_errors.BlockchainError(
1828
+ `Failed to untrust server: ${error instanceof Error ? error.message : "Unknown error"}`,
1829
+ error
1830
+ );
1831
+ }
1832
+ }
1833
+ /**
1834
+ * Removes a server from the user's trusted servers list in the DataPortabilityServers contract.
1835
+ *
1836
+ * This revokes the server's authorization to handle data portability requests for the user.
1837
+ * The server remains registered in the system but will no longer be trusted by this user.
1838
+ *
1839
+ * @param params - Parameters for untrusting the server
1840
+ * @param params.serverId - The numeric ID of the server to untrust
1841
+ * @param options - Optional transaction options for gas parameters and timeout
1842
+ * @returns Promise resolving to transaction hash
1843
+ * @throws {Error} When wallet account is not available
1844
+ * @throws {NonceError} When retrieving user nonce fails
1845
+ * @throws {UserRejectedRequestError} When user rejects the transaction
1846
+ * @throws {ServerNotTrustedError} When the server is not currently trusted
1847
+ * @throws {BlockchainError} When untrust transaction fails
1848
+ *
1849
+ * @example
1850
+ * ```typescript
1851
+ * // Untrust a specific server
1852
+ * const txHash = await vana.permissions.untrustServer({
1853
+ * serverId: 1
1854
+ * });
1855
+ * console.log('Server untrusted in transaction:', txHash);
1856
+ *
1857
+ * // Verify the server is no longer trusted
1858
+ * const trustedServers = await vana.permissions.getTrustedServers();
1859
+ * console.log('Still trusting servers:', trustedServers);
1860
+ * ```
1861
+ */
1862
+ async submitUntrustServer(params, options) {
1863
+ this.assertWallet();
1864
+ const nonce = await this.getServersUserNonce();
1865
+ const untrustServerInput = {
1866
+ nonce,
1867
+ serverId: params.serverId
1868
+ };
1869
+ return await this.submitDirectUntrustTransaction(
1870
+ untrustServerInput,
1871
+ options
1872
+ );
1873
+ }
1874
+ /**
1875
+ * Untrusts a server using a signature (gasless transaction).
1876
+ *
1877
+ * @param params - Parameters for untrusting the server
1878
+ * @param params.serverId - The server's Ethereum address to untrust
1879
+ * @returns Promise resolving to transaction hash
1880
+ * @throws {Error} When wallet account is not available
1881
+ * @throws {NonceError} When retrieving user nonce fails
1882
+ * @throws {SignatureError} When user rejects the signature request
1883
+ * @throws {RelayerError} When gasless submission fails
1884
+ * @throws {BlockchainError} When untrust transaction fails
1885
+ */
1886
+ async submitUntrustServerWithSignature(params) {
1887
+ this.assertWallet();
1888
+ try {
1889
+ const nonce = await this.getServersUserNonce();
1890
+ const untrustServerInput = {
1891
+ nonce,
1892
+ serverId: params.serverId
1893
+ };
1894
+ const typedData = await this.composeUntrustServerMessage(untrustServerInput);
1895
+ const signature = await this.signTypedData(typedData);
1896
+ let hash;
1897
+ if (this.context.relayer) {
1898
+ const request = {
1899
+ type: "signed",
1900
+ operation: "submitUntrustServer",
1901
+ typedData,
1902
+ signature
1903
+ };
1904
+ const response = await this.context.relayer(request);
1905
+ if (response.type === "error") {
1906
+ throw new import_errors.RelayerError(response.error);
1907
+ }
1908
+ if (response.type === "signed") {
1909
+ hash = response.hash;
1910
+ } else {
1911
+ throw new Error("Unexpected response type from relayer");
1912
+ }
1913
+ } else {
1914
+ hash = await this.submitSignedUntrustTransaction(typedData, signature);
1915
+ }
1916
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
1917
+ const { tx } = await import("../utils/transactionHelpers");
1918
+ return tx({
1919
+ hash,
1920
+ from: typeof account === "string" ? account : account.address,
1921
+ contract: "DataPortabilityServers",
1922
+ fn: "untrustServerWithSignature"
1923
+ });
1924
+ } catch (error) {
1925
+ if (error instanceof Error) {
1926
+ if (error instanceof import_errors.RelayerError || error instanceof import_errors.UserRejectedRequestError || error instanceof import_errors.SerializationError || error instanceof import_errors.SignatureError || error instanceof import_errors.NetworkError || error instanceof import_errors.NonceError) {
1927
+ throw error;
1928
+ }
1929
+ throw new import_errors.BlockchainError(
1930
+ `Untrust server failed: ${error.message}`,
1931
+ error
1932
+ );
1933
+ }
1934
+ throw new import_errors.BlockchainError("Untrust server failed with unknown error");
1935
+ }
1936
+ }
1937
+ /**
1938
+ * Retrieves all servers trusted by a user from the DataPortabilityServers contract.
1939
+ *
1940
+ * Returns an array of server IDs that the specified user has explicitly trusted.
1941
+ * Trusted servers are those that users have authorized to handle their data portability requests.
1942
+ *
1943
+ * @param userAddress - Optional user address to query (defaults to current wallet user)
1944
+ * @returns Promise resolving to array of trusted server IDs (numeric)
1945
+ * @throws {BlockchainError} When reading from contract fails or chain is unavailable
1946
+ * @throws {NetworkError} When unable to connect to the blockchain network
1947
+ *
1948
+ * @example
1949
+ * ```typescript
1950
+ * // Get trusted servers for current user
1951
+ * const myServers = await vana.permissions.getTrustedServers();
1952
+ * console.log(`I trust ${myServers.length} servers: ${myServers.join(', ')}`);
1953
+ *
1954
+ * // Get trusted servers for another user
1955
+ * const userServers = await vana.permissions.getTrustedServers("0x1234...");
1956
+ * console.log(`User trusts servers: ${userServers.join(', ')}`);
1957
+ * ```
1958
+ */
1959
+ async getTrustedServers(userAddress) {
1960
+ try {
1961
+ const user = userAddress ?? this.context.userAddress;
1962
+ const chainId = await this.context.publicClient.getChainId();
1963
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
1964
+ chainId,
1965
+ "DataPortabilityServers"
1966
+ );
1967
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
1968
+ const serverIds = await this.context.publicClient.readContract({
1969
+ address: DataPortabilityServersAddress,
1970
+ abi: DataPortabilityServersAbi,
1971
+ functionName: "userServerIdsValues",
1972
+ args: [user]
1973
+ });
1974
+ return serverIds.map((id) => Number(id));
1975
+ } catch (error) {
1976
+ throw new import_errors.BlockchainError(
1977
+ `Failed to get trusted servers: ${error instanceof Error ? error.message : "Unknown error"}`,
1978
+ error
1979
+ );
1980
+ }
1981
+ }
1982
+ /**
1983
+ * Gets the total count of trusted servers for a user.
1984
+ *
1985
+ * @param userAddress - Optional user address (defaults to current user)
1986
+ * @returns Promise resolving to the number of trusted servers
1987
+ * @throws {BlockchainError} When reading from contract fails or chain is unavailable
1988
+ */
1989
+ async getTrustedServersCount(userAddress) {
1990
+ try {
1991
+ const user = userAddress ?? this.context.userAddress;
1992
+ const chainId = await this.context.publicClient.getChainId();
1993
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
1994
+ chainId,
1995
+ "DataPortabilityServers"
1996
+ );
1997
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
1998
+ const count = await this.context.publicClient.readContract({
1999
+ address: DataPortabilityServersAddress,
2000
+ abi: DataPortabilityServersAbi,
2001
+ functionName: "userServerIdsLength",
2002
+ args: [user]
2003
+ });
2004
+ return Number(count);
2005
+ } catch (error) {
2006
+ throw new import_errors.BlockchainError(
2007
+ `Failed to get trusted servers count: ${error instanceof Error ? error.message : "Unknown error"}`,
2008
+ error
2009
+ );
2010
+ }
2011
+ }
2012
+ /**
2013
+ * Gets trusted servers with pagination support.
2014
+ *
2015
+ * @param options - Query options including pagination parameters
2016
+ * @returns Promise resolving to paginated trusted servers
2017
+ * @throws {BlockchainError} When reading from contract fails or chain is unavailable
2018
+ */
2019
+ async getTrustedServersPaginated(options = {}) {
2020
+ try {
2021
+ const user = options.userAddress ?? this.context.userAddress;
2022
+ const limit = options.limit ?? 50;
2023
+ const offset = options.offset ?? 0;
2024
+ const chainId = await this.context.publicClient.getChainId();
2025
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
2026
+ chainId,
2027
+ "DataPortabilityServers"
2028
+ );
2029
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
2030
+ const totalCount = await this.context.publicClient.readContract({
2031
+ address: DataPortabilityServersAddress,
2032
+ abi: DataPortabilityServersAbi,
2033
+ functionName: "userServerIdsLength",
2034
+ args: [user]
2035
+ });
2036
+ const total = Number(totalCount);
2037
+ if (offset >= total) {
2038
+ return {
2039
+ servers: [],
2040
+ total,
2041
+ offset,
2042
+ limit,
2043
+ hasMore: false
2044
+ };
2045
+ }
2046
+ const endIndex = Math.min(offset + limit, total);
2047
+ const serverIdCalls = [];
2048
+ for (let i = offset; i < endIndex; i++) {
2049
+ serverIdCalls.push({
2050
+ address: DataPortabilityServersAddress,
2051
+ abi: DataPortabilityServersAbi,
2052
+ functionName: "userServerIdsAt",
2053
+ args: [user, BigInt(i)]
2054
+ });
2055
+ }
2056
+ const serverIdResults = await (0, import_multicall.gasAwareMulticall)(this.context.publicClient, {
2057
+ contracts: serverIdCalls
2058
+ });
2059
+ const servers = serverIdResults.map((result) => Number(result)).filter((id) => id > 0);
2060
+ return {
2061
+ servers,
2062
+ total,
2063
+ offset,
2064
+ limit,
2065
+ hasMore: offset + limit < total
2066
+ };
2067
+ } catch (error) {
2068
+ throw new import_errors.BlockchainError(
2069
+ `Failed to get paginated trusted servers: ${error instanceof Error ? error.message : "Unknown error"}`,
2070
+ error
2071
+ );
2072
+ }
2073
+ }
2074
+ /**
2075
+ * Gets trusted servers with their complete information.
2076
+ *
2077
+ * @param options - Query options
2078
+ * @returns Promise resolving to array of trusted server info
2079
+ * @throws {BlockchainError} When reading from contract fails or chain is unavailable
2080
+ */
2081
+ async getTrustedServersWithInfo(options = {}) {
2082
+ try {
2083
+ const paginatedResult = await this.getTrustedServersPaginated(options);
2084
+ const chainId = await this.context.publicClient.getChainId();
2085
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
2086
+ chainId,
2087
+ "DataPortabilityServers"
2088
+ );
2089
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
2090
+ const serverInfoCalls = paginatedResult.servers.map(
2091
+ (serverId) => ({
2092
+ address: DataPortabilityServersAddress,
2093
+ abi: DataPortabilityServersAbi,
2094
+ functionName: "servers",
2095
+ args: [BigInt(serverId)]
2096
+ })
2097
+ );
2098
+ const serverInfoResults = await (0, import_multicall.gasAwareMulticall)(this.context.publicClient, {
2099
+ contracts: serverInfoCalls,
2100
+ allowFailure: true
2101
+ });
2102
+ return serverInfoResults.map((result, index) => {
2103
+ const serverId = paginatedResult.servers[index];
2104
+ if (result.status === "success" && result.result) {
2105
+ const serverInfo = result.result;
2106
+ return {
2107
+ id: BigInt(serverId),
2108
+ owner: serverInfo.owner,
2109
+ serverAddress: serverInfo.serverAddress,
2110
+ publicKey: serverInfo.publicKey,
2111
+ url: serverInfo.url,
2112
+ startBlock: 0n,
2113
+ // We don't have this info from the old method structure
2114
+ endBlock: 0n
2115
+ // 0 means still active
2116
+ };
2117
+ } else {
2118
+ return {
2119
+ id: BigInt(serverId),
2120
+ owner: "0x0000000000000000000000000000000000000000",
2121
+ serverAddress: "0x0000000000000000000000000000000000000000",
2122
+ publicKey: "",
2123
+ url: "",
2124
+ startBlock: 0n,
2125
+ endBlock: 0n
2126
+ };
2127
+ }
2128
+ });
2129
+ } catch (error) {
2130
+ throw new import_errors.BlockchainError(
2131
+ `Failed to get trusted servers with info: ${error instanceof Error ? error.message : "Unknown error"}`,
2132
+ error
2133
+ );
2134
+ }
2135
+ }
2136
+ /**
2137
+ * Gets server information for multiple servers efficiently.
2138
+ *
2139
+ * @remarks
2140
+ * This method uses multicall to fetch information for multiple servers in a single
2141
+ * blockchain call, improving performance when querying many servers. Failed lookups
2142
+ * are returned separately for error handling.
2143
+ *
2144
+ * @param serverIds - Array of numeric server IDs to query
2145
+ * @returns Promise resolving to batch result containing successful lookups and failed IDs
2146
+ * @throws {BlockchainError} When reading from contract fails or chain is unavailable
2147
+ * @example
2148
+ * ```typescript
2149
+ * const result = await vana.permissions.getServerInfoBatch([1, 2, 3, 999]);
2150
+ *
2151
+ * // Process successful lookups
2152
+ * result.servers.forEach((server, id) => {
2153
+ * console.log(`Server ${id}: ${server.url}`);
2154
+ * });
2155
+ *
2156
+ * // Handle failed lookups
2157
+ * if (result.failed.length > 0) {
2158
+ * console.log(`Failed to fetch: ${result.failed.join(', ')}`);
2159
+ * }
2160
+ * ```
2161
+ */
2162
+ async getServerInfoBatch(serverIds) {
2163
+ if (serverIds.length === 0) {
2164
+ return {
2165
+ servers: /* @__PURE__ */ new Map(),
2166
+ failed: []
2167
+ };
2168
+ }
2169
+ try {
2170
+ const chainId = await this.context.publicClient.getChainId();
2171
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
2172
+ chainId,
2173
+ "DataPortabilityServers"
2174
+ );
2175
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
2176
+ const serverInfoCalls = serverIds.map(
2177
+ (serverId) => ({
2178
+ address: DataPortabilityServersAddress,
2179
+ abi: DataPortabilityServersAbi,
2180
+ functionName: "servers",
2181
+ args: [BigInt(serverId)]
2182
+ })
2183
+ );
2184
+ const serverInfoResults = await (0, import_multicall.gasAwareMulticall)(this.context.publicClient, {
2185
+ contracts: serverInfoCalls,
2186
+ allowFailure: true
2187
+ });
2188
+ const results = serverInfoResults.map((result, index) => {
2189
+ const serverId = serverIds[index];
2190
+ if (result.status === "success" && result.result) {
2191
+ const serverInfo = result.result;
2192
+ const server = {
2193
+ id: Number(serverInfo.id),
2194
+ owner: serverInfo.owner,
2195
+ url: serverInfo.url,
2196
+ serverAddress: serverInfo.serverAddress,
2197
+ publicKey: serverInfo.publicKey
2198
+ };
2199
+ return { serverId, server, success: true };
2200
+ } else {
2201
+ return { serverId, server: null, success: false };
2202
+ }
2203
+ });
2204
+ const servers = /* @__PURE__ */ new Map();
2205
+ const failed = [];
2206
+ for (const result of results) {
2207
+ if (result.success && result.server) {
2208
+ servers.set(result.serverId, result.server);
2209
+ } else {
2210
+ failed.push(result.serverId);
2211
+ }
2212
+ }
2213
+ return { servers, failed };
2214
+ } catch (error) {
2215
+ throw new import_errors.BlockchainError(
2216
+ `Failed to batch get server info: ${error instanceof Error ? error.message : "Unknown error"}`,
2217
+ error
2218
+ );
2219
+ }
2220
+ }
2221
+ /**
2222
+ * Checks whether a specific server is trusted by a user.
2223
+ *
2224
+ * @remarks
2225
+ * This method queries the user's trusted server list and checks if the specified
2226
+ * server is present. Returns both the trust status and the index in the trust list
2227
+ * if trusted.
2228
+ *
2229
+ * @param serverId - Numeric server ID to check
2230
+ * @param userAddress - Optional user address (defaults to current user)
2231
+ * @returns Promise resolving to server trust status with trust index if applicable
2232
+ * @throws {BlockchainError} When reading from contract fails
2233
+ * @example
2234
+ * ```typescript
2235
+ * const status = await vana.permissions.checkServerTrustStatus(1);
2236
+ * if (status.isTrusted) {
2237
+ * console.log(`Server is trusted at index ${status.trustIndex}`);
2238
+ * } else {
2239
+ * console.log('Server is not trusted');
2240
+ * }
2241
+ * ```
2242
+ */
2243
+ async checkServerTrustStatus(serverId, userAddress) {
2244
+ try {
2245
+ const user = userAddress ?? this.context.userAddress;
2246
+ const trustedServers = await this.getTrustedServers(user);
2247
+ const trustIndex = trustedServers.findIndex(
2248
+ (server) => server === serverId
2249
+ );
2250
+ return {
2251
+ serverId,
2252
+ isTrusted: trustIndex !== -1,
2253
+ trustIndex: trustIndex !== -1 ? trustIndex : void 0
2254
+ };
2255
+ } catch (error) {
2256
+ throw new import_errors.BlockchainError(
2257
+ `Failed to check server trust status: ${error instanceof Error ? error.message : "Unknown error"}`,
2258
+ error
2259
+ );
2260
+ }
2261
+ }
2262
+ /**
2263
+ * Composes EIP-712 typed data for AddAndTrustServer.
2264
+ *
2265
+ * @remarks
2266
+ * Creates the complete typed data structure required for EIP-712 signature generation
2267
+ * when adding and trusting a new server in a single transaction.
2268
+ *
2269
+ * @param input - The add and trust server input data containing server details
2270
+ * @returns Promise resolving to the typed data structure for server add and trust
2271
+ */
2272
+ async composeAddAndTrustServerMessage(input) {
2273
+ const domain = await this.getServersDomain();
2274
+ console.debug(domain);
2275
+ return {
2276
+ domain,
2277
+ types: {
2278
+ AddServer: [
2279
+ { name: "nonce", type: "uint256" },
2280
+ { name: "serverAddress", type: "address" },
2281
+ { name: "publicKey", type: "string" },
2282
+ { name: "serverUrl", type: "string" }
2283
+ ]
2284
+ },
2285
+ primaryType: "AddServer",
2286
+ message: input
2287
+ };
2288
+ }
2289
+ /**
2290
+ * Composes EIP-712 typed data for TrustServer.
2291
+ *
2292
+ * @param input - The trust server input data containing server details
2293
+ * @returns Promise resolving to the typed data structure for server trust
2294
+ */
2295
+ async composeTrustServerMessage(input) {
2296
+ const domain = await this.getServersDomain();
2297
+ return {
2298
+ domain,
2299
+ types: {
2300
+ TrustServer: [
2301
+ { name: "nonce", type: "uint256" },
2302
+ { name: "serverId", type: "uint256" }
2303
+ ]
2304
+ },
2305
+ primaryType: "TrustServer",
2306
+ message: input
2307
+ };
2308
+ }
2309
+ /**
2310
+ * Composes EIP-712 typed data for UntrustServer.
2311
+ *
2312
+ * @param input - The untrust server input data containing server details
2313
+ * @returns Promise resolving to the typed data structure for server untrust
2314
+ */
2315
+ async composeUntrustServerMessage(input) {
2316
+ const domain = await this.getServersDomain();
2317
+ return {
2318
+ domain,
2319
+ types: {
2320
+ UntrustServer: [
2321
+ { name: "nonce", type: "uint256" },
2322
+ { name: "serverId", type: "uint256" }
2323
+ ]
2324
+ },
2325
+ primaryType: "UntrustServer",
2326
+ message: input
2327
+ };
2328
+ }
2329
+ /**
2330
+ * Gets the EIP-712 domain for DataPortabilityServers signatures.
2331
+ *
2332
+ * @returns Promise resolving to the EIP-712 domain configuration
2333
+ */
2334
+ async getServersDomain() {
2335
+ const chainId = await this.context.publicClient.getChainId();
2336
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
2337
+ chainId,
2338
+ "DataPortabilityServers"
2339
+ );
2340
+ return {
2341
+ name: "VanaDataPortabilityServers",
2342
+ version: "1",
2343
+ chainId,
2344
+ verifyingContract: DataPortabilityServersAddress
2345
+ };
2346
+ }
2347
+ /**
2348
+ * Submits an add and trust server transaction directly to the blockchain.
2349
+ *
2350
+ * @param addAndTrustServerInput - The add and trust server input data containing server details
2351
+ * @param signature - The cryptographic signature for the transaction
2352
+ * @returns Promise resolving to the transaction hash
2353
+ */
2354
+ async submitAddAndTrustServerTransaction(addAndTrustServerInput, signature) {
2355
+ this.assertWallet();
2356
+ const chainId = await this.context.walletClient.getChainId();
2357
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
2358
+ chainId,
2359
+ "DataPortabilityServers"
2360
+ );
2361
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
2362
+ console.debug("\u{1F50D} Transaction Debug Info:", {
2363
+ chainId,
2364
+ contractAddress: DataPortabilityServersAddress,
2365
+ input: {
2366
+ nonce: addAndTrustServerInput.nonce.toString(),
2367
+ serverAddress: addAndTrustServerInput.serverAddress,
2368
+ publicKey: addAndTrustServerInput.publicKey,
2369
+ serverUrl: addAndTrustServerInput.serverUrl
2370
+ },
2371
+ signature
2372
+ });
2373
+ const formattedSignature = (0, import_signatureFormatter.formatSignatureForContract)(signature);
2374
+ const txHash = await this.context.walletClient.writeContract({
2375
+ address: DataPortabilityServersAddress,
2376
+ abi: DataPortabilityServersAbi,
2377
+ functionName: "addAndTrustServerWithSignature",
2378
+ args: [
2379
+ {
2380
+ nonce: addAndTrustServerInput.nonce,
2381
+ serverAddress: addAndTrustServerInput.serverAddress,
2382
+ publicKey: addAndTrustServerInput.publicKey,
2383
+ serverUrl: addAndTrustServerInput.serverUrl
2384
+ },
2385
+ formattedSignature
2386
+ ],
2387
+ account: this.context.walletClient?.account ?? this.context.userAddress,
2388
+ chain: this.context.walletClient?.chain ?? null
2389
+ });
2390
+ return txHash;
2391
+ }
2392
+ /**
2393
+ * Submits a trust server transaction directly to the blockchain.
2394
+ *
2395
+ * @param trustServerInput - The trust server input data containing server details
2396
+ * @param signature - The cryptographic signature for the transaction
2397
+ * @returns Promise resolving to the transaction hash
2398
+ */
2399
+ async submitTrustServerTransaction(trustServerInput, signature, options) {
2400
+ this.assertWallet();
2401
+ const chainId = await this.context.walletClient.getChainId();
2402
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
2403
+ chainId,
2404
+ "DataPortabilityServers"
2405
+ );
2406
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
2407
+ const formattedSignature = (0, import_signatureFormatter.formatSignatureForContract)(signature);
2408
+ const txHash = await this.context.walletClient.writeContract({
2409
+ address: DataPortabilityServersAddress,
2410
+ abi: DataPortabilityServersAbi,
2411
+ functionName: "trustServerWithSignature",
2412
+ args: [
2413
+ {
2414
+ nonce: trustServerInput.nonce,
2415
+ serverId: BigInt(trustServerInput.serverId)
2416
+ },
2417
+ formattedSignature
2418
+ ],
2419
+ account: this.context.walletClient?.account ?? this.context.userAddress,
2420
+ chain: this.context.walletClient?.chain ?? null,
2421
+ ...this.spreadTransactionOptions(options)
2422
+ });
2423
+ return txHash;
2424
+ }
2425
+ /**
2426
+ * Submits a revoke transaction directly to the blockchain with signature.
2427
+ *
2428
+ * @param typedData - The EIP-712 typed data structure for the revoke operation
2429
+ * @param signature - The cryptographic signature authorizing the revoke
2430
+ * @returns Promise resolving to the transaction hash
2431
+ */
2432
+ async submitDirectRevokeTransaction(typedData, signature) {
2433
+ this.assertWallet();
2434
+ const chainId = await this.context.walletClient.getChainId();
2435
+ const DataPortabilityPermissionsAddress = (0, import_addresses.getContractAddress)(
2436
+ chainId,
2437
+ "DataPortabilityPermissions"
2438
+ );
2439
+ const DataPortabilityPermissionsAbi = (0, import_abi.getAbi)("DataPortabilityPermissions");
2440
+ const formattedSignature = (0, import_signatureFormatter.formatSignatureForContract)(signature);
2441
+ const txHash = await this.context.walletClient.writeContract({
2442
+ address: DataPortabilityPermissionsAddress,
2443
+ abi: DataPortabilityPermissionsAbi,
2444
+ functionName: "revokePermissionWithSignature",
2445
+ args: [typedData.message, formattedSignature],
2446
+ account: this.context.walletClient?.account ?? this.context.userAddress,
2447
+ chain: this.context.walletClient?.chain ?? null
2448
+ });
2449
+ return txHash;
2450
+ }
2451
+ /**
2452
+ * Submits an untrust server transaction with signature.
2453
+ *
2454
+ * @param typedData - The EIP-712 typed data structure for the untrust operation
2455
+ * @param signature - The cryptographic signature authorizing the untrust
2456
+ * @returns Promise resolving to the transaction hash
2457
+ */
2458
+ async submitSignedUntrustTransaction(typedData, signature, _options) {
2459
+ this.assertWallet();
2460
+ const chainId = await this.context.walletClient.getChainId();
2461
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
2462
+ chainId,
2463
+ "DataPortabilityServers"
2464
+ );
2465
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
2466
+ const formattedSignature = (0, import_signatureFormatter.formatSignatureForContract)(signature);
2467
+ const contractMessage = {
2468
+ nonce: typedData.message.nonce,
2469
+ serverId: BigInt(typedData.message.serverId)
2470
+ };
2471
+ const txHash = await this.context.walletClient.writeContract({
2472
+ address: DataPortabilityServersAddress,
2473
+ abi: DataPortabilityServersAbi,
2474
+ functionName: "untrustServerWithSignature",
2475
+ args: [contractMessage, formattedSignature],
2476
+ account: this.context.walletClient?.account ?? this.context.userAddress,
2477
+ chain: this.context.walletClient?.chain ?? null
2478
+ });
2479
+ return txHash;
2480
+ }
2481
+ // ===========================
2482
+ // GRANTEE METHODS
2483
+ // ===========================
2484
+ /**
2485
+ * Registers a new grantee in the DataPortabilityGrantees contract.
2486
+ *
2487
+ * A grantee is an entity (like an application) that can receive data permissions
2488
+ * from users. Once registered, users can grant the grantee access to their data.
2489
+ *
2490
+ * @param params - Parameters for registering the grantee
2491
+ * @param params.owner - The Ethereum address that will own this grantee registration
2492
+ * @param params.granteeAddress - The Ethereum address of the grantee (application)
2493
+ * @param params.publicKey - The public key used for data encryption/decryption (hex string)
2494
+ * @param options - Optional transaction options for gas parameters and timeout
2495
+ * @returns Promise resolving to the transaction hash
2496
+ * @throws {BlockchainError} When the grantee registration transaction fails
2497
+ * @throws {UserRejectedRequestError} When user rejects the transaction
2498
+ * @throws {ContractError} When grantee is already registered
2499
+ *
2500
+ * @example
2501
+ * ```typescript
2502
+ * const txHash = await vana.permissions.registerGrantee({
2503
+ * owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
2504
+ * granteeAddress: "0xApp1234567890123456789012345678901234567890",
2505
+ * publicKey: "0x1234567890abcdef..."
2506
+ * });
2507
+ * console.log(`Grantee registered in transaction: ${txHash}`);
2508
+ * ```
2509
+ */
2510
+ async submitRegisterGrantee(params, options) {
2511
+ this.assertWallet();
2512
+ const chainId = await this.context.walletClient.getChainId();
2513
+ const DataPortabilityGranteesAddress = (0, import_addresses.getContractAddress)(
2514
+ chainId,
2515
+ "DataPortabilityGrantees"
2516
+ );
2517
+ const DataPortabilityGranteesAbi = (0, import_abi.getAbi)("DataPortabilityGrantees");
2518
+ const ownerAddress = (0, import_viem.getAddress)(params.owner);
2519
+ const granteeAddress = (0, import_viem.getAddress)(params.granteeAddress);
2520
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
2521
+ const txHash = await this.context.walletClient.writeContract({
2522
+ address: DataPortabilityGranteesAddress,
2523
+ abi: DataPortabilityGranteesAbi,
2524
+ functionName: "registerGrantee",
2525
+ args: [ownerAddress, granteeAddress, params.publicKey],
2526
+ account,
2527
+ chain: this.context.walletClient?.chain ?? null,
2528
+ ...this.spreadTransactionOptions(options)
2529
+ });
2530
+ const { tx } = await import("../utils/transactionHelpers");
2531
+ return tx({
2532
+ hash: txHash,
2533
+ from: typeof account === "string" ? account : account.address,
2534
+ contract: "DataPortabilityGrantees",
2535
+ fn: "registerGrantee"
2536
+ });
2537
+ }
2538
+ // TODO: When DataPortabilityGrantees contract adds registerGranteeWithSignature function,
2539
+ // implement submitRegisterGranteeWithSignature and submitSignedRegisterGrantee methods
2540
+ // to support gasless transactions via relayer
2541
+ /**
2542
+ * Retrieves all registered grantees from the DataPortabilityGrantees contract.
2543
+ *
2544
+ * Returns a paginated list of all grantees (applications) that have been registered
2545
+ * in the system and can receive data permissions from users.
2546
+ *
2547
+ * @param options - Query options for pagination and filtering
2548
+ * @param options.limit - Maximum number of grantees to return (default: 50)
2549
+ * @param options.offset - Number of grantees to skip for pagination (default: 0)
2550
+ * @returns Promise resolving to paginated grantees with metadata
2551
+ * @throws {BlockchainError} When contract read operation fails
2552
+ * @throws {NetworkError} When unable to connect to the blockchain network
2553
+ *
2554
+ * @example
2555
+ * ```typescript
2556
+ * // Get first 10 grantees
2557
+ * const result = await vana.permissions.getGrantees({
2558
+ * limit: 10,
2559
+ * offset: 0
2560
+ * });
2561
+ *
2562
+ * console.log(`Found ${result.total} total grantees`);
2563
+ * result.grantees.forEach(grantee => {
2564
+ * console.log(`Grantee ${grantee.id}: ${grantee.granteeAddress}`);
2565
+ * });
2566
+ *
2567
+ * // Check if there are more results
2568
+ * if (result.hasMore) {
2569
+ * console.log('More grantees available');
2570
+ * }
2571
+ * ```
2572
+ */
2573
+ async getGrantees(options = {}) {
2574
+ const chainId = await this.context.publicClient.getChainId();
2575
+ const DataPortabilityGranteesAddress = (0, import_addresses.getContractAddress)(
2576
+ chainId,
2577
+ "DataPortabilityGrantees"
2578
+ );
2579
+ const DataPortabilityGranteesAbi = (0, import_abi.getAbi)("DataPortabilityGrantees");
2580
+ const totalCount = await this.context.publicClient.readContract({
2581
+ address: DataPortabilityGranteesAddress,
2582
+ abi: DataPortabilityGranteesAbi,
2583
+ functionName: "granteesCount"
2584
+ });
2585
+ const total = Number(totalCount);
2586
+ const limit = options.limit ?? 50;
2587
+ const offset = options.offset ?? 0;
2588
+ const grantees = [];
2589
+ const endIndex = Math.min(offset + limit, total);
2590
+ for (let i = offset; i < endIndex; i++) {
2591
+ try {
2592
+ const granteeInfo = await this.context.publicClient.readContract({
2593
+ address: DataPortabilityGranteesAddress,
2594
+ abi: DataPortabilityGranteesAbi,
2595
+ functionName: "grantees",
2596
+ args: [BigInt(i + 1)]
2597
+ // Grantee IDs are 1-indexed
2598
+ });
2599
+ grantees.push({
2600
+ id: i + 1,
2601
+ owner: granteeInfo.owner,
2602
+ address: granteeInfo.granteeAddress,
2603
+ publicKey: granteeInfo.publicKey,
2604
+ permissionIds: granteeInfo.permissionIds.map((id) => Number(id))
2605
+ });
2606
+ } catch (error) {
2607
+ console.warn(`Failed to fetch grantee ${i + 1}:`, error);
2608
+ }
2609
+ }
2610
+ return {
2611
+ grantees,
2612
+ total,
2613
+ offset,
2614
+ limit,
2615
+ hasMore: offset + limit < total
2616
+ };
2617
+ }
2618
+ /**
2619
+ * Retrieves a specific grantee by their Ethereum address from the DataPortabilityGrantees contract.
2620
+ *
2621
+ * Looks up a registered grantee (application) using their Ethereum address
2622
+ * and returns their complete registration information including permissions.
2623
+ *
2624
+ * @param granteeAddress - The Ethereum address of the grantee to look up
2625
+ * @returns Promise resolving to the grantee information, or null if not found
2626
+ * @throws {BlockchainError} When contract read operation fails
2627
+ * @throws {NetworkError} When unable to connect to the blockchain network
2628
+ *
2629
+ * @example
2630
+ * ```typescript
2631
+ * const granteeAddress = "0xApp1234567890123456789012345678901234567890";
2632
+ * const grantee = await vana.permissions.getGranteeByAddress(granteeAddress);
2633
+ *
2634
+ * if (grantee) {
2635
+ * console.log(`Found grantee ${grantee.id}`);
2636
+ * console.log(`Owner: ${grantee.owner}`);
2637
+ * console.log(`Public Key: ${grantee.publicKey}`);
2638
+ * console.log(`Permissions: ${grantee.permissionIds.join(', ')}`);
2639
+ * } else {
2640
+ * console.log('Grantee not found');
2641
+ * }
2642
+ * ```
2643
+ */
2644
+ async getGranteeByAddress(granteeAddress) {
2645
+ const chainId = await this.context.publicClient.getChainId();
2646
+ const DataPortabilityGranteesAddress = (0, import_addresses.getContractAddress)(
2647
+ chainId,
2648
+ "DataPortabilityGrantees"
2649
+ );
2650
+ const DataPortabilityGranteesAbi = (0, import_abi.getAbi)("DataPortabilityGrantees");
2651
+ try {
2652
+ const granteeInfo = await this.context.publicClient.readContract({
2653
+ address: DataPortabilityGranteesAddress,
2654
+ abi: DataPortabilityGranteesAbi,
2655
+ functionName: "granteeByAddress",
2656
+ args: [granteeAddress]
2657
+ });
2658
+ const granteeId = await this.context.publicClient.readContract({
2659
+ address: DataPortabilityGranteesAddress,
2660
+ abi: DataPortabilityGranteesAbi,
2661
+ functionName: "granteeAddressToId",
2662
+ args: [granteeAddress]
2663
+ });
2664
+ return {
2665
+ id: Number(granteeId),
2666
+ owner: granteeInfo.owner,
2667
+ address: granteeInfo.granteeAddress,
2668
+ publicKey: granteeInfo.publicKey,
2669
+ permissionIds: granteeInfo.permissionIds.map((id) => Number(id))
2670
+ };
2671
+ } catch (error) {
2672
+ console.warn(`Failed to fetch grantee ${granteeAddress}:`, error);
2673
+ return null;
2674
+ }
2675
+ }
2676
+ /**
2677
+ * Retrieves a specific grantee by their unique ID from the DataPortabilityGrantees contract.
2678
+ *
2679
+ * Looks up a registered grantee (application) using their numeric ID assigned during
2680
+ * registration and returns their complete information including permissions.
2681
+ *
2682
+ * @param granteeId - The unique numeric ID of the grantee (1-indexed)
2683
+ * @returns Promise resolving to the grantee information, or null if not found
2684
+ * @throws {BlockchainError} When contract read operation fails
2685
+ * @throws {NetworkError} When unable to connect to the blockchain network
2686
+ *
2687
+ * @example
2688
+ * ```typescript
2689
+ * const grantee = await vana.permissions.getGranteeById(1);
2690
+ *
2691
+ * if (grantee) {
2692
+ * console.log(`Grantee ID: ${grantee.id}`);
2693
+ * console.log(`Address: ${grantee.granteeAddress}`);
2694
+ * console.log(`Owner: ${grantee.owner}`);
2695
+ * console.log(`Total permissions: ${grantee.permissionIds.length}`);
2696
+ * } else {
2697
+ * console.log('Grantee with ID 1 not found');
2698
+ * }
2699
+ * ```
2700
+ */
2701
+ async getGranteeById(granteeId) {
2702
+ const chainId = await this.context.publicClient.getChainId();
2703
+ const DataPortabilityGranteesAddress = (0, import_addresses.getContractAddress)(
2704
+ chainId,
2705
+ "DataPortabilityGrantees"
2706
+ );
2707
+ const DataPortabilityGranteesAbi = (0, import_abi.getAbi)("DataPortabilityGrantees");
2708
+ try {
2709
+ const granteeInfo = await this.context.publicClient.readContract({
2710
+ address: DataPortabilityGranteesAddress,
2711
+ abi: DataPortabilityGranteesAbi,
2712
+ functionName: "grantees",
2713
+ args: [BigInt(granteeId)]
2714
+ });
2715
+ return {
2716
+ id: granteeId,
2717
+ owner: granteeInfo.owner,
2718
+ address: granteeInfo.granteeAddress,
2719
+ publicKey: granteeInfo.publicKey,
2720
+ permissionIds: granteeInfo.permissionIds.map((id) => Number(id))
2721
+ };
2722
+ } catch (error) {
2723
+ console.warn(`Failed to fetch grantee ${granteeId}:`, error);
2724
+ return null;
2725
+ }
2726
+ }
2727
+ // ===========================
2728
+ // DATA PORTABILITY SERVERS HELPER METHODS
2729
+ // ===========================
2730
+ /**
2731
+ * Get all trusted server IDs for a user
2732
+ *
2733
+ * @param userAddress - User address to query (defaults to current user)
2734
+ * @returns Promise resolving to array of server IDs
2735
+ */
2736
+ async getUserServerIds(userAddress) {
2737
+ try {
2738
+ const targetAddress = userAddress ?? this.context.userAddress;
2739
+ const chainId = await this.context.publicClient.getChainId();
2740
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
2741
+ chainId,
2742
+ "DataPortabilityServers"
2743
+ );
2744
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
2745
+ const serverIds = await this.context.publicClient.readContract({
2746
+ address: DataPortabilityServersAddress,
2747
+ abi: DataPortabilityServersAbi,
2748
+ functionName: "userServerIdsValues",
2749
+ args: [targetAddress]
2750
+ });
2751
+ return [...serverIds];
2752
+ } catch (error) {
2753
+ throw new import_errors.BlockchainError(
2754
+ `Failed to get user server IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
2755
+ error
2756
+ );
2757
+ }
2758
+ }
2759
+ /**
2760
+ * Get server ID at specific index for a user
2761
+ *
2762
+ * @param userAddress - User address to query
2763
+ * @param serverIndex - Index in the user's server list
2764
+ * @returns Promise resolving to server ID
2765
+ */
2766
+ async getUserServerIdAt(userAddress, serverIndex) {
2767
+ try {
2768
+ const chainId = await this.context.publicClient.getChainId();
2769
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
2770
+ chainId,
2771
+ "DataPortabilityServers"
2772
+ );
2773
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
2774
+ const serverId = await this.context.publicClient.readContract({
2775
+ address: DataPortabilityServersAddress,
2776
+ abi: DataPortabilityServersAbi,
2777
+ functionName: "userServerIdsAt",
2778
+ args: [userAddress, serverIndex]
2779
+ });
2780
+ return serverId;
2781
+ } catch (error) {
2782
+ throw new import_errors.BlockchainError(
2783
+ `Failed to get user server ID at index: ${error instanceof Error ? error.message : "Unknown error"}`,
2784
+ error
2785
+ );
2786
+ }
2787
+ }
2788
+ /**
2789
+ * Get the number of trusted servers for a user
2790
+ *
2791
+ * @param userAddress - User address to query (defaults to current user)
2792
+ * @returns Promise resolving to number of trusted servers
2793
+ */
2794
+ async getUserServerCount(userAddress) {
2795
+ try {
2796
+ const targetAddress = userAddress ?? this.context.userAddress;
2797
+ const chainId = await this.context.publicClient.getChainId();
2798
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
2799
+ chainId,
2800
+ "DataPortabilityServers"
2801
+ );
2802
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
2803
+ const count = await this.context.publicClient.readContract({
2804
+ address: DataPortabilityServersAddress,
2805
+ abi: DataPortabilityServersAbi,
2806
+ functionName: "userServerIdsLength",
2807
+ args: [targetAddress]
2808
+ });
2809
+ return count;
2810
+ } catch (error) {
2811
+ throw new import_errors.BlockchainError(
2812
+ `Failed to get user server count: ${error instanceof Error ? error.message : "Unknown error"}`,
2813
+ error
2814
+ );
2815
+ }
2816
+ }
2817
+ /**
2818
+ * Get detailed information about trusted servers for a user
2819
+ *
2820
+ * @param userAddress - User address to query (defaults to current user)
2821
+ * @returns Promise resolving to array of trusted server info
2822
+ */
2823
+ async getUserTrustedServers(userAddress) {
2824
+ try {
2825
+ const targetAddress = userAddress ?? this.context.userAddress;
2826
+ const chainId = await this.context.publicClient.getChainId();
2827
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
2828
+ chainId,
2829
+ "DataPortabilityServers"
2830
+ );
2831
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
2832
+ const servers = await this.context.publicClient.readContract({
2833
+ address: DataPortabilityServersAddress,
2834
+ abi: DataPortabilityServersAbi,
2835
+ functionName: "userServerValues",
2836
+ args: [targetAddress]
2837
+ });
2838
+ return [...servers];
2839
+ } catch (error) {
2840
+ throw new import_errors.BlockchainError(
2841
+ `Failed to get user trusted servers: ${error instanceof Error ? error.message : "Unknown error"}`,
2842
+ error
2843
+ );
2844
+ }
2845
+ }
2846
+ /**
2847
+ * Get trusted server info for a specific server ID and user
2848
+ *
2849
+ * @param userAddress - User address to query
2850
+ * @param serverId - Server ID to get info for
2851
+ * @returns Promise resolving to trusted server info
2852
+ */
2853
+ async getUserTrustedServer(userAddress, serverId) {
2854
+ try {
2855
+ const chainId = await this.context.publicClient.getChainId();
2856
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
2857
+ chainId,
2858
+ "DataPortabilityServers"
2859
+ );
2860
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
2861
+ const serverInfo = await this.context.publicClient.readContract({
2862
+ address: DataPortabilityServersAddress,
2863
+ abi: DataPortabilityServersAbi,
2864
+ functionName: "userServers",
2865
+ args: [userAddress, serverId]
2866
+ });
2867
+ return serverInfo;
2868
+ } catch (error) {
2869
+ throw new import_errors.BlockchainError(
2870
+ `Failed to get user trusted server: ${error instanceof Error ? error.message : "Unknown error"}`,
2871
+ error
2872
+ );
2873
+ }
2874
+ }
2875
+ /**
2876
+ * Get server information by server ID
2877
+ *
2878
+ * @param serverId - Server ID to get info for
2879
+ * @returns Promise resolving to server info
2880
+ */
2881
+ async getServerInfo(serverId) {
2882
+ try {
2883
+ const chainId = await this.context.publicClient.getChainId();
2884
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
2885
+ chainId,
2886
+ "DataPortabilityServers"
2887
+ );
2888
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
2889
+ const serverInfo = await this.context.publicClient.readContract({
2890
+ address: DataPortabilityServersAddress,
2891
+ abi: DataPortabilityServersAbi,
2892
+ functionName: "servers",
2893
+ args: [serverId]
2894
+ });
2895
+ return serverInfo;
2896
+ } catch (error) {
2897
+ throw new import_errors.BlockchainError(
2898
+ `Failed to get server info: ${error instanceof Error ? error.message : "Unknown error"}`,
2899
+ error
2900
+ );
2901
+ }
2902
+ }
2903
+ /**
2904
+ * Get server information by server address
2905
+ *
2906
+ * @param serverAddress - Server address to get info for
2907
+ * @returns Promise resolving to server info
2908
+ */
2909
+ async getServerInfoByAddress(serverAddress) {
2910
+ try {
2911
+ const chainId = await this.context.publicClient.getChainId();
2912
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
2913
+ chainId,
2914
+ "DataPortabilityServers"
2915
+ );
2916
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
2917
+ const serverInfo = await this.context.publicClient.readContract({
2918
+ address: DataPortabilityServersAddress,
2919
+ abi: DataPortabilityServersAbi,
2920
+ functionName: "serverByAddress",
2921
+ args: [serverAddress]
2922
+ });
2923
+ return serverInfo;
2924
+ } catch (error) {
2925
+ throw new import_errors.BlockchainError(
2926
+ `Failed to get server info by address: ${error instanceof Error ? error.message : "Unknown error"}`,
2927
+ error
2928
+ );
2929
+ }
2930
+ }
2931
+ // ===========================
2932
+ // DATA PORTABILITY PERMISSIONS HELPER METHODS
2933
+ // ===========================
2934
+ /**
2935
+ * Get all permission IDs for a user
2936
+ *
2937
+ * @param userAddress - User address to query (defaults to current user)
2938
+ * @returns Promise resolving to array of permission IDs
2939
+ */
2940
+ async getUserPermissionIds(userAddress) {
2941
+ try {
2942
+ const targetAddress = userAddress ?? this.context.userAddress;
2943
+ const chainId = await this.context.publicClient.getChainId();
2944
+ const DataPortabilityPermissionsAddress = (0, import_addresses.getContractAddress)(
2945
+ chainId,
2946
+ "DataPortabilityPermissions"
2947
+ );
2948
+ const DataPortabilityPermissionsAbi = (0, import_abi.getAbi)(
2949
+ "DataPortabilityPermissions"
2950
+ );
2951
+ const permissionIds = await this.context.publicClient.readContract({
2952
+ address: DataPortabilityPermissionsAddress,
2953
+ abi: DataPortabilityPermissionsAbi,
2954
+ functionName: "userPermissionIdsValues",
2955
+ args: [targetAddress]
2956
+ });
2957
+ return [...permissionIds];
2958
+ } catch (error) {
2959
+ throw new import_errors.BlockchainError(
2960
+ `Failed to get user permission IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
2961
+ error
2962
+ );
2963
+ }
2964
+ }
2965
+ /**
2966
+ * Get permission ID at specific index for a user
2967
+ *
2968
+ * @param userAddress - User address to query
2969
+ * @param permissionIndex - Index in the user's permission list
2970
+ * @returns Promise resolving to permission ID
2971
+ */
2972
+ async getUserPermissionIdAt(userAddress, permissionIndex) {
2973
+ try {
2974
+ const chainId = await this.context.publicClient.getChainId();
2975
+ const DataPortabilityPermissionsAddress = (0, import_addresses.getContractAddress)(
2976
+ chainId,
2977
+ "DataPortabilityPermissions"
2978
+ );
2979
+ const DataPortabilityPermissionsAbi = (0, import_abi.getAbi)(
2980
+ "DataPortabilityPermissions"
2981
+ );
2982
+ const permissionId = await this.context.publicClient.readContract({
2983
+ address: DataPortabilityPermissionsAddress,
2984
+ abi: DataPortabilityPermissionsAbi,
2985
+ functionName: "userPermissionIdsAt",
2986
+ args: [userAddress, permissionIndex]
2987
+ });
2988
+ return permissionId;
2989
+ } catch (error) {
2990
+ throw new import_errors.BlockchainError(
2991
+ `Failed to get user permission ID at index: ${error instanceof Error ? error.message : "Unknown error"}`,
2992
+ error
2993
+ );
2994
+ }
2995
+ }
2996
+ /**
2997
+ * Get the number of permissions for a user
2998
+ *
2999
+ * @param userAddress - User address to query (defaults to current user)
3000
+ * @returns Promise resolving to number of permissions
3001
+ */
3002
+ async getUserPermissionCount(userAddress) {
3003
+ try {
3004
+ const targetAddress = userAddress ?? this.context.userAddress;
3005
+ const chainId = await this.context.publicClient.getChainId();
3006
+ const DataPortabilityPermissionsAddress = (0, import_addresses.getContractAddress)(
3007
+ chainId,
3008
+ "DataPortabilityPermissions"
3009
+ );
3010
+ const DataPortabilityPermissionsAbi = (0, import_abi.getAbi)(
3011
+ "DataPortabilityPermissions"
3012
+ );
3013
+ const count = await this.context.publicClient.readContract({
3014
+ address: DataPortabilityPermissionsAddress,
3015
+ abi: DataPortabilityPermissionsAbi,
3016
+ functionName: "userPermissionIdsLength",
3017
+ args: [targetAddress]
3018
+ });
3019
+ return count;
3020
+ } catch (error) {
3021
+ throw new import_errors.BlockchainError(
3022
+ `Failed to get user permission count: ${error instanceof Error ? error.message : "Unknown error"}`,
3023
+ error
3024
+ );
3025
+ }
3026
+ }
3027
+ /**
3028
+ * Get detailed permission information by permission ID
3029
+ *
3030
+ * @param permissionId - Permission ID to get info for
3031
+ * @returns Promise resolving to permission info
3032
+ */
3033
+ async getPermissionInfo(permissionId) {
3034
+ try {
3035
+ const chainId = await this.context.publicClient.getChainId();
3036
+ const DataPortabilityPermissionsAddress = (0, import_addresses.getContractAddress)(
3037
+ chainId,
3038
+ "DataPortabilityPermissions"
3039
+ );
3040
+ const DataPortabilityPermissionsAbi = (0, import_abi.getAbi)(
3041
+ "DataPortabilityPermissions"
3042
+ );
3043
+ const permissionInfo = await this.context.publicClient.readContract({
3044
+ address: DataPortabilityPermissionsAddress,
3045
+ abi: DataPortabilityPermissionsAbi,
3046
+ functionName: "permissions",
3047
+ args: [permissionId]
3048
+ });
3049
+ return permissionInfo;
3050
+ } catch (error) {
3051
+ throw new import_errors.BlockchainError(
3052
+ `Failed to get permission info: ${error instanceof Error ? error.message : "Unknown error"}`,
3053
+ error
3054
+ );
3055
+ }
3056
+ }
3057
+ /**
3058
+ * Get all permission IDs for a specific file
3059
+ *
3060
+ * @param fileId - File ID to get permissions for
3061
+ * @returns Promise resolving to array of permission IDs
3062
+ */
3063
+ async getFilePermissionIds(fileId) {
3064
+ try {
3065
+ const chainId = await this.context.publicClient.getChainId();
3066
+ const DataPortabilityPermissionsAddress = (0, import_addresses.getContractAddress)(
3067
+ chainId,
3068
+ "DataPortabilityPermissions"
3069
+ );
3070
+ const DataPortabilityPermissionsAbi = (0, import_abi.getAbi)(
3071
+ "DataPortabilityPermissions"
3072
+ );
3073
+ const permissionIds = await this.context.publicClient.readContract({
3074
+ address: DataPortabilityPermissionsAddress,
3075
+ abi: DataPortabilityPermissionsAbi,
3076
+ functionName: "filePermissionIds",
3077
+ args: [fileId]
3078
+ });
3079
+ return [...permissionIds];
3080
+ } catch (error) {
3081
+ throw new import_errors.BlockchainError(
3082
+ `Failed to get file permission IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
3083
+ error
3084
+ );
3085
+ }
3086
+ }
3087
+ /**
3088
+ * Get all file IDs for a specific permission
3089
+ *
3090
+ * @param permissionId - Permission ID to get files for
3091
+ * @returns Promise resolving to array of file IDs
3092
+ */
3093
+ async getPermissionFileIds(permissionId) {
3094
+ try {
3095
+ const chainId = await this.context.publicClient.getChainId();
3096
+ const DataPortabilityPermissionsAddress = (0, import_addresses.getContractAddress)(
3097
+ chainId,
3098
+ "DataPortabilityPermissions"
3099
+ );
3100
+ const DataPortabilityPermissionsAbi = (0, import_abi.getAbi)(
3101
+ "DataPortabilityPermissions"
3102
+ );
3103
+ const fileIds = await this.context.publicClient.readContract({
3104
+ address: DataPortabilityPermissionsAddress,
3105
+ abi: DataPortabilityPermissionsAbi,
3106
+ functionName: "permissionFileIds",
3107
+ args: [permissionId]
3108
+ });
3109
+ return [...fileIds];
3110
+ } catch (error) {
3111
+ throw new import_errors.BlockchainError(
3112
+ `Failed to get permission file IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
3113
+ error
3114
+ );
3115
+ }
3116
+ }
3117
+ /**
3118
+ * Get all permissions for a specific file (alias for getFilePermissionIds)
3119
+ *
3120
+ * @param fileId - File ID to get permissions for
3121
+ * @returns Promise resolving to array of permission IDs
3122
+ */
3123
+ async getFilePermissions(fileId) {
3124
+ const chainId = await this.context.publicClient.getChainId();
3125
+ const DataPortabilityPermissionsAddress = (0, import_addresses.getContractAddress)(
3126
+ chainId,
3127
+ "DataPortabilityPermissions"
3128
+ );
3129
+ const DataPortabilityPermissionsAbi = (0, import_abi.getAbi)("DataPortabilityPermissions");
3130
+ const permissions = await this.context.publicClient.readContract({
3131
+ address: DataPortabilityPermissionsAddress,
3132
+ abi: DataPortabilityPermissionsAbi,
3133
+ functionName: "filePermissions",
3134
+ args: [fileId]
3135
+ });
3136
+ return [...permissions];
3137
+ }
3138
+ // ===========================
3139
+ // DATA PORTABILITY GRANTEES HELPER METHODS
3140
+ // ===========================
3141
+ /**
3142
+ * Get grantee information by grantee ID
3143
+ *
3144
+ * @param granteeId - Grantee ID to get info for
3145
+ * @returns Promise resolving to grantee info
3146
+ */
3147
+ async getGranteeInfo(granteeId) {
3148
+ try {
3149
+ const chainId = await this.context.publicClient.getChainId();
3150
+ const DataPortabilityGranteesAddress = (0, import_addresses.getContractAddress)(
3151
+ chainId,
3152
+ "DataPortabilityGrantees"
3153
+ );
3154
+ const DataPortabilityGranteesAbi = (0, import_abi.getAbi)("DataPortabilityGrantees");
3155
+ const granteeInfo = await this.context.publicClient.readContract({
3156
+ address: DataPortabilityGranteesAddress,
3157
+ abi: DataPortabilityGranteesAbi,
3158
+ functionName: "granteeInfo",
3159
+ args: [granteeId]
3160
+ });
3161
+ return granteeInfo;
3162
+ } catch (error) {
3163
+ throw new import_errors.BlockchainError(
3164
+ `Failed to get grantee info: ${error instanceof Error ? error.message : "Unknown error"}`,
3165
+ error
3166
+ );
3167
+ }
3168
+ }
3169
+ /**
3170
+ * Get grantee information by grantee address
3171
+ *
3172
+ * @param granteeAddress - Grantee address to get info for
3173
+ * @returns Promise resolving to grantee info
3174
+ */
3175
+ async getGranteeInfoByAddress(granteeAddress) {
3176
+ try {
3177
+ const chainId = await this.context.publicClient.getChainId();
3178
+ const DataPortabilityGranteesAddress = (0, import_addresses.getContractAddress)(
3179
+ chainId,
3180
+ "DataPortabilityGrantees"
3181
+ );
3182
+ const DataPortabilityGranteesAbi = (0, import_abi.getAbi)("DataPortabilityGrantees");
3183
+ const granteeInfo = await this.context.publicClient.readContract({
3184
+ address: DataPortabilityGranteesAddress,
3185
+ abi: DataPortabilityGranteesAbi,
3186
+ functionName: "granteeByAddress",
3187
+ args: [granteeAddress]
3188
+ });
3189
+ return granteeInfo;
3190
+ } catch (error) {
3191
+ throw new import_errors.BlockchainError(
3192
+ `Failed to get grantee info by address: ${error instanceof Error ? error.message : "Unknown error"}`,
3193
+ error
3194
+ );
3195
+ }
3196
+ }
3197
+ /**
3198
+ * Get all permission IDs for a specific grantee
3199
+ *
3200
+ * @param granteeId - Grantee ID to get permissions for
3201
+ * @returns Promise resolving to array of permission IDs
3202
+ */
3203
+ async getGranteePermissionIds(granteeId) {
3204
+ try {
3205
+ const chainId = await this.context.publicClient.getChainId();
3206
+ const DataPortabilityGranteesAddress = (0, import_addresses.getContractAddress)(
3207
+ chainId,
3208
+ "DataPortabilityGrantees"
3209
+ );
3210
+ const DataPortabilityGranteesAbi = (0, import_abi.getAbi)("DataPortabilityGrantees");
3211
+ const permissionIds = await this.context.publicClient.readContract({
3212
+ address: DataPortabilityGranteesAddress,
3213
+ abi: DataPortabilityGranteesAbi,
3214
+ functionName: "granteePermissionIds",
3215
+ args: [granteeId]
3216
+ });
3217
+ return [...permissionIds];
3218
+ } catch (error) {
3219
+ throw new import_errors.BlockchainError(
3220
+ `Failed to get grantee permission IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
3221
+ error
3222
+ );
3223
+ }
3224
+ }
3225
+ /**
3226
+ * Get all permissions for a specific grantee (alias for getGranteePermissionIds)
3227
+ *
3228
+ * @param granteeId - Grantee ID to get permissions for
3229
+ * @returns Promise resolving to array of permission IDs
3230
+ */
3231
+ async getGranteePermissions(granteeId) {
3232
+ try {
3233
+ const chainId = await this.context.publicClient.getChainId();
3234
+ const DataPortabilityGranteesAddress = (0, import_addresses.getContractAddress)(
3235
+ chainId,
3236
+ "DataPortabilityGrantees"
3237
+ );
3238
+ const DataPortabilityGranteesAbi = (0, import_abi.getAbi)("DataPortabilityGrantees");
3239
+ const permissions = await this.context.publicClient.readContract({
3240
+ address: DataPortabilityGranteesAddress,
3241
+ abi: DataPortabilityGranteesAbi,
3242
+ functionName: "granteePermissions",
3243
+ args: [granteeId]
3244
+ });
3245
+ return [...permissions];
3246
+ } catch (error) {
3247
+ throw new import_errors.BlockchainError(
3248
+ `Failed to get grantee permissions: ${error instanceof Error ? error.message : "Unknown error"}`,
3249
+ error
3250
+ );
3251
+ }
3252
+ }
3253
+ // ===== DataPortabilityServersImplementation Methods =====
3254
+ /**
3255
+ * Get all server IDs for a user
3256
+ *
3257
+ * @param userAddress - User address to get server IDs for
3258
+ * @returns Promise resolving to array of server IDs
3259
+ */
3260
+ async getUserServerIdsValues(userAddress) {
3261
+ try {
3262
+ const chainId = await this.context.publicClient.getChainId();
3263
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
3264
+ chainId,
3265
+ "DataPortabilityServers"
3266
+ );
3267
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
3268
+ const serverIds = await this.context.publicClient.readContract({
3269
+ address: DataPortabilityServersAddress,
3270
+ abi: DataPortabilityServersAbi,
3271
+ functionName: "userServerIdsValues",
3272
+ args: [userAddress]
3273
+ });
3274
+ return [...serverIds];
3275
+ } catch (error) {
3276
+ throw new import_errors.BlockchainError(
3277
+ `Failed to get user server IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
3278
+ error
3279
+ );
3280
+ }
3281
+ }
3282
+ /**
3283
+ * Get server ID at specific index for a user
3284
+ *
3285
+ * @param userAddress - User address
3286
+ * @param serverIndex - Index of the server ID
3287
+ * @returns Promise resolving to server ID
3288
+ */
3289
+ async getUserServerIdsAt(userAddress, serverIndex) {
3290
+ try {
3291
+ const chainId = await this.context.publicClient.getChainId();
3292
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
3293
+ chainId,
3294
+ "DataPortabilityServers"
3295
+ );
3296
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
3297
+ const serverId = await this.context.publicClient.readContract({
3298
+ address: DataPortabilityServersAddress,
3299
+ abi: DataPortabilityServersAbi,
3300
+ functionName: "userServerIdsAt",
3301
+ args: [userAddress, serverIndex]
3302
+ });
3303
+ return serverId;
3304
+ } catch (error) {
3305
+ throw new import_errors.BlockchainError(
3306
+ `Failed to get user server ID at index: ${error instanceof Error ? error.message : "Unknown error"}`,
3307
+ error
3308
+ );
3309
+ }
3310
+ }
3311
+ /**
3312
+ * Get the number of servers a user has
3313
+ *
3314
+ * @param userAddress - User address
3315
+ * @returns Promise resolving to number of servers
3316
+ */
3317
+ async getUserServerIdsLength(userAddress) {
3318
+ try {
3319
+ const chainId = await this.context.publicClient.getChainId();
3320
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
3321
+ chainId,
3322
+ "DataPortabilityServers"
3323
+ );
3324
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
3325
+ const length = await this.context.publicClient.readContract({
3326
+ address: DataPortabilityServersAddress,
3327
+ abi: DataPortabilityServersAbi,
3328
+ functionName: "userServerIdsLength",
3329
+ args: [userAddress]
3330
+ });
3331
+ return length;
3332
+ } catch (error) {
3333
+ throw new import_errors.BlockchainError(
3334
+ `Failed to get user server IDs length: ${error instanceof Error ? error.message : "Unknown error"}`,
3335
+ error
3336
+ );
3337
+ }
3338
+ }
3339
+ /**
3340
+ * Get trusted server info for a specific user and server ID
3341
+ *
3342
+ * @param userAddress - User address
3343
+ * @param serverId - Server ID
3344
+ * @returns Promise resolving to trusted server info
3345
+ */
3346
+ async getUserServers(userAddress, serverId) {
3347
+ try {
3348
+ const chainId = await this.context.publicClient.getChainId();
3349
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
3350
+ chainId,
3351
+ "DataPortabilityServers"
3352
+ );
3353
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
3354
+ const serverInfo = await this.context.publicClient.readContract({
3355
+ address: DataPortabilityServersAddress,
3356
+ abi: DataPortabilityServersAbi,
3357
+ functionName: "userServers",
3358
+ args: [userAddress, serverId]
3359
+ });
3360
+ return {
3361
+ id: serverInfo.id,
3362
+ owner: serverInfo.owner,
3363
+ serverAddress: serverInfo.serverAddress,
3364
+ publicKey: serverInfo.publicKey,
3365
+ url: serverInfo.url,
3366
+ startBlock: serverInfo.startBlock,
3367
+ endBlock: serverInfo.endBlock
3368
+ };
3369
+ } catch (error) {
3370
+ throw new import_errors.BlockchainError(
3371
+ `Failed to get user server info: ${error instanceof Error ? error.message : "Unknown error"}`,
3372
+ error
3373
+ );
3374
+ }
3375
+ }
3376
+ /**
3377
+ * Get server info by server ID
3378
+ *
3379
+ * @param serverId - Server ID
3380
+ * @returns Promise resolving to server info
3381
+ */
3382
+ async getServers(serverId) {
3383
+ try {
3384
+ const chainId = await this.context.publicClient.getChainId();
3385
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
3386
+ chainId,
3387
+ "DataPortabilityServers"
3388
+ );
3389
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
3390
+ const serverInfo = await this.context.publicClient.readContract({
3391
+ address: DataPortabilityServersAddress,
3392
+ abi: DataPortabilityServersAbi,
3393
+ functionName: "servers",
3394
+ args: [serverId]
3395
+ });
3396
+ return {
3397
+ id: serverInfo.id,
3398
+ owner: serverInfo.owner,
3399
+ serverAddress: serverInfo.serverAddress,
3400
+ publicKey: serverInfo.publicKey,
3401
+ url: serverInfo.url
3402
+ };
3403
+ } catch (error) {
3404
+ throw new import_errors.BlockchainError(
3405
+ `Failed to get server info: ${error instanceof Error ? error.message : "Unknown error"}`,
3406
+ error
3407
+ );
3408
+ }
3409
+ }
3410
+ /**
3411
+ * Get user info including nonce and trusted server IDs
3412
+ *
3413
+ * @param userAddress - User address
3414
+ * @returns Promise resolving to user info
3415
+ */
3416
+ async getUsers(userAddress) {
3417
+ try {
3418
+ const chainId = await this.context.publicClient.getChainId();
3419
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
3420
+ chainId,
3421
+ "DataPortabilityServers"
3422
+ );
3423
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
3424
+ const userInfo = await this.context.publicClient.readContract({
3425
+ address: DataPortabilityServersAddress,
3426
+ abi: DataPortabilityServersAbi,
3427
+ functionName: "users",
3428
+ args: [userAddress]
3429
+ });
3430
+ return {
3431
+ nonce: userInfo[0],
3432
+ trustedServerIds: [...userInfo[1]]
3433
+ };
3434
+ } catch (error) {
3435
+ throw new import_errors.BlockchainError(
3436
+ `Failed to get user info: ${error instanceof Error ? error.message : "Unknown error"}`,
3437
+ error
3438
+ );
3439
+ }
3440
+ }
3441
+ /**
3442
+ * Update server URL
3443
+ *
3444
+ * @param serverId - Server ID to update
3445
+ * @param url - New URL for the server
3446
+ * @param options - Optional transaction options for gas parameters and timeout
3447
+ * @returns Promise resolving to transaction hash
3448
+ */
3449
+ async submitUpdateServer(serverId, url, options) {
3450
+ this.assertWallet();
3451
+ try {
3452
+ const chainId = await this.context.walletClient.getChainId();
3453
+ const DataPortabilityServersAddress = (0, import_addresses.getContractAddress)(
3454
+ chainId,
3455
+ "DataPortabilityServers"
3456
+ );
3457
+ const DataPortabilityServersAbi = (0, import_abi.getAbi)("DataPortabilityServers");
3458
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
3459
+ const hash = await this.context.walletClient.writeContract({
3460
+ address: DataPortabilityServersAddress,
3461
+ abi: DataPortabilityServersAbi,
3462
+ functionName: "updateServer",
3463
+ args: [serverId, url],
3464
+ chain: this.context.walletClient?.chain,
3465
+ account,
3466
+ ...options?.gas && { gas: options.gas },
3467
+ ...options?.nonce && { nonce: options.nonce },
3468
+ // Use EIP-1559 if available, otherwise fall back to legacy gasPrice
3469
+ ...options?.maxFeePerGas || options?.maxPriorityFeePerGas ? {
3470
+ ...options.maxFeePerGas && {
3471
+ maxFeePerGas: options.maxFeePerGas
3472
+ },
3473
+ ...options.maxPriorityFeePerGas && {
3474
+ maxPriorityFeePerGas: options.maxPriorityFeePerGas
3475
+ }
3476
+ } : options?.gasPrice && { gasPrice: options.gasPrice }
3477
+ });
3478
+ const { tx } = await import("../utils/transactionHelpers");
3479
+ return tx({
3480
+ hash,
3481
+ from: typeof account === "string" ? account : account.address,
3482
+ contract: "DataPortabilityServers",
3483
+ fn: "updateServer"
3484
+ });
3485
+ } catch (error) {
3486
+ throw new import_errors.BlockchainError(
3487
+ `Failed to update server: ${error instanceof Error ? error.message : "Unknown error"}`,
3488
+ error
3489
+ );
3490
+ }
3491
+ }
3492
+ // ===== DataPortabilityPermissionsImplementation Methods =====
3493
+ /**
3494
+ * Get all permission IDs for a user
3495
+ *
3496
+ * @param userAddress - User address to get permission IDs for
3497
+ * @returns Promise resolving to array of permission IDs
3498
+ */
3499
+ async getUserPermissionIdsValues(userAddress) {
3500
+ try {
3501
+ const chainId = await this.context.publicClient.getChainId();
3502
+ const DataPortabilityPermissionsAddress = (0, import_addresses.getContractAddress)(
3503
+ chainId,
3504
+ "DataPortabilityPermissions"
3505
+ );
3506
+ const DataPortabilityPermissionsAbi = (0, import_abi.getAbi)(
3507
+ "DataPortabilityPermissions"
3508
+ );
3509
+ const permissionIds = await this.context.publicClient.readContract({
3510
+ address: DataPortabilityPermissionsAddress,
3511
+ abi: DataPortabilityPermissionsAbi,
3512
+ functionName: "userPermissionIdsValues",
3513
+ args: [userAddress]
3514
+ });
3515
+ return [...permissionIds];
3516
+ } catch (error) {
3517
+ throw new import_errors.BlockchainError(
3518
+ `Failed to get user permission IDs: ${error instanceof Error ? error.message : "Unknown error"}`,
3519
+ error
3520
+ );
3521
+ }
3522
+ }
3523
+ /**
3524
+ * Get permission ID at specific index for a user
3525
+ *
3526
+ * @param userAddress - User address
3527
+ * @param permissionIndex - Index of the permission ID
3528
+ * @returns Promise resolving to permission ID
3529
+ */
3530
+ async getUserPermissionIdsAt(userAddress, permissionIndex) {
3531
+ try {
3532
+ const chainId = await this.context.publicClient.getChainId();
3533
+ const DataPortabilityPermissionsAddress = (0, import_addresses.getContractAddress)(
3534
+ chainId,
3535
+ "DataPortabilityPermissions"
3536
+ );
3537
+ const DataPortabilityPermissionsAbi = (0, import_abi.getAbi)(
3538
+ "DataPortabilityPermissions"
3539
+ );
3540
+ const permissionId = await this.context.publicClient.readContract({
3541
+ address: DataPortabilityPermissionsAddress,
3542
+ abi: DataPortabilityPermissionsAbi,
3543
+ functionName: "userPermissionIdsAt",
3544
+ args: [userAddress, permissionIndex]
3545
+ });
3546
+ return permissionId;
3547
+ } catch (error) {
3548
+ throw new import_errors.BlockchainError(
3549
+ `Failed to get user permission ID at index: ${error instanceof Error ? error.message : "Unknown error"}`,
3550
+ error
3551
+ );
3552
+ }
3553
+ }
3554
+ /**
3555
+ * Get the number of permissions a user has
3556
+ *
3557
+ * @param userAddress - User address
3558
+ * @returns Promise resolving to number of permissions
3559
+ */
3560
+ async getUserPermissionIdsLength(userAddress) {
3561
+ try {
3562
+ const chainId = await this.context.publicClient.getChainId();
3563
+ const DataPortabilityPermissionsAddress = (0, import_addresses.getContractAddress)(
3564
+ chainId,
3565
+ "DataPortabilityPermissions"
3566
+ );
3567
+ const DataPortabilityPermissionsAbi = (0, import_abi.getAbi)(
3568
+ "DataPortabilityPermissions"
3569
+ );
3570
+ const length = await this.context.publicClient.readContract({
3571
+ address: DataPortabilityPermissionsAddress,
3572
+ abi: DataPortabilityPermissionsAbi,
3573
+ functionName: "userPermissionIdsLength",
3574
+ args: [userAddress]
3575
+ });
3576
+ return length;
3577
+ } catch (error) {
3578
+ throw new import_errors.BlockchainError(
3579
+ `Failed to get user permission IDs length: ${error instanceof Error ? error.message : "Unknown error"}`,
3580
+ error
3581
+ );
3582
+ }
3583
+ }
3584
+ /**
3585
+ * Get permission info by permission ID
3586
+ *
3587
+ * @param permissionId - Permission ID
3588
+ * @returns Promise resolving to permission info
3589
+ */
3590
+ async getPermissions(permissionId) {
3591
+ try {
3592
+ const chainId = await this.context.publicClient.getChainId();
3593
+ const DataPortabilityPermissionsAddress = (0, import_addresses.getContractAddress)(
3594
+ chainId,
3595
+ "DataPortabilityPermissions"
3596
+ );
3597
+ const DataPortabilityPermissionsAbi = (0, import_abi.getAbi)(
3598
+ "DataPortabilityPermissions"
3599
+ );
3600
+ const permissionInfo = await this.context.publicClient.readContract({
3601
+ address: DataPortabilityPermissionsAddress,
3602
+ abi: DataPortabilityPermissionsAbi,
3603
+ functionName: "permissions",
3604
+ args: [permissionId]
3605
+ });
3606
+ return {
3607
+ id: permissionInfo.id,
3608
+ grantor: permissionInfo.grantor,
3609
+ nonce: permissionInfo.nonce,
3610
+ granteeId: permissionInfo.granteeId,
3611
+ grant: permissionInfo.grant,
3612
+ startBlock: permissionInfo.startBlock,
3613
+ endBlock: permissionInfo.endBlock,
3614
+ fileIds: [...permissionInfo.fileIds]
3615
+ };
3616
+ } catch (error) {
3617
+ throw new import_errors.BlockchainError(
3618
+ `Failed to get permission info: ${error instanceof Error ? error.message : "Unknown error"}`,
3619
+ error
3620
+ );
3621
+ }
3622
+ }
3623
+ /**
3624
+ * Submit permission with signature to the blockchain (supports gasless transactions)
3625
+ *
3626
+ * @param params - Parameters for adding permission
3627
+ * @returns Promise resolving to transaction hash
3628
+ * @throws {RelayerError} When gasless transaction submission fails
3629
+ * @throws {SignatureError} When user rejects the signature request
3630
+ * @throws {BlockchainError} When permission addition fails
3631
+ * @throws {NetworkError} When network communication fails
3632
+ */
3633
+ async submitAddPermission(params) {
3634
+ this.assertWallet();
3635
+ try {
3636
+ const nonce = await this.getPermissionsUserNonce();
3637
+ const addPermissionInput = {
3638
+ nonce,
3639
+ granteeId: params.granteeId,
3640
+ grant: params.grant,
3641
+ fileUrls: params.fileUrls,
3642
+ schemaIds: params.schemaIds,
3643
+ serverAddress: params.serverAddress,
3644
+ serverUrl: params.serverUrl,
3645
+ serverPublicKey: params.serverPublicKey,
3646
+ filePermissions: params.filePermissions
3647
+ };
3648
+ const typedData = await this.composeServerFilesAndPermissionMessage(addPermissionInput);
3649
+ const signature = await this.signTypedData(typedData);
3650
+ return await this.submitSignedAddPermission(typedData, signature);
3651
+ } catch (error) {
3652
+ if (error instanceof import_errors.RelayerError || error instanceof import_errors.UserRejectedRequestError || error instanceof import_errors.SerializationError || error instanceof import_errors.SignatureError || error instanceof import_errors.NetworkError || error instanceof import_errors.NonceError) {
3653
+ throw error;
3654
+ }
3655
+ throw new import_errors.BlockchainError(
3656
+ `Failed to add permission: ${error instanceof Error ? error.message : "Unknown error"}`,
3657
+ error
3658
+ );
3659
+ }
3660
+ }
3661
+ /**
3662
+ * Submits an already-signed add permission transaction to the blockchain.
3663
+ * This method supports both relayer-based gasless transactions and direct transactions.
3664
+ *
3665
+ * @param typedData - The EIP-712 typed data for AddPermission
3666
+ * @param signature - The user's signature
3667
+ * @returns Promise resolving to TransactionResult with PermissionGrantResult event data
3668
+ * @throws {RelayerError} When gasless transaction submission fails
3669
+ * @throws {BlockchainError} When permission addition fails
3670
+ * @throws {NetworkError} When network communication fails
3671
+ */
3672
+ async submitSignedAddPermission(typedData, signature, options) {
3673
+ this.assertWallet();
3674
+ try {
3675
+ let hash;
3676
+ if (this.context.relayer) {
3677
+ const request = {
3678
+ type: "signed",
3679
+ operation: "submitAddPermission",
3680
+ typedData,
3681
+ signature
3682
+ };
3683
+ const response = await this.context.relayer(request);
3684
+ if (response.type === "error") {
3685
+ throw new import_errors.RelayerError(response.error);
3686
+ }
3687
+ if (response.type === "signed") {
3688
+ hash = response.hash;
3689
+ } else {
3690
+ throw new Error("Unexpected response type from relayer");
3691
+ }
3692
+ } else {
3693
+ hash = await this.submitDirectAddPermissionTransaction(
3694
+ typedData,
3695
+ signature,
3696
+ options
3697
+ );
3698
+ }
3699
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
3700
+ const { tx } = await import("../utils/transactionHelpers");
3701
+ return tx({
3702
+ hash,
3703
+ from: typeof account === "string" ? account : account.address,
3704
+ contract: "DataPortabilityPermissions",
3705
+ fn: "addPermission"
3706
+ });
3707
+ } catch (error) {
3708
+ if (error instanceof import_errors.RelayerError || error instanceof import_errors.NetworkError || error instanceof import_errors.UserRejectedRequestError || error instanceof import_errors.SignatureError || error instanceof import_errors.NonceError) {
3709
+ throw error;
3710
+ }
3711
+ throw new import_errors.BlockchainError(
3712
+ `Add permission submission failed: ${error instanceof Error ? error.message : "Unknown error"}`,
3713
+ error
3714
+ );
3715
+ }
3716
+ }
3717
+ /**
3718
+ * Submits server files and permissions with signature to the blockchain, supporting schema validation and gasless transactions.
3719
+ *
3720
+ * @remarks
3721
+ * This method validates files against their specified schemas before submission.
3722
+ * Schema validation ensures data conforms to expected formats before on-chain registration.
3723
+ * Files with schemaId = 0 bypass validation. The method supports atomic batch operations
3724
+ * where all files and permissions are registered in a single transaction.
3725
+ *
3726
+ * @param params - Parameters for adding server files and permissions
3727
+ * @param params.granteeId - The ID of the permission grantee
3728
+ * @param params.grant - Grant URL containing permission parameters (typically IPFS)
3729
+ * @param params.fileUrls - Array of file URLs to register
3730
+ * @param params.schemaIds - Schema IDs for each file. Use 0 for files without schema validation.
3731
+ * Array length must match fileUrls length.
3732
+ * @param params.serverAddress - Server wallet address for decryption permissions
3733
+ * @param params.serverUrl - Server endpoint URL
3734
+ * @param params.serverPublicKey - Server's public key for encryption.
3735
+ * Obtain via `vana.server.getIdentity(userAddress).publicKey`.
3736
+ * @param params.filePermissions - Nested array of permissions for each file
3737
+ * @param options - Optional transaction options for gas parameters and timeout.
3738
+ * Note: These options are only applied for direct blockchain transactions.
3739
+ * When using relayer callbacks (gasless transactions), these options are ignored.
3740
+ * @returns TransactionResult with immediate hash access and optional event data
3741
+ * @throws {Error} When schemaIds array length doesn't match fileUrls array length
3742
+ * @throws {SchemaValidationError} When file data doesn't match the specified schema.
3743
+ * Verify data structure matches schema definition from `vana.schemas.get(schemaId)`.
3744
+ * @throws {RelayerError} When gasless transaction submission fails.
3745
+ * Retry without relayer configuration to submit direct transaction.
3746
+ * @throws {SignatureError} When user rejects the signature request
3747
+ * @throws {BlockchainError} When server files and permissions addition fails
3748
+ * @throws {NetworkError} When network communication fails.
3749
+ * Check network connection or configure alternative gateways.
3750
+ *
3751
+ * @example
3752
+ * ```typescript
3753
+ * // Submit with custom gas parameters and timeout
3754
+ * const result = await vana.permissions.submitAddServerFilesAndPermissions({
3755
+ * granteeId: BigInt(1),
3756
+ * grant: "ipfs://QmXxx...",
3757
+ * fileUrls: ["https://storage.example.com/data.json"],
3758
+ * schemaIds: [123], // LinkedIn profile schema ID
3759
+ * serverAddress: "0x742d35Cc6634C0532925a3b844Bc9e7595f0b0Bb",
3760
+ * serverUrl: "https://server.example.com",
3761
+ * serverPublicKey: serverInfo.publicKey,
3762
+ * filePermissions: [[{
3763
+ * account: "0x742d35Cc6634C0532925a3b844Bc9e7595f0b0Bb",
3764
+ * key: encryptedKey
3765
+ * }]]
3766
+ * }, {
3767
+ * maxFeePerGas: 100n * 10n ** 9n, // 100 gwei
3768
+ * maxPriorityFeePerGas: 2n * 10n ** 9n, // 2 gwei tip
3769
+ * });
3770
+ *
3771
+ * // Wait for confirmation with custom timeout
3772
+ * const receipt = await vana.waitForTransactionReceipt(result, {
3773
+ * timeout: 180000 // 3 minutes
3774
+ * });
3775
+ * console.log(`Transaction confirmed: ${receipt.transactionHash}`);
3776
+ * ```
3777
+ */
3778
+ async submitAddServerFilesAndPermissions(params, options) {
3779
+ this.assertWallet();
3780
+ try {
3781
+ if (params.schemaIds.length !== params.fileUrls.length) {
3782
+ throw new Error(
3783
+ `schemaIds array length (${params.schemaIds.length}) must match fileUrls array length (${params.fileUrls.length})`
3784
+ );
3785
+ }
3786
+ const nonce = await this.getPermissionsUserNonce();
3787
+ const serverFilesAndPermissionInput = {
3788
+ nonce,
3789
+ granteeId: params.granteeId,
3790
+ grant: params.grant,
3791
+ fileUrls: params.fileUrls,
3792
+ schemaIds: params.schemaIds,
3793
+ serverAddress: params.serverAddress,
3794
+ serverUrl: params.serverUrl,
3795
+ serverPublicKey: params.serverPublicKey,
3796
+ filePermissions: params.filePermissions
3797
+ };
3798
+ const typedData = await this.composeServerFilesAndPermissionMessage(
3799
+ serverFilesAndPermissionInput
3800
+ );
3801
+ const signature = await this.signTypedData(typedData);
3802
+ return await this.submitSignedAddServerFilesAndPermissions(
3803
+ typedData,
3804
+ signature,
3805
+ options
3806
+ );
3807
+ } catch (error) {
3808
+ if (error instanceof import_errors.RelayerError || error instanceof import_errors.UserRejectedRequestError || error instanceof import_errors.SerializationError || error instanceof import_errors.SignatureError || error instanceof import_errors.NetworkError || error instanceof import_errors.NonceError) {
3809
+ throw error;
3810
+ }
3811
+ throw new import_errors.BlockchainError(
3812
+ `Failed to add server files and permissions: ${error instanceof Error ? error.message : "Unknown error"}`,
3813
+ error
3814
+ );
3815
+ }
3816
+ }
3817
+ /**
3818
+ * Submits an already-signed add server files and permissions transaction to the blockchain.
3819
+ *
3820
+ * @remarks
3821
+ * This method returns a TransactionResult that provides immediate access to the transaction hash.
3822
+ * The eventData field may contain parsed event details after transaction confirmation.
3823
+ *
3824
+ * @param typedData - The EIP-712 typed data for AddServerFilesAndPermissions
3825
+ * @param signature - The user's signature
3826
+ * @param options - Optional transaction options for gas parameters and timeout.
3827
+ * Note: These options are only applied for direct blockchain transactions.
3828
+ * When using relayer callbacks (gasless transactions), these options are ignored.
3829
+ * @returns TransactionResult with immediate hash access and optional event data
3830
+ * @throws {RelayerError} When gasless transaction submission fails
3831
+ * @throws {BlockchainError} When server files and permissions addition fails
3832
+ * @throws {NetworkError} When network communication fails
3833
+ *
3834
+ * @example
3835
+ * ```typescript
3836
+ * const tx = await vana.permissions.submitSignedAddServerFilesAndPermissions(
3837
+ * typedData,
3838
+ * signature
3839
+ * );
3840
+ * console.log(`Transaction submitted: ${tx.hash}`);
3841
+ *
3842
+ * // Wait for confirmation and get the permission ID
3843
+ * const { permissionId } = await tx.waitForEvents();
3844
+ * console.log(`Permission created with ID: ${permissionId}`);
3845
+ * ```
3846
+ */
3847
+ async submitSignedAddServerFilesAndPermissions(typedData, signature, options) {
3848
+ this.assertWallet();
3849
+ try {
3850
+ let hash;
3851
+ if (this.context.relayer) {
3852
+ console.debug(
3853
+ "\u{1F680} Using relayer for submitAddServerFilesAndPermissions"
3854
+ );
3855
+ const request = {
3856
+ type: "signed",
3857
+ operation: "submitAddServerFilesAndPermissions",
3858
+ typedData,
3859
+ signature
3860
+ };
3861
+ const response = await this.context.relayer(request);
3862
+ if (response.type === "error") {
3863
+ throw new import_errors.RelayerError(response.error);
3864
+ }
3865
+ if (response.type === "signed") {
3866
+ hash = response.hash;
3867
+ } else {
3868
+ throw new Error("Unexpected response type from relayer");
3869
+ }
3870
+ } else {
3871
+ console.debug(
3872
+ "\u{1F4DD} Using direct transaction for submitAddServerFilesAndPermissions"
3873
+ );
3874
+ hash = await this.submitDirectAddServerFilesAndPermissionsTransaction(
3875
+ typedData,
3876
+ signature,
3877
+ options
3878
+ );
3879
+ }
3880
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
3881
+ const { tx } = await import("../utils/transactionHelpers");
3882
+ return tx({
3883
+ hash,
3884
+ from: typeof account === "string" ? account : account.address,
3885
+ contract: "DataPortabilityPermissions",
3886
+ fn: "addServerFilesAndPermissions"
3887
+ });
3888
+ } catch (error) {
3889
+ if (error instanceof import_errors.RelayerError || error instanceof import_errors.NetworkError || error instanceof import_errors.UserRejectedRequestError || error instanceof import_errors.SignatureError || error instanceof import_errors.NonceError) {
3890
+ throw error;
3891
+ }
3892
+ throw new import_errors.BlockchainError(
3893
+ `Add server files and permissions submission failed: ${error instanceof Error ? error.message : "Unknown error"}`,
3894
+ error
3895
+ );
3896
+ }
3897
+ }
3898
+ /**
3899
+ * Submit permission revocation with signature to the blockchain
3900
+ *
3901
+ * @param permissionId - Permission ID to revoke
3902
+ * @param options - Optional transaction options for gas parameters and timeout
3903
+ * @returns Promise resolving to transaction hash
3904
+ */
3905
+ async submitRevokePermission(permissionId, options) {
3906
+ this.assertWallet();
3907
+ try {
3908
+ const chainId = await this.context.walletClient.getChainId();
3909
+ const DataPortabilityPermissionsAddress = (0, import_addresses.getContractAddress)(
3910
+ chainId,
3911
+ "DataPortabilityPermissions"
3912
+ );
3913
+ const DataPortabilityPermissionsAbi = (0, import_abi.getAbi)(
3914
+ "DataPortabilityPermissions"
3915
+ );
3916
+ const { account } = this.context.walletClient;
3917
+ if (!account) {
3918
+ throw new Error("No wallet account connected");
3919
+ }
3920
+ const hash = await this.context.walletClient.writeContract({
3921
+ address: DataPortabilityPermissionsAddress,
3922
+ abi: DataPortabilityPermissionsAbi,
3923
+ functionName: "revokePermission",
3924
+ args: [permissionId],
3925
+ chain: this.context.walletClient?.chain,
3926
+ account,
3927
+ ...options?.gas && { gas: options.gas },
3928
+ ...options?.nonce && { nonce: options.nonce },
3929
+ // Use EIP-1559 if available, otherwise fall back to legacy gasPrice
3930
+ ...options?.maxFeePerGas || options?.maxPriorityFeePerGas ? {
3931
+ ...options.maxFeePerGas && {
3932
+ maxFeePerGas: options.maxFeePerGas
3933
+ },
3934
+ ...options.maxPriorityFeePerGas && {
3935
+ maxPriorityFeePerGas: options.maxPriorityFeePerGas
3936
+ }
3937
+ } : options?.gasPrice && { gasPrice: options.gasPrice }
3938
+ });
3939
+ const { tx } = await import("../utils/transactionHelpers");
3940
+ return tx({
3941
+ hash,
3942
+ from: typeof account === "string" ? account : account.address,
3943
+ contract: "DataPortabilityPermissions",
3944
+ fn: "revokePermission"
3945
+ });
3946
+ } catch (error) {
3947
+ throw new import_errors.BlockchainError(
3948
+ `Failed to revoke permission: ${error instanceof Error ? error.message : "Unknown error"}`,
3949
+ error
3950
+ );
3951
+ }
3952
+ }
3953
+ /**
3954
+ * Submits a signed add permission transaction directly to the blockchain.
3955
+ *
3956
+ * @param typedData - The typed data structure for the permission addition
3957
+ * @param signature - The cryptographic signature authorizing the transaction
3958
+ * @returns Promise resolving to the transaction hash
3959
+ */
3960
+ async submitDirectAddPermissionTransaction(typedData, signature, options) {
3961
+ this.assertWallet();
3962
+ const chainId = await this.context.walletClient.getChainId();
3963
+ const DataPortabilityPermissionsAddress = (0, import_addresses.getContractAddress)(
3964
+ chainId,
3965
+ "DataPortabilityPermissions"
3966
+ );
3967
+ const DataPortabilityPermissionsAbi = (0, import_abi.getAbi)("DataPortabilityPermissions");
3968
+ const permissionInput = {
3969
+ nonce: typedData.message.nonce,
3970
+ granteeId: typedData.message.granteeId,
3971
+ grant: typedData.message.grant,
3972
+ fileIds: typedData.message.fileIds ?? []
3973
+ };
3974
+ const formattedSignature = (0, import_signatureFormatter.formatSignatureForContract)(signature);
3975
+ const hash = await this.context.walletClient.writeContract({
3976
+ address: DataPortabilityPermissionsAddress,
3977
+ abi: DataPortabilityPermissionsAbi,
3978
+ functionName: "addPermission",
3979
+ args: [permissionInput, formattedSignature],
3980
+ account: this.context.walletClient?.account ?? this.context.userAddress,
3981
+ chain: this.context.walletClient?.chain ?? null,
3982
+ ...this.spreadTransactionOptions(options)
3983
+ });
3984
+ return hash;
3985
+ }
3986
+ /**
3987
+ * Submits a signed add server files and permissions transaction directly to the blockchain.
3988
+ *
3989
+ * @param typedData - The typed data structure for the server files and permissions addition
3990
+ * @param signature - The cryptographic signature authorizing the transaction
3991
+ * @returns Promise resolving to the transaction hash
3992
+ */
3993
+ async submitDirectAddServerFilesAndPermissionsTransaction(typedData, signature, options) {
3994
+ this.assertWallet();
3995
+ const chainId = await this.context.publicClient.getChainId();
3996
+ const DataPortabilityPermissionsAddress = (0, import_addresses.getContractAddress)(
3997
+ chainId,
3998
+ "DataPortabilityPermissions"
3999
+ );
4000
+ const DataPortabilityPermissionsAbi = (0, import_abi.getAbi)("DataPortabilityPermissions");
4001
+ const serverFilesAndPermissionInput = {
4002
+ nonce: typedData.message.nonce,
4003
+ granteeId: typedData.message.granteeId,
4004
+ grant: typedData.message.grant,
4005
+ fileUrls: typedData.message.fileUrls,
4006
+ schemaIds: typedData.message.schemaIds,
4007
+ serverAddress: typedData.message.serverAddress,
4008
+ serverUrl: typedData.message.serverUrl,
4009
+ serverPublicKey: typedData.message.serverPublicKey,
4010
+ filePermissions: typedData.message.filePermissions
4011
+ };
4012
+ const formattedSignature = (0, import_signatureFormatter.formatSignatureForContract)(signature);
4013
+ const hash = await this.context.walletClient.writeContract({
4014
+ address: DataPortabilityPermissionsAddress,
4015
+ abi: DataPortabilityPermissionsAbi,
4016
+ functionName: "addServerFilesAndPermissions",
4017
+ args: [serverFilesAndPermissionInput, formattedSignature],
4018
+ account: this.context.walletClient?.account ?? this.context.userAddress,
4019
+ chain: this.context.walletClient?.chain ?? null,
4020
+ ...options?.value && { value: options.value },
4021
+ ...this.spreadTransactionOptions(options)
4022
+ });
4023
+ return hash;
4024
+ }
4025
+ }
4026
+ // Annotate the CommonJS export names for ESM import in node:
4027
+ 0 && (module.exports = {
4028
+ PermissionsController
4029
+ });
4030
+ //# sourceMappingURL=permissions.cjs.map