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

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