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