@opendatalabs/vana-sdk 0.1.0-alpha.f54fafd → 0.1.0-alpha.f732fa2

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