@opendatalabs/vana-sdk 0.1.0-alpha.f35bb9c → 0.1.0-alpha.f48b66e

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 (95) hide show
  1. package/dist/controllers/__tests__/data-consistency-integration.test.d.ts +7 -0
  2. package/dist/controllers/base.cjs +33 -0
  3. package/dist/controllers/base.cjs.map +1 -1
  4. package/dist/controllers/base.d.ts +10 -0
  5. package/dist/controllers/base.js +33 -0
  6. package/dist/controllers/base.js.map +1 -1
  7. package/dist/controllers/data.cjs +210 -147
  8. package/dist/controllers/data.cjs.map +1 -1
  9. package/dist/controllers/data.d.ts +15 -12
  10. package/dist/controllers/data.js +223 -150
  11. package/dist/controllers/data.js.map +1 -1
  12. package/dist/controllers/permissions.cjs +203 -94
  13. package/dist/controllers/permissions.cjs.map +1 -1
  14. package/dist/controllers/permissions.d.ts +20 -11
  15. package/dist/controllers/permissions.js +203 -94
  16. package/dist/controllers/permissions.js.map +1 -1
  17. package/dist/controllers/schemas.cjs +11 -1
  18. package/dist/controllers/schemas.cjs.map +1 -1
  19. package/dist/controllers/schemas.d.ts +2 -0
  20. package/dist/controllers/schemas.js +11 -1
  21. package/dist/controllers/schemas.js.map +1 -1
  22. package/dist/core.cjs +4 -1
  23. package/dist/core.cjs.map +1 -1
  24. package/dist/core.d.ts +2 -1
  25. package/dist/core.js +4 -1
  26. package/dist/core.js.map +1 -1
  27. package/dist/generated/subgraph.cjs +797 -32
  28. package/dist/generated/subgraph.cjs.map +1 -1
  29. package/dist/generated/subgraph.d.ts +135 -0
  30. package/dist/generated/subgraph.js +792 -32
  31. package/dist/generated/subgraph.js.map +1 -1
  32. package/dist/index.node.cjs +2 -0
  33. package/dist/index.node.cjs.map +1 -1
  34. package/dist/index.node.d.ts +27 -4
  35. package/dist/index.node.js +2 -0
  36. package/dist/index.node.js.map +1 -1
  37. package/dist/server/relayerHandler.cjs +201 -87
  38. package/dist/server/relayerHandler.cjs.map +1 -1
  39. package/dist/server/relayerHandler.d.ts +3 -1
  40. package/dist/server/relayerHandler.js +201 -87
  41. package/dist/server/relayerHandler.js.map +1 -1
  42. package/dist/types/config.cjs.map +1 -1
  43. package/dist/types/config.d.ts +32 -0
  44. package/dist/types/config.js.map +1 -1
  45. package/dist/types/controller-context.cjs.map +1 -1
  46. package/dist/types/controller-context.d.ts +3 -1
  47. package/dist/types/data.cjs.map +1 -1
  48. package/dist/types/data.d.ts +0 -4
  49. package/dist/types/generics.cjs.map +1 -1
  50. package/dist/types/generics.d.ts +1 -1
  51. package/dist/types/index.cjs.map +1 -1
  52. package/dist/types/index.d.ts +4 -2
  53. package/dist/types/index.js.map +1 -1
  54. package/dist/types/operations.cjs.map +1 -1
  55. package/dist/types/operations.d.ts +33 -0
  56. package/dist/types/operations.js.map +1 -1
  57. package/dist/types/options.cjs +17 -0
  58. package/dist/types/options.cjs.map +1 -0
  59. package/dist/types/options.d.ts +213 -0
  60. package/dist/types/options.js +1 -0
  61. package/dist/types/options.js.map +1 -0
  62. package/dist/types/permissions.cjs.map +1 -1
  63. package/dist/types/permissions.d.ts +2 -0
  64. package/dist/types/relayer.cjs.map +1 -1
  65. package/dist/types/relayer.d.ts +19 -8
  66. package/dist/types/utils.cjs.map +1 -1
  67. package/dist/types/utils.d.ts +0 -49
  68. package/dist/utils/__tests__/subgraphConsistency.test.d.ts +4 -0
  69. package/dist/utils/__tests__/subgraphPagination.test.d.ts +4 -0
  70. package/dist/utils/chainQuery.cjs +107 -0
  71. package/dist/utils/chainQuery.cjs.map +1 -0
  72. package/dist/utils/chainQuery.d.ts +31 -0
  73. package/dist/utils/chainQuery.js +82 -0
  74. package/dist/utils/chainQuery.js.map +1 -0
  75. package/dist/utils/ipfs.cjs +2 -4
  76. package/dist/utils/ipfs.cjs.map +1 -1
  77. package/dist/utils/ipfs.d.ts +1 -1
  78. package/dist/utils/ipfs.js +2 -4
  79. package/dist/utils/ipfs.js.map +1 -1
  80. package/dist/utils/subgraphConsistency.cjs +184 -0
  81. package/dist/utils/subgraphConsistency.cjs.map +1 -0
  82. package/dist/utils/subgraphConsistency.d.ts +65 -0
  83. package/dist/utils/subgraphConsistency.js +155 -0
  84. package/dist/utils/subgraphConsistency.js.map +1 -0
  85. package/dist/utils/subgraphMetaCache.cjs +101 -0
  86. package/dist/utils/subgraphMetaCache.cjs.map +1 -0
  87. package/dist/utils/subgraphMetaCache.d.ts +56 -0
  88. package/dist/utils/subgraphMetaCache.js +76 -0
  89. package/dist/utils/subgraphMetaCache.js.map +1 -0
  90. package/dist/utils/subgraphPagination.cjs +104 -0
  91. package/dist/utils/subgraphPagination.cjs.map +1 -0
  92. package/dist/utils/subgraphPagination.d.ts +78 -0
  93. package/dist/utils/subgraphPagination.js +78 -0
  94. package/dist/utils/subgraphPagination.js.map +1 -0
  95. package/package.json +3 -1
