@opendatalabs/vana-sdk 0.1.0-alpha.d6bebb0 → 0.1.0-alpha.d7fc764

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