@opendatalabs/vana-sdk 0.1.0-alpha.d7fc764 → 0.1.0-alpha.dba79a3
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/__tests__/waitForTransactionEvents.test.d.ts +1 -0
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.ts +36 -2
- package/dist/browser.js.map +1 -1
- package/dist/chains/definitions.cjs +9 -6
- package/dist/chains/definitions.cjs.map +1 -1
- package/dist/chains/definitions.d.ts +9 -11
- package/dist/chains/definitions.js +9 -6
- package/dist/chains/definitions.js.map +1 -1
- package/dist/chains/index.cjs.map +1 -1
- package/dist/chains/index.d.ts +34 -2
- package/dist/chains/index.js.map +1 -1
- package/dist/chains.browser.d.ts +8 -2
- package/dist/chains.d.ts +8 -2
- package/dist/chains.node.d.ts +8 -2
- package/dist/config/addresses.d.ts +8 -24
- package/dist/config/chains.cjs.map +1 -1
- package/dist/config/chains.d.ts +108 -13
- package/dist/config/chains.js.map +1 -1
- package/dist/config/default-services.cjs +60 -0
- package/dist/config/default-services.cjs.map +1 -0
- package/dist/config/default-services.d.ts +46 -0
- package/dist/config/default-services.js +33 -0
- package/dist/config/default-services.js.map +1 -0
- package/dist/config/default-services.test.d.ts +1 -0
- package/dist/config/features.d.ts +1 -3
- package/dist/config/tests/addresses.test.d.ts +1 -0
- package/dist/contracts/contractController.cjs +3 -3
- package/dist/contracts/contractController.cjs.map +1 -1
- package/dist/contracts/contractController.d.ts +77 -38
- package/dist/contracts/contractController.js +4 -7
- package/dist/contracts/contractController.js.map +1 -1
- package/dist/contracts/tests/contractController.test.d.ts +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/__tests__/schemas-edge-cases.test.d.ts +1 -0
- package/dist/controllers/base.cjs +116 -0
- package/dist/controllers/base.cjs.map +1 -0
- package/dist/controllers/base.d.ts +94 -0
- package/dist/controllers/base.js +92 -0
- package/dist/controllers/base.js.map +1 -0
- package/dist/controllers/data-error-handling.test.d.ts +1 -0
- package/dist/controllers/data.cjs +827 -439
- package/dist/controllers/data.cjs.map +1 -1
- package/dist/controllers/data.d.ts +373 -254
- package/dist/controllers/data.js +840 -442
- 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 +929 -483
- package/dist/controllers/permissions.cjs.map +1 -1
- package/dist/controllers/permissions.d.ts +1318 -25
- package/dist/controllers/permissions.js +929 -483
- package/dist/controllers/permissions.js.map +1 -1
- package/dist/controllers/protocol.cjs +15 -11
- package/dist/controllers/protocol.cjs.map +1 -1
- package/dist/controllers/protocol.d.ts +34 -63
- package/dist/controllers/protocol.js +15 -14
- package/dist/controllers/protocol.js.map +1 -1
- package/dist/controllers/schemas.cjs +100 -75
- package/dist/controllers/schemas.cjs.map +1 -1
- package/dist/controllers/schemas.d.ts +56 -74
- package/dist/controllers/schemas.js +100 -75
- package/dist/controllers/schemas.js.map +1 -1
- package/dist/controllers/server-additional.test.d.ts +1 -0
- package/dist/controllers/server.cjs +32 -25
- package/dist/controllers/server.cjs.map +1 -1
- package/dist/controllers/server.d.ts +53 -71
- package/dist/controllers/server.js +32 -25
- 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 +68 -15
- package/dist/core/apiClient.cjs.map +1 -1
- package/dist/core/apiClient.d.ts +137 -16
- package/dist/core/apiClient.js +72 -22
- package/dist/core/apiClient.js.map +1 -1
- package/dist/core/client.cjs +7 -7
- package/dist/core/client.cjs.map +1 -1
- package/dist/core/client.d.ts +6 -9
- package/dist/core/client.js +7 -7
- package/dist/core/client.js.map +1 -1
- package/dist/core/core.test.d.ts +1 -0
- package/dist/core/generics.cjs +41 -12
- package/dist/core/generics.cjs.map +1 -1
- package/dist/core/generics.d.ts +104 -19
- package/dist/core/generics.js +52 -32
- 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/tests/apiClient.test.d.ts +1 -0
- package/dist/core/tests/client.test.d.ts +1 -0
- package/dist/core/tests/generics.test.d.ts +1 -0
- package/dist/core.cjs +152 -61
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +50 -67
- package/dist/core.js +164 -86
- package/dist/core.js.map +1 -1
- package/dist/crypto/ecies/__tests__/base.test.d.ts +4 -0
- package/dist/crypto/ecies/__tests__/compatibility.test.d.ts +8 -0
- package/dist/crypto/ecies/__tests__/constants.test.d.ts +4 -0
- package/dist/crypto/ecies/__tests__/native-parity.test.d.ts +7 -0
- package/dist/crypto/ecies/__tests__/normalization.test.d.ts +1 -0
- package/dist/crypto/ecies/__tests__/test-vectors.d.ts +2 -4
- package/dist/crypto/ecies/base.cjs +20 -6
- package/dist/crypto/ecies/base.cjs.map +1 -1
- package/dist/crypto/ecies/base.d.ts +2 -5
- package/dist/crypto/ecies/base.js +28 -18
- package/dist/crypto/ecies/base.js.map +1 -1
- package/dist/crypto/ecies/browser.cjs +2 -1
- package/dist/crypto/ecies/browser.cjs.map +1 -1
- package/dist/crypto/ecies/browser.d.ts +2 -7
- package/dist/crypto/ecies/browser.js +2 -1
- package/dist/crypto/ecies/browser.js.map +1 -1
- package/dist/crypto/ecies/constants.d.ts +7 -9
- package/dist/crypto/ecies/index.d.ts +8 -1
- package/dist/crypto/ecies/interface.cjs +4 -5
- package/dist/crypto/ecies/interface.cjs.map +1 -1
- package/dist/crypto/ecies/interface.d.ts +9 -11
- package/dist/crypto/ecies/interface.js +4 -5
- package/dist/crypto/ecies/interface.js.map +1 -1
- package/dist/crypto/ecies/node.cjs +3 -2
- package/dist/crypto/ecies/node.cjs.map +1 -1
- package/dist/crypto/ecies/node.d.ts +2 -7
- package/dist/crypto/ecies/node.js +11 -16
- package/dist/crypto/ecies/node.js.map +1 -1
- package/dist/crypto/ecies/test-vectors/eccrypto-vectors.json +72 -0
- package/dist/crypto/ecies/utils.cjs +2 -41
- package/dist/crypto/ecies/utils.cjs.map +1 -1
- package/dist/crypto/ecies/utils.d.ts +3 -40
- package/dist/crypto/ecies/utils.js +1 -35
- package/dist/crypto/ecies/utils.js.map +1 -1
- package/dist/crypto/services/WalletKeyEncryptionService.cjs +2 -2
- package/dist/crypto/services/WalletKeyEncryptionService.cjs.map +1 -1
- package/dist/crypto/services/WalletKeyEncryptionService.d.ts +3 -7
- package/dist/crypto/services/WalletKeyEncryptionService.js +5 -9
- package/dist/crypto/services/WalletKeyEncryptionService.js.map +1 -1
- package/dist/crypto/services/WalletKeyEncryptionService.test.d.ts +1 -0
- package/dist/diagnostics.d.ts +1 -3
- package/dist/diagnostics.test.d.ts +1 -0
- package/dist/errors.cjs +45 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +117 -15
- package/dist/errors.js +46 -6
- package/dist/errors.js.map +1 -1
- package/dist/generated/abi/ComputeEngineImplementation.d.ts +2 -3
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.d.ts +2 -3
- package/dist/generated/abi/DATFactoryImplementation.d.ts +2 -3
- package/dist/generated/abi/DATImplementation.d.ts +2 -3
- package/dist/generated/abi/DATPausableImplementation.d.ts +2 -3
- package/dist/generated/abi/DATVotesImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPPerformanceImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRegistryImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRegistryTreasuryImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRewardDeployerImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRewardSwapImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRootImplementation.d.ts +1 -3
- package/dist/generated/abi/DLPTreasuryImplementation.d.ts +2 -3
- package/dist/generated/abi/DataLiquidityPoolImplementation.d.ts +1 -3
- package/dist/generated/abi/DataPortabilityGranteesImplementation.d.ts +2 -3
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.ts +2 -3
- package/dist/generated/abi/DataPortabilityServersImplementation.d.ts +2 -3
- package/dist/generated/abi/DataRefinerRegistryImplementation.d.ts +2 -3
- package/dist/generated/abi/DataRegistryImplementation.cjs +13 -0
- package/dist/generated/abi/DataRegistryImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataRegistryImplementation.d.ts +12 -3
- package/dist/generated/abi/DataRegistryImplementation.js +13 -0
- package/dist/generated/abi/DataRegistryImplementation.js.map +1 -1
- package/dist/generated/abi/QueryEngineImplementation.d.ts +2 -3
- package/dist/generated/abi/SwapHelperImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolDedicatedGpuImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolDedicatedStandardImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolEphemeralStandardImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolPersistentGpuImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolPersistentStandardImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolPhalaImplementation.d.ts +2 -3
- package/dist/generated/abi/VanaEpochImplementation.d.ts +2 -3
- package/dist/generated/abi/VanaPoolEntityImplementation.d.ts +2 -3
- package/dist/generated/abi/VanaPoolStakingImplementation.d.ts +2 -3
- package/dist/generated/abi/VanaPoolTreasuryImplementation.d.ts +2 -3
- package/dist/generated/abi/index.cjs +42 -0
- package/dist/generated/abi/index.cjs.map +1 -1
- package/dist/generated/abi/index.d.ts +47 -18
- package/dist/generated/abi/index.js +21 -0
- package/dist/generated/abi/index.js.map +1 -1
- package/dist/generated/event-types.cjs +17 -0
- package/dist/generated/event-types.cjs.map +1 -0
- package/dist/generated/event-types.d.ts +854 -0
- package/dist/generated/event-types.js +1 -0
- package/dist/generated/event-types.js.map +1 -0
- package/dist/generated/eventRegistry.cjs +3351 -0
- package/dist/generated/eventRegistry.cjs.map +1 -0
- package/dist/generated/eventRegistry.d.ts +14 -0
- package/dist/generated/eventRegistry.js +3326 -0
- package/dist/generated/eventRegistry.js.map +1 -0
- package/dist/generated/server/server-exports.d.ts +19 -21
- package/dist/generated/server/server.cjs.map +1 -1
- package/dist/generated/server/server.d.ts +113 -87
- package/dist/generated/subgraph.cjs +797 -32
- package/dist/generated/subgraph.cjs.map +1 -1
- package/dist/generated/subgraph.d.ts +464 -332
- package/dist/generated/subgraph.js +792 -32
- package/dist/generated/subgraph.js.map +1 -1
- package/dist/index.browser.d.ts +49 -73
- package/dist/index.browser.js +14 -0
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/index.node.cjs +31 -3
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.ts +223 -64
- package/dist/index.node.js +28 -2
- 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 +42 -2
- package/dist/node.js.map +1 -1
- package/dist/platform/browser-only.d.ts +5 -8
- package/dist/platform/browser-only.test.d.ts +1 -0
- package/dist/platform/browser-safe.d.ts +6 -9
- package/dist/platform/browser-safe.test.d.ts +1 -0
- package/dist/platform/browser.cjs +167 -8
- package/dist/platform/browser.cjs.map +1 -1
- package/dist/platform/browser.d.ts +235 -18
- package/dist/platform/browser.js +179 -29
- package/dist/platform/browser.js.map +1 -1
- package/dist/platform/browser.test.d.ts +1 -0
- package/dist/platform/index.d.ts +11 -5
- package/dist/platform/interface.cjs.map +1 -1
- package/dist/platform/interface.d.ts +289 -98
- package/dist/platform/node.cjs +163 -2
- package/dist/platform/node.cjs.map +1 -1
- package/dist/platform/node.d.ts +72 -13
- package/dist/platform/node.js +175 -21
- package/dist/platform/node.js.map +1 -1
- package/dist/platform/ports/openpgp-port.cjs +74 -0
- package/dist/platform/ports/openpgp-port.cjs.map +1 -0
- package/dist/platform/ports/openpgp-port.d.ts +13 -0
- package/dist/platform/ports/openpgp-port.js +59 -0
- package/dist/platform/ports/openpgp-port.js.map +1 -0
- package/dist/platform/ports/pgp-port.cjs +17 -0
- package/dist/platform/ports/pgp-port.cjs.map +1 -0
- package/dist/platform/ports/pgp-port.d.ts +35 -0
- package/dist/platform/ports/pgp-port.js +1 -0
- package/dist/platform/ports/pgp-port.js.map +1 -0
- package/dist/platform/shared/error-utils.d.ts +2 -4
- package/dist/platform/shared/pgp-utils.cjs +2 -2
- package/dist/platform/shared/pgp-utils.cjs.map +1 -1
- package/dist/platform/shared/pgp-utils.d.ts +3 -5
- package/dist/platform/shared/pgp-utils.js +2 -2
- package/dist/platform/shared/pgp-utils.js.map +1 -1
- package/dist/platform/shared/stream-utils.d.ts +1 -3
- package/dist/platform/utils.d.ts +6 -10
- package/dist/platform/utils.test.d.ts +1 -0
- package/dist/platform.browser.d.ts +9 -4
- package/dist/platform.d.ts +11 -5
- package/dist/platform.node.d.ts +10 -5
- package/dist/schemas/dataSchema.schema.json +53 -0
- package/dist/schemas/grantFile.schema.json +43 -0
- package/dist/server/relayerHandler.cjs +420 -0
- package/dist/server/relayerHandler.cjs.map +1 -0
- package/dist/server/relayerHandler.d.ts +69 -0
- package/dist/server/relayerHandler.js +396 -0
- package/dist/server/relayerHandler.js.map +1 -0
- package/dist/storage/index.d.ts +56 -10
- package/dist/storage/manager.cjs +114 -31
- package/dist/storage/manager.cjs.map +1 -1
- package/dist/storage/manager.d.ts +121 -30
- package/dist/storage/manager.js +113 -37
- package/dist/storage/manager.js.map +1 -1
- package/dist/storage/providers/callback-storage.cjs +89 -18
- package/dist/storage/providers/callback-storage.cjs.map +1 -1
- package/dist/storage/providers/callback-storage.d.ts +111 -28
- package/dist/storage/providers/callback-storage.js +89 -18
- package/dist/storage/providers/callback-storage.js.map +1 -1
- package/dist/storage/providers/google-drive.cjs +2 -2
- package/dist/storage/providers/google-drive.cjs.map +1 -1
- package/dist/storage/providers/google-drive.d.ts +3 -7
- package/dist/storage/providers/google-drive.js +4 -7
- package/dist/storage/providers/google-drive.js.map +1 -1
- package/dist/storage/providers/google-drive.test.d.ts +1 -0
- package/dist/storage/providers/ipfs.cjs +5 -5
- package/dist/storage/providers/ipfs.cjs.map +1 -1
- package/dist/storage/providers/ipfs.d.ts +3 -6
- package/dist/storage/providers/ipfs.js +7 -10
- package/dist/storage/providers/ipfs.js.map +1 -1
- package/dist/storage/providers/pinata.cjs +6 -6
- package/dist/storage/providers/pinata.cjs.map +1 -1
- package/dist/storage/providers/pinata.d.ts +17 -22
- package/dist/storage/providers/pinata.js +8 -11
- package/dist/storage/providers/pinata.js.map +1 -1
- package/dist/storage/tests/callbackStorage.test.d.ts +1 -0
- package/dist/storage/tests/googleDriveStorage.test.d.ts +1 -0
- package/dist/storage/tests/ipfsStorage.test.d.ts +1 -0
- package/dist/storage/tests/pinataStorage.test.d.ts +1 -0
- package/dist/storage/tests/storageManager.test.d.ts +1 -0
- package/dist/tests/abi.test.d.ts +1 -0
- package/dist/tests/chains-definitions.test.d.ts +1 -0
- package/dist/tests/core-encryption.test.d.ts +1 -0
- package/dist/tests/core-extended.test.d.ts +1 -0
- package/dist/tests/core-generics-coverage.test.d.ts +1 -0
- package/dist/tests/coverage-boost.test.d.ts +1 -0
- package/dist/tests/crypto-cross-platform-compatibility.test.d.ts +1 -0
- package/dist/tests/data-addfile-permissions-schema.test.d.ts +1 -0
- package/dist/tests/data-additional-methods.test.d.ts +1 -0
- package/dist/tests/data-controller-edge-cases.test.d.ts +1 -0
- package/dist/tests/data-ipfs-gateways.test.d.ts +1 -0
- package/dist/tests/data-relayer.test.d.ts +1 -0
- package/dist/tests/data-schema-validation.test.d.ts +1 -0
- package/dist/tests/data-simple-methods.test.d.ts +1 -0
- package/dist/tests/data.test.d.ts +1 -0
- package/dist/tests/demo-integration.test.d.ts +1 -0
- package/dist/tests/demo-trusted-server-integration.test.d.ts +1 -0
- package/dist/tests/download-relayer.test.d.ts +1 -0
- package/dist/tests/dual-mode-permissions.test.d.ts +1 -0
- package/dist/tests/dual-mode-trusted-servers.test.d.ts +1 -0
- package/dist/tests/encryption-correct-implementation.test.d.ts +1 -0
- package/dist/tests/encryption-coverage.test.d.ts +1 -0
- package/dist/tests/encryption-edge-cases.test.d.ts +1 -0
- package/dist/tests/encryption-utils-updated.test.d.ts +1 -0
- package/dist/tests/errors-coverage.test.d.ts +1 -0
- package/dist/tests/errors.test.d.ts +1 -0
- package/dist/tests/factories/mockFactory.d.ts +316 -0
- package/dist/tests/fakes/FakeStorageManager.d.ts +200 -0
- package/dist/tests/fakes/FakeStorageManager.test.d.ts +1 -0
- package/dist/tests/fakes/FakeWaitForTransactionEvents.d.ts +170 -0
- package/dist/tests/fakes/FakeWaitForTransactionEvents.test.d.ts +1 -0
- package/dist/tests/fakes/fake-pgp-port.d.ts +13 -0
- package/dist/tests/grantValidation-edge-cases.test.d.ts +1 -0
- package/dist/tests/grantValidation-unreachable-branch.test.d.ts +1 -0
- package/dist/tests/helper-methods.test.d.ts +1 -0
- package/dist/tests/helpers/platformTestHelpers.d.ts +106 -0
- package/dist/tests/helpers/typedMocks.d.ts +64 -0
- package/dist/tests/index-browser.test.d.ts +1 -0
- package/dist/tests/index-node.test.d.ts +1 -0
- package/dist/tests/index.test.d.ts +1 -0
- package/dist/tests/mocks/platformAdapter.d.ts +12 -0
- package/dist/tests/new-permissions-methods.test.d.ts +1 -0
- package/dist/tests/no-buffer-browser.test.d.ts +1 -0
- package/dist/tests/permissions-grantee.test.d.ts +1 -0
- package/dist/tests/permissions-revoke-relayer.test.d.ts +1 -0
- package/dist/tests/permissions-schema-validation.test.d.ts +1 -0
- package/dist/tests/permissions-server-files.test.d.ts +1 -0
- package/dist/tests/permissions-transaction-options.test.d.ts +1 -0
- package/dist/tests/permissions-trust-servers.test.d.ts +1 -0
- package/dist/tests/permissions.test.d.ts +1 -0
- package/dist/tests/personal.test.d.ts +1 -0
- package/dist/tests/platform-browser.test.d.ts +1 -0
- package/dist/tests/platform-crypto-expanded.test.d.ts +1 -0
- package/dist/tests/platform-crypto.test.d.ts +1 -0
- package/dist/tests/platform-index.test.d.ts +1 -0
- package/dist/tests/platform-node.test.d.ts +1 -0
- package/dist/tests/platform-shared-utils.test.d.ts +1 -0
- package/dist/tests/platform-updated.test.d.ts +1 -0
- package/dist/tests/protocol-additional-methods.test.d.ts +1 -0
- package/dist/tests/protocol.test.d.ts +1 -0
- package/dist/tests/read-only-mode.test.d.ts +1 -0
- package/dist/tests/relayer-integration.test.d.ts +1 -0
- package/dist/tests/relayer-unified.test.d.ts +1 -0
- package/dist/tests/schemas.test.d.ts +1 -0
- package/dist/tests/server-relayer-handler.test.d.ts +1 -0
- package/dist/tests/setup.d.ts +7 -0
- package/dist/tests/signatureFormatter.test.d.ts +1 -0
- package/dist/tests/trusted-server-queries.test.d.ts +1 -0
- package/dist/tests/typedDataConverter.test.d.ts +1 -0
- package/dist/tests/types-contracts.test.d.ts +1 -0
- package/dist/tests/types-data.test.d.ts +1 -0
- package/dist/tests/types-external-apis.test.d.ts +1 -0
- package/dist/tests/types-generics.test.d.ts +1 -0
- package/dist/tests/types-permissions.test.d.ts +1 -0
- package/dist/tests/types-upload-params.test.d.ts +1 -0
- package/dist/tests/types.test.d.ts +1 -0
- package/dist/tests/utils-formatters.test.d.ts +1 -0
- package/dist/tests/utils-grantFiles-edge-cases.test.d.ts +1 -0
- package/dist/tests/utils-grantFiles-validation.test.d.ts +1 -0
- package/dist/tests/utils-grantFiles.test.d.ts +1 -0
- package/dist/tests/utils-grantValidation-consolidated.test.d.ts +1 -0
- package/dist/tests/utils-grants.test.d.ts +1 -0
- package/dist/tests/utils-ipfs-additional.test.d.ts +1 -0
- package/dist/tests/utils-ipfs.test.d.ts +4 -0
- package/dist/tests/utils-schemaValidation.test.d.ts +1 -0
- package/dist/tests/vana.test.d.ts +1 -0
- package/dist/tests/wallet-crypto-compatibility.test.d.ts +1 -0
- package/dist/{chains.browser.cjs → types/atomicStore.cjs} +9 -15
- 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 +17 -0
- package/dist/types/blockchain.cjs.map +1 -0
- package/dist/types/blockchain.d.ts +85 -0
- package/dist/types/blockchain.js +1 -0
- package/dist/types/blockchain.js.map +1 -0
- package/dist/types/chains-additional.test.d.ts +1 -0
- package/dist/types/chains.cjs.map +1 -1
- package/dist/types/chains.d.ts +80 -16
- package/dist/types/chains.js.map +1 -1
- package/dist/types/config.cjs +10 -0
- package/dist/types/config.cjs.map +1 -1
- package/dist/types/config.d.ts +236 -242
- package/dist/types/config.js +8 -0
- package/dist/types/config.js.map +1 -1
- package/dist/types/contracts.cjs.map +1 -1
- package/dist/types/contracts.d.ts +79 -18
- package/dist/types/controller-context.cjs +17 -0
- package/dist/types/controller-context.cjs.map +1 -0
- package/dist/types/controller-context.d.ts +68 -0
- package/dist/types/controller-context.js +1 -0
- package/dist/types/controller-context.js.map +1 -0
- package/dist/types/data.cjs.map +1 -1
- package/dist/types/data.d.ts +118 -49
- package/dist/types/external-apis.d.ts +10 -12
- package/dist/types/generics.cjs.map +1 -1
- package/dist/types/generics.d.ts +116 -48
- package/dist/types/index.cjs +5 -4
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.ts +48 -34
- package/dist/types/index.js +9 -2
- 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 +2 -2
- package/dist/types/operations.cjs.map +1 -1
- package/dist/types/operations.d.ts +164 -42
- package/dist/types/operations.js +2 -2
- 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 +72 -78
- package/dist/types/personal.cjs.map +1 -1
- package/dist/types/personal.d.ts +137 -22
- package/dist/types/relayer.cjs.map +1 -1
- package/dist/types/relayer.d.ts +293 -50
- package/dist/types/storage.cjs.map +1 -1
- package/dist/types/storage.d.ts +15 -29
- package/dist/types/storage.js +2 -5
- package/dist/types/storage.js.map +1 -1
- package/dist/types/transactionResults.cjs.map +1 -1
- package/dist/types/transactionResults.d.ts +193 -25
- package/dist/types/utils.cjs.map +1 -1
- package/dist/types/utils.d.ts +20 -68
- package/dist/types.d.ts +4 -40
- package/dist/utils/__tests__/parseTransaction.test.d.ts +1 -0
- package/dist/utils/__tests__/pojo-serialization.test.d.ts +1 -0
- package/dist/utils/__tests__/signatureCache.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/__tests__/transaction-edge-cases.test.d.ts +1 -0
- package/dist/utils/__tests__/transactionHelpers.test.d.ts +1 -0
- package/dist/utils/__tests__/urlResolver.test.d.ts +4 -0
- package/dist/utils/blockchain/registry.cjs +2 -2
- package/dist/utils/blockchain/registry.cjs.map +1 -1
- package/dist/utils/blockchain/registry.d.ts +6 -8
- package/dist/utils/blockchain/registry.js +2 -2
- package/dist/utils/blockchain/registry.js.map +1 -1
- package/dist/utils/blockchain/registry.test.d.ts +1 -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/crypto-utils.cjs +0 -12
- package/dist/utils/crypto-utils.cjs.map +1 -1
- package/dist/utils/crypto-utils.d.ts +9 -27
- package/dist/utils/crypto-utils.js +0 -11
- package/dist/utils/crypto-utils.js.map +1 -1
- package/dist/utils/crypto-utils.test.d.ts +1 -0
- package/dist/utils/download.cjs +3 -3
- package/dist/utils/download.cjs.map +1 -1
- package/dist/utils/download.d.ts +13 -14
- package/dist/utils/download.js +2 -2
- package/dist/utils/download.js.map +1 -1
- package/dist/utils/encoding.cjs +1 -1
- package/dist/utils/encoding.cjs.map +1 -1
- package/dist/utils/encoding.d.ts +4 -6
- package/dist/utils/encoding.js +1 -1
- package/dist/utils/encoding.js.map +1 -1
- package/dist/utils/encoding.test.d.ts +1 -0
- package/dist/utils/encryption.cjs +16 -10
- package/dist/utils/encryption.cjs.map +1 -1
- package/dist/utils/encryption.d.ts +13 -17
- package/dist/utils/encryption.js +16 -10
- package/dist/utils/encryption.js.map +1 -1
- package/dist/utils/formatters.cjs +4 -2
- package/dist/utils/formatters.cjs.map +1 -1
- package/dist/utils/formatters.d.ts +4 -6
- package/dist/utils/formatters.js +4 -2
- package/dist/utils/formatters.js.map +1 -1
- package/dist/utils/grantFiles.cjs +7 -4
- package/dist/utils/grantFiles.cjs.map +1 -1
- package/dist/utils/grantFiles.d.ts +16 -30
- package/dist/utils/grantFiles.js +7 -4
- package/dist/utils/grantFiles.js.map +1 -1
- package/dist/utils/grantValidation.cjs +1 -1
- package/dist/utils/grantValidation.cjs.map +1 -1
- package/dist/utils/grantValidation.d.ts +109 -33
- package/dist/utils/grantValidation.js +1 -1
- package/dist/utils/grantValidation.js.map +1 -1
- package/dist/utils/grants.cjs +1 -1
- package/dist/utils/grants.cjs.map +1 -1
- package/dist/utils/grants.d.ts +101 -23
- package/dist/utils/grants.js +1 -1
- 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 +8 -10
- package/dist/utils/ipfs.js +2 -4
- package/dist/utils/ipfs.js.map +1 -1
- package/dist/utils/lazy-import.cjs +4 -6
- package/dist/utils/lazy-import.cjs.map +1 -1
- package/dist/utils/lazy-import.d.ts +33 -10
- package/dist/utils/lazy-import.js +4 -6
- package/dist/utils/lazy-import.js.map +1 -1
- package/dist/utils/multicall.cjs +4 -2
- package/dist/utils/multicall.cjs.map +1 -1
- package/dist/utils/multicall.d.ts +5 -8
- package/dist/utils/multicall.js +4 -2
- package/dist/utils/multicall.js.map +1 -1
- package/dist/utils/parseTransactionPojo.cjs +87 -0
- package/dist/utils/parseTransactionPojo.cjs.map +1 -0
- package/dist/utils/parseTransactionPojo.d.ts +31 -0
- package/dist/utils/parseTransactionPojo.js +63 -0
- package/dist/utils/parseTransactionPojo.js.map +1 -0
- package/dist/utils/schemaValidation.cjs +5 -5
- package/dist/utils/schemaValidation.cjs.map +1 -1
- package/dist/utils/schemaValidation.d.ts +8 -12
- package/dist/utils/schemaValidation.js +7 -10
- package/dist/utils/schemaValidation.js.map +1 -1
- package/dist/utils/signatureCache.cjs +9 -4
- package/dist/utils/signatureCache.cjs.map +1 -1
- package/dist/utils/signatureCache.d.ts +53 -15
- package/dist/utils/signatureCache.js +12 -10
- package/dist/utils/signatureCache.js.map +1 -1
- package/dist/utils/signatureFormatter.cjs +6 -9
- package/dist/utils/signatureFormatter.cjs.map +1 -1
- package/dist/utils/signatureFormatter.d.ts +2 -5
- package/dist/utils/signatureFormatter.js +6 -9
- package/dist/utils/signatureFormatter.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/tests/multicall.test.d.ts +1 -0
- package/dist/utils/transactionHelpers.cjs +54 -0
- package/dist/utils/transactionHelpers.cjs.map +1 -0
- package/dist/utils/transactionHelpers.d.ts +80 -0
- package/dist/utils/transactionHelpers.js +29 -0
- package/dist/utils/transactionHelpers.js.map +1 -0
- package/dist/utils/typeGuards.cjs +109 -0
- package/dist/utils/typeGuards.cjs.map +1 -0
- package/dist/utils/typeGuards.d.ts +138 -0
- package/dist/utils/typeGuards.js +74 -0
- package/dist/utils/typeGuards.js.map +1 -0
- package/dist/utils/typedDataConverter.cjs.map +1 -1
- package/dist/utils/typedDataConverter.d.ts +42 -9
- package/dist/utils/typedDataConverter.js.map +1 -1
- package/dist/utils/urlResolver.cjs +8 -1
- package/dist/utils/urlResolver.cjs.map +1 -1
- package/dist/utils/urlResolver.d.ts +24 -8
- package/dist/utils/urlResolver.js +9 -2
- package/dist/utils/urlResolver.js.map +1 -1
- package/dist/utils/wallet.cjs +63 -0
- package/dist/utils/wallet.cjs.map +1 -0
- package/dist/utils/wallet.d.ts +94 -0
- package/dist/utils/wallet.js +37 -0
- package/dist/utils/wallet.js.map +1 -0
- package/dist/utils/withEvents.cjs +44 -0
- package/dist/utils/withEvents.cjs.map +1 -0
- package/dist/utils/withEvents.d.ts +56 -0
- package/dist/utils/withEvents.js +18 -0
- package/dist/utils/withEvents.js.map +1 -0
- package/package.json +25 -13
- package/dist/browser.d.cts +0 -2
- package/dist/chains/definitions.d.cts +0 -53
- package/dist/chains/index.d.cts +0 -2
- package/dist/chains.browser.cjs.map +0 -1
- package/dist/chains.browser.d.cts +0 -2
- package/dist/chains.d.cts +0 -2
- package/dist/chains.node.d.cts +0 -2
- package/dist/config/addresses.d.cts +0 -380
- package/dist/config/chains.d.cts +0 -85
- package/dist/config/eventMappings.cjs +0 -114
- package/dist/config/eventMappings.cjs.map +0 -1
- package/dist/config/eventMappings.d.cts +0 -108
- package/dist/config/eventMappings.d.ts +0 -108
- package/dist/config/eventMappings.js +0 -90
- package/dist/config/eventMappings.js.map +0 -1
- package/dist/config/features.d.cts +0 -64
- package/dist/contracts/contractController.d.cts +0 -96
- package/dist/controllers/data.d.cts +0 -941
- package/dist/controllers/permissions.d.cts +0 -25
- package/dist/controllers/protocol.d.cts +0 -167
- package/dist/controllers/schemas.d.cts +0 -272
- package/dist/controllers/server.d.cts +0 -243
- package/dist/core/apiClient.d.cts +0 -165
- package/dist/core/client.d.cts +0 -92
- package/dist/core/generics.d.cts +0 -120
- package/dist/core.d.cts +0 -466
- package/dist/crypto/ecies/__tests__/test-vectors.d.cts +0 -40
- package/dist/crypto/ecies/base.d.cts +0 -143
- package/dist/crypto/ecies/browser.d.cts +0 -48
- package/dist/crypto/ecies/constants.d.cts +0 -122
- package/dist/crypto/ecies/index.d.cts +0 -1
- package/dist/crypto/ecies/interface.d.cts +0 -176
- package/dist/crypto/ecies/node.d.cts +0 -50
- package/dist/crypto/ecies/utils.d.cts +0 -67
- package/dist/crypto/services/WalletKeyEncryptionService.d.cts +0 -92
- package/dist/diagnostics.d.cts +0 -26
- package/dist/errors.d.cts +0 -350
- package/dist/generated/abi/ComputeEngineImplementation.d.cts +0 -996
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.d.cts +0 -545
- package/dist/generated/abi/DATFactoryImplementation.d.cts +0 -661
- package/dist/generated/abi/DATImplementation.d.cts +0 -693
- package/dist/generated/abi/DATPausableImplementation.d.cts +0 -1145
- package/dist/generated/abi/DATVotesImplementation.d.cts +0 -1095
- package/dist/generated/abi/DLPPerformanceImplementation.d.cts +0 -883
- package/dist/generated/abi/DLPRegistryImplementation.d.cts +0 -1123
- package/dist/generated/abi/DLPRegistryTreasuryImplementation.d.cts +0 -452
- package/dist/generated/abi/DLPRewardDeployerImplementation.d.cts +0 -714
- package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.d.cts +0 -452
- package/dist/generated/abi/DLPRewardSwapImplementation.d.cts +0 -706
- package/dist/generated/abi/DLPRootImplementation.d.cts +0 -1248
- package/dist/generated/abi/DLPTreasuryImplementation.d.cts +0 -452
- package/dist/generated/abi/DataLiquidityPoolImplementation.d.cts +0 -737
- package/dist/generated/abi/DataPortabilityGranteesImplementation.d.cts +0 -661
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.cts +0 -989
- package/dist/generated/abi/DataPortabilityServersImplementation.d.cts +0 -1086
- package/dist/generated/abi/DataRefinerRegistryImplementation.d.cts +0 -737
- package/dist/generated/abi/DataRegistryImplementation.d.cts +0 -1004
- package/dist/generated/abi/QueryEngineImplementation.d.cts +0 -1001
- package/dist/generated/abi/SwapHelperImplementation.d.cts +0 -764
- package/dist/generated/abi/TeePoolDedicatedGpuImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolDedicatedStandardImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolEphemeralStandardImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolImplementation.d.cts +0 -993
- package/dist/generated/abi/TeePoolPersistentGpuImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolPersistentStandardImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolPhalaImplementation.d.cts +0 -993
- package/dist/generated/abi/VanaEpochImplementation.d.cts +0 -900
- package/dist/generated/abi/VanaPoolEntityImplementation.d.cts +0 -934
- package/dist/generated/abi/VanaPoolStakingImplementation.d.cts +0 -693
- package/dist/generated/abi/VanaPoolTreasuryImplementation.d.cts +0 -394
- package/dist/generated/abi/index.d.cts +0 -26516
- package/dist/generated/server/server-exports.d.cts +0 -21
- package/dist/generated/server/server.d.cts +0 -512
- package/dist/generated/subgraph.d.cts +0 -5981
- package/dist/index.browser.cjs +0 -151
- package/dist/index.browser.cjs.map +0 -1
- package/dist/index.browser.d.cts +0 -177
- package/dist/index.d.cts +0 -2
- package/dist/index.node.d.cts +0 -64
- package/dist/node.d.cts +0 -2
- package/dist/permissions-DNKPu_G0.d.cts +0 -1666
- package/dist/permissions-eo8YeLGf.d.ts +0 -1666
- package/dist/platform/browser-only.d.cts +0 -25
- package/dist/platform/browser-safe.d.cts +0 -32
- package/dist/platform/browser.d.cts +0 -74
- package/dist/platform/index.d.cts +0 -5
- package/dist/platform/interface.d.cts +0 -218
- package/dist/platform/node.d.cts +0 -27
- package/dist/platform/shared/error-utils.d.cts +0 -25
- package/dist/platform/shared/pgp-utils.d.cts +0 -61
- package/dist/platform/shared/stream-utils.d.cts +0 -16
- package/dist/platform/utils.d.cts +0 -53
- package/dist/platform.browser.cjs +0 -41
- package/dist/platform.browser.cjs.map +0 -1
- package/dist/platform.browser.d.cts +0 -4
- package/dist/platform.d.cts +0 -5
- package/dist/platform.node.d.cts +0 -5
- package/dist/server/handler.cjs +0 -101
- package/dist/server/handler.cjs.map +0 -1
- package/dist/server/handler.d.cts +0 -282
- package/dist/server/handler.d.ts +0 -282
- package/dist/server/handler.js +0 -77
- package/dist/server/handler.js.map +0 -1
- package/dist/storage/index.d.cts +0 -10
- package/dist/storage/manager.d.cts +0 -150
- package/dist/storage/providers/callback-storage.d.cts +0 -100
- package/dist/storage/providers/google-drive.d.cts +0 -156
- package/dist/storage/providers/ipfs.d.cts +0 -163
- package/dist/storage/providers/pinata.d.cts +0 -173
- package/dist/types/chains.d.cts +0 -34
- package/dist/types/config.d.cts +0 -726
- package/dist/types/contracts.d.cts +0 -68
- package/dist/types/data.d.cts +0 -694
- package/dist/types/eccrypto-js.d.d.cts +0 -13
- package/dist/types/eccrypto-js.d.d.ts +0 -13
- package/dist/types/external-apis.d.cts +0 -186
- package/dist/types/generics.d.cts +0 -450
- package/dist/types/index.d.cts +0 -34
- package/dist/types/operations.d.cts +0 -108
- package/dist/types/permissions.d.cts +0 -957
- package/dist/types/personal.d.cts +0 -40
- package/dist/types/relayer.d.cts +0 -284
- package/dist/types/storage.d.cts +0 -131
- package/dist/types/transactionResults.d.cts +0 -25
- package/dist/types/utils.d.cts +0 -819
- package/dist/types.d.cts +0 -66
- package/dist/utils/blockchain/registry.d.cts +0 -34
- package/dist/utils/crypto-utils.d.cts +0 -118
- package/dist/utils/download.d.cts +0 -41
- package/dist/utils/encoding.d.cts +0 -54
- package/dist/utils/encryption.d.cts +0 -275
- package/dist/utils/eventParsing.cjs +0 -111
- package/dist/utils/eventParsing.cjs.map +0 -1
- package/dist/utils/eventParsing.d.cts +0 -60
- package/dist/utils/eventParsing.d.ts +0 -60
- package/dist/utils/eventParsing.js +0 -86
- package/dist/utils/eventParsing.js.map +0 -1
- package/dist/utils/formatters.d.cts +0 -120
- package/dist/utils/grantFiles.d.cts +0 -186
- package/dist/utils/grantValidation.d.cts +0 -150
- package/dist/utils/grants.d.cts +0 -70
- package/dist/utils/ipfs.d.cts +0 -90
- package/dist/utils/lazy-import.d.cts +0 -20
- package/dist/utils/multicall.d.cts +0 -129
- package/dist/utils/schemaValidation.d.cts +0 -172
- package/dist/utils/signatureCache.d.cts +0 -134
- package/dist/utils/signatureFormatter.d.cts +0 -39
- package/dist/utils/transactionParsing.cjs +0 -84
- package/dist/utils/transactionParsing.cjs.map +0 -1
- package/dist/utils/transactionParsing.d.cts +0 -25
- package/dist/utils/transactionParsing.d.ts +0 -25
- package/dist/utils/transactionParsing.js +0 -62
- package/dist/utils/transactionParsing.js.map +0 -1
- package/dist/utils/typedDataConverter.d.cts +0 -13
- package/dist/utils/urlResolver.d.cts +0 -40
package/dist/controllers/data.js
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
import { getContract } from "viem";
|
|
2
|
+
import { PollingManager } from "../core/pollingManager";
|
|
3
|
+
import { BaseController } from "./base";
|
|
2
4
|
import { getContractAddress } from "../config/addresses";
|
|
3
5
|
import { getAbi } from "../generated/abi";
|
|
4
6
|
import {
|
|
5
|
-
|
|
7
|
+
GetUserFilesPaginatedDocument,
|
|
6
8
|
GetFileProofsDocument,
|
|
7
9
|
GetDlpDocument,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
GetUserPermissionsPaginatedDocument,
|
|
11
|
+
GetUserTrustedServersPaginatedDocument
|
|
10
12
|
} from "../generated/subgraph";
|
|
11
13
|
import { print } from "graphql";
|
|
14
|
+
import {
|
|
15
|
+
checkSubgraphConsistency,
|
|
16
|
+
fetchSubgraphMeta
|
|
17
|
+
} from "../utils/subgraphConsistency";
|
|
18
|
+
import {
|
|
19
|
+
executePaginatedQuery,
|
|
20
|
+
mapOrderByToEnum,
|
|
21
|
+
mapOrderDirection
|
|
22
|
+
} from "../utils/subgraphPagination";
|
|
23
|
+
import {
|
|
24
|
+
getUserFilesFromChain,
|
|
25
|
+
determineDataSource
|
|
26
|
+
} from "../utils/chainQuery";
|
|
12
27
|
import {
|
|
13
28
|
generateEncryptionKey,
|
|
14
29
|
decryptBlobWithSignedKey,
|
|
@@ -23,11 +38,12 @@ import {
|
|
|
23
38
|
fetchAndValidateSchema
|
|
24
39
|
} from "../utils/schemaValidation";
|
|
25
40
|
import { gasAwareMulticall } from "../utils/multicall";
|
|
26
|
-
class DataController {
|
|
41
|
+
class DataController extends BaseController {
|
|
27
42
|
constructor(context) {
|
|
28
|
-
|
|
43
|
+
super(context);
|
|
29
44
|
}
|
|
30
45
|
async upload(params) {
|
|
46
|
+
this.assertWallet();
|
|
31
47
|
const {
|
|
32
48
|
content,
|
|
33
49
|
filename,
|
|
@@ -35,12 +51,13 @@ class DataController {
|
|
|
35
51
|
permissions = [],
|
|
36
52
|
encrypt = true,
|
|
37
53
|
providerName,
|
|
38
|
-
owner
|
|
54
|
+
owner,
|
|
55
|
+
schemaValidation = "strict"
|
|
39
56
|
} = params;
|
|
40
57
|
try {
|
|
41
58
|
let isValid = true;
|
|
42
59
|
let validationErrors = [];
|
|
43
|
-
if (schemaId !== void 0) {
|
|
60
|
+
if (schemaId !== void 0 && schemaValidation !== "skip") {
|
|
44
61
|
try {
|
|
45
62
|
const { SchemaController } = await import("./schemas");
|
|
46
63
|
const schemaController = new SchemaController(this.context);
|
|
@@ -52,15 +69,33 @@ class DataController {
|
|
|
52
69
|
} catch {
|
|
53
70
|
parsedContent = content;
|
|
54
71
|
}
|
|
72
|
+
} else if (content instanceof Blob) {
|
|
73
|
+
const text = await content.text();
|
|
74
|
+
try {
|
|
75
|
+
parsedContent = JSON.parse(text);
|
|
76
|
+
} catch {
|
|
77
|
+
parsedContent = text;
|
|
78
|
+
}
|
|
55
79
|
} else {
|
|
56
80
|
parsedContent = content;
|
|
57
81
|
}
|
|
58
82
|
validateDataAgainstSchema(parsedContent, schema);
|
|
59
83
|
} catch (error) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
84
|
+
if (schemaValidation === "strict") {
|
|
85
|
+
throw error;
|
|
86
|
+
} else if (schemaValidation === "warn") {
|
|
87
|
+
console.warn(
|
|
88
|
+
'[Vana SDK] Schema validation failed, but continuing due to validation mode "warn"'
|
|
89
|
+
);
|
|
90
|
+
if (error instanceof Error) {
|
|
91
|
+
console.warn(" Validation error:", error.message);
|
|
92
|
+
if (typeof error === "object" && "errors" in error && Array.isArray(error.errors)) {
|
|
93
|
+
console.warn(" Detailed errors:", error.errors);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
isValid = false;
|
|
97
|
+
validationErrors = error instanceof Error ? [error.message] : ["Schema validation failed"];
|
|
98
|
+
}
|
|
64
99
|
}
|
|
65
100
|
}
|
|
66
101
|
const uploadResult = await this.uploadToStorage(
|
|
@@ -69,9 +104,10 @@ class DataController {
|
|
|
69
104
|
encrypt,
|
|
70
105
|
providerName
|
|
71
106
|
);
|
|
72
|
-
const userAddress = owner
|
|
107
|
+
const userAddress = owner ?? this.context.userAddress;
|
|
73
108
|
let encryptedPermissions = [];
|
|
74
109
|
if (permissions.length > 0 && encrypt) {
|
|
110
|
+
this.assertWallet();
|
|
75
111
|
const userEncryptionKey = await generateEncryptionKey(
|
|
76
112
|
this.context.walletClient,
|
|
77
113
|
this.context.platform,
|
|
@@ -92,34 +128,54 @@ class DataController {
|
|
|
92
128
|
);
|
|
93
129
|
}
|
|
94
130
|
let result;
|
|
95
|
-
if (this.context.
|
|
96
|
-
|
|
97
|
-
|
|
131
|
+
if (this.context.relayer) {
|
|
132
|
+
const request = {
|
|
133
|
+
type: "direct",
|
|
134
|
+
operation: "submitFileAdditionComplete",
|
|
135
|
+
params: {
|
|
98
136
|
url: uploadResult.url,
|
|
99
137
|
userAddress,
|
|
100
138
|
permissions: encryptedPermissions,
|
|
101
|
-
schemaId: schemaId
|
|
139
|
+
schemaId: schemaId ?? 0,
|
|
102
140
|
ownerAddress: owner
|
|
103
141
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
142
|
+
};
|
|
143
|
+
const response = await this.context.relayer(request);
|
|
144
|
+
if (response.type === "error") {
|
|
145
|
+
throw new Error(response.error);
|
|
146
|
+
}
|
|
147
|
+
if (response.type === "pending") {
|
|
148
|
+
result = await this.pollRelayerForConfirmation(
|
|
149
|
+
response.operationId,
|
|
150
|
+
void 0
|
|
151
|
+
// TODO: Add TransactionOptions to upload method signature
|
|
110
152
|
);
|
|
153
|
+
} else if (response.type === "direct" && typeof response.result === "object" && response.result !== null && "fileId" in response.result) {
|
|
154
|
+
result = response.result;
|
|
155
|
+
} else {
|
|
156
|
+
throw new Error("Invalid response from relayer");
|
|
111
157
|
}
|
|
112
|
-
result = await this.context.relayerCallbacks.submitFileAddition(
|
|
113
|
-
uploadResult.url,
|
|
114
|
-
userAddress
|
|
115
|
-
);
|
|
116
158
|
} else {
|
|
117
|
-
|
|
159
|
+
const txResult = await this.addFileWithEncryptedPermissionsAndSchema(
|
|
118
160
|
uploadResult.url,
|
|
119
161
|
userAddress,
|
|
120
162
|
encryptedPermissions,
|
|
121
|
-
schemaId
|
|
163
|
+
schemaId ?? 0
|
|
122
164
|
);
|
|
165
|
+
if (!this.context.waitForTransactionEvents) {
|
|
166
|
+
throw new Error(
|
|
167
|
+
"Cannot upload without relay: waitForTransactionEvents not configured"
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
const eventResult = await this.context.waitForTransactionEvents(txResult);
|
|
171
|
+
const fileAddedEvent = eventResult.expectedEvents.FileAdded;
|
|
172
|
+
if (!fileAddedEvent) {
|
|
173
|
+
throw new Error("FileAdded event not found in transaction");
|
|
174
|
+
}
|
|
175
|
+
result = {
|
|
176
|
+
fileId: Number(fileAddedEvent.fileId),
|
|
177
|
+
transactionHash: txResult.hash
|
|
178
|
+
};
|
|
123
179
|
}
|
|
124
180
|
return {
|
|
125
181
|
fileId: result.fileId,
|
|
@@ -136,35 +192,110 @@ class DataController {
|
|
|
136
192
|
}
|
|
137
193
|
}
|
|
138
194
|
/**
|
|
139
|
-
*
|
|
195
|
+
* Encrypts data using wallet-derived encryption.
|
|
140
196
|
*
|
|
141
197
|
* @remarks
|
|
142
|
-
* This
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
* decryption.
|
|
198
|
+
* This method provides secure, wallet-based encryption for data before uploading
|
|
199
|
+
* to the Vana network. It's the counterpart to decryptFile for preparing data
|
|
200
|
+
* for secure storage.
|
|
146
201
|
*
|
|
147
202
|
* The method automatically:
|
|
148
|
-
* - Generates
|
|
149
|
-
* -
|
|
150
|
-
* -
|
|
151
|
-
* -
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
* @param
|
|
158
|
-
* @
|
|
159
|
-
* @
|
|
160
|
-
* @
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
203
|
+
* - Generates an encryption key from the user's wallet signature
|
|
204
|
+
* - Converts the input data to a Blob if necessary
|
|
205
|
+
* - Encrypts the data using the generated key
|
|
206
|
+
* - Returns both the encrypted data and the encryption key
|
|
207
|
+
*
|
|
208
|
+
* The encryption key returned can be stored and later used for decryption,
|
|
209
|
+
* or shared with others to grant them decryption access.
|
|
210
|
+
*
|
|
211
|
+
* @param data - The data to encrypt (Blob, string, or object)
|
|
212
|
+
* @param options - Optional encryption configuration
|
|
213
|
+
* @returns Promise resolving to encrypted data and the encryption key used
|
|
214
|
+
* @throws {Error} When wallet is not connected or encryption fails
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* // Encrypt a string
|
|
218
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
219
|
+
* "My secret data"
|
|
220
|
+
* );
|
|
221
|
+
*
|
|
222
|
+
* // Encrypt JSON with custom MIME type
|
|
223
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
224
|
+
* { name: "Alice", age: 30 },
|
|
225
|
+
* { mimeType: "application/json" }
|
|
226
|
+
* );
|
|
227
|
+
*
|
|
228
|
+
* // With custom encryption seed
|
|
229
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
230
|
+
* "Secret message",
|
|
231
|
+
* { seed: "My custom encryption seed" }
|
|
232
|
+
* );
|
|
233
|
+
*
|
|
234
|
+
* // Upload the encrypted data
|
|
235
|
+
* const result = await vana.data.uploadToStorage(encryptedData);
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
async encryptFile(data, options) {
|
|
239
|
+
this.assertWallet();
|
|
240
|
+
try {
|
|
241
|
+
const encryptionKey = await generateEncryptionKey(
|
|
242
|
+
this.context.walletClient,
|
|
243
|
+
this.context.platform,
|
|
244
|
+
options?.seed ?? DEFAULT_ENCRYPTION_SEED
|
|
245
|
+
);
|
|
246
|
+
let blob;
|
|
247
|
+
if (data instanceof Blob) {
|
|
248
|
+
blob = data;
|
|
249
|
+
} else if (typeof data === "string") {
|
|
250
|
+
blob = new Blob([data], { type: options?.mimeType ?? "text/plain" });
|
|
251
|
+
} else {
|
|
252
|
+
blob = new Blob([JSON.stringify(data)], {
|
|
253
|
+
type: options?.mimeType ?? "application/json"
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
const encryptedData = await encryptBlobWithSignedKey(
|
|
257
|
+
blob,
|
|
258
|
+
encryptionKey,
|
|
259
|
+
this.context.platform
|
|
260
|
+
);
|
|
261
|
+
return {
|
|
262
|
+
encryptedData,
|
|
263
|
+
encryptionKey
|
|
264
|
+
};
|
|
265
|
+
} catch (error) {
|
|
266
|
+
throw new Error(
|
|
267
|
+
`Failed to encrypt file: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Decrypts a file using wallet-derived decryption key.
|
|
273
|
+
*
|
|
274
|
+
* @remarks
|
|
275
|
+
* Counterpart to `upload()` for decrypting user files. Automatically
|
|
276
|
+
* generates decryption key from wallet, fetches encrypted content,
|
|
277
|
+
* and decrypts. Supports IPFS (with gateway fallback) and HTTP URLs.
|
|
278
|
+
*
|
|
279
|
+
* @param file - UserFile object from `getUserFiles()`
|
|
280
|
+
* @param options - Decryption options
|
|
281
|
+
* @param options.seed - Custom encryption seed.
|
|
282
|
+
* Defaults to standard Vana seed.
|
|
283
|
+
*
|
|
284
|
+
* @returns Decrypted content as Blob
|
|
285
|
+
*
|
|
286
|
+
* @throws {Error} No wallet connected.
|
|
287
|
+
* Connect wallet before decrypting.
|
|
288
|
+
* @throws {Error} Network error accessing file.
|
|
289
|
+
* Check CORS settings or server availability.
|
|
290
|
+
* @throws {Error} File not found (404).
|
|
291
|
+
* File no longer available at stored URL.
|
|
292
|
+
* @throws {Error} Access denied (403).
|
|
293
|
+
* No permission to access file.
|
|
294
|
+
* @throws {Error} Invalid file format.
|
|
295
|
+
* File not encrypted with Vana protocol.
|
|
296
|
+
* @throws {Error} Wrong encryption key.
|
|
297
|
+
* Verify seed matches upload or use default.
|
|
298
|
+
*
|
|
168
299
|
* @example
|
|
169
300
|
* ```typescript
|
|
170
301
|
* // Basic file decryption
|
|
@@ -190,12 +321,14 @@ class DataController {
|
|
|
190
321
|
* fs.writeFileSync('decrypted-file.txt', Buffer.from(buffer));
|
|
191
322
|
* ```
|
|
192
323
|
*/
|
|
193
|
-
async decryptFile(file,
|
|
324
|
+
async decryptFile(file, options) {
|
|
325
|
+
this.assertWallet();
|
|
194
326
|
try {
|
|
327
|
+
this.assertWallet();
|
|
195
328
|
const encryptionKey = await generateEncryptionKey(
|
|
196
329
|
this.context.walletClient,
|
|
197
330
|
this.context.platform,
|
|
198
|
-
|
|
331
|
+
options?.seed ?? DEFAULT_ENCRYPTION_SEED
|
|
199
332
|
);
|
|
200
333
|
let encryptedBlob;
|
|
201
334
|
try {
|
|
@@ -278,99 +411,126 @@ class DataController {
|
|
|
278
411
|
}
|
|
279
412
|
}
|
|
280
413
|
/**
|
|
281
|
-
* Retrieves all
|
|
414
|
+
* Retrieves all files owned by a specific user address.
|
|
282
415
|
*
|
|
283
416
|
* @remarks
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
* @
|
|
295
|
-
*
|
|
296
|
-
* @
|
|
297
|
-
*
|
|
298
|
-
* @throws {Error}
|
|
299
|
-
*
|
|
300
|
-
* @throws {Error}
|
|
417
|
+
* Queries the Vana subgraph for files owned by the specified address.
|
|
418
|
+
* Automatically deduplicates by file ID, keeping the latest version
|
|
419
|
+
* when duplicates exist from re-indexing or chain reorganizations.
|
|
420
|
+
* Enriches results with DLP proof data when available.
|
|
421
|
+
*
|
|
422
|
+
* @param params - Query configuration
|
|
423
|
+
* @param params.owner - Wallet address of the file owner
|
|
424
|
+
* @param params.subgraphUrl - Subgraph endpoint override.
|
|
425
|
+
* Defaults to context configuration.
|
|
426
|
+
*
|
|
427
|
+
* @returns Array of UserFile objects sorted by timestamp (newest first)
|
|
428
|
+
*
|
|
429
|
+
* @throws {Error} Subgraph URL not configured.
|
|
430
|
+
* Provide `subgraphUrl` parameter or configure in Vana constructor.
|
|
431
|
+
* @throws {Error} Subgraph request failed.
|
|
432
|
+
* Check network connectivity and subgraph availability.
|
|
433
|
+
* @throws {Error} Subgraph returned errors.
|
|
434
|
+
* Review query parameters and subgraph logs.
|
|
435
|
+
*
|
|
301
436
|
* @example
|
|
302
437
|
* ```typescript
|
|
303
|
-
* // Query files for a specific user
|
|
304
438
|
* const files = await vana.data.getUserFiles({
|
|
305
|
-
* owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
|
|
439
|
+
* owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
|
|
306
440
|
* });
|
|
307
441
|
*
|
|
308
442
|
* files.forEach(file => {
|
|
309
|
-
* console.log(`File ${file.id}: ${file.url}
|
|
443
|
+
* console.log(`File ${file.id}: ${file.url}`);
|
|
444
|
+
* console.log(` Schema: ${file.schemaId}`);
|
|
445
|
+
* console.log(` DLPs: ${file.dlpIds?.join(", ") || "none"}`);
|
|
310
446
|
* });
|
|
311
447
|
* ```
|
|
312
448
|
*/
|
|
313
|
-
async getUserFiles(params) {
|
|
449
|
+
async getUserFiles(params, options) {
|
|
314
450
|
const { owner, subgraphUrl } = params;
|
|
315
|
-
|
|
451
|
+
let dataSource = options?.source === "chain" ? "chain" : "subgraph";
|
|
452
|
+
if (options?.source === "auto" || !options?.source && options?.minBlock) {
|
|
453
|
+
const endpoint2 = subgraphUrl ?? this.context.subgraphUrl;
|
|
454
|
+
const currentBlock = await this.context.publicClient.getBlockNumber();
|
|
455
|
+
let subgraphBlock;
|
|
456
|
+
if (endpoint2) {
|
|
457
|
+
try {
|
|
458
|
+
const meta = await fetchSubgraphMeta(endpoint2);
|
|
459
|
+
subgraphBlock = meta.blockNumber;
|
|
460
|
+
} catch {
|
|
461
|
+
subgraphBlock = void 0;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
dataSource = determineDataSource(
|
|
465
|
+
options?.source,
|
|
466
|
+
options?.minBlock,
|
|
467
|
+
currentBlock,
|
|
468
|
+
subgraphBlock
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
if (dataSource === "chain") {
|
|
472
|
+
const publicClient = this.context.publicClient;
|
|
473
|
+
const chainId = await publicClient.getChainId();
|
|
474
|
+
const contractAddress = getContractAddress(chainId, "DataRegistry");
|
|
475
|
+
const files = await getUserFilesFromChain(
|
|
476
|
+
publicClient,
|
|
477
|
+
contractAddress,
|
|
478
|
+
owner,
|
|
479
|
+
options?.minBlock ? BigInt(options.minBlock) : void 0
|
|
480
|
+
);
|
|
481
|
+
const limit = options?.fetchAll ? files.length : options?.limit ?? 100;
|
|
482
|
+
const offset = options?.offset ?? 0;
|
|
483
|
+
return files.slice(offset, offset + limit);
|
|
484
|
+
}
|
|
485
|
+
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
316
486
|
if (!endpoint) {
|
|
317
487
|
throw new Error(
|
|
318
488
|
"subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor."
|
|
319
489
|
);
|
|
320
490
|
}
|
|
491
|
+
if (options?.minBlock || options?.waitForSync) {
|
|
492
|
+
await checkSubgraphConsistency(endpoint, options);
|
|
493
|
+
}
|
|
321
494
|
try {
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
495
|
+
const orderByMap = {
|
|
496
|
+
id: "id",
|
|
497
|
+
addedAtBlock: "addedAtBlock",
|
|
498
|
+
addedAtTimestamp: "addedAtTimestamp",
|
|
499
|
+
url: "url",
|
|
500
|
+
schemaId: "schemaId"
|
|
501
|
+
};
|
|
502
|
+
const allFiles = await executePaginatedQuery({
|
|
503
|
+
endpoint,
|
|
504
|
+
document: GetUserFilesPaginatedDocument,
|
|
505
|
+
baseVariables: {
|
|
506
|
+
userId: owner.toLowerCase(),
|
|
507
|
+
// Subgraph requires lowercase addresses
|
|
508
|
+
orderBy: mapOrderByToEnum(
|
|
509
|
+
options?.orderBy,
|
|
510
|
+
orderByMap,
|
|
511
|
+
"addedAtBlock"
|
|
512
|
+
),
|
|
513
|
+
orderDirection: mapOrderDirection(
|
|
514
|
+
options?.orderDirection,
|
|
515
|
+
"asc",
|
|
516
|
+
"desc"
|
|
517
|
+
)
|
|
326
518
|
},
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
// Subgraph requires lowercase addresses
|
|
332
|
-
}
|
|
333
|
-
})
|
|
334
|
-
});
|
|
335
|
-
if (!response.ok) {
|
|
336
|
-
throw new Error(
|
|
337
|
-
`Subgraph request failed: ${response.status} ${response.statusText}`
|
|
338
|
-
);
|
|
339
|
-
}
|
|
340
|
-
const result = await response.json();
|
|
341
|
-
if (result.errors) {
|
|
342
|
-
throw new Error(
|
|
343
|
-
`Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
344
|
-
);
|
|
345
|
-
}
|
|
346
|
-
const user = result.data?.user;
|
|
347
|
-
if (!user || !user.files?.length) {
|
|
348
|
-
console.warn("No files found for user:", owner);
|
|
349
|
-
return [];
|
|
350
|
-
}
|
|
351
|
-
const fileMap = /* @__PURE__ */ new Map();
|
|
352
|
-
user.files.forEach((file) => {
|
|
353
|
-
const fileId = parseInt(file.id);
|
|
354
|
-
const userFile = {
|
|
355
|
-
id: fileId,
|
|
519
|
+
options,
|
|
520
|
+
extractItems: (data) => data?.user?.files,
|
|
521
|
+
transformItem: (file) => ({
|
|
522
|
+
id: parseInt(file.id),
|
|
356
523
|
url: file.url,
|
|
357
524
|
ownerAddress: file.owner.id,
|
|
358
525
|
addedAtBlock: BigInt(file.addedAtBlock),
|
|
359
526
|
schemaId: parseInt(file.schemaId),
|
|
360
527
|
addedAtTimestamp: BigInt(file.addedAtTimestamp),
|
|
361
528
|
transactionHash: file.transactionHash
|
|
362
|
-
}
|
|
363
|
-
const existing = fileMap.get(fileId);
|
|
364
|
-
if (!existing || userFile.addedAtTimestamp && existing.addedAtTimestamp && userFile.addedAtTimestamp > existing.addedAtTimestamp) {
|
|
365
|
-
fileMap.set(fileId, userFile);
|
|
366
|
-
}
|
|
529
|
+
})
|
|
367
530
|
});
|
|
368
|
-
|
|
369
|
-
(a, b) => Number((b.addedAtTimestamp || 0n) - (a.addedAtTimestamp || 0n))
|
|
370
|
-
);
|
|
371
|
-
if (userFiles.length > 0) {
|
|
531
|
+
if (allFiles.length > 0) {
|
|
372
532
|
try {
|
|
373
|
-
const fileIds =
|
|
533
|
+
const fileIds = allFiles.map((f) => f.id);
|
|
374
534
|
let proofMap;
|
|
375
535
|
try {
|
|
376
536
|
proofMap = await this._fetchProofsFromSubgraph(fileIds, endpoint);
|
|
@@ -381,7 +541,7 @@ class DataController {
|
|
|
381
541
|
);
|
|
382
542
|
proofMap = await this._fetchProofsFromChain(fileIds);
|
|
383
543
|
}
|
|
384
|
-
for (const file of
|
|
544
|
+
for (const file of allFiles) {
|
|
385
545
|
const dlpIds = proofMap.get(file.id);
|
|
386
546
|
if (dlpIds && dlpIds.length > 0) {
|
|
387
547
|
file.dlpIds = dlpIds;
|
|
@@ -391,7 +551,7 @@ class DataController {
|
|
|
391
551
|
console.warn("Failed to fetch proof data for files:", error);
|
|
392
552
|
}
|
|
393
553
|
}
|
|
394
|
-
return
|
|
554
|
+
return allFiles;
|
|
395
555
|
} catch (error) {
|
|
396
556
|
console.error("Failed to fetch user files from subgraph:", error);
|
|
397
557
|
throw new Error(
|
|
@@ -437,10 +597,11 @@ class DataController {
|
|
|
437
597
|
if (proof.dlp?.id) {
|
|
438
598
|
const fileId = parseInt(proof.fileId);
|
|
439
599
|
const dlpId = parseInt(proof.dlp.id);
|
|
440
|
-
|
|
441
|
-
|
|
600
|
+
let dlpIds = proofMap.get(fileId);
|
|
601
|
+
if (!dlpIds) {
|
|
602
|
+
dlpIds = [];
|
|
603
|
+
proofMap.set(fileId, dlpIds);
|
|
442
604
|
}
|
|
443
|
-
const dlpIds = proofMap.get(fileId);
|
|
444
605
|
if (!dlpIds.includes(dlpId)) {
|
|
445
606
|
dlpIds.push(dlpId);
|
|
446
607
|
}
|
|
@@ -458,7 +619,7 @@ class DataController {
|
|
|
458
619
|
* @returns Map of file IDs to their associated DLP IDs
|
|
459
620
|
*/
|
|
460
621
|
async _fetchProofsFromChain(fileIds) {
|
|
461
|
-
const chainId = this.context.
|
|
622
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
462
623
|
if (!chainId) {
|
|
463
624
|
throw new Error("Chain ID not available");
|
|
464
625
|
}
|
|
@@ -515,7 +676,10 @@ class DataController {
|
|
|
515
676
|
* ```
|
|
516
677
|
*/
|
|
517
678
|
async getDLP(dlpId, options = {}) {
|
|
518
|
-
const subgraphUrl = options.subgraphUrl
|
|
679
|
+
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
680
|
+
if (subgraphUrl && (options.minBlock || options.waitForSync)) {
|
|
681
|
+
await checkSubgraphConsistency(subgraphUrl, options);
|
|
682
|
+
}
|
|
519
683
|
if (subgraphUrl) {
|
|
520
684
|
try {
|
|
521
685
|
const response = await fetch(subgraphUrl, {
|
|
@@ -546,18 +710,18 @@ class DataController {
|
|
|
546
710
|
}
|
|
547
711
|
return {
|
|
548
712
|
id: parseInt(result.data.dlp.id),
|
|
549
|
-
name: result.data.dlp.name
|
|
550
|
-
metadata: result.data.dlp.metadata
|
|
713
|
+
name: result.data.dlp.name ?? "",
|
|
714
|
+
metadata: result.data.dlp.metadata ?? void 0,
|
|
551
715
|
status: result.data.dlp.status ? parseInt(result.data.dlp.status) : void 0,
|
|
552
|
-
address: result.data.dlp.address,
|
|
553
|
-
owner: result.data.dlp.owner
|
|
716
|
+
address: result.data.dlp.address ? result.data.dlp.address : void 0,
|
|
717
|
+
owner: result.data.dlp.owner ? result.data.dlp.owner : void 0
|
|
554
718
|
};
|
|
555
719
|
} catch (error) {
|
|
556
720
|
console.debug("Subgraph query failed, falling back to chain:", error);
|
|
557
721
|
}
|
|
558
722
|
}
|
|
559
723
|
try {
|
|
560
|
-
const chainId = this.context.
|
|
724
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
561
725
|
if (!chainId) {
|
|
562
726
|
throw new Error("Chain ID not available");
|
|
563
727
|
}
|
|
@@ -569,7 +733,7 @@ class DataController {
|
|
|
569
733
|
functionName: "dlps",
|
|
570
734
|
args: [BigInt(dlpId)]
|
|
571
735
|
});
|
|
572
|
-
if (!dlpData
|
|
736
|
+
if (!dlpData?.name) {
|
|
573
737
|
throw new Error(`DLP not found: ${dlpId}`);
|
|
574
738
|
}
|
|
575
739
|
return {
|
|
@@ -611,7 +775,7 @@ class DataController {
|
|
|
611
775
|
*/
|
|
612
776
|
async listDLPs(options = {}) {
|
|
613
777
|
const { limit = 100, offset = 0 } = options;
|
|
614
|
-
const subgraphUrl = options.subgraphUrl
|
|
778
|
+
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
615
779
|
if (subgraphUrl) {
|
|
616
780
|
try {
|
|
617
781
|
const query = `
|
|
@@ -650,21 +814,21 @@ class DataController {
|
|
|
650
814
|
`Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
651
815
|
);
|
|
652
816
|
}
|
|
653
|
-
const dlps = result.data?.dlps
|
|
817
|
+
const dlps = result.data?.dlps ?? [];
|
|
654
818
|
return dlps.map((dlp) => ({
|
|
655
819
|
id: parseInt(dlp.id),
|
|
656
|
-
name: dlp.name
|
|
820
|
+
name: dlp.name ?? "",
|
|
657
821
|
metadata: dlp.metadata,
|
|
658
822
|
status: dlp.status ? parseInt(dlp.status) : void 0,
|
|
659
|
-
address: dlp.address,
|
|
660
|
-
owner: dlp.owner
|
|
823
|
+
address: dlp.address ? dlp.address : void 0,
|
|
824
|
+
owner: dlp.owner ? dlp.owner : void 0
|
|
661
825
|
}));
|
|
662
826
|
} catch (error) {
|
|
663
827
|
console.debug("Subgraph query failed, falling back to chain:", error);
|
|
664
828
|
}
|
|
665
829
|
}
|
|
666
830
|
try {
|
|
667
|
-
const chainId = this.context.
|
|
831
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
668
832
|
if (!chainId) {
|
|
669
833
|
throw new Error("Chain ID not available");
|
|
670
834
|
}
|
|
@@ -734,21 +898,33 @@ class DataController {
|
|
|
734
898
|
* @returns Promise resolving to an array of permission objects
|
|
735
899
|
* @throws Error if both subgraph and RPC queries fail
|
|
736
900
|
*/
|
|
737
|
-
async getUserPermissions(params) {
|
|
901
|
+
async getUserPermissions(params, options) {
|
|
738
902
|
const { user, subgraphUrl } = params;
|
|
739
|
-
const endpoint = subgraphUrl
|
|
903
|
+
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
904
|
+
if (endpoint && (options?.minBlock || options?.waitForSync)) {
|
|
905
|
+
await checkSubgraphConsistency(endpoint, options);
|
|
906
|
+
}
|
|
740
907
|
if (endpoint) {
|
|
741
908
|
try {
|
|
742
|
-
const permissions = await this._getUserPermissionsViaSubgraph(
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
909
|
+
const permissions = await this._getUserPermissionsViaSubgraph(
|
|
910
|
+
{
|
|
911
|
+
user,
|
|
912
|
+
subgraphUrl: endpoint
|
|
913
|
+
},
|
|
914
|
+
options
|
|
915
|
+
);
|
|
746
916
|
return permissions;
|
|
747
917
|
} catch (error) {
|
|
748
918
|
console.warn("Subgraph query failed, falling back to RPC:", error);
|
|
749
919
|
}
|
|
750
920
|
}
|
|
751
|
-
|
|
921
|
+
const allPermissions = await this._getUserPermissionsViaRpc({ user });
|
|
922
|
+
if (options && !options.fetchAll) {
|
|
923
|
+
const limit = options.limit ?? 100;
|
|
924
|
+
const offset = options.offset ?? 0;
|
|
925
|
+
return allPermissions.slice(offset, offset + limit);
|
|
926
|
+
}
|
|
927
|
+
return allPermissions;
|
|
752
928
|
}
|
|
753
929
|
/**
|
|
754
930
|
* Internal method: Query user permissions via subgraph
|
|
@@ -758,46 +934,48 @@ class DataController {
|
|
|
758
934
|
* @param params.subgraphUrl - The subgraph URL endpoint to query
|
|
759
935
|
* @returns Promise resolving to an array of permission objects
|
|
760
936
|
*/
|
|
761
|
-
async _getUserPermissionsViaSubgraph(params) {
|
|
937
|
+
async _getUserPermissionsViaSubgraph(params, options) {
|
|
762
938
|
const { user, subgraphUrl } = params;
|
|
763
939
|
try {
|
|
764
|
-
const
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
940
|
+
const orderByMap = {
|
|
941
|
+
id: "id",
|
|
942
|
+
addedAtBlock: "addedAtBlock",
|
|
943
|
+
addedAtTimestamp: "addedAtTimestamp",
|
|
944
|
+
grant: "grant",
|
|
945
|
+
nonce: "nonce",
|
|
946
|
+
startBlock: "startBlock",
|
|
947
|
+
endBlock: "endBlock"
|
|
948
|
+
};
|
|
949
|
+
const permissions = await executePaginatedQuery({
|
|
950
|
+
endpoint: subgraphUrl,
|
|
951
|
+
document: GetUserPermissionsPaginatedDocument,
|
|
952
|
+
baseVariables: {
|
|
953
|
+
userId: user.toLowerCase(),
|
|
954
|
+
orderBy: mapOrderByToEnum(
|
|
955
|
+
options?.orderBy,
|
|
956
|
+
orderByMap,
|
|
957
|
+
"addedAtTimestamp"
|
|
958
|
+
),
|
|
959
|
+
orderDirection: mapOrderDirection(
|
|
960
|
+
options?.orderDirection,
|
|
961
|
+
"desc",
|
|
962
|
+
"asc"
|
|
963
|
+
)
|
|
768
964
|
},
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
965
|
+
options,
|
|
966
|
+
extractItems: (data) => data?.user?.permissions,
|
|
967
|
+
transformItem: (permission) => ({
|
|
968
|
+
id: permission.id,
|
|
969
|
+
grant: permission.grant,
|
|
970
|
+
nonce: BigInt(permission.nonce),
|
|
971
|
+
signature: permission.signature,
|
|
972
|
+
addedAtBlock: BigInt(permission.addedAtBlock),
|
|
973
|
+
addedAtTimestamp: BigInt(permission.addedAtTimestamp),
|
|
974
|
+
transactionHash: permission.transactionHash,
|
|
975
|
+
user
|
|
774
976
|
})
|
|
775
977
|
});
|
|
776
|
-
|
|
777
|
-
throw new Error(
|
|
778
|
-
`Subgraph request failed: ${response.status} ${response.statusText}`
|
|
779
|
-
);
|
|
780
|
-
}
|
|
781
|
-
const result = await response.json();
|
|
782
|
-
if (result.errors) {
|
|
783
|
-
throw new Error(
|
|
784
|
-
`Subgraph query errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
785
|
-
);
|
|
786
|
-
}
|
|
787
|
-
const userData = result.data?.user;
|
|
788
|
-
if (!userData || !userData.permissions?.length) {
|
|
789
|
-
return [];
|
|
790
|
-
}
|
|
791
|
-
return userData.permissions.map((permission) => ({
|
|
792
|
-
id: permission.id,
|
|
793
|
-
grant: permission.grant,
|
|
794
|
-
nonce: BigInt(permission.nonce),
|
|
795
|
-
signature: permission.signature,
|
|
796
|
-
addedAtBlock: BigInt(permission.addedAtBlock),
|
|
797
|
-
addedAtTimestamp: BigInt(permission.addedAtTimestamp),
|
|
798
|
-
transactionHash: permission.transactionHash,
|
|
799
|
-
user
|
|
800
|
-
})).sort((a, b) => Number(b.addedAtTimestamp - a.addedAtTimestamp));
|
|
978
|
+
return permissions;
|
|
801
979
|
} catch (error) {
|
|
802
980
|
console.error("Failed to query user permissions from subgraph:", error);
|
|
803
981
|
throw error;
|
|
@@ -813,7 +991,7 @@ class DataController {
|
|
|
813
991
|
async _getUserPermissionsViaRpc(params) {
|
|
814
992
|
const { user } = params;
|
|
815
993
|
try {
|
|
816
|
-
const chainId = this.context.
|
|
994
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
817
995
|
if (!chainId) {
|
|
818
996
|
throw new Error("Chain ID not available");
|
|
819
997
|
}
|
|
@@ -930,20 +1108,28 @@ class DataController {
|
|
|
930
1108
|
* });
|
|
931
1109
|
* ```
|
|
932
1110
|
*/
|
|
933
|
-
async getUserTrustedServers(params) {
|
|
934
|
-
const { user
|
|
935
|
-
const subgraphUrl = params.subgraphUrl
|
|
1111
|
+
async getUserTrustedServers(params, options) {
|
|
1112
|
+
const { user } = params;
|
|
1113
|
+
const subgraphUrl = params.subgraphUrl ?? this.context.subgraphUrl;
|
|
1114
|
+
if (subgraphUrl && (options?.minBlock || options?.waitForSync)) {
|
|
1115
|
+
await checkSubgraphConsistency(subgraphUrl, options);
|
|
1116
|
+
}
|
|
936
1117
|
if (subgraphUrl) {
|
|
937
1118
|
try {
|
|
938
|
-
const servers = await this._getUserTrustedServersViaSubgraph(
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
1119
|
+
const servers = await this._getUserTrustedServersViaSubgraph(
|
|
1120
|
+
{
|
|
1121
|
+
user,
|
|
1122
|
+
subgraphUrl
|
|
1123
|
+
},
|
|
1124
|
+
options
|
|
1125
|
+
);
|
|
1126
|
+
return servers;
|
|
943
1127
|
} catch (error) {
|
|
944
1128
|
console.warn("Subgraph query failed, falling back to RPC:", error);
|
|
945
1129
|
}
|
|
946
1130
|
}
|
|
1131
|
+
const limit = options?.fetchAll ? Number.MAX_SAFE_INTEGER : options?.limit ?? 100;
|
|
1132
|
+
const offset = options?.offset ?? 0;
|
|
947
1133
|
const rpcResult = await this._getUserTrustedServersViaRpc({
|
|
948
1134
|
user,
|
|
949
1135
|
limit,
|
|
@@ -959,7 +1145,7 @@ class DataController {
|
|
|
959
1145
|
* @param params.subgraphUrl - The subgraph URL endpoint to query
|
|
960
1146
|
* @returns Promise resolving to an array of trusted server objects
|
|
961
1147
|
*/
|
|
962
|
-
async _getUserTrustedServersViaSubgraph(params) {
|
|
1148
|
+
async _getUserTrustedServersViaSubgraph(params, options) {
|
|
963
1149
|
const { user, subgraphUrl } = params;
|
|
964
1150
|
const graphqlEndpoint = subgraphUrl;
|
|
965
1151
|
if (!graphqlEndpoint) {
|
|
@@ -968,42 +1154,46 @@ class DataController {
|
|
|
968
1154
|
);
|
|
969
1155
|
}
|
|
970
1156
|
try {
|
|
971
|
-
const
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
1157
|
+
const orderByMap = {
|
|
1158
|
+
id: "id",
|
|
1159
|
+
trustedAt: "trustedAt",
|
|
1160
|
+
trustedAtBlock: "trustedAtBlock",
|
|
1161
|
+
server: "server",
|
|
1162
|
+
user: "user"
|
|
1163
|
+
};
|
|
1164
|
+
const serverTrusts = await executePaginatedQuery({
|
|
1165
|
+
endpoint: graphqlEndpoint,
|
|
1166
|
+
document: GetUserTrustedServersPaginatedDocument,
|
|
1167
|
+
baseVariables: {
|
|
1168
|
+
userId: user.toLowerCase(),
|
|
1169
|
+
// Subgraph requires lowercase addresses
|
|
1170
|
+
orderBy: mapOrderByToEnum(
|
|
1171
|
+
options?.orderBy,
|
|
1172
|
+
orderByMap,
|
|
1173
|
+
"trustedAtBlock"
|
|
1174
|
+
),
|
|
1175
|
+
orderDirection: mapOrderDirection(
|
|
1176
|
+
options?.orderDirection,
|
|
1177
|
+
"desc",
|
|
1178
|
+
"asc"
|
|
1179
|
+
)
|
|
975
1180
|
},
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
1181
|
+
options,
|
|
1182
|
+
extractItems: (data) => {
|
|
1183
|
+
const trusts = data?.user?.serverTrusts ?? [];
|
|
1184
|
+
return trusts.filter((trust) => !trust.untrustedAtBlock);
|
|
1185
|
+
},
|
|
1186
|
+
transformItem: (trust) => ({
|
|
1187
|
+
id: trust.server.id,
|
|
1188
|
+
serverAddress: trust.server.serverAddress,
|
|
1189
|
+
serverUrl: trust.server.url,
|
|
1190
|
+
trustedAt: BigInt(trust.trustedAt),
|
|
1191
|
+
user,
|
|
1192
|
+
name: ""
|
|
1193
|
+
// Not available in new schema, will be empty
|
|
982
1194
|
})
|
|
983
1195
|
});
|
|
984
|
-
|
|
985
|
-
throw new Error(
|
|
986
|
-
`Subgraph request failed: ${response.status} ${response.statusText}`
|
|
987
|
-
);
|
|
988
|
-
}
|
|
989
|
-
const result = await response.json();
|
|
990
|
-
if (result.errors) {
|
|
991
|
-
throw new Error(
|
|
992
|
-
`Subgraph query errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
993
|
-
);
|
|
994
|
-
}
|
|
995
|
-
if (!result.data?.user) {
|
|
996
|
-
return [];
|
|
997
|
-
}
|
|
998
|
-
return (result.data.user.serverTrusts || []).filter((trust) => !trust.untrustedAtBlock).map((trust) => ({
|
|
999
|
-
id: trust.server.id,
|
|
1000
|
-
serverAddress: trust.server.serverAddress,
|
|
1001
|
-
serverUrl: trust.server.url,
|
|
1002
|
-
trustedAt: BigInt(trust.trustedAt),
|
|
1003
|
-
user,
|
|
1004
|
-
name: ""
|
|
1005
|
-
// Not available in new schema, will be empty
|
|
1006
|
-
}));
|
|
1196
|
+
return serverTrusts;
|
|
1007
1197
|
} catch (error) {
|
|
1008
1198
|
console.error("Failed to query trusted servers from subgraph:", error);
|
|
1009
1199
|
throw error;
|
|
@@ -1021,7 +1211,7 @@ class DataController {
|
|
|
1021
1211
|
async _getUserTrustedServersViaRpc(params) {
|
|
1022
1212
|
const { user, limit, offset } = params;
|
|
1023
1213
|
try {
|
|
1024
|
-
const chainId = this.context.
|
|
1214
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1025
1215
|
if (!chainId) {
|
|
1026
1216
|
throw new Error("Chain ID not available");
|
|
1027
1217
|
}
|
|
@@ -1105,23 +1295,31 @@ class DataController {
|
|
|
1105
1295
|
}
|
|
1106
1296
|
}
|
|
1107
1297
|
/**
|
|
1108
|
-
*
|
|
1298
|
+
* Retrieves total file count from Data Registry.
|
|
1299
|
+
*
|
|
1300
|
+
* @remarks
|
|
1301
|
+
* Queries blockchain for complete file count across all users.
|
|
1302
|
+
* Useful for pagination and network statistics.
|
|
1303
|
+
*
|
|
1304
|
+
* @returns Total number of registered files
|
|
1305
|
+
*
|
|
1306
|
+
* @throws {Error} Chain ID not available.
|
|
1307
|
+
* Ensure network connection.
|
|
1308
|
+
* @throws {Error} Contract read failed.
|
|
1309
|
+
* Check RPC availability.
|
|
1109
1310
|
*
|
|
1110
|
-
* @returns Promise resolving to the total file count
|
|
1111
1311
|
* @example
|
|
1112
1312
|
* ```typescript
|
|
1113
|
-
* const
|
|
1114
|
-
* console.log(`Total files
|
|
1313
|
+
* const total = await vana.data.getTotalFilesCount();
|
|
1314
|
+
* console.log(`Total files: ${total}`);
|
|
1115
1315
|
*
|
|
1116
|
-
* //
|
|
1117
|
-
* const
|
|
1118
|
-
* const totalPages = Math.ceil(totalFiles / filesPerPage);
|
|
1119
|
-
* console.log(`Total pages: ${totalPages}`);
|
|
1316
|
+
* // Calculate pagination
|
|
1317
|
+
* const pages = Math.ceil(total / 20);
|
|
1120
1318
|
* ```
|
|
1121
1319
|
*/
|
|
1122
1320
|
async getTotalFilesCount() {
|
|
1123
1321
|
try {
|
|
1124
|
-
const chainId = this.context.
|
|
1322
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1125
1323
|
if (!chainId) {
|
|
1126
1324
|
throw new Error("Chain ID not available");
|
|
1127
1325
|
}
|
|
@@ -1130,7 +1328,7 @@ class DataController {
|
|
|
1130
1328
|
const dataRegistry = getContract({
|
|
1131
1329
|
address: dataRegistryAddress,
|
|
1132
1330
|
abi: dataRegistryAbi,
|
|
1133
|
-
client: this.context.
|
|
1331
|
+
client: this.context.publicClient
|
|
1134
1332
|
});
|
|
1135
1333
|
const count = await dataRegistry.read.filesCount();
|
|
1136
1334
|
return Number(count);
|
|
@@ -1143,36 +1341,36 @@ class DataController {
|
|
|
1143
1341
|
}
|
|
1144
1342
|
}
|
|
1145
1343
|
/**
|
|
1146
|
-
* Retrieves
|
|
1344
|
+
* Retrieves file metadata by ID from the blockchain.
|
|
1345
|
+
*
|
|
1346
|
+
* @remarks
|
|
1347
|
+
* Queries DataRegistry contract directly for file details.
|
|
1348
|
+
* Works for any file ID regardless of ownership, enabling
|
|
1349
|
+
* cross-user file discovery and verification.
|
|
1350
|
+
*
|
|
1351
|
+
* @param fileId - Numeric file ID to retrieve
|
|
1352
|
+
*
|
|
1353
|
+
* @returns UserFile object with metadata
|
|
1354
|
+
*
|
|
1355
|
+
* @throws {Error} Chain ID not available.
|
|
1356
|
+
* Ensure proper network connection.
|
|
1357
|
+
* @throws {Error} File not found.
|
|
1358
|
+
* Verify file ID exists on-chain.
|
|
1359
|
+
* @throws {Error} Contract call failed.
|
|
1360
|
+
* Check network and RPC availability.
|
|
1147
1361
|
*
|
|
1148
|
-
* @param fileId - The file ID to look up
|
|
1149
|
-
* @returns Promise resolving to UserFile object
|
|
1150
|
-
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1151
|
-
* @throws {Error} "File not found" - When file ID doesn't exist or returns empty data
|
|
1152
|
-
* @throws {Error} "Failed to fetch file {fileId}: {error}" - General contract read failures
|
|
1153
1362
|
* @example
|
|
1154
1363
|
* ```typescript
|
|
1155
|
-
*
|
|
1156
|
-
*
|
|
1157
|
-
*
|
|
1158
|
-
*
|
|
1159
|
-
*
|
|
1160
|
-
* owner: file.ownerAddress,
|
|
1161
|
-
* addedAt: file.addedAtBlock
|
|
1162
|
-
* });
|
|
1163
|
-
* } catch (error) {
|
|
1164
|
-
* console.error('File not found or error retrieving file:', error);
|
|
1165
|
-
* }
|
|
1364
|
+
* const file = await vana.data.getFileById(123);
|
|
1365
|
+
* console.log(`File ${file.id}:`);
|
|
1366
|
+
* console.log(` URL: ${file.url}`);
|
|
1367
|
+
* console.log(` Owner: ${file.ownerAddress}`);
|
|
1368
|
+
* console.log(` Block: ${file.addedAtBlock}`);
|
|
1166
1369
|
* ```
|
|
1167
|
-
*
|
|
1168
|
-
* This method queries the DataRegistry contract directly
|
|
1169
|
-
* to get file details for any file ID, regardless of user ownership.
|
|
1170
|
-
* This is useful for file lookup functionality where users can search
|
|
1171
|
-
* for specific files by ID.
|
|
1172
1370
|
*/
|
|
1173
1371
|
async getFileById(fileId) {
|
|
1174
1372
|
try {
|
|
1175
|
-
const chainId = this.context.
|
|
1373
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1176
1374
|
if (!chainId) {
|
|
1177
1375
|
throw new Error("Chain ID not available");
|
|
1178
1376
|
}
|
|
@@ -1181,7 +1379,7 @@ class DataController {
|
|
|
1181
1379
|
const dataRegistry = getContract({
|
|
1182
1380
|
address: dataRegistryAddress,
|
|
1183
1381
|
abi: dataRegistryAbi,
|
|
1184
|
-
client: this.context.
|
|
1382
|
+
client: this.context.publicClient
|
|
1185
1383
|
});
|
|
1186
1384
|
const fileDetails = await dataRegistry.read.files([BigInt(fileId)]);
|
|
1187
1385
|
if (!fileDetails) {
|
|
@@ -1239,35 +1437,34 @@ class DataController {
|
|
|
1239
1437
|
* console.log(`File ${fileId} registered with schema in tx ${transactionHash}`);
|
|
1240
1438
|
* ```
|
|
1241
1439
|
*/
|
|
1242
|
-
async registerFileWithSchema(url, schemaId) {
|
|
1440
|
+
async registerFileWithSchema(url, schemaId, options) {
|
|
1441
|
+
this.assertWallet();
|
|
1243
1442
|
try {
|
|
1244
|
-
const chainId = this.context.
|
|
1443
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1245
1444
|
if (!chainId) {
|
|
1246
1445
|
throw new Error("Chain ID not available");
|
|
1247
1446
|
}
|
|
1447
|
+
this.assertWallet();
|
|
1248
1448
|
const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
|
|
1249
1449
|
const dataRegistryAbi = getAbi("DataRegistry");
|
|
1250
|
-
const
|
|
1251
|
-
const
|
|
1450
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1451
|
+
const from = typeof account === "string" ? account : account.address;
|
|
1452
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1252
1453
|
address: dataRegistryAddress,
|
|
1253
1454
|
abi: dataRegistryAbi,
|
|
1254
1455
|
functionName: "addFileWithSchema",
|
|
1255
1456
|
args: [url, BigInt(schemaId)],
|
|
1256
|
-
account
|
|
1257
|
-
chain: this.context.walletClient.chain
|
|
1457
|
+
account,
|
|
1458
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1459
|
+
...this.spreadTransactionOptions(options)
|
|
1460
|
+
});
|
|
1461
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
1462
|
+
return tx({
|
|
1463
|
+
hash,
|
|
1464
|
+
from,
|
|
1465
|
+
contract: "DataRegistry",
|
|
1466
|
+
fn: "addFileWithSchema"
|
|
1258
1467
|
});
|
|
1259
|
-
const receipt = await this.context.publicClient.waitForTransactionReceipt(
|
|
1260
|
-
{
|
|
1261
|
-
hash: txHash,
|
|
1262
|
-
confirmations: 1
|
|
1263
|
-
}
|
|
1264
|
-
);
|
|
1265
|
-
const { parseFileAddedEvent } = await import("../utils/eventParsing");
|
|
1266
|
-
const eventData = parseFileAddedEvent(receipt);
|
|
1267
|
-
return {
|
|
1268
|
-
fileId: Number(eventData.fileId),
|
|
1269
|
-
transactionHash: txHash
|
|
1270
|
-
};
|
|
1271
1468
|
} catch (error) {
|
|
1272
1469
|
console.error("Failed to register file with schema:", error);
|
|
1273
1470
|
throw new Error(
|
|
@@ -1281,13 +1478,6 @@ class DataController {
|
|
|
1281
1478
|
* @returns Promise resolving to the user's wallet address
|
|
1282
1479
|
* @throws {Error} When no addresses are available in wallet client
|
|
1283
1480
|
*/
|
|
1284
|
-
async getUserAddress() {
|
|
1285
|
-
const addresses = await this.context.walletClient.getAddresses();
|
|
1286
|
-
if (addresses.length === 0) {
|
|
1287
|
-
throw new Error("No addresses available in wallet client");
|
|
1288
|
-
}
|
|
1289
|
-
return addresses[0];
|
|
1290
|
-
}
|
|
1291
1481
|
/**
|
|
1292
1482
|
* Adds a file with permissions to the DataRegistry contract.
|
|
1293
1483
|
*
|
|
@@ -1304,34 +1494,34 @@ class DataController {
|
|
|
1304
1494
|
* with specific permissions on the DataRegistry contract. It can be used
|
|
1305
1495
|
* by both direct transactions and relayer services.
|
|
1306
1496
|
*/
|
|
1307
|
-
async addFileWithPermissions(url, ownerAddress, permissions = []) {
|
|
1497
|
+
async addFileWithPermissions(url, ownerAddress, permissions = [], options) {
|
|
1498
|
+
this.assertWallet();
|
|
1308
1499
|
try {
|
|
1309
|
-
const chainId = this.context.
|
|
1500
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1310
1501
|
if (!chainId) {
|
|
1311
1502
|
throw new Error("Chain ID not available");
|
|
1312
1503
|
}
|
|
1504
|
+
this.assertWallet();
|
|
1313
1505
|
const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
|
|
1314
1506
|
const dataRegistryAbi = getAbi("DataRegistry");
|
|
1315
|
-
const
|
|
1507
|
+
const account = this.context.walletClient.account ?? ownerAddress;
|
|
1508
|
+
const from = typeof account === "string" ? account : account.address;
|
|
1509
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1316
1510
|
address: dataRegistryAddress,
|
|
1317
1511
|
abi: dataRegistryAbi,
|
|
1318
1512
|
functionName: "addFileWithPermissions",
|
|
1319
1513
|
args: [url, ownerAddress, permissions],
|
|
1320
|
-
account
|
|
1321
|
-
chain: this.context.walletClient.chain
|
|
1514
|
+
account,
|
|
1515
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1516
|
+
...this.spreadTransactionOptions(options)
|
|
1517
|
+
});
|
|
1518
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
1519
|
+
return tx({
|
|
1520
|
+
hash,
|
|
1521
|
+
from,
|
|
1522
|
+
contract: "DataRegistry",
|
|
1523
|
+
fn: "addFileWithPermissions"
|
|
1322
1524
|
});
|
|
1323
|
-
const receipt = await this.context.publicClient.waitForTransactionReceipt(
|
|
1324
|
-
{
|
|
1325
|
-
hash: txHash,
|
|
1326
|
-
confirmations: 1
|
|
1327
|
-
}
|
|
1328
|
-
);
|
|
1329
|
-
const { parseFileAddedEvent } = await import("../utils/eventParsing");
|
|
1330
|
-
const eventData = parseFileAddedEvent(receipt);
|
|
1331
|
-
return {
|
|
1332
|
-
fileId: Number(eventData.fileId),
|
|
1333
|
-
transactionHash: txHash
|
|
1334
|
-
};
|
|
1335
1525
|
} catch (error) {
|
|
1336
1526
|
console.error("Failed to add file with permissions:", error);
|
|
1337
1527
|
throw new Error(
|
|
@@ -1343,44 +1533,150 @@ class DataController {
|
|
|
1343
1533
|
* Adds a file to the registry with permissions and schema.
|
|
1344
1534
|
* This combines the functionality of addFileWithPermissions and schema validation.
|
|
1345
1535
|
*
|
|
1536
|
+
* @remarks
|
|
1537
|
+
* This method automatically encrypts permissions when a publicKey is provided.
|
|
1538
|
+
* It generates the user's encryption key and encrypts it with each recipient's
|
|
1539
|
+
* public key before registering on the blockchain.
|
|
1540
|
+
*
|
|
1346
1541
|
* @param url - The URL of the file to register
|
|
1347
1542
|
* @param ownerAddress - The address of the file owner
|
|
1348
|
-
* @param permissions - Array of permissions to grant
|
|
1543
|
+
* @param permissions - Array of permissions to grant, each with account and publicKey properties
|
|
1349
1544
|
* @param schemaId - The schema ID to associate with the file (0 for no schema)
|
|
1350
|
-
* @returns Promise resolving to
|
|
1545
|
+
* @returns Promise resolving to TransactionResult with fileId and transactionHash
|
|
1546
|
+
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1547
|
+
* @throws {Error} "Failed to generate encryption key" - When encryption key generation fails
|
|
1548
|
+
* @throws {Error} "Permission for {account} must include 'publicKey'" - When publicKey is missing
|
|
1549
|
+
* @throws {Error} "Failed to add file with permissions and schema: {error}" - When transaction fails
|
|
1550
|
+
* @example
|
|
1551
|
+
* ```typescript
|
|
1552
|
+
* // Get server's public key
|
|
1553
|
+
* const serverIdentity = await vana.server.getIdentity({
|
|
1554
|
+
* userAddress: "0x..."
|
|
1555
|
+
* });
|
|
1556
|
+
*
|
|
1557
|
+
* // Add file with permissions and schema
|
|
1558
|
+
* const result = await vana.data.addFileWithPermissionsAndSchema(
|
|
1559
|
+
* "ipfs://QmXxx...",
|
|
1560
|
+
* ownerAddress,
|
|
1561
|
+
* [{
|
|
1562
|
+
* account: serverIdentity.address,
|
|
1563
|
+
* publicKey: serverIdentity.publicKey
|
|
1564
|
+
* }],
|
|
1565
|
+
* schemaId
|
|
1566
|
+
* );
|
|
1567
|
+
*
|
|
1568
|
+
* console.log(`File ${result.fileId} registered in tx ${result.hash}`);
|
|
1569
|
+
* ```
|
|
1570
|
+
*/
|
|
1571
|
+
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
|
|
1572
|
+
this.assertWallet();
|
|
1573
|
+
try {
|
|
1574
|
+
let encryptedPermissions = [];
|
|
1575
|
+
if (permissions.length > 0) {
|
|
1576
|
+
this.assertWallet();
|
|
1577
|
+
const userEncryptionKey = await generateEncryptionKey(
|
|
1578
|
+
this.context.walletClient,
|
|
1579
|
+
this.context.platform,
|
|
1580
|
+
DEFAULT_ENCRYPTION_SEED
|
|
1581
|
+
);
|
|
1582
|
+
encryptedPermissions = await Promise.all(
|
|
1583
|
+
permissions.map(async (permission) => {
|
|
1584
|
+
if (!permission.publicKey) {
|
|
1585
|
+
throw new Error(
|
|
1586
|
+
`Permission for ${permission.account} must include 'publicKey'`
|
|
1587
|
+
);
|
|
1588
|
+
}
|
|
1589
|
+
const encryptedKey = await encryptWithWalletPublicKey(
|
|
1590
|
+
userEncryptionKey,
|
|
1591
|
+
permission.publicKey,
|
|
1592
|
+
this.context.platform
|
|
1593
|
+
);
|
|
1594
|
+
return {
|
|
1595
|
+
account: permission.account,
|
|
1596
|
+
key: encryptedKey
|
|
1597
|
+
};
|
|
1598
|
+
})
|
|
1599
|
+
);
|
|
1600
|
+
}
|
|
1601
|
+
return await this.addFileWithEncryptedPermissionsAndSchema(
|
|
1602
|
+
url,
|
|
1603
|
+
ownerAddress,
|
|
1604
|
+
encryptedPermissions,
|
|
1605
|
+
schemaId,
|
|
1606
|
+
options
|
|
1607
|
+
);
|
|
1608
|
+
} catch (error) {
|
|
1609
|
+
console.error("Failed to add file with permissions and schema:", error);
|
|
1610
|
+
throw new Error(
|
|
1611
|
+
`Failed to add file with permissions and schema: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
1612
|
+
);
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
/**
|
|
1616
|
+
* Adds a file with pre-encrypted permissions and schema to the DataRegistry.
|
|
1617
|
+
*
|
|
1618
|
+
* @remarks
|
|
1619
|
+
* This method is designed for relay services and advanced use cases where permissions
|
|
1620
|
+
* have already been encrypted client-side. Unlike `addFileWithPermissionsAndSchema()`,
|
|
1621
|
+
* this method expects permissions in the encrypted format with a 'key' field instead
|
|
1622
|
+
* of 'publicKey'.
|
|
1623
|
+
*
|
|
1624
|
+
* This is typically used by relay endpoints that receive pre-encrypted data from
|
|
1625
|
+
* the client SDK's `upload()` method, avoiding double encryption.
|
|
1626
|
+
*
|
|
1627
|
+
* @param url - The storage URL of the file (e.g., IPFS URL)
|
|
1628
|
+
* @param ownerAddress - The address that will own this file
|
|
1629
|
+
* @param permissions - Array of pre-encrypted permissions with 'account' and 'key' fields
|
|
1630
|
+
* @param schemaId - Optional schema ID for data validation (defaults to 0)
|
|
1631
|
+
* @returns Promise resolving to transaction result with hash and contract details
|
|
1351
1632
|
* @throws {Error} When chain ID is not available
|
|
1352
|
-
* @throws {
|
|
1353
|
-
* @throws {Error} When transaction
|
|
1354
|
-
* @
|
|
1633
|
+
* @throws {Error} When wallet is not connected
|
|
1634
|
+
* @throws {Error} When transaction fails
|
|
1635
|
+
* @example
|
|
1636
|
+
* ```typescript
|
|
1637
|
+
* // In a relay endpoint that receives pre-encrypted permissions
|
|
1638
|
+
* const result = await vana.data.addFileWithEncryptedPermissionsAndSchema(
|
|
1639
|
+
* "ipfs://QmXxx...",
|
|
1640
|
+
* ownerAddress,
|
|
1641
|
+
* [
|
|
1642
|
+
* {
|
|
1643
|
+
* account: "0xServerAddress...",
|
|
1644
|
+
* key: "encrypted_key_string" // Already encrypted by client
|
|
1645
|
+
* }
|
|
1646
|
+
* ],
|
|
1647
|
+
* schemaId
|
|
1648
|
+
* );
|
|
1649
|
+
*
|
|
1650
|
+
* console.log(`File registered in tx ${result.hash}`);
|
|
1651
|
+
* ```
|
|
1355
1652
|
*/
|
|
1356
|
-
async
|
|
1653
|
+
async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
|
|
1357
1654
|
try {
|
|
1358
|
-
const chainId = this.context.
|
|
1655
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1359
1656
|
if (!chainId) {
|
|
1360
1657
|
throw new Error("Chain ID not available");
|
|
1361
1658
|
}
|
|
1659
|
+
this.assertWallet();
|
|
1362
1660
|
const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
|
|
1363
1661
|
const dataRegistryAbi = getAbi("DataRegistry");
|
|
1364
|
-
const
|
|
1662
|
+
const account = this.context.walletClient.account ?? ownerAddress;
|
|
1663
|
+
const from = typeof account === "string" ? account : account.address;
|
|
1664
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1365
1665
|
address: dataRegistryAddress,
|
|
1366
1666
|
abi: dataRegistryAbi,
|
|
1367
1667
|
functionName: "addFileWithPermissionsAndSchema",
|
|
1368
1668
|
args: [url, ownerAddress, permissions, BigInt(schemaId)],
|
|
1369
|
-
account
|
|
1370
|
-
chain: this.context.walletClient.chain
|
|
1669
|
+
account,
|
|
1670
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1671
|
+
...this.spreadTransactionOptions(options)
|
|
1672
|
+
});
|
|
1673
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
1674
|
+
return tx({
|
|
1675
|
+
hash,
|
|
1676
|
+
from,
|
|
1677
|
+
contract: "DataRegistry",
|
|
1678
|
+
fn: "addFileWithPermissionsAndSchema"
|
|
1371
1679
|
});
|
|
1372
|
-
const receipt = await this.context.publicClient.waitForTransactionReceipt(
|
|
1373
|
-
{
|
|
1374
|
-
hash: txHash,
|
|
1375
|
-
confirmations: 1
|
|
1376
|
-
}
|
|
1377
|
-
);
|
|
1378
|
-
const { parseFileAddedEvent } = await import("../utils/eventParsing");
|
|
1379
|
-
const eventData = parseFileAddedEvent(receipt);
|
|
1380
|
-
return {
|
|
1381
|
-
fileId: Number(eventData.fileId),
|
|
1382
|
-
transactionHash: txHash
|
|
1383
|
-
};
|
|
1384
1680
|
} catch (error) {
|
|
1385
1681
|
console.error("Failed to add file with permissions and schema:", error);
|
|
1386
1682
|
throw new Error(
|
|
@@ -1389,36 +1685,41 @@ class DataController {
|
|
|
1389
1685
|
}
|
|
1390
1686
|
}
|
|
1391
1687
|
/**
|
|
1392
|
-
*
|
|
1688
|
+
* Registers a data refiner for processing templates.
|
|
1393
1689
|
*
|
|
1394
1690
|
* @remarks
|
|
1395
|
-
* Refiners
|
|
1396
|
-
*
|
|
1397
|
-
*
|
|
1398
|
-
*
|
|
1399
|
-
*
|
|
1400
|
-
* @param params - Refiner
|
|
1401
|
-
* @param params.
|
|
1402
|
-
*
|
|
1403
|
-
* @param params.
|
|
1404
|
-
*
|
|
1405
|
-
* @returns
|
|
1406
|
-
*
|
|
1407
|
-
* @throws {Error}
|
|
1691
|
+
* Refiners define data transformation rules for DLPs.
|
|
1692
|
+
* Associates schema, instructions, and processing logic.
|
|
1693
|
+
*
|
|
1694
|
+
* @param params - Refiner configuration
|
|
1695
|
+
* @param params.dlpId - Data Liquidity Pool ID
|
|
1696
|
+
* @param params.name - Refiner display name
|
|
1697
|
+
* @param params.schemaId - Output schema ID.
|
|
1698
|
+
* Obtain via `vana.schemas.list()`.
|
|
1699
|
+
* @param params.refinementInstructionUrl - Processing instructions URL
|
|
1700
|
+
*
|
|
1701
|
+
* @returns Refiner ID and transaction hash
|
|
1702
|
+
*
|
|
1703
|
+
* @throws {Error} Chain ID not available.
|
|
1704
|
+
* Ensure network connection.
|
|
1705
|
+
* @throws {Error} Transaction failed.
|
|
1706
|
+
* Check wallet balance and network status.
|
|
1707
|
+
*
|
|
1408
1708
|
* @example
|
|
1409
1709
|
* ```typescript
|
|
1410
1710
|
* const result = await vana.data.addRefiner({
|
|
1411
1711
|
* dlpId: 1,
|
|
1412
|
-
* name: "
|
|
1712
|
+
* name: "Sentiment Analyzer",
|
|
1413
1713
|
* schemaId: 42,
|
|
1414
1714
|
* refinementInstructionUrl: "ipfs://QmXxx..."
|
|
1415
1715
|
* });
|
|
1416
|
-
* console.log(`
|
|
1716
|
+
* console.log(`Refiner ${result.refinerId} created`);
|
|
1417
1717
|
* ```
|
|
1418
1718
|
*/
|
|
1419
|
-
async addRefiner(params) {
|
|
1719
|
+
async addRefiner(params, options) {
|
|
1720
|
+
this.assertWallet();
|
|
1420
1721
|
try {
|
|
1421
|
-
const chainId = this.context.
|
|
1722
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1422
1723
|
if (!chainId) {
|
|
1423
1724
|
throw new Error("Chain ID not available");
|
|
1424
1725
|
}
|
|
@@ -1427,7 +1728,10 @@ class DataController {
|
|
|
1427
1728
|
"DataRefinerRegistry"
|
|
1428
1729
|
);
|
|
1429
1730
|
const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
|
|
1430
|
-
|
|
1731
|
+
this.assertWallet();
|
|
1732
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1733
|
+
const from = typeof account === "string" ? account : account.address;
|
|
1734
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1431
1735
|
address: dataRefinerRegistryAddress,
|
|
1432
1736
|
abi: dataRefinerRegistryAbi,
|
|
1433
1737
|
functionName: "addRefinerWithSchemaId",
|
|
@@ -1437,20 +1741,28 @@ class DataController {
|
|
|
1437
1741
|
BigInt(params.schemaId),
|
|
1438
1742
|
params.refinementInstructionUrl
|
|
1439
1743
|
],
|
|
1440
|
-
account
|
|
1441
|
-
chain: this.context.walletClient.chain
|
|
1744
|
+
account,
|
|
1745
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1746
|
+
...this.spreadTransactionOptions(options)
|
|
1442
1747
|
});
|
|
1443
|
-
const
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1748
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
1749
|
+
const txResult = tx({
|
|
1750
|
+
hash,
|
|
1751
|
+
from,
|
|
1752
|
+
contract: "DataRefinerRegistry",
|
|
1753
|
+
fn: "addRefinerWithSchemaId"
|
|
1754
|
+
});
|
|
1755
|
+
if (!this.context.waitForTransactionEvents) {
|
|
1756
|
+
throw new Error("waitForTransactionEvents not configured");
|
|
1757
|
+
}
|
|
1758
|
+
const result = await this.context.waitForTransactionEvents(txResult);
|
|
1759
|
+
const event = result.expectedEvents.RefinerAdded;
|
|
1760
|
+
if (!event) {
|
|
1761
|
+
throw new Error("RefinerAdded event not found in transaction");
|
|
1762
|
+
}
|
|
1451
1763
|
return {
|
|
1452
|
-
refinerId: Number(
|
|
1453
|
-
transactionHash:
|
|
1764
|
+
refinerId: Number(event.refinerId),
|
|
1765
|
+
transactionHash: hash
|
|
1454
1766
|
};
|
|
1455
1767
|
} catch (error) {
|
|
1456
1768
|
console.error("Failed to add refiner:", error);
|
|
@@ -1460,31 +1772,34 @@ class DataController {
|
|
|
1460
1772
|
}
|
|
1461
1773
|
}
|
|
1462
1774
|
/**
|
|
1463
|
-
* Retrieves
|
|
1775
|
+
* Retrieves refiner configuration by ID.
|
|
1464
1776
|
*
|
|
1465
1777
|
* @remarks
|
|
1466
|
-
* Queries
|
|
1467
|
-
*
|
|
1778
|
+
* Queries DataRefinerRegistry for refiner details.
|
|
1779
|
+
* Returns DLP association, schema, and processing instructions.
|
|
1780
|
+
*
|
|
1781
|
+
* @param refinerId - Numeric refiner ID
|
|
1782
|
+
*
|
|
1783
|
+
* @returns Refiner configuration object
|
|
1784
|
+
*
|
|
1785
|
+
* @throws {Error} Chain ID not available.
|
|
1786
|
+
* Ensure network connection.
|
|
1787
|
+
* @throws {Error} Refiner not found.
|
|
1788
|
+
* Verify refiner ID exists.
|
|
1789
|
+
* @throws {Error} Contract read failed.
|
|
1790
|
+
* Check network and RPC status.
|
|
1468
1791
|
*
|
|
1469
|
-
* @param refinerId - The numeric refiner ID to retrieve
|
|
1470
|
-
* @returns Promise resolving to the refiner information object
|
|
1471
|
-
* @throws {Error} When chain ID is not available - "Chain ID not available"
|
|
1472
|
-
* @throws {Error} When refiner doesn't exist - "Refiner with ID {refinerId} does not exist"
|
|
1473
|
-
* @throws {Error} When contract read fails - "Failed to fetch refiner: {error}"
|
|
1474
1792
|
* @example
|
|
1475
1793
|
* ```typescript
|
|
1476
1794
|
* const refiner = await vana.data.getRefiner(1);
|
|
1477
|
-
* console.log({
|
|
1478
|
-
*
|
|
1479
|
-
*
|
|
1480
|
-
* schema: refiner.schemaId,
|
|
1481
|
-
* instructions: refiner.refinementInstructionUrl
|
|
1482
|
-
* });
|
|
1795
|
+
* console.log(`Refiner: ${refiner.name}`);
|
|
1796
|
+
* console.log(`DLP: ${refiner.dlpId}`);
|
|
1797
|
+
* console.log(`Schema: ${refiner.schemaId}`);
|
|
1483
1798
|
* ```
|
|
1484
1799
|
*/
|
|
1485
1800
|
async getRefiner(refinerId) {
|
|
1486
1801
|
try {
|
|
1487
|
-
const chainId = this.context.
|
|
1802
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1488
1803
|
if (!chainId) {
|
|
1489
1804
|
throw new Error("Chain ID not available");
|
|
1490
1805
|
}
|
|
@@ -1496,7 +1811,7 @@ class DataController {
|
|
|
1496
1811
|
const dataRefinerRegistry = getContract({
|
|
1497
1812
|
address: dataRefinerRegistryAddress,
|
|
1498
1813
|
abi: dataRefinerRegistryAbi,
|
|
1499
|
-
client: this.context.
|
|
1814
|
+
client: this.context.publicClient
|
|
1500
1815
|
});
|
|
1501
1816
|
const refinerData = await dataRefinerRegistry.read.refiners([
|
|
1502
1817
|
BigInt(refinerId)
|
|
@@ -1520,27 +1835,33 @@ class DataController {
|
|
|
1520
1835
|
}
|
|
1521
1836
|
}
|
|
1522
1837
|
/**
|
|
1523
|
-
* Validates
|
|
1838
|
+
* Validates schema ID existence.
|
|
1524
1839
|
*
|
|
1525
1840
|
* @remarks
|
|
1526
|
-
*
|
|
1527
|
-
*
|
|
1841
|
+
* Verifies schema registration in DataRegistry.
|
|
1842
|
+
* Check before using schemas for uploads.
|
|
1843
|
+
*
|
|
1844
|
+
* @param schemaId - Numeric schema ID to validate
|
|
1845
|
+
*
|
|
1846
|
+
* @returns True if schema exists, false otherwise
|
|
1847
|
+
*
|
|
1848
|
+
* @throws {Error} Chain ID not available.
|
|
1849
|
+
* Ensure network connection.
|
|
1850
|
+
* @throws {Error} Contract read failed.
|
|
1851
|
+
* Check RPC availability.
|
|
1528
1852
|
*
|
|
1529
|
-
* @param schemaId - The numeric schema ID to validate
|
|
1530
|
-
* @returns Promise resolving to true if schema exists, false otherwise
|
|
1531
1853
|
* @example
|
|
1532
1854
|
* ```typescript
|
|
1533
|
-
* const
|
|
1534
|
-
* if (
|
|
1535
|
-
*
|
|
1536
|
-
*
|
|
1537
|
-
* console.log('Schema 42 does not exist');
|
|
1855
|
+
* const valid = await vana.data.isValidSchemaId(42);
|
|
1856
|
+
* if (valid) {
|
|
1857
|
+
* // Safe to use schema 42
|
|
1858
|
+
* await vana.data.upload({ schemaId: 42, ... });
|
|
1538
1859
|
* }
|
|
1539
1860
|
* ```
|
|
1540
1861
|
*/
|
|
1541
1862
|
async isValidSchemaId(schemaId) {
|
|
1542
1863
|
try {
|
|
1543
|
-
const chainId = this.context.
|
|
1864
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1544
1865
|
if (!chainId) {
|
|
1545
1866
|
throw new Error("Chain ID not available");
|
|
1546
1867
|
}
|
|
@@ -1552,7 +1873,7 @@ class DataController {
|
|
|
1552
1873
|
const dataRefinerRegistry = getContract({
|
|
1553
1874
|
address: dataRefinerRegistryAddress,
|
|
1554
1875
|
abi: dataRefinerRegistryAbi,
|
|
1555
|
-
client: this.context.
|
|
1876
|
+
client: this.context.publicClient
|
|
1556
1877
|
});
|
|
1557
1878
|
const isValid = await dataRefinerRegistry.read.isValidSchemaId([
|
|
1558
1879
|
BigInt(schemaId)
|
|
@@ -1579,7 +1900,7 @@ class DataController {
|
|
|
1579
1900
|
*/
|
|
1580
1901
|
async getRefinersCount() {
|
|
1581
1902
|
try {
|
|
1582
|
-
const chainId = this.context.
|
|
1903
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1583
1904
|
if (!chainId) {
|
|
1584
1905
|
throw new Error("Chain ID not available");
|
|
1585
1906
|
}
|
|
@@ -1591,7 +1912,7 @@ class DataController {
|
|
|
1591
1912
|
const dataRefinerRegistry = getContract({
|
|
1592
1913
|
address: dataRefinerRegistryAddress,
|
|
1593
1914
|
abi: dataRefinerRegistryAbi,
|
|
1594
|
-
client: this.context.
|
|
1915
|
+
client: this.context.publicClient
|
|
1595
1916
|
});
|
|
1596
1917
|
const count = await dataRefinerRegistry.read.refinersCount();
|
|
1597
1918
|
return Number(count);
|
|
@@ -1622,9 +1943,10 @@ class DataController {
|
|
|
1622
1943
|
* console.log(`Schema updated in tx ${result.transactionHash}`);
|
|
1623
1944
|
* ```
|
|
1624
1945
|
*/
|
|
1625
|
-
async updateSchemaId(params) {
|
|
1946
|
+
async updateSchemaId(params, options) {
|
|
1947
|
+
this.assertWallet();
|
|
1626
1948
|
try {
|
|
1627
|
-
const chainId = this.context.
|
|
1949
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1628
1950
|
if (!chainId) {
|
|
1629
1951
|
throw new Error("Chain ID not available");
|
|
1630
1952
|
}
|
|
@@ -1633,20 +1955,20 @@ class DataController {
|
|
|
1633
1955
|
"DataRefinerRegistry"
|
|
1634
1956
|
);
|
|
1635
1957
|
const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
|
|
1636
|
-
|
|
1958
|
+
this.assertWallet();
|
|
1959
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1960
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1637
1961
|
address: dataRefinerRegistryAddress,
|
|
1638
1962
|
abi: dataRefinerRegistryAbi,
|
|
1639
1963
|
functionName: "updateSchemaId",
|
|
1640
1964
|
args: [BigInt(params.refinerId), BigInt(params.newSchemaId)],
|
|
1641
|
-
account
|
|
1642
|
-
chain: this.context.walletClient.chain
|
|
1643
|
-
|
|
1644
|
-
await this.context.publicClient.waitForTransactionReceipt({
|
|
1645
|
-
hash: txHash,
|
|
1646
|
-
timeout: 3e4
|
|
1965
|
+
account,
|
|
1966
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1967
|
+
...this.spreadTransactionOptions(options)
|
|
1647
1968
|
});
|
|
1969
|
+
await this.context.publicClient.waitForTransactionReceipt({ hash });
|
|
1648
1970
|
return {
|
|
1649
|
-
transactionHash:
|
|
1971
|
+
transactionHash: hash
|
|
1650
1972
|
};
|
|
1651
1973
|
} catch (error) {
|
|
1652
1974
|
console.error("Failed to update schema ID:", error);
|
|
@@ -1664,13 +1986,12 @@ class DataController {
|
|
|
1664
1986
|
* 3. Encrypts the user's encryption key with the provided public key
|
|
1665
1987
|
* 4. Registers the file with permissions
|
|
1666
1988
|
*
|
|
1667
|
-
* @param
|
|
1668
|
-
* @param permissions - Array of permissions to grant, each with account address and public key
|
|
1669
|
-
* @param filename - Optional filename for the upload
|
|
1670
|
-
* @param providerName - Optional storage provider to use
|
|
1989
|
+
* @param params - Upload parameters including data, permissions, and options
|
|
1671
1990
|
* @returns Promise resolving to upload result with file ID and storage URL
|
|
1672
1991
|
*/
|
|
1673
|
-
async uploadFileWithPermissions(
|
|
1992
|
+
async uploadFileWithPermissions(params) {
|
|
1993
|
+
this.assertWallet();
|
|
1994
|
+
const { data, permissions, filename, providerName } = params;
|
|
1674
1995
|
try {
|
|
1675
1996
|
const uploadResult = await this.uploadToStorage(
|
|
1676
1997
|
data,
|
|
@@ -1679,7 +2000,7 @@ class DataController {
|
|
|
1679
2000
|
// Always encrypt for uploadFileWithPermissions
|
|
1680
2001
|
providerName
|
|
1681
2002
|
);
|
|
1682
|
-
const userAddress =
|
|
2003
|
+
const userAddress = this.context.userAddress;
|
|
1683
2004
|
const userEncryptionKey = await generateEncryptionKey(
|
|
1684
2005
|
this.context.walletClient,
|
|
1685
2006
|
this.context.platform,
|
|
@@ -1698,26 +2019,61 @@ class DataController {
|
|
|
1698
2019
|
};
|
|
1699
2020
|
})
|
|
1700
2021
|
);
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
2022
|
+
if (this.context.relayer) {
|
|
2023
|
+
const request = {
|
|
2024
|
+
type: "direct",
|
|
2025
|
+
operation: "submitFileAdditionWithPermissions",
|
|
2026
|
+
params: {
|
|
2027
|
+
url: uploadResult.url,
|
|
2028
|
+
userAddress,
|
|
2029
|
+
permissions: encryptedPermissions
|
|
2030
|
+
}
|
|
2031
|
+
};
|
|
2032
|
+
const response = await this.context.relayer(request);
|
|
2033
|
+
if (response.type === "error") {
|
|
2034
|
+
throw new Error(response.error);
|
|
2035
|
+
}
|
|
2036
|
+
let result;
|
|
2037
|
+
if (response.type === "pending") {
|
|
2038
|
+
result = await this.pollRelayerForConfirmation(
|
|
2039
|
+
response.operationId,
|
|
2040
|
+
void 0
|
|
2041
|
+
// TODO: Add TransactionOptions to upload method signature
|
|
2042
|
+
);
|
|
2043
|
+
} else if (response.type === "direct" && typeof response.result === "object" && response.result !== null && "fileId" in response.result) {
|
|
2044
|
+
result = response.result;
|
|
2045
|
+
} else {
|
|
2046
|
+
throw new Error("Invalid response from relayer");
|
|
2047
|
+
}
|
|
2048
|
+
return {
|
|
2049
|
+
fileId: result.fileId,
|
|
2050
|
+
url: uploadResult.url,
|
|
2051
|
+
size: uploadResult.size,
|
|
2052
|
+
transactionHash: result.transactionHash
|
|
2053
|
+
};
|
|
1708
2054
|
} else {
|
|
1709
|
-
|
|
2055
|
+
const txResult = await this.addFileWithPermissions(
|
|
1710
2056
|
uploadResult.url,
|
|
1711
2057
|
userAddress,
|
|
1712
2058
|
encryptedPermissions
|
|
1713
2059
|
);
|
|
2060
|
+
if (!this.context.waitForTransactionEvents) {
|
|
2061
|
+
throw new Error(
|
|
2062
|
+
"Cannot upload without relay: waitForTransactionEvents not configured"
|
|
2063
|
+
);
|
|
2064
|
+
}
|
|
2065
|
+
const eventResult = await this.context.waitForTransactionEvents(txResult);
|
|
2066
|
+
const fileAddedEvent = eventResult.expectedEvents.FileAdded;
|
|
2067
|
+
if (!fileAddedEvent) {
|
|
2068
|
+
throw new Error("FileAdded event not found in transaction");
|
|
2069
|
+
}
|
|
2070
|
+
return {
|
|
2071
|
+
fileId: Number(fileAddedEvent.fileId),
|
|
2072
|
+
url: uploadResult.url,
|
|
2073
|
+
size: uploadResult.size,
|
|
2074
|
+
transactionHash: txResult.hash
|
|
2075
|
+
};
|
|
1714
2076
|
}
|
|
1715
|
-
return {
|
|
1716
|
-
fileId: result.fileId,
|
|
1717
|
-
url: uploadResult.url,
|
|
1718
|
-
size: uploadResult.size,
|
|
1719
|
-
transactionHash: result.transactionHash
|
|
1720
|
-
};
|
|
1721
2077
|
} catch (error) {
|
|
1722
2078
|
console.error("Failed to upload file with permissions:", error);
|
|
1723
2079
|
throw new Error(
|
|
@@ -1755,6 +2111,7 @@ class DataController {
|
|
|
1755
2111
|
}
|
|
1756
2112
|
let finalBlob = blob;
|
|
1757
2113
|
if (encrypt) {
|
|
2114
|
+
this.assertWallet();
|
|
1758
2115
|
const encryptionKey = await generateEncryptionKey(
|
|
1759
2116
|
this.context.walletClient,
|
|
1760
2117
|
this.context.platform,
|
|
@@ -1776,7 +2133,15 @@ class DataController {
|
|
|
1776
2133
|
);
|
|
1777
2134
|
}
|
|
1778
2135
|
}
|
|
1779
|
-
const finalFilename =
|
|
2136
|
+
const finalFilename = (() => {
|
|
2137
|
+
if (filename) {
|
|
2138
|
+
if (encrypt && !filename.endsWith(".enc")) {
|
|
2139
|
+
return `${filename}.enc`;
|
|
2140
|
+
}
|
|
2141
|
+
return filename;
|
|
2142
|
+
}
|
|
2143
|
+
return encrypt ? `upload-${Date.now()}.enc` : `upload-${Date.now()}.dat`;
|
|
2144
|
+
})();
|
|
1780
2145
|
const uploadResult = await this.context.storageManager.upload(
|
|
1781
2146
|
finalBlob,
|
|
1782
2147
|
finalFilename,
|
|
@@ -1801,22 +2166,30 @@ class DataController {
|
|
|
1801
2166
|
* For advanced users who need more control over transaction timing,
|
|
1802
2167
|
* use `submitFilePermission()` instead.
|
|
1803
2168
|
*
|
|
1804
|
-
* @param
|
|
1805
|
-
* @param
|
|
1806
|
-
* @param
|
|
2169
|
+
* @param params - Parameters for adding file permission
|
|
2170
|
+
* @param params.fileId - The ID of the file to grant permission for
|
|
2171
|
+
* @param params.account - The recipient's wallet address that will access the file
|
|
2172
|
+
* @param params.publicKey - The recipient's public key for encryption.
|
|
2173
|
+
* Obtain via `vana.server.getIdentity(account).publicKey`
|
|
1807
2174
|
* @returns Promise resolving to permission data from PermissionGranted event
|
|
1808
2175
|
* @throws {Error} "No addresses available in wallet client" - When wallet is not connected
|
|
1809
2176
|
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1810
2177
|
* @throws {Error} "Failed to add permission to file: {error}" - When transaction fails or user doesn't own file
|
|
1811
2178
|
* @example
|
|
1812
2179
|
* ```typescript
|
|
1813
|
-
* const result = await vana.data.addPermissionToFile(
|
|
2180
|
+
* const result = await vana.data.addPermissionToFile({
|
|
2181
|
+
* fileId: 123,
|
|
2182
|
+
* account: "0xRecipientAddress...",
|
|
2183
|
+
* publicKey: "0xRecipientPublicKey..."
|
|
2184
|
+
* });
|
|
1814
2185
|
* console.log(`Permission granted to ${result.account} for file ${result.fileId}`);
|
|
1815
2186
|
* console.log(`Transaction: ${result.transactionHash}`);
|
|
1816
2187
|
* ```
|
|
1817
2188
|
*/
|
|
1818
|
-
async addPermissionToFile(
|
|
1819
|
-
|
|
2189
|
+
async addPermissionToFile(params, options) {
|
|
2190
|
+
this.assertWallet();
|
|
2191
|
+
const { fileId, account, publicKey } = params;
|
|
2192
|
+
return await this.submitFilePermission(fileId, account, publicKey, options);
|
|
1820
2193
|
}
|
|
1821
2194
|
/**
|
|
1822
2195
|
* Submits a file permission transaction to the blockchain.
|
|
@@ -1829,7 +2202,7 @@ class DataController {
|
|
|
1829
2202
|
* @param fileId - The ID of the file to grant permission for
|
|
1830
2203
|
* @param account - The recipient's wallet address that will access the file
|
|
1831
2204
|
* @param publicKey - The recipient's public key for encryption.
|
|
1832
|
-
* Obtain via `vana.server.getIdentity(account).
|
|
2205
|
+
* Obtain via `vana.server.getIdentity(account).publicKey`
|
|
1833
2206
|
* @returns Promise resolving to TransactionResult for tracking the transaction
|
|
1834
2207
|
* @throws {Error} When chain ID is not available
|
|
1835
2208
|
* @throws {Error} When encryption key generation fails
|
|
@@ -1846,7 +2219,8 @@ class DataController {
|
|
|
1846
2219
|
* console.log(`Permission granted with ID: ${result.permissionId}`);
|
|
1847
2220
|
* ```
|
|
1848
2221
|
*/
|
|
1849
|
-
async submitFilePermission(fileId, account, publicKey) {
|
|
2222
|
+
async submitFilePermission(fileId, account, publicKey, options) {
|
|
2223
|
+
this.assertWallet();
|
|
1850
2224
|
try {
|
|
1851
2225
|
const userEncryptionKey = await generateEncryptionKey(
|
|
1852
2226
|
this.context.walletClient,
|
|
@@ -1858,24 +2232,30 @@ class DataController {
|
|
|
1858
2232
|
publicKey,
|
|
1859
2233
|
this.context.platform
|
|
1860
2234
|
);
|
|
1861
|
-
const chainId = this.context.
|
|
2235
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1862
2236
|
if (!chainId) {
|
|
1863
2237
|
throw new Error("Chain ID not available");
|
|
1864
2238
|
}
|
|
1865
2239
|
const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
|
|
1866
2240
|
const dataRegistryAbi = getAbi("DataRegistry");
|
|
2241
|
+
this.assertWallet();
|
|
2242
|
+
const walletAccount = this.context.walletClient.account ?? this.context.userAddress;
|
|
1867
2243
|
const txHash = await this.context.walletClient.writeContract({
|
|
1868
2244
|
address: dataRegistryAddress,
|
|
1869
2245
|
abi: dataRegistryAbi,
|
|
1870
2246
|
functionName: "addFilePermission",
|
|
1871
2247
|
args: [BigInt(fileId), account, encryptedKey],
|
|
1872
|
-
account:
|
|
1873
|
-
chain: this.context.walletClient.chain
|
|
2248
|
+
account: walletAccount,
|
|
2249
|
+
chain: this.context.walletClient.chain ?? null,
|
|
2250
|
+
...this.spreadTransactionOptions(options)
|
|
1874
2251
|
});
|
|
1875
|
-
|
|
2252
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
2253
|
+
return tx({
|
|
1876
2254
|
hash: txHash,
|
|
1877
|
-
from:
|
|
1878
|
-
|
|
2255
|
+
from: typeof walletAccount === "string" ? walletAccount : walletAccount.address,
|
|
2256
|
+
contract: "DataRegistry",
|
|
2257
|
+
fn: "addFilePermission"
|
|
2258
|
+
});
|
|
1879
2259
|
} catch (error) {
|
|
1880
2260
|
console.error("Failed to add permission to file:", error);
|
|
1881
2261
|
throw new Error(
|
|
@@ -1892,7 +2272,7 @@ class DataController {
|
|
|
1892
2272
|
*/
|
|
1893
2273
|
async getFilePermission(fileId, account) {
|
|
1894
2274
|
try {
|
|
1895
|
-
const chainId = this.context.
|
|
2275
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1896
2276
|
if (!chainId) {
|
|
1897
2277
|
throw new Error("Chain ID not available");
|
|
1898
2278
|
}
|
|
@@ -1901,7 +2281,7 @@ class DataController {
|
|
|
1901
2281
|
const dataRegistry = getContract({
|
|
1902
2282
|
address: dataRegistryAddress,
|
|
1903
2283
|
abi: dataRegistryAbi,
|
|
1904
|
-
client: this.context.
|
|
2284
|
+
client: this.context.publicClient
|
|
1905
2285
|
});
|
|
1906
2286
|
const encryptedKey = await dataRegistry.read.filePermissions([
|
|
1907
2287
|
BigInt(fileId),
|
|
@@ -1925,12 +2305,13 @@ class DataController {
|
|
|
1925
2305
|
*
|
|
1926
2306
|
* @param file - The file to decrypt
|
|
1927
2307
|
* @param privateKey - The private key to decrypt the user's encryption key
|
|
1928
|
-
* @param
|
|
2308
|
+
* @param options - Optional decryption configuration
|
|
2309
|
+
* @param options.account - The account address that has permission (defaults to current wallet account)
|
|
1929
2310
|
* @returns Promise resolving to the decrypted file data
|
|
1930
2311
|
*/
|
|
1931
|
-
async decryptFileWithPermission(file, privateKey,
|
|
2312
|
+
async decryptFileWithPermission(file, privateKey, options) {
|
|
1932
2313
|
try {
|
|
1933
|
-
const permissionAccount = account
|
|
2314
|
+
const permissionAccount = options?.account ?? this.context.userAddress;
|
|
1934
2315
|
const encryptedKey = await this.getFilePermission(
|
|
1935
2316
|
file.id,
|
|
1936
2317
|
permissionAccount
|
|
@@ -1994,11 +2375,8 @@ class DataController {
|
|
|
1994
2375
|
*/
|
|
1995
2376
|
async fetch(url) {
|
|
1996
2377
|
try {
|
|
1997
|
-
const {
|
|
1998
|
-
const response = await
|
|
1999
|
-
url,
|
|
2000
|
-
this.context.downloadRelayer
|
|
2001
|
-
);
|
|
2378
|
+
const { universalFetch } = await import("../utils/download");
|
|
2379
|
+
const response = await universalFetch(url, this.context.downloadRelayer);
|
|
2002
2380
|
if (!response.ok) {
|
|
2003
2381
|
throw new Error(
|
|
2004
2382
|
`HTTP error! status: ${response.status} ${response.statusText}`
|
|
@@ -2063,7 +2441,7 @@ class DataController {
|
|
|
2063
2441
|
"https://dweb.link/ipfs/",
|
|
2064
2442
|
"https://ipfs.io/ipfs/"
|
|
2065
2443
|
];
|
|
2066
|
-
const gateways = options?.gateways
|
|
2444
|
+
const gateways = options?.gateways ?? this.context.ipfsGateways ?? defaultGateways;
|
|
2067
2445
|
const { extractIpfsHash } = await import("../utils/ipfs");
|
|
2068
2446
|
const cid = extractIpfsHash(url);
|
|
2069
2447
|
if (!cid) {
|
|
@@ -2192,7 +2570,7 @@ class DataController {
|
|
|
2192
2570
|
* ```
|
|
2193
2571
|
*/
|
|
2194
2572
|
validateDataAgainstSchema(data, schema) {
|
|
2195
|
-
|
|
2573
|
+
validateDataAgainstSchema(data, schema);
|
|
2196
2574
|
}
|
|
2197
2575
|
/**
|
|
2198
2576
|
* Fetches and validates a data schema from a URL, then returns the parsed data schema.
|
|
@@ -2215,6 +2593,26 @@ class DataController {
|
|
|
2215
2593
|
async fetchAndValidateSchema(url) {
|
|
2216
2594
|
return fetchAndValidateSchema(url);
|
|
2217
2595
|
}
|
|
2596
|
+
/**
|
|
2597
|
+
* Polls for confirmation of a relayer operation.
|
|
2598
|
+
* @internal
|
|
2599
|
+
*/
|
|
2600
|
+
async pollRelayerForConfirmation(operationId, options) {
|
|
2601
|
+
if (!this.context.relayer) {
|
|
2602
|
+
throw new Error("Relayer not configured for polling");
|
|
2603
|
+
}
|
|
2604
|
+
const pollingManager = new PollingManager(this.context.relayer);
|
|
2605
|
+
const result = await pollingManager.startPolling(operationId, {
|
|
2606
|
+
signal: options?.signal,
|
|
2607
|
+
onStatusUpdate: options?.onStatusUpdate,
|
|
2608
|
+
...options?.pollingOptions
|
|
2609
|
+
});
|
|
2610
|
+
return {
|
|
2611
|
+
fileId: 0,
|
|
2612
|
+
// This would need to be extracted from transaction events
|
|
2613
|
+
transactionHash: result.hash
|
|
2614
|
+
};
|
|
2615
|
+
}
|
|
2218
2616
|
}
|
|
2219
2617
|
export {
|
|
2220
2618
|
DataController
|