@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.
- package/dist/controllers/__tests__/data-consistency-integration.test.d.ts +7 -0
- package/dist/controllers/base.cjs +33 -0
- package/dist/controllers/base.cjs.map +1 -1
- package/dist/controllers/base.d.ts +10 -0
- package/dist/controllers/base.js +33 -0
- package/dist/controllers/base.js.map +1 -1
- package/dist/controllers/data.cjs +210 -147
- package/dist/controllers/data.cjs.map +1 -1
- package/dist/controllers/data.d.ts +15 -12
- package/dist/controllers/data.js +223 -150
- package/dist/controllers/data.js.map +1 -1
- package/dist/controllers/permissions.cjs +203 -94
- package/dist/controllers/permissions.cjs.map +1 -1
- package/dist/controllers/permissions.d.ts +20 -11
- package/dist/controllers/permissions.js +203 -94
- package/dist/controllers/permissions.js.map +1 -1
- package/dist/controllers/schemas.cjs +11 -1
- package/dist/controllers/schemas.cjs.map +1 -1
- package/dist/controllers/schemas.d.ts +2 -0
- package/dist/controllers/schemas.js +11 -1
- package/dist/controllers/schemas.js.map +1 -1
- package/dist/core.cjs +4 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +2 -1
- package/dist/core.js +4 -1
- package/dist/core.js.map +1 -1
- package/dist/generated/subgraph.cjs +797 -32
- package/dist/generated/subgraph.cjs.map +1 -1
- package/dist/generated/subgraph.d.ts +135 -0
- package/dist/generated/subgraph.js +792 -32
- package/dist/generated/subgraph.js.map +1 -1
- package/dist/index.node.cjs +2 -0
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.ts +27 -4
- package/dist/index.node.js +2 -0
- package/dist/index.node.js.map +1 -1
- package/dist/server/relayerHandler.cjs +201 -87
- package/dist/server/relayerHandler.cjs.map +1 -1
- package/dist/server/relayerHandler.d.ts +3 -1
- package/dist/server/relayerHandler.js +201 -87
- package/dist/server/relayerHandler.js.map +1 -1
- package/dist/types/config.cjs.map +1 -1
- package/dist/types/config.d.ts +32 -0
- package/dist/types/config.js.map +1 -1
- package/dist/types/controller-context.cjs.map +1 -1
- package/dist/types/controller-context.d.ts +3 -1
- package/dist/types/data.cjs.map +1 -1
- package/dist/types/data.d.ts +0 -4
- package/dist/types/generics.cjs.map +1 -1
- package/dist/types/generics.d.ts +1 -1
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.ts +4 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/operations.cjs.map +1 -1
- package/dist/types/operations.d.ts +33 -0
- package/dist/types/operations.js.map +1 -1
- package/dist/types/options.cjs +17 -0
- package/dist/types/options.cjs.map +1 -0
- package/dist/types/options.d.ts +213 -0
- package/dist/types/options.js +1 -0
- package/dist/types/options.js.map +1 -0
- package/dist/types/permissions.cjs.map +1 -1
- package/dist/types/permissions.d.ts +2 -0
- package/dist/types/relayer.cjs.map +1 -1
- package/dist/types/relayer.d.ts +19 -8
- package/dist/types/utils.cjs.map +1 -1
- package/dist/types/utils.d.ts +0 -49
- package/dist/utils/__tests__/subgraphConsistency.test.d.ts +4 -0
- package/dist/utils/__tests__/subgraphPagination.test.d.ts +4 -0
- package/dist/utils/chainQuery.cjs +107 -0
- package/dist/utils/chainQuery.cjs.map +1 -0
- package/dist/utils/chainQuery.d.ts +31 -0
- package/dist/utils/chainQuery.js +82 -0
- package/dist/utils/chainQuery.js.map +1 -0
- package/dist/utils/ipfs.cjs +2 -4
- package/dist/utils/ipfs.cjs.map +1 -1
- package/dist/utils/ipfs.d.ts +1 -1
- package/dist/utils/ipfs.js +2 -4
- package/dist/utils/ipfs.js.map +1 -1
- package/dist/utils/subgraphConsistency.cjs +184 -0
- package/dist/utils/subgraphConsistency.cjs.map +1 -0
- package/dist/utils/subgraphConsistency.d.ts +65 -0
- package/dist/utils/subgraphConsistency.js +155 -0
- package/dist/utils/subgraphConsistency.js.map +1 -0
- package/dist/utils/subgraphMetaCache.cjs +101 -0
- package/dist/utils/subgraphMetaCache.cjs.map +1 -0
- package/dist/utils/subgraphMetaCache.d.ts +56 -0
- package/dist/utils/subgraphMetaCache.js +76 -0
- package/dist/utils/subgraphMetaCache.js.map +1 -0
- package/dist/utils/subgraphPagination.cjs +104 -0
- package/dist/utils/subgraphPagination.cjs.map +1 -0
- package/dist/utils/subgraphPagination.d.ts +78 -0
- package/dist/utils/subgraphPagination.js +78 -0
- package/dist/utils/subgraphPagination.js.map +1 -0
- package/package.json +3 -1
|
@@ -37,6 +37,9 @@ var import_addresses = require("../config/addresses");
|
|
|
37
37
|
var import_abi = require("../generated/abi");
|
|
38
38
|
var import_subgraph = require("../generated/subgraph");
|
|
39
39
|
var import_graphql = require("graphql");
|
|
40
|
+
var import_subgraphConsistency = require("../utils/subgraphConsistency");
|
|
41
|
+
var import_subgraphPagination = require("../utils/subgraphPagination");
|
|
42
|
+
var import_chainQuery = require("../utils/chainQuery");
|
|
40
43
|
var import_encryption = require("../utils/encryption");
|
|
41
44
|
var import_schemaValidation = require("../utils/schemaValidation");
|
|
42
45
|
var import_multicall = require("../utils/multicall");
|
|
@@ -140,7 +143,7 @@ class DataController extends import_base.BaseController {
|
|
|
140
143
|
if (response.type === "error") {
|
|
141
144
|
throw new Error(response.error);
|
|
142
145
|
}
|
|
143
|
-
if (response.type !== "direct" || !("fileId" in response.result)) {
|
|
146
|
+
if (response.type !== "direct" || typeof response.result !== "object" || response.result === null || !("fileId" in response.result)) {
|
|
144
147
|
throw new Error("Invalid response from relayer");
|
|
145
148
|
}
|
|
146
149
|
result = response.result;
|
|
@@ -435,67 +438,91 @@ class DataController extends import_base.BaseController {
|
|
|
435
438
|
* });
|
|
436
439
|
* ```
|
|
437
440
|
*/
|
|
438
|
-
async getUserFiles(params) {
|
|
441
|
+
async getUserFiles(params, options) {
|
|
439
442
|
const { owner, subgraphUrl } = params;
|
|
443
|
+
let dataSource = options?.source === "chain" ? "chain" : "subgraph";
|
|
444
|
+
if (options?.source === "auto" || !options?.source && options?.minBlock) {
|
|
445
|
+
const endpoint2 = subgraphUrl ?? this.context.subgraphUrl;
|
|
446
|
+
const currentBlock = await this.context.publicClient.getBlockNumber();
|
|
447
|
+
let subgraphBlock;
|
|
448
|
+
if (endpoint2) {
|
|
449
|
+
try {
|
|
450
|
+
const meta = await (0, import_subgraphConsistency.fetchSubgraphMeta)(endpoint2);
|
|
451
|
+
subgraphBlock = meta.blockNumber;
|
|
452
|
+
} catch {
|
|
453
|
+
subgraphBlock = void 0;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
dataSource = (0, import_chainQuery.determineDataSource)(
|
|
457
|
+
options?.source,
|
|
458
|
+
options?.minBlock,
|
|
459
|
+
currentBlock,
|
|
460
|
+
subgraphBlock
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
if (dataSource === "chain") {
|
|
464
|
+
const publicClient = this.context.publicClient;
|
|
465
|
+
const chainId = await publicClient.getChainId();
|
|
466
|
+
const contractAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
467
|
+
const files = await (0, import_chainQuery.getUserFilesFromChain)(
|
|
468
|
+
publicClient,
|
|
469
|
+
contractAddress,
|
|
470
|
+
owner,
|
|
471
|
+
options?.minBlock ? BigInt(options.minBlock) : void 0
|
|
472
|
+
);
|
|
473
|
+
const limit = options?.fetchAll ? files.length : options?.limit ?? 100;
|
|
474
|
+
const offset = options?.offset ?? 0;
|
|
475
|
+
return files.slice(offset, offset + limit);
|
|
476
|
+
}
|
|
440
477
|
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
441
478
|
if (!endpoint) {
|
|
442
479
|
throw new Error(
|
|
443
480
|
"subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor."
|
|
444
481
|
);
|
|
445
482
|
}
|
|
483
|
+
if (options?.minBlock || options?.waitForSync) {
|
|
484
|
+
await (0, import_subgraphConsistency.checkSubgraphConsistency)(endpoint, options);
|
|
485
|
+
}
|
|
446
486
|
try {
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
487
|
+
const orderByMap = {
|
|
488
|
+
id: "id",
|
|
489
|
+
addedAtBlock: "addedAtBlock",
|
|
490
|
+
addedAtTimestamp: "addedAtTimestamp",
|
|
491
|
+
url: "url",
|
|
492
|
+
schemaId: "schemaId"
|
|
493
|
+
};
|
|
494
|
+
const allFiles = await (0, import_subgraphPagination.executePaginatedQuery)({
|
|
495
|
+
endpoint,
|
|
496
|
+
document: import_subgraph.GetUserFilesPaginatedDocument,
|
|
497
|
+
baseVariables: {
|
|
498
|
+
userId: owner.toLowerCase(),
|
|
499
|
+
// Subgraph requires lowercase addresses
|
|
500
|
+
orderBy: (0, import_subgraphPagination.mapOrderByToEnum)(
|
|
501
|
+
options?.orderBy,
|
|
502
|
+
orderByMap,
|
|
503
|
+
"addedAtBlock"
|
|
504
|
+
),
|
|
505
|
+
orderDirection: (0, import_subgraphPagination.mapOrderDirection)(
|
|
506
|
+
options?.orderDirection,
|
|
507
|
+
"asc",
|
|
508
|
+
"desc"
|
|
509
|
+
)
|
|
451
510
|
},
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
// Subgraph requires lowercase addresses
|
|
457
|
-
}
|
|
458
|
-
})
|
|
459
|
-
});
|
|
460
|
-
if (!response.ok) {
|
|
461
|
-
throw new Error(
|
|
462
|
-
`Subgraph request failed: ${response.status} ${response.statusText}`
|
|
463
|
-
);
|
|
464
|
-
}
|
|
465
|
-
const result = await response.json();
|
|
466
|
-
if (result.errors) {
|
|
467
|
-
throw new Error(
|
|
468
|
-
`Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
469
|
-
);
|
|
470
|
-
}
|
|
471
|
-
const user = result.data?.user;
|
|
472
|
-
if (!user?.files?.length) {
|
|
473
|
-
console.warn("No files found for user:", owner);
|
|
474
|
-
return [];
|
|
475
|
-
}
|
|
476
|
-
const fileMap = /* @__PURE__ */ new Map();
|
|
477
|
-
user.files.forEach((file) => {
|
|
478
|
-
const fileId = parseInt(file.id);
|
|
479
|
-
const userFile = {
|
|
480
|
-
id: fileId,
|
|
511
|
+
options,
|
|
512
|
+
extractItems: (data) => data?.user?.files,
|
|
513
|
+
transformItem: (file) => ({
|
|
514
|
+
id: parseInt(file.id),
|
|
481
515
|
url: file.url,
|
|
482
516
|
ownerAddress: file.owner.id,
|
|
483
517
|
addedAtBlock: BigInt(file.addedAtBlock),
|
|
484
518
|
schemaId: parseInt(file.schemaId),
|
|
485
519
|
addedAtTimestamp: BigInt(file.addedAtTimestamp),
|
|
486
520
|
transactionHash: file.transactionHash
|
|
487
|
-
}
|
|
488
|
-
const existing = fileMap.get(fileId);
|
|
489
|
-
if (!existing || userFile.addedAtTimestamp && existing.addedAtTimestamp && userFile.addedAtTimestamp > existing.addedAtTimestamp) {
|
|
490
|
-
fileMap.set(fileId, userFile);
|
|
491
|
-
}
|
|
521
|
+
})
|
|
492
522
|
});
|
|
493
|
-
|
|
494
|
-
(a, b) => Number((b.addedAtTimestamp ?? 0n) - (a.addedAtTimestamp ?? 0n))
|
|
495
|
-
);
|
|
496
|
-
if (userFiles.length > 0) {
|
|
523
|
+
if (allFiles.length > 0) {
|
|
497
524
|
try {
|
|
498
|
-
const fileIds =
|
|
525
|
+
const fileIds = allFiles.map((f) => f.id);
|
|
499
526
|
let proofMap;
|
|
500
527
|
try {
|
|
501
528
|
proofMap = await this._fetchProofsFromSubgraph(fileIds, endpoint);
|
|
@@ -506,7 +533,7 @@ class DataController extends import_base.BaseController {
|
|
|
506
533
|
);
|
|
507
534
|
proofMap = await this._fetchProofsFromChain(fileIds);
|
|
508
535
|
}
|
|
509
|
-
for (const file of
|
|
536
|
+
for (const file of allFiles) {
|
|
510
537
|
const dlpIds = proofMap.get(file.id);
|
|
511
538
|
if (dlpIds && dlpIds.length > 0) {
|
|
512
539
|
file.dlpIds = dlpIds;
|
|
@@ -516,7 +543,7 @@ class DataController extends import_base.BaseController {
|
|
|
516
543
|
console.warn("Failed to fetch proof data for files:", error);
|
|
517
544
|
}
|
|
518
545
|
}
|
|
519
|
-
return
|
|
546
|
+
return allFiles;
|
|
520
547
|
} catch (error) {
|
|
521
548
|
console.error("Failed to fetch user files from subgraph:", error);
|
|
522
549
|
throw new Error(
|
|
@@ -642,6 +669,9 @@ class DataController extends import_base.BaseController {
|
|
|
642
669
|
*/
|
|
643
670
|
async getDLP(dlpId, options = {}) {
|
|
644
671
|
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
672
|
+
if (subgraphUrl && (options.minBlock || options.waitForSync)) {
|
|
673
|
+
await (0, import_subgraphConsistency.checkSubgraphConsistency)(subgraphUrl, options);
|
|
674
|
+
}
|
|
645
675
|
if (subgraphUrl) {
|
|
646
676
|
try {
|
|
647
677
|
const response = await fetch(subgraphUrl, {
|
|
@@ -860,21 +890,33 @@ class DataController extends import_base.BaseController {
|
|
|
860
890
|
* @returns Promise resolving to an array of permission objects
|
|
861
891
|
* @throws Error if both subgraph and RPC queries fail
|
|
862
892
|
*/
|
|
863
|
-
async getUserPermissions(params) {
|
|
893
|
+
async getUserPermissions(params, options) {
|
|
864
894
|
const { user, subgraphUrl } = params;
|
|
865
895
|
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
896
|
+
if (endpoint && (options?.minBlock || options?.waitForSync)) {
|
|
897
|
+
await (0, import_subgraphConsistency.checkSubgraphConsistency)(endpoint, options);
|
|
898
|
+
}
|
|
866
899
|
if (endpoint) {
|
|
867
900
|
try {
|
|
868
|
-
const permissions = await this._getUserPermissionsViaSubgraph(
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
901
|
+
const permissions = await this._getUserPermissionsViaSubgraph(
|
|
902
|
+
{
|
|
903
|
+
user,
|
|
904
|
+
subgraphUrl: endpoint
|
|
905
|
+
},
|
|
906
|
+
options
|
|
907
|
+
);
|
|
872
908
|
return permissions;
|
|
873
909
|
} catch (error) {
|
|
874
910
|
console.warn("Subgraph query failed, falling back to RPC:", error);
|
|
875
911
|
}
|
|
876
912
|
}
|
|
877
|
-
|
|
913
|
+
const allPermissions = await this._getUserPermissionsViaRpc({ user });
|
|
914
|
+
if (options && !options.fetchAll) {
|
|
915
|
+
const limit = options.limit ?? 100;
|
|
916
|
+
const offset = options.offset ?? 0;
|
|
917
|
+
return allPermissions.slice(offset, offset + limit);
|
|
918
|
+
}
|
|
919
|
+
return allPermissions;
|
|
878
920
|
}
|
|
879
921
|
/**
|
|
880
922
|
* Internal method: Query user permissions via subgraph
|
|
@@ -884,46 +926,48 @@ class DataController extends import_base.BaseController {
|
|
|
884
926
|
* @param params.subgraphUrl - The subgraph URL endpoint to query
|
|
885
927
|
* @returns Promise resolving to an array of permission objects
|
|
886
928
|
*/
|
|
887
|
-
async _getUserPermissionsViaSubgraph(params) {
|
|
929
|
+
async _getUserPermissionsViaSubgraph(params, options) {
|
|
888
930
|
const { user, subgraphUrl } = params;
|
|
889
931
|
try {
|
|
890
|
-
const
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
932
|
+
const orderByMap = {
|
|
933
|
+
id: "id",
|
|
934
|
+
addedAtBlock: "addedAtBlock",
|
|
935
|
+
addedAtTimestamp: "addedAtTimestamp",
|
|
936
|
+
grant: "grant",
|
|
937
|
+
nonce: "nonce",
|
|
938
|
+
startBlock: "startBlock",
|
|
939
|
+
endBlock: "endBlock"
|
|
940
|
+
};
|
|
941
|
+
const permissions = await (0, import_subgraphPagination.executePaginatedQuery)({
|
|
942
|
+
endpoint: subgraphUrl,
|
|
943
|
+
document: import_subgraph.GetUserPermissionsPaginatedDocument,
|
|
944
|
+
baseVariables: {
|
|
945
|
+
userId: user.toLowerCase(),
|
|
946
|
+
orderBy: (0, import_subgraphPagination.mapOrderByToEnum)(
|
|
947
|
+
options?.orderBy,
|
|
948
|
+
orderByMap,
|
|
949
|
+
"addedAtTimestamp"
|
|
950
|
+
),
|
|
951
|
+
orderDirection: (0, import_subgraphPagination.mapOrderDirection)(
|
|
952
|
+
options?.orderDirection,
|
|
953
|
+
"desc",
|
|
954
|
+
"asc"
|
|
955
|
+
)
|
|
894
956
|
},
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
957
|
+
options,
|
|
958
|
+
extractItems: (data) => data?.user?.permissions,
|
|
959
|
+
transformItem: (permission) => ({
|
|
960
|
+
id: permission.id,
|
|
961
|
+
grant: permission.grant,
|
|
962
|
+
nonce: BigInt(permission.nonce),
|
|
963
|
+
signature: permission.signature,
|
|
964
|
+
addedAtBlock: BigInt(permission.addedAtBlock),
|
|
965
|
+
addedAtTimestamp: BigInt(permission.addedAtTimestamp),
|
|
966
|
+
transactionHash: permission.transactionHash,
|
|
967
|
+
user
|
|
900
968
|
})
|
|
901
969
|
});
|
|
902
|
-
|
|
903
|
-
throw new Error(
|
|
904
|
-
`Subgraph request failed: ${response.status} ${response.statusText}`
|
|
905
|
-
);
|
|
906
|
-
}
|
|
907
|
-
const result = await response.json();
|
|
908
|
-
if (result.errors) {
|
|
909
|
-
throw new Error(
|
|
910
|
-
`Subgraph query errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
911
|
-
);
|
|
912
|
-
}
|
|
913
|
-
const userData = result.data?.user;
|
|
914
|
-
if (!userData?.permissions?.length) {
|
|
915
|
-
return [];
|
|
916
|
-
}
|
|
917
|
-
return userData.permissions.map((permission) => ({
|
|
918
|
-
id: permission.id,
|
|
919
|
-
grant: permission.grant,
|
|
920
|
-
nonce: BigInt(permission.nonce),
|
|
921
|
-
signature: permission.signature,
|
|
922
|
-
addedAtBlock: BigInt(permission.addedAtBlock),
|
|
923
|
-
addedAtTimestamp: BigInt(permission.addedAtTimestamp),
|
|
924
|
-
transactionHash: permission.transactionHash,
|
|
925
|
-
user
|
|
926
|
-
})).sort((a, b) => Number(b.addedAtTimestamp - a.addedAtTimestamp));
|
|
970
|
+
return permissions;
|
|
927
971
|
} catch (error) {
|
|
928
972
|
console.error("Failed to query user permissions from subgraph:", error);
|
|
929
973
|
throw error;
|
|
@@ -1056,20 +1100,28 @@ class DataController extends import_base.BaseController {
|
|
|
1056
1100
|
* });
|
|
1057
1101
|
* ```
|
|
1058
1102
|
*/
|
|
1059
|
-
async getUserTrustedServers(params) {
|
|
1060
|
-
const { user
|
|
1103
|
+
async getUserTrustedServers(params, options) {
|
|
1104
|
+
const { user } = params;
|
|
1061
1105
|
const subgraphUrl = params.subgraphUrl ?? this.context.subgraphUrl;
|
|
1106
|
+
if (subgraphUrl && (options?.minBlock || options?.waitForSync)) {
|
|
1107
|
+
await (0, import_subgraphConsistency.checkSubgraphConsistency)(subgraphUrl, options);
|
|
1108
|
+
}
|
|
1062
1109
|
if (subgraphUrl) {
|
|
1063
1110
|
try {
|
|
1064
|
-
const servers = await this._getUserTrustedServersViaSubgraph(
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1111
|
+
const servers = await this._getUserTrustedServersViaSubgraph(
|
|
1112
|
+
{
|
|
1113
|
+
user,
|
|
1114
|
+
subgraphUrl
|
|
1115
|
+
},
|
|
1116
|
+
options
|
|
1117
|
+
);
|
|
1118
|
+
return servers;
|
|
1069
1119
|
} catch (error) {
|
|
1070
1120
|
console.warn("Subgraph query failed, falling back to RPC:", error);
|
|
1071
1121
|
}
|
|
1072
1122
|
}
|
|
1123
|
+
const limit = options?.fetchAll ? Number.MAX_SAFE_INTEGER : options?.limit ?? 100;
|
|
1124
|
+
const offset = options?.offset ?? 0;
|
|
1073
1125
|
const rpcResult = await this._getUserTrustedServersViaRpc({
|
|
1074
1126
|
user,
|
|
1075
1127
|
limit,
|
|
@@ -1085,7 +1137,7 @@ class DataController extends import_base.BaseController {
|
|
|
1085
1137
|
* @param params.subgraphUrl - The subgraph URL endpoint to query
|
|
1086
1138
|
* @returns Promise resolving to an array of trusted server objects
|
|
1087
1139
|
*/
|
|
1088
|
-
async _getUserTrustedServersViaSubgraph(params) {
|
|
1140
|
+
async _getUserTrustedServersViaSubgraph(params, options) {
|
|
1089
1141
|
const { user, subgraphUrl } = params;
|
|
1090
1142
|
const graphqlEndpoint = subgraphUrl;
|
|
1091
1143
|
if (!graphqlEndpoint) {
|
|
@@ -1094,42 +1146,46 @@ class DataController extends import_base.BaseController {
|
|
|
1094
1146
|
);
|
|
1095
1147
|
}
|
|
1096
1148
|
try {
|
|
1097
|
-
const
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1149
|
+
const orderByMap = {
|
|
1150
|
+
id: "id",
|
|
1151
|
+
trustedAt: "trustedAt",
|
|
1152
|
+
trustedAtBlock: "trustedAtBlock",
|
|
1153
|
+
server: "server",
|
|
1154
|
+
user: "user"
|
|
1155
|
+
};
|
|
1156
|
+
const serverTrusts = await (0, import_subgraphPagination.executePaginatedQuery)({
|
|
1157
|
+
endpoint: graphqlEndpoint,
|
|
1158
|
+
document: import_subgraph.GetUserTrustedServersPaginatedDocument,
|
|
1159
|
+
baseVariables: {
|
|
1160
|
+
userId: user.toLowerCase(),
|
|
1161
|
+
// Subgraph requires lowercase addresses
|
|
1162
|
+
orderBy: (0, import_subgraphPagination.mapOrderByToEnum)(
|
|
1163
|
+
options?.orderBy,
|
|
1164
|
+
orderByMap,
|
|
1165
|
+
"trustedAtBlock"
|
|
1166
|
+
),
|
|
1167
|
+
orderDirection: (0, import_subgraphPagination.mapOrderDirection)(
|
|
1168
|
+
options?.orderDirection,
|
|
1169
|
+
"desc",
|
|
1170
|
+
"asc"
|
|
1171
|
+
)
|
|
1101
1172
|
},
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1173
|
+
options,
|
|
1174
|
+
extractItems: (data) => {
|
|
1175
|
+
const trusts = data?.user?.serverTrusts ?? [];
|
|
1176
|
+
return trusts.filter((trust) => !trust.untrustedAtBlock);
|
|
1177
|
+
},
|
|
1178
|
+
transformItem: (trust) => ({
|
|
1179
|
+
id: trust.server.id,
|
|
1180
|
+
serverAddress: trust.server.serverAddress,
|
|
1181
|
+
serverUrl: trust.server.url,
|
|
1182
|
+
trustedAt: BigInt(trust.trustedAt),
|
|
1183
|
+
user,
|
|
1184
|
+
name: ""
|
|
1185
|
+
// Not available in new schema, will be empty
|
|
1108
1186
|
})
|
|
1109
1187
|
});
|
|
1110
|
-
|
|
1111
|
-
throw new Error(
|
|
1112
|
-
`Subgraph request failed: ${response.status} ${response.statusText}`
|
|
1113
|
-
);
|
|
1114
|
-
}
|
|
1115
|
-
const result = await response.json();
|
|
1116
|
-
if (result.errors) {
|
|
1117
|
-
throw new Error(
|
|
1118
|
-
`Subgraph query errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
1119
|
-
);
|
|
1120
|
-
}
|
|
1121
|
-
if (!result.data?.user) {
|
|
1122
|
-
return [];
|
|
1123
|
-
}
|
|
1124
|
-
return (result.data.user.serverTrusts ?? []).filter((trust) => !trust.untrustedAtBlock).map((trust) => ({
|
|
1125
|
-
id: trust.server.id,
|
|
1126
|
-
serverAddress: trust.server.serverAddress,
|
|
1127
|
-
serverUrl: trust.server.url,
|
|
1128
|
-
trustedAt: BigInt(trust.trustedAt),
|
|
1129
|
-
user,
|
|
1130
|
-
name: ""
|
|
1131
|
-
// Not available in new schema, will be empty
|
|
1132
|
-
}));
|
|
1188
|
+
return serverTrusts;
|
|
1133
1189
|
} catch (error) {
|
|
1134
1190
|
console.error("Failed to query trusted servers from subgraph:", error);
|
|
1135
1191
|
throw error;
|
|
@@ -1373,7 +1429,7 @@ class DataController extends import_base.BaseController {
|
|
|
1373
1429
|
* console.log(`File ${fileId} registered with schema in tx ${transactionHash}`);
|
|
1374
1430
|
* ```
|
|
1375
1431
|
*/
|
|
1376
|
-
async registerFileWithSchema(url, schemaId) {
|
|
1432
|
+
async registerFileWithSchema(url, schemaId, options) {
|
|
1377
1433
|
this.assertWallet();
|
|
1378
1434
|
try {
|
|
1379
1435
|
const chainId = this.context.publicClient.chain?.id;
|
|
@@ -1391,7 +1447,8 @@ class DataController extends import_base.BaseController {
|
|
|
1391
1447
|
functionName: "addFileWithSchema",
|
|
1392
1448
|
args: [url, BigInt(schemaId)],
|
|
1393
1449
|
account,
|
|
1394
|
-
chain: this.context.walletClient.chain ?? null
|
|
1450
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1451
|
+
...this.spreadTransactionOptions(options)
|
|
1395
1452
|
});
|
|
1396
1453
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1397
1454
|
return tx({
|
|
@@ -1429,7 +1486,7 @@ class DataController extends import_base.BaseController {
|
|
|
1429
1486
|
* with specific permissions on the DataRegistry contract. It can be used
|
|
1430
1487
|
* by both direct transactions and relayer services.
|
|
1431
1488
|
*/
|
|
1432
|
-
async addFileWithPermissions(url, ownerAddress, permissions = []) {
|
|
1489
|
+
async addFileWithPermissions(url, ownerAddress, permissions = [], options) {
|
|
1433
1490
|
this.assertWallet();
|
|
1434
1491
|
try {
|
|
1435
1492
|
const chainId = this.context.publicClient.chain?.id;
|
|
@@ -1447,7 +1504,8 @@ class DataController extends import_base.BaseController {
|
|
|
1447
1504
|
functionName: "addFileWithPermissions",
|
|
1448
1505
|
args: [url, ownerAddress, permissions],
|
|
1449
1506
|
account,
|
|
1450
|
-
chain: this.context.walletClient.chain ?? null
|
|
1507
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1508
|
+
...this.spreadTransactionOptions(options)
|
|
1451
1509
|
});
|
|
1452
1510
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1453
1511
|
return tx({
|
|
@@ -1502,7 +1560,7 @@ class DataController extends import_base.BaseController {
|
|
|
1502
1560
|
* console.log(`File ${result.fileId} registered in tx ${result.hash}`);
|
|
1503
1561
|
* ```
|
|
1504
1562
|
*/
|
|
1505
|
-
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1563
|
+
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
|
|
1506
1564
|
this.assertWallet();
|
|
1507
1565
|
try {
|
|
1508
1566
|
let encryptedPermissions = [];
|
|
@@ -1536,7 +1594,8 @@ class DataController extends import_base.BaseController {
|
|
|
1536
1594
|
url,
|
|
1537
1595
|
ownerAddress,
|
|
1538
1596
|
encryptedPermissions,
|
|
1539
|
-
schemaId
|
|
1597
|
+
schemaId,
|
|
1598
|
+
options
|
|
1540
1599
|
);
|
|
1541
1600
|
} catch (error) {
|
|
1542
1601
|
console.error("Failed to add file with permissions and schema:", error);
|
|
@@ -1583,7 +1642,7 @@ class DataController extends import_base.BaseController {
|
|
|
1583
1642
|
* console.log(`File registered in tx ${result.hash}`);
|
|
1584
1643
|
* ```
|
|
1585
1644
|
*/
|
|
1586
|
-
async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1645
|
+
async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
|
|
1587
1646
|
try {
|
|
1588
1647
|
const chainId = this.context.publicClient.chain?.id;
|
|
1589
1648
|
if (!chainId) {
|
|
@@ -1600,7 +1659,8 @@ class DataController extends import_base.BaseController {
|
|
|
1600
1659
|
functionName: "addFileWithPermissionsAndSchema",
|
|
1601
1660
|
args: [url, ownerAddress, permissions, BigInt(schemaId)],
|
|
1602
1661
|
account,
|
|
1603
|
-
chain: this.context.walletClient.chain ?? null
|
|
1662
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1663
|
+
...this.spreadTransactionOptions(options)
|
|
1604
1664
|
});
|
|
1605
1665
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1606
1666
|
return tx({
|
|
@@ -1648,7 +1708,7 @@ class DataController extends import_base.BaseController {
|
|
|
1648
1708
|
* console.log(`Refiner ${result.refinerId} created`);
|
|
1649
1709
|
* ```
|
|
1650
1710
|
*/
|
|
1651
|
-
async addRefiner(params) {
|
|
1711
|
+
async addRefiner(params, options) {
|
|
1652
1712
|
this.assertWallet();
|
|
1653
1713
|
try {
|
|
1654
1714
|
const chainId = this.context.publicClient.chain?.id;
|
|
@@ -1674,7 +1734,8 @@ class DataController extends import_base.BaseController {
|
|
|
1674
1734
|
params.refinementInstructionUrl
|
|
1675
1735
|
],
|
|
1676
1736
|
account,
|
|
1677
|
-
chain: this.context.walletClient.chain ?? null
|
|
1737
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1738
|
+
...this.spreadTransactionOptions(options)
|
|
1678
1739
|
});
|
|
1679
1740
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1680
1741
|
const txResult = tx({
|
|
@@ -1874,7 +1935,7 @@ class DataController extends import_base.BaseController {
|
|
|
1874
1935
|
* console.log(`Schema updated in tx ${result.transactionHash}`);
|
|
1875
1936
|
* ```
|
|
1876
1937
|
*/
|
|
1877
|
-
async updateSchemaId(params) {
|
|
1938
|
+
async updateSchemaId(params, options) {
|
|
1878
1939
|
this.assertWallet();
|
|
1879
1940
|
try {
|
|
1880
1941
|
const chainId = this.context.publicClient.chain?.id;
|
|
@@ -1894,7 +1955,8 @@ class DataController extends import_base.BaseController {
|
|
|
1894
1955
|
functionName: "updateSchemaId",
|
|
1895
1956
|
args: [BigInt(params.refinerId), BigInt(params.newSchemaId)],
|
|
1896
1957
|
account,
|
|
1897
|
-
chain: this.context.walletClient.chain ?? null
|
|
1958
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1959
|
+
...this.spreadTransactionOptions(options)
|
|
1898
1960
|
});
|
|
1899
1961
|
await this.context.publicClient.waitForTransactionReceipt({ hash });
|
|
1900
1962
|
return {
|
|
@@ -1963,7 +2025,7 @@ class DataController extends import_base.BaseController {
|
|
|
1963
2025
|
if (response.type === "error") {
|
|
1964
2026
|
throw new Error(response.error);
|
|
1965
2027
|
}
|
|
1966
|
-
if (response.type !== "direct" || !("fileId" in response.result)) {
|
|
2028
|
+
if (response.type !== "direct" || typeof response.result !== "object" || response.result === null || !("fileId" in response.result)) {
|
|
1967
2029
|
throw new Error("Invalid response from relayer");
|
|
1968
2030
|
}
|
|
1969
2031
|
const result = response.result;
|
|
@@ -2055,7 +2117,7 @@ class DataController extends import_base.BaseController {
|
|
|
2055
2117
|
);
|
|
2056
2118
|
}
|
|
2057
2119
|
}
|
|
2058
|
-
const finalFilename = filename ??
|
|
2120
|
+
const finalFilename = filename ?? `upload-${Date.now()}.dat`;
|
|
2059
2121
|
const uploadResult = await this.context.storageManager.upload(
|
|
2060
2122
|
finalBlob,
|
|
2061
2123
|
finalFilename,
|
|
@@ -2100,10 +2162,10 @@ class DataController extends import_base.BaseController {
|
|
|
2100
2162
|
* console.log(`Transaction: ${result.transactionHash}`);
|
|
2101
2163
|
* ```
|
|
2102
2164
|
*/
|
|
2103
|
-
async addPermissionToFile(params) {
|
|
2165
|
+
async addPermissionToFile(params, options) {
|
|
2104
2166
|
this.assertWallet();
|
|
2105
2167
|
const { fileId, account, publicKey } = params;
|
|
2106
|
-
return await this.submitFilePermission(fileId, account, publicKey);
|
|
2168
|
+
return await this.submitFilePermission(fileId, account, publicKey, options);
|
|
2107
2169
|
}
|
|
2108
2170
|
/**
|
|
2109
2171
|
* Submits a file permission transaction to the blockchain.
|
|
@@ -2133,7 +2195,7 @@ class DataController extends import_base.BaseController {
|
|
|
2133
2195
|
* console.log(`Permission granted with ID: ${result.permissionId}`);
|
|
2134
2196
|
* ```
|
|
2135
2197
|
*/
|
|
2136
|
-
async submitFilePermission(fileId, account, publicKey) {
|
|
2198
|
+
async submitFilePermission(fileId, account, publicKey, options) {
|
|
2137
2199
|
this.assertWallet();
|
|
2138
2200
|
try {
|
|
2139
2201
|
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
@@ -2160,7 +2222,8 @@ class DataController extends import_base.BaseController {
|
|
|
2160
2222
|
functionName: "addFilePermission",
|
|
2161
2223
|
args: [BigInt(fileId), account, encryptedKey],
|
|
2162
2224
|
account: walletAccount,
|
|
2163
|
-
chain: this.context.walletClient.chain ?? null
|
|
2225
|
+
chain: this.context.walletClient.chain ?? null,
|
|
2226
|
+
...this.spreadTransactionOptions(options)
|
|
2164
2227
|
});
|
|
2165
2228
|
const { tx } = await import("../utils/transactionHelpers");
|
|
2166
2229
|
return tx({
|