@opendatalabs/vana-sdk 0.1.0-alpha.e9cead7 → 0.1.0-alpha.eebb656

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