@opendatalabs/vana-sdk 0.1.0-alpha.fd33fc9 → 2.0.0
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/browser.cjs.map +1 -1
- package/dist/browser.d.ts +33 -1
- package/dist/browser.js.map +1 -1
- package/dist/chains/index.cjs.map +1 -1
- package/dist/chains/index.d.ts +30 -1
- package/dist/chains/index.js.map +1 -1
- 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/config/chains.cjs.map +1 -1
- package/dist/config/chains.d.ts +99 -0
- package/dist/config/chains.js.map +1 -1
- package/dist/contracts/contractController.cjs.map +1 -1
- package/dist/contracts/contractController.d.ts +66 -10
- package/dist/contracts/contractController.js.map +1 -1
- 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 +417 -276
- package/dist/controllers/data.cjs.map +1 -1
- package/dist/controllers/data.d.ts +246 -193
- package/dist/controllers/data.js +430 -279
- 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 +690 -209
- package/dist/controllers/permissions.cjs.map +1 -1
- package/dist/controllers/permissions.d.ts +196 -68
- package/dist/controllers/permissions.js +690 -209
- package/dist/controllers/permissions.js.map +1 -1
- package/dist/controllers/protocol.cjs.map +1 -1
- package/dist/controllers/protocol.d.ts +27 -28
- package/dist/controllers/protocol.js.map +1 -1
- package/dist/controllers/schemas.cjs +104 -25
- package/dist/controllers/schemas.cjs.map +1 -1
- package/dist/controllers/schemas.d.ts +88 -40
- package/dist/controllers/schemas.js +104 -25
- package/dist/controllers/schemas.js.map +1 -1
- package/dist/controllers/server.cjs +269 -58
- package/dist/controllers/server.cjs.map +1 -1
- package/dist/controllers/server.d.ts +157 -52
- package/dist/controllers/server.js +269 -58
- 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/apiClient.cjs +53 -3
- package/dist/core/apiClient.cjs.map +1 -1
- package/dist/core/apiClient.d.ts +132 -7
- package/dist/core/apiClient.js +53 -3
- package/dist/core/apiClient.js.map +1 -1
- package/dist/core/generics.cjs +30 -3
- package/dist/core/generics.cjs.map +1 -1
- package/dist/core/generics.d.ts +95 -6
- package/dist/core/generics.js +30 -3
- package/dist/core/generics.js.map +1 -1
- 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.cjs.map +1 -1
- package/dist/index.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/node.cjs.map +1 -1
- package/dist/node.d.ts +39 -1
- package/dist/node.js.map +1 -1
- package/dist/platform/browser.cjs +160 -2
- package/dist/platform/browser.cjs.map +1 -1
- package/dist/platform/browser.d.ts +232 -12
- package/dist/platform/browser.js +160 -2
- package/dist/platform/browser.js.map +1 -1
- package/dist/platform/interface.cjs.map +1 -1
- package/dist/platform/interface.d.ts +283 -90
- package/dist/platform/node.cjs +163 -2
- package/dist/platform/node.cjs.map +1 -1
- package/dist/platform/node.d.ts +69 -6
- package/dist/platform/node.js +163 -2
- package/dist/platform/node.js.map +1 -1
- package/dist/server/relayerHandler.cjs +315 -81
- package/dist/server/relayerHandler.cjs.map +1 -1
- package/dist/server/relayerHandler.d.ts +35 -2
- package/dist/server/relayerHandler.js +315 -81
- 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/manager.cjs +108 -25
- package/dist/storage/manager.cjs.map +1 -1
- package/dist/storage/manager.d.ts +119 -25
- package/dist/storage/manager.js +108 -25
- package/dist/storage/manager.js.map +1 -1
- package/dist/storage/providers/callback-storage.cjs +86 -15
- package/dist/storage/providers/callback-storage.cjs.map +1 -1
- package/dist/storage/providers/callback-storage.d.ts +109 -20
- package/dist/storage/providers/callback-storage.js +86 -15
- package/dist/storage/providers/callback-storage.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/storage/providers/pinata.cjs.map +1 -1
- package/dist/storage/providers/pinata.d.ts +12 -14
- package/dist/storage/providers/pinata.js.map +1 -1
- package/dist/tests/data-upload-owner-validation.test.d.ts +1 -0
- package/dist/tests/permissions-transaction-options.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/blockchain.cjs.map +1 -1
- package/dist/types/blockchain.d.ts +39 -11
- package/dist/types/chains.cjs.map +1 -1
- package/dist/types/chains.d.ts +74 -7
- package/dist/types/chains.js.map +1 -1
- package/dist/types/config.cjs.map +1 -1
- package/dist/types/config.d.ts +38 -4
- package/dist/types/config.js.map +1 -1
- package/dist/types/contracts.cjs.map +1 -1
- package/dist/types/contracts.d.ts +71 -7
- 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 +11 -10
- package/dist/types/generics.cjs.map +1 -1
- package/dist/types/generics.d.ts +81 -10
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.ts +31 -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 +131 -39
- 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 +19 -20
- package/dist/types/personal.cjs.map +1 -1
- package/dist/types/personal.d.ts +150 -14
- package/dist/types/relayer.cjs.map +1 -1
- package/dist/types/relayer.d.ts +145 -24
- package/dist/types/storage.cjs.map +1 -1
- package/dist/types/storage.d.ts +9 -21
- package/dist/types/storage.js.map +1 -1
- package/dist/types/utils.cjs.map +1 -1
- package/dist/types/utils.d.ts +0 -45
- 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.d.ts +10 -20
- package/dist/utils/grantFiles.js +4 -1
- package/dist/utils/grantFiles.js.map +1 -1
- package/dist/utils/grantValidation.cjs.map +1 -1
- package/dist/utils/grantValidation.d.ts +95 -16
- package/dist/utils/grantValidation.js.map +1 -1
- package/dist/utils/grants.cjs.map +1 -1
- package/dist/utils/grants.d.ts +93 -12
- package/dist/utils/grants.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/lazy-import.cjs.map +1 -1
- package/dist/utils/lazy-import.d.ts +32 -7
- package/dist/utils/lazy-import.js.map +1 -1
- package/dist/utils/signatureCache.cjs +8 -2
- package/dist/utils/signatureCache.cjs.map +1 -1
- package/dist/utils/signatureCache.d.ts +49 -8
- package/dist/utils/signatureCache.js +8 -2
- package/dist/utils/signatureCache.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/dist/utils/transactionHelpers.cjs.map +1 -1
- package/dist/utils/transactionHelpers.d.ts +12 -12
- package/dist/utils/transactionHelpers.js.map +1 -1
- package/dist/utils/typedDataConverter.cjs.map +1 -1
- package/dist/utils/typedDataConverter.d.ts +39 -3
- package/dist/utils/typedDataConverter.js.map +1 -1
- package/dist/utils/urlResolver.cjs +7 -0
- package/dist/utils/urlResolver.cjs.map +1 -1
- package/dist/utils/urlResolver.d.ts +22 -4
- package/dist/utils/urlResolver.js +7 -0
- package/dist/utils/urlResolver.js.map +1 -1
- package/dist/utils/wallet.cjs.map +1 -1
- package/dist/utils/wallet.d.ts +78 -16
- package/dist/utils/wallet.js.map +1 -1
- 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,
|
|
@@ -258,35 +281,33 @@ class DataController extends import_base.BaseController {
|
|
|
258
281
|
}
|
|
259
282
|
}
|
|
260
283
|
/**
|
|
261
|
-
* Decrypts a file
|
|
284
|
+
* Decrypts a file using wallet-derived decryption key.
|
|
262
285
|
*
|
|
263
286
|
* @remarks
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
287
|
+
* Counterpart to `upload()` for decrypting user files. Automatically
|
|
288
|
+
* generates decryption key from wallet, fetches encrypted content,
|
|
289
|
+
* and decrypts. Supports IPFS (with gateway fallback) and HTTP URLs.
|
|
290
|
+
*
|
|
291
|
+
* @param file - UserFile object from `getUserFiles()`
|
|
292
|
+
* @param options - Decryption options
|
|
293
|
+
* @param options.seed - Custom encryption seed.
|
|
294
|
+
* Defaults to standard Vana seed.
|
|
295
|
+
*
|
|
296
|
+
* @returns Decrypted content as Blob
|
|
297
|
+
*
|
|
298
|
+
* @throws {Error} No wallet connected.
|
|
299
|
+
* Connect wallet before decrypting.
|
|
300
|
+
* @throws {Error} Network error accessing file.
|
|
301
|
+
* Check CORS settings or server availability.
|
|
302
|
+
* @throws {Error} File not found (404).
|
|
303
|
+
* File no longer available at stored URL.
|
|
304
|
+
* @throws {Error} Access denied (403).
|
|
305
|
+
* No permission to access file.
|
|
306
|
+
* @throws {Error} Invalid file format.
|
|
307
|
+
* File not encrypted with Vana protocol.
|
|
308
|
+
* @throws {Error} Wrong encryption key.
|
|
309
|
+
* Verify seed matches upload or use default.
|
|
268
310
|
*
|
|
269
|
-
* The method automatically:
|
|
270
|
-
* - Generates the decryption key from the user's wallet signature
|
|
271
|
-
* - Determines the appropriate fetch method based on the file URL protocol
|
|
272
|
-
* - Fetches the encrypted content from IPFS or standard HTTP URLs
|
|
273
|
-
* - Decrypts the content using the generated key
|
|
274
|
-
*
|
|
275
|
-
* For IPFS URLs, the method uses gateway fallback for improved reliability. For
|
|
276
|
-
* standard HTTP URLs, it uses a simple fetch. If you need custom authentication
|
|
277
|
-
* headers or specific gateway configurations, use the low-level primitives directly.
|
|
278
|
-
*
|
|
279
|
-
* @param file - The user file to decrypt (typically from getUserFiles)
|
|
280
|
-
* @param encryptionSeed - Optional custom encryption seed (defaults to Vana standard)
|
|
281
|
-
* @returns Promise resolving to the decrypted file content as a Blob
|
|
282
|
-
* @throws {Error} "No addresses available in wallet client" - When wallet is not connected
|
|
283
|
-
* @throws {Error} "Network error: Cannot access the file URL" - When file URL is inaccessible (CORS, server down)
|
|
284
|
-
* @throws {Error} "File not found: The encrypted file is no longer available" - When file returns 404
|
|
285
|
-
* @throws {Error} "Access denied" - When file returns 403 (no permission)
|
|
286
|
-
* @throws {Error} "File is empty or could not be retrieved" - When file has no content
|
|
287
|
-
* @throws {Error} "Invalid file format: This file doesn't appear to be encrypted with the Vana protocol" - When file is not properly encrypted
|
|
288
|
-
* @throws {Error} "Wrong encryption key" - When decryption fails due to incorrect key/seed
|
|
289
|
-
* @throws {Error} "Failed to decrypt file: {error}" - General decryption failures
|
|
290
311
|
* @example
|
|
291
312
|
* ```typescript
|
|
292
313
|
* // Basic file decryption
|
|
@@ -402,99 +423,126 @@ class DataController extends import_base.BaseController {
|
|
|
402
423
|
}
|
|
403
424
|
}
|
|
404
425
|
/**
|
|
405
|
-
* Retrieves all
|
|
426
|
+
* Retrieves all files owned by a specific user address.
|
|
406
427
|
*
|
|
407
428
|
* @remarks
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
* @
|
|
419
|
-
*
|
|
420
|
-
* @
|
|
421
|
-
*
|
|
422
|
-
* @throws {Error}
|
|
423
|
-
*
|
|
424
|
-
* @throws {Error}
|
|
429
|
+
* Queries the Vana subgraph for files owned by the specified address.
|
|
430
|
+
* Automatically deduplicates by file ID, keeping the latest version
|
|
431
|
+
* when duplicates exist from re-indexing or chain reorganizations.
|
|
432
|
+
* Enriches results with DLP proof data when available.
|
|
433
|
+
*
|
|
434
|
+
* @param params - Query configuration
|
|
435
|
+
* @param params.owner - Wallet address of the file owner
|
|
436
|
+
* @param params.subgraphUrl - Subgraph endpoint override.
|
|
437
|
+
* Defaults to context configuration.
|
|
438
|
+
*
|
|
439
|
+
* @returns Array of UserFile objects sorted by timestamp (newest first)
|
|
440
|
+
*
|
|
441
|
+
* @throws {Error} Subgraph URL not configured.
|
|
442
|
+
* Provide `subgraphUrl` parameter or configure in Vana constructor.
|
|
443
|
+
* @throws {Error} Subgraph request failed.
|
|
444
|
+
* Check network connectivity and subgraph availability.
|
|
445
|
+
* @throws {Error} Subgraph returned errors.
|
|
446
|
+
* Review query parameters and subgraph logs.
|
|
447
|
+
*
|
|
425
448
|
* @example
|
|
426
449
|
* ```typescript
|
|
427
|
-
* // Query files for a specific user
|
|
428
450
|
* const files = await vana.data.getUserFiles({
|
|
429
|
-
* owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
|
|
451
|
+
* owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
|
|
430
452
|
* });
|
|
431
453
|
*
|
|
432
454
|
* files.forEach(file => {
|
|
433
|
-
* console.log(`File ${file.id}: ${file.url}
|
|
455
|
+
* console.log(`File ${file.id}: ${file.url}`);
|
|
456
|
+
* console.log(` Schema: ${file.schemaId}`);
|
|
457
|
+
* console.log(` DLPs: ${file.dlpIds?.join(", ") || "none"}`);
|
|
434
458
|
* });
|
|
435
459
|
* ```
|
|
436
460
|
*/
|
|
437
|
-
async getUserFiles(params) {
|
|
461
|
+
async getUserFiles(params, options) {
|
|
438
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
|
+
}
|
|
439
497
|
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
440
498
|
if (!endpoint) {
|
|
441
499
|
throw new Error(
|
|
442
500
|
"subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor."
|
|
443
501
|
);
|
|
444
502
|
}
|
|
503
|
+
if (options?.minBlock || options?.waitForSync) {
|
|
504
|
+
await (0, import_subgraphConsistency.checkSubgraphConsistency)(endpoint, options);
|
|
505
|
+
}
|
|
445
506
|
try {
|
|
446
|
-
const
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
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
|
+
)
|
|
450
530
|
},
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
// Subgraph requires lowercase addresses
|
|
456
|
-
}
|
|
457
|
-
})
|
|
458
|
-
});
|
|
459
|
-
if (!response.ok) {
|
|
460
|
-
throw new Error(
|
|
461
|
-
`Subgraph request failed: ${response.status} ${response.statusText}`
|
|
462
|
-
);
|
|
463
|
-
}
|
|
464
|
-
const result = await response.json();
|
|
465
|
-
if (result.errors) {
|
|
466
|
-
throw new Error(
|
|
467
|
-
`Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
468
|
-
);
|
|
469
|
-
}
|
|
470
|
-
const user = result.data?.user;
|
|
471
|
-
if (!user?.files?.length) {
|
|
472
|
-
console.warn("No files found for user:", owner);
|
|
473
|
-
return [];
|
|
474
|
-
}
|
|
475
|
-
const fileMap = /* @__PURE__ */ new Map();
|
|
476
|
-
user.files.forEach((file) => {
|
|
477
|
-
const fileId = parseInt(file.id);
|
|
478
|
-
const userFile = {
|
|
479
|
-
id: fileId,
|
|
531
|
+
options,
|
|
532
|
+
extractItems: (data) => data?.user?.files,
|
|
533
|
+
transformItem: (file) => ({
|
|
534
|
+
id: parseInt(file.id),
|
|
480
535
|
url: file.url,
|
|
481
536
|
ownerAddress: file.owner.id,
|
|
482
537
|
addedAtBlock: BigInt(file.addedAtBlock),
|
|
483
538
|
schemaId: parseInt(file.schemaId),
|
|
484
539
|
addedAtTimestamp: BigInt(file.addedAtTimestamp),
|
|
485
540
|
transactionHash: file.transactionHash
|
|
486
|
-
}
|
|
487
|
-
const existing = fileMap.get(fileId);
|
|
488
|
-
if (!existing || userFile.addedAtTimestamp && existing.addedAtTimestamp && userFile.addedAtTimestamp > existing.addedAtTimestamp) {
|
|
489
|
-
fileMap.set(fileId, userFile);
|
|
490
|
-
}
|
|
541
|
+
})
|
|
491
542
|
});
|
|
492
|
-
|
|
493
|
-
(a, b) => Number((b.addedAtTimestamp ?? 0n) - (a.addedAtTimestamp ?? 0n))
|
|
494
|
-
);
|
|
495
|
-
if (userFiles.length > 0) {
|
|
543
|
+
if (allFiles.length > 0) {
|
|
496
544
|
try {
|
|
497
|
-
const fileIds =
|
|
545
|
+
const fileIds = allFiles.map((f) => f.id);
|
|
498
546
|
let proofMap;
|
|
499
547
|
try {
|
|
500
548
|
proofMap = await this._fetchProofsFromSubgraph(fileIds, endpoint);
|
|
@@ -505,7 +553,7 @@ class DataController extends import_base.BaseController {
|
|
|
505
553
|
);
|
|
506
554
|
proofMap = await this._fetchProofsFromChain(fileIds);
|
|
507
555
|
}
|
|
508
|
-
for (const file of
|
|
556
|
+
for (const file of allFiles) {
|
|
509
557
|
const dlpIds = proofMap.get(file.id);
|
|
510
558
|
if (dlpIds && dlpIds.length > 0) {
|
|
511
559
|
file.dlpIds = dlpIds;
|
|
@@ -515,7 +563,7 @@ class DataController extends import_base.BaseController {
|
|
|
515
563
|
console.warn("Failed to fetch proof data for files:", error);
|
|
516
564
|
}
|
|
517
565
|
}
|
|
518
|
-
return
|
|
566
|
+
return allFiles;
|
|
519
567
|
} catch (error) {
|
|
520
568
|
console.error("Failed to fetch user files from subgraph:", error);
|
|
521
569
|
throw new Error(
|
|
@@ -641,6 +689,9 @@ class DataController extends import_base.BaseController {
|
|
|
641
689
|
*/
|
|
642
690
|
async getDLP(dlpId, options = {}) {
|
|
643
691
|
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
692
|
+
if (subgraphUrl && (options.minBlock || options.waitForSync)) {
|
|
693
|
+
await (0, import_subgraphConsistency.checkSubgraphConsistency)(subgraphUrl, options);
|
|
694
|
+
}
|
|
644
695
|
if (subgraphUrl) {
|
|
645
696
|
try {
|
|
646
697
|
const response = await fetch(subgraphUrl, {
|
|
@@ -859,21 +910,33 @@ class DataController extends import_base.BaseController {
|
|
|
859
910
|
* @returns Promise resolving to an array of permission objects
|
|
860
911
|
* @throws Error if both subgraph and RPC queries fail
|
|
861
912
|
*/
|
|
862
|
-
async getUserPermissions(params) {
|
|
913
|
+
async getUserPermissions(params, options) {
|
|
863
914
|
const { user, subgraphUrl } = params;
|
|
864
915
|
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
916
|
+
if (endpoint && (options?.minBlock || options?.waitForSync)) {
|
|
917
|
+
await (0, import_subgraphConsistency.checkSubgraphConsistency)(endpoint, options);
|
|
918
|
+
}
|
|
865
919
|
if (endpoint) {
|
|
866
920
|
try {
|
|
867
|
-
const permissions = await this._getUserPermissionsViaSubgraph(
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
921
|
+
const permissions = await this._getUserPermissionsViaSubgraph(
|
|
922
|
+
{
|
|
923
|
+
user,
|
|
924
|
+
subgraphUrl: endpoint
|
|
925
|
+
},
|
|
926
|
+
options
|
|
927
|
+
);
|
|
871
928
|
return permissions;
|
|
872
929
|
} catch (error) {
|
|
873
930
|
console.warn("Subgraph query failed, falling back to RPC:", error);
|
|
874
931
|
}
|
|
875
932
|
}
|
|
876
|
-
|
|
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;
|
|
877
940
|
}
|
|
878
941
|
/**
|
|
879
942
|
* Internal method: Query user permissions via subgraph
|
|
@@ -883,46 +946,48 @@ class DataController extends import_base.BaseController {
|
|
|
883
946
|
* @param params.subgraphUrl - The subgraph URL endpoint to query
|
|
884
947
|
* @returns Promise resolving to an array of permission objects
|
|
885
948
|
*/
|
|
886
|
-
async _getUserPermissionsViaSubgraph(params) {
|
|
949
|
+
async _getUserPermissionsViaSubgraph(params, options) {
|
|
887
950
|
const { user, subgraphUrl } = params;
|
|
888
951
|
try {
|
|
889
|
-
const
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
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
|
+
)
|
|
893
976
|
},
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
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
|
|
899
988
|
})
|
|
900
989
|
});
|
|
901
|
-
|
|
902
|
-
throw new Error(
|
|
903
|
-
`Subgraph request failed: ${response.status} ${response.statusText}`
|
|
904
|
-
);
|
|
905
|
-
}
|
|
906
|
-
const result = await response.json();
|
|
907
|
-
if (result.errors) {
|
|
908
|
-
throw new Error(
|
|
909
|
-
`Subgraph query errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
910
|
-
);
|
|
911
|
-
}
|
|
912
|
-
const userData = result.data?.user;
|
|
913
|
-
if (!userData?.permissions?.length) {
|
|
914
|
-
return [];
|
|
915
|
-
}
|
|
916
|
-
return userData.permissions.map((permission) => ({
|
|
917
|
-
id: permission.id,
|
|
918
|
-
grant: permission.grant,
|
|
919
|
-
nonce: BigInt(permission.nonce),
|
|
920
|
-
signature: permission.signature,
|
|
921
|
-
addedAtBlock: BigInt(permission.addedAtBlock),
|
|
922
|
-
addedAtTimestamp: BigInt(permission.addedAtTimestamp),
|
|
923
|
-
transactionHash: permission.transactionHash,
|
|
924
|
-
user
|
|
925
|
-
})).sort((a, b) => Number(b.addedAtTimestamp - a.addedAtTimestamp));
|
|
990
|
+
return permissions;
|
|
926
991
|
} catch (error) {
|
|
927
992
|
console.error("Failed to query user permissions from subgraph:", error);
|
|
928
993
|
throw error;
|
|
@@ -1055,20 +1120,28 @@ class DataController extends import_base.BaseController {
|
|
|
1055
1120
|
* });
|
|
1056
1121
|
* ```
|
|
1057
1122
|
*/
|
|
1058
|
-
async getUserTrustedServers(params) {
|
|
1059
|
-
const { user
|
|
1123
|
+
async getUserTrustedServers(params, options) {
|
|
1124
|
+
const { user } = params;
|
|
1060
1125
|
const subgraphUrl = params.subgraphUrl ?? this.context.subgraphUrl;
|
|
1126
|
+
if (subgraphUrl && (options?.minBlock || options?.waitForSync)) {
|
|
1127
|
+
await (0, import_subgraphConsistency.checkSubgraphConsistency)(subgraphUrl, options);
|
|
1128
|
+
}
|
|
1061
1129
|
if (subgraphUrl) {
|
|
1062
1130
|
try {
|
|
1063
|
-
const servers = await this._getUserTrustedServersViaSubgraph(
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1131
|
+
const servers = await this._getUserTrustedServersViaSubgraph(
|
|
1132
|
+
{
|
|
1133
|
+
user,
|
|
1134
|
+
subgraphUrl
|
|
1135
|
+
},
|
|
1136
|
+
options
|
|
1137
|
+
);
|
|
1138
|
+
return servers;
|
|
1068
1139
|
} catch (error) {
|
|
1069
1140
|
console.warn("Subgraph query failed, falling back to RPC:", error);
|
|
1070
1141
|
}
|
|
1071
1142
|
}
|
|
1143
|
+
const limit = options?.fetchAll ? Number.MAX_SAFE_INTEGER : options?.limit ?? 100;
|
|
1144
|
+
const offset = options?.offset ?? 0;
|
|
1072
1145
|
const rpcResult = await this._getUserTrustedServersViaRpc({
|
|
1073
1146
|
user,
|
|
1074
1147
|
limit,
|
|
@@ -1084,7 +1157,7 @@ class DataController extends import_base.BaseController {
|
|
|
1084
1157
|
* @param params.subgraphUrl - The subgraph URL endpoint to query
|
|
1085
1158
|
* @returns Promise resolving to an array of trusted server objects
|
|
1086
1159
|
*/
|
|
1087
|
-
async _getUserTrustedServersViaSubgraph(params) {
|
|
1160
|
+
async _getUserTrustedServersViaSubgraph(params, options) {
|
|
1088
1161
|
const { user, subgraphUrl } = params;
|
|
1089
1162
|
const graphqlEndpoint = subgraphUrl;
|
|
1090
1163
|
if (!graphqlEndpoint) {
|
|
@@ -1093,42 +1166,46 @@ class DataController extends import_base.BaseController {
|
|
|
1093
1166
|
);
|
|
1094
1167
|
}
|
|
1095
1168
|
try {
|
|
1096
|
-
const
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
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
|
+
)
|
|
1100
1192
|
},
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
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
|
|
1107
1206
|
})
|
|
1108
1207
|
});
|
|
1109
|
-
|
|
1110
|
-
throw new Error(
|
|
1111
|
-
`Subgraph request failed: ${response.status} ${response.statusText}`
|
|
1112
|
-
);
|
|
1113
|
-
}
|
|
1114
|
-
const result = await response.json();
|
|
1115
|
-
if (result.errors) {
|
|
1116
|
-
throw new Error(
|
|
1117
|
-
`Subgraph query errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
1118
|
-
);
|
|
1119
|
-
}
|
|
1120
|
-
if (!result.data?.user) {
|
|
1121
|
-
return [];
|
|
1122
|
-
}
|
|
1123
|
-
return (result.data.user.serverTrusts ?? []).filter((trust) => !trust.untrustedAtBlock).map((trust) => ({
|
|
1124
|
-
id: trust.server.id,
|
|
1125
|
-
serverAddress: trust.server.serverAddress,
|
|
1126
|
-
serverUrl: trust.server.url,
|
|
1127
|
-
trustedAt: BigInt(trust.trustedAt),
|
|
1128
|
-
user,
|
|
1129
|
-
name: ""
|
|
1130
|
-
// Not available in new schema, will be empty
|
|
1131
|
-
}));
|
|
1208
|
+
return serverTrusts;
|
|
1132
1209
|
} catch (error) {
|
|
1133
1210
|
console.error("Failed to query trusted servers from subgraph:", error);
|
|
1134
1211
|
throw error;
|
|
@@ -1230,18 +1307,26 @@ class DataController extends import_base.BaseController {
|
|
|
1230
1307
|
}
|
|
1231
1308
|
}
|
|
1232
1309
|
/**
|
|
1233
|
-
*
|
|
1310
|
+
* Retrieves total file count from Data Registry.
|
|
1311
|
+
*
|
|
1312
|
+
* @remarks
|
|
1313
|
+
* Queries blockchain for complete file count across all users.
|
|
1314
|
+
* Useful for pagination and network statistics.
|
|
1315
|
+
*
|
|
1316
|
+
* @returns Total number of registered files
|
|
1317
|
+
*
|
|
1318
|
+
* @throws {Error} Chain ID not available.
|
|
1319
|
+
* Ensure network connection.
|
|
1320
|
+
* @throws {Error} Contract read failed.
|
|
1321
|
+
* Check RPC availability.
|
|
1234
1322
|
*
|
|
1235
|
-
* @returns Promise resolving to the total file count
|
|
1236
1323
|
* @example
|
|
1237
1324
|
* ```typescript
|
|
1238
|
-
* const
|
|
1239
|
-
* console.log(`Total files
|
|
1325
|
+
* const total = await vana.data.getTotalFilesCount();
|
|
1326
|
+
* console.log(`Total files: ${total}`);
|
|
1240
1327
|
*
|
|
1241
|
-
* //
|
|
1242
|
-
* const
|
|
1243
|
-
* const totalPages = Math.ceil(totalFiles / filesPerPage);
|
|
1244
|
-
* console.log(`Total pages: ${totalPages}`);
|
|
1328
|
+
* // Calculate pagination
|
|
1329
|
+
* const pages = Math.ceil(total / 20);
|
|
1245
1330
|
* ```
|
|
1246
1331
|
*/
|
|
1247
1332
|
async getTotalFilesCount() {
|
|
@@ -1268,32 +1353,32 @@ class DataController extends import_base.BaseController {
|
|
|
1268
1353
|
}
|
|
1269
1354
|
}
|
|
1270
1355
|
/**
|
|
1271
|
-
* Retrieves
|
|
1356
|
+
* Retrieves file metadata by ID from the blockchain.
|
|
1357
|
+
*
|
|
1358
|
+
* @remarks
|
|
1359
|
+
* Queries DataRegistry contract directly for file details.
|
|
1360
|
+
* Works for any file ID regardless of ownership, enabling
|
|
1361
|
+
* cross-user file discovery and verification.
|
|
1362
|
+
*
|
|
1363
|
+
* @param fileId - Numeric file ID to retrieve
|
|
1364
|
+
*
|
|
1365
|
+
* @returns UserFile object with metadata
|
|
1366
|
+
*
|
|
1367
|
+
* @throws {Error} Chain ID not available.
|
|
1368
|
+
* Ensure proper network connection.
|
|
1369
|
+
* @throws {Error} File not found.
|
|
1370
|
+
* Verify file ID exists on-chain.
|
|
1371
|
+
* @throws {Error} Contract call failed.
|
|
1372
|
+
* Check network and RPC availability.
|
|
1272
1373
|
*
|
|
1273
|
-
* @param fileId - The file ID to look up
|
|
1274
|
-
* @returns Promise resolving to UserFile object
|
|
1275
|
-
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1276
|
-
* @throws {Error} "File not found" - When file ID doesn't exist or returns empty data
|
|
1277
|
-
* @throws {Error} "Failed to fetch file {fileId}: {error}" - General contract read failures
|
|
1278
1374
|
* @example
|
|
1279
1375
|
* ```typescript
|
|
1280
|
-
*
|
|
1281
|
-
*
|
|
1282
|
-
*
|
|
1283
|
-
*
|
|
1284
|
-
*
|
|
1285
|
-
* owner: file.ownerAddress,
|
|
1286
|
-
* addedAt: file.addedAtBlock
|
|
1287
|
-
* });
|
|
1288
|
-
* } catch (error) {
|
|
1289
|
-
* console.error('File not found or error retrieving file:', error);
|
|
1290
|
-
* }
|
|
1376
|
+
* const file = await vana.data.getFileById(123);
|
|
1377
|
+
* console.log(`File ${file.id}:`);
|
|
1378
|
+
* console.log(` URL: ${file.url}`);
|
|
1379
|
+
* console.log(` Owner: ${file.ownerAddress}`);
|
|
1380
|
+
* console.log(` Block: ${file.addedAtBlock}`);
|
|
1291
1381
|
* ```
|
|
1292
|
-
*
|
|
1293
|
-
* This method queries the DataRegistry contract directly
|
|
1294
|
-
* to get file details for any file ID, regardless of user ownership.
|
|
1295
|
-
* This is useful for file lookup functionality where users can search
|
|
1296
|
-
* for specific files by ID.
|
|
1297
1382
|
*/
|
|
1298
1383
|
async getFileById(fileId) {
|
|
1299
1384
|
try {
|
|
@@ -1364,7 +1449,7 @@ class DataController extends import_base.BaseController {
|
|
|
1364
1449
|
* console.log(`File ${fileId} registered with schema in tx ${transactionHash}`);
|
|
1365
1450
|
* ```
|
|
1366
1451
|
*/
|
|
1367
|
-
async registerFileWithSchema(url, schemaId) {
|
|
1452
|
+
async registerFileWithSchema(url, schemaId, options) {
|
|
1368
1453
|
this.assertWallet();
|
|
1369
1454
|
try {
|
|
1370
1455
|
const chainId = this.context.publicClient.chain?.id;
|
|
@@ -1382,7 +1467,8 @@ class DataController extends import_base.BaseController {
|
|
|
1382
1467
|
functionName: "addFileWithSchema",
|
|
1383
1468
|
args: [url, BigInt(schemaId)],
|
|
1384
1469
|
account,
|
|
1385
|
-
chain: this.context.walletClient.chain ?? null
|
|
1470
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1471
|
+
...this.spreadTransactionOptions(options)
|
|
1386
1472
|
});
|
|
1387
1473
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1388
1474
|
return tx({
|
|
@@ -1420,7 +1506,7 @@ class DataController extends import_base.BaseController {
|
|
|
1420
1506
|
* with specific permissions on the DataRegistry contract. It can be used
|
|
1421
1507
|
* by both direct transactions and relayer services.
|
|
1422
1508
|
*/
|
|
1423
|
-
async addFileWithPermissions(url, ownerAddress, permissions = []) {
|
|
1509
|
+
async addFileWithPermissions(url, ownerAddress, permissions = [], options) {
|
|
1424
1510
|
this.assertWallet();
|
|
1425
1511
|
try {
|
|
1426
1512
|
const chainId = this.context.publicClient.chain?.id;
|
|
@@ -1438,7 +1524,8 @@ class DataController extends import_base.BaseController {
|
|
|
1438
1524
|
functionName: "addFileWithPermissions",
|
|
1439
1525
|
args: [url, ownerAddress, permissions],
|
|
1440
1526
|
account,
|
|
1441
|
-
chain: this.context.walletClient.chain ?? null
|
|
1527
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1528
|
+
...this.spreadTransactionOptions(options)
|
|
1442
1529
|
});
|
|
1443
1530
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1444
1531
|
return tx({
|
|
@@ -1493,7 +1580,7 @@ class DataController extends import_base.BaseController {
|
|
|
1493
1580
|
* console.log(`File ${result.fileId} registered in tx ${result.hash}`);
|
|
1494
1581
|
* ```
|
|
1495
1582
|
*/
|
|
1496
|
-
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1583
|
+
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
|
|
1497
1584
|
this.assertWallet();
|
|
1498
1585
|
try {
|
|
1499
1586
|
let encryptedPermissions = [];
|
|
@@ -1527,7 +1614,8 @@ class DataController extends import_base.BaseController {
|
|
|
1527
1614
|
url,
|
|
1528
1615
|
ownerAddress,
|
|
1529
1616
|
encryptedPermissions,
|
|
1530
|
-
schemaId
|
|
1617
|
+
schemaId,
|
|
1618
|
+
options
|
|
1531
1619
|
);
|
|
1532
1620
|
} catch (error) {
|
|
1533
1621
|
console.error("Failed to add file with permissions and schema:", error);
|
|
@@ -1574,7 +1662,7 @@ class DataController extends import_base.BaseController {
|
|
|
1574
1662
|
* console.log(`File registered in tx ${result.hash}`);
|
|
1575
1663
|
* ```
|
|
1576
1664
|
*/
|
|
1577
|
-
async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1665
|
+
async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
|
|
1578
1666
|
try {
|
|
1579
1667
|
const chainId = this.context.publicClient.chain?.id;
|
|
1580
1668
|
if (!chainId) {
|
|
@@ -1591,7 +1679,8 @@ class DataController extends import_base.BaseController {
|
|
|
1591
1679
|
functionName: "addFileWithPermissionsAndSchema",
|
|
1592
1680
|
args: [url, ownerAddress, permissions, BigInt(schemaId)],
|
|
1593
1681
|
account,
|
|
1594
|
-
chain: this.context.walletClient.chain ?? null
|
|
1682
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1683
|
+
...this.spreadTransactionOptions(options)
|
|
1595
1684
|
});
|
|
1596
1685
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1597
1686
|
return tx({
|
|
@@ -1608,34 +1697,38 @@ class DataController extends import_base.BaseController {
|
|
|
1608
1697
|
}
|
|
1609
1698
|
}
|
|
1610
1699
|
/**
|
|
1611
|
-
*
|
|
1700
|
+
* Registers a data refiner for processing templates.
|
|
1612
1701
|
*
|
|
1613
1702
|
* @remarks
|
|
1614
|
-
* Refiners
|
|
1615
|
-
*
|
|
1616
|
-
*
|
|
1617
|
-
*
|
|
1618
|
-
*
|
|
1619
|
-
* @param params - Refiner
|
|
1620
|
-
* @param params.
|
|
1621
|
-
*
|
|
1622
|
-
* @param params.
|
|
1623
|
-
*
|
|
1624
|
-
* @returns
|
|
1625
|
-
*
|
|
1626
|
-
* @throws {Error}
|
|
1703
|
+
* Refiners define data transformation rules for DLPs.
|
|
1704
|
+
* Associates schema, instructions, and processing logic.
|
|
1705
|
+
*
|
|
1706
|
+
* @param params - Refiner configuration
|
|
1707
|
+
* @param params.dlpId - Data Liquidity Pool ID
|
|
1708
|
+
* @param params.name - Refiner display name
|
|
1709
|
+
* @param params.schemaId - Output schema ID.
|
|
1710
|
+
* Obtain via `vana.schemas.list()`.
|
|
1711
|
+
* @param params.refinementInstructionUrl - Processing instructions URL
|
|
1712
|
+
*
|
|
1713
|
+
* @returns Refiner ID and transaction hash
|
|
1714
|
+
*
|
|
1715
|
+
* @throws {Error} Chain ID not available.
|
|
1716
|
+
* Ensure network connection.
|
|
1717
|
+
* @throws {Error} Transaction failed.
|
|
1718
|
+
* Check wallet balance and network status.
|
|
1719
|
+
*
|
|
1627
1720
|
* @example
|
|
1628
1721
|
* ```typescript
|
|
1629
1722
|
* const result = await vana.data.addRefiner({
|
|
1630
1723
|
* dlpId: 1,
|
|
1631
|
-
* name: "
|
|
1724
|
+
* name: "Sentiment Analyzer",
|
|
1632
1725
|
* schemaId: 42,
|
|
1633
1726
|
* refinementInstructionUrl: "ipfs://QmXxx..."
|
|
1634
1727
|
* });
|
|
1635
|
-
* console.log(`
|
|
1728
|
+
* console.log(`Refiner ${result.refinerId} created`);
|
|
1636
1729
|
* ```
|
|
1637
1730
|
*/
|
|
1638
|
-
async addRefiner(params) {
|
|
1731
|
+
async addRefiner(params, options) {
|
|
1639
1732
|
this.assertWallet();
|
|
1640
1733
|
try {
|
|
1641
1734
|
const chainId = this.context.publicClient.chain?.id;
|
|
@@ -1661,7 +1754,8 @@ class DataController extends import_base.BaseController {
|
|
|
1661
1754
|
params.refinementInstructionUrl
|
|
1662
1755
|
],
|
|
1663
1756
|
account,
|
|
1664
|
-
chain: this.context.walletClient.chain ?? null
|
|
1757
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1758
|
+
...this.spreadTransactionOptions(options)
|
|
1665
1759
|
});
|
|
1666
1760
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1667
1761
|
const txResult = tx({
|
|
@@ -1690,26 +1784,29 @@ class DataController extends import_base.BaseController {
|
|
|
1690
1784
|
}
|
|
1691
1785
|
}
|
|
1692
1786
|
/**
|
|
1693
|
-
* Retrieves
|
|
1787
|
+
* Retrieves refiner configuration by ID.
|
|
1694
1788
|
*
|
|
1695
1789
|
* @remarks
|
|
1696
|
-
* Queries
|
|
1697
|
-
*
|
|
1790
|
+
* Queries DataRefinerRegistry for refiner details.
|
|
1791
|
+
* Returns DLP association, schema, and processing instructions.
|
|
1792
|
+
*
|
|
1793
|
+
* @param refinerId - Numeric refiner ID
|
|
1794
|
+
*
|
|
1795
|
+
* @returns Refiner configuration object
|
|
1796
|
+
*
|
|
1797
|
+
* @throws {Error} Chain ID not available.
|
|
1798
|
+
* Ensure network connection.
|
|
1799
|
+
* @throws {Error} Refiner not found.
|
|
1800
|
+
* Verify refiner ID exists.
|
|
1801
|
+
* @throws {Error} Contract read failed.
|
|
1802
|
+
* Check network and RPC status.
|
|
1698
1803
|
*
|
|
1699
|
-
* @param refinerId - The numeric refiner ID to retrieve
|
|
1700
|
-
* @returns Promise resolving to the refiner information object
|
|
1701
|
-
* @throws {Error} When chain ID is not available - "Chain ID not available"
|
|
1702
|
-
* @throws {Error} When refiner doesn't exist - "Refiner with ID {refinerId} does not exist"
|
|
1703
|
-
* @throws {Error} When contract read fails - "Failed to fetch refiner: {error}"
|
|
1704
1804
|
* @example
|
|
1705
1805
|
* ```typescript
|
|
1706
1806
|
* const refiner = await vana.data.getRefiner(1);
|
|
1707
|
-
* console.log({
|
|
1708
|
-
*
|
|
1709
|
-
*
|
|
1710
|
-
* schema: refiner.schemaId,
|
|
1711
|
-
* instructions: refiner.refinementInstructionUrl
|
|
1712
|
-
* });
|
|
1807
|
+
* console.log(`Refiner: ${refiner.name}`);
|
|
1808
|
+
* console.log(`DLP: ${refiner.dlpId}`);
|
|
1809
|
+
* console.log(`Schema: ${refiner.schemaId}`);
|
|
1713
1810
|
* ```
|
|
1714
1811
|
*/
|
|
1715
1812
|
async getRefiner(refinerId) {
|
|
@@ -1750,21 +1847,27 @@ class DataController extends import_base.BaseController {
|
|
|
1750
1847
|
}
|
|
1751
1848
|
}
|
|
1752
1849
|
/**
|
|
1753
|
-
* Validates
|
|
1850
|
+
* Validates schema ID existence.
|
|
1754
1851
|
*
|
|
1755
1852
|
* @remarks
|
|
1756
|
-
*
|
|
1757
|
-
*
|
|
1853
|
+
* Verifies schema registration in DataRegistry.
|
|
1854
|
+
* Check before using schemas for uploads.
|
|
1855
|
+
*
|
|
1856
|
+
* @param schemaId - Numeric schema ID to validate
|
|
1857
|
+
*
|
|
1858
|
+
* @returns True if schema exists, false otherwise
|
|
1859
|
+
*
|
|
1860
|
+
* @throws {Error} Chain ID not available.
|
|
1861
|
+
* Ensure network connection.
|
|
1862
|
+
* @throws {Error} Contract read failed.
|
|
1863
|
+
* Check RPC availability.
|
|
1758
1864
|
*
|
|
1759
|
-
* @param schemaId - The numeric schema ID to validate
|
|
1760
|
-
* @returns Promise resolving to true if schema exists, false otherwise
|
|
1761
1865
|
* @example
|
|
1762
1866
|
* ```typescript
|
|
1763
|
-
* const
|
|
1764
|
-
* if (
|
|
1765
|
-
*
|
|
1766
|
-
*
|
|
1767
|
-
* console.log('Schema 42 does not exist');
|
|
1867
|
+
* const valid = await vana.data.isValidSchemaId(42);
|
|
1868
|
+
* if (valid) {
|
|
1869
|
+
* // Safe to use schema 42
|
|
1870
|
+
* await vana.data.upload({ schemaId: 42, ... });
|
|
1768
1871
|
* }
|
|
1769
1872
|
* ```
|
|
1770
1873
|
*/
|
|
@@ -1852,7 +1955,7 @@ class DataController extends import_base.BaseController {
|
|
|
1852
1955
|
* console.log(`Schema updated in tx ${result.transactionHash}`);
|
|
1853
1956
|
* ```
|
|
1854
1957
|
*/
|
|
1855
|
-
async updateSchemaId(params) {
|
|
1958
|
+
async updateSchemaId(params, options) {
|
|
1856
1959
|
this.assertWallet();
|
|
1857
1960
|
try {
|
|
1858
1961
|
const chainId = this.context.publicClient.chain?.id;
|
|
@@ -1872,7 +1975,8 @@ class DataController extends import_base.BaseController {
|
|
|
1872
1975
|
functionName: "updateSchemaId",
|
|
1873
1976
|
args: [BigInt(params.refinerId), BigInt(params.newSchemaId)],
|
|
1874
1977
|
account,
|
|
1875
|
-
chain: this.context.walletClient.chain ?? null
|
|
1978
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1979
|
+
...this.spreadTransactionOptions(options)
|
|
1876
1980
|
});
|
|
1877
1981
|
await this.context.publicClient.waitForTransactionReceipt({ hash });
|
|
1878
1982
|
return {
|
|
@@ -1941,10 +2045,18 @@ class DataController extends import_base.BaseController {
|
|
|
1941
2045
|
if (response.type === "error") {
|
|
1942
2046
|
throw new Error(response.error);
|
|
1943
2047
|
}
|
|
1944
|
-
|
|
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 {
|
|
1945
2058
|
throw new Error("Invalid response from relayer");
|
|
1946
2059
|
}
|
|
1947
|
-
const result = response.result;
|
|
1948
2060
|
return {
|
|
1949
2061
|
fileId: result.fileId,
|
|
1950
2062
|
url: uploadResult.url,
|
|
@@ -2033,7 +2145,15 @@ class DataController extends import_base.BaseController {
|
|
|
2033
2145
|
);
|
|
2034
2146
|
}
|
|
2035
2147
|
}
|
|
2036
|
-
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
|
+
})();
|
|
2037
2157
|
const uploadResult = await this.context.storageManager.upload(
|
|
2038
2158
|
finalBlob,
|
|
2039
2159
|
finalFilename,
|
|
@@ -2078,10 +2198,10 @@ class DataController extends import_base.BaseController {
|
|
|
2078
2198
|
* console.log(`Transaction: ${result.transactionHash}`);
|
|
2079
2199
|
* ```
|
|
2080
2200
|
*/
|
|
2081
|
-
async addPermissionToFile(params) {
|
|
2201
|
+
async addPermissionToFile(params, options) {
|
|
2082
2202
|
this.assertWallet();
|
|
2083
2203
|
const { fileId, account, publicKey } = params;
|
|
2084
|
-
return await this.submitFilePermission(fileId, account, publicKey);
|
|
2204
|
+
return await this.submitFilePermission(fileId, account, publicKey, options);
|
|
2085
2205
|
}
|
|
2086
2206
|
/**
|
|
2087
2207
|
* Submits a file permission transaction to the blockchain.
|
|
@@ -2111,7 +2231,7 @@ class DataController extends import_base.BaseController {
|
|
|
2111
2231
|
* console.log(`Permission granted with ID: ${result.permissionId}`);
|
|
2112
2232
|
* ```
|
|
2113
2233
|
*/
|
|
2114
|
-
async submitFilePermission(fileId, account, publicKey) {
|
|
2234
|
+
async submitFilePermission(fileId, account, publicKey, options) {
|
|
2115
2235
|
this.assertWallet();
|
|
2116
2236
|
try {
|
|
2117
2237
|
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
@@ -2138,7 +2258,8 @@ class DataController extends import_base.BaseController {
|
|
|
2138
2258
|
functionName: "addFilePermission",
|
|
2139
2259
|
args: [BigInt(fileId), account, encryptedKey],
|
|
2140
2260
|
account: walletAccount,
|
|
2141
|
-
chain: this.context.walletClient.chain ?? null
|
|
2261
|
+
chain: this.context.walletClient.chain ?? null,
|
|
2262
|
+
...this.spreadTransactionOptions(options)
|
|
2142
2263
|
});
|
|
2143
2264
|
const { tx } = await import("../utils/transactionHelpers");
|
|
2144
2265
|
return tx({
|
|
@@ -2484,6 +2605,26 @@ class DataController extends import_base.BaseController {
|
|
|
2484
2605
|
async fetchAndValidateSchema(url) {
|
|
2485
2606
|
return (0, import_schemaValidation.fetchAndValidateSchema)(url);
|
|
2486
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
|
+
}
|
|
2487
2628
|
}
|
|
2488
2629
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2489
2630
|
0 && (module.exports = {
|