@opendatalabs/vana-sdk 0.1.0-alpha.db07fe1 → 0.1.0-alpha.dc68f39

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