@opendatalabs/vana-sdk 0.1.0-alpha.a6b60fc → 0.1.0-alpha.a78ce5c
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/client/__tests__/enhancedResponse.test.d.ts +1 -0
- package/dist/client/enhancedResponse.cjs +164 -0
- package/dist/client/enhancedResponse.cjs.map +1 -0
- package/dist/client/enhancedResponse.d.ts +120 -0
- package/dist/client/enhancedResponse.js +138 -0
- package/dist/client/enhancedResponse.js.map +1 -0
- package/dist/controllers/__tests__/data-consistency-integration.test.d.ts +7 -0
- package/dist/controllers/__tests__/operations.processQueue.test.d.ts +1 -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 +278 -159
- package/dist/controllers/data.cjs.map +1 -1
- package/dist/controllers/data.d.ts +34 -19
- package/dist/controllers/data.js +291 -162
- package/dist/controllers/data.js.map +1 -1
- package/dist/controllers/operations.cjs +430 -0
- package/dist/controllers/operations.cjs.map +1 -0
- package/dist/controllers/operations.d.ts +229 -0
- package/dist/controllers/operations.js +406 -0
- package/dist/controllers/operations.js.map +1 -0
- package/dist/controllers/permissions.cjs +605 -213
- package/dist/controllers/permissions.cjs.map +1 -1
- package/dist/controllers/permissions.d.ts +141 -34
- package/dist/controllers/permissions.js +605 -213
- package/dist/controllers/permissions.js.map +1 -1
- package/dist/controllers/schemas.cjs +81 -4
- package/dist/controllers/schemas.cjs.map +1 -1
- package/dist/controllers/schemas.d.ts +41 -0
- package/dist/controllers/schemas.js +81 -4
- package/dist/controllers/schemas.js.map +1 -1
- package/dist/controllers/server.cjs +251 -42
- package/dist/controllers/server.cjs.map +1 -1
- package/dist/controllers/server.d.ts +111 -14
- package/dist/controllers/server.js +251 -42
- package/dist/controllers/server.js.map +1 -1
- package/dist/core/__tests__/health.test.d.ts +1 -0
- package/dist/core/__tests__/inMemoryNonceManager.test.d.ts +1 -0
- package/dist/core/__tests__/nonceManager.test.d.ts +1 -0
- package/dist/core/__tests__/pollingManager.test.d.ts +4 -0
- package/dist/core/health.cjs +289 -0
- package/dist/core/health.cjs.map +1 -0
- package/dist/core/health.d.ts +143 -0
- package/dist/core/health.js +265 -0
- package/dist/core/health.js.map +1 -0
- package/dist/core/inMemoryNonceManager.cjs +138 -0
- package/dist/core/inMemoryNonceManager.cjs.map +1 -0
- package/dist/core/inMemoryNonceManager.d.ts +69 -0
- package/dist/core/inMemoryNonceManager.js +114 -0
- package/dist/core/inMemoryNonceManager.js.map +1 -0
- package/dist/core/nonceManager.cjs +304 -0
- package/dist/core/nonceManager.cjs.map +1 -0
- package/dist/core/nonceManager.d.ts +116 -0
- package/dist/core/nonceManager.js +280 -0
- package/dist/core/nonceManager.js.map +1 -0
- package/dist/core/pollingManager.cjs +292 -0
- package/dist/core/pollingManager.cjs.map +1 -0
- package/dist/core/pollingManager.d.ts +120 -0
- package/dist/core/pollingManager.js +268 -0
- package/dist/core/pollingManager.js.map +1 -0
- package/dist/core.cjs +55 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +54 -3
- package/dist/core.js +55 -1
- package/dist/core.js.map +1 -1
- package/dist/crypto/ecies/base.cjs +16 -3
- package/dist/crypto/ecies/base.cjs.map +1 -1
- package/dist/crypto/ecies/base.js +16 -3
- package/dist/crypto/ecies/base.js.map +1 -1
- package/dist/errors.cjs +29 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +64 -0
- package/dist/errors.js +28 -0
- package/dist/errors.js.map +1 -1
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.cjs.map +1 -1
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.js.map +1 -1
- package/dist/generated/abi/DLPPerformanceImplementation.cjs +42 -0
- package/dist/generated/abi/DLPPerformanceImplementation.cjs.map +1 -1
- package/dist/generated/abi/DLPPerformanceImplementation.d.ts +32 -0
- package/dist/generated/abi/DLPPerformanceImplementation.js +42 -0
- package/dist/generated/abi/DLPPerformanceImplementation.js.map +1 -1
- package/dist/generated/abi/DLPRegistryImplementation.cjs +5 -5
- package/dist/generated/abi/DLPRegistryImplementation.cjs.map +1 -1
- package/dist/generated/abi/DLPRegistryImplementation.d.ts +4 -4
- package/dist/generated/abi/DLPRegistryImplementation.js +5 -5
- package/dist/generated/abi/DLPRegistryImplementation.js.map +1 -1
- package/dist/generated/abi/DLPRewardDeployerImplementation.cjs +166 -2
- package/dist/generated/abi/DLPRewardDeployerImplementation.cjs.map +1 -1
- package/dist/generated/abi/DLPRewardDeployerImplementation.d.ts +129 -2
- package/dist/generated/abi/DLPRewardDeployerImplementation.js +166 -2
- package/dist/generated/abi/DLPRewardDeployerImplementation.js.map +1 -1
- package/dist/generated/abi/DataPortabilityGranteesImplementation.cjs +167 -19
- package/dist/generated/abi/DataPortabilityGranteesImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataPortabilityGranteesImplementation.d.ts +127 -14
- package/dist/generated/abi/DataPortabilityGranteesImplementation.js +167 -19
- package/dist/generated/abi/DataPortabilityGranteesImplementation.js.map +1 -1
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs +0 -19
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.ts +0 -14
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.js +0 -19
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.js.map +1 -1
- package/dist/generated/abi/DataPortabilityServersImplementation.cjs +0 -19
- package/dist/generated/abi/DataPortabilityServersImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataPortabilityServersImplementation.d.ts +0 -14
- package/dist/generated/abi/DataPortabilityServersImplementation.js +0 -19
- package/dist/generated/abi/DataPortabilityServersImplementation.js.map +1 -1
- package/dist/generated/abi/DataRegistryImplementation.cjs +0 -13
- package/dist/generated/abi/DataRegistryImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataRegistryImplementation.d.ts +0 -10
- package/dist/generated/abi/DataRegistryImplementation.js +0 -13
- package/dist/generated/abi/DataRegistryImplementation.js.map +1 -1
- package/dist/generated/abi/SwapHelperImplementation.cjs +0 -43
- package/dist/generated/abi/SwapHelperImplementation.cjs.map +1 -1
- package/dist/generated/abi/SwapHelperImplementation.d.ts +0 -35
- package/dist/generated/abi/SwapHelperImplementation.js +0 -43
- package/dist/generated/abi/SwapHelperImplementation.js.map +1 -1
- package/dist/generated/abi/VanaEpochImplementation.cjs +195 -0
- package/dist/generated/abi/VanaEpochImplementation.cjs.map +1 -1
- package/dist/generated/abi/VanaEpochImplementation.d.ts +151 -0
- package/dist/generated/abi/VanaEpochImplementation.js +195 -0
- package/dist/generated/abi/VanaEpochImplementation.js.map +1 -1
- package/dist/generated/abi/VanaPoolEntityImplementation.cjs +22 -65
- package/dist/generated/abi/VanaPoolEntityImplementation.cjs.map +1 -1
- package/dist/generated/abi/VanaPoolEntityImplementation.d.ts +17 -51
- package/dist/generated/abi/VanaPoolEntityImplementation.js +22 -65
- package/dist/generated/abi/VanaPoolEntityImplementation.js.map +1 -1
- package/dist/generated/abi/VanaPoolStakingImplementation.cjs +113 -1
- package/dist/generated/abi/VanaPoolStakingImplementation.cjs.map +1 -1
- package/dist/generated/abi/VanaPoolStakingImplementation.d.ts +85 -1
- package/dist/generated/abi/VanaPoolStakingImplementation.js +113 -1
- package/dist/generated/abi/VanaPoolStakingImplementation.js.map +1 -1
- package/dist/generated/abi/index.d.ts +546 -146
- package/dist/generated/event-types.cjs.map +1 -1
- package/dist/generated/event-types.d.ts +14 -8
- package/dist/generated/eventRegistry.cjs +42 -18
- package/dist/generated/eventRegistry.cjs.map +1 -1
- package/dist/generated/eventRegistry.js +42 -18
- package/dist/generated/eventRegistry.js.map +1 -1
- package/dist/generated/server/server-exports.cjs +22 -0
- package/dist/generated/server/server-exports.cjs.map +1 -1
- package/dist/generated/server/server-exports.d.ts +27 -10
- package/dist/generated/server/server-exports.js +17 -0
- package/dist/generated/server/server-exports.js.map +1 -1
- package/dist/generated/server/server.cjs.map +1 -1
- package/dist/generated/server/server.d.ts +771 -402
- 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.browser.d.ts +2 -0
- package/dist/index.browser.js +10 -0
- package/dist/index.browser.js.map +1 -1
- package/dist/index.node.cjs +26 -0
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.ts +49 -5
- package/dist/index.node.js +25 -1
- package/dist/index.node.js.map +1 -1
- package/dist/lib/__tests__/redisAtomicStore.test.d.ts +1 -0
- package/dist/lib/redisAtomicStore.cjs +201 -0
- package/dist/lib/redisAtomicStore.cjs.map +1 -0
- package/dist/lib/redisAtomicStore.d.ts +120 -0
- package/dist/lib/redisAtomicStore.js +177 -0
- package/dist/lib/redisAtomicStore.js.map +1 -0
- package/dist/server/relayerHandler.cjs +313 -75
- package/dist/server/relayerHandler.cjs.map +1 -1
- package/dist/server/relayerHandler.d.ts +35 -2
- package/dist/server/relayerHandler.js +313 -75
- package/dist/server/relayerHandler.js.map +1 -1
- package/dist/storage/index.cjs +3 -0
- package/dist/storage/index.cjs.map +1 -1
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/providers/dropbox.cjs +237 -0
- package/dist/storage/providers/dropbox.cjs.map +1 -0
- package/dist/storage/providers/dropbox.d.ts +39 -0
- package/dist/storage/providers/dropbox.js +215 -0
- package/dist/storage/providers/dropbox.js.map +1 -0
- package/dist/storage/providers/dropbox.test.d.ts +1 -0
- package/dist/tests/data-upload-owner-validation.test.d.ts +1 -0
- package/dist/types/atomicStore.cjs +31 -0
- package/dist/types/atomicStore.cjs.map +1 -0
- package/dist/types/atomicStore.d.ts +236 -0
- package/dist/types/atomicStore.js +7 -0
- package/dist/types/atomicStore.js.map +1 -0
- 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 +4 -1
- package/dist/types/data.cjs.map +1 -1
- package/dist/types/data.d.ts +7 -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 +6 -3
- package/dist/types/index.js.map +1 -1
- package/dist/types/operationStore.cjs +17 -0
- package/dist/types/operationStore.cjs.map +1 -0
- package/dist/types/operationStore.d.ts +171 -0
- package/dist/types/operationStore.js +1 -0
- package/dist/types/operationStore.js.map +1 -0
- package/dist/types/operations.cjs +3 -15
- package/dist/types/operations.cjs.map +1 -1
- package/dist/types/operations.d.ts +17 -42
- package/dist/types/operations.js +2 -13
- 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 +308 -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 +4 -0
- package/dist/types/personal.cjs.map +1 -1
- package/dist/types/personal.d.ts +19 -0
- package/dist/types/relayer.cjs.map +1 -1
- package/dist/types/relayer.d.ts +53 -9
- package/dist/types/utils.cjs.map +1 -1
- package/dist/types/utils.d.ts +0 -49
- package/dist/utils/__tests__/chainQuery.test.d.ts +1 -0
- 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/grantFiles.cjs +4 -1
- package/dist/utils/grantFiles.cjs.map +1 -1
- package/dist/utils/grantFiles.js +4 -1
- package/dist/utils/grantFiles.js.map +1 -1
- 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
|
@@ -32,11 +32,16 @@ __export(data_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(data_exports);
|
|
34
34
|
var import_viem = require("viem");
|
|
35
|
+
var import_pollingManager = require("../core/pollingManager");
|
|
35
36
|
var import_base = require("./base");
|
|
36
37
|
var import_addresses = require("../config/addresses");
|
|
37
38
|
var import_abi = require("../generated/abi");
|
|
39
|
+
var import_errors = require("../errors");
|
|
38
40
|
var import_subgraph = require("../generated/subgraph");
|
|
39
41
|
var import_graphql = require("graphql");
|
|
42
|
+
var import_subgraphConsistency = require("../utils/subgraphConsistency");
|
|
43
|
+
var import_subgraphPagination = require("../utils/subgraphPagination");
|
|
44
|
+
var import_chainQuery = require("../utils/chainQuery");
|
|
40
45
|
var import_encryption = require("../utils/encryption");
|
|
41
46
|
var import_schemaValidation = require("../utils/schemaValidation");
|
|
42
47
|
var import_multicall = require("../utils/multicall");
|
|
@@ -53,12 +58,18 @@ class DataController extends import_base.BaseController {
|
|
|
53
58
|
permissions = [],
|
|
54
59
|
encrypt = true,
|
|
55
60
|
providerName,
|
|
56
|
-
owner
|
|
61
|
+
owner,
|
|
62
|
+
schemaValidation = "strict"
|
|
57
63
|
} = params;
|
|
64
|
+
if (encrypt && owner && owner.toLowerCase() !== this.context.userAddress.toLowerCase()) {
|
|
65
|
+
throw new import_errors.InvalidConfigurationError(
|
|
66
|
+
"The 'owner' parameter cannot be different from the connected wallet's address when encryption is enabled. This would create an un-decryptable file."
|
|
67
|
+
);
|
|
68
|
+
}
|
|
58
69
|
try {
|
|
59
70
|
let isValid = true;
|
|
60
71
|
let validationErrors = [];
|
|
61
|
-
if (schemaId !== void 0) {
|
|
72
|
+
if (schemaId !== void 0 && schemaValidation !== "skip") {
|
|
62
73
|
try {
|
|
63
74
|
const { SchemaController } = await import("./schemas");
|
|
64
75
|
const schemaController = new SchemaController(this.context);
|
|
@@ -82,15 +93,20 @@ class DataController extends import_base.BaseController {
|
|
|
82
93
|
}
|
|
83
94
|
(0, import_schemaValidation.validateDataAgainstSchema)(parsedContent, schema);
|
|
84
95
|
} catch (error) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
if (schemaValidation === "strict") {
|
|
97
|
+
throw error;
|
|
98
|
+
} else if (schemaValidation === "warn") {
|
|
99
|
+
console.warn(
|
|
100
|
+
'[Vana SDK] Schema validation failed, but continuing due to validation mode "warn"'
|
|
101
|
+
);
|
|
102
|
+
if (error instanceof Error) {
|
|
103
|
+
console.warn(" Validation error:", error.message);
|
|
104
|
+
if (typeof error === "object" && "errors" in error && Array.isArray(error.errors)) {
|
|
105
|
+
console.warn(" Detailed errors:", error.errors);
|
|
106
|
+
}
|
|
91
107
|
}
|
|
92
|
-
|
|
93
|
-
validationErrors = ["Schema validation failed"];
|
|
108
|
+
isValid = false;
|
|
109
|
+
validationErrors = error instanceof Error ? [error.message] : ["Schema validation failed"];
|
|
94
110
|
}
|
|
95
111
|
}
|
|
96
112
|
}
|
|
@@ -140,10 +156,17 @@ class DataController extends import_base.BaseController {
|
|
|
140
156
|
if (response.type === "error") {
|
|
141
157
|
throw new Error(response.error);
|
|
142
158
|
}
|
|
143
|
-
if (response.type
|
|
159
|
+
if (response.type === "pending") {
|
|
160
|
+
result = await this.pollRelayerForConfirmation(
|
|
161
|
+
response.operationId,
|
|
162
|
+
void 0
|
|
163
|
+
// TODO: Add TransactionOptions to upload method signature
|
|
164
|
+
);
|
|
165
|
+
} else if (response.type === "direct" && typeof response.result === "object" && response.result !== null && "fileId" in response.result) {
|
|
166
|
+
result = response.result;
|
|
167
|
+
} else {
|
|
144
168
|
throw new Error("Invalid response from relayer");
|
|
145
169
|
}
|
|
146
|
-
result = response.result;
|
|
147
170
|
} else {
|
|
148
171
|
const txResult = await this.addFileWithEncryptedPermissionsAndSchema(
|
|
149
172
|
uploadResult.url,
|
|
@@ -435,67 +458,91 @@ class DataController extends import_base.BaseController {
|
|
|
435
458
|
* });
|
|
436
459
|
* ```
|
|
437
460
|
*/
|
|
438
|
-
async getUserFiles(params) {
|
|
461
|
+
async getUserFiles(params, options) {
|
|
439
462
|
const { owner, subgraphUrl } = params;
|
|
463
|
+
let dataSource = options?.source === "chain" ? "chain" : "subgraph";
|
|
464
|
+
if (options?.source === "auto" || !options?.source && options?.minBlock) {
|
|
465
|
+
const endpoint2 = subgraphUrl ?? this.context.subgraphUrl;
|
|
466
|
+
const currentBlock = await this.context.publicClient.getBlockNumber();
|
|
467
|
+
let subgraphBlock;
|
|
468
|
+
if (endpoint2) {
|
|
469
|
+
try {
|
|
470
|
+
const meta = await (0, import_subgraphConsistency.fetchSubgraphMeta)(endpoint2);
|
|
471
|
+
subgraphBlock = meta.blockNumber;
|
|
472
|
+
} catch {
|
|
473
|
+
subgraphBlock = void 0;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
dataSource = (0, import_chainQuery.determineDataSource)(
|
|
477
|
+
options?.source,
|
|
478
|
+
options?.minBlock,
|
|
479
|
+
currentBlock,
|
|
480
|
+
subgraphBlock
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
if (dataSource === "chain") {
|
|
484
|
+
const publicClient = this.context.publicClient;
|
|
485
|
+
const chainId = await publicClient.getChainId();
|
|
486
|
+
const contractAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
487
|
+
const files = await (0, import_chainQuery.getUserFilesFromChain)(
|
|
488
|
+
publicClient,
|
|
489
|
+
contractAddress,
|
|
490
|
+
owner,
|
|
491
|
+
options?.minBlock ? BigInt(options.minBlock) : void 0
|
|
492
|
+
);
|
|
493
|
+
const limit = options?.fetchAll ? files.length : options?.limit ?? 100;
|
|
494
|
+
const offset = options?.offset ?? 0;
|
|
495
|
+
return files.slice(offset, offset + limit);
|
|
496
|
+
}
|
|
440
497
|
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
441
498
|
if (!endpoint) {
|
|
442
499
|
throw new Error(
|
|
443
500
|
"subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor."
|
|
444
501
|
);
|
|
445
502
|
}
|
|
503
|
+
if (options?.minBlock || options?.waitForSync) {
|
|
504
|
+
await (0, import_subgraphConsistency.checkSubgraphConsistency)(endpoint, options);
|
|
505
|
+
}
|
|
446
506
|
try {
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
507
|
+
const orderByMap = {
|
|
508
|
+
id: "id",
|
|
509
|
+
addedAtBlock: "addedAtBlock",
|
|
510
|
+
addedAtTimestamp: "addedAtTimestamp",
|
|
511
|
+
url: "url",
|
|
512
|
+
schemaId: "schemaId"
|
|
513
|
+
};
|
|
514
|
+
const allFiles = await (0, import_subgraphPagination.executePaginatedQuery)({
|
|
515
|
+
endpoint,
|
|
516
|
+
document: import_subgraph.GetUserFilesPaginatedDocument,
|
|
517
|
+
baseVariables: {
|
|
518
|
+
userId: owner.toLowerCase(),
|
|
519
|
+
// Subgraph requires lowercase addresses
|
|
520
|
+
orderBy: (0, import_subgraphPagination.mapOrderByToEnum)(
|
|
521
|
+
options?.orderBy,
|
|
522
|
+
orderByMap,
|
|
523
|
+
"addedAtBlock"
|
|
524
|
+
),
|
|
525
|
+
orderDirection: (0, import_subgraphPagination.mapOrderDirection)(
|
|
526
|
+
options?.orderDirection,
|
|
527
|
+
"asc",
|
|
528
|
+
"desc"
|
|
529
|
+
)
|
|
451
530
|
},
|
|
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,
|
|
531
|
+
options,
|
|
532
|
+
extractItems: (data) => data?.user?.files,
|
|
533
|
+
transformItem: (file) => ({
|
|
534
|
+
id: parseInt(file.id),
|
|
481
535
|
url: file.url,
|
|
482
536
|
ownerAddress: file.owner.id,
|
|
483
537
|
addedAtBlock: BigInt(file.addedAtBlock),
|
|
484
538
|
schemaId: parseInt(file.schemaId),
|
|
485
539
|
addedAtTimestamp: BigInt(file.addedAtTimestamp),
|
|
486
540
|
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
|
-
}
|
|
541
|
+
})
|
|
492
542
|
});
|
|
493
|
-
|
|
494
|
-
(a, b) => Number((b.addedAtTimestamp ?? 0n) - (a.addedAtTimestamp ?? 0n))
|
|
495
|
-
);
|
|
496
|
-
if (userFiles.length > 0) {
|
|
543
|
+
if (allFiles.length > 0) {
|
|
497
544
|
try {
|
|
498
|
-
const fileIds =
|
|
545
|
+
const fileIds = allFiles.map((f) => f.id);
|
|
499
546
|
let proofMap;
|
|
500
547
|
try {
|
|
501
548
|
proofMap = await this._fetchProofsFromSubgraph(fileIds, endpoint);
|
|
@@ -506,7 +553,7 @@ class DataController extends import_base.BaseController {
|
|
|
506
553
|
);
|
|
507
554
|
proofMap = await this._fetchProofsFromChain(fileIds);
|
|
508
555
|
}
|
|
509
|
-
for (const file of
|
|
556
|
+
for (const file of allFiles) {
|
|
510
557
|
const dlpIds = proofMap.get(file.id);
|
|
511
558
|
if (dlpIds && dlpIds.length > 0) {
|
|
512
559
|
file.dlpIds = dlpIds;
|
|
@@ -516,7 +563,7 @@ class DataController extends import_base.BaseController {
|
|
|
516
563
|
console.warn("Failed to fetch proof data for files:", error);
|
|
517
564
|
}
|
|
518
565
|
}
|
|
519
|
-
return
|
|
566
|
+
return allFiles;
|
|
520
567
|
} catch (error) {
|
|
521
568
|
console.error("Failed to fetch user files from subgraph:", error);
|
|
522
569
|
throw new Error(
|
|
@@ -642,6 +689,9 @@ class DataController extends import_base.BaseController {
|
|
|
642
689
|
*/
|
|
643
690
|
async getDLP(dlpId, options = {}) {
|
|
644
691
|
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
692
|
+
if (subgraphUrl && (options.minBlock || options.waitForSync)) {
|
|
693
|
+
await (0, import_subgraphConsistency.checkSubgraphConsistency)(subgraphUrl, options);
|
|
694
|
+
}
|
|
645
695
|
if (subgraphUrl) {
|
|
646
696
|
try {
|
|
647
697
|
const response = await fetch(subgraphUrl, {
|
|
@@ -860,21 +910,33 @@ class DataController extends import_base.BaseController {
|
|
|
860
910
|
* @returns Promise resolving to an array of permission objects
|
|
861
911
|
* @throws Error if both subgraph and RPC queries fail
|
|
862
912
|
*/
|
|
863
|
-
async getUserPermissions(params) {
|
|
913
|
+
async getUserPermissions(params, options) {
|
|
864
914
|
const { user, subgraphUrl } = params;
|
|
865
915
|
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
916
|
+
if (endpoint && (options?.minBlock || options?.waitForSync)) {
|
|
917
|
+
await (0, import_subgraphConsistency.checkSubgraphConsistency)(endpoint, options);
|
|
918
|
+
}
|
|
866
919
|
if (endpoint) {
|
|
867
920
|
try {
|
|
868
|
-
const permissions = await this._getUserPermissionsViaSubgraph(
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
921
|
+
const permissions = await this._getUserPermissionsViaSubgraph(
|
|
922
|
+
{
|
|
923
|
+
user,
|
|
924
|
+
subgraphUrl: endpoint
|
|
925
|
+
},
|
|
926
|
+
options
|
|
927
|
+
);
|
|
872
928
|
return permissions;
|
|
873
929
|
} catch (error) {
|
|
874
930
|
console.warn("Subgraph query failed, falling back to RPC:", error);
|
|
875
931
|
}
|
|
876
932
|
}
|
|
877
|
-
|
|
933
|
+
const allPermissions = await this._getUserPermissionsViaRpc({ user });
|
|
934
|
+
if (options && !options.fetchAll) {
|
|
935
|
+
const limit = options.limit ?? 100;
|
|
936
|
+
const offset = options.offset ?? 0;
|
|
937
|
+
return allPermissions.slice(offset, offset + limit);
|
|
938
|
+
}
|
|
939
|
+
return allPermissions;
|
|
878
940
|
}
|
|
879
941
|
/**
|
|
880
942
|
* Internal method: Query user permissions via subgraph
|
|
@@ -884,46 +946,48 @@ class DataController extends import_base.BaseController {
|
|
|
884
946
|
* @param params.subgraphUrl - The subgraph URL endpoint to query
|
|
885
947
|
* @returns Promise resolving to an array of permission objects
|
|
886
948
|
*/
|
|
887
|
-
async _getUserPermissionsViaSubgraph(params) {
|
|
949
|
+
async _getUserPermissionsViaSubgraph(params, options) {
|
|
888
950
|
const { user, subgraphUrl } = params;
|
|
889
951
|
try {
|
|
890
|
-
const
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
952
|
+
const orderByMap = {
|
|
953
|
+
id: "id",
|
|
954
|
+
addedAtBlock: "addedAtBlock",
|
|
955
|
+
addedAtTimestamp: "addedAtTimestamp",
|
|
956
|
+
grant: "grant",
|
|
957
|
+
nonce: "nonce",
|
|
958
|
+
startBlock: "startBlock",
|
|
959
|
+
endBlock: "endBlock"
|
|
960
|
+
};
|
|
961
|
+
const permissions = await (0, import_subgraphPagination.executePaginatedQuery)({
|
|
962
|
+
endpoint: subgraphUrl,
|
|
963
|
+
document: import_subgraph.GetUserPermissionsPaginatedDocument,
|
|
964
|
+
baseVariables: {
|
|
965
|
+
userId: user.toLowerCase(),
|
|
966
|
+
orderBy: (0, import_subgraphPagination.mapOrderByToEnum)(
|
|
967
|
+
options?.orderBy,
|
|
968
|
+
orderByMap,
|
|
969
|
+
"addedAtTimestamp"
|
|
970
|
+
),
|
|
971
|
+
orderDirection: (0, import_subgraphPagination.mapOrderDirection)(
|
|
972
|
+
options?.orderDirection,
|
|
973
|
+
"desc",
|
|
974
|
+
"asc"
|
|
975
|
+
)
|
|
894
976
|
},
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
977
|
+
options,
|
|
978
|
+
extractItems: (data) => data?.user?.permissions,
|
|
979
|
+
transformItem: (permission) => ({
|
|
980
|
+
id: permission.id,
|
|
981
|
+
grant: permission.grant,
|
|
982
|
+
nonce: BigInt(permission.nonce),
|
|
983
|
+
signature: permission.signature,
|
|
984
|
+
addedAtBlock: BigInt(permission.addedAtBlock),
|
|
985
|
+
addedAtTimestamp: BigInt(permission.addedAtTimestamp),
|
|
986
|
+
transactionHash: permission.transactionHash,
|
|
987
|
+
user
|
|
900
988
|
})
|
|
901
989
|
});
|
|
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));
|
|
990
|
+
return permissions;
|
|
927
991
|
} catch (error) {
|
|
928
992
|
console.error("Failed to query user permissions from subgraph:", error);
|
|
929
993
|
throw error;
|
|
@@ -1056,20 +1120,28 @@ class DataController extends import_base.BaseController {
|
|
|
1056
1120
|
* });
|
|
1057
1121
|
* ```
|
|
1058
1122
|
*/
|
|
1059
|
-
async getUserTrustedServers(params) {
|
|
1060
|
-
const { user
|
|
1123
|
+
async getUserTrustedServers(params, options) {
|
|
1124
|
+
const { user } = params;
|
|
1061
1125
|
const subgraphUrl = params.subgraphUrl ?? this.context.subgraphUrl;
|
|
1126
|
+
if (subgraphUrl && (options?.minBlock || options?.waitForSync)) {
|
|
1127
|
+
await (0, import_subgraphConsistency.checkSubgraphConsistency)(subgraphUrl, options);
|
|
1128
|
+
}
|
|
1062
1129
|
if (subgraphUrl) {
|
|
1063
1130
|
try {
|
|
1064
|
-
const servers = await this._getUserTrustedServersViaSubgraph(
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1131
|
+
const servers = await this._getUserTrustedServersViaSubgraph(
|
|
1132
|
+
{
|
|
1133
|
+
user,
|
|
1134
|
+
subgraphUrl
|
|
1135
|
+
},
|
|
1136
|
+
options
|
|
1137
|
+
);
|
|
1138
|
+
return servers;
|
|
1069
1139
|
} catch (error) {
|
|
1070
1140
|
console.warn("Subgraph query failed, falling back to RPC:", error);
|
|
1071
1141
|
}
|
|
1072
1142
|
}
|
|
1143
|
+
const limit = options?.fetchAll ? Number.MAX_SAFE_INTEGER : options?.limit ?? 100;
|
|
1144
|
+
const offset = options?.offset ?? 0;
|
|
1073
1145
|
const rpcResult = await this._getUserTrustedServersViaRpc({
|
|
1074
1146
|
user,
|
|
1075
1147
|
limit,
|
|
@@ -1085,7 +1157,7 @@ class DataController extends import_base.BaseController {
|
|
|
1085
1157
|
* @param params.subgraphUrl - The subgraph URL endpoint to query
|
|
1086
1158
|
* @returns Promise resolving to an array of trusted server objects
|
|
1087
1159
|
*/
|
|
1088
|
-
async _getUserTrustedServersViaSubgraph(params) {
|
|
1160
|
+
async _getUserTrustedServersViaSubgraph(params, options) {
|
|
1089
1161
|
const { user, subgraphUrl } = params;
|
|
1090
1162
|
const graphqlEndpoint = subgraphUrl;
|
|
1091
1163
|
if (!graphqlEndpoint) {
|
|
@@ -1094,42 +1166,46 @@ class DataController extends import_base.BaseController {
|
|
|
1094
1166
|
);
|
|
1095
1167
|
}
|
|
1096
1168
|
try {
|
|
1097
|
-
const
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1169
|
+
const orderByMap = {
|
|
1170
|
+
id: "id",
|
|
1171
|
+
trustedAt: "trustedAt",
|
|
1172
|
+
trustedAtBlock: "trustedAtBlock",
|
|
1173
|
+
server: "server",
|
|
1174
|
+
user: "user"
|
|
1175
|
+
};
|
|
1176
|
+
const serverTrusts = await (0, import_subgraphPagination.executePaginatedQuery)({
|
|
1177
|
+
endpoint: graphqlEndpoint,
|
|
1178
|
+
document: import_subgraph.GetUserTrustedServersPaginatedDocument,
|
|
1179
|
+
baseVariables: {
|
|
1180
|
+
userId: user.toLowerCase(),
|
|
1181
|
+
// Subgraph requires lowercase addresses
|
|
1182
|
+
orderBy: (0, import_subgraphPagination.mapOrderByToEnum)(
|
|
1183
|
+
options?.orderBy,
|
|
1184
|
+
orderByMap,
|
|
1185
|
+
"trustedAtBlock"
|
|
1186
|
+
),
|
|
1187
|
+
orderDirection: (0, import_subgraphPagination.mapOrderDirection)(
|
|
1188
|
+
options?.orderDirection,
|
|
1189
|
+
"desc",
|
|
1190
|
+
"asc"
|
|
1191
|
+
)
|
|
1101
1192
|
},
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1193
|
+
options,
|
|
1194
|
+
extractItems: (data) => {
|
|
1195
|
+
const trusts = data?.user?.serverTrusts ?? [];
|
|
1196
|
+
return trusts.filter((trust) => !trust.untrustedAtBlock);
|
|
1197
|
+
},
|
|
1198
|
+
transformItem: (trust) => ({
|
|
1199
|
+
id: trust.server.id,
|
|
1200
|
+
serverAddress: trust.server.serverAddress,
|
|
1201
|
+
serverUrl: trust.server.url,
|
|
1202
|
+
trustedAt: BigInt(trust.trustedAt),
|
|
1203
|
+
user,
|
|
1204
|
+
name: ""
|
|
1205
|
+
// Not available in new schema, will be empty
|
|
1108
1206
|
})
|
|
1109
1207
|
});
|
|
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
|
-
}));
|
|
1208
|
+
return serverTrusts;
|
|
1133
1209
|
} catch (error) {
|
|
1134
1210
|
console.error("Failed to query trusted servers from subgraph:", error);
|
|
1135
1211
|
throw error;
|
|
@@ -1373,7 +1449,7 @@ class DataController extends import_base.BaseController {
|
|
|
1373
1449
|
* console.log(`File ${fileId} registered with schema in tx ${transactionHash}`);
|
|
1374
1450
|
* ```
|
|
1375
1451
|
*/
|
|
1376
|
-
async registerFileWithSchema(url, schemaId) {
|
|
1452
|
+
async registerFileWithSchema(url, schemaId, options) {
|
|
1377
1453
|
this.assertWallet();
|
|
1378
1454
|
try {
|
|
1379
1455
|
const chainId = this.context.publicClient.chain?.id;
|
|
@@ -1391,7 +1467,8 @@ class DataController extends import_base.BaseController {
|
|
|
1391
1467
|
functionName: "addFileWithSchema",
|
|
1392
1468
|
args: [url, BigInt(schemaId)],
|
|
1393
1469
|
account,
|
|
1394
|
-
chain: this.context.walletClient.chain ?? null
|
|
1470
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1471
|
+
...this.spreadTransactionOptions(options)
|
|
1395
1472
|
});
|
|
1396
1473
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1397
1474
|
return tx({
|
|
@@ -1429,7 +1506,7 @@ class DataController extends import_base.BaseController {
|
|
|
1429
1506
|
* with specific permissions on the DataRegistry contract. It can be used
|
|
1430
1507
|
* by both direct transactions and relayer services.
|
|
1431
1508
|
*/
|
|
1432
|
-
async addFileWithPermissions(url, ownerAddress, permissions = []) {
|
|
1509
|
+
async addFileWithPermissions(url, ownerAddress, permissions = [], options) {
|
|
1433
1510
|
this.assertWallet();
|
|
1434
1511
|
try {
|
|
1435
1512
|
const chainId = this.context.publicClient.chain?.id;
|
|
@@ -1447,7 +1524,8 @@ class DataController extends import_base.BaseController {
|
|
|
1447
1524
|
functionName: "addFileWithPermissions",
|
|
1448
1525
|
args: [url, ownerAddress, permissions],
|
|
1449
1526
|
account,
|
|
1450
|
-
chain: this.context.walletClient.chain ?? null
|
|
1527
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1528
|
+
...this.spreadTransactionOptions(options)
|
|
1451
1529
|
});
|
|
1452
1530
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1453
1531
|
return tx({
|
|
@@ -1502,7 +1580,7 @@ class DataController extends import_base.BaseController {
|
|
|
1502
1580
|
* console.log(`File ${result.fileId} registered in tx ${result.hash}`);
|
|
1503
1581
|
* ```
|
|
1504
1582
|
*/
|
|
1505
|
-
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1583
|
+
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
|
|
1506
1584
|
this.assertWallet();
|
|
1507
1585
|
try {
|
|
1508
1586
|
let encryptedPermissions = [];
|
|
@@ -1536,7 +1614,8 @@ class DataController extends import_base.BaseController {
|
|
|
1536
1614
|
url,
|
|
1537
1615
|
ownerAddress,
|
|
1538
1616
|
encryptedPermissions,
|
|
1539
|
-
schemaId
|
|
1617
|
+
schemaId,
|
|
1618
|
+
options
|
|
1540
1619
|
);
|
|
1541
1620
|
} catch (error) {
|
|
1542
1621
|
console.error("Failed to add file with permissions and schema:", error);
|
|
@@ -1583,7 +1662,7 @@ class DataController extends import_base.BaseController {
|
|
|
1583
1662
|
* console.log(`File registered in tx ${result.hash}`);
|
|
1584
1663
|
* ```
|
|
1585
1664
|
*/
|
|
1586
|
-
async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1665
|
+
async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
|
|
1587
1666
|
try {
|
|
1588
1667
|
const chainId = this.context.publicClient.chain?.id;
|
|
1589
1668
|
if (!chainId) {
|
|
@@ -1600,7 +1679,8 @@ class DataController extends import_base.BaseController {
|
|
|
1600
1679
|
functionName: "addFileWithPermissionsAndSchema",
|
|
1601
1680
|
args: [url, ownerAddress, permissions, BigInt(schemaId)],
|
|
1602
1681
|
account,
|
|
1603
|
-
chain: this.context.walletClient.chain ?? null
|
|
1682
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1683
|
+
...this.spreadTransactionOptions(options)
|
|
1604
1684
|
});
|
|
1605
1685
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1606
1686
|
return tx({
|
|
@@ -1648,7 +1728,7 @@ class DataController extends import_base.BaseController {
|
|
|
1648
1728
|
* console.log(`Refiner ${result.refinerId} created`);
|
|
1649
1729
|
* ```
|
|
1650
1730
|
*/
|
|
1651
|
-
async addRefiner(params) {
|
|
1731
|
+
async addRefiner(params, options) {
|
|
1652
1732
|
this.assertWallet();
|
|
1653
1733
|
try {
|
|
1654
1734
|
const chainId = this.context.publicClient.chain?.id;
|
|
@@ -1674,7 +1754,8 @@ class DataController extends import_base.BaseController {
|
|
|
1674
1754
|
params.refinementInstructionUrl
|
|
1675
1755
|
],
|
|
1676
1756
|
account,
|
|
1677
|
-
chain: this.context.walletClient.chain ?? null
|
|
1757
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1758
|
+
...this.spreadTransactionOptions(options)
|
|
1678
1759
|
});
|
|
1679
1760
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1680
1761
|
const txResult = tx({
|
|
@@ -1874,7 +1955,7 @@ class DataController extends import_base.BaseController {
|
|
|
1874
1955
|
* console.log(`Schema updated in tx ${result.transactionHash}`);
|
|
1875
1956
|
* ```
|
|
1876
1957
|
*/
|
|
1877
|
-
async updateSchemaId(params) {
|
|
1958
|
+
async updateSchemaId(params, options) {
|
|
1878
1959
|
this.assertWallet();
|
|
1879
1960
|
try {
|
|
1880
1961
|
const chainId = this.context.publicClient.chain?.id;
|
|
@@ -1894,7 +1975,8 @@ class DataController extends import_base.BaseController {
|
|
|
1894
1975
|
functionName: "updateSchemaId",
|
|
1895
1976
|
args: [BigInt(params.refinerId), BigInt(params.newSchemaId)],
|
|
1896
1977
|
account,
|
|
1897
|
-
chain: this.context.walletClient.chain ?? null
|
|
1978
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1979
|
+
...this.spreadTransactionOptions(options)
|
|
1898
1980
|
});
|
|
1899
1981
|
await this.context.publicClient.waitForTransactionReceipt({ hash });
|
|
1900
1982
|
return {
|
|
@@ -1963,10 +2045,18 @@ class DataController extends import_base.BaseController {
|
|
|
1963
2045
|
if (response.type === "error") {
|
|
1964
2046
|
throw new Error(response.error);
|
|
1965
2047
|
}
|
|
1966
|
-
|
|
2048
|
+
let result;
|
|
2049
|
+
if (response.type === "pending") {
|
|
2050
|
+
result = await this.pollRelayerForConfirmation(
|
|
2051
|
+
response.operationId,
|
|
2052
|
+
void 0
|
|
2053
|
+
// TODO: Add TransactionOptions to upload method signature
|
|
2054
|
+
);
|
|
2055
|
+
} else if (response.type === "direct" && typeof response.result === "object" && response.result !== null && "fileId" in response.result) {
|
|
2056
|
+
result = response.result;
|
|
2057
|
+
} else {
|
|
1967
2058
|
throw new Error("Invalid response from relayer");
|
|
1968
2059
|
}
|
|
1969
|
-
const result = response.result;
|
|
1970
2060
|
return {
|
|
1971
2061
|
fileId: result.fileId,
|
|
1972
2062
|
url: uploadResult.url,
|
|
@@ -2055,7 +2145,15 @@ class DataController extends import_base.BaseController {
|
|
|
2055
2145
|
);
|
|
2056
2146
|
}
|
|
2057
2147
|
}
|
|
2058
|
-
const finalFilename =
|
|
2148
|
+
const finalFilename = (() => {
|
|
2149
|
+
if (filename) {
|
|
2150
|
+
if (encrypt && !filename.endsWith(".enc")) {
|
|
2151
|
+
return `${filename}.enc`;
|
|
2152
|
+
}
|
|
2153
|
+
return filename;
|
|
2154
|
+
}
|
|
2155
|
+
return encrypt ? `upload-${Date.now()}.enc` : `upload-${Date.now()}.dat`;
|
|
2156
|
+
})();
|
|
2059
2157
|
const uploadResult = await this.context.storageManager.upload(
|
|
2060
2158
|
finalBlob,
|
|
2061
2159
|
finalFilename,
|
|
@@ -2100,10 +2198,10 @@ class DataController extends import_base.BaseController {
|
|
|
2100
2198
|
* console.log(`Transaction: ${result.transactionHash}`);
|
|
2101
2199
|
* ```
|
|
2102
2200
|
*/
|
|
2103
|
-
async addPermissionToFile(params) {
|
|
2201
|
+
async addPermissionToFile(params, options) {
|
|
2104
2202
|
this.assertWallet();
|
|
2105
2203
|
const { fileId, account, publicKey } = params;
|
|
2106
|
-
return await this.submitFilePermission(fileId, account, publicKey);
|
|
2204
|
+
return await this.submitFilePermission(fileId, account, publicKey, options);
|
|
2107
2205
|
}
|
|
2108
2206
|
/**
|
|
2109
2207
|
* Submits a file permission transaction to the blockchain.
|
|
@@ -2133,7 +2231,7 @@ class DataController extends import_base.BaseController {
|
|
|
2133
2231
|
* console.log(`Permission granted with ID: ${result.permissionId}`);
|
|
2134
2232
|
* ```
|
|
2135
2233
|
*/
|
|
2136
|
-
async submitFilePermission(fileId, account, publicKey) {
|
|
2234
|
+
async submitFilePermission(fileId, account, publicKey, options) {
|
|
2137
2235
|
this.assertWallet();
|
|
2138
2236
|
try {
|
|
2139
2237
|
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
@@ -2160,7 +2258,8 @@ class DataController extends import_base.BaseController {
|
|
|
2160
2258
|
functionName: "addFilePermission",
|
|
2161
2259
|
args: [BigInt(fileId), account, encryptedKey],
|
|
2162
2260
|
account: walletAccount,
|
|
2163
|
-
chain: this.context.walletClient.chain ?? null
|
|
2261
|
+
chain: this.context.walletClient.chain ?? null,
|
|
2262
|
+
...this.spreadTransactionOptions(options)
|
|
2164
2263
|
});
|
|
2165
2264
|
const { tx } = await import("../utils/transactionHelpers");
|
|
2166
2265
|
return tx({
|
|
@@ -2506,6 +2605,26 @@ class DataController extends import_base.BaseController {
|
|
|
2506
2605
|
async fetchAndValidateSchema(url) {
|
|
2507
2606
|
return (0, import_schemaValidation.fetchAndValidateSchema)(url);
|
|
2508
2607
|
}
|
|
2608
|
+
/**
|
|
2609
|
+
* Polls for confirmation of a relayer operation.
|
|
2610
|
+
* @internal
|
|
2611
|
+
*/
|
|
2612
|
+
async pollRelayerForConfirmation(operationId, options) {
|
|
2613
|
+
if (!this.context.relayer) {
|
|
2614
|
+
throw new Error("Relayer not configured for polling");
|
|
2615
|
+
}
|
|
2616
|
+
const pollingManager = new import_pollingManager.PollingManager(this.context.relayer);
|
|
2617
|
+
const result = await pollingManager.startPolling(operationId, {
|
|
2618
|
+
signal: options?.signal,
|
|
2619
|
+
onStatusUpdate: options?.onStatusUpdate,
|
|
2620
|
+
...options?.pollingOptions
|
|
2621
|
+
});
|
|
2622
|
+
return {
|
|
2623
|
+
fileId: 0,
|
|
2624
|
+
// This would need to be extracted from transaction events
|
|
2625
|
+
transactionHash: result.hash
|
|
2626
|
+
};
|
|
2627
|
+
}
|
|
2509
2628
|
}
|
|
2510
2629
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2511
2630
|
0 && (module.exports = {
|