@@ -3,13 +3,26 @@ import { BaseController } from "./base";
3
3
  import { getContractAddress } from "../config/addresses";
4
4
  import { getAbi } from "../generated/abi";
5
5
  import {
6
- GetUserFilesDocument,
6
+ GetUserFilesPaginatedDocument,
7
7
  GetFileProofsDocument,
8
8
  GetDlpDocument,
9
- GetUserPermissionsDocument,
10
- GetUserTrustedServersDocument
9
+ GetUserPermissionsPaginatedDocument,
10
+ GetUserTrustedServersPaginatedDocument
11
11
  } from "../generated/subgraph";
12
12
  import { print } from "graphql";
13
+ import {
14
+ checkSubgraphConsistency,
15
+ fetchSubgraphMeta
16
+ } from "../utils/subgraphConsistency";
17
+ import {
18
+ executePaginatedQuery,
19
+ mapOrderByToEnum,
20
+ mapOrderDirection
21
+ } from "../utils/subgraphPagination";
22
+ import {
23
+ getUserFilesFromChain,
24
+ determineDataSource
25
+ } from "../utils/chainQuery";
13
26
  import {
14
27
  generateEncryptionKey,
15
28
  decryptBlobWithSignedKey,
@@ -124,7 +137,7 @@ class DataController extends BaseController {
124
137
  if (response.type === "error") {
125
138
  throw new Error(response.error);
126
139
  }
127
- if (response.type !== "direct" || !("fileId" in response.result)) {
140
+ if (response.type !== "direct" || typeof response.result !== "object" || response.result === null || !("fileId" in response.result)) {
128
141
  throw new Error("Invalid response from relayer");
129
142
  }
130
143
  result = response.result;
@@ -419,67 +432,91 @@ class DataController extends BaseController {
419
432
  * });
420
433
  * ```
421
434
  */
422
- async getUserFiles(params) {
435
+ async getUserFiles(params, options) {
423
436
  const { owner, subgraphUrl } = params;
437
+ let dataSource = options?.source === "chain" ? "chain" : "subgraph";
438
+ if (options?.source === "auto" || !options?.source && options?.minBlock) {
439
+ const endpoint2 = subgraphUrl ?? this.context.subgraphUrl;
440
+ const currentBlock = await this.context.publicClient.getBlockNumber();
441
+ let subgraphBlock;
442
+ if (endpoint2) {
443
+ try {
444
+ const meta = await fetchSubgraphMeta(endpoint2);
445
+ subgraphBlock = meta.blockNumber;
446
+ } catch {
447
+ subgraphBlock = void 0;
448
+ }
449
+ }
450
+ dataSource = determineDataSource(
451
+ options?.source,
452
+ options?.minBlock,
453
+ currentBlock,
454
+ subgraphBlock
455
+ );
456
+ }
457
+ if (dataSource === "chain") {
458
+ const publicClient = this.context.publicClient;
459
+ const chainId = await publicClient.getChainId();
460
+ const contractAddress = getContractAddress(chainId, "DataRegistry");
461
+ const files = await getUserFilesFromChain(
462
+ publicClient,
463
+ contractAddress,
464
+ owner,
465
+ options?.minBlock ? BigInt(options.minBlock) : void 0
466
+ );
467
+ const limit = options?.fetchAll ? files.length : options?.limit ?? 100;
468
+ const offset = options?.offset ?? 0;
469
+ return files.slice(offset, offset + limit);
470
+ }
424
471
  const endpoint = subgraphUrl ?? this.context.subgraphUrl;
425
472
  if (!endpoint) {
426
473
  throw new Error(
427
474
  "subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor."
428
475
  );
429
476
  }
477
+ if (options?.minBlock || options?.waitForSync) {
478
+ await checkSubgraphConsistency(endpoint, options);
479
+ }
430
480
  try {
431
- const response = await fetch(endpoint, {
432
- method: "POST",
433
- headers: {
434
- "Content-Type": "application/json"
481
+ const orderByMap = {
482
+ id: "id",
483
+ addedAtBlock: "addedAtBlock",
484
+ addedAtTimestamp: "addedAtTimestamp",
485
+ url: "url",
486
+ schemaId: "schemaId"
487
+ };
488
+ const allFiles = await executePaginatedQuery({
489
+ endpoint,
490
+ document: GetUserFilesPaginatedDocument,
491
+ baseVariables: {
492
+ userId: owner.toLowerCase(),
493
+ // Subgraph requires lowercase addresses
494
+ orderBy: mapOrderByToEnum(
495
+ options?.orderBy,
496
+ orderByMap,
497
+ "addedAtBlock"
498
+ ),
499
+ orderDirection: mapOrderDirection(
500
+ options?.orderDirection,
501
+ "asc",
502
+ "desc"
503
+ )
435
504
  },
436
- body: JSON.stringify({
437
- query: print(GetUserFilesDocument),
438
- variables: {
439
- userId: owner.toLowerCase()
440
- // Subgraph requires lowercase addresses
441
- }
442
- })
443
- });
444
- if (!response.ok) {
445
- throw new Error(
446
- `Subgraph request failed: ${response.status} ${response.statusText}`
447
- );
448
- }
449
- const result = await response.json();
450
- if (result.errors) {
451
- throw new Error(
452
- `Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
453
- );
454
- }
455
- const user = result.data?.user;
456
- if (!user?.files?.length) {
457
- console.warn("No files found for user:", owner);
458
- return [];
459
- }
460
- const fileMap = /* @__PURE__ */ new Map();
461
- user.files.forEach((file) => {
462
- const fileId = parseInt(file.id);
463
- const userFile = {
464
- id: fileId,
505
+ options,
506
+ extractItems: (data) => data?.user?.files,
507
+ transformItem: (file) => ({
508
+ id: parseInt(file.id),
465
509
  url: file.url,
466
510
  ownerAddress: file.owner.id,
467
511
  addedAtBlock: BigInt(file.addedAtBlock),
468
512
  schemaId: parseInt(file.schemaId),
469
513
  addedAtTimestamp: BigInt(file.addedAtTimestamp),
470
514
  transactionHash: file.transactionHash
471
- };
472
- const existing = fileMap.get(fileId);
473
- if (!existing || userFile.addedAtTimestamp && existing.addedAtTimestamp && userFile.addedAtTimestamp > existing.addedAtTimestamp) {
474
- fileMap.set(fileId, userFile);
475
- }
515
+ })
476
516
  });
