@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
package/dist/controllers/data.js
CHANGED
|
@@ -1,15 +1,30 @@
|
|
|
1
1
|
import { getContract } from "viem";
|
|
2
|
+
import { PollingManager } from "../core/pollingManager";
|
|
2
3
|
import { BaseController } from "./base";
|
|
3
4
|
import { getContractAddress } from "../config/addresses";
|
|
4
5
|
import { getAbi } from "../generated/abi";
|
|
6
|
+
import { InvalidConfigurationError } from "../errors";
|
|
5
7
|
import {
|
|
6
|
-
|
|
8
|
+
GetUserFilesPaginatedDocument,
|
|
7
9
|
GetFileProofsDocument,
|
|
8
10
|
GetDlpDocument,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
GetUserPermissionsPaginatedDocument,
|
|
12
|
+
GetUserTrustedServersPaginatedDocument
|
|
11
13
|
} from "../generated/subgraph";
|
|
12
14
|
import { print } from "graphql";
|
|
15
|
+
import {
|
|
16
|
+
checkSubgraphConsistency,
|
|
17
|
+
fetchSubgraphMeta
|
|
18
|
+
} from "../utils/subgraphConsistency";
|
|
19
|
+
import {
|
|
20
|
+
executePaginatedQuery,
|
|
21
|
+
mapOrderByToEnum,
|
|
22
|
+
mapOrderDirection
|
|
23
|
+
} from "../utils/subgraphPagination";
|
|
24
|
+
import {
|
|
25
|
+
getUserFilesFromChain,
|
|
26
|
+
determineDataSource
|
|
27
|
+
} from "../utils/chainQuery";
|
|
13
28
|
import {
|
|
14
29
|
generateEncryptionKey,
|
|
15
30
|
decryptBlobWithSignedKey,
|
|
@@ -37,12 +52,18 @@ class DataController extends BaseController {
|
|
|
37
52
|
permissions = [],
|
|
38
53
|
encrypt = true,
|
|
39
54
|
providerName,
|
|
40
|
-
owner
|
|
55
|
+
owner,
|
|
56
|
+
schemaValidation = "strict"
|
|
41
57
|
} = params;
|
|
58
|
+
if (encrypt && owner && owner.toLowerCase() !== this.context.userAddress.toLowerCase()) {
|
|
59
|
+
throw new InvalidConfigurationError(
|
|
60
|
+
"The 'owner' parameter cannot be different from the connected wallet's address when encryption is enabled. This would create an un-decryptable file."
|
|
61
|
+
);
|
|
62
|
+
}
|
|
42
63
|
try {
|
|
43
64
|
let isValid = true;
|
|
44
65
|
let validationErrors = [];
|
|
45
|
-
if (schemaId !== void 0) {
|
|
66
|
+
if (schemaId !== void 0 && schemaValidation !== "skip") {
|
|
46
67
|
try {
|
|
47
68
|
const { SchemaController } = await import("./schemas");
|
|
48
69
|
const schemaController = new SchemaController(this.context);
|
|
@@ -66,15 +87,20 @@ class DataController extends BaseController {
|
|
|
66
87
|
}
|
|
67
88
|
validateDataAgainstSchema(parsedContent, schema);
|
|
68
89
|
} catch (error) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
90
|
+
if (schemaValidation === "strict") {
|
|
91
|
+
throw error;
|
|
92
|
+
} else if (schemaValidation === "warn") {
|
|
93
|
+
console.warn(
|
|
94
|
+
'[Vana SDK] Schema validation failed, but continuing due to validation mode "warn"'
|
|
95
|
+
);
|
|
96
|
+
if (error instanceof Error) {
|
|
97
|
+
console.warn(" Validation error:", error.message);
|
|
98
|
+
if (typeof error === "object" && "errors" in error && Array.isArray(error.errors)) {
|
|
99
|
+
console.warn(" Detailed errors:", error.errors);
|
|
100
|
+
}
|
|
75
101
|
}
|
|
76
|
-
|
|
77
|
-
validationErrors = ["Schema validation failed"];
|
|
102
|
+
isValid = false;
|
|
103
|
+
validationErrors = error instanceof Error ? [error.message] : ["Schema validation failed"];
|
|
78
104
|
}
|
|
79
105
|
}
|
|
80
106
|
}
|
|
@@ -124,10 +150,17 @@ class DataController extends BaseController {
|
|
|
124
150
|
if (response.type === "error") {
|
|
125
151
|
throw new Error(response.error);
|
|
126
152
|
}
|
|
127
|
-
if (response.type
|
|
153
|
+
if (response.type === "pending") {
|
|
154
|
+
result = await this.pollRelayerForConfirmation(
|
|
155
|
+
response.operationId,
|
|
156
|
+
void 0
|
|
157
|
+
// TODO: Add TransactionOptions to upload method signature
|
|
158
|
+
);
|
|
159
|
+
} else if (response.type === "direct" && typeof response.result === "object" && response.result !== null && "fileId" in response.result) {
|
|
160
|
+
result = response.result;
|
|
161
|
+
} else {
|
|
128
162
|
throw new Error("Invalid response from relayer");
|
|
129
163
|
}
|
|
130
|
-
result = response.result;
|
|
131
164
|
} else {
|
|
132
165
|
const txResult = await this.addFileWithEncryptedPermissionsAndSchema(
|
|
133
166
|
uploadResult.url,
|
|
@@ -419,67 +452,91 @@ class DataController extends BaseController {
|
|
|
419
452
|
* });
|
|
420
453
|
* ```
|
|
421
454
|
*/
|
|
422
|
-
async getUserFiles(params) {
|
|
455
|
+
async getUserFiles(params, options) {
|
|
423
456
|
const { owner, subgraphUrl } = params;
|
|
457
|
+
let dataSource = options?.source === "chain" ? "chain" : "subgraph";
|
|
458
|
+
if (options?.source === "auto" || !options?.source && options?.minBlock) {
|
|
459
|
+
const endpoint2 = subgraphUrl ?? this.context.subgraphUrl;
|
|
460
|
+
const currentBlock = await this.context.publicClient.getBlockNumber();
|
|
461
|
+
let subgraphBlock;
|
|
462
|
+
if (endpoint2) {
|
|
463
|
+
try {
|
|
464
|
+
const meta = await fetchSubgraphMeta(endpoint2);
|
|
465
|
+
subgraphBlock = meta.blockNumber;
|
|
466
|
+
} catch {
|
|
467
|
+
subgraphBlock = void 0;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
dataSource = determineDataSource(
|
|
471
|
+
options?.source,
|
|
472
|
+
options?.minBlock,
|
|
473
|
+
currentBlock,
|
|
474
|
+
subgraphBlock
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
if (dataSource === "chain") {
|
|
478
|
+
const publicClient = this.context.publicClient;
|
|
479
|
+
const chainId = await publicClient.getChainId();
|
|
480
|
+
const contractAddress = getContractAddress(chainId, "DataRegistry");
|
|
481
|
+
const files = await getUserFilesFromChain(
|
|
482
|
+
publicClient,
|
|
483
|
+
contractAddress,
|
|
484
|
+
owner,
|
|
485
|
+
options?.minBlock ? BigInt(options.minBlock) : void 0
|
|
486
|
+
);
|
|
487
|
+
const limit = options?.fetchAll ? files.length : options?.limit ?? 100;
|
|
488
|
+
const offset = options?.offset ?? 0;
|
|
489
|
+
return files.slice(offset, offset + limit);
|
|
490
|
+
}
|
|
424
491
|
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
425
492
|
if (!endpoint) {
|
|
426
493
|
throw new Error(
|
|
427
494
|
"subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor."
|
|
428
495
|
);
|
|
429
496
|
}
|
|
497
|
+
if (options?.minBlock || options?.waitForSync) {
|
|
498
|
+
await checkSubgraphConsistency(endpoint, options);
|
|
499
|
+
}
|
|
430
500
|
try {
|
|
431
|
-
const
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
501
|
+
const orderByMap = {
|
|
502
|
+
id: "id",
|
|
503
|
+
addedAtBlock: "addedAtBlock",
|
|
504
|
+
addedAtTimestamp: "addedAtTimestamp",
|
|
505
|
+
url: "url",
|
|
506
|
+
schemaId: "schemaId"
|
|
507
|
+
};
|
|
508
|
+
const allFiles = await executePaginatedQuery({
|
|
509
|
+
endpoint,
|
|
510
|
+
document: GetUserFilesPaginatedDocument,
|
|
511
|
+
baseVariables: {
|
|
512
|
+
userId: owner.toLowerCase(),
|
|
513
|
+
// Subgraph requires lowercase addresses
|
|
514
|
+
orderBy: mapOrderByToEnum(
|
|
515
|
+
options?.orderBy,
|
|
516
|
+
orderByMap,
|
|
517
|
+
"addedAtBlock"
|
|
518
|
+
),
|
|
519
|
+
orderDirection: mapOrderDirection(
|
|
520
|
+
options?.orderDirection,
|
|
521
|
+
"asc",
|
|
522
|
+
"desc"
|
|
523
|
+
)
|
|
435
524
|
},
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
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,
|
|
525
|
+
options,
|
|
526
|
+
extractItems: (data) => data?.user?.files,
|
|
527
|
+
transformItem: (file) => ({
|
|
528
|
+
id: parseInt(file.id),
|
|
465
529
|
url: file.url,
|
|
466
530
|
ownerAddress: file.owner.id,
|
|
467
531
|
addedAtBlock: BigInt(file.addedAtBlock),
|
|
468
532
|
schemaId: parseInt(file.schemaId),
|
|
469
533
|
addedAtTimestamp: BigInt(file.addedAtTimestamp),
|
|
470
534
|
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
|
-
}
|
|
535
|
+
})
|
|
476
536
|
});
|
|
477
|
-
|
|
478
|
-
(a, b) => Number((b.addedAtTimestamp ?? 0n) - (a.addedAtTimestamp ?? 0n))
|
|
479
|
-
);
|
|
480
|
-
if (userFiles.length > 0) {
|
|
537
|
+
if (allFiles.length > 0) {
|
|
481
538
|
try {
|
|
482
|
-
const fileIds =
|
|
539
|
+
const fileIds = allFiles.map((f) => f.id);
|
|
483
540
|
let proofMap;
|
|
484
541
|
try {
|
|
485
542
|
proofMap = await this._fetchProofsFromSubgraph(fileIds, endpoint);
|
|
@@ -490,7 +547,7 @@ class DataController extends BaseController {
|
|
|
490
547
|
);
|
|
491
548
|
proofMap = await this._fetchProofsFromChain(fileIds);
|
|
492
549
|
}
|
|
493
|
-
for (const file of
|
|
550
|
+
for (const file of allFiles) {
|
|
494
551
|
const dlpIds = proofMap.get(file.id);
|
|
495
552
|
if (dlpIds && dlpIds.length > 0) {
|
|
496
553
|
file.dlpIds = dlpIds;
|
|
@@ -500,7 +557,7 @@ class DataController extends BaseController {
|
|
|
500
557
|
console.warn("Failed to fetch proof data for files:", error);
|
|
501
558
|
}
|
|
502
559
|
}
|
|
503
|
-
return
|
|
560
|
+
return allFiles;
|
|
504
561
|
} catch (error) {
|
|
505
562
|
console.error("Failed to fetch user files from subgraph:", error);
|
|
506
563
|
throw new Error(
|
|
@@ -626,6 +683,9 @@ class DataController extends BaseController {
|
|
|
626
683
|
*/
|
|
627
684
|
async getDLP(dlpId, options = {}) {
|
|
628
685
|
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
686
|
+
if (subgraphUrl && (options.minBlock || options.waitForSync)) {
|
|
687
|
+
await checkSubgraphConsistency(subgraphUrl, options);
|
|
688
|
+
}
|
|
629
689
|
if (subgraphUrl) {
|
|
630
690
|
try {
|
|
631
691
|
const response = await fetch(subgraphUrl, {
|
|
@@ -844,21 +904,33 @@ class DataController extends BaseController {
|
|
|
844
904
|
* @returns Promise resolving to an array of permission objects
|
|
845
905
|
* @throws Error if both subgraph and RPC queries fail
|
|
846
906
|
*/
|
|
847
|
-
async getUserPermissions(params) {
|
|
907
|
+
async getUserPermissions(params, options) {
|
|
848
908
|
const { user, subgraphUrl } = params;
|
|
849
909
|
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
910
|
+
if (endpoint && (options?.minBlock || options?.waitForSync)) {
|
|
911
|
+
await checkSubgraphConsistency(endpoint, options);
|
|
912
|
+
}
|
|
850
913
|
if (endpoint) {
|
|
851
914
|
try {
|
|
852
|
-
const permissions = await this._getUserPermissionsViaSubgraph(
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
915
|
+
const permissions = await this._getUserPermissionsViaSubgraph(
|
|
916
|
+
{
|
|
917
|
+
user,
|
|
918
|
+
subgraphUrl: endpoint
|
|
919
|
+
},
|
|
920
|
+
options
|
|
921
|
+
);
|
|
856
922
|
return permissions;
|
|
857
923
|
} catch (error) {
|
|
858
924
|
console.warn("Subgraph query failed, falling back to RPC:", error);
|
|
859
925
|
}
|
|
860
926
|
}
|
|
861
|
-
|
|
927
|
+
const allPermissions = await this._getUserPermissionsViaRpc({ user });
|
|
928
|
+
if (options && !options.fetchAll) {
|
|
929
|
+
const limit = options.limit ?? 100;
|
|
930
|
+
const offset = options.offset ?? 0;
|
|
931
|
+
return allPermissions.slice(offset, offset + limit);
|
|
932
|
+
}
|
|
933
|
+
return allPermissions;
|
|
862
934
|
}
|
|
863
935
|
/**
|
|
864
936
|
* Internal method: Query user permissions via subgraph
|
|
@@ -868,46 +940,48 @@ class DataController extends BaseController {
|
|
|
868
940
|
* @param params.subgraphUrl - The subgraph URL endpoint to query
|
|
869
941
|
* @returns Promise resolving to an array of permission objects
|
|
870
942
|
*/
|
|
871
|
-
async _getUserPermissionsViaSubgraph(params) {
|
|
943
|
+
async _getUserPermissionsViaSubgraph(params, options) {
|
|
872
944
|
const { user, subgraphUrl } = params;
|
|
873
945
|
try {
|
|
874
|
-
const
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
946
|
+
const orderByMap = {
|
|
947
|
+
id: "id",
|
|
948
|
+
addedAtBlock: "addedAtBlock",
|
|
949
|
+
addedAtTimestamp: "addedAtTimestamp",
|
|
950
|
+
grant: "grant",
|
|
951
|
+
nonce: "nonce",
|
|
952
|
+
startBlock: "startBlock",
|
|
953
|
+
endBlock: "endBlock"
|
|
954
|
+
};
|
|
955
|
+
const permissions = await executePaginatedQuery({
|
|
956
|
+
endpoint: subgraphUrl,
|
|
957
|
+
document: GetUserPermissionsPaginatedDocument,
|
|
958
|
+
baseVariables: {
|
|
959
|
+
userId: user.toLowerCase(),
|
|
960
|
+
orderBy: mapOrderByToEnum(
|
|
961
|
+
options?.orderBy,
|
|
962
|
+
orderByMap,
|
|
963
|
+
"addedAtTimestamp"
|
|
964
|
+
),
|
|
965
|
+
orderDirection: mapOrderDirection(
|
|
966
|
+
options?.orderDirection,
|
|
967
|
+
"desc",
|
|
968
|
+
"asc"
|
|
969
|
+
)
|
|
878
970
|
},
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
971
|
+
options,
|
|
972
|
+
extractItems: (data) => data?.user?.permissions,
|
|
973
|
+
transformItem: (permission) => ({
|
|
974
|
+
id: permission.id,
|
|
975
|
+
grant: permission.grant,
|
|
976
|
+
nonce: BigInt(permission.nonce),
|
|
977
|
+
signature: permission.signature,
|
|
978
|
+
addedAtBlock: BigInt(permission.addedAtBlock),
|
|
979
|
+
addedAtTimestamp: BigInt(permission.addedAtTimestamp),
|
|
980
|
+
transactionHash: permission.transactionHash,
|
|
981
|
+
user
|
|
884
982
|
})
|
|
885
983
|
});
|
|
886
|
-
|
|
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));
|
|
984
|
+
return permissions;
|
|
911
985
|
} catch (error) {
|
|
912
986
|
console.error("Failed to query user permissions from subgraph:", error);
|
|
913
987
|
throw error;
|
|
@@ -1040,20 +1114,28 @@ class DataController extends BaseController {
|
|
|
1040
1114
|
* });
|
|
1041
1115
|
* ```
|
|
1042
1116
|
*/
|
|
1043
|
-
async getUserTrustedServers(params) {
|
|
1044
|
-
const { user
|
|
1117
|
+
async getUserTrustedServers(params, options) {
|
|
1118
|
+
const { user } = params;
|
|
1045
1119
|
const subgraphUrl = params.subgraphUrl ?? this.context.subgraphUrl;
|
|
1120
|
+
if (subgraphUrl && (options?.minBlock || options?.waitForSync)) {
|
|
1121
|
+
await checkSubgraphConsistency(subgraphUrl, options);
|
|
1122
|
+
}
|
|
1046
1123
|
if (subgraphUrl) {
|
|
1047
1124
|
try {
|
|
1048
|
-
const servers = await this._getUserTrustedServersViaSubgraph(
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1125
|
+
const servers = await this._getUserTrustedServersViaSubgraph(
|
|
1126
|
+
{
|
|
1127
|
+
user,
|
|
1128
|
+
subgraphUrl
|
|
1129
|
+
},
|
|
1130
|
+
options
|
|
1131
|
+
);
|
|
1132
|
+
return servers;
|
|
1053
1133
|
} catch (error) {
|
|
1054
1134
|
console.warn("Subgraph query failed, falling back to RPC:", error);
|
|
1055
1135
|
}
|
|
1056
1136
|
}
|
|
1137
|
+
const limit = options?.fetchAll ? Number.MAX_SAFE_INTEGER : options?.limit ?? 100;
|
|
1138
|
+
const offset = options?.offset ?? 0;
|
|
1057
1139
|
const rpcResult = await this._getUserTrustedServersViaRpc({
|
|
1058
1140
|
user,
|
|
1059
1141
|
limit,
|
|
@@ -1069,7 +1151,7 @@ class DataController extends BaseController {
|
|
|
1069
1151
|
* @param params.subgraphUrl - The subgraph URL endpoint to query
|
|
1070
1152
|
* @returns Promise resolving to an array of trusted server objects
|
|
1071
1153
|
*/
|
|
1072
|
-
async _getUserTrustedServersViaSubgraph(params) {
|
|
1154
|
+
async _getUserTrustedServersViaSubgraph(params, options) {
|
|
1073
1155
|
const { user, subgraphUrl } = params;
|
|
1074
1156
|
const graphqlEndpoint = subgraphUrl;
|
|
1075
1157
|
if (!graphqlEndpoint) {
|
|
@@ -1078,42 +1160,46 @@ class DataController extends BaseController {
|
|
|
1078
1160
|
);
|
|
1079
1161
|
}
|
|
1080
1162
|
try {
|
|
1081
|
-
const
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1163
|
+
const orderByMap = {
|
|
1164
|
+
id: "id",
|
|
1165
|
+
trustedAt: "trustedAt",
|
|
1166
|
+
trustedAtBlock: "trustedAtBlock",
|
|
1167
|
+
server: "server",
|
|
1168
|
+
user: "user"
|
|
1169
|
+
};
|
|
1170
|
+
const serverTrusts = await executePaginatedQuery({
|
|
1171
|
+
endpoint: graphqlEndpoint,
|
|
1172
|
+
document: GetUserTrustedServersPaginatedDocument,
|
|
1173
|
+
baseVariables: {
|
|
1174
|
+
userId: user.toLowerCase(),
|
|
1175
|
+
// Subgraph requires lowercase addresses
|
|
1176
|
+
orderBy: mapOrderByToEnum(
|
|
1177
|
+
options?.orderBy,
|
|
1178
|
+
orderByMap,
|
|
1179
|
+
"trustedAtBlock"
|
|
1180
|
+
),
|
|
1181
|
+
orderDirection: mapOrderDirection(
|
|
1182
|
+
options?.orderDirection,
|
|
1183
|
+
"desc",
|
|
1184
|
+
"asc"
|
|
1185
|
+
)
|
|
1085
1186
|
},
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1187
|
+
options,
|
|
1188
|
+
extractItems: (data) => {
|
|
1189
|
+
const trusts = data?.user?.serverTrusts ?? [];
|
|
1190
|
+
return trusts.filter((trust) => !trust.untrustedAtBlock);
|
|
1191
|
+
},
|
|
1192
|
+
transformItem: (trust) => ({
|
|
1193
|
+
id: trust.server.id,
|
|
1194
|
+
serverAddress: trust.server.serverAddress,
|
|
1195
|
+
serverUrl: trust.server.url,
|
|
1196
|
+
trustedAt: BigInt(trust.trustedAt),
|
|
1197
|
+
user,
|
|
1198
|
+
name: ""
|
|
1199
|
+
// Not available in new schema, will be empty
|
|
1092
1200
|
})
|
|
1093
1201
|
});
|
|
1094
|
-
|
|
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
|
-
}));
|
|
1202
|
+
return serverTrusts;
|
|
1117
1203
|
} catch (error) {
|
|
1118
1204
|
console.error("Failed to query trusted servers from subgraph:", error);
|
|
1119
1205
|
throw error;
|
|
@@ -1357,7 +1443,7 @@ class DataController extends BaseController {
|
|
|
1357
1443
|
* console.log(`File ${fileId} registered with schema in tx ${transactionHash}`);
|
|
1358
1444
|
* ```
|
|
1359
1445
|
*/
|
|
1360
|
-
async registerFileWithSchema(url, schemaId) {
|
|
1446
|
+
async registerFileWithSchema(url, schemaId, options) {
|
|
1361
1447
|
this.assertWallet();
|
|
1362
1448
|
try {
|
|
1363
1449
|
const chainId = this.context.publicClient.chain?.id;
|
|
@@ -1375,7 +1461,8 @@ class DataController extends BaseController {
|
|
|
1375
1461
|
functionName: "addFileWithSchema",
|
|
1376
1462
|
args: [url, BigInt(schemaId)],
|
|
1377
1463
|
account,
|
|
1378
|
-
chain: this.context.walletClient.chain ?? null
|
|
1464
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1465
|
+
...this.spreadTransactionOptions(options)
|
|
1379
1466
|
});
|
|
1380
1467
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1381
1468
|
return tx({
|
|
@@ -1413,7 +1500,7 @@ class DataController extends BaseController {
|
|
|
1413
1500
|
* with specific permissions on the DataRegistry contract. It can be used
|
|
1414
1501
|
* by both direct transactions and relayer services.
|
|
1415
1502
|
*/
|
|
1416
|
-
async addFileWithPermissions(url, ownerAddress, permissions = []) {
|
|
1503
|
+
async addFileWithPermissions(url, ownerAddress, permissions = [], options) {
|
|
1417
1504
|
this.assertWallet();
|
|
1418
1505
|
try {
|
|
1419
1506
|
const chainId = this.context.publicClient.chain?.id;
|
|
@@ -1431,7 +1518,8 @@ class DataController extends BaseController {
|
|
|
1431
1518
|
functionName: "addFileWithPermissions",
|
|
1432
1519
|
args: [url, ownerAddress, permissions],
|
|
1433
1520
|
account,
|
|
1434
|
-
chain: this.context.walletClient.chain ?? null
|
|
1521
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1522
|
+
...this.spreadTransactionOptions(options)
|
|
1435
1523
|
});
|
|
1436
1524
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1437
1525
|
return tx({
|
|
@@ -1486,7 +1574,7 @@ class DataController extends BaseController {
|
|
|
1486
1574
|
* console.log(`File ${result.fileId} registered in tx ${result.hash}`);
|
|
1487
1575
|
* ```
|
|
1488
1576
|
*/
|
|
1489
|
-
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1577
|
+
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
|
|
1490
1578
|
this.assertWallet();
|
|
1491
1579
|
try {
|
|
1492
1580
|
let encryptedPermissions = [];
|
|
@@ -1520,7 +1608,8 @@ class DataController extends BaseController {
|
|
|
1520
1608
|
url,
|
|
1521
1609
|
ownerAddress,
|
|
1522
1610
|
encryptedPermissions,
|
|
1523
|
-
schemaId
|
|
1611
|
+
schemaId,
|
|
1612
|
+
options
|
|
1524
1613
|
);
|
|
1525
1614
|
} catch (error) {
|
|
1526
1615
|
console.error("Failed to add file with permissions and schema:", error);
|
|
@@ -1567,7 +1656,7 @@ class DataController extends BaseController {
|
|
|
1567
1656
|
* console.log(`File registered in tx ${result.hash}`);
|
|
1568
1657
|
* ```
|
|
1569
1658
|
*/
|
|
1570
|
-
async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1659
|
+
async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
|
|
1571
1660
|
try {
|
|
1572
1661
|
const chainId = this.context.publicClient.chain?.id;
|
|
1573
1662
|
if (!chainId) {
|
|
@@ -1584,7 +1673,8 @@ class DataController extends BaseController {
|
|
|
1584
1673
|
functionName: "addFileWithPermissionsAndSchema",
|
|
1585
1674
|
args: [url, ownerAddress, permissions, BigInt(schemaId)],
|
|
1586
1675
|
account,
|
|
1587
|
-
chain: this.context.walletClient.chain ?? null
|
|
1676
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1677
|
+
...this.spreadTransactionOptions(options)
|
|
1588
1678
|
});
|
|
1589
1679
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1590
1680
|
return tx({
|
|
@@ -1632,7 +1722,7 @@ class DataController extends BaseController {
|
|
|
1632
1722
|
* console.log(`Refiner ${result.refinerId} created`);
|
|
1633
1723
|
* ```
|
|
1634
1724
|
*/
|
|
1635
|
-
async addRefiner(params) {
|
|
1725
|
+
async addRefiner(params, options) {
|
|
1636
1726
|
this.assertWallet();
|
|
1637
1727
|
try {
|
|
1638
1728
|
const chainId = this.context.publicClient.chain?.id;
|
|
@@ -1658,7 +1748,8 @@ class DataController extends BaseController {
|
|
|
1658
1748
|
params.refinementInstructionUrl
|
|
1659
1749
|
],
|
|
1660
1750
|
account,
|
|
1661
|
-
chain: this.context.walletClient.chain ?? null
|
|
1751
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1752
|
+
...this.spreadTransactionOptions(options)
|
|
1662
1753
|
});
|
|
1663
1754
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1664
1755
|
const txResult = tx({
|
|
@@ -1858,7 +1949,7 @@ class DataController extends BaseController {
|
|
|
1858
1949
|
* console.log(`Schema updated in tx ${result.transactionHash}`);
|
|
1859
1950
|
* ```
|
|
1860
1951
|
*/
|
|
1861
|
-
async updateSchemaId(params) {
|
|
1952
|
+
async updateSchemaId(params, options) {
|
|
1862
1953
|
this.assertWallet();
|
|
1863
1954
|
try {
|
|
1864
1955
|
const chainId = this.context.publicClient.chain?.id;
|
|
@@ -1878,7 +1969,8 @@ class DataController extends BaseController {
|
|
|
1878
1969
|
functionName: "updateSchemaId",
|
|
1879
1970
|
args: [BigInt(params.refinerId), BigInt(params.newSchemaId)],
|
|
1880
1971
|
account,
|
|
1881
|
-
chain: this.context.walletClient.chain ?? null
|
|
1972
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1973
|
+
...this.spreadTransactionOptions(options)
|
|
1882
1974
|
});
|
|
1883
1975
|
await this.context.publicClient.waitForTransactionReceipt({ hash });
|
|
1884
1976
|
return {
|
|
@@ -1947,10 +2039,18 @@ class DataController extends BaseController {
|
|
|
1947
2039
|
if (response.type === "error") {
|
|
1948
2040
|
throw new Error(response.error);
|
|
1949
2041
|
}
|
|
1950
|
-
|
|
2042
|
+
let result;
|
|
2043
|
+
if (response.type === "pending") {
|
|
2044
|
+
result = await this.pollRelayerForConfirmation(
|
|
2045
|
+
response.operationId,
|
|
2046
|
+
void 0
|
|
2047
|
+
// TODO: Add TransactionOptions to upload method signature
|
|
2048
|
+
);
|
|
2049
|
+
} else if (response.type === "direct" && typeof response.result === "object" && response.result !== null && "fileId" in response.result) {
|
|
2050
|
+
result = response.result;
|
|
2051
|
+
} else {
|
|
1951
2052
|
throw new Error("Invalid response from relayer");
|
|
1952
2053
|
}
|
|
1953
|
-
const result = response.result;
|
|
1954
2054
|
return {
|
|
1955
2055
|
fileId: result.fileId,
|
|
1956
2056
|
url: uploadResult.url,
|
|
@@ -2039,7 +2139,15 @@ class DataController extends BaseController {
|
|
|
2039
2139
|
);
|
|
2040
2140
|
}
|
|
2041
2141
|
}
|
|
2042
|
-
const finalFilename =
|
|
2142
|
+
const finalFilename = (() => {
|
|
2143
|
+
if (filename) {
|
|
2144
|
+
if (encrypt && !filename.endsWith(".enc")) {
|
|
2145
|
+
return `${filename}.enc`;
|
|
2146
|
+
}
|
|
2147
|
+
return filename;
|
|
2148
|
+
}
|
|
2149
|
+
return encrypt ? `upload-${Date.now()}.enc` : `upload-${Date.now()}.dat`;
|
|
2150
|
+
})();
|
|
2043
2151
|
const uploadResult = await this.context.storageManager.upload(
|
|
2044
2152
|
finalBlob,
|
|
2045
2153
|
finalFilename,
|
|
@@ -2084,10 +2192,10 @@ class DataController extends BaseController {
|
|
|
2084
2192
|
* console.log(`Transaction: ${result.transactionHash}`);
|
|
2085
2193
|
* ```
|
|
2086
2194
|
*/
|
|
2087
|
-
async addPermissionToFile(params) {
|
|
2195
|
+
async addPermissionToFile(params, options) {
|
|
2088
2196
|
this.assertWallet();
|
|
2089
2197
|
const { fileId, account, publicKey } = params;
|
|
2090
|
-
return await this.submitFilePermission(fileId, account, publicKey);
|
|
2198
|
+
return await this.submitFilePermission(fileId, account, publicKey, options);
|
|
2091
2199
|
}
|
|
2092
2200
|
/**
|
|
2093
2201
|
* Submits a file permission transaction to the blockchain.
|
|
@@ -2117,7 +2225,7 @@ class DataController extends BaseController {
|
|
|
2117
2225
|
* console.log(`Permission granted with ID: ${result.permissionId}`);
|
|
2118
2226
|
* ```
|
|
2119
2227
|
*/
|
|
2120
|
-
async submitFilePermission(fileId, account, publicKey) {
|
|
2228
|
+
async submitFilePermission(fileId, account, publicKey, options) {
|
|
2121
2229
|
this.assertWallet();
|
|
2122
2230
|
try {
|
|
2123
2231
|
const userEncryptionKey = await generateEncryptionKey(
|
|
@@ -2144,7 +2252,8 @@ class DataController extends BaseController {
|
|
|
2144
2252
|
functionName: "addFilePermission",
|
|
2145
2253
|
args: [BigInt(fileId), account, encryptedKey],
|
|
2146
2254
|
account: walletAccount,
|
|
2147
|
-
chain: this.context.walletClient.chain ?? null
|
|
2255
|
+
chain: this.context.walletClient.chain ?? null,
|
|
2256
|
+
...this.spreadTransactionOptions(options)
|
|
2148
2257
|
});
|
|
2149
2258
|
const { tx } = await import("../utils/transactionHelpers");
|
|
2150
2259
|
return tx({
|
|
@@ -2490,6 +2599,26 @@ class DataController extends BaseController {
|
|
|
2490
2599
|
async fetchAndValidateSchema(url) {
|
|
2491
2600
|
return fetchAndValidateSchema(url);
|
|
2492
2601
|
}
|
|
2602
|
+
/**
|
|
2603
|
+
* Polls for confirmation of a relayer operation.
|
|
2604
|
+
* @internal
|
|
2605
|
+
*/
|
|
2606
|
+
async pollRelayerForConfirmation(operationId, options) {
|
|
2607
|
+
if (!this.context.relayer) {
|
|
2608
|
+
throw new Error("Relayer not configured for polling");
|
|
2609
|
+
}
|
|
2610
|
+
const pollingManager = new PollingManager(this.context.relayer);
|
|
2611
|
+
const result = await pollingManager.startPolling(operationId, {
|
|
2612
|
+
signal: options?.signal,
|
|
2613
|
+
onStatusUpdate: options?.onStatusUpdate,
|
|
2614
|
+
...options?.pollingOptions
|
|
2615
|
+
});
|
|
2616
|
+
return {
|
|
2617
|
+
fileId: 0,
|
|
2618
|
+
// This would need to be extracted from transaction events
|
|
2619
|
+
transactionHash: result.hash
|
|
2620
|
+
};
|
|
2621
|
+
}
|
|
2493
2622
|
}
|
|
2494
2623
|
export {
|
|
2495
2624
|
DataController
|