@opendatalabs/vana-sdk 0.1.0-alpha.a25bcc7 → 0.1.0-alpha.a6b60fc

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 (165) hide show
  1. package/dist/browser.cjs.map +1 -1
  2. package/dist/browser.d.ts +33 -1
  3. package/dist/browser.js.map +1 -1
  4. package/dist/chains/index.cjs.map +1 -1
  5. package/dist/chains/index.d.ts +30 -1
  6. package/dist/chains/index.js.map +1 -1
  7. package/dist/config/chains.cjs.map +1 -1
  8. package/dist/config/chains.d.ts +99 -0
  9. package/dist/config/chains.js.map +1 -1
  10. package/dist/contracts/contractController.cjs.map +1 -1
  11. package/dist/contracts/contractController.d.ts +66 -10
  12. package/dist/contracts/contractController.js.map +1 -1
  13. package/dist/controllers/data.cjs +172 -140
  14. package/dist/controllers/data.cjs.map +1 -1
  15. package/dist/controllers/data.d.ts +213 -175
  16. package/dist/controllers/data.js +172 -140
  17. package/dist/controllers/data.js.map +1 -1
  18. package/dist/controllers/permissions.cjs +184 -190
  19. package/dist/controllers/permissions.cjs.map +1 -1
  20. package/dist/controllers/permissions.d.ts +29 -73
  21. package/dist/controllers/permissions.js +184 -190
  22. package/dist/controllers/permissions.js.map +1 -1
  23. package/dist/controllers/protocol.cjs.map +1 -1
  24. package/dist/controllers/protocol.d.ts +27 -28
  25. package/dist/controllers/protocol.js.map +1 -1
  26. package/dist/controllers/schemas.cjs +19 -17
  27. package/dist/controllers/schemas.cjs.map +1 -1
  28. package/dist/controllers/schemas.d.ts +47 -40
  29. package/dist/controllers/schemas.js +19 -17
  30. package/dist/controllers/schemas.js.map +1 -1
  31. package/dist/controllers/server.cjs +17 -15
  32. package/dist/controllers/server.cjs.map +1 -1
  33. package/dist/controllers/server.d.ts +46 -38
  34. package/dist/controllers/server.js +17 -15
  35. package/dist/controllers/server.js.map +1 -1
  36. package/dist/core/apiClient.cjs +53 -3
  37. package/dist/core/apiClient.cjs.map +1 -1
  38. package/dist/core/apiClient.d.ts +132 -7
  39. package/dist/core/apiClient.js +53 -3
  40. package/dist/core/apiClient.js.map +1 -1
  41. package/dist/core/generics.cjs +30 -3
  42. package/dist/core/generics.cjs.map +1 -1
  43. package/dist/core/generics.d.ts +95 -6
  44. package/dist/core/generics.js +30 -3
  45. package/dist/core/generics.js.map +1 -1
  46. package/dist/core.cjs +29 -12
  47. package/dist/core.cjs.map +1 -1
  48. package/dist/core.d.ts +2 -1
  49. package/dist/core.js +29 -12
  50. package/dist/core.js.map +1 -1
  51. package/dist/index.cjs.map +1 -1
  52. package/dist/index.js.map +1 -1
  53. package/dist/index.node.cjs +3 -3
  54. package/dist/index.node.cjs.map +1 -1
  55. package/dist/index.node.d.ts +8 -9
  56. package/dist/index.node.js +2 -2
  57. package/dist/index.node.js.map +1 -1
  58. package/dist/node.cjs.map +1 -1
  59. package/dist/node.d.ts +39 -1
  60. package/dist/node.js.map +1 -1
  61. package/dist/platform/browser.cjs +160 -2
  62. package/dist/platform/browser.cjs.map +1 -1
  63. package/dist/platform/browser.d.ts +232 -12
  64. package/dist/platform/browser.js +160 -2
  65. package/dist/platform/browser.js.map +1 -1
  66. package/dist/platform/interface.cjs.map +1 -1
  67. package/dist/platform/interface.d.ts +283 -90
  68. package/dist/platform/node.cjs +163 -2
  69. package/dist/platform/node.cjs.map +1 -1
  70. package/dist/platform/node.d.ts +69 -6
  71. package/dist/platform/node.js +163 -2
  72. package/dist/platform/node.js.map +1 -1
  73. package/dist/server/relayerHandler.cjs +214 -0
  74. package/dist/server/relayerHandler.cjs.map +1 -0
  75. package/dist/server/relayerHandler.d.ts +36 -0
  76. package/dist/server/relayerHandler.js +190 -0
  77. package/dist/server/relayerHandler.js.map +1 -0
  78. package/dist/storage/manager.cjs +108 -25
  79. package/dist/storage/manager.cjs.map +1 -1
  80. package/dist/storage/manager.d.ts +119 -25
  81. package/dist/storage/manager.js +108 -25
  82. package/dist/storage/manager.js.map +1 -1
  83. package/dist/storage/providers/callback-storage.cjs +86 -15
  84. package/dist/storage/providers/callback-storage.cjs.map +1 -1
  85. package/dist/storage/providers/callback-storage.d.ts +109 -20
  86. package/dist/storage/providers/callback-storage.js +86 -15
  87. package/dist/storage/providers/callback-storage.js.map +1 -1
  88. package/dist/storage/providers/pinata.cjs.map +1 -1
  89. package/dist/storage/providers/pinata.d.ts +12 -14
  90. package/dist/storage/providers/pinata.js.map +1 -1
  91. package/dist/tests/factories/mockFactory.d.ts +2 -2
  92. package/dist/tests/relayer-integration.test.d.ts +1 -0
  93. package/dist/tests/relayer-unified.test.d.ts +1 -0
  94. package/dist/tests/server-relayer-handler.test.d.ts +1 -0
  95. package/dist/types/blockchain.cjs.map +1 -1
  96. package/dist/types/blockchain.d.ts +39 -11
  97. package/dist/types/chains.cjs.map +1 -1
  98. package/dist/types/chains.d.ts +74 -7
  99. package/dist/types/chains.js.map +1 -1
  100. package/dist/types/config.cjs.map +1 -1
  101. package/dist/types/config.d.ts +46 -191
  102. package/dist/types/config.js.map +1 -1
  103. package/dist/types/contracts.cjs.map +1 -1
  104. package/dist/types/contracts.d.ts +71 -7
  105. package/dist/types/controller-context.cjs.map +1 -1
  106. package/dist/types/controller-context.d.ts +3 -2
  107. package/dist/types/data.cjs.map +1 -1
  108. package/dist/types/data.d.ts +4 -6
  109. package/dist/types/generics.cjs.map +1 -1
  110. package/dist/types/generics.d.ts +80 -9
  111. package/dist/types/index.cjs.map +1 -1
  112. package/dist/types/index.d.ts +27 -2
  113. package/dist/types/index.js.map +1 -1
  114. package/dist/types/operations.cjs.map +1 -1
  115. package/dist/types/operations.d.ts +132 -15
  116. package/dist/types/operations.js.map +1 -1
  117. package/dist/types/permissions.cjs.map +1 -1
  118. package/dist/types/permissions.d.ts +15 -20
  119. package/dist/types/personal.cjs.map +1 -1
  120. package/dist/types/personal.d.ts +131 -14
  121. package/dist/types/relayer.cjs.map +1 -1
  122. package/dist/types/relayer.d.ts +262 -35
  123. package/dist/types/storage.cjs.map +1 -1
  124. package/dist/types/storage.d.ts +9 -21
  125. package/dist/types/storage.js.map +1 -1
  126. package/dist/utils/grantFiles.cjs.map +1 -1
  127. package/dist/utils/grantFiles.d.ts +10 -20
  128. package/dist/utils/grantFiles.js.map +1 -1
  129. package/dist/utils/grantValidation.cjs.map +1 -1
  130. package/dist/utils/grantValidation.d.ts +95 -16
  131. package/dist/utils/grantValidation.js.map +1 -1
  132. package/dist/utils/grants.cjs.map +1 -1
  133. package/dist/utils/grants.d.ts +93 -12
  134. package/dist/utils/grants.js.map +1 -1
  135. package/dist/utils/lazy-import.cjs.map +1 -1
  136. package/dist/utils/lazy-import.d.ts +32 -7
  137. package/dist/utils/lazy-import.js.map +1 -1
  138. package/dist/utils/signatureCache.cjs +8 -2
  139. package/dist/utils/signatureCache.cjs.map +1 -1
  140. package/dist/utils/signatureCache.d.ts +49 -8
  141. package/dist/utils/signatureCache.js +8 -2
  142. package/dist/utils/signatureCache.js.map +1 -1
  143. package/dist/utils/transactionHelpers.cjs.map +1 -1
  144. package/dist/utils/transactionHelpers.d.ts +12 -12
  145. package/dist/utils/transactionHelpers.js.map +1 -1
  146. package/dist/utils/typedDataConverter.cjs.map +1 -1
  147. package/dist/utils/typedDataConverter.d.ts +39 -3
  148. package/dist/utils/typedDataConverter.js.map +1 -1
  149. package/dist/utils/urlResolver.cjs +7 -0
  150. package/dist/utils/urlResolver.cjs.map +1 -1
  151. package/dist/utils/urlResolver.d.ts +22 -4
  152. package/dist/utils/urlResolver.js +7 -0
  153. package/dist/utils/urlResolver.js.map +1 -1
  154. package/dist/utils/wallet.cjs +2 -1
  155. package/dist/utils/wallet.cjs.map +1 -1
  156. package/dist/utils/wallet.d.ts +78 -16
  157. package/dist/utils/wallet.js +2 -1
  158. package/dist/utils/wallet.js.map +1 -1
  159. package/package.json +1 -1
  160. package/dist/server/handler.cjs +0 -101
  161. package/dist/server/handler.cjs.map +0 -1
  162. package/dist/server/handler.d.ts +0 -87
  163. package/dist/server/handler.js +0 -77
  164. package/dist/server/handler.js.map +0 -1
  165. /package/dist/tests/{server-handler.test.d.ts → permissions-revoke-relayer.test.d.ts} +0 -0
