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

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