@opendatalabs/vana-sdk 0.1.0-alpha.4dd34d4 → 0.1.0-alpha.4fc2c2f

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