@@ -1,5 +1,5 @@
1
1
  import type { Address, Hash } from "viem";
2
- import type { GrantPermissionParams, RevokePermissionParams, PermissionGrantTypedData, GenericTypedData, OnChainPermissionGrant, GetUserPermissionsOptions, AddAndTrustServerParams, TrustServerParams, UntrustServerParams, AddAndTrustServerTypedData, TrustServerTypedData, TrustedServerInfo, PaginatedTrustedServers, TrustedServerQueryOptions, BatchServerInfoResult, ServerTrustStatus, GrantFile, Grantee, GranteeInfo, RegisterGranteeParams, RegisterGranteeTypedData, GranteeQueryOptions, PaginatedGrantees, ServerInfo, ServerFilesAndPermissionParams, ServerFilesAndPermissionTypedData, TransactionOptions } from "../types/index";
2
+ import type { GrantPermissionParams, RevokePermissionParams, PermissionGrantTypedData, GenericTypedData, OnChainPermissionGrant, GetUserPermissionsOptions, AddAndTrustServerParams, TrustServerParams, UntrustServerParams, AddAndTrustServerTypedData, TrustServerTypedData, TrustedServerInfo, PaginatedTrustedServers, TrustedServerQueryOptions, BatchServerInfoResult, ServerTrustStatus, GrantFile, Grantee, GranteeInfo, RegisterGranteeParams, GranteeQueryOptions, PaginatedGrantees, ServerInfo, ServerFilesAndPermissionParams, ServerFilesAndPermissionTypedData, TransactionOptions } from "../types/index";
3
3
  import type { PermissionGrantResult, PermissionRevokeResult, ServerTrustResult } from "../types/transactionResults";
