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

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 (545) hide show
  1. package/README.md +67 -351
  2. package/dist/browser.cjs.map +1 -1
  3. package/dist/browser.d.ts +33 -1
  4. package/dist/browser.js.map +1 -1
  5. package/dist/chains/definitions.cjs +9 -6
  6. package/dist/chains/definitions.cjs.map +1 -1
  7. package/dist/chains/definitions.d.ts +2 -0
  8. package/dist/chains/definitions.js +9 -6
  9. package/dist/chains/definitions.js.map +1 -1
  10. package/dist/chains/index.cjs.map +1 -1
  11. package/dist/chains/index.d.ts +30 -1
  12. package/dist/chains/index.js.map +1 -1
  13. package/dist/client/enhancedResponse.cjs +164 -0
  14. package/dist/client/enhancedResponse.cjs.map +1 -0
  15. package/dist/client/enhancedResponse.d.ts +120 -0
  16. package/dist/client/enhancedResponse.js +138 -0
  17. package/dist/client/enhancedResponse.js.map +1 -0
  18. package/dist/config/chains.cjs.map +1 -1
  19. package/dist/config/chains.d.ts +99 -0
  20. package/dist/config/chains.js.map +1 -1
  21. package/dist/config/contracts.config.cjs +400 -0
  22. package/dist/config/contracts.config.cjs.map +1 -0
  23. package/dist/config/contracts.config.d.ts +84 -0
  24. package/dist/config/contracts.config.js +375 -0
  25. package/dist/config/contracts.config.js.map +1 -0
  26. package/dist/config/default-services.cjs +60 -0
  27. package/dist/config/default-services.cjs.map +1 -0
  28. package/dist/config/default-services.d.ts +46 -0
  29. package/dist/config/default-services.js +33 -0
  30. package/dist/config/default-services.js.map +1 -0
  31. package/dist/config/default-services.test.d.ts +1 -0
  32. package/dist/contracts/contractController.cjs +1 -1
  33. package/dist/contracts/contractController.cjs.map +1 -1
  34. package/dist/contracts/contractController.d.ts +66 -10
  35. package/dist/contracts/contractController.js +1 -1
  36. package/dist/contracts/contractController.js.map +1 -1
  37. package/dist/controllers/__tests__/data-consistency-integration.test.d.ts +7 -0
  38. package/dist/controllers/__tests__/operations.processQueue.test.d.ts +1 -0
  39. package/dist/controllers/accessSettlement.cjs +289 -0
  40. package/dist/controllers/accessSettlement.cjs.map +1 -0
  41. package/dist/controllers/accessSettlement.d.ts +157 -0
  42. package/dist/controllers/accessSettlement.js +265 -0
  43. package/dist/controllers/accessSettlement.js.map +1 -0
  44. package/dist/controllers/accessSettlement.test.d.ts +1 -0
  45. package/dist/controllers/base.cjs +116 -0
  46. package/dist/controllers/base.cjs.map +1 -0
  47. package/dist/controllers/base.d.ts +94 -0
  48. package/dist/controllers/base.js +92 -0
  49. package/dist/controllers/base.js.map +1 -0
  50. package/dist/controllers/data.cjs +634 -352
  51. package/dist/controllers/data.cjs.map +1 -1
  52. package/dist/controllers/data.d.ts +348 -213
  53. package/dist/controllers/data.js +647 -355
  54. package/dist/controllers/data.js.map +1 -1
  55. package/dist/controllers/operations.cjs +430 -0
  56. package/dist/controllers/operations.cjs.map +1 -0
  57. package/dist/controllers/operations.d.ts +229 -0
  58. package/dist/controllers/operations.js +406 -0
  59. package/dist/controllers/operations.js.map +1 -0
  60. package/dist/controllers/permissions.cjs +943 -443
  61. package/dist/controllers/permissions.cjs.map +1 -1
  62. package/dist/controllers/permissions.d.ts +201 -120
  63. package/dist/controllers/permissions.js +943 -443
  64. package/dist/controllers/permissions.js.map +1 -1
  65. package/dist/controllers/protocol.cjs +14 -10
  66. package/dist/controllers/protocol.cjs.map +1 -1
  67. package/dist/controllers/protocol.d.ts +30 -31
  68. package/dist/controllers/protocol.js +14 -10
  69. package/dist/controllers/protocol.js.map +1 -1
  70. package/dist/controllers/runtimePermissions.cjs +272 -0
  71. package/dist/controllers/runtimePermissions.cjs.map +1 -0
  72. package/dist/controllers/runtimePermissions.d.ts +152 -0
  73. package/dist/controllers/runtimePermissions.js +251 -0
  74. package/dist/controllers/runtimePermissions.js.map +1 -0
  75. package/dist/controllers/runtimePermissions.test.d.ts +1 -0
  76. package/dist/controllers/schemas.cjs +113 -43
  77. package/dist/controllers/schemas.cjs.map +1 -1
  78. package/dist/controllers/schemas.d.ts +90 -43
  79. package/dist/controllers/schemas.js +113 -43
  80. package/dist/controllers/schemas.js.map +1 -1
  81. package/dist/controllers/server.cjs +276 -60
  82. package/dist/controllers/server.cjs.map +1 -1
  83. package/dist/controllers/server.d.ts +159 -54
  84. package/dist/controllers/server.js +276 -60
  85. package/dist/controllers/server.js.map +1 -1
  86. package/dist/core/__tests__/health.test.d.ts +1 -0
  87. package/dist/core/__tests__/inMemoryNonceManager.test.d.ts +1 -0
  88. package/dist/core/__tests__/nonceManager.test.d.ts +1 -0
  89. package/dist/core/__tests__/pollingManager.test.d.ts +4 -0
  90. package/dist/core/apiClient.cjs +53 -3
  91. package/dist/core/apiClient.cjs.map +1 -1
  92. package/dist/core/apiClient.d.ts +132 -7
  93. package/dist/core/apiClient.js +53 -3
  94. package/dist/core/apiClient.js.map +1 -1
  95. package/dist/core/generics.cjs +30 -3
  96. package/dist/core/generics.cjs.map +1 -1
  97. package/dist/core/generics.d.ts +95 -6
  98. package/dist/core/generics.js +30 -3
  99. package/dist/core/generics.js.map +1 -1
  100. package/dist/core/health.cjs +289 -0
  101. package/dist/core/health.cjs.map +1 -0
  102. package/dist/core/health.d.ts +143 -0
  103. package/dist/core/health.js +265 -0
  104. package/dist/core/health.js.map +1 -0
  105. package/dist/core/inMemoryNonceManager.cjs +138 -0
  106. package/dist/core/inMemoryNonceManager.cjs.map +1 -0
  107. package/dist/core/inMemoryNonceManager.d.ts +69 -0
  108. package/dist/core/inMemoryNonceManager.js +114 -0
  109. package/dist/core/inMemoryNonceManager.js.map +1 -0
  110. package/dist/core/nonceManager.cjs +304 -0
  111. package/dist/core/nonceManager.cjs.map +1 -0
  112. package/dist/core/nonceManager.d.ts +116 -0
  113. package/dist/core/nonceManager.js +280 -0
  114. package/dist/core/nonceManager.js.map +1 -0
  115. package/dist/core/pollingManager.cjs +292 -0
  116. package/dist/core/pollingManager.cjs.map +1 -0
  117. package/dist/core/pollingManager.d.ts +120 -0
  118. package/dist/core/pollingManager.js +268 -0
  119. package/dist/core/pollingManager.js.map +1 -0
  120. package/dist/core.cjs +164 -36
  121. package/dist/core.cjs.map +1 -1
  122. package/dist/core.d.ts +69 -10
  123. package/dist/core.js +167 -37
  124. package/dist/core.js.map +1 -1
  125. package/dist/crypto/ecies/__tests__/constants.test.d.ts +1 -1
  126. package/dist/crypto/ecies/__tests__/interface.test.d.ts +1 -0
  127. package/dist/crypto/ecies/__tests__/serialization.test.d.ts +8 -0
  128. package/dist/crypto/ecies/__tests__/utils.test.d.ts +1 -0
  129. package/dist/crypto/ecies/base.cjs +59 -23
  130. package/dist/crypto/ecies/base.cjs.map +1 -1
  131. package/dist/crypto/ecies/base.js +59 -23
  132. package/dist/crypto/ecies/base.js.map +1 -1
  133. package/dist/crypto/ecies/constants.cjs +2 -10
  134. package/dist/crypto/ecies/constants.cjs.map +1 -1
  135. package/dist/crypto/ecies/constants.d.ts +0 -9
  136. package/dist/crypto/ecies/constants.js +1 -8
  137. package/dist/crypto/ecies/constants.js.map +1 -1
  138. package/dist/crypto/ecies/interface.cjs +19 -2
  139. package/dist/crypto/ecies/interface.cjs.map +1 -1
  140. package/dist/crypto/ecies/interface.js +19 -2
  141. package/dist/crypto/ecies/interface.js.map +1 -1
  142. package/dist/errors.cjs +45 -0
  143. package/dist/errors.cjs.map +1 -1
  144. package/dist/errors.d.ts +104 -0
  145. package/dist/errors.js +43 -0
  146. package/dist/errors.js.map +1 -1
  147. package/dist/generated/abi/AccessSettlementImplementation.cjs +635 -0
  148. package/dist/generated/abi/AccessSettlementImplementation.cjs.map +1 -0
  149. package/dist/generated/abi/AccessSettlementImplementation.d.ts +468 -0
  150. package/dist/generated/abi/AccessSettlementImplementation.js +611 -0
  151. package/dist/generated/abi/AccessSettlementImplementation.js.map +1 -0
  152. package/dist/generated/abi/AttestationPolicyImplementation.cjs +614 -0
  153. package/dist/generated/abi/AttestationPolicyImplementation.cjs.map +1 -0
  154. package/dist/generated/abi/AttestationPolicyImplementation.d.ts +449 -0
  155. package/dist/generated/abi/AttestationPolicyImplementation.js +590 -0
  156. package/dist/generated/abi/AttestationPolicyImplementation.js.map +1 -0
  157. package/dist/generated/abi/ComputeEngineImplementation.cjs.map +1 -1
  158. package/dist/generated/abi/ComputeEngineImplementation.js.map +1 -1
  159. package/dist/generated/abi/{DLPTreasuryImplementation.cjs → ComputeEngineTreasuryImplementation.cjs} +16 -92
  160. package/dist/generated/abi/ComputeEngineTreasuryImplementation.cjs.map +1 -0
  161. package/dist/generated/abi/{DLPTreasuryImplementation.d.ts → ComputeEngineTreasuryImplementation.d.ts} +9 -67
  162. package/dist/generated/abi/{DLPTreasuryImplementation.js → ComputeEngineTreasuryImplementation.js} +12 -88
  163. package/dist/generated/abi/ComputeEngineTreasuryImplementation.js.map +1 -0
  164. package/dist/generated/abi/ComputeInstructionRegistryImplementation.cjs.map +1 -1
  165. package/dist/generated/abi/ComputeInstructionRegistryImplementation.js.map +1 -1
  166. package/dist/generated/abi/DATFactoryImplementation.cjs.map +1 -1
  167. package/dist/generated/abi/DATFactoryImplementation.js.map +1 -1
  168. package/dist/generated/abi/DATImplementation.cjs.map +1 -1
  169. package/dist/generated/abi/DATImplementation.js.map +1 -1
  170. package/dist/generated/abi/DATPausableImplementation.cjs.map +1 -1
  171. package/dist/generated/abi/DATPausableImplementation.js.map +1 -1
  172. package/dist/generated/abi/DATVotesImplementation.cjs.map +1 -1
  173. package/dist/generated/abi/DATVotesImplementation.js.map +1 -1
  174. package/dist/generated/abi/DLPPerformanceImplementation.cjs +42 -0
  175. package/dist/generated/abi/DLPPerformanceImplementation.cjs.map +1 -1
  176. package/dist/generated/abi/DLPPerformanceImplementation.d.ts +32 -0
  177. package/dist/generated/abi/DLPPerformanceImplementation.js +42 -0
  178. package/dist/generated/abi/DLPPerformanceImplementation.js.map +1 -1
  179. package/dist/generated/abi/DLPRegistryImplementation.cjs +5 -5
  180. package/dist/generated/abi/DLPRegistryImplementation.cjs.map +1 -1
  181. package/dist/generated/abi/DLPRegistryImplementation.d.ts +4 -4
  182. package/dist/generated/abi/DLPRegistryImplementation.js +5 -5
  183. package/dist/generated/abi/DLPRegistryImplementation.js.map +1 -1
  184. package/dist/generated/abi/DLPRegistryTreasuryImplementation.cjs.map +1 -1
  185. package/dist/generated/abi/DLPRegistryTreasuryImplementation.js.map +1 -1
  186. package/dist/generated/abi/DLPRewardDeployerImplementation.cjs +166 -2
  187. package/dist/generated/abi/DLPRewardDeployerImplementation.cjs.map +1 -1
  188. package/dist/generated/abi/DLPRewardDeployerImplementation.d.ts +129 -2
  189. package/dist/generated/abi/DLPRewardDeployerImplementation.js +166 -2
  190. package/dist/generated/abi/DLPRewardDeployerImplementation.js.map +1 -1
  191. package/dist/generated/abi/DLPRewardSwapImplementation.cjs.map +1 -1
  192. package/dist/generated/abi/DLPRewardSwapImplementation.js.map +1 -1
  193. package/dist/generated/abi/DataLiquidityPoolImplementation.cjs +282 -100
  194. package/dist/generated/abi/DataLiquidityPoolImplementation.cjs.map +1 -1
  195. package/dist/generated/abi/DataLiquidityPoolImplementation.d.ts +218 -79
  196. package/dist/generated/abi/DataLiquidityPoolImplementation.js +281 -99
  197. package/dist/generated/abi/DataLiquidityPoolImplementation.js.map +1 -1
  198. package/dist/generated/abi/DataPortabilityGranteesImplementation.cjs +167 -19
  199. package/dist/generated/abi/DataPortabilityGranteesImplementation.cjs.map +1 -1
  200. package/dist/generated/abi/DataPortabilityGranteesImplementation.d.ts +127 -14
  201. package/dist/generated/abi/DataPortabilityGranteesImplementation.js +167 -19
  202. package/dist/generated/abi/DataPortabilityGranteesImplementation.js.map +1 -1
  203. package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs +0 -19
  204. package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs.map +1 -1
  205. package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.ts +0 -14
  206. package/dist/generated/abi/DataPortabilityPermissionsImplementation.js +0 -19
  207. package/dist/generated/abi/DataPortabilityPermissionsImplementation.js.map +1 -1
  208. package/dist/generated/abi/DataPortabilityServersImplementation.cjs +0 -19
  209. package/dist/generated/abi/DataPortabilityServersImplementation.cjs.map +1 -1
  210. package/dist/generated/abi/DataPortabilityServersImplementation.d.ts +0 -14
  211. package/dist/generated/abi/DataPortabilityServersImplementation.js +0 -19
  212. package/dist/generated/abi/DataPortabilityServersImplementation.js.map +1 -1
  213. package/dist/generated/abi/DataRefinerRegistryImplementation.cjs.map +1 -1
  214. package/dist/generated/abi/DataRefinerRegistryImplementation.js.map +1 -1
  215. package/dist/generated/abi/DataRegistryImplementation.cjs +0 -13
  216. package/dist/generated/abi/DataRegistryImplementation.cjs.map +1 -1
  217. package/dist/generated/abi/DataRegistryImplementation.d.ts +0 -10
  218. package/dist/generated/abi/DataRegistryImplementation.js +0 -13
  219. package/dist/generated/abi/DataRegistryImplementation.js.map +1 -1
  220. package/dist/generated/abi/DatasetRegistryImplementation.cjs +751 -0
  221. package/dist/generated/abi/DatasetRegistryImplementation.cjs.map +1 -0
  222. package/dist/generated/abi/DatasetRegistryImplementation.d.ts +557 -0
  223. package/dist/generated/abi/DatasetRegistryImplementation.js +727 -0
  224. package/dist/generated/abi/DatasetRegistryImplementation.js.map +1 -0
  225. package/dist/generated/abi/ProtocolConfigImplementation.cjs +578 -0
  226. package/dist/generated/abi/ProtocolConfigImplementation.cjs.map +1 -0
  227. package/dist/generated/abi/ProtocolConfigImplementation.d.ts +423 -0
  228. package/dist/generated/abi/ProtocolConfigImplementation.js +554 -0
  229. package/dist/generated/abi/ProtocolConfigImplementation.js.map +1 -0
  230. package/dist/generated/abi/QueryEngineImplementation.cjs.map +1 -1
  231. package/dist/generated/abi/QueryEngineImplementation.js.map +1 -1
  232. package/dist/generated/abi/SwapHelperImplementation.cjs +0 -43
  233. package/dist/generated/abi/SwapHelperImplementation.cjs.map +1 -1
  234. package/dist/generated/abi/SwapHelperImplementation.d.ts +0 -35
  235. package/dist/generated/abi/SwapHelperImplementation.js +0 -43
  236. package/dist/generated/abi/SwapHelperImplementation.js.map +1 -1
  237. package/dist/generated/abi/TeePoolDedicatedGpuImplementation.cjs.map +1 -1
  238. package/dist/generated/abi/TeePoolDedicatedGpuImplementation.js.map +1 -1
  239. package/dist/generated/abi/TeePoolDedicatedStandardImplementation.cjs.map +1 -1
  240. package/dist/generated/abi/TeePoolDedicatedStandardImplementation.js.map +1 -1
  241. package/dist/generated/abi/TeePoolEphemeralStandardImplementation.cjs.map +1 -1
  242. package/dist/generated/abi/TeePoolEphemeralStandardImplementation.js.map +1 -1
  243. package/dist/generated/abi/TeePoolPersistentGpuImplementation.cjs.map +1 -1
  244. package/dist/generated/abi/TeePoolPersistentGpuImplementation.js.map +1 -1
  245. package/dist/generated/abi/TeePoolPersistentStandardImplementation.cjs.map +1 -1
  246. package/dist/generated/abi/TeePoolPersistentStandardImplementation.js.map +1 -1
  247. package/dist/generated/abi/TeePoolPhalaImplementation.cjs.map +1 -1
  248. package/dist/generated/abi/TeePoolPhalaImplementation.js.map +1 -1
  249. package/dist/generated/abi/UniswapV3NonfungiblePositionManagerImplementation.cjs +1251 -0
  250. package/dist/generated/abi/UniswapV3NonfungiblePositionManagerImplementation.cjs.map +1 -0
  251. package/dist/generated/abi/UniswapV3NonfungiblePositionManagerImplementation.d.ts +948 -0
  252. package/dist/generated/abi/UniswapV3NonfungiblePositionManagerImplementation.js +1227 -0
  253. package/dist/generated/abi/UniswapV3NonfungiblePositionManagerImplementation.js.map +1 -0
  254. package/dist/generated/abi/UniswapV3QuoterV2Implementation.cjs +297 -0
  255. package/dist/generated/abi/UniswapV3QuoterV2Implementation.cjs.map +1 -0
  256. package/dist/generated/abi/UniswapV3QuoterV2Implementation.d.ts +206 -0
  257. package/dist/generated/abi/UniswapV3QuoterV2Implementation.js +273 -0
  258. package/dist/generated/abi/UniswapV3QuoterV2Implementation.js.map +1 -0
  259. package/dist/generated/abi/VanaEpochImplementation.cjs +195 -0
  260. package/dist/generated/abi/VanaEpochImplementation.cjs.map +1 -1
  261. package/dist/generated/abi/VanaEpochImplementation.d.ts +151 -0
  262. package/dist/generated/abi/VanaEpochImplementation.js +195 -0
  263. package/dist/generated/abi/VanaEpochImplementation.js.map +1 -1
  264. package/dist/generated/abi/VanaPoolEntityImplementation.cjs +22 -65
  265. package/dist/generated/abi/VanaPoolEntityImplementation.cjs.map +1 -1
  266. package/dist/generated/abi/VanaPoolEntityImplementation.d.ts +17 -51
  267. package/dist/generated/abi/VanaPoolEntityImplementation.js +22 -65
  268. package/dist/generated/abi/VanaPoolEntityImplementation.js.map +1 -1
  269. package/dist/generated/abi/VanaPoolStakingImplementation.cjs +113 -1
  270. package/dist/generated/abi/VanaPoolStakingImplementation.cjs.map +1 -1
  271. package/dist/generated/abi/VanaPoolStakingImplementation.d.ts +85 -1
  272. package/dist/generated/abi/VanaPoolStakingImplementation.js +113 -1
  273. package/dist/generated/abi/VanaPoolStakingImplementation.js.map +1 -1
  274. package/dist/generated/abi/VanaPoolTreasuryImplementation.cjs.map +1 -1
  275. package/dist/generated/abi/VanaPoolTreasuryImplementation.js.map +1 -1
  276. package/dist/generated/abi/VanaRuntimePermissionsImplementation.cjs +759 -0
  277. package/dist/generated/abi/VanaRuntimePermissionsImplementation.cjs.map +1 -0
  278. package/dist/generated/abi/VanaRuntimePermissionsImplementation.d.ts +563 -0
  279. package/dist/generated/abi/VanaRuntimePermissionsImplementation.js +735 -0
  280. package/dist/generated/abi/VanaRuntimePermissionsImplementation.js.map +1 -0
  281. package/dist/generated/abi/VanaRuntimeServersImplementation.cjs +820 -0
  282. package/dist/generated/abi/VanaRuntimeServersImplementation.cjs.map +1 -0
  283. package/dist/generated/abi/VanaRuntimeServersImplementation.d.ts +609 -0
  284. package/dist/generated/abi/VanaRuntimeServersImplementation.js +796 -0
  285. package/dist/generated/abi/VanaRuntimeServersImplementation.js.map +1 -0
  286. package/dist/generated/abi/VanaTreasuryImplementation.cjs +536 -0
  287. package/dist/generated/abi/VanaTreasuryImplementation.cjs.map +1 -0
  288. package/dist/generated/abi/VanaTreasuryImplementation.d.ts +393 -0
  289. package/dist/generated/abi/VanaTreasuryImplementation.js +512 -0
  290. package/dist/generated/abi/VanaTreasuryImplementation.js.map +1 -0
  291. package/dist/generated/abi/WVANAImplementation.cjs +339 -0
  292. package/dist/generated/abi/WVANAImplementation.cjs.map +1 -0
  293. package/dist/generated/abi/WVANAImplementation.d.ts +244 -0
  294. package/dist/generated/abi/WVANAImplementation.js +315 -0
  295. package/dist/generated/abi/WVANAImplementation.js.map +1 -0
  296. package/dist/generated/abi/index.cjs +79 -47
  297. package/dist/generated/abi/index.cjs.map +1 -1
  298. package/dist/generated/abi/index.d.ts +15783 -10449
  299. package/dist/generated/abi/index.js +65 -43
  300. package/dist/generated/abi/index.js.map +1 -1
  301. package/dist/{config → generated}/addresses.cjs +174 -75
  302. package/dist/generated/addresses.cjs.map +1 -0
  303. package/dist/{config → generated}/addresses.d.ts +174 -165
  304. package/dist/{config → generated}/addresses.js +174 -75
  305. package/dist/generated/addresses.js.map +1 -0
  306. package/dist/generated/event-types.cjs.map +1 -1
  307. package/dist/generated/event-types.d.ts +482 -399
  308. package/dist/generated/eventRegistry.cjs +2601 -724
  309. package/dist/generated/eventRegistry.cjs.map +1 -1
  310. package/dist/generated/eventRegistry.d.ts +2 -2
  311. package/dist/generated/eventRegistry.js +2601 -724
  312. package/dist/generated/eventRegistry.js.map +1 -1
  313. package/dist/generated/server/server-exports.cjs +22 -0
  314. package/dist/generated/server/server-exports.cjs.map +1 -1
  315. package/dist/generated/server/server-exports.d.ts +31 -11
  316. package/dist/generated/server/server-exports.js +17 -0
  317. package/dist/generated/server/server-exports.js.map +1 -1
  318. package/dist/generated/server/server.cjs.map +1 -1
  319. package/dist/generated/server/server.d.ts +771 -402
  320. package/dist/generated/subgraph.cjs +797 -32
  321. package/dist/generated/subgraph.cjs.map +1 -1
  322. package/dist/generated/subgraph.d.ts +135 -0
  323. package/dist/generated/subgraph.js +792 -32
  324. package/dist/generated/subgraph.js.map +1 -1
  325. package/dist/index.browser.d.ts +6 -1
  326. package/dist/index.browser.js +26 -1
  327. package/dist/index.browser.js.map +1 -1
  328. package/dist/index.cjs.map +1 -1
  329. package/dist/index.js.map +1 -1
  330. package/dist/index.node.cjs +47 -4
  331. package/dist/index.node.cjs.map +1 -1
  332. package/dist/index.node.d.ts +60 -14
  333. package/dist/index.node.js +42 -3
  334. package/dist/index.node.js.map +1 -1
  335. package/dist/lib/__tests__/redisAtomicStore.test.d.ts +1 -0
  336. package/dist/lib/redisAtomicStore.cjs +201 -0
  337. package/dist/lib/redisAtomicStore.cjs.map +1 -0
  338. package/dist/lib/redisAtomicStore.d.ts +120 -0
  339. package/dist/lib/redisAtomicStore.js +177 -0
  340. package/dist/lib/redisAtomicStore.js.map +1 -0
  341. package/dist/node.cjs.map +1 -1
  342. package/dist/node.d.ts +39 -1
  343. package/dist/node.js.map +1 -1
  344. package/dist/platform/browser.cjs +160 -2
  345. package/dist/platform/browser.cjs.map +1 -1
  346. package/dist/platform/browser.d.ts +232 -12
  347. package/dist/platform/browser.js +160 -2
  348. package/dist/platform/browser.js.map +1 -1
  349. package/dist/platform/interface.cjs.map +1 -1
  350. package/dist/platform/interface.d.ts +283 -90
  351. package/dist/platform/node.cjs +163 -2
  352. package/dist/platform/node.cjs.map +1 -1
  353. package/dist/platform/node.d.ts +69 -6
  354. package/dist/platform/node.js +163 -2
  355. package/dist/platform/node.js.map +1 -1
  356. package/dist/server/relayerHandler.cjs +452 -0
  357. package/dist/server/relayerHandler.cjs.map +1 -0
  358. package/dist/server/relayerHandler.d.ts +69 -0
  359. package/dist/server/relayerHandler.js +428 -0
  360. package/dist/server/relayerHandler.js.map +1 -0
  361. package/dist/storage/index.cjs +3 -0
  362. package/dist/storage/index.cjs.map +1 -1
  363. package/dist/storage/index.d.ts +1 -0
  364. package/dist/storage/index.js +2 -0
  365. package/dist/storage/index.js.map +1 -1
  366. package/dist/storage/manager.cjs +108 -25
  367. package/dist/storage/manager.cjs.map +1 -1
  368. package/dist/storage/manager.d.ts +119 -25
  369. package/dist/storage/manager.js +108 -25
  370. package/dist/storage/manager.js.map +1 -1
  371. package/dist/storage/providers/callback-storage.cjs +86 -15
  372. package/dist/storage/providers/callback-storage.cjs.map +1 -1
  373. package/dist/storage/providers/callback-storage.d.ts +109 -20
  374. package/dist/storage/providers/callback-storage.js +86 -15
  375. package/dist/storage/providers/callback-storage.js.map +1 -1
  376. package/dist/storage/providers/dropbox.cjs +237 -0
  377. package/dist/storage/providers/dropbox.cjs.map +1 -0
  378. package/dist/storage/providers/dropbox.d.ts +39 -0
  379. package/dist/storage/providers/dropbox.js +215 -0
  380. package/dist/storage/providers/dropbox.js.map +1 -0
  381. package/dist/storage/providers/dropbox.test.d.ts +1 -0
  382. package/dist/storage/providers/pinata.cjs.map +1 -1
  383. package/dist/storage/providers/pinata.d.ts +12 -14
  384. package/dist/storage/providers/pinata.js.map +1 -1
  385. package/dist/tests/data-upload-owner-validation.test.d.ts +1 -0
  386. package/dist/tests/factories/mockFactory.d.ts +6 -6
  387. package/dist/tests/fakes/FakeWaitForTransactionEvents.d.ts +2 -2
  388. package/dist/tests/permissions-revoke-relayer.test.d.ts +1 -0
  389. package/dist/tests/permissions-transaction-options.test.d.ts +1 -0
  390. package/dist/tests/read-only-mode.test.d.ts +1 -0
  391. package/dist/tests/relayer-integration.test.d.ts +1 -0
  392. package/dist/tests/relayer-unified.test.d.ts +1 -0
  393. package/dist/tests/server-relayer-handler.test.d.ts +1 -0
  394. package/dist/types/accessSettlement.cjs +17 -0
  395. package/dist/types/accessSettlement.cjs.map +1 -0
  396. package/dist/types/accessSettlement.d.ts +66 -0
  397. package/dist/types/accessSettlement.js +1 -0
  398. package/dist/types/accessSettlement.js.map +1 -0
  399. package/dist/types/atomicStore.cjs +31 -0
  400. package/dist/types/atomicStore.cjs.map +1 -0
  401. package/dist/types/atomicStore.d.ts +236 -0
  402. package/dist/types/atomicStore.js +7 -0
  403. package/dist/types/atomicStore.js.map +1 -0
  404. package/dist/types/blockchain.cjs.map +1 -1
  405. package/dist/types/blockchain.d.ts +39 -11
  406. package/dist/types/chains.cjs.map +1 -1
  407. package/dist/types/chains.d.ts +74 -7
  408. package/dist/types/chains.js.map +1 -1
  409. package/dist/types/config.cjs +10 -0
  410. package/dist/types/config.cjs.map +1 -1
  411. package/dist/types/config.d.ts +217 -220
  412. package/dist/types/config.js +8 -0
  413. package/dist/types/config.js.map +1 -1
  414. package/dist/types/contracts.cjs.map +1 -1
  415. package/dist/types/contracts.d.ts +71 -7
  416. package/dist/types/controller-context.cjs.map +1 -1
  417. package/dist/types/controller-context.d.ts +12 -6
  418. package/dist/types/data.cjs.map +1 -1
  419. package/dist/types/data.d.ts +82 -10
  420. package/dist/types/generics.cjs.map +1 -1
  421. package/dist/types/generics.d.ts +81 -10
  422. package/dist/types/index.cjs +4 -0
  423. package/dist/types/index.cjs.map +1 -1
  424. package/dist/types/index.d.ts +36 -6
  425. package/dist/types/index.js +9 -1
  426. package/dist/types/index.js.map +1 -1
  427. package/dist/types/operationStore.cjs +17 -0
  428. package/dist/types/operationStore.cjs.map +1 -0
  429. package/dist/types/operationStore.d.ts +171 -0
  430. package/dist/types/operationStore.js +1 -0
  431. package/dist/types/operationStore.js.map +1 -0
  432. package/dist/types/operations.cjs +3 -15
  433. package/dist/types/operations.cjs.map +1 -1
  434. package/dist/types/operations.d.ts +131 -39
  435. package/dist/types/operations.js +2 -13
  436. package/dist/types/operations.js.map +1 -1
  437. package/dist/types/options.cjs +17 -0
  438. package/dist/types/options.cjs.map +1 -0
  439. package/dist/types/options.d.ts +308 -0
  440. package/dist/types/options.js +1 -0
  441. package/dist/types/options.js.map +1 -0
  442. package/dist/types/permissions.cjs.map +1 -1
  443. package/dist/types/permissions.d.ts +19 -20
  444. package/dist/types/personal.cjs.map +1 -1
  445. package/dist/types/personal.d.ts +150 -14
  446. package/dist/types/relayer.cjs.map +1 -1
  447. package/dist/types/relayer.d.ts +307 -35
  448. package/dist/types/runtimePermissions.cjs +17 -0
  449. package/dist/types/runtimePermissions.cjs.map +1 -0
  450. package/dist/types/runtimePermissions.d.ts +122 -0
  451. package/dist/types/runtimePermissions.js +1 -0
  452. package/dist/types/runtimePermissions.js.map +1 -0
  453. package/dist/types/storage.cjs.map +1 -1
  454. package/dist/types/storage.d.ts +9 -21
  455. package/dist/types/storage.js.map +1 -1
  456. package/dist/types/utils.cjs.map +1 -1
  457. package/dist/types/utils.d.ts +0 -45
  458. package/dist/utils/__tests__/chainQuery.test.d.ts +1 -0
  459. package/dist/utils/__tests__/subgraphConsistency.test.d.ts +4 -0
  460. package/dist/utils/__tests__/subgraphPagination.test.d.ts +4 -0
  461. package/dist/utils/blockchain/registry.cjs +3 -3
  462. package/dist/utils/blockchain/registry.cjs.map +1 -1
  463. package/dist/utils/blockchain/registry.d.ts +1 -1
  464. package/dist/utils/blockchain/registry.js +3 -3
  465. package/dist/utils/blockchain/registry.js.map +1 -1
  466. package/dist/utils/chainQuery.cjs +107 -0
  467. package/dist/utils/chainQuery.cjs.map +1 -0
  468. package/dist/utils/chainQuery.d.ts +31 -0
  469. package/dist/utils/chainQuery.js +82 -0
  470. package/dist/utils/chainQuery.js.map +1 -0
  471. package/dist/utils/grantFiles.cjs +4 -1
  472. package/dist/utils/grantFiles.cjs.map +1 -1
  473. package/dist/utils/grantFiles.d.ts +10 -20
  474. package/dist/utils/grantFiles.js +4 -1
  475. package/dist/utils/grantFiles.js.map +1 -1
  476. package/dist/utils/grantValidation.cjs.map +1 -1
  477. package/dist/utils/grantValidation.d.ts +95 -16
  478. package/dist/utils/grantValidation.js.map +1 -1
  479. package/dist/utils/grants.cjs.map +1 -1
  480. package/dist/utils/grants.d.ts +93 -12
  481. package/dist/utils/grants.js.map +1 -1
  482. package/dist/utils/ipfs.cjs +2 -4
  483. package/dist/utils/ipfs.cjs.map +1 -1
  484. package/dist/utils/ipfs.d.ts +1 -1
  485. package/dist/utils/ipfs.js +2 -4
  486. package/dist/utils/ipfs.js.map +1 -1
  487. package/dist/utils/lazy-import.cjs.map +1 -1
  488. package/dist/utils/lazy-import.d.ts +32 -7
  489. package/dist/utils/lazy-import.js.map +1 -1
  490. package/dist/utils/multicall.cjs +1 -1
  491. package/dist/utils/multicall.cjs.map +1 -1
  492. package/dist/utils/multicall.js +1 -1
  493. package/dist/utils/multicall.js.map +1 -1
  494. package/dist/utils/runtimeGrantFiles.cjs +84 -0
  495. package/dist/utils/runtimeGrantFiles.cjs.map +1 -0
  496. package/dist/utils/runtimeGrantFiles.d.ts +66 -0
  497. package/dist/utils/runtimeGrantFiles.js +58 -0
  498. package/dist/utils/runtimeGrantFiles.js.map +1 -0
  499. package/dist/utils/signatureCache.cjs +8 -2
  500. package/dist/utils/signatureCache.cjs.map +1 -1
  501. package/dist/utils/signatureCache.d.ts +49 -8
  502. package/dist/utils/signatureCache.js +8 -2
  503. package/dist/utils/signatureCache.js.map +1 -1
  504. package/dist/utils/subgraphConsistency.cjs +184 -0
  505. package/dist/utils/subgraphConsistency.cjs.map +1 -0
  506. package/dist/utils/subgraphConsistency.d.ts +65 -0
  507. package/dist/utils/subgraphConsistency.js +155 -0
  508. package/dist/utils/subgraphConsistency.js.map +1 -0
  509. package/dist/utils/subgraphMetaCache.cjs +101 -0
  510. package/dist/utils/subgraphMetaCache.cjs.map +1 -0
  511. package/dist/utils/subgraphMetaCache.d.ts +56 -0
  512. package/dist/utils/subgraphMetaCache.js +76 -0
  513. package/dist/utils/subgraphMetaCache.js.map +1 -0
  514. package/dist/utils/subgraphPagination.cjs +104 -0
  515. package/dist/utils/subgraphPagination.cjs.map +1 -0
  516. package/dist/utils/subgraphPagination.d.ts +78 -0
  517. package/dist/utils/subgraphPagination.js +78 -0
  518. package/dist/utils/subgraphPagination.js.map +1 -0
  519. package/dist/utils/transactionHelpers.cjs.map +1 -1
  520. package/dist/utils/transactionHelpers.d.ts +12 -12
  521. package/dist/utils/transactionHelpers.js.map +1 -1
  522. package/dist/utils/typedDataConverter.cjs.map +1 -1
  523. package/dist/utils/typedDataConverter.d.ts +39 -3
  524. package/dist/utils/typedDataConverter.js.map +1 -1
  525. package/dist/utils/urlResolver.cjs +7 -0
  526. package/dist/utils/urlResolver.cjs.map +1 -1
  527. package/dist/utils/urlResolver.d.ts +22 -4
  528. package/dist/utils/urlResolver.js +7 -0
  529. package/dist/utils/urlResolver.js.map +1 -1
  530. package/dist/utils/wallet.cjs +63 -0
  531. package/dist/utils/wallet.cjs.map +1 -0
  532. package/dist/utils/wallet.d.ts +94 -0
  533. package/dist/utils/wallet.js +37 -0
  534. package/dist/utils/wallet.js.map +1 -0
  535. package/package.json +7 -2
  536. package/dist/config/addresses.cjs.map +0 -1
  537. package/dist/config/addresses.js.map +0 -1
  538. package/dist/generated/abi/DLPTreasuryImplementation.cjs.map +0 -1
  539. package/dist/generated/abi/DLPTreasuryImplementation.js.map +0 -1
  540. package/dist/server/handler.cjs +0 -101
  541. package/dist/server/handler.cjs.map +0 -1
  542. package/dist/server/handler.d.ts +0 -87
  543. package/dist/server/handler.js +0 -77
  544. package/dist/server/handler.js.map +0 -1
  545. /package/dist/{tests/server-handler.test.d.ts → client/__tests__/enhancedResponse.test.d.ts} +0 -0
