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

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