4
4
  import type { TransactionResult } from "../types/operations";
5
5
  import type { PermissionInfo } from "../types/permissions";
@@ -18,50 +18,52 @@ import type { ControllerContext } from "../types/controller-context";
18
18
  import { BaseController } from "./base";
19
19
  export type { ControllerContext };
20
20
  /**
21
- * Manages gasless data access permissions and trusted server registry operations.
21
+ * Manages data access permissions and trusted server operations with gasless transaction support.
22
22
  *
23
23
  * @remarks
24
- * This controller enables users to grant applications access to their data without
25
- * paying gas fees. It handles the complete EIP-712 permission flow including signature
26
- * creation, IPFS storage of permission details, and gasless transaction submission.
27
- * The controller also manages trusted servers that can process user data and provides
28
- * methods for revoking permissions when access is no longer needed.
24
+ * Enables applications to access user data through EIP-712 signatures, eliminating gas fees
25
+ * for users. Handles permission lifecycle from creation through revocation, plus trusted
26
+ * server management for data processing operations.
29
27
  *
30
- * **Permission Architecture:**
31
- * Permissions use dual storage: detailed parameters stored on IPFS, references stored on blockchain.
32
- * This enables complex permissions while maintaining minimal on-chain data.
28
+ * **Architecture:**
29
+ * Permissions use dual storage: complex parameters on IPFS, references on blockchain.
30
+ * This minimizes on-chain data while maintaining decentralization and auditability.
33
31
  *
34
32
  * **Method Selection:**
35
- * - `grant()` creates new permissions with automatic IPFS upload and blockchain registration
36
- * - `prepareGrant()` allows preview before signing for interactive applications
37
- * - `revoke()` removes permissions by ID, supporting both gasless and direct transactions
38
- * - `getUserPermissionGrantsOnChain()` queries existing permissions efficiently
39
- * - `trustServer()` and `untrustServer()` manage server access for data processing
33
+ * - `grant()` - Create permissions with automatic IPFS upload and blockchain registration
34
+ * - `prepareGrant()` - Preview permission structure before signing
35
+ * - `revoke()` - Remove permissions by ID (gasless or direct)
36
+ * - `getUserPermissionGrantsOnChain()` - Query active permissions
37
+ * - `trustServer()`/`untrustServer()` - Manage server access
38
+ *
39
+ * **Gasless Support:**
40
+ * All permission methods support both gasless (via relayer) and direct transactions.
41
+ * Configure relayer callbacks in Vana initialization for gasless operations.
40
42
  *
41
- * **Transaction Types:**
42
- * Methods with gasless support: `grant()`, `revoke()`, `trustServer()`, `untrustServer()`
43
- * Methods requiring direct transactions: none (all support both gasless and direct)
44
43
  * @example
45
44
  * ```typescript
46
- * // Grant permission for an app to access your data
47
- * const txHash = await vana.permissions.grant({
45
+ * // Grant data access permission
46
+ * const result = await vana.permissions.grant({
48
47
  * grantee: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
49
48
  * operation: "llm_inference",
50
- * files: [1, 2, 3],
51
- * parameters: { model: "gpt-4", maxTokens: 1000 },
49
+ * fileIds: [1, 2, 3],
50
+ * parameters: { model: "gpt-4", maxTokens: 1000 }
52
51
  * });
52
+ * console.log(`Permission ${result.permissionId} granted`);
53
53
  *
54
- * // Trust a server for data processing
54
+ * // Trust server for processing
55
55
  * await vana.permissions.trustServer({
56
- * serverId: "0x123...",
57
- * serverUrl: "https://personal-server.vana.org",
56
+ * serverAddress: "0x123...",
57
+ * serverUrl: "https://personal-server.vana.org"
58
58
  * });
59
59
  *
60
- * // Query current permissions
60
+ * // Query active permissions
61
61
  * const permissions = await vana.permissions.getUserPermissionGrantsOnChain();
62
+ * permissions.forEach(p => console.log(`Permission ${p.id}: ${p.grantee}`));
62
63
  * ```
64
+ *
63
65
  * @category Permissions
64
- * @see {@link https://docs.vana.com/developer/permissions | Vana Permissions System} for conceptual overview
66
+ * @see For conceptual overview, visit {@link https://docs.vana.org/docs/permissions}
65
67
  */