@@ -1,5 +1,6 @@
1
1
  import { getAddress } from "viem";
2
2
  import { gasAwareMulticall } from "../utils/multicall";
3
+ import { PollingManager } from "../core/pollingManager";
3
4
  import {
4
5
  RelayerError,
5
6
  UserRejectedRequestError,
@@ -11,16 +12,17 @@ import {
11
12
  ServerUrlMismatchError,
12
13
  PermissionError
13
14
  } from "../errors";
14
- import { getContractAddress } from "../config/addresses";
15
+ import { getContractAddress } from "../generated/addresses";
15
16
  import { getAbi } from "../generated/abi";
16
17
  import { createGrantFile, getGrantFileHash } from "../utils/grantFiles";
17
18
  import { validateGrant } from "../utils/grantValidation";
18
19
  import { withSignatureCache } from "../utils/signatureCache";
19
20
  import { formatSignatureForContract } from "../utils/signatureFormatter";
20
21
  import { toViemTypedDataDefinition } from "../utils/typedDataConverter";
21
- class PermissionsController {
22
+ import { BaseController } from "./base";
23
+ class PermissionsController extends BaseController {
22
24
  constructor(context) {
23
- this.context = context;
25
+ super(context);
24
26
  }
25
27
  /**
26
28
  * Grants permission for an application to access user data with gasless transactions.
@@ -56,9 +58,14 @@ class PermissionsController {
56
58
  * await vana.permissions.revoke({ permissionId: result.permissionId });
57
59
  * ```
58
60
  */
59
- async grant(params) {
61
+ async grant(params, options) {
62
+ this.assertWallet();
60
63
  const { typedData, signature } = await this.createAndSign(params);
61
- const result = await this.submitSignedGrantWithEvents(typedData, signature);
64
+ const result = await this.submitSignedGrantWithEvents(
65
+ typedData,
66
+ signature,
67
+ options
68
+ );
62
69
  return result;
63
70
  }
64
71
  /**
@@ -86,9 +93,10 @@ class PermissionsController {
86
93
  * console.log(`Permission ID: ${eventData.permissionId}`);
87
94
  * ```
88
95
  */
89
- async submitPermissionGrant(params) {
96
+ async submitPermissionGrant(params, options) {
97
+ this.assertWallet();
90
98
  const { typedData, signature } = await this.createAndSign(params);
91
- return await this.submitSignedGrant(typedData, signature);
99
+ return await this.submitSignedGrant(typedData, signature, options);
92
100
  }
93
101
  /**
94
102
  * Prepares a permission grant with preview before signing.
@@ -115,14 +123,19 @@ class PermissionsController {
115
123
  * const transactionHash = await confirm();
116
124
  * ```
117
125
  */
118
- async prepareGrant(params) {
126
+ async prepareGrant(params, options) {
127
+ this.assertWallet();
119
128
  try {
120
129
  const grantFile = createGrantFile(params);
121
130
  validateGrant(grantFile);
122
131
  return {
123
132
  preview: grantFile,
124
133
  confirm: async () => {
125
- return await this.confirmGrantInternalWithEvents(params, grantFile);
134
+ return await this.confirmGrantInternalWithEvents(
135
+ params,
136
+ grantFile,
137
+ options
138
+ );
126
139
  }
127
140
  };
128
141
  } catch (error) {
@@ -154,22 +167,36 @@ class PermissionsController {
154
167
  * @throws {NetworkError} When IPFS upload fails
155
168
  * @throws {SignatureError} When user rejects the signature
156
169
  */
157
- async confirmGrantInternal(params, grantFile) {
170
+ async confirmGrantInternal(params, grantFile, options) {
158
171
  try {
159
172
  let { grantUrl } = params;
160
173
  console.debug("\u{1F50D} Debug - Grant URL from params:", grantUrl);
161
174
  if (!grantUrl) {
162
- if (!this.context.relayerCallbacks?.storeGrantFile && !this.context.storageManager) {
175
+ const canStoreViaRelayer = this.context.relayer !== void 0;
176
+ if (!canStoreViaRelayer && !this.context.storageManager) {
163
177
  if (this.context.validateStorageRequired) {
164
178
  this.context.validateStorageRequired();
165
179
  } else {
166
180
  throw new Error(
167
- "No storage available. Provide a grantUrl, configure relayerCallbacks.storeGrantFile, or storageManager."
181
+ "No storage available. Provide a grantUrl, configure relayer, or storageManager."
168
182
  );
169
183
  }
170
184
  }
171
- if (this.context.relayerCallbacks?.storeGrantFile) {
172
- grantUrl = await this.context.relayerCallbacks.storeGrantFile(grantFile);
185
+ if (canStoreViaRelayer && this.context.relayer) {
186
+ const request = {
187
+ type: "direct",
188
+ operation: "storeGrantFile",
189
+ params: grantFile
190
+ };
191
+ const response = await this.context.relayer(request);
192
+ if (response.type === "error") {
193
+ throw new Error(response.error);
194
+ }
195
+ if (response.type === "direct" && typeof response.result === "object" && response.result !== null && "url" in response.result) {
196
+ grantUrl = response.result.url;
197
+ } else {
198
+ throw new Error("Invalid response from relayer for grant storage");
199
+ }
173
200
  } else if (this.context.storageManager) {
174
201
  const blob = new Blob([JSON.stringify(grantFile)], {
175
202
  type: "application/json"
@@ -201,7 +228,7 @@ class PermissionsController {
201
228
  nonce
202
229
  });
203
230
  const signature = await this.signTypedData(typedData);
204
- return await this.submitSignedGrant(typedData, signature);
231
+ return await this.submitSignedGrant(typedData, signature, options);
205
232
  } catch (error) {
206
233
  if (error instanceof Error) {
207
234
  if (error instanceof RelayerError || error instanceof UserRejectedRequestError || error instanceof SerializationError || error instanceof SignatureError || error instanceof NetworkError || error instanceof NonceError) {
@@ -246,23 +273,38 @@ class PermissionsController {
246
273
  * ```
247
274
  */
248
275
  async createAndSign(params) {
276
+ this.assertWallet();
249
277
  try {
250
278
  const grantFile = createGrantFile(params);
251
279
  validateGrant(grantFile);
252
280
  let { grantUrl } = params;
253
281
  console.debug("\u{1F50D} Debug - Grant URL from params:", grantUrl);
254
282
  if (!grantUrl) {
255
- if (!this.context.relayerCallbacks?.storeGrantFile && !this.context.storageManager) {
283
+ const canStoreViaRelayer = this.context.relayer !== void 0;
284
+ if (!canStoreViaRelayer && !this.context.storageManager) {
256
285
  if (this.context.validateStorageRequired) {
257
286
  this.context.validateStorageRequired();
258
287
  } else {
259
288
  throw new Error(
260
- "No storage available. Provide a grantUrl, configure relayerCallbacks.storeGrantFile, or storageManager."
289
+ "No storage available. Provide a grantUrl, configure relayer, or storageManager."
261
290
  );
262
291
  }
263
292
  }
264
- if (this.context.relayerCallbacks?.storeGrantFile) {
265
- grantUrl = await this.context.relayerCallbacks.storeGrantFile(grantFile);
293
+ if (canStoreViaRelayer && this.context.relayer) {
294
+ const request = {
295
+ type: "direct",
296
+ operation: "storeGrantFile",
297
+ params: grantFile
298
+ };
299
+ const response = await this.context.relayer(request);
300
+ if (response.type === "error") {
301
+ throw new Error(response.error);
302
+ }
303
+ if (response.type === "direct" && typeof response.result === "object" && response.result !== null && "url" in response.result) {
304
+ grantUrl = response.result.url;
305
+ } else {
306
+ throw new Error("Invalid response from relayer for grant storage");
307
+ }
266
308
  } else if (this.context.storageManager) {
267
309
  const blob = new Blob([JSON.stringify(grantFile)], {
268
310
  type: "application/json"
@@ -331,7 +373,7 @@ class PermissionsController {
331
373
  * );
332
374
  * ```
333
375
  */
334
- async submitSignedGrant(typedData, signature) {
376
+ async submitSignedGrant(typedData, signature, options) {
335
377
  try {
336
378
  console.debug(
337
379
  "\u{1F50D} Debug - submitSignedGrant called with typed data:",
@@ -341,21 +383,49 @@ class PermissionsController {
341
383
  2
342
384
  )
343
385
  );
344
- if (this.context.relayerCallbacks?.submitPermissionGrant) {
345
- const hash = await this.context.relayerCallbacks.submitPermissionGrant(
386
+ if (this.context.relayer) {
387
+ const response = await this.context.relayer({
388
+ type: "signed",
389
+ operation: "submitAddPermission",
346
390
  typedData,
347
- signature
348
- );
349
- const account = this.context.walletClient.account ?? await this.getUserAddress();
391
+ signature,
392
+ expectedUserAddress: this.context.userAddress
393
+ });
394
+ if (response.type === "error") {
395
+ throw new Error(`Relayer error: ${response.error}`);
396
+ }
397
+ let finalHash;
398
+ if (response.type === "submitted") {
399
+ finalHash = response.hash;
400
+ } else if (response.type === "pending") {
401
+ const pollResult = await this.pollRelayerForConfirmation(
402
+ response.operationId,
403
+ options
404
+ );
405
+ finalHash = pollResult.hash;
406
+ } else if (response.type === "confirmed") {
407
+ finalHash = response.hash;
408
+ } else if (response.type === "signed") {
409
+ finalHash = response.hash;
410
+ } else {
411
+ throw new Error(
412
+ "Invalid response from relayer: unexpected response type"
413
+ );
414
+ }
415
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
350
416
  const { tx } = await import("../utils/transactionHelpers");
351
417
  return tx({
352
- hash,
418
+ hash: finalHash,
353
419
  from: typeof account === "string" ? account : account.address,
354
420
  contract: "DataPortabilityPermissions",
355
421
  fn: "addPermission"
356
422
  });
357
423
  } else {
358
- return await this.submitDirectTransaction(typedData, signature);
424
+ return await this.submitDirectTransaction(
425
+ typedData,
426
+ signature,
427
+ options
428
+ );
359
429
  }
360
430
  } catch (error) {
361
431
  if (error instanceof RelayerError || error instanceof NetworkError || error instanceof UserRejectedRequestError || error instanceof SignatureError || error instanceof NonceError) {
@@ -388,7 +458,7 @@ class PermissionsController {
388
458
  * const result = await txHandle.waitForEvents();
389
459
  * ```
390
460
  */
391
- async submitSignedTrustServer(typedData, signature) {
461
+ async submitSignedTrustServer(typedData, signature, options) {
392
462
  try {
393
463
  const trustServerInput = {
394
464
  nonce: BigInt(typedData.message.nonce),
@@ -396,13 +466,14 @@ class PermissionsController {
396
466
  };
397
467
  const hash = await this.submitTrustServerTransaction(
398
468
  trustServerInput,
399
- signature
469
+ signature,
470
+ options
400
471
  );
401
- const account = this.context.walletClient.account ?? await this.getUserAddress();
472
+ const account = this.context.userAddress;
402
473
  const { tx } = await import("../utils/transactionHelpers");
403
474
  return tx({
404
475
  hash,
405
- from: typeof account === "string" ? account : account.address,
476
+ from: account,
406
477
  contract: "DataPortabilityServers",
407
478
  fn: "trustServerWithSignature"
408
479
  });
@@ -451,7 +522,7 @@ class PermissionsController {
451
522
  * const result = await txHandle.waitForEvents();
452
523
  * ```
453
524
  */
454
- async submitSignedAddAndTrustServer(typedData, signature) {
525
+ async submitSignedAddAndTrustServer(typedData, signature, options) {
455
526
  try {
456
527
  const addAndTrustServerInput = {
457
528
  nonce: BigInt(typedData.message.nonce),
@@ -461,9 +532,10 @@ class PermissionsController {
461
532
  };
462
533
  const hash = await this.submitAddAndTrustServerTransaction(
463
534
  addAndTrustServerInput,
464
- signature
535
+ signature,
536
+ options
465
537
  );
466
- const account = this.context.walletClient.account ?? await this.getUserAddress();
538
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
467
539
  const { tx } = await import("../utils/transactionHelpers");
468
540
  return tx({
469
541
  hash,
@@ -489,8 +561,12 @@ class PermissionsController {
489
561
  * @param signature - The user's signature authorizing the transaction
490
562
  * @returns Promise resolving to PermissionGrantResult with parsed events
491
563
  */
492
- async submitSignedGrantWithEvents(typedData, signature) {
493
- const txResult = await this.submitSignedGrant(typedData, signature);
564
+ async submitSignedGrantWithEvents(typedData, signature, options) {
565
+ const txResult = await this.submitSignedGrant(
566
+ typedData,
567
+ signature,
568
+ options
569
+ );
494
570
  if (!this.context.waitForTransactionEvents) {
495
571
  throw new BlockchainError("waitForTransactionEvents not configured");
496
572
  }
@@ -522,8 +598,12 @@ class PermissionsController {
522
598
  * @param grantFile - The pre-created grant file object
523
599
  * @returns Promise resolving to PermissionGrantResult with parsed events
524
600
  */
525
- async confirmGrantInternalWithEvents(params, grantFile) {
526
- const txResult = await this.confirmGrantInternal(params, grantFile);
601
+ async confirmGrantInternalWithEvents(params, grantFile, options) {
602
+ const txResult = await this.confirmGrantInternal(
603
+ params,
604
+ grantFile,
605
+ options
606
+ );
527
607
  if (!this.context.waitForTransactionEvents) {
528
608
  throw new BlockchainError("waitForTransactionEvents not configured");
529
609
  }
@@ -547,6 +627,27 @@ class PermissionsController {
547
627
  fileIds: event.fileIds
548
628
  };
549
629
  }
630
+ /**
631
+ * Polls the relayer for confirmation of a pending operation.
632
+ *
633
+ * @param operationId - The operation ID to poll
634
+ * @param options - Polling configuration including status updates and cancellation
635
+ * @returns Promise resolving to the confirmed hash and receipt
636
+ * @throws {TransactionPendingError} When the operation times out
637
+ * @throws {Error} When the operation fails or is cancelled
638
+ * @internal
639
+ */
640
+ async pollRelayerForConfirmation(operationId, options) {
641
+ if (!this.context.relayer) {
642
+ throw new Error("Relayer not configured for polling");
643
+ }
644
+ const pollingManager = new PollingManager(this.context.relayer);
645
+ return await pollingManager.startPolling(operationId, {
646
+ signal: options?.signal,
647
+ onStatusUpdate: options?.onStatusUpdate,
648
+ ...options?.pollingOptions
649
+ });
650
+ }
550
651
  /**
551
652
  * Submits an already-signed permission revoke transaction to the blockchain.
552
653
  *
@@ -568,21 +669,45 @@ class PermissionsController {
568
669
  * const result = await txHandle.waitForEvents();
569
670
  * ```
570
671
  */
571
- async submitSignedRevoke(typedData, signature) {
672
+ async submitSignedRevoke(typedData, signature, options) {
572
673
  try {
573
674
  let hash;
574
- if (this.context.relayerCallbacks?.submitPermissionRevoke) {
575
- hash = await this.context.relayerCallbacks.submitPermissionRevoke(
675
+ if (this.context.relayer) {
676
+ const response = await this.context.relayer({
677
+ type: "signed",
678
+ operation: "submitPermissionRevoke",
576
679
  typedData,
577
- signature
578
- );
680
+ signature,
681
+ expectedUserAddress: this.context.userAddress
682
+ });
683
+ if (response.type === "error") {
684
+ throw new Error(`Relayer error: ${response.error}`);
685
+ }
686
+ if (response.type === "submitted") {
687
+ hash = response.hash;
688
+ } else if (response.type === "pending") {
689
+ const pollResult = await this.pollRelayerForConfirmation(
690
+ response.operationId,
691
+ options
692
+ );
693
+ hash = pollResult.hash;
694
+ } else if (response.type === "confirmed") {
695
+ hash = response.hash;
696
+ } else if (response.type === "signed") {
697
+ hash = response.hash;
698
+ } else {
699
+ throw new Error(
700
+ "Invalid response from relayer: unexpected response type"
701
+ );
702
+ }
579
703
  } else {
580
704
  hash = await this.submitDirectRevokeTransaction(
581
705
  typedData,
582
- signature
706
+ signature,
707
+ options
583
708
  );
584
709
  }
585
- const account = this.context.walletClient.account ?? await this.getUserAddress();
710
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
586
711
  const { tx } = await import("../utils/transactionHelpers");
587
712
  return tx({
588
713
  hash,
@@ -621,21 +746,36 @@ class PermissionsController {
621
746
  * const result = await txHandle.waitForEvents();
622
747
  * ```
623
748
  */
624
- async submitSignedUntrustServer(typedData, signature) {
749
+ async submitSignedUntrustServer(typedData, signature, options) {
625
750
  try {
626
751
  let hash;
627
- if (this.context.relayerCallbacks?.submitUntrustServer) {
628
- hash = await this.context.relayerCallbacks.submitUntrustServer(
752
+ if (this.context.relayer) {
753
+ const response = await this.context.relayer({
754
+ type: "signed",
755
+ operation: "submitUntrustServer",
629
756
  typedData,
630
- signature
631
- );
757
+ signature,
758
+ expectedUserAddress: this.context.userAddress
759
+ });
760
+ if (response.type === "submitted") {
761
+ hash = response.hash;
762
+ } else if (response.type === "signed") {
763
+ hash = response.hash;
764
+ } else if (response.type === "error") {
765
+ throw new Error(`Relayer error: ${response.error}`);
766
+ } else {
767
+ throw new Error(
768
+ "Invalid response from relayer: expected signed transaction"
769
+ );
770
+ }
632
771
  } else {
633
772
  hash = await this.submitSignedUntrustTransaction(
634
773
  typedData,
635
- signature
774
+ signature,
775
+ options
636
776
  );
637
777
  }
638
- const account = this.context.walletClient.account ?? await this.getUserAddress();
778
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
639
779
  const { tx } = await import("../utils/transactionHelpers");
640
780
  return tx({
641
781
  hash,
@@ -665,8 +805,9 @@ class PermissionsController {
665
805
  * @returns Promise resolving to the transaction hash
666
806
  * @throws {BlockchainError} When contract submission fails
667
807
  */
668
- async submitDirectTransaction(typedData, signature) {
669
- const chainId = await this.context.walletClient.getChainId();
808
+ async submitDirectTransaction(typedData, signature, options) {
809
+ this.assertWallet();
810
+ const chainId = await this.context.publicClient.getChainId();
670
811
  const DataPortabilityPermissionsAddress = getContractAddress(
671
812
  chainId,
672
813
  "DataPortabilityPermissions"
@@ -689,14 +830,15 @@ class PermissionsController {
689
830
  typedData.message.grant?.length ?? 0
690
831
  );
691
832
  const formattedSignature = formatSignatureForContract(signature);
692
- const account = this.context.walletClient.account ?? await this.getUserAddress();
833
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
693
834
  const txHash = await this.context.walletClient.writeContract({
694
835
  address: DataPortabilityPermissionsAddress,
695
836
  abi: DataPortabilityPermissionsAbi,
696
837
  functionName: "addPermission",
697
838
  args: [permissionInput, formattedSignature],
698
839
  account,
699
- chain: this.context.walletClient.chain ?? null
840
+ chain: this.context.walletClient?.chain ?? null,
841
+ ...this.spreadTransactionOptions(options)
700
842
  });
701
843
  const { tx } = await import("../utils/transactionHelpers");
702
844
  return tx({
@@ -731,6 +873,7 @@ class PermissionsController {
731
873
  * ```
732
874
  */
733
875
  async revoke(params) {
876
+ this.assertWallet();
734
877
  const txResult = await this.submitPermissionRevoke(params);
735
878
  if (!this.context.waitForTransactionEvents) {
736
879
  throw new BlockchainError("waitForTransactionEvents not configured");
@@ -759,6 +902,7 @@ class PermissionsController {
759
902
  * Use this when you want to handle transaction confirmation and event parsing separately.
760
903
  *
761
904
  * @param params - Parameters for revoking the permission
905
+ * @param options - Optional transaction options for gas parameters and timeout
762
906
  * @returns Promise resolving to the transaction hash when successfully submitted
763
907
  * @throws {BlockchainError} When revocation transaction fails
764
908
  * @throws {UserRejectedRequestError} When user rejects the transaction
@@ -771,12 +915,13 @@ class PermissionsController {
771
915
  * console.log(`Revocation submitted: ${txHash}`);
772
916
  * ```
773
917
  */
774
- async submitPermissionRevoke(params) {
918
+ async submitPermissionRevoke(params, options) {
919
+ this.assertWallet();
775
920
  try {
776
- if (!this.context.walletClient.chain?.id) {
921
+ if (!this.context.walletClient?.chain?.id) {
777
922
  throw new BlockchainError("Chain ID not available");
778
923
  }
779
- const chainId = await this.context.walletClient.getChainId();
924
+ const chainId = await this.context.publicClient.getChainId();
780
925
  const DataPortabilityPermissionsAddress = getContractAddress(
781
926
  chainId,
782
927
  "DataPortabilityPermissions"
@@ -784,14 +929,25 @@ class PermissionsController {
784
929
  const DataPortabilityPermissionsAbi = getAbi(
785
930
  "DataPortabilityPermissions"
786
931
  );
787
- const account = this.context.walletClient.account ?? await this.getUserAddress();
932
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
788
933
  const txHash = await this.context.walletClient.writeContract({
789
934
  address: DataPortabilityPermissionsAddress,
790
935
  abi: DataPortabilityPermissionsAbi,
791
936
  functionName: "revokePermission",
792
937
  args: [params.permissionId],
793
938
  account,
794
- chain: this.context.walletClient.chain ?? null
939
+ chain: this.context.walletClient?.chain ?? null,
940
+ ...options?.gas && { gas: options.gas },
941
+ ...options?.nonce && { nonce: options.nonce },
942
+ // Use EIP-1559 if available, otherwise fall back to legacy gasPrice
943
+ ...options?.maxFeePerGas || options?.maxPriorityFeePerGas ? {
944
+ ...options.maxFeePerGas && {
945
+ maxFeePerGas: options.maxFeePerGas
946
+ },
947
+ ...options.maxPriorityFeePerGas && {
948
+ maxPriorityFeePerGas: options.maxPriorityFeePerGas
949
+ }
950
+ } : options?.gasPrice && { gasPrice: options.gasPrice }
795
951
  });
796
952
  const { tx } = await import("../utils/transactionHelpers");
797
953
  return tx({
@@ -838,9 +994,10 @@ class PermissionsController {
838
994
  * console.log(`Permission ${result.permissionId} revoked`);
839
995
  * ```
840
996
  */
841
- async submitRevokeWithSignature(params) {
997
+ async submitRevokeWithSignature(params, options) {
998
+ this.assertWallet();
842
999
  try {
843
- if (!this.context.walletClient.chain?.id) {
1000
+ if (!this.context.walletClient?.chain?.id) {
844
1001
  throw new BlockchainError("Chain ID not available");
845
1002
  }
846
1003
  const nonce = await this.getPermissionsUserNonce();
@@ -861,18 +1018,33 @@ class PermissionsController {
861
1018
  };
862
1019
  const signature = await this.signTypedData(typedData);
863
1020
  let hash;
864
- if (this.context.relayerCallbacks?.submitPermissionRevoke) {
865
- hash = await this.context.relayerCallbacks.submitPermissionRevoke(
1021
+ if (this.context.relayer) {
1022
+ const response = await this.context.relayer({
1023
+ type: "signed",
1024
+ operation: "submitPermissionRevoke",
866
1025
  typedData,
867
- signature
868
- );
1026
+ signature,
1027
+ expectedUserAddress: this.context.userAddress
1028
+ });
1029
+ if (response.type === "submitted") {
1030
+ hash = response.hash;
1031
+ } else if (response.type === "signed") {
1032
+ hash = response.hash;
1033
+ } else if (response.type === "error") {
1034
+ throw new Error(`Relayer error: ${response.error}`);
1035
+ } else {
1036
+ throw new Error(
1037
+ "Invalid response from relayer: expected signed transaction"
1038
+ );
1039
+ }
869
1040
  } else {
870
1041
  hash = await this.submitDirectRevokeTransaction(
871
1042
  typedData,
872
- signature
1043
+ signature,
1044
+ options
873
1045
  );
874
1046
  }
875
- const account = this.context.walletClient.account ?? await this.getUserAddress();
1047
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
876
1048
  const { tx } = await import("../utils/transactionHelpers");
877
1049
  return tx({
878
1050
  hash,
@@ -913,8 +1085,8 @@ class PermissionsController {
913
1085
  */
914
1086
  async getServersUserNonce() {
915
1087
  try {
916
- const userAddress = await this.getUserAddress();
917
- const chainId = await this.context.walletClient.getChainId();
1088
+ const userAddress = this.context.userAddress;
1089
+ const chainId = await this.context.publicClient.getChainId();
918
1090
  const DataPortabilityServersAddress = getContractAddress(
919
1091
  chainId,
920
1092
  "DataPortabilityServers"
@@ -959,8 +1131,8 @@ class PermissionsController {
959
1131
  */
960
1132
  async getPermissionsUserNonce() {
961
1133
  try {
962
- const userAddress = await this.getUserAddress();
963
- const chainId = await this.context.walletClient.getChainId();
1134
+ const userAddress = this.context.userAddress;
1135
+ const chainId = await this.context.publicClient.getChainId();
964
1136
  const DataPortabilityPermissionsAddress = getContractAddress(
965
1137
  chainId,
966
1138
  "DataPortabilityPermissions"
@@ -999,7 +1171,7 @@ class PermissionsController {
999
1171
  "\u{1F50D} Debug - Composing permission message with grantUrl:",
1000
1172
  params.grantUrl
1001
1173
  );
1002
- const chainId = await this.context.walletClient.getChainId();
1174
+ const chainId = await this.context.publicClient.getChainId();
1003
1175
  const DataPortabilityGranteesAddress = getContractAddress(
1004
1176
  chainId,
1005
1177
  "DataPortabilityGrantees"
@@ -1108,7 +1280,7 @@ class PermissionsController {
1108
1280
  * @returns Promise resolving to the EIP-712 domain configuration
1109
1281
  */
1110
1282
  async getPermissionDomain() {
1111
- const chainId = await this.context.walletClient.getChainId();
1283
+ const chainId = await this.context.publicClient.getChainId();
1112
1284
  const DataPortabilityPermissionsAddress = getContractAddress(
1113
1285
  chainId,
1114
1286
  "DataPortabilityPermissions"
@@ -1127,8 +1299,9 @@ class PermissionsController {
1127
1299
  * @returns Promise resolving to the cryptographic signature
1128
1300
  */
1129
1301
  async signTypedData(typedData) {
1302
+ this.assertWallet();
1130
1303
  try {
1131
- const walletAddress = this.context.walletClient.account?.address ?? await this.getUserAddress();
1304
+ const walletAddress = this.context.walletClient.account?.address ?? this.context.userAddress;
1132
1305
  return await withSignatureCache(
1133
1306
  this.context.platform.cache,
1134
1307
  walletAddress,
@@ -1154,17 +1327,10 @@ class PermissionsController {
1154
1327
  }
1155
1328
  }
1156
1329
  /**
1157
- * Gets the user's address from the wallet client.
1330
+ * Gets the user's address from the context.
1158
1331
  *
1159
- * @returns Promise resolving to the user's wallet address
1332
+ * @returns The user's address
1160
1333
  */
1161
- async getUserAddress() {
1162
- const addresses = await this.context.walletClient.getAddresses();
1163
- if (addresses.length === 0) {
1164
- throw new BlockchainError("No addresses available in wallet client");
1165
- }
1166
- return addresses[0];
1167
- }
1168
1334
  /**
1169
1335
  * Gets on-chain permission grant data without expensive off-chain resolution.
1170
1336
  *
@@ -1201,9 +1367,11 @@ class PermissionsController {
1201
1367
  * ```
1202
1368
  */
1203
1369
  async getUserPermissionGrantsOnChain(options = {}) {
1204
- const { limit = 50, subgraphUrl } = options;
1370
+ const { limit = 50, fetchAll = false, subgraphUrl } = options;
1371
+ const pageSize = fetchAll ? 100 : limit;
1372
+ const maxResults = fetchAll ? 1e4 : limit;
1205
1373
  try {
1206
- const userAddress = await this.getUserAddress();
1374
+ const userAddress = this.context.userAddress;
1207
1375
  const graphqlEndpoint = subgraphUrl ?? this.context.subgraphUrl;
1208
1376
  if (!graphqlEndpoint) {
1209
1377
  throw new BlockchainError(
@@ -1211,10 +1379,10 @@ class PermissionsController {
1211
1379
  );
1212
1380
  }
1213
1381
  const query = `
1214
- query GetUserPermissions($userId: ID!) {
1382
+ query GetUserPermissions($userId: ID!, $first: Int!, $skip: Int!) {
1215
1383
  user(id: $userId) {
1216
1384
  id
1217
- permissions {
1385
+ permissions(first: $first, skip: $skip, orderBy: addedAtBlock, orderDirection: desc) {
1218
1386
  id
1219
1387
  grant
1220
1388
  nonce
@@ -1232,34 +1400,82 @@ class PermissionsController {
1232
1400
  }
1233
1401
  }
1234
1402
  `;
1235
- const response = await fetch(graphqlEndpoint, {
1236
- method: "POST",
1237
- headers: {
1238
- "Content-Type": "application/json"
1239
- },
1240
- body: JSON.stringify({
1241
- query,
1242
- variables: {
1243
- userId: userAddress.toLowerCase()
1403
+ const allPermissions = [];
1404
+ let currentOffset = 0;
1405
+ if (!fetchAll) {
1406
+ const response = await fetch(graphqlEndpoint, {
1407
+ method: "POST",
1408
+ headers: {
1409
+ "Content-Type": "application/json"
1410
+ },
1411
+ body: JSON.stringify({
1412
+ query,
1413
+ variables: {
1414
+ userId: userAddress.toLowerCase(),
1415
+ first: limit,
1416
+ skip: 0
1417
+ }
1418
+ })
1419
+ });
1420
+ if (!response.ok) {
1421
+ throw new BlockchainError(
1422
+ `Subgraph request failed: ${response.status} ${response.statusText}`
1423
+ );
1424
+ }
1425
+ const result = await response.json();
1426
+ if (result.errors) {
1427
+ throw new BlockchainError(
1428
+ `Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
1429
+ );
1430
+ }
1431
+ const userData = result.data?.user;
1432
+ if (!userData?.permissions?.length) {
1433
+ return [];
1434
+ }
1435
+ allPermissions.push(...userData.permissions);
1436
+ } else {
1437
+ while (allPermissions.length < maxResults) {
1438
+ const currentLimit = Math.min(
1439
+ pageSize,
1440
+ maxResults - allPermissions.length
1441
+ );
1442
+ const response = await fetch(graphqlEndpoint, {
1443
+ method: "POST",
1444
+ headers: {
1445
+ "Content-Type": "application/json"
1446
+ },
1447
+ body: JSON.stringify({
1448
+ query,
1449
+ variables: {
1450
+ userId: userAddress.toLowerCase(),
1451
+ first: currentLimit,
1452
+ skip: currentOffset
1453
+ }
1454
+ })
1455
+ });
1456
+ if (!response.ok) {
1457
+ throw new BlockchainError(
1458
+ `Subgraph request failed: ${response.status} ${response.statusText}`
1459
+ );
1244
1460
  }
1245
- })
1246
- });
1247
- if (!response.ok) {
1248
- throw new BlockchainError(
1249
- `Subgraph request failed: ${response.status} ${response.statusText}`
1250
- );
1251
- }
1252
- const result = await response.json();
1253
- if (result.errors) {
1254
- throw new BlockchainError(
1255
- `Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
1256
- );
1257
- }
1258
- const userData = result.data?.user;
1259
- if (!userData?.permissions?.length) {
1260
- return [];
1461
+ const result = await response.json();
1462
+ if (result.errors) {
1463
+ throw new BlockchainError(
1464
+ `Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
1465
+ );
1466
+ }
1467
+ const userData = result.data?.user;
1468
+ if (!userData?.permissions?.length) {
1469
+ break;
1470
+ }
1471
+ allPermissions.push(...userData.permissions);
1472
+ if (userData.permissions.length < currentLimit) {
1473
+ break;
1474
+ }
1475
+ currentOffset += userData.permissions.length;
1476
+ }
1261
1477
  }
1262
- const onChainGrants = userData.permissions.slice(0, limit).map(
1478
+ const onChainGrants = allPermissions.map(
1263
1479
  (permission) => ({
1264
1480
  id: BigInt(permission.id),
1265
1481
  grantUrl: permission.grant,
@@ -1323,6 +1539,7 @@ class PermissionsController {
1323
1539
  * ```
1324
1540
  */
1325
1541
  async addAndTrustServer(params) {
1542
+ this.assertWallet();
1326
1543
  try {
1327
1544
  const chainId = await this.context.walletClient.getChainId();
1328
1545
  const DataPortabilityServersAddress = getContractAddress(
@@ -1330,7 +1547,7 @@ class PermissionsController {
1330
1547
  "DataPortabilityServers"
1331
1548
  );
1332
1549
  const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
1333
- const account = this.context.walletClient.account ?? await this.getUserAddress();
1550
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
1334
1551
  const userAddress = typeof account === "string" ? account : account.address;
1335
1552
  const normalizedUserAddress = getAddress(userAddress);
1336
1553
  const normalizedServerAddress = getAddress(params.serverAddress);
@@ -1347,7 +1564,7 @@ class PermissionsController {
1347
1564
  }
1348
1565
  ],
1349
1566
  account,
1350
- chain: this.context.walletClient.chain ?? null
1567
+ chain: this.context.walletClient?.chain ?? null
1351
1568
  });
1352
1569
  const { tx } = await import("../utils/transactionHelpers");
1353
1570
  const txResult = tx({
@@ -1399,6 +1616,7 @@ class PermissionsController {
1399
1616
  * @deprecated Use addAndTrustServer instead
1400
1617
  */
1401
1618
  async submitTrustServer(params) {
1619
+ this.assertWallet();
1402
1620
  try {
1403
1621
  const chainId = await this.context.walletClient.getChainId();
1404
1622
  const DataPortabilityServersAddress = getContractAddress(
@@ -1406,14 +1624,14 @@ class PermissionsController {
1406
1624
  "DataPortabilityServers"
1407
1625
  );
1408
1626
  const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
1409
- const account = this.context.walletClient.account ?? await this.getUserAddress();
1627
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
1410
1628
  const txHash = await this.context.walletClient.writeContract({
1411
1629
  address: DataPortabilityServersAddress,
1412
1630
  abi: DataPortabilityServersAbi,
1413
1631
  functionName: "trustServer",
1414
1632
  args: [BigInt(params.serverId)],
1415
1633
  account,
1416
- chain: this.context.walletClient.chain ?? null
1634
+ chain: this.context.walletClient?.chain ?? null
1417
1635
  });
1418
1636
  const { tx } = await import("../utils/transactionHelpers");
1419
1637
  return tx({
@@ -1438,7 +1656,8 @@ class PermissionsController {
1438
1656
  * @param params - Parameters for adding and trusting the server
1439
1657
  * @returns Promise resolving to TransactionResult with ServerTrustResult event data
1440
1658
  */
1441
- async submitAddAndTrustServerWithSignature(params) {
1659
+ async submitAddAndTrustServerWithSignature(params, options) {
1660
+ this.assertWallet();
1442
1661
  try {
1443
1662
  const nonce = await this.getServersUserNonce();
1444
1663
  const serverAddress = getAddress(params.serverAddress);
@@ -1462,18 +1681,32 @@ class PermissionsController {
1462
1681
  const signature = await this.signTypedData(typedData);
1463
1682
  console.debug("\u{1F50D} Generated signature:", signature);
1464
1683
  let hash;
1465
- if (this.context.relayerCallbacks?.submitAddAndTrustServer) {
1466
- hash = await this.context.relayerCallbacks.submitAddAndTrustServer(
1684
+ if (this.context.relayer) {
1685
+ const request = {
1686
+ type: "signed",
1687
+ operation: "submitAddAndTrustServer",
1467
1688
  typedData,
1468
1689
  signature
1469
- );
1690
+ };
1691
+ const response = await this.context.relayer(request);
1692
+ if (response.type === "error") {
1693
+ throw new RelayerError(response.error);
1694
+ }
1695
+ if (response.type === "submitted") {
1696
+ hash = response.hash;
1697
+ } else if (response.type === "signed") {
1698
+ hash = response.hash;
1699
+ } else {
1700
+ throw new Error("Unexpected response type from relayer");
1701
+ }
1470
1702
  } else {
1471
1703
  hash = await this.submitAddAndTrustServerTransaction(
1472
1704
  addAndTrustServerInput,
1473
- signature
1705
+ signature,
1706
+ options
1474
1707
  );
1475
1708
  }
1476
- const account = this.context.walletClient.account ?? await this.getUserAddress();
1709
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
1477
1710
  const { tx } = await import("../utils/transactionHelpers");
1478
1711
  return tx({
1479
1712
  hash,
@@ -1509,7 +1742,8 @@ class PermissionsController {
1509
1742
  * @throws {ServerUrlMismatchError} When server URL doesn't match existing registration
1510
1743
  * @throws {BlockchainError} When trust operation fails for any other reason
1511
1744
  */
1512
- async submitTrustServerWithSignature(params) {
1745
+ async submitTrustServerWithSignature(params, options) {
1746
+ this.assertWallet();
1513
1747
  try {
1514
1748
  const nonce = await this.getServersUserNonce();
1515
1749
  const trustServerInput = {
@@ -1519,18 +1753,32 @@ class PermissionsController {
1519
1753
  const typedData = await this.composeTrustServerMessage(trustServerInput);
1520
1754
  const signature = await this.signTypedData(typedData);
1521
1755
  let hash;
1522
- if (this.context.relayerCallbacks?.submitTrustServer) {
1523
- hash = await this.context.relayerCallbacks.submitTrustServer(
1756
+ if (this.context.relayer) {
1757
+ const request = {
1758
+ type: "signed",
1759
+ operation: "submitTrustServer",
1524
1760
  typedData,
1525
1761
  signature
1526
- );
1762
+ };
1763
+ const response = await this.context.relayer(request);
1764
+ if (response.type === "error") {
1765
+ throw new RelayerError(response.error);
1766
+ }
1767
+ if (response.type === "submitted") {
1768
+ hash = response.hash;
1769
+ } else if (response.type === "signed") {
1770
+ hash = response.hash;
1771
+ } else {
1772
+ throw new Error("Unexpected response type from relayer");
1773
+ }
1527
1774
  } else {
1528
1775
  hash = await this.submitTrustServerTransaction(
1529
1776
  trustServerInput,
1530
- signature
1777
+ signature,
1778
+ options
1531
1779
  );
1532
1780
  }
1533
- const account = this.context.walletClient.account ?? await this.getUserAddress();
1781
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
1534
1782
  const { tx } = await import("../utils/transactionHelpers");
1535
1783
  return tx({
1536
1784
  hash,
@@ -1568,7 +1816,8 @@ class PermissionsController {
1568
1816
  * @returns Promise resolving to TransactionResult for transaction tracking
1569
1817
  * @throws {BlockchainError} When contract submission fails
1570
1818
  */
1571
- async submitDirectUntrustTransaction(params) {
1819
+ async submitDirectUntrustTransaction(params, options) {
1820
+ this.assertWallet();
1572
1821
  try {
1573
1822
  const chainId = await this.context.walletClient.getChainId();
1574
1823
  const DataPortabilityServersAddress = getContractAddress(
@@ -1576,14 +1825,25 @@ class PermissionsController {
1576
1825
  "DataPortabilityServers"
1577
1826
  );
1578
1827
  const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
1579
- const account = this.context.walletClient.account ?? await this.getUserAddress();
1828
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
1580
1829
  const txHash = await this.context.walletClient.writeContract({
1581
1830
  address: DataPortabilityServersAddress,
1582
1831
  abi: DataPortabilityServersAbi,
1583
1832
  functionName: "untrustServer",
1584
1833
  args: [BigInt(params.serverId)],
1585
1834
  account,
1586
- chain: this.context.walletClient.chain ?? null
1835
+ chain: this.context.walletClient?.chain ?? null,
1836
+ ...options?.gas && { gas: options.gas },
1837
+ ...options?.nonce && { nonce: options.nonce },
1838
+ // Use EIP-1559 if available, otherwise fall back to legacy gasPrice
1839
+ ...options?.maxFeePerGas || options?.maxPriorityFeePerGas ? {
1840
+ ...options.maxFeePerGas && {
1841
+ maxFeePerGas: options.maxFeePerGas
1842
+ },
1843
+ ...options.maxPriorityFeePerGas && {
1844
+ maxPriorityFeePerGas: options.maxPriorityFeePerGas
1845
+ }
1846
+ } : options?.gasPrice && { gasPrice: options.gasPrice }
1587
1847
  });
1588
1848
  const { tx } = await import("../utils/transactionHelpers");
1589
1849
  return tx({
@@ -1610,6 +1870,7 @@ class PermissionsController {
1610
1870
  *
1611
1871
  * @param params - Parameters for untrusting the server
1612
1872
  * @param params.serverId - The numeric ID of the server to untrust
1873
+ * @param options - Optional transaction options for gas parameters and timeout
1613
1874
  * @returns Promise resolving to transaction hash
1614
1875
  * @throws {Error} When wallet account is not available
1615
1876
  * @throws {NonceError} When retrieving user nonce fails
@@ -1630,13 +1891,17 @@ class PermissionsController {
1630
1891
  * console.log('Still trusting servers:', trustedServers);
1631
1892
  * ```
1632
1893
  */
1633
- async submitUntrustServer(params) {
1894
+ async submitUntrustServer(params, options) {
1895
+ this.assertWallet();
1634
1896
  const nonce = await this.getServersUserNonce();
1635
1897
  const untrustServerInput = {
1636
1898
  nonce,
1637
1899
  serverId: params.serverId
1638
1900
  };
1639
- return await this.submitDirectUntrustTransaction(untrustServerInput);
1901
+ return await this.submitDirectUntrustTransaction(
1902
+ untrustServerInput,
1903
+ options
1904
+ );
1640
1905
  }
1641
1906
  /**
1642
1907
  * Untrusts a server using a signature (gasless transaction).
@@ -1651,6 +1916,7 @@ class PermissionsController {
1651
1916
  * @throws {BlockchainError} When untrust transaction fails
1652
1917
  */
1653
1918
  async submitUntrustServerWithSignature(params) {
1919
+ this.assertWallet();
1654
1920
  try {
1655
1921
  const nonce = await this.getServersUserNonce();
1656
1922
  const untrustServerInput = {
@@ -1660,15 +1926,28 @@ class PermissionsController {
1660
1926
  const typedData = await this.composeUntrustServerMessage(untrustServerInput);
1661
1927
  const signature = await this.signTypedData(typedData);
1662
1928
  let hash;
1663
- if (this.context.relayerCallbacks?.submitUntrustServer) {
1664
- hash = await this.context.relayerCallbacks.submitUntrustServer(
1929
+ if (this.context.relayer) {
1930
+ const request = {
1931
+ type: "signed",
1932
+ operation: "submitUntrustServer",
1665
1933
  typedData,
1666
1934
  signature
1667
- );
1935
+ };
1936
+ const response = await this.context.relayer(request);
1937
+ if (response.type === "error") {
1938
+ throw new RelayerError(response.error);
1939
+ }
1940
+ if (response.type === "submitted") {
1941
+ hash = response.hash;
1942
+ } else if (response.type === "signed") {
1943
+ hash = response.hash;
1944
+ } else {
1945
+ throw new Error("Unexpected response type from relayer");
1946
+ }
1668
1947
  } else {
1669
1948
  hash = await this.submitSignedUntrustTransaction(typedData, signature);
1670
1949
  }
1671
- const account = this.context.walletClient.account ?? await this.getUserAddress();
1950
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
1672
1951
  const { tx } = await import("../utils/transactionHelpers");
1673
1952
  return tx({
1674
1953
  hash,
@@ -1713,8 +1992,8 @@ class PermissionsController {
1713
1992
  */
1714
1993
  async getTrustedServers(userAddress) {
1715
1994
  try {
1716
- const user = userAddress ?? await this.getUserAddress();
1717
- const chainId = await this.context.walletClient.getChainId();
1995
+ const user = userAddress ?? this.context.userAddress;
1996
+ const chainId = await this.context.publicClient.getChainId();
1718
1997
  const DataPortabilityServersAddress = getContractAddress(
1719
1998
  chainId,
1720
1999
  "DataPortabilityServers"
@@ -1743,8 +2022,8 @@ class PermissionsController {
1743
2022
  */
1744
2023
  async getTrustedServersCount(userAddress) {
1745
2024
  try {
1746
- const user = userAddress ?? await this.getUserAddress();
1747
- const chainId = await this.context.walletClient.getChainId();
2025
+ const user = userAddress ?? this.context.userAddress;
2026
+ const chainId = await this.context.publicClient.getChainId();
1748
2027
  const DataPortabilityServersAddress = getContractAddress(
1749
2028
  chainId,
1750
2029
  "DataPortabilityServers"
@@ -1773,10 +2052,10 @@ class PermissionsController {
1773
2052
  */
1774
2053
  async getTrustedServersPaginated(options = {}) {
1775
2054
  try {
1776
- const user = options.userAddress ?? await this.getUserAddress();
2055
+ const user = options.userAddress ?? this.context.userAddress;
1777
2056
  const limit = options.limit ?? 50;
1778
2057
  const offset = options.offset ?? 0;
1779
- const chainId = await this.context.walletClient.getChainId();
2058
+ const chainId = await this.context.publicClient.getChainId();
1780
2059
  const DataPortabilityServersAddress = getContractAddress(
1781
2060
  chainId,
1782
2061
  "DataPortabilityServers"
@@ -1922,7 +2201,7 @@ class PermissionsController {
1922
2201
  };
1923
2202
  }
1924
2203
  try {
1925
- const chainId = await this.context.walletClient.getChainId();
2204
+ const chainId = await this.context.publicClient.getChainId();
1926
2205
  const DataPortabilityServersAddress = getContractAddress(
1927
2206
  chainId,
1928
2207
  "DataPortabilityServers"
@@ -1997,7 +2276,7 @@ class PermissionsController {
1997
2276
  */
1998
2277
  async checkServerTrustStatus(serverId, userAddress) {
1999
2278
  try {
2000
- const user = userAddress ?? await this.getUserAddress();
2279
+ const user = userAddress ?? this.context.userAddress;
2001
2280
  const trustedServers = await this.getTrustedServers(user);
2002
2281
  const trustIndex = trustedServers.findIndex(
2003
2282
  (server) => server === serverId
@@ -2087,7 +2366,7 @@ class PermissionsController {
2087
2366
  * @returns Promise resolving to the EIP-712 domain configuration
2088
2367
  */
2089
2368
  async getServersDomain() {
2090
- const chainId = await this.context.walletClient.getChainId();
2369
+ const chainId = await this.context.publicClient.getChainId();
2091
2370
  const DataPortabilityServersAddress = getContractAddress(
2092
2371
  chainId,
2093
2372
  "DataPortabilityServers"
@@ -2106,7 +2385,8 @@ class PermissionsController {
2106
2385
  * @param signature - The cryptographic signature for the transaction
2107
2386
  * @returns Promise resolving to the transaction hash
2108
2387
  */
2109
- async submitAddAndTrustServerTransaction(addAndTrustServerInput, signature) {
2388
+ async submitAddAndTrustServerTransaction(addAndTrustServerInput, signature, options) {
2389
+ this.assertWallet();
2110
2390
  const chainId = await this.context.walletClient.getChainId();
2111
2391
  const DataPortabilityServersAddress = getContractAddress(
2112
2392
  chainId,
@@ -2138,8 +2418,17 @@ class PermissionsController {
2138
2418
  },
2139
2419
  formattedSignature
2140
2420
  ],
2141
- account: this.context.walletClient.account ?? await this.getUserAddress(),
2142
- chain: this.context.walletClient.chain ?? null
2421
+ account: this.context.walletClient?.account ?? this.context.userAddress,
2422
+ chain: this.context.walletClient?.chain ?? null,
2423
+ ...options && {
2424
+ gas: options.gas,
2425
+ nonce: options.nonce,
2426
+ // Use EIP-1559 gas pricing if available, otherwise legacy
2427
+ ...options.maxFeePerGas || options.maxPriorityFeePerGas ? {
2428
+ maxFeePerGas: options.maxFeePerGas,
2429
+ maxPriorityFeePerGas: options.maxPriorityFeePerGas
2430
+ } : options.gasPrice ? { gasPrice: options.gasPrice } : {}
2431
+ }
2143
2432
  });
2144
2433
  return txHash;
2145
2434
  }
@@ -2150,7 +2439,8 @@ class PermissionsController {
2150
2439
  * @param signature - The cryptographic signature for the transaction
2151
2440
  * @returns Promise resolving to the transaction hash
2152
2441
  */
2153
- async submitTrustServerTransaction(trustServerInput, signature) {
2442
+ async submitTrustServerTransaction(trustServerInput, signature, options) {
2443
+ this.assertWallet();
2154
2444
  const chainId = await this.context.walletClient.getChainId();
2155
2445
  const DataPortabilityServersAddress = getContractAddress(
2156
2446
  chainId,
@@ -2169,8 +2459,9 @@ class PermissionsController {
2169
2459
  },
2170
2460
  formattedSignature
2171
2461
  ],
2172
- account: this.context.walletClient.account ?? await this.getUserAddress(),
2173
- chain: this.context.walletClient.chain ?? null
2462
+ account: this.context.walletClient?.account ?? this.context.userAddress,
2463
+ chain: this.context.walletClient?.chain ?? null,
2464
+ ...this.spreadTransactionOptions(options)
2174
2465
  });
2175
2466
  return txHash;
2176
2467
  }
@@ -2181,7 +2472,8 @@ class PermissionsController {
2181
2472
  * @param signature - The cryptographic signature authorizing the revoke
2182
2473
  * @returns Promise resolving to the transaction hash
2183
2474
  */
2184
- async submitDirectRevokeTransaction(typedData, signature) {
2475
+ async submitDirectRevokeTransaction(typedData, signature, options) {
2476
+ this.assertWallet();
2185
2477
  const chainId = await this.context.walletClient.getChainId();
2186
2478
  const DataPortabilityPermissionsAddress = getContractAddress(
2187
2479
  chainId,
@@ -2194,8 +2486,17 @@ class PermissionsController {
2194
2486
  abi: DataPortabilityPermissionsAbi,
2195
2487
  functionName: "revokePermissionWithSignature",
2196
2488
  args: [typedData.message, formattedSignature],
2197
- account: this.context.walletClient.account ?? await this.getUserAddress(),
2198
- chain: this.context.walletClient.chain ?? null
2489
+ account: this.context.walletClient?.account ?? this.context.userAddress,
2490
+ chain: this.context.walletClient?.chain ?? null,
2491
+ ...options && {
2492
+ gas: options.gas,
2493
+ nonce: options.nonce,
2494
+ // Use EIP-1559 gas pricing if available, otherwise legacy
2495
+ ...options.maxFeePerGas || options.maxPriorityFeePerGas ? {
2496
+ maxFeePerGas: options.maxFeePerGas,
2497
+ maxPriorityFeePerGas: options.maxPriorityFeePerGas
2498
+ } : options.gasPrice ? { gasPrice: options.gasPrice } : {}
2499
+ }
2199
2500
  });
2200
2501
  return txHash;
2201
2502
  }
@@ -2206,7 +2507,8 @@ class PermissionsController {
2206
2507
  * @param signature - The cryptographic signature authorizing the untrust
2207
2508
  * @returns Promise resolving to the transaction hash
2208
2509
  */
2209
- async submitSignedUntrustTransaction(typedData, signature) {
2510
+ async submitSignedUntrustTransaction(typedData, signature, options) {
2511
+ this.assertWallet();
2210
2512
  const chainId = await this.context.walletClient.getChainId();
2211
2513
  const DataPortabilityServersAddress = getContractAddress(
2212
2514
  chainId,
@@ -2223,8 +2525,17 @@ class PermissionsController {
2223
2525
  abi: DataPortabilityServersAbi,
2224
2526
  functionName: "untrustServerWithSignature",
2225
2527
  args: [contractMessage, formattedSignature],
2226
- account: this.context.walletClient.account ?? await this.getUserAddress(),
2227
- chain: this.context.walletClient.chain ?? null
2528
+ account: this.context.walletClient?.account ?? this.context.userAddress,
2529
+ chain: this.context.walletClient?.chain ?? null,
2530
+ ...options && {
2531
+ gas: options.gas,
2532
+ nonce: options.nonce,
2533
+ // Use EIP-1559 gas pricing if available, otherwise legacy
2534
+ ...options.maxFeePerGas || options.maxPriorityFeePerGas ? {
2535
+ maxFeePerGas: options.maxFeePerGas,
2536
+ maxPriorityFeePerGas: options.maxPriorityFeePerGas
2537
+ } : options.gasPrice ? { gasPrice: options.gasPrice } : {}
2538
+ }
2228
2539
  });
2229
2540
  return txHash;
2230
2541
  }
@@ -2237,14 +2548,18 @@ class PermissionsController {
2237
2548
  * A grantee is an entity (like an application) that can receive data permissions
2238
2549
  * from users. Once registered, users can grant the grantee access to their data.
2239
2550
  *
2551
+ * This method supports gasless transactions via relayer when configured.
2552
+ * If no relayer is available, it falls back to direct wallet transactions.
2553
+ *
2240
2554
  * @param params - Parameters for registering the grantee
2241
2555
  * @param params.owner - The Ethereum address that will own this grantee registration
2242
2556
  * @param params.granteeAddress - The Ethereum address of the grantee (application)
2243
2557
  * @param params.publicKey - The public key used for data encryption/decryption (hex string)
2558
+ * @param options - Optional transaction options for gas parameters and timeout
2244
2559
  * @returns Promise resolving to the transaction hash
2245
2560
  * @throws {BlockchainError} When the grantee registration transaction fails
2246
2561
  * @throws {UserRejectedRequestError} When user rejects the transaction
2247
- * @throws {ContractError} When grantee is already registered
2562
+ * @throws {RelayerError} When gasless transaction submission fails
2248
2563
  *
2249
2564
  * @example
2250
2565
  * ```typescript
@@ -2256,98 +2571,88 @@ class PermissionsController {
2256
2571
  * console.log(`Grantee registered in transaction: ${txHash}`);
2257
2572
  * ```
2258
2573
  */
2259
- async submitRegisterGrantee(params) {
2260
- const chainId = await this.context.walletClient.getChainId();
2261
- const DataPortabilityGranteesAddress = getContractAddress(
2262
- chainId,
2263
- "DataPortabilityGrantees"
2264
- );
2265
- const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
2266
- const ownerAddress = getAddress(params.owner);
2267
- const granteeAddress = getAddress(params.granteeAddress);
2268
- const account = this.context.walletClient.account ?? await this.getUserAddress();
2269
- const txHash = await this.context.walletClient.writeContract({
2270
- address: DataPortabilityGranteesAddress,
2271
- abi: DataPortabilityGranteesAbi,
2272
- functionName: "registerGrantee",
2273
- args: [ownerAddress, granteeAddress, params.publicKey],
2274
- account,
2275
- chain: this.context.walletClient.chain ?? null
2276
- });
2277
- const { tx } = await import("../utils/transactionHelpers");
2278
- return tx({
2279
- hash: txHash,
2280
- from: typeof account === "string" ? account : account.address,
2281
- contract: "DataPortabilityGrantees",
2282
- fn: "registerGrantee"
2283
- });
2284
- }
2285
- /**
2286
- * Registers a grantee with a signature (gasless transaction)
2287
- *
2288
- * @param params - Parameters for registering the grantee
2289
- * @returns Promise resolving to the transaction hash
2290
- *
2291
- * @example
2292
- * ```typescript
2293
- * const txHash = await vana.permissions.registerGranteeWithSignature({
2294
- * owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
2295
- * granteeAddress: "0xApp1234567890123456789012345678901234567890",
2296
- * publicKey: "0x1234567890abcdef..."
2297
- * });
2298
- * ```
2299
- */
2300
- async submitRegisterGranteeWithSignature(params) {
2301
- const nonce = await this.getServersUserNonce();
2302
- const owner = getAddress(params.owner);
2303
- const granteeAddress = getAddress(params.granteeAddress);
2304
- const registerGranteeInput = {
2305
- nonce,
2306
- owner,
2307
- granteeAddress,
2308
- publicKey: params.publicKey
2309
- };
2310
- const typedData = await this.buildRegisterGranteeTypedData(registerGranteeInput);
2311
- const signature = await this.signTypedData(typedData);
2312
- const hash = await this.submitSignedRegisterGranteeTransaction(
2313
- typedData,
2314
- signature
2315
- );
2316
- const account = this.context.walletClient.account ?? await this.getUserAddress();
2317
- const { tx } = await import("../utils/transactionHelpers");
2318
- return tx({
2319
- hash,
2320
- from: typeof account === "string" ? account : account.address,
2321
- contract: "DataPortabilityGrantees",
2322
- fn: "registerGrantee"
2323
- });
2324
- }
2325
- /**
2326
- * Submits a signed register grantee transaction via relayer
2327
- *
2328
- * @param typedData - The EIP-712 typed data for register grantee
2329
- * @param signature - The cryptographic signature
2330
- * @returns Promise resolving to the transaction hash
2331
- *
2332
- * @example
2333
- * ```typescript
2334
- * const result = await vana.permissions.submitSignedRegisterGrantee(typedData, signature);
2335
- * ```
2336
- */
2337
- async submitSignedRegisterGrantee(typedData, signature) {
2338
- const hash = await this.submitSignedRegisterGranteeTransaction(
2339
- typedData,
2340
- signature
2341
- );
2342
- const account = this.context.walletClient.account ?? await this.getUserAddress();
2343
- const { tx } = await import("../utils/transactionHelpers");
2344
- return tx({
2345
- hash,
2346
- from: typeof account === "string" ? account : account.address,
2347
- contract: "DataPortabilityGrantees",
2348
- fn: "registerGrantee"
2349
- });
2574
+ async submitRegisterGrantee(params, options) {
2575
+ try {
2576
+ let hash;
2577
+ if (this.context.relayer) {
2578
+ const request = {
2579
+ type: "direct",
2580
+ operation: "submitRegisterGrantee",
2581
+ params: {
2582
+ owner: params.owner,
2583
+ granteeAddress: params.granteeAddress,
2584
+ publicKey: params.publicKey
2585
+ }
2586
+ };
2587
+ const response = await this.context.relayer(request);
2588
+ if (response.type === "error") {
2589
+ throw new RelayerError(response.error);
2590
+ }
2591
+ if (response.type === "submitted") {
2592
+ hash = response.hash;
2593
+ } else if (response.type === "direct") {
2594
+ const result = response.result;
2595
+ hash = result.transactionHash;
2596
+ } else {
2597
+ throw new Error("Unexpected response type from relayer");
2598
+ }
2599
+ } else {
2600
+ this.assertWallet();
2601
+ const chainId = await this.context.walletClient.getChainId();
2602
+ const DataPortabilityGranteesAddress = getContractAddress(
2603
+ chainId,
2604
+ "DataPortabilityGrantees"
2605
+ );
2606
+ const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
2607
+ const ownerAddress = getAddress(params.owner);
2608
+ const granteeAddress = getAddress(params.granteeAddress);
2609
+ const account2 = this.context.walletClient?.account ?? this.context.userAddress;
2610
+ hash = await this.context.walletClient.writeContract({
2611
+ address: DataPortabilityGranteesAddress,
2612
+ abi: DataPortabilityGranteesAbi,
2613
+ functionName: "registerGrantee",
2614
+ args: [ownerAddress, granteeAddress, params.publicKey],
2615
+ account: account2,
2616
+ chain: this.context.walletClient?.chain ?? null,
2617
+ ...this.spreadTransactionOptions(options)
2618
+ });
2619
+ }
2620
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
2621
+ const { tx } = await import("../utils/transactionHelpers");
2622
+ return tx({
2623
+ hash,
2624
+ from: typeof account === "string" ? account : account.address,
2625
+ contract: "DataPortabilityGrantees",
2626
+ fn: "registerGrantee"
2627
+ });
2628
+ } catch (error) {
2629
+ if (error instanceof Error) {
2630
+ if (error instanceof RelayerError || error instanceof UserRejectedRequestError || error instanceof SerializationError || error instanceof SignatureError || error instanceof BlockchainError) {
2631
+ throw error;
2632
+ }
2633
+ if (error.name === "ContractFunctionExecutionError") {
2634
+ throw new BlockchainError(
2635
+ `Grantee registration failed: ${error.message}`,
2636
+ error
2637
+ );
2638
+ }
2639
+ if (error.name === "UserRejectedRequestError") {
2640
+ throw new UserRejectedRequestError(
2641
+ "User rejected the grantee registration transaction"
2642
+ );
2643
+ }
2644
+ throw new BlockchainError(
2645
+ `Failed to register grantee: ${error.message}`,
2646
+ error
2647
+ );
2648
+ }
2649
+ throw new BlockchainError(`Failed to register grantee: ${String(error)}`);
2650
+ }
2350
2651
  }
2652
+ // TODO: When DataPortabilityGrantees contract adds registerGranteeWithSignature function,
2653
+ // implement submitRegisterGranteeWithSignature and submitSignedRegisterGrantee methods
2654
+ // to support EIP-712 signed gasless transactions via relayer.
2655
+ // Current implementation above supports direct gasless transactions (relayer pays gas directly).
2351
2656
  /**
2352
2657
  * Retrieves all registered grantees from the DataPortabilityGrantees contract.
2353
2658
  *
@@ -2395,27 +2700,52 @@ class PermissionsController {
2395
2700
  const total = Number(totalCount);
2396
2701
  const limit = options.limit ?? 50;
2397
2702
  const offset = options.offset ?? 0;
2398
- const grantees = [];
2399
- const endIndex = Math.min(offset + limit, total);
2400
- for (let i = offset; i < endIndex; i++) {
2401
- try {
2402
- const granteeInfo = await this.context.publicClient.readContract({
2403
- address: DataPortabilityGranteesAddress,
2404
- abi: DataPortabilityGranteesAbi,
2405
- functionName: "grantees",
2406
- args: [BigInt(i + 1)]
2407
- // Grantee IDs are 1-indexed
2408
- });
2409
- grantees.push({
2410
- id: i + 1,
2411
- owner: granteeInfo.owner,
2412
- address: granteeInfo.granteeAddress,
2413
- publicKey: granteeInfo.publicKey,
2414
- permissionIds: granteeInfo.permissionIds.map((id) => Number(id))
2415
- });
2416
- } catch (error) {
2417
- console.warn(`Failed to fetch grantee ${i + 1}:`, error);
2418
- }
2703
+ const includePermissions = options.includePermissions ?? true;
2704
+ const startId = total - offset;
2705
+ const endId = Math.max(startId - limit + 1, 1);
2706
+ const granteeIds = Array.from(
2707
+ { length: startId - endId + 1 },
2708
+ (_, i) => startId - i
2709
+ // Generate IDs in descending order
2710
+ );
2711
+ let grantees;
2712
+ if (includePermissions) {
2713
+ const granteePromises = granteeIds.map(
2714
+ (granteeId) => this.getGranteeById(granteeId)
2715
+ );
2716
+ const granteeResults = await Promise.all(granteePromises);
2717
+ grantees = granteeResults.filter(
2718
+ (grantee) => grantee !== null
2719
+ );
2720
+ } else {
2721
+ const granteeInfoPromises = granteeIds.map(
2722
+ async (granteeId) => {
2723
+ try {
2724
+ const granteeInfo = await this.context.publicClient.readContract({
2725
+ address: DataPortabilityGranteesAddress,
2726
+ abi: DataPortabilityGranteesAbi,
2727
+ functionName: "granteesV2",
2728
+ args: [BigInt(granteeId)]
2729
+ });
2730
+ const grantee = {
2731
+ id: granteeId,
2732
+ owner: granteeInfo.owner,
2733
+ address: granteeInfo.granteeAddress,
2734
+ publicKey: granteeInfo.publicKey,
2735
+ permissionIds: []
2736
+ // TypeScript infers number[] from Grantee type
2737
+ };
2738
+ return grantee;
2739
+ } catch (error) {
2740
+ console.warn(`Failed to fetch grantee ${granteeId}:`, error);
2741
+ return null;
2742
+ }
2743
+ }
2744
+ );
2745
+ const granteeInfoResults = await Promise.all(granteeInfoPromises);
2746
+ grantees = granteeInfoResults.filter(
2747
+ (grantee) => grantee !== null
2748
+ );
2419
2749
  }
2420
2750
  return {
2421
2751
  grantees,
@@ -2426,15 +2756,16 @@ class PermissionsController {
2426
2756
  };
2427
2757
  }
2428
2758
  /**
2429
- * Retrieves a specific grantee by their Ethereum address from the DataPortabilityGrantees contract.
2759
+ * Retrieves a specific grantee by their Ethereum wallet address.
2430
2760
  *
2761
+ * @remarks
2431
2762
  * Looks up a registered grantee (application) using their Ethereum address
2432
- * and returns their complete registration information including permissions.
2763
+ * and returns their complete registration information including all associated permissions.
2433
2764
  *
2434
- * @param granteeAddress - The Ethereum address of the grantee to look up
2435
- * @returns Promise resolving to the grantee information, or null if not found
2436
- * @throws {BlockchainError} When contract read operation fails
2437
- * @throws {NetworkError} When unable to connect to the blockchain network
2765
+ * Returns `null` if the address is not registered as a grantee or if an error occurs.
2766
+ *
2767
+ * @param granteeAddress - Ethereum wallet address of the grantee to query
2768
+ * @returns Grantee information including ID, addresses, public key, and permission IDs, or `null` if not found
2438
2769
  *
2439
2770
  * @example
2440
2771
  * ```typescript
@@ -2459,40 +2790,32 @@ class PermissionsController {
2459
2790
  );
2460
2791
  const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
2461
2792
  try {
2462
- const granteeInfo = await this.context.publicClient.readContract({
2463
- address: DataPortabilityGranteesAddress,
2464
- abi: DataPortabilityGranteesAbi,
2465
- functionName: "granteeByAddress",
2466
- args: [granteeAddress]
2467
- });
2468
2793
  const granteeId = await this.context.publicClient.readContract({
2469
2794
  address: DataPortabilityGranteesAddress,
2470
2795
  abi: DataPortabilityGranteesAbi,
2471
2796
  functionName: "granteeAddressToId",
2472
2797
  args: [granteeAddress]
2473
2798
  });
2474
- return {
2475
- id: Number(granteeId),
2476
- owner: granteeInfo.owner,
2477
- address: granteeInfo.granteeAddress,
2478
- publicKey: granteeInfo.publicKey,
2479
- permissionIds: granteeInfo.permissionIds.map((id) => Number(id))
2480
- };
2799
+ if (granteeId === 0n) {
2800
+ return null;
2801
+ }
2802
+ return await this.getGranteeById(Number(granteeId));
2481
2803
  } catch (error) {
2482
2804
  console.warn(`Failed to fetch grantee ${granteeAddress}:`, error);
2483
2805
  return null;
2484
2806
  }
2485
2807
  }
2486
2808
  /**
2487
- * Retrieves a specific grantee by their unique ID from the DataPortabilityGrantees contract.
2809
+ * Retrieves a specific grantee by their unique ID.
2488
2810
  *
2811
+ * @remarks
2489
2812
  * Looks up a registered grantee (application) using their numeric ID assigned during
2490
- * registration and returns their complete information including permissions.
2813
+ * registration and returns their complete information including all associated permissions.
2491
2814
  *
2492
- * @param granteeId - The unique numeric ID of the grantee (1-indexed)
2493
- * @returns Promise resolving to the grantee information, or null if not found
2494
- * @throws {BlockchainError} When contract read operation fails
2495
- * @throws {NetworkError} When unable to connect to the blockchain network
2815
+ * Returns `null` if the grantee is not found or if an error occurs during fetching.
2816
+ *
2817
+ * @param granteeId - Unique numeric ID of the grantee (1-indexed)
2818
+ * @returns Grantee information including ID, addresses, public key, and permission IDs, or `null` if not found
2496
2819
  *
2497
2820
  * @example
2498
2821
  * ```typescript
@@ -2500,7 +2823,7 @@ class PermissionsController {
2500
2823
  *
2501
2824
  * if (grantee) {
2502
2825
  * console.log(`Grantee ID: ${grantee.id}`);
2503
- * console.log(`Address: ${grantee.granteeAddress}`);
2826
+ * console.log(`Address: ${grantee.address}`);
2504
2827
  * console.log(`Owner: ${grantee.owner}`);
2505
2828
  * console.log(`Total permissions: ${grantee.permissionIds.length}`);
2506
2829
  * } else {
@@ -2516,85 +2839,29 @@ class PermissionsController {
2516
2839
  );
2517
2840
  const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
2518
2841
  try {
2519
- const granteeInfo = await this.context.publicClient.readContract({
2842
+ const granteeInfoResult = await this.context.publicClient.readContract({
2520
2843
  address: DataPortabilityGranteesAddress,
2521
2844
  abi: DataPortabilityGranteesAbi,
2522
- functionName: "grantees",
2845
+ functionName: "granteesV2",
2523
2846
  args: [BigInt(granteeId)]
2524
2847
  });
2848
+ const granteeInfo = granteeInfoResult;
2849
+ const allPermissionIdsResult = await this.getGranteePermissionsPaginated(
2850
+ BigInt(granteeId)
2851
+ );
2852
+ const allPermissionIds = allPermissionIdsResult;
2525
2853
  return {
2526
2854
  id: granteeId,
2527
2855
  owner: granteeInfo.owner,
2528
2856
  address: granteeInfo.granteeAddress,
2529
2857
  publicKey: granteeInfo.publicKey,
2530
- permissionIds: granteeInfo.permissionIds.map((id) => Number(id))
2858
+ permissionIds: allPermissionIds.map((id) => Number(id))
2531
2859
  };
2532
2860
  } catch (error) {
2533
2861
  console.warn(`Failed to fetch grantee ${granteeId}:`, error);
2534
2862
  return null;
2535
2863
  }
2536
2864
  }
2537
- /**
2538
- * Builds EIP-712 typed data for grantee registration
2539
- *
2540
- * @param input - The register grantee input
2541
- * @returns Promise resolving to the typed data structure
2542
- * @private
2543
- */
2544
- async buildRegisterGranteeTypedData(input) {
2545
- const chainId = await this.context.walletClient.getChainId();
2546
- const verifyingContract = getContractAddress(
2547
- chainId,
2548
- "DataPortabilityGrantees"
2549
- );
2550
- return {
2551
- domain: {
2552
- name: "DataPortabilityGrantees",
2553
- version: "1",
2554
- chainId,
2555
- verifyingContract
2556
- },
2557
- types: {
2558
- RegisterGrantee: [
2559
- { name: "nonce", type: "uint256" },
2560
- { name: "owner", type: "address" },
2561
- { name: "granteeAddress", type: "address" },
2562
- { name: "publicKey", type: "string" }
2563
- ]
2564
- },
2565
- primaryType: "RegisterGrantee",
2566
- message: input
2567
- };
2568
- }
2569
- /**
2570
- * Submits a register grantee transaction with signature.
2571
- *
2572
- * @param typedData - The EIP-712 typed data structure for the registration
2573
- * @param _signature - The cryptographic signature authorizing the registration (currently unused)
2574
- * @returns Promise resolving to the transaction hash
2575
- * @private
2576
- */
2577
- async submitSignedRegisterGranteeTransaction(typedData, _signature) {
2578
- const chainId = await this.context.walletClient.getChainId();
2579
- const DataPortabilityGranteesAddress = getContractAddress(
2580
- chainId,
2581
- "DataPortabilityGrantees"
2582
- );
2583
- const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
2584
- const txHash = await this.context.walletClient.writeContract({
2585
- address: DataPortabilityGranteesAddress,
2586
- abi: DataPortabilityGranteesAbi,
2587
- functionName: "registerGrantee",
2588
- args: [
2589
- typedData.message.owner,
2590
- typedData.message.granteeAddress,
2591
- typedData.message.publicKey
2592
- ],
2593
- account: this.context.walletClient.account ?? await this.getUserAddress(),
2594
- chain: this.context.walletClient.chain ?? null
2595
- });
2596
- return txHash;
2597
- }
2598
2865
  // ===========================
2599
2866
  // DATA PORTABILITY SERVERS HELPER METHODS
2600
2867
  // ===========================
@@ -2606,7 +2873,7 @@ class PermissionsController {
2606
2873
  */
2607
2874
  async getUserServerIds(userAddress) {
2608
2875
  try {
2609
- const targetAddress = userAddress ?? await this.getUserAddress();
2876
+ const targetAddress = userAddress ?? this.context.userAddress;
2610
2877
  const chainId = await this.context.publicClient.getChainId();
2611
2878
  const DataPortabilityServersAddress = getContractAddress(
2612
2879
  chainId,
@@ -2664,7 +2931,7 @@ class PermissionsController {
2664
2931
  */
2665
2932
  async getUserServerCount(userAddress) {
2666
2933
  try {
2667
- const targetAddress = userAddress ?? await this.getUserAddress();
2934
+ const targetAddress = userAddress ?? this.context.userAddress;
2668
2935
  const chainId = await this.context.publicClient.getChainId();
2669
2936
  const DataPortabilityServersAddress = getContractAddress(
2670
2937
  chainId,
@@ -2693,7 +2960,7 @@ class PermissionsController {
2693
2960
  */
2694
2961
  async getUserTrustedServers(userAddress) {
2695
2962
  try {
2696
- const targetAddress = userAddress ?? await this.getUserAddress();
2963
+ const targetAddress = userAddress ?? this.context.userAddress;
2697
2964
  const chainId = await this.context.publicClient.getChainId();
2698
2965
  const DataPortabilityServersAddress = getContractAddress(
2699
2966
  chainId,
@@ -2810,7 +3077,7 @@ class PermissionsController {
2810
3077
  */
2811
3078
  async getUserPermissionIds(userAddress) {
2812
3079
  try {
2813
- const targetAddress = userAddress ?? await this.getUserAddress();
3080
+ const targetAddress = userAddress ?? this.context.userAddress;
2814
3081
  const chainId = await this.context.publicClient.getChainId();
2815
3082
  const DataPortabilityPermissionsAddress = getContractAddress(
2816
3083
  chainId,
@@ -2872,7 +3139,7 @@ class PermissionsController {
2872
3139
  */
2873
3140
  async getUserPermissionCount(userAddress) {
2874
3141
  try {
2875
- const targetAddress = userAddress ?? await this.getUserAddress();
3142
+ const targetAddress = userAddress ?? this.context.userAddress;
2876
3143
  const chainId = await this.context.publicClient.getChainId();
2877
3144
  const DataPortabilityPermissionsAddress = getContractAddress(
2878
3145
  chainId,
@@ -2985,6 +3252,31 @@ class PermissionsController {
2985
3252
  );
2986
3253
  }
2987
3254
  }
3255
+ /**
3256
+ * Retrieves detailed grant file data from IPFS or HTTP storage.
3257
+ *
3258
+ * @remarks
3259
+ * This method automatically uses the SDK's configured downloadRelayer to bypass CORS restrictions.
3260
+ * Use this instead of importing the standalone `retrieveGrantFile` utility.
3261
+ *
3262
+ * @param grantUrl - The grant file URL (from OnChainPermissionGrant.grantUrl)
3263
+ * @returns Promise resolving to the complete grant file with operation details
3264
+ * @throws {NetworkError} When all retrieval attempts fail
3265
+ * @example
3266
+ * ```typescript
3267
+ * const grants = await vana.permissions.getUserPermissionGrantsOnChain();
3268
+ * const grantFile = await vana.permissions.retrieveGrantFile(grants[0].grantUrl);
3269
+ * console.log(`Operation: ${grantFile.operation}`);
3270
+ * ```
3271
+ */
3272
+ async retrieveGrantFile(grantUrl) {
3273
+ const { retrieveGrantFile: retrieveGrantFileUtil } = await import("../utils/grantFiles");
3274
+ return retrieveGrantFileUtil(
3275
+ grantUrl,
3276
+ void 0,
3277
+ this.context.downloadRelayer
3278
+ );
3279
+ }
2988
3280
  /**
2989
3281
  * Get all permissions for a specific file (alias for getFilePermissionIds)
2990
3282
  *
@@ -3010,26 +3302,34 @@ class PermissionsController {
3010
3302
  // DATA PORTABILITY GRANTEES HELPER METHODS
3011
3303
  // ===========================
3012
3304
  /**
3013
- * Get grantee information by grantee ID
3305
+ * Retrieves detailed grantee information including all associated permissions.
3014
3306
  *
3015
- * @param granteeId - Grantee ID to get info for
3016
- * @returns Promise resolving to grantee info
3307
+ * @remarks
3308
+ * Returns grantee metadata and associated permission IDs. Uses the newer
3309
+ * paginated contract method internally for efficient permission fetching.
3310
+ *
3311
+ * @param granteeId - Unique grantee identifier as bigint
3312
+ * @returns Grantee information containing owner address, grantee address, public key, and permission IDs
3313
+ * @throws {BlockchainError} When grantee ID is not found or contract read fails
3314
+ *
3315
+ * @example
3316
+ * ```typescript
3317
+ * const granteeInfo = await vana.permissions.getGranteeInfo(BigInt(1));
3318
+ * console.log(`Grantee ${granteeInfo.granteeAddress} has ${granteeInfo.permissionIds.length} permissions`);
3319
+ * ```
3017
3320
  */
3018
3321
  async getGranteeInfo(granteeId) {
3019
3322
  try {
3020
- const chainId = await this.context.publicClient.getChainId();
3021
- const DataPortabilityGranteesAddress = getContractAddress(
3022
- chainId,
3023
- "DataPortabilityGrantees"
3024
- );
3025
- const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
3026
- const granteeInfo = await this.context.publicClient.readContract({
3027
- address: DataPortabilityGranteesAddress,
3028
- abi: DataPortabilityGranteesAbi,
3029
- functionName: "granteeInfo",
3030
- args: [granteeId]
3031
- });
3032
- return granteeInfo;
3323
+ const grantee = await this.getGranteeById(Number(granteeId));
3324
+ if (!grantee) {
3325
+ throw new Error("Grantee not found");
3326
+ }
3327
+ return {
3328
+ owner: grantee.owner,
3329
+ granteeAddress: grantee.address,
3330
+ publicKey: grantee.publicKey,
3331
+ permissionIds: grantee.permissionIds.map((id) => BigInt(id))
3332
+ };
3033
3333
  } catch (error) {
3034
3334
  throw new BlockchainError(
3035
3335
  `Failed to get grantee info: ${error instanceof Error ? error.message : "Unknown error"}`,
@@ -3038,10 +3338,21 @@ class PermissionsController {
3038
3338
  }
3039
3339
  }
3040
3340
  /**
3041
- * Get grantee information by grantee address
3341
+ * Retrieves detailed grantee information by wallet address.
3042
3342
  *
3043
- * @param granteeAddress - Grantee address to get info for
3044
- * @returns Promise resolving to grantee info
3343
+ * @remarks
3344
+ * Looks up the grantee ID from the provided address, then fetches complete
3345
+ * grantee information including all associated permissions.
3346
+ *
3347
+ * @param granteeAddress - Ethereum wallet address of the grantee to query
3348
+ * @returns Grantee information containing owner address, grantee address, public key, and permission IDs
3349
+ * @throws {BlockchainError} When grantee address is not registered or contract read fails
3350
+ *
3351
+ * @example
3352
+ * ```typescript
3353
+ * const granteeInfo = await vana.permissions.getGranteeInfoByAddress("0x742d35Cc6634c0532925a3b844Bc9e8e1ee3b2De");
3354
+ * console.log(`Found grantee with ${granteeInfo.permissionIds.length} permissions`);
3355
+ * ```
3045
3356
  */
3046
3357
  async getGranteeInfoByAddress(granteeAddress) {
3047
3358
  try {
@@ -3051,13 +3362,26 @@ class PermissionsController {
3051
3362
  "DataPortabilityGrantees"
3052
3363
  );
3053
3364
  const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
3054
- const granteeInfo = await this.context.publicClient.readContract({
3365
+ const granteeIdResult = await this.context.publicClient.readContract({
3055
3366
  address: DataPortabilityGranteesAddress,
3056
3367
  abi: DataPortabilityGranteesAbi,
3057
- functionName: "granteeByAddress",
3368
+ functionName: "granteeAddressToId",
3058
3369
  args: [granteeAddress]
3059
3370
  });
3060
- return granteeInfo;
3371
+ const granteeId = granteeIdResult;
3372
+ if (granteeId === 0n) {
3373
+ throw new Error("Grantee not found");
3374
+ }
3375
+ const grantee = await this.getGranteeById(Number(granteeId));
3376
+ if (!grantee) {
3377
+ throw new Error("Grantee not found");
3378
+ }
3379
+ return {
3380
+ owner: grantee.owner,
3381
+ granteeAddress: grantee.address,
3382
+ publicKey: grantee.publicKey,
3383
+ permissionIds: grantee.permissionIds.map((id) => BigInt(id))
3384
+ };
3061
3385
  } catch (error) {
3062
3386
  throw new BlockchainError(
3063
3387
  `Failed to get grantee info by address: ${error instanceof Error ? error.message : "Unknown error"}`,
@@ -3121,6 +3445,117 @@ class PermissionsController {
3121
3445
  );
3122
3446
  }
3123
3447
  }
3448
+ /**
3449
+ * Retrieves permission IDs for a specific grantee with flexible pagination.
3450
+ *
3451
+ * @remarks
3452
+ * **Pagination Behavior:**
3453
+ * Returns different types based on parameters:
3454
+ * - Without offset/limit: Returns `bigint[]` of all permissions using batched multicall
3455
+ * - With offset/limit: Returns paginated object with `permissionIds`, `totalCount`, and `hasMore`
3456
+ *
3457
+ * Uses gas-aware multicall for efficient batch fetching when retrieving all permissions.
3458
+ *
3459
+ * @param granteeId - Grantee ID to get permissions for
3460
+ * @param options - Optional pagination parameters
3461
+ * @param options.offset - Zero-based starting index for pagination. Defaults to 0 when fetching all permissions. Required for single-page requests.
3462
+ * @param options.limit - Maximum number of permission IDs to return per page. Defaults to 100 when fetching all permissions. Required for single-page requests.
3463
+ * @returns When called without options: Array of all permission IDs as `bigint[]`.
3464
+ * When called with offset and limit: Paginated result object containing `permissionIds` array,
3465
+ * `totalCount`, and `hasMore` boolean.
3466
+ * @throws {BlockchainError} When contract read operation fails
3467
+ *
3468
+ * @example
3469
+ * ```typescript
3470
+ * // Fetch all permissions (no pagination params)
3471
+ * const allPermissions = await vana.permissions.getGranteePermissionsPaginated(BigInt(1));
3472
+ * console.log(`Total permissions: ${allPermissions.length}`);
3473
+ *
3474
+ * // Fetch a specific page (with pagination params)
3475
+ * const page = await vana.permissions.getGranteePermissionsPaginated(BigInt(1), {
3476
+ * offset: BigInt(0),
3477
+ * limit: BigInt(100)
3478
+ * });
3479
+ * console.log(`Fetched ${page.permissionIds.length} permissions`);
3480
+ * console.log(`Total: ${page.totalCount}, Has more: ${page.hasMore}`);
3481
+ *
3482
+ * // Fetch next page
3483
+ * if (page.hasMore) {
3484
+ * const nextPage = await vana.permissions.getGranteePermissionsPaginated(BigInt(1), {
3485
+ * offset: BigInt(100),
3486
+ * limit: BigInt(100)
3487
+ * });
3488
+ * }
3489
+ * ```
3490
+ */
3491
+ async getGranteePermissionsPaginated(granteeId, options) {
3492
+ try {
3493
+ const chainId = await this.context.publicClient.getChainId();
3494
+ const DataPortabilityGranteesAddress = getContractAddress(
3495
+ chainId,
3496
+ "DataPortabilityGrantees"
3497
+ );
3498
+ const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
3499
+ const fetchOnlyOnePage = options?.offset !== void 0 && options?.limit !== void 0;
3500
+ if (fetchOnlyOnePage) {
3501
+ const result = await this.context.publicClient.readContract({
3502
+ address: DataPortabilityGranteesAddress,
3503
+ abi: DataPortabilityGranteesAbi,
3504
+ functionName: "granteePermissionsPaginated",
3505
+ args: [granteeId, options.offset, options.limit]
3506
+ });
3507
+ const [permissionIds, totalCount2, hasMore] = result;
3508
+ return {
3509
+ permissionIds: [...permissionIds],
3510
+ totalCount: totalCount2,
3511
+ hasMore
3512
+ };
3513
+ }
3514
+ const countResult = await this.context.publicClient.readContract({
3515
+ address: DataPortabilityGranteesAddress,
3516
+ abi: DataPortabilityGranteesAbi,
3517
+ functionName: "granteePermissionsPaginated",
3518
+ args: [granteeId, BigInt(0), BigInt(1)]
3519
+ });
3520
+ const [, totalCount] = countResult;
3521
+ if (totalCount === BigInt(0)) {
3522
+ return [];
3523
+ }
3524
+ const batchSize = options?.limit ?? BigInt(100);
3525
+ const startOffset = options?.offset ?? BigInt(0);
3526
+ const endOffset = totalCount;
3527
+ const numBatches = Math.ceil(
3528
+ Number(endOffset - startOffset) / Number(batchSize)
3529
+ );
3530
+ const paginationCalls = Array.from({ length: numBatches }, (_, i) => ({
3531
+ address: DataPortabilityGranteesAddress,
3532
+ abi: DataPortabilityGranteesAbi,
3533
+ functionName: "granteePermissionsPaginated",
3534
+ args: [
3535
+ granteeId,
3536
+ startOffset + BigInt(i) * batchSize,
3537
+ batchSize
3538
+ ]
3539
+ }));
3540
+ const results = await gasAwareMulticall(
3541
+ this.context.publicClient,
3542
+ {
3543
+ contracts: paginationCalls
3544
+ }
3545
+ );
3546
+ const allPermissionIds = [];
3547
+ for (const result of results) {
3548
+ const [permissionIds] = result;
3549
+ allPermissionIds.push(...permissionIds);
3550
+ }
3551
+ return allPermissionIds;
3552
+ } catch (error) {
3553
+ throw new BlockchainError(
3554
+ `Failed to get grantee permissions: ${error instanceof Error ? error.message : "Unknown error"}`,
3555
+ error
3556
+ );
3557
+ }
3558
+ }
3124
3559
  // ===== DataPortabilityServersImplementation Methods =====
3125
3560
  /**
3126
3561
  * Get all server IDs for a user
@@ -3314,9 +3749,11 @@ class PermissionsController {
3314
3749
  *
3315
3750
  * @param serverId - Server ID to update
3316
3751
  * @param url - New URL for the server
3752
+ * @param options - Optional transaction options for gas parameters and timeout
3317
3753
  * @returns Promise resolving to transaction hash
3318
3754
  */
3319
- async submitUpdateServer(serverId, url) {
3755
+ async submitUpdateServer(serverId, url, options) {
3756
+ this.assertWallet();
3320
3757
  try {
3321
3758
  const chainId = await this.context.walletClient.getChainId();
3322
3759
  const DataPortabilityServersAddress = getContractAddress(
@@ -3324,14 +3761,25 @@ class PermissionsController {
3324
3761
  "DataPortabilityServers"
3325
3762
  );
3326
3763
  const DataPortabilityServersAbi = getAbi("DataPortabilityServers");
3327
- const account = this.context.walletClient.account ?? await this.getUserAddress();
3764
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
3328
3765
  const hash = await this.context.walletClient.writeContract({
3329
3766
  address: DataPortabilityServersAddress,
3330
3767
  abi: DataPortabilityServersAbi,
3331
3768
  functionName: "updateServer",
3332
3769
  args: [serverId, url],
3333
- chain: this.context.walletClient.chain,
3334
- account
3770
+ chain: this.context.walletClient?.chain,
3771
+ account,
3772
+ ...options?.gas && { gas: options.gas },
3773
+ ...options?.nonce && { nonce: options.nonce },
3774
+ // Use EIP-1559 if available, otherwise fall back to legacy gasPrice
3775
+ ...options?.maxFeePerGas || options?.maxPriorityFeePerGas ? {
3776
+ ...options.maxFeePerGas && {
3777
+ maxFeePerGas: options.maxFeePerGas
3778
+ },
3779
+ ...options.maxPriorityFeePerGas && {
3780
+ maxPriorityFeePerGas: options.maxPriorityFeePerGas
3781
+ }
3782
+ } : options?.gasPrice && { gasPrice: options.gasPrice }
3335
3783
  });
3336
3784
  const { tx } = await import("../utils/transactionHelpers");
3337
3785
  return tx({
@@ -3489,6 +3937,7 @@ class PermissionsController {
3489
3937
  * @throws {NetworkError} When network communication fails
3490
3938
  */
3491
3939
  async submitAddPermission(params) {
3940
+ this.assertWallet();
3492
3941
  try {
3493
3942
  const nonce = await this.getPermissionsUserNonce();
3494
3943
  const addPermissionInput = {
@@ -3526,21 +3975,36 @@ class PermissionsController {
3526
3975
  * @throws {BlockchainError} When permission addition fails
3527
3976
  * @throws {NetworkError} When network communication fails
3528
3977
  */
3529
- async submitSignedAddPermission(typedData, signature) {
3978
+ async submitSignedAddPermission(typedData, signature, options) {
3979
+ this.assertWallet();
3530
3980
  try {
3531
3981
  let hash;
3532
- if (this.context.relayerCallbacks?.submitAddPermission) {
3533
- hash = await this.context.relayerCallbacks.submitAddPermission(
3982
+ if (this.context.relayer) {
3983
+ const request = {
3984
+ type: "signed",
3985
+ operation: "submitAddPermission",
3534
3986
  typedData,
3535
3987
  signature
3536
- );
3988
+ };
3989
+ const response = await this.context.relayer(request);
3990
+ if (response.type === "error") {
3991
+ throw new RelayerError(response.error);
3992
+ }
3993
+ if (response.type === "submitted") {
3994
+ hash = response.hash;
3995
+ } else if (response.type === "signed") {
3996
+ hash = response.hash;
3997
+ } else {
3998
+ throw new Error("Unexpected response type from relayer");
3999
+ }
3537
4000
  } else {
3538
4001
  hash = await this.submitDirectAddPermissionTransaction(
3539
4002
  typedData,
3540
- signature
4003
+ signature,
4004
+ options
3541
4005
  );
3542
4006
  }
3543
- const account = this.context.walletClient.account ?? await this.getUserAddress();
4007
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
3544
4008
  const { tx } = await import("../utils/transactionHelpers");
3545
4009
  return tx({
3546
4010
  hash,
@@ -3578,6 +4042,9 @@ class PermissionsController {
3578
4042
  * @param params.serverPublicKey - Server's public key for encryption.
3579
4043
  * Obtain via `vana.server.getIdentity(userAddress).publicKey`.
3580
4044
  * @param params.filePermissions - Nested array of permissions for each file
4045
+ * @param options - Optional transaction options for gas parameters and timeout.
4046
+ * Note: These options are only applied for direct blockchain transactions.
4047
+ * When using relayer callbacks (gasless transactions), these options are ignored.
3581
4048
  * @returns TransactionResult with immediate hash access and optional event data
3582
4049
  * @throws {Error} When schemaIds array length doesn't match fileUrls array length
3583
4050
  * @throws {SchemaValidationError} When file data doesn't match the specified schema.
@@ -3591,6 +4058,7 @@ class PermissionsController {
3591
4058
  *
3592
4059
  * @example
3593
4060
  * ```typescript
4061
+ * // Submit with custom gas parameters and timeout
3594
4062
  * const result = await vana.permissions.submitAddServerFilesAndPermissions({
3595
4063
  * granteeId: BigInt(1),
3596
4064
  * grant: "ipfs://QmXxx...",
@@ -3603,12 +4071,20 @@ class PermissionsController {
3603
4071
  * account: "0x742d35Cc6634C0532925a3b844Bc9e7595f0b0Bb",
3604
4072
  * key: encryptedKey
3605
4073
  * }]]
4074
+ * }, {
4075
+ * maxFeePerGas: 100n * 10n ** 9n, // 100 gwei
4076
+ * maxPriorityFeePerGas: 2n * 10n ** 9n, // 2 gwei tip
4077
+ * });
4078
+ *
4079
+ * // Wait for confirmation with custom timeout
4080
+ * const receipt = await vana.waitForTransactionReceipt(result, {
4081
+ * timeout: 180000 // 3 minutes
3606
4082
  * });
3607
- * const events = await result.waitForEvents();
3608
- * console.log(`Permission ID: ${events.permissionId}`);
4083
+ * console.log(`Transaction confirmed: ${receipt.transactionHash}`);
3609
4084
  * ```
3610
4085
  */
3611
- async submitAddServerFilesAndPermissions(params) {
4086
+ async submitAddServerFilesAndPermissions(params, options) {
4087
+ this.assertWallet();
3612
4088
  try {
3613
4089
  if (params.schemaIds.length !== params.fileUrls.length) {
3614
4090
  throw new Error(
@@ -3633,7 +4109,8 @@ class PermissionsController {
3633
4109
  const signature = await this.signTypedData(typedData);
3634
4110
  return await this.submitSignedAddServerFilesAndPermissions(
3635
4111
  typedData,
3636
- signature
4112
+ signature,
4113
+ options
3637
4114
  );
3638
4115
  } catch (error) {
3639
4116
  if (error instanceof RelayerError || error instanceof UserRejectedRequestError || error instanceof SerializationError || error instanceof SignatureError || error instanceof NetworkError || error instanceof NonceError) {
@@ -3654,6 +4131,9 @@ class PermissionsController {
3654
4131
  *
3655
4132
  * @param typedData - The EIP-712 typed data for AddServerFilesAndPermissions
3656
4133
  * @param signature - The user's signature
4134
+ * @param options - Optional transaction options for gas parameters and timeout.
4135
+ * Note: These options are only applied for direct blockchain transactions.
4136
+ * When using relayer callbacks (gasless transactions), these options are ignored.
3657
4137
  * @returns TransactionResult with immediate hash access and optional event data
3658
4138
  * @throws {RelayerError} When gasless transaction submission fails
3659
4139
  * @throws {BlockchainError} When server files and permissions addition fails
@@ -3672,46 +4152,49 @@ class PermissionsController {
3672
4152
  * console.log(`Permission created with ID: ${permissionId}`);
3673
4153
  * ```
3674
4154
  */
3675
- async submitSignedAddServerFilesAndPermissions(typedData, signature) {
4155
+ async submitSignedAddServerFilesAndPermissions(typedData, signature, options) {
4156
+ this.assertWallet();
3676
4157
  try {
3677
- console.debug("\u{1F50D} submitSignedAddServerFilesAndPermissions Debug Info:", {
3678
- hasRelayerCallbacks: !!this.context.relayerCallbacks,
3679
- hasSubmitMethod: !!this.context.relayerCallbacks?.submitAddServerFilesAndPermissions,
3680
- availableRelayerMethods: this.context.relayerCallbacks ? Object.keys(this.context.relayerCallbacks) : []
3681
- });
3682
- if (this.context.relayerCallbacks?.submitAddServerFilesAndPermissions) {
4158
+ let hash;
4159
+ if (this.context.relayer) {
3683
4160
  console.debug(
3684
4161
  "\u{1F680} Using relayer for submitAddServerFilesAndPermissions"
3685
4162
  );
3686
- const hash = await this.context.relayerCallbacks.submitAddServerFilesAndPermissions(
4163
+ const request = {
4164
+ type: "signed",
4165
+ operation: "submitAddServerFilesAndPermissions",
3687
4166
  typedData,
3688
4167
  signature
3689
- );
3690
- const account = this.context.walletClient.account ?? await this.getUserAddress();
3691
- const { tx } = await import("../utils/transactionHelpers");
3692
- return tx({
3693
- hash,
3694
- from: typeof account === "string" ? account : account.address,
3695
- contract: "DataPortabilityPermissions",
3696
- fn: "addServerFilesAndPermissions"
3697
- });
4168
+ };
4169
+ const response = await this.context.relayer(request);
4170
+ if (response.type === "error") {
4171
+ throw new RelayerError(response.error);
4172
+ }
4173
+ if (response.type === "submitted") {
4174
+ hash = response.hash;
4175
+ } else if (response.type === "signed") {
4176
+ hash = response.hash;
4177
+ } else {
4178
+ throw new Error("Unexpected response type from relayer");
4179
+ }
3698
4180
  } else {
3699
4181
  console.debug(
3700
4182
  "\u{1F4DD} Using direct transaction for submitAddServerFilesAndPermissions"
3701
4183
  );
3702
- const hash = await this.submitDirectAddServerFilesAndPermissionsTransaction(
4184
+ hash = await this.submitDirectAddServerFilesAndPermissionsTransaction(
3703
4185
  typedData,
3704
- signature
4186
+ signature,
4187
+ options
3705
4188
  );
3706
- const account = this.context.walletClient.account ?? await this.getUserAddress();
3707
- const { tx } = await import("../utils/transactionHelpers");
3708
- return tx({
3709
- hash,
3710
- from: typeof account === "string" ? account : account.address,
3711
- contract: "DataPortabilityPermissions",
3712
- fn: "addServerFilesAndPermissions"
3713
- });
3714
4189
  }
4190
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
4191
+ const { tx } = await import("../utils/transactionHelpers");
4192
+ return tx({
4193
+ hash,
4194
+ from: typeof account === "string" ? account : account.address,
4195
+ contract: "DataPortabilityPermissions",
4196
+ fn: "addServerFilesAndPermissions"
4197
+ });
3715
4198
  } catch (error) {
3716
4199
  if (error instanceof RelayerError || error instanceof NetworkError || error instanceof UserRejectedRequestError || error instanceof SignatureError || error instanceof NonceError) {
3717
4200
  throw error;
@@ -3726,9 +4209,11 @@ class PermissionsController {
3726
4209
  * Submit permission revocation with signature to the blockchain
3727
4210
  *
3728
4211
  * @param permissionId - Permission ID to revoke
4212
+ * @param options - Optional transaction options for gas parameters and timeout
3729
4213
  * @returns Promise resolving to transaction hash
3730
4214
  */
3731
- async submitRevokePermission(permissionId) {
4215
+ async submitRevokePermission(permissionId, options) {
4216
+ this.assertWallet();
3732
4217
  try {
3733
4218
  const chainId = await this.context.walletClient.getChainId();
3734
4219
  const DataPortabilityPermissionsAddress = getContractAddress(
@@ -3747,8 +4232,19 @@ class PermissionsController {
3747
4232
  abi: DataPortabilityPermissionsAbi,
3748
4233
  functionName: "revokePermission",
3749
4234
  args: [permissionId],
3750
- chain: this.context.walletClient.chain,
3751
- account
4235
+ chain: this.context.walletClient?.chain,
4236
+ account,
4237
+ ...options?.gas && { gas: options.gas },
4238
+ ...options?.nonce && { nonce: options.nonce },
4239
+ // Use EIP-1559 if available, otherwise fall back to legacy gasPrice
4240
+ ...options?.maxFeePerGas || options?.maxPriorityFeePerGas ? {
4241
+ ...options.maxFeePerGas && {
4242
+ maxFeePerGas: options.maxFeePerGas
4243
+ },
4244
+ ...options.maxPriorityFeePerGas && {
4245
+ maxPriorityFeePerGas: options.maxPriorityFeePerGas
4246
+ }
4247
+ } : options?.gasPrice && { gasPrice: options.gasPrice }
3752
4248
  });
3753
4249
  const { tx } = await import("../utils/transactionHelpers");
3754
4250
  return tx({
@@ -3771,7 +4267,8 @@ class PermissionsController {
3771
4267
  * @param signature - The cryptographic signature authorizing the transaction
3772
4268
  * @returns Promise resolving to the transaction hash
3773
4269
  */
3774
- async submitDirectAddPermissionTransaction(typedData, signature) {
4270
+ async submitDirectAddPermissionTransaction(typedData, signature, options) {
4271
+ this.assertWallet();
3775
4272
  const chainId = await this.context.walletClient.getChainId();
3776
4273
  const DataPortabilityPermissionsAddress = getContractAddress(
3777
4274
  chainId,
@@ -3790,8 +4287,9 @@ class PermissionsController {
3790
4287
  abi: DataPortabilityPermissionsAbi,
3791
4288
  functionName: "addPermission",
3792
4289
  args: [permissionInput, formattedSignature],
3793
- account: this.context.walletClient.account ?? await this.getUserAddress(),
3794
- chain: this.context.walletClient.chain ?? null
4290
+ account: this.context.walletClient?.account ?? this.context.userAddress,
4291
+ chain: this.context.walletClient?.chain ?? null,
4292
+ ...this.spreadTransactionOptions(options)
3795
4293
  });
3796
4294
  return hash;
3797
4295
  }
@@ -3802,8 +4300,9 @@ class PermissionsController {
3802
4300
  * @param signature - The cryptographic signature authorizing the transaction
3803
4301
  * @returns Promise resolving to the transaction hash
3804
4302
  */
3805
- async submitDirectAddServerFilesAndPermissionsTransaction(typedData, signature) {
3806
- const chainId = await this.context.walletClient.getChainId();
4303
+ async submitDirectAddServerFilesAndPermissionsTransaction(typedData, signature, options) {
4304
+ this.assertWallet();
4305
+ const chainId = await this.context.publicClient.getChainId();
3807
4306
  const DataPortabilityPermissionsAddress = getContractAddress(
3808
4307
  chainId,
3809
4308
  "DataPortabilityPermissions"
@@ -3825,10 +4324,11 @@ class PermissionsController {
3825
4324
  address: DataPortabilityPermissionsAddress,
3826
4325
  abi: DataPortabilityPermissionsAbi,
3827
4326
  functionName: "addServerFilesAndPermissions",
3828
- // @ts-expect-error - Viem's type inference for nested Permission[][] arrays is incompatible with our Permission type
3829
4327
  args: [serverFilesAndPermissionInput, formattedSignature],
3830
- account: this.context.walletClient.account ?? await this.getUserAddress(),
3831
- chain: this.context.walletClient.chain ?? null
4328
+ account: this.context.walletClient?.account ?? this.context.userAddress,
4329
+ chain: this.context.walletClient?.chain ?? null,
4330
+ ...options?.value && { value: options.value },
4331
+ ...this.spreadTransactionOptions(options)
3832
4332
  });
3833
4333
  return hash;
3834
4334
  }