@opendatalabs/vana-sdk 0.1.0-alpha.e9cead7 → 0.1.0-alpha.eebb656

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