477
- const userFiles = Array.from(fileMap.values()).sort(
478
- (a, b) => Number((b.addedAtTimestamp ?? 0n) - (a.addedAtTimestamp ?? 0n))
479
- );
480
- if (userFiles.length > 0) {
517
+ if (allFiles.length > 0) {
481
518
  try {
482
- const fileIds = userFiles.map((f) => f.id);
519
+ const fileIds = allFiles.map((f) => f.id);
483
520
  let proofMap;
484
521
  try {
485
522
  proofMap = await this._fetchProofsFromSubgraph(fileIds, endpoint);
@@ -490,7 +527,7 @@ class DataController extends BaseController {
490
527
  );
491
528
  proofMap = await this._fetchProofsFromChain(fileIds);
492
529
  }
493
- for (const file of userFiles) {
530
+ for (const file of allFiles) {
494
531
  const dlpIds = proofMap.get(file.id);
495
532
  if (dlpIds && dlpIds.length > 0) {
496
533
  file.dlpIds = dlpIds;
@@ -500,7 +537,7 @@ class DataController extends BaseController {
500
537
  console.warn("Failed to fetch proof data for files:", error);
501
538
  }
502
539
  }
503
- return userFiles;
540
+ return allFiles;
504
541
  } catch (error) {
505
542
  console.error("Failed to fetch user files from subgraph:", error);
506
543
  throw new Error(
@@ -626,6 +663,9 @@ class DataController extends BaseController {
626
663
  */
627
664
  async getDLP(dlpId, options = {}) {
628
665
  const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
666
+ if (subgraphUrl && (options.minBlock || options.waitForSync)) {
667
+ await checkSubgraphConsistency(subgraphUrl, options);
668
+ }
629
669
  if (subgraphUrl) {
630
670
  try {
631
671
  const response = await fetch(subgraphUrl, {
@@ -844,21 +884,33 @@ class DataController extends BaseController {
844
884
  * @returns Promise resolving to an array of permission objects
845
885
  * @throws Error if both subgraph and RPC queries fail
846
886
  */
847
- async getUserPermissions(params) {
887
+ async getUserPermissions(params, options) {
848
888
  const { user, subgraphUrl } = params;
849
889
  const endpoint = subgraphUrl ?? this.context.subgraphUrl;
890
+ if (endpoint && (options?.minBlock || options?.waitForSync)) {
891
+ await checkSubgraphConsistency(endpoint, options);
892
+ }
850
893
  if (endpoint) {
851
894
  try {
852
- const permissions = await this._getUserPermissionsViaSubgraph({
853
- user,
854
- subgraphUrl: endpoint
855
- });
895
+ const permissions = await this._getUserPermissionsViaSubgraph(
896
+ {
897
+ user,
898
+ subgraphUrl: endpoint
899
+ },
900
+ options
901
+ );
856
902
  return permissions;
857
903
  } catch (error) {
858
904
  console.warn("Subgraph query failed, falling back to RPC:", error);
859
905
  }
860
906
  }
861
- return await this._getUserPermissionsViaRpc({ user });
907
+ const allPermissions = await this._getUserPermissionsViaRpc({ user });
908
+ if (options && !options.fetchAll) {
909
+ const limit = options.limit ?? 100;
910
+ const offset = options.offset ?? 0;
911
+ return allPermissions.slice(offset, offset + limit);
912
+ }
913
+ return allPermissions;
862
914
  }
863
915
  /**
864
916
  * Internal method: Query user permissions via subgraph
@@ -868,46 +920,48 @@ class DataController extends BaseController {
868
920
  * @param params.subgraphUrl - The subgraph URL endpoint to query
869
921
  * @returns Promise resolving to an array of permission objects
870
922
  */
871
- async _getUserPermissionsViaSubgraph(params) {
923
+ async _getUserPermissionsViaSubgraph(params, options) {
872
924
  const { user, subgraphUrl } = params;
873
925
  try {
874
- const response = await fetch(subgraphUrl, {
875
- method: "POST",
876
- headers: {
877
- "Content-Type": "application/json"
926
+ const orderByMap = {
927
+ id: "id",
928
+ addedAtBlock: "addedAtBlock",
929
+ addedAtTimestamp: "addedAtTimestamp",
930
+ grant: "grant",
931
+ nonce: "nonce",
932
+ startBlock: "startBlock",
933
+ endBlock: "endBlock"
934
+ };
935
+ const permissions = await executePaginatedQuery({
936
+ endpoint: subgraphUrl,
937
+ document: GetUserPermissionsPaginatedDocument,
938
+ baseVariables: {
939
+ userId: user.toLowerCase(),
940
+ orderBy: mapOrderByToEnum(
941
+ options?.orderBy,
942
+ orderByMap,
943
+ "addedAtTimestamp"
944
+ ),
945
+ orderDirection: mapOrderDirection(
946
+ options?.orderDirection,
947
+ "desc",
948
+ "asc"
949
+ )
878
950
  },
879
- body: JSON.stringify({
880
- query: print(GetUserPermissionsDocument),
881
- variables: {
882
- userId: user.toLowerCase()
883
- }
951
+ options,
952
+ extractItems: (data) => data?.user?.permissions,
953
+ transformItem: (permission) => ({
954
+ id: permission.id,
955
+ grant: permission.grant,
956
+ nonce: BigInt(permission.nonce),
957
+ signature: permission.signature,
958
+ addedAtBlock: BigInt(permission.addedAtBlock),
959
+ addedAtTimestamp: BigInt(permission.addedAtTimestamp),
960
+ transactionHash: permission.transactionHash,
961
+ user
884
962
  })
885
963
  });
886
- if (!response.ok) {
887
- throw new Error(
888
- `Subgraph request failed: ${response.status} ${response.statusText}`
889
- );
890
- }
891
- const result = await response.json();
892
- if (result.errors) {
893
- throw new Error(
894
- `Subgraph query errors: ${result.errors.map((e) => e.message).join(", ")}`
895
- );
896
- }
897
- const userData = result.data?.user;
898
- if (!userData?.permissions?.length) {
899
- return [];
900
- }
901
- return userData.permissions.map((permission) => ({
902
- id: permission.id,
903
- grant: permission.grant,
904
- nonce: BigInt(permission.nonce),
905
- signature: permission.signature,
906
- addedAtBlock: BigInt(permission.addedAtBlock),
907
- addedAtTimestamp: BigInt(permission.addedAtTimestamp),
908
- transactionHash: permission.transactionHash,
909
- user
910
- })).sort((a, b) => Number(b.addedAtTimestamp - a.addedAtTimestamp));
964
+ return permissions;
911
965
  } catch (error) {
912
966
  console.error("Failed to query user permissions from subgraph:", error);
913
967
  throw error;
@@ -1040,20 +1094,28 @@ class DataController extends BaseController {
1040
1094
  * });
1041
1095
  * ```
1042
1096
  */
1043
- async getUserTrustedServers(params) {
1044
- const { user, limit = 50, offset = 0 } = params;
1097
+ async getUserTrustedServers(params, options) {
1098
+ const { user } = params;
1045
1099
  const subgraphUrl = params.subgraphUrl ?? this.context.subgraphUrl;
1100
+ if (subgraphUrl && (options?.minBlock || options?.waitForSync)) {
1101
+ await checkSubgraphConsistency(subgraphUrl, options);
1102
+ }
1046
1103
  if (subgraphUrl) {
1047
1104
  try {
1048
- const servers = await this._getUserTrustedServersViaSubgraph({
1049
- user,
1050
- subgraphUrl
1051
- });
1052
- return limit ? servers.slice(offset, offset + limit) : servers;
1105
+ const servers = await this._getUserTrustedServersViaSubgraph(
1106
+ {
1107
+ user,
1108
+ subgraphUrl
1109
+ },
1110
+ options
1111
+ );
1112
+ return servers;
1053
1113
  } catch (error) {
1054
1114
  console.warn("Subgraph query failed, falling back to RPC:", error);
1055
1115
  }
1056
1116
  }
1117
+ const limit = options?.fetchAll ? Number.MAX_SAFE_INTEGER : options?.limit ?? 100;
1118
+ const offset = options?.offset ?? 0;
1057
1119
  const rpcResult = await this._getUserTrustedServersViaRpc({
1058
1120
  user,
1059
1121
  limit,
@@ -1069,7 +1131,7 @@ class DataController extends BaseController {
1069
1131
  * @param params.subgraphUrl - The subgraph URL endpoint to query
1070
1132
  * @returns Promise resolving to an array of trusted server objects
1071
1133
  */
1072
- async _getUserTrustedServersViaSubgraph(params) {
1134
+ async _getUserTrustedServersViaSubgraph(params, options) {
1073
1135
  const { user, subgraphUrl } = params;
1074
1136
  const graphqlEndpoint = subgraphUrl;
1075
1137
  if (!graphqlEndpoint) {
@@ -1078,42 +1140,46 @@ class DataController extends BaseController {
1078
1140
  );
1079
1141
  }
1080
1142
  try {
1081
- const response = await fetch(graphqlEndpoint, {
1082
- method: "POST",
1083
- headers: {
1084
- "Content-Type": "application/json"
1143
+ const orderByMap = {
1144
+ id: "id",
1145
+ trustedAt: "trustedAt",
1146
+ trustedAtBlock: "trustedAtBlock",
1147
+ server: "server",
1148
+ user: "user"
1149
+ };
1150
+ const serverTrusts = await executePaginatedQuery({
1151
+ endpoint: graphqlEndpoint,
1152
+ document: GetUserTrustedServersPaginatedDocument,
1153
+ baseVariables: {
1154
+ userId: user.toLowerCase(),
1155
+ // Subgraph requires lowercase addresses
1156
+ orderBy: mapOrderByToEnum(
1157
+ options?.orderBy,
1158
+ orderByMap,
1159
+ "trustedAtBlock"
1160
+ ),
1161
+ orderDirection: mapOrderDirection(
1162
+ options?.orderDirection,
1163
+ "desc",
1164
+ "asc"
1165
+ )
1085
1166
  },
1086
- body: JSON.stringify({
1087
- query: print(GetUserTrustedServersDocument),
1088
- variables: {
1089
- userId: user.toLowerCase()
1090
- // Subgraph requires lowercase addresses
1091
- }
1167
+ options,
1168
+ extractItems: (data) => {
1169
+ const trusts = data?.user?.serverTrusts ?? [];
1170
+ return trusts.filter((trust) => !trust.untrustedAtBlock);
1171
+ },
1172
+ transformItem: (trust) => ({
1173
+ id: trust.server.id,
1174
+ serverAddress: trust.server.serverAddress,
1175
+ serverUrl: trust.server.url,
1176
+ trustedAt: BigInt(trust.trustedAt),
1177
+ user,
1178
+ name: ""
1179
+ // Not available in new schema, will be empty
1092
1180
  })
1093
1181
  });
1094
- if (!response.ok) {
1095
- throw new Error(
1096
- `Subgraph request failed: ${response.status} ${response.statusText}`
1097
- );
1098
- }
1099
- const result = await response.json();
1100
- if (result.errors) {
1101
- throw new Error(
1102
- `Subgraph query errors: ${result.errors.map((e) => e.message).join(", ")}`
1103
- );
1104
- }
1105
- if (!result.data?.user) {
1106
- return [];
1107
- }
1108
- return (result.data.user.serverTrusts ?? []).filter((trust) => !trust.untrustedAtBlock).map((trust) => ({
1109
- id: trust.server.id,
1110
- serverAddress: trust.server.serverAddress,
1111
- serverUrl: trust.server.url,
1112
- trustedAt: BigInt(trust.trustedAt),
1113
- user,
1114
- name: ""
1115
- // Not available in new schema, will be empty
1116
- }));
1182
+ return serverTrusts;
1117
1183
  } catch (error) {
1118
1184
  console.error("Failed to query trusted servers from subgraph:", error);
1119
1185
  throw error;
@@ -1357,7 +1423,7 @@ class DataController extends BaseController {
1357
1423
  * console.log(`File ${fileId} registered with schema in tx ${transactionHash}`);
1358
1424
  * ```
1359
1425
  */
1360
- async registerFileWithSchema(url, schemaId) {
1426
+ async registerFileWithSchema(url, schemaId, options) {
1361
1427
  this.assertWallet();
1362
1428
  try {
1363
1429
  const chainId = this.context.publicClient.chain?.id;
@@ -1375,7 +1441,8 @@ class DataController extends BaseController {
1375
1441
  functionName: "addFileWithSchema",
1376
1442
  args: [url, BigInt(schemaId)],
1377
1443
  account,
1378
- chain: this.context.walletClient.chain ?? null
1444
+ chain: this.context.walletClient.chain ?? null,
1445
+ ...this.spreadTransactionOptions(options)
1379
1446
  });
1380
1447
  const { tx } = await import("../utils/transactionHelpers");
1381
1448
  return tx({
@@ -1413,7 +1480,7 @@ class DataController extends BaseController {
1413
1480
  * with specific permissions on the DataRegistry contract. It can be used
1414
1481
  * by both direct transactions and relayer services.
1415
1482
  */
1416
- async addFileWithPermissions(url, ownerAddress, permissions = []) {
1483
+ async addFileWithPermissions(url, ownerAddress, permissions = [], options) {
1417
1484
  this.assertWallet();
1418
1485
  try {
1419
1486
  const chainId = this.context.publicClient.chain?.id;
@@ -1431,7 +1498,8 @@ class DataController extends BaseController {
1431
1498
  functionName: "addFileWithPermissions",
1432
1499
  args: [url, ownerAddress, permissions],
1433
1500
  account,
1434
- chain: this.context.walletClient.chain ?? null
1501
+ chain: this.context.walletClient.chain ?? null,
1502
+ ...this.spreadTransactionOptions(options)
1435
1503
  });
1436
1504
  const { tx } = await import("../utils/transactionHelpers");
1437
1505
  return tx({
@@ -1486,7 +1554,7 @@ class DataController extends BaseController {
1486
1554
  * console.log(`File ${result.fileId} registered in tx ${result.hash}`);
1487
1555
  * ```
1488
1556
  */
1489
- async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
1557
+ async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
1490
1558
  this.assertWallet();
1491
1559
  try {
1492
1560
  let encryptedPermissions = [];
@@ -1520,7 +1588,8 @@ class DataController extends BaseController {
1520
1588
  url,
1521
1589
  ownerAddress,
1522
1590
  encryptedPermissions,
1523
- schemaId
1591
+ schemaId,
1592
+ options
1524
1593
  );
1525
1594
  } catch (error) {
1526
1595
  console.error("Failed to add file with permissions and schema:", error);
@@ -1567,7 +1636,7 @@ class DataController extends BaseController {
1567
1636
  * console.log(`File registered in tx ${result.hash}`);
1568
1637
  * ```
1569
1638
  */
1570
- async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
1639
+ async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
1571
1640
  try {
1572
1641
  const chainId = this.context.publicClient.chain?.id;
1573
1642
  if (!chainId) {
@@ -1584,7 +1653,8 @@ class DataController extends BaseController {
1584
1653
  functionName: "addFileWithPermissionsAndSchema",
1585
1654
  args: [url, ownerAddress, permissions, BigInt(schemaId)],
1586
1655
  account,
1587
- chain: this.context.walletClient.chain ?? null
1656
+ chain: this.context.walletClient.chain ?? null,
1657
+ ...this.spreadTransactionOptions(options)
1588
1658
  });
1589
1659
  const { tx } = await import("../utils/transactionHelpers");
1590
1660
  return tx({
@@ -1632,7 +1702,7 @@ class DataController extends BaseController {
1632
1702
  * console.log(`Refiner ${result.refinerId} created`);
1633
1703
  * ```
1634
1704
  */
1635
- async addRefiner(params) {
1705
+ async addRefiner(params, options) {
1636
1706
  this.assertWallet();
1637
1707
  try {
1638
1708
  const chainId = this.context.publicClient.chain?.id;
@@ -1658,7 +1728,8 @@ class DataController extends BaseController {
1658
1728
  params.refinementInstructionUrl
1659
1729
  ],
1660
1730
  account,
1661
- chain: this.context.walletClient.chain ?? null
1731
+ chain: this.context.walletClient.chain ?? null,
1732
+ ...this.spreadTransactionOptions(options)
1662
1733
  });
1663
1734
  const { tx } = await import("../utils/transactionHelpers");
1664
1735
  const txResult = tx({
@@ -1858,7 +1929,7 @@ class DataController extends BaseController {
1858
1929
  * console.log(`Schema updated in tx ${result.transactionHash}`);
1859
1930
  * ```
1860
1931
  */
1861
- async updateSchemaId(params) {
1932
+ async updateSchemaId(params, options) {
1862
1933
  this.assertWallet();
1863
1934
  try {
1864
1935
  const chainId = this.context.publicClient.chain?.id;
@@ -1878,7 +1949,8 @@ class DataController extends BaseController {
1878
1949
  functionName: "updateSchemaId",
1879
1950
  args: [BigInt(params.refinerId), BigInt(params.newSchemaId)],
1880
1951
  account,
1881
- chain: this.context.walletClient.chain ?? null
1952
+ chain: this.context.walletClient.chain ?? null,
1953
+ ...this.spreadTransactionOptions(options)
1882
1954
  });
1883
1955
  await this.context.publicClient.waitForTransactionReceipt({ hash });
1884
1956
  return {
@@ -1947,7 +2019,7 @@ class DataController extends BaseController {
1947
2019
  if (response.type === "error") {
1948
2020
  throw new Error(response.error);
1949
2021
  }
1950
- if (response.type !== "direct" || !("fileId" in response.result)) {
2022
+ if (response.type !== "direct" || typeof response.result !== "object" || response.result === null || !("fileId" in response.result)) {
1951
2023
  throw new Error("Invalid response from relayer");
1952
2024
  }
1953
2025
  const result = response.result;
@@ -2039,7 +2111,7 @@ class DataController extends BaseController {
2039
2111
  );
2040
2112
  }
2041
2113
  }
2042
- const finalFilename = filename ?? encrypt ? `upload-${Date.now()}.enc` : `upload-${Date.now()}.dat`;
2114
+ const finalFilename = filename ?? `upload-${Date.now()}.dat`;
2043
2115
  const uploadResult = await this.context.storageManager.upload(
2044
2116
  finalBlob,
2045
2117
  finalFilename,
@@ -2084,10 +2156,10 @@ class DataController extends BaseController {
2084
2156
  * console.log(`Transaction: ${result.transactionHash}`);
2085
2157
  * ```
2086
2158
  */
2087
- async addPermissionToFile(params) {
2159
+ async addPermissionToFile(params, options) {
2088
2160
  this.assertWallet();
2089
2161
  const { fileId, account, publicKey } = params;
2090
- return await this.submitFilePermission(fileId, account, publicKey);
2162
+ return await this.submitFilePermission(fileId, account, publicKey, options);
2091
2163
  }
2092
2164
  /**
2093
2165
  * Submits a file permission transaction to the blockchain.
@@ -2117,7 +2189,7 @@ class DataController extends BaseController {
2117
2189
  * console.log(`Permission granted with ID: ${result.permissionId}`);
2118
2190
  * ```
2119
2191
  */
2120
- async submitFilePermission(fileId, account, publicKey) {
2192
+ async submitFilePermission(fileId, account, publicKey, options) {
2121
2193
  this.assertWallet();
2122
2194
  try {
2123
2195
  const userEncryptionKey = await generateEncryptionKey(
@@ -2144,7 +2216,8 @@ class DataController extends BaseController {
2144
2216
  functionName: "addFilePermission",
2145
2217
  args: [BigInt(fileId), account, encryptedKey],
2146
2218
  account: walletAccount,
2147
- chain: this.context.walletClient.chain ?? null
2219
+ chain: this.context.walletClient.chain ?? null,
2220
+ ...this.spreadTransactionOptions(options)
2148
2221
  });
2149
2222
  const { tx } = await import("../utils/transactionHelpers");
2150
2223
  return tx({