@opendatalabs/vana-sdk 0.1.0-alpha.ffe4659 → 2.0.0

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