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

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