@opendatalabs/vana-sdk 0.1.0-alpha.7e4db82 → 0.1.0-alpha.7ee7635

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