66
68
  export declare class PermissionsController extends BaseController {
67
69
  constructor(context: ControllerContext);
@@ -859,35 +861,6 @@ export declare class PermissionsController extends BaseController {
859
861
  * ```
860
862
  */
861
863
  submitRegisterGrantee(params: RegisterGranteeParams, options?: TransactionOptions): Promise<TransactionResult<"DataPortabilityGrantees", "registerGrantee">>;
862
- /**
863
- * Registers a grantee with a signature (gasless transaction)
864
- *
865
- * @param params - Parameters for registering the grantee
866
- * @returns Promise resolving to the transaction hash
867
- *
868
- * @example
869
- * ```typescript
870
- * const txHash = await vana.permissions.registerGranteeWithSignature({
871
- * owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
872
- * granteeAddress: "0xApp1234567890123456789012345678901234567890",
873
- * publicKey: "0x1234567890abcdef..."
874
- * });
875
- * ```
876
- */
877
- submitRegisterGranteeWithSignature(params: RegisterGranteeParams): Promise<TransactionResult<"DataPortabilityGrantees", "registerGrantee">>;
878
- /**
879
- * Submits a signed register grantee transaction via relayer
880
- *
881
- * @param typedData - The EIP-712 typed data for register grantee
882
- * @param signature - The cryptographic signature
883
- * @returns Promise resolving to the transaction hash
884
- *
885
- * @example
886
- * ```typescript
887
- * const result = await vana.permissions.submitSignedRegisterGrantee(typedData, signature);
888
- * ```
889
- */
890
- submitSignedRegisterGrantee(typedData: RegisterGranteeTypedData, signature: Hash): Promise<TransactionResult<"DataPortabilityGrantees", "registerGrantee">>;
891
864
  /**
892
865
  * Retrieves all registered grantees from the DataPortabilityGrantees contract.
893
866
  *
@@ -974,23 +947,6 @@ export declare class PermissionsController extends BaseController {
974
947
  * ```
975
948
  */
976
949
  getGranteeById(granteeId: number): Promise<Grantee | null>;
977
- /**
978
- * Builds EIP-712 typed data for grantee registration
979
- *
980
- * @param input - The register grantee input
981
- * @returns Promise resolving to the typed data structure
982
- * @private
983
- */
984
- private buildRegisterGranteeTypedData;
985
- /**
986
- * Submits a register grantee transaction with signature.
987
- *
988
- * @param typedData - The EIP-712 typed data structure for the registration
989
- * @param _signature - The cryptographic signature authorizing the registration (currently unused)
990
- * @returns Promise resolving to the transaction hash
991
- * @private
992
- */
993
- private submitSignedRegisterGranteeTransaction;
994
950
  /**
995
951
  * Get all trusted server IDs for a user
996
952
  *
@@ -163,17 +163,31 @@ class PermissionsController extends BaseController {
163
163
  let { grantUrl } = params;
164
164
  console.debug("\u{1F50D} Debug - Grant URL from params:", grantUrl);
165
165
  if (!grantUrl) {
166
- if (!this.context.relayerCallbacks?.storeGrantFile && !this.context.storageManager) {
166
+ const canStoreViaRelayer = this.context.relayer !== void 0;
167
+ if (!canStoreViaRelayer && !this.context.storageManager) {
167
168
  if (this.context.validateStorageRequired) {
168
169
  this.context.validateStorageRequired();
169
170
  } else {
170
171
  throw new Error(
171
- "No storage available. Provide a grantUrl, configure relayerCallbacks.storeGrantFile, or storageManager."
172
+ "No storage available. Provide a grantUrl, configure relayer, or storageManager."
172
173
  );
173
174
  }
174
175
  }
175
- if (this.context.relayerCallbacks?.storeGrantFile) {
176
- grantUrl = await this.context.relayerCallbacks.storeGrantFile(grantFile);
176
+ if (canStoreViaRelayer && this.context.relayer) {
177
+ const request = {
178
+ type: "direct",
179
+ operation: "storeGrantFile",
180
+ params: grantFile
181
+ };
182
+ const response = await this.context.relayer(request);
183
+ if (response.type === "error") {
184
+ throw new Error(response.error);
185
+ }
186
+ if (response.type === "direct" && typeof response.result === "object" && "url" in response.result) {
187
+ grantUrl = response.result.url;
188
+ } else {
189
+ throw new Error("Invalid response from relayer for grant storage");
190
+ }
177
191
  } else if (this.context.storageManager) {
178
192
  const blob = new Blob([JSON.stringify(grantFile)], {
179
193
  type: "application/json"
@@ -257,17 +271,31 @@ class PermissionsController extends BaseController {
257
271
  let { grantUrl } = params;
258
272
  console.debug("\u{1F50D} Debug - Grant URL from params:", grantUrl);
259
273
  if (!grantUrl) {
260
- if (!this.context.relayerCallbacks?.storeGrantFile && !this.context.storageManager) {
274
+ const canStoreViaRelayer = this.context.relayer !== void 0;
275
+ if (!canStoreViaRelayer && !this.context.storageManager) {
261
276
  if (this.context.validateStorageRequired) {
262
277
  this.context.validateStorageRequired();
263
278
  } else {
264
279
  throw new Error(
265
- "No storage available. Provide a grantUrl, configure relayerCallbacks.storeGrantFile, or storageManager."
280
+ "No storage available. Provide a grantUrl, configure relayer, or storageManager."
266
281
  );
267
282
  }
268
283
  }
269
- if (this.context.relayerCallbacks?.storeGrantFile) {
270
- grantUrl = await this.context.relayerCallbacks.storeGrantFile(grantFile);
284
+ if (canStoreViaRelayer && this.context.relayer) {
285
+ const request = {
286
+ type: "direct",
287
+ operation: "storeGrantFile",
288
+ params: grantFile
289
+ };
290
+ const response = await this.context.relayer(request);
291
+ if (response.type === "error") {
292
+ throw new Error(response.error);
293
+ }
294
+ if (response.type === "direct" && typeof response.result === "object" && "url" in response.result) {
295
+ grantUrl = response.result.url;
296
+ } else {
297
+ throw new Error("Invalid response from relayer for grant storage");
298
+ }
271
299
  } else if (this.context.storageManager) {
272
300
  const blob = new Blob([JSON.stringify(grantFile)], {
273
301
  type: "application/json"
@@ -346,11 +374,24 @@ class PermissionsController extends BaseController {
346
374
  2
347
375
  )
348
376
  );
349
- if (this.context.relayerCallbacks?.submitPermissionGrant) {
350
- const hash = await this.context.relayerCallbacks.submitPermissionGrant(
377
+ if (this.context.relayer) {
378
+ const response = await this.context.relayer({
379
+ type: "signed",
380
+ operation: "submitAddPermission",
351
381
  typedData,
352
- signature
353
- );
382
+ signature,
383
+ expectedUserAddress: this.context.userAddress
384
+ });
385
+ let hash;
386
+ if (response.type === "signed") {
387
+ hash = response.hash;
388
+ } else if (response.type === "error") {
389
+ throw new Error(`Relayer error: ${response.error}`);
390
+ } else {
391
+ throw new Error(
392
+ "Invalid response from relayer: expected signed transaction"
393
+ );
394
+ }
354
395
  const account = this.context.walletClient?.account ?? this.context.userAddress;
355
396
  const { tx } = await import("../utils/transactionHelpers");
356
397
  return tx({
@@ -576,11 +617,23 @@ class PermissionsController extends BaseController {
576
617
  async submitSignedRevoke(typedData, signature) {
577
618
  try {
578
619
  let hash;
579
- if (this.context.relayerCallbacks?.submitPermissionRevoke) {
580
- hash = await this.context.relayerCallbacks.submitPermissionRevoke(
620
+ if (this.context.relayer) {
621
+ const response = await this.context.relayer({
622
+ type: "signed",
623
+ operation: "submitPermissionRevoke",
581
624
  typedData,
582
- signature
583
- );
625
+ signature,
626
+ expectedUserAddress: this.context.userAddress
627
+ });
628
+ if (response.type === "signed") {
629
+ hash = response.hash;
630
+ } else if (response.type === "error") {
631
+ throw new Error(`Relayer error: ${response.error}`);
632
+ } else {
633
+ throw new Error(
634
+ "Invalid response from relayer: expected signed transaction"
635
+ );
636
+ }
584
637
  } else {
585
638
  hash = await this.submitDirectRevokeTransaction(
586
639
  typedData,
@@ -629,11 +682,23 @@ class PermissionsController extends BaseController {
629
682
  async submitSignedUntrustServer(typedData, signature) {
630
683
  try {
631
684
  let hash;
632
- if (this.context.relayerCallbacks?.submitUntrustServer) {
633
- hash = await this.context.relayerCallbacks.submitUntrustServer(
685
+ if (this.context.relayer) {
686
+ const response = await this.context.relayer({
687
+ type: "signed",
688
+ operation: "submitUntrustServer",
634
689
  typedData,
635
- signature
636
- );
690
+ signature,
691
+ expectedUserAddress: this.context.userAddress
692
+ });
693
+ if (response.type === "signed") {
694
+ hash = response.hash;
695
+ } else if (response.type === "error") {
696
+ throw new Error(`Relayer error: ${response.error}`);
697
+ } else {
698
+ throw new Error(
699
+ "Invalid response from relayer: expected signed transaction"
700
+ );
701
+ }
637
702
  } else {
638
703
  hash = await this.submitSignedUntrustTransaction(
639
704
  typedData,
@@ -882,11 +947,23 @@ class PermissionsController extends BaseController {
882
947
  };
883
948
  const signature = await this.signTypedData(typedData);
884
949
  let hash;
885
- if (this.context.relayerCallbacks?.submitPermissionRevoke) {
886
- hash = await this.context.relayerCallbacks.submitPermissionRevoke(
950
+ if (this.context.relayer) {
951
+ const response = await this.context.relayer({
952
+ type: "signed",
953
+ operation: "submitPermissionRevoke",
887
954
  typedData,
888
- signature
889
- );
955
+ signature,
956
+ expectedUserAddress: this.context.userAddress
957
+ });
958
+ if (response.type === "signed") {
959
+ hash = response.hash;
960
+ } else if (response.type === "error") {
961
+ throw new Error(`Relayer error: ${response.error}`);
962
+ } else {
963
+ throw new Error(
964
+ "Invalid response from relayer: expected signed transaction"
965
+ );
966
+ }
890
967
  } else {
891
968
  hash = await this.submitDirectRevokeTransaction(
892
969
  typedData,
@@ -1480,11 +1557,22 @@ class PermissionsController extends BaseController {
1480
1557
  const signature = await this.signTypedData(typedData);
1481
1558
  console.debug("\u{1F50D} Generated signature:", signature);
1482
1559
  let hash;
1483
- if (this.context.relayerCallbacks?.submitAddAndTrustServer) {
1484
- hash = await this.context.relayerCallbacks.submitAddAndTrustServer(
1560
+ if (this.context.relayer) {
1561
+ const request = {
1562
+ type: "signed",
1563
+ operation: "submitAddAndTrustServer",
1485
1564
  typedData,
1486
1565
  signature
1487
- );
1566
+ };
1567
+ const response = await this.context.relayer(request);
1568
+ if (response.type === "error") {
1569
+ throw new RelayerError(response.error);
1570
+ }
1571
+ if (response.type === "signed") {
1572
+ hash = response.hash;
1573
+ } else {
1574
+ throw new Error("Unexpected response type from relayer");
1575
+ }
1488
1576
  } else {
1489
1577
  hash = await this.submitAddAndTrustServerTransaction(
1490
1578
  addAndTrustServerInput,
@@ -1538,11 +1626,22 @@ class PermissionsController extends BaseController {
1538
1626
  const typedData = await this.composeTrustServerMessage(trustServerInput);
1539
1627
  const signature = await this.signTypedData(typedData);
1540
1628
  let hash;
1541
- if (this.context.relayerCallbacks?.submitTrustServer) {
1542
- hash = await this.context.relayerCallbacks.submitTrustServer(
1629
+ if (this.context.relayer) {
1630
+ const request = {
1631
+ type: "signed",
1632
+ operation: "submitTrustServer",
1543
1633
  typedData,
1544
1634
  signature
1545
- );
1635
+ };
1636
+ const response = await this.context.relayer(request);
1637
+ if (response.type === "error") {
1638
+ throw new RelayerError(response.error);
1639
+ }
1640
+ if (response.type === "signed") {
1641
+ hash = response.hash;
1642
+ } else {
1643
+ throw new Error("Unexpected response type from relayer");
1644
+ }
1546
1645
  } else {
1547
1646
  hash = await this.submitTrustServerTransaction(
1548
1647
  trustServerInput,
@@ -1697,11 +1796,22 @@ class PermissionsController extends BaseController {
1697
1796
  const typedData = await this.composeUntrustServerMessage(untrustServerInput);
1698
1797
  const signature = await this.signTypedData(typedData);
1699
1798
  let hash;
1700
- if (this.context.relayerCallbacks?.submitUntrustServer) {
1701
- hash = await this.context.relayerCallbacks.submitUntrustServer(
1799
+ if (this.context.relayer) {
1800
+ const request = {
1801
+ type: "signed",
1802
+ operation: "submitUntrustServer",
1702
1803
  typedData,
1703
1804
  signature
1704
- );
1805
+ };
1806
+ const response = await this.context.relayer(request);
1807
+ if (response.type === "error") {
1808
+ throw new RelayerError(response.error);
1809
+ }
1810
+ if (response.type === "signed") {
1811
+ hash = response.hash;
1812
+ } else {
1813
+ throw new Error("Unexpected response type from relayer");
1814
+ }
1705
1815
  } else {
1706
1816
  hash = await this.submitSignedUntrustTransaction(typedData, signature);
1707
1817
  }
@@ -2334,73 +2444,9 @@ class PermissionsController extends BaseController {
2334
2444
  fn: "registerGrantee"
2335
2445
  });
2336
2446
  }
2337
- /**
2338
- * Registers a grantee with a signature (gasless transaction)
2339
- *
2340
- * @param params - Parameters for registering the grantee
2341
- * @returns Promise resolving to the transaction hash
2342
- *
2343
- * @example
2344
- * ```typescript
2345
- * const txHash = await vana.permissions.registerGranteeWithSignature({
2346
- * owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
2347
- * granteeAddress: "0xApp1234567890123456789012345678901234567890",
2348
- * publicKey: "0x1234567890abcdef..."
2349
- * });
2350
- * ```
2351
- */
2352
- async submitRegisterGranteeWithSignature(params) {
2353
- this.assertWallet();
2354
- const nonce = await this.getServersUserNonce();
2355
- const owner = getAddress(params.owner);
2356
- const granteeAddress = getAddress(params.granteeAddress);
2357
- const registerGranteeInput = {
2358
- nonce,
2359
- owner,
2360
- granteeAddress,
2361
- publicKey: params.publicKey
2362
- };
2363
- const typedData = await this.buildRegisterGranteeTypedData(registerGranteeInput);
2364
- const signature = await this.signTypedData(typedData);
2365
- const hash = await this.submitSignedRegisterGranteeTransaction(
2366
- typedData,
2367
- signature
2368
- );
2369
- const account = this.context.walletClient?.account ?? this.context.userAddress;
2370
- const { tx } = await import("../utils/transactionHelpers");
2371
- return tx({
2372
- hash,
2373
- from: typeof account === "string" ? account : account.address,
2374
- contract: "DataPortabilityGrantees",
2375
- fn: "registerGrantee"
2376
- });
2377
- }
2378
- /**
2379
- * Submits a signed register grantee transaction via relayer
2380
- *
2381
- * @param typedData - The EIP-712 typed data for register grantee
2382
- * @param signature - The cryptographic signature
2383
- * @returns Promise resolving to the transaction hash
2384
- *
2385
- * @example
2386
- * ```typescript
2387
- * const result = await vana.permissions.submitSignedRegisterGrantee(typedData, signature);
2388
- * ```
2389
- */
2390
- async submitSignedRegisterGrantee(typedData, signature) {
2391
- const hash = await this.submitSignedRegisterGranteeTransaction(
2392
- typedData,
2393
- signature
2394
- );
2395
- const account = this.context.walletClient?.account ?? this.context.userAddress;
2396
- const { tx } = await import("../utils/transactionHelpers");
2397
- return tx({
2398
- hash,
2399
- from: typeof account === "string" ? account : account.address,
2400
- contract: "DataPortabilityGrantees",
2401
- fn: "registerGrantee"
2402
- });
2403
- }
2447
+ // TODO: When DataPortabilityGrantees contract adds registerGranteeWithSignature function,
2448
+ // implement submitRegisterGranteeWithSignature and submitSignedRegisterGrantee methods
2449
+ // to support gasless transactions via relayer
2404
2450
  /**
2405
2451
  * Retrieves all registered grantees from the DataPortabilityGrantees contract.
2406
2452
  *
@@ -2587,68 +2633,6 @@ class PermissionsController extends BaseController {
2587
2633
  return null;
2588
2634
  }
2589
2635
  }
2590
- /**
2591
- * Builds EIP-712 typed data for grantee registration
2592
- *
2593
- * @param input - The register grantee input
2594
- * @returns Promise resolving to the typed data structure
2595
- * @private
2596
- */
2597
- async buildRegisterGranteeTypedData(input) {
2598
- const chainId = await this.context.publicClient.getChainId();
2599
- const verifyingContract = getContractAddress(
2600
- chainId,
2601
- "DataPortabilityGrantees"
2602
- );
2603
- return {
2604
- domain: {
2605
- name: "DataPortabilityGrantees",
2606
- version: "1",
2607
- chainId,
2608
- verifyingContract
2609
- },
2610
- types: {
2611
- RegisterGrantee: [
2612
- { name: "nonce", type: "uint256" },
2613
- { name: "owner", type: "address" },
2614
- { name: "granteeAddress", type: "address" },
2615
- { name: "publicKey", type: "string" }
2616
- ]
2617
- },
2618
- primaryType: "RegisterGrantee",
2619
- message: input
2620
- };
2621
- }
2622
- /**
2623
- * Submits a register grantee transaction with signature.
2624
- *
2625
- * @param typedData - The EIP-712 typed data structure for the registration
2626
- * @param _signature - The cryptographic signature authorizing the registration (currently unused)
2627
- * @returns Promise resolving to the transaction hash
2628
- * @private
2629
- */
2630
- async submitSignedRegisterGranteeTransaction(typedData, _signature) {
2631
- this.assertWallet();
2632
- const chainId = await this.context.walletClient.getChainId();
2633
- const DataPortabilityGranteesAddress = getContractAddress(
2634
- chainId,
2635
- "DataPortabilityGrantees"
2636
- );
2637
- const DataPortabilityGranteesAbi = getAbi("DataPortabilityGrantees");
2638
- const txHash = await this.context.walletClient.writeContract({
2639
- address: DataPortabilityGranteesAddress,
2640
- abi: DataPortabilityGranteesAbi,
2641
- functionName: "registerGrantee",
2642
- args: [
2643
- typedData.message.owner,
2644
- typedData.message.granteeAddress,
2645
- typedData.message.publicKey
2646
- ],
2647
- account: this.context.walletClient?.account ?? this.context.userAddress,
2648
- chain: this.context.walletClient?.chain ?? null
2649
- });
2650
- return txHash;
2651
- }
2652
2636
  // ===========================
2653
2637
  // DATA PORTABILITY SERVERS HELPER METHODS
2654
2638
  // ===========================
@@ -3598,11 +3582,22 @@ class PermissionsController extends BaseController {
3598
3582
  this.assertWallet();
3599
3583
  try {
3600
3584
  let hash;
3601
- if (this.context.relayerCallbacks?.submitAddPermission) {
3602
- hash = await this.context.relayerCallbacks.submitAddPermission(
3585
+ if (this.context.relayer) {
3586
+ const request = {
3587
+ type: "signed",
3588
+ operation: "submitAddPermission",
3603
3589
  typedData,
3604
3590
  signature
3605
- );
3591
+ };
3592
+ const response = await this.context.relayer(request);
3593
+ if (response.type === "error") {
3594
+ throw new RelayerError(response.error);
3595
+ }
3596
+ if (response.type === "signed") {
3597
+ hash = response.hash;
3598
+ } else {
3599
+ throw new Error("Unexpected response type from relayer");
3600
+ }
3606
3601
  } else {
3607
3602
  hash = await this.submitDirectAddPermissionTransaction(
3608
3603
  typedData,
@@ -3760,45 +3755,44 @@ class PermissionsController extends BaseController {
3760
3755
  async submitSignedAddServerFilesAndPermissions(typedData, signature, options) {
3761
3756
  this.assertWallet();
3762
3757
  try {
3763
- console.debug("\u{1F50D} submitSignedAddServerFilesAndPermissions Debug Info:", {
3764
- hasRelayerCallbacks: !!this.context.relayerCallbacks,
3765
- hasSubmitMethod: !!this.context.relayerCallbacks?.submitAddServerFilesAndPermissions,
3766
- availableRelayerMethods: this.context.relayerCallbacks ? Object.keys(this.context.relayerCallbacks) : []
3767
- });
3768
- if (this.context.relayerCallbacks?.submitAddServerFilesAndPermissions) {
3758
+ let hash;
3759
+ if (this.context.relayer) {
3769
3760
  console.debug(
3770
3761
  "\u{1F680} Using relayer for submitAddServerFilesAndPermissions"
3771
3762
  );
3772
- const hash = await this.context.relayerCallbacks.submitAddServerFilesAndPermissions(
3763
+ const request = {
3764
+ type: "signed",
3765
+ operation: "submitAddServerFilesAndPermissions",
3773
3766
  typedData,
3774
3767
  signature
3775
- );
3776
- const account = this.context.walletClient?.account ?? this.context.userAddress;
3777
- const { tx } = await import("../utils/transactionHelpers");
3778
- return tx({
3779
- hash,
3780
- from: typeof account === "string" ? account : account.address,
3781
- contract: "DataPortabilityPermissions",
3782
- fn: "addServerFilesAndPermissions"
3783
- });
3768
+ };
3769
+ const response = await this.context.relayer(request);
3770
+ if (response.type === "error") {
3771
+ throw new RelayerError(response.error);
3772
+ }
3773
+ if (response.type === "signed") {
3774
+ hash = response.hash;
3775
+ } else {
3776
+ throw new Error("Unexpected response type from relayer");
3777
+ }
3784
3778
  } else {
3785
3779
  console.debug(
3786
3780
  "\u{1F4DD} Using direct transaction for submitAddServerFilesAndPermissions"
3787
3781
  );
3788
- const hash = await this.submitDirectAddServerFilesAndPermissionsTransaction(
3782
+ hash = await this.submitDirectAddServerFilesAndPermissionsTransaction(
3789
3783
  typedData,
3790
3784
  signature,
3791
3785
  options
3792
3786
  );
3793
- const account = this.context.userAddress;
3794
- const { tx } = await import("../utils/transactionHelpers");
3795
- return tx({
3796
- hash,
3797
- from: account,
3798
- contract: "DataPortabilityPermissions",
3799
- fn: "addServerFilesAndPermissions"
3800
- });
3801
3787
  }
3788
+ const account = this.context.walletClient?.account ?? this.context.userAddress;
3789
+ const { tx } = await import("../utils/transactionHelpers");
3790
+ return tx({
3791
+ hash,
3792
+ from: typeof account === "string" ? account : account.address,
3793
+ contract: "DataPortabilityPermissions",
3794
+ fn: "addServerFilesAndPermissions"
3795
+ });
3802
3796
  } catch (error) {
3803
3797
  if (error instanceof RelayerError || error instanceof NetworkError || error instanceof UserRejectedRequestError || error instanceof SignatureError || error instanceof NonceError) {
3804
3798
  throw error;