@opendatalabs/vana-sdk 0.1.0-alpha.82bbb39 → 0.1.0-alpha.853aa70

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