@opendatalabs/vana-sdk 0.1.0-alpha.7ee7635 → 0.1.0-alpha.8117ac2
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 -45
- 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 -59
- 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__/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 +699 -373
- package/dist/controllers/data.cjs.map +1 -1
- package/dist/controllers/data.d.ts +368 -228
- package/dist/controllers/data.js +712 -376
- package/dist/controllers/data.js.map +1 -1
- package/dist/controllers/permissions.cjs +688 -489
- package/dist/controllers/permissions.cjs.map +1 -1
- package/dist/controllers/permissions.d.ts +98 -165
- package/dist/controllers/permissions.js +688 -489
- 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 -84
- package/dist/controllers/protocol.js +15 -14
- package/dist/controllers/protocol.js.map +1 -1
- package/dist/controllers/schemas.cjs +57 -52
- package/dist/controllers/schemas.cjs.map +1 -1
- package/dist/controllers/schemas.d.ts +55 -61
- package/dist/controllers/schemas.js +57 -52
- 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 -58
- package/dist/controllers/server.js +32 -25
- package/dist/controllers/server.js.map +1 -1
- 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/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 +115 -47
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +24 -74
- package/dist/core.js +137 -72
- 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 +4 -3
- package/dist/crypto/ecies/base.cjs.map +1 -1
- package/dist/crypto/ecies/base.d.ts +2 -5
- package/dist/crypto/ecies/base.js +12 -15
- 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/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 +16 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +53 -15
- package/dist/errors.js +18 -6
- package/dist/errors.js.map +1 -1
- package/dist/generated/abi/ComputeEngineImplementation.d.ts +2 -3
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.cjs.map +1 -1
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.d.ts +2 -3
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.js.map +1 -1
- 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.cjs.map +1 -1
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.ts +2 -3
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.js.map +1 -1
- package/dist/generated/abi/DataPortabilityServersImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataPortabilityServersImplementation.d.ts +2 -3
- package/dist/generated/abi/DataPortabilityServersImplementation.js.map +1 -1
- package/dist/generated/abi/DataRefinerRegistryImplementation.d.ts +2 -3
- package/dist/generated/abi/DataRegistryImplementation.d.ts +2 -3
- 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.d.ts +37 -39
- package/dist/generated/event-types.d.ts +9 -10
- package/dist/generated/eventRegistry.d.ts +3 -7
- 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 +47 -96
- package/dist/index.browser.js +12 -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 +14 -3
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.ts +203 -87
- package/dist/index.node.js +14 -2
- package/dist/index.node.js.map +1 -1
- 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/server/relayerHandler.cjs +337 -0
- package/dist/server/relayerHandler.cjs.map +1 -0
- package/dist/server/relayerHandler.d.ts +38 -0
- package/dist/server/relayerHandler.js +313 -0
- package/dist/server/relayerHandler.js.map +1 -0
- package/dist/storage/index.d.ts +56 -10
- package/dist/storage/manager.cjs +110 -27
- 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/types/blockchain.cjs.map +1 -1
- package/dist/types/blockchain.d.ts +46 -13
- 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.map +1 -1
- package/dist/types/controller-context.d.ts +17 -21
- package/dist/types/data.cjs.map +1 -1
- package/dist/types/data.d.ts +111 -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 +47 -22
- package/dist/types/index.js +9 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/operations.cjs +2 -2
- package/dist/types/operations.cjs.map +1 -1
- package/dist/types/operations.d.ts +178 -32
- 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 +213 -0
- package/dist/types/options.js +1 -0
- package/dist/types/options.js.map +1 -0
- package/dist/types/permissions.cjs.map +1 -1
- package/dist/types/permissions.d.ts +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.d.ts +16 -18
- package/dist/types/utils.cjs.map +1 -1
- package/dist/types/utils.d.ts +20 -68
- package/dist/types.d.ts +4 -28
- 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.map +1 -1
- package/dist/utils/parseTransactionPojo.d.ts +4 -10
- package/dist/utils/parseTransactionPojo.js.map +1 -1
- 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.map +1 -1
- package/dist/utils/transactionHelpers.d.ts +17 -23
- package/dist/utils/transactionHelpers.js.map +1 -1
- 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.map +1 -1
- package/dist/utils/withEvents.d.ts +5 -12
- package/dist/utils/withEvents.js.map +1 -1
- package/package.json +24 -16
- 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 +0 -37
- 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 -401
- package/dist/config/chains.d.cts +0 -85
- package/dist/config/features.d.cts +0 -64
- package/dist/contracts/contractController.d.cts +0 -117
- package/dist/controllers/data.d.cts +0 -915
- package/dist/controllers/permissions.d.cts +0 -1383
- package/dist/controllers/protocol.d.cts +0 -188
- package/dist/controllers/schemas.d.cts +0 -260
- package/dist/controllers/server.d.cts +0 -230
- 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 -493
- 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/test-vectors/eccrypto-vectors.d.cts +0 -76
- package/dist/crypto/ecies/test-vectors/eccrypto-vectors.d.ts +0 -76
- 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 -1014
- 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 -26547
- package/dist/generated/event-types.d.cts +0 -855
- package/dist/generated/eventRegistry.d.cts +0 -18
- 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 -201
- package/dist/index.d.cts +0 -2
- package/dist/index.node.d.cts +0 -87
- package/dist/node.d.cts +0 -2
- 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/schemas/dataSchema.schema.d.cts +0 -88
- package/dist/schemas/dataSchema.schema.d.ts +0 -88
- package/dist/schemas/grantFile.schema.d.cts +0 -57
- package/dist/schemas/grantFile.schema.d.ts +0 -57
- package/dist/server/handler.cjs +0 -101
- package/dist/server/handler.cjs.map +0 -1
- package/dist/server/handler.d.cts +0 -306
- package/dist/server/handler.d.ts +0 -306
- 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/blockchain.d.cts +0 -52
- 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/controller-context.d.cts +0 -71
- 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 -22
- package/dist/types/operations.d.cts +0 -116
- 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 -195
- package/dist/types/utils.d.cts +0 -819
- package/dist/types.d.cts +0 -54
- 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/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/parseTransactionPojo.d.cts +0 -37
- 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/transactionHelpers.d.cts +0 -86
- package/dist/utils/typedDataConverter.d.cts +0 -13
- package/dist/utils/urlResolver.d.cts +0 -40
- package/dist/utils/withEvents.d.cts +0 -63
|
@@ -32,18 +32,23 @@ __export(data_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(data_exports);
|
|
34
34
|
var import_viem = require("viem");
|
|
35
|
+
var import_base = require("./base");
|
|
35
36
|
var import_addresses = require("../config/addresses");
|
|
36
37
|
var import_abi = require("../generated/abi");
|
|
37
38
|
var import_subgraph = require("../generated/subgraph");
|
|
38
39
|
var import_graphql = require("graphql");
|
|
40
|
+
var import_subgraphConsistency = require("../utils/subgraphConsistency");
|
|
41
|
+
var import_subgraphPagination = require("../utils/subgraphPagination");
|
|
42
|
+
var import_chainQuery = require("../utils/chainQuery");
|
|
39
43
|
var import_encryption = require("../utils/encryption");
|
|
40
44
|
var import_schemaValidation = require("../utils/schemaValidation");
|
|
41
45
|
var import_multicall = require("../utils/multicall");
|
|
42
|
-
class DataController {
|
|
46
|
+
class DataController extends import_base.BaseController {
|
|
43
47
|
constructor(context) {
|
|
44
|
-
|
|
48
|
+
super(context);
|
|
45
49
|
}
|
|
46
50
|
async upload(params) {
|
|
51
|
+
this.assertWallet();
|
|
47
52
|
const {
|
|
48
53
|
content,
|
|
49
54
|
filename,
|
|
@@ -68,15 +73,28 @@ class DataController {
|
|
|
68
73
|
} catch {
|
|
69
74
|
parsedContent = content;
|
|
70
75
|
}
|
|
76
|
+
} else if (content instanceof Blob) {
|
|
77
|
+
const text = await content.text();
|
|
78
|
+
try {
|
|
79
|
+
parsedContent = JSON.parse(text);
|
|
80
|
+
} catch {
|
|
81
|
+
parsedContent = text;
|
|
82
|
+
}
|
|
71
83
|
} else {
|
|
72
84
|
parsedContent = content;
|
|
73
85
|
}
|
|
74
86
|
(0, import_schemaValidation.validateDataAgainstSchema)(parsedContent, schema);
|
|
75
87
|
} catch (error) {
|
|
76
88
|
isValid = false;
|
|
77
|
-
|
|
78
|
-
error
|
|
79
|
-
|
|
89
|
+
if (error instanceof Error) {
|
|
90
|
+
if (typeof error === "object" && "errors" in error && Array.isArray(error.errors)) {
|
|
91
|
+
validationErrors = error.errors;
|
|
92
|
+
} else {
|
|
93
|
+
validationErrors = [error.message];
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
validationErrors = ["Schema validation failed"];
|
|
97
|
+
}
|
|
80
98
|
}
|
|
81
99
|
}
|
|
82
100
|
const uploadResult = await this.uploadToStorage(
|
|
@@ -85,9 +103,10 @@ class DataController {
|
|
|
85
103
|
encrypt,
|
|
86
104
|
providerName
|
|
87
105
|
);
|
|
88
|
-
const userAddress = owner
|
|
106
|
+
const userAddress = owner ?? this.context.userAddress;
|
|
89
107
|
let encryptedPermissions = [];
|
|
90
108
|
if (permissions.length > 0 && encrypt) {
|
|
109
|
+
this.assertWallet();
|
|
91
110
|
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
92
111
|
this.context.walletClient,
|
|
93
112
|
this.context.platform,
|
|
@@ -108,37 +127,45 @@ class DataController {
|
|
|
108
127
|
);
|
|
109
128
|
}
|
|
110
129
|
let result;
|
|
111
|
-
if (this.context.
|
|
112
|
-
|
|
113
|
-
|
|
130
|
+
if (this.context.relayer) {
|
|
131
|
+
const request = {
|
|
132
|
+
type: "direct",
|
|
133
|
+
operation: "submitFileAdditionComplete",
|
|
134
|
+
params: {
|
|
114
135
|
url: uploadResult.url,
|
|
115
136
|
userAddress,
|
|
116
137
|
permissions: encryptedPermissions,
|
|
117
|
-
schemaId: schemaId
|
|
138
|
+
schemaId: schemaId ?? 0,
|
|
118
139
|
ownerAddress: owner
|
|
119
140
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
throw new Error(
|
|
125
|
-
"The configured relay callback does not support schemas or permissions. Please update your relay server implementation to provide the `submitFileAdditionComplete` callback."
|
|
126
|
-
);
|
|
141
|
+
};
|
|
142
|
+
const response = await this.context.relayer(request);
|
|
143
|
+
if (response.type === "error") {
|
|
144
|
+
throw new Error(response.error);
|
|
127
145
|
}
|
|
128
|
-
result
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
146
|
+
if (response.type !== "direct" || typeof response.result !== "object" || response.result === null || !("fileId" in response.result)) {
|
|
147
|
+
throw new Error("Invalid response from relayer");
|
|
148
|
+
}
|
|
149
|
+
result = response.result;
|
|
132
150
|
} else {
|
|
133
|
-
const txResult = await this.
|
|
151
|
+
const txResult = await this.addFileWithEncryptedPermissionsAndSchema(
|
|
134
152
|
uploadResult.url,
|
|
135
153
|
userAddress,
|
|
136
154
|
encryptedPermissions,
|
|
137
|
-
schemaId
|
|
155
|
+
schemaId ?? 0
|
|
138
156
|
);
|
|
157
|
+
if (!this.context.waitForTransactionEvents) {
|
|
158
|
+
throw new Error(
|
|
159
|
+
"Cannot upload without relay: waitForTransactionEvents not configured"
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
const eventResult = await this.context.waitForTransactionEvents(txResult);
|
|
163
|
+
const fileAddedEvent = eventResult.expectedEvents.FileAdded;
|
|
164
|
+
if (!fileAddedEvent) {
|
|
165
|
+
throw new Error("FileAdded event not found in transaction");
|
|
166
|
+
}
|
|
139
167
|
result = {
|
|
140
|
-
fileId:
|
|
141
|
-
// Placeholder - actual fileId available after waiting for events
|
|
168
|
+
fileId: Number(fileAddedEvent.fileId),
|
|
142
169
|
transactionHash: txResult.hash
|
|
143
170
|
};
|
|
144
171
|
}
|
|
@@ -157,35 +184,110 @@ class DataController {
|
|
|
157
184
|
}
|
|
158
185
|
}
|
|
159
186
|
/**
|
|
160
|
-
*
|
|
187
|
+
* Encrypts data using wallet-derived encryption.
|
|
161
188
|
*
|
|
162
189
|
* @remarks
|
|
163
|
-
* This
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
* decryption.
|
|
190
|
+
* This method provides secure, wallet-based encryption for data before uploading
|
|
191
|
+
* to the Vana network. It's the counterpart to decryptFile for preparing data
|
|
192
|
+
* for secure storage.
|
|
167
193
|
*
|
|
168
194
|
* The method automatically:
|
|
169
|
-
* - Generates
|
|
170
|
-
* -
|
|
171
|
-
* -
|
|
172
|
-
* -
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
* @param
|
|
179
|
-
* @
|
|
180
|
-
* @
|
|
181
|
-
* @
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
195
|
+
* - Generates an encryption key from the user's wallet signature
|
|
196
|
+
* - Converts the input data to a Blob if necessary
|
|
197
|
+
* - Encrypts the data using the generated key
|
|
198
|
+
* - Returns both the encrypted data and the encryption key
|
|
199
|
+
*
|
|
200
|
+
* The encryption key returned can be stored and later used for decryption,
|
|
201
|
+
* or shared with others to grant them decryption access.
|
|
202
|
+
*
|
|
203
|
+
* @param data - The data to encrypt (Blob, string, or object)
|
|
204
|
+
* @param options - Optional encryption configuration
|
|
205
|
+
* @returns Promise resolving to encrypted data and the encryption key used
|
|
206
|
+
* @throws {Error} When wallet is not connected or encryption fails
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* // Encrypt a string
|
|
210
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
211
|
+
* "My secret data"
|
|
212
|
+
* );
|
|
213
|
+
*
|
|
214
|
+
* // Encrypt JSON with custom MIME type
|
|
215
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
216
|
+
* { name: "Alice", age: 30 },
|
|
217
|
+
* { mimeType: "application/json" }
|
|
218
|
+
* );
|
|
219
|
+
*
|
|
220
|
+
* // With custom encryption seed
|
|
221
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
222
|
+
* "Secret message",
|
|
223
|
+
* { seed: "My custom encryption seed" }
|
|
224
|
+
* );
|
|
225
|
+
*
|
|
226
|
+
* // Upload the encrypted data
|
|
227
|
+
* const result = await vana.data.uploadToStorage(encryptedData);
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
async encryptFile(data, options) {
|
|
231
|
+
this.assertWallet();
|
|
232
|
+
try {
|
|
233
|
+
const encryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
234
|
+
this.context.walletClient,
|
|
235
|
+
this.context.platform,
|
|
236
|
+
options?.seed ?? import_encryption.DEFAULT_ENCRYPTION_SEED
|
|
237
|
+
);
|
|
238
|
+
let blob;
|
|
239
|
+
if (data instanceof Blob) {
|
|
240
|
+
blob = data;
|
|
241
|
+
} else if (typeof data === "string") {
|
|
242
|
+
blob = new Blob([data], { type: options?.mimeType ?? "text/plain" });
|
|
243
|
+
} else {
|
|
244
|
+
blob = new Blob([JSON.stringify(data)], {
|
|
245
|
+
type: options?.mimeType ?? "application/json"
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
const encryptedData = await (0, import_encryption.encryptBlobWithSignedKey)(
|
|
249
|
+
blob,
|
|
250
|
+
encryptionKey,
|
|
251
|
+
this.context.platform
|
|
252
|
+
);
|
|
253
|
+
return {
|
|
254
|
+
encryptedData,
|
|
255
|
+
encryptionKey
|
|
256
|
+
};
|
|
257
|
+
} catch (error) {
|
|
258
|
+
throw new Error(
|
|
259
|
+
`Failed to encrypt file: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Decrypts a file using wallet-derived decryption key.
|
|
265
|
+
*
|
|
266
|
+
* @remarks
|
|
267
|
+
* Counterpart to `upload()` for decrypting user files. Automatically
|
|
268
|
+
* generates decryption key from wallet, fetches encrypted content,
|
|
269
|
+
* and decrypts. Supports IPFS (with gateway fallback) and HTTP URLs.
|
|
270
|
+
*
|
|
271
|
+
* @param file - UserFile object from `getUserFiles()`
|
|
272
|
+
* @param options - Decryption options
|
|
273
|
+
* @param options.seed - Custom encryption seed.
|
|
274
|
+
* Defaults to standard Vana seed.
|
|
275
|
+
*
|
|
276
|
+
* @returns Decrypted content as Blob
|
|
277
|
+
*
|
|
278
|
+
* @throws {Error} No wallet connected.
|
|
279
|
+
* Connect wallet before decrypting.
|
|
280
|
+
* @throws {Error} Network error accessing file.
|
|
281
|
+
* Check CORS settings or server availability.
|
|
282
|
+
* @throws {Error} File not found (404).
|
|
283
|
+
* File no longer available at stored URL.
|
|
284
|
+
* @throws {Error} Access denied (403).
|
|
285
|
+
* No permission to access file.
|
|
286
|
+
* @throws {Error} Invalid file format.
|
|
287
|
+
* File not encrypted with Vana protocol.
|
|
288
|
+
* @throws {Error} Wrong encryption key.
|
|
289
|
+
* Verify seed matches upload or use default.
|
|
290
|
+
*
|
|
189
291
|
* @example
|
|
190
292
|
* ```typescript
|
|
191
293
|
* // Basic file decryption
|
|
@@ -211,12 +313,14 @@ class DataController {
|
|
|
211
313
|
* fs.writeFileSync('decrypted-file.txt', Buffer.from(buffer));
|
|
212
314
|
* ```
|
|
213
315
|
*/
|
|
214
|
-
async decryptFile(file,
|
|
316
|
+
async decryptFile(file, options) {
|
|
317
|
+
this.assertWallet();
|
|
215
318
|
try {
|
|
319
|
+
this.assertWallet();
|
|
216
320
|
const encryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
217
321
|
this.context.walletClient,
|
|
218
322
|
this.context.platform,
|
|
219
|
-
|
|
323
|
+
options?.seed ?? import_encryption.DEFAULT_ENCRYPTION_SEED
|
|
220
324
|
);
|
|
221
325
|
let encryptedBlob;
|
|
222
326
|
try {
|
|
@@ -299,99 +403,126 @@ class DataController {
|
|
|
299
403
|
}
|
|
300
404
|
}
|
|
301
405
|
/**
|
|
302
|
-
* Retrieves all
|
|
406
|
+
* Retrieves all files owned by a specific user address.
|
|
303
407
|
*
|
|
304
408
|
* @remarks
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
* @
|
|
316
|
-
*
|
|
317
|
-
* @
|
|
318
|
-
*
|
|
319
|
-
* @throws {Error}
|
|
320
|
-
*
|
|
321
|
-
* @throws {Error}
|
|
409
|
+
* Queries the Vana subgraph for files owned by the specified address.
|
|
410
|
+
* Automatically deduplicates by file ID, keeping the latest version
|
|
411
|
+
* when duplicates exist from re-indexing or chain reorganizations.
|
|
412
|
+
* Enriches results with DLP proof data when available.
|
|
413
|
+
*
|
|
414
|
+
* @param params - Query configuration
|
|
415
|
+
* @param params.owner - Wallet address of the file owner
|
|
416
|
+
* @param params.subgraphUrl - Subgraph endpoint override.
|
|
417
|
+
* Defaults to context configuration.
|
|
418
|
+
*
|
|
419
|
+
* @returns Array of UserFile objects sorted by timestamp (newest first)
|
|
420
|
+
*
|
|
421
|
+
* @throws {Error} Subgraph URL not configured.
|
|
422
|
+
* Provide `subgraphUrl` parameter or configure in Vana constructor.
|
|
423
|
+
* @throws {Error} Subgraph request failed.
|
|
424
|
+
* Check network connectivity and subgraph availability.
|
|
425
|
+
* @throws {Error} Subgraph returned errors.
|
|
426
|
+
* Review query parameters and subgraph logs.
|
|
427
|
+
*
|
|
322
428
|
* @example
|
|
323
429
|
* ```typescript
|
|
324
|
-
* // Query files for a specific user
|
|
325
430
|
* const files = await vana.data.getUserFiles({
|
|
326
|
-
* owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
|
|
431
|
+
* owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
|
|
327
432
|
* });
|
|
328
433
|
*
|
|
329
434
|
* files.forEach(file => {
|
|
330
|
-
* console.log(`File ${file.id}: ${file.url}
|
|
435
|
+
* console.log(`File ${file.id}: ${file.url}`);
|
|
436
|
+
* console.log(` Schema: ${file.schemaId}`);
|
|
437
|
+
* console.log(` DLPs: ${file.dlpIds?.join(", ") || "none"}`);
|
|
331
438
|
* });
|
|
332
439
|
* ```
|
|
333
440
|
*/
|
|
334
|
-
async getUserFiles(params) {
|
|
441
|
+
async getUserFiles(params, options) {
|
|
335
442
|
const { owner, subgraphUrl } = params;
|
|
336
|
-
|
|
443
|
+
let dataSource = options?.source === "chain" ? "chain" : "subgraph";
|
|
444
|
+
if (options?.source === "auto" || !options?.source && options?.minBlock) {
|
|
445
|
+
const endpoint2 = subgraphUrl ?? this.context.subgraphUrl;
|
|
446
|
+
const currentBlock = await this.context.publicClient.getBlockNumber();
|
|
447
|
+
let subgraphBlock;
|
|
448
|
+
if (endpoint2) {
|
|
449
|
+
try {
|
|
450
|
+
const meta = await (0, import_subgraphConsistency.fetchSubgraphMeta)(endpoint2);
|
|
451
|
+
subgraphBlock = meta.blockNumber;
|
|
452
|
+
} catch {
|
|
453
|
+
subgraphBlock = void 0;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
dataSource = (0, import_chainQuery.determineDataSource)(
|
|
457
|
+
options?.source,
|
|
458
|
+
options?.minBlock,
|
|
459
|
+
currentBlock,
|
|
460
|
+
subgraphBlock
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
if (dataSource === "chain") {
|
|
464
|
+
const publicClient = this.context.publicClient;
|
|
465
|
+
const chainId = await publicClient.getChainId();
|
|
466
|
+
const contractAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
467
|
+
const files = await (0, import_chainQuery.getUserFilesFromChain)(
|
|
468
|
+
publicClient,
|
|
469
|
+
contractAddress,
|
|
470
|
+
owner,
|
|
471
|
+
options?.minBlock ? BigInt(options.minBlock) : void 0
|
|
472
|
+
);
|
|
473
|
+
const limit = options?.fetchAll ? files.length : options?.limit ?? 100;
|
|
474
|
+
const offset = options?.offset ?? 0;
|
|
475
|
+
return files.slice(offset, offset + limit);
|
|
476
|
+
}
|
|
477
|
+
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
337
478
|
if (!endpoint) {
|
|
338
479
|
throw new Error(
|
|
339
480
|
"subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor."
|
|
340
481
|
);
|
|
341
482
|
}
|
|
483
|
+
if (options?.minBlock || options?.waitForSync) {
|
|
484
|
+
await (0, import_subgraphConsistency.checkSubgraphConsistency)(endpoint, options);
|
|
485
|
+
}
|
|
342
486
|
try {
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
487
|
+
const orderByMap = {
|
|
488
|
+
id: "id",
|
|
489
|
+
addedAtBlock: "addedAtBlock",
|
|
490
|
+
addedAtTimestamp: "addedAtTimestamp",
|
|
491
|
+
url: "url",
|
|
492
|
+
schemaId: "schemaId"
|
|
493
|
+
};
|
|
494
|
+
const allFiles = await (0, import_subgraphPagination.executePaginatedQuery)({
|
|
495
|
+
endpoint,
|
|
496
|
+
document: import_subgraph.GetUserFilesPaginatedDocument,
|
|
497
|
+
baseVariables: {
|
|
498
|
+
userId: owner.toLowerCase(),
|
|
499
|
+
// Subgraph requires lowercase addresses
|
|
500
|
+
orderBy: (0, import_subgraphPagination.mapOrderByToEnum)(
|
|
501
|
+
options?.orderBy,
|
|
502
|
+
orderByMap,
|
|
503
|
+
"addedAtBlock"
|
|
504
|
+
),
|
|
505
|
+
orderDirection: (0, import_subgraphPagination.mapOrderDirection)(
|
|
506
|
+
options?.orderDirection,
|
|
507
|
+
"asc",
|
|
508
|
+
"desc"
|
|
509
|
+
)
|
|
347
510
|
},
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
// Subgraph requires lowercase addresses
|
|
353
|
-
}
|
|
354
|
-
})
|
|
355
|
-
});
|
|
356
|
-
if (!response.ok) {
|
|
357
|
-
throw new Error(
|
|
358
|
-
`Subgraph request failed: ${response.status} ${response.statusText}`
|
|
359
|
-
);
|
|
360
|
-
}
|
|
361
|
-
const result = await response.json();
|
|
362
|
-
if (result.errors) {
|
|
363
|
-
throw new Error(
|
|
364
|
-
`Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
365
|
-
);
|
|
366
|
-
}
|
|
367
|
-
const user = result.data?.user;
|
|
368
|
-
if (!user || !user.files?.length) {
|
|
369
|
-
console.warn("No files found for user:", owner);
|
|
370
|
-
return [];
|
|
371
|
-
}
|
|
372
|
-
const fileMap = /* @__PURE__ */ new Map();
|
|
373
|
-
user.files.forEach((file) => {
|
|
374
|
-
const fileId = parseInt(file.id);
|
|
375
|
-
const userFile = {
|
|
376
|
-
id: fileId,
|
|
511
|
+
options,
|
|
512
|
+
extractItems: (data) => data?.user?.files,
|
|
513
|
+
transformItem: (file) => ({
|
|
514
|
+
id: parseInt(file.id),
|
|
377
515
|
url: file.url,
|
|
378
516
|
ownerAddress: file.owner.id,
|
|
379
517
|
addedAtBlock: BigInt(file.addedAtBlock),
|
|
380
518
|
schemaId: parseInt(file.schemaId),
|
|
381
519
|
addedAtTimestamp: BigInt(file.addedAtTimestamp),
|
|
382
520
|
transactionHash: file.transactionHash
|
|
383
|
-
}
|
|
384
|
-
const existing = fileMap.get(fileId);
|
|
385
|
-
if (!existing || userFile.addedAtTimestamp && existing.addedAtTimestamp && userFile.addedAtTimestamp > existing.addedAtTimestamp) {
|
|
386
|
-
fileMap.set(fileId, userFile);
|
|
387
|
-
}
|
|
521
|
+
})
|
|
388
522
|
});
|
|
389
|
-
|
|
390
|
-
(a, b) => Number((b.addedAtTimestamp || 0n) - (a.addedAtTimestamp || 0n))
|
|
391
|
-
);
|
|
392
|
-
if (userFiles.length > 0) {
|
|
523
|
+
if (allFiles.length > 0) {
|
|
393
524
|
try {
|
|
394
|
-
const fileIds =
|
|
525
|
+
const fileIds = allFiles.map((f) => f.id);
|
|
395
526
|
let proofMap;
|
|
396
527
|
try {
|
|
397
528
|
proofMap = await this._fetchProofsFromSubgraph(fileIds, endpoint);
|
|
@@ -402,7 +533,7 @@ class DataController {
|
|
|
402
533
|
);
|
|
403
534
|
proofMap = await this._fetchProofsFromChain(fileIds);
|
|
404
535
|
}
|
|
405
|
-
for (const file of
|
|
536
|
+
for (const file of allFiles) {
|
|
406
537
|
const dlpIds = proofMap.get(file.id);
|
|
407
538
|
if (dlpIds && dlpIds.length > 0) {
|
|
408
539
|
file.dlpIds = dlpIds;
|
|
@@ -412,7 +543,7 @@ class DataController {
|
|
|
412
543
|
console.warn("Failed to fetch proof data for files:", error);
|
|
413
544
|
}
|
|
414
545
|
}
|
|
415
|
-
return
|
|
546
|
+
return allFiles;
|
|
416
547
|
} catch (error) {
|
|
417
548
|
console.error("Failed to fetch user files from subgraph:", error);
|
|
418
549
|
throw new Error(
|
|
@@ -458,10 +589,11 @@ class DataController {
|
|
|
458
589
|
if (proof.dlp?.id) {
|
|
459
590
|
const fileId = parseInt(proof.fileId);
|
|
460
591
|
const dlpId = parseInt(proof.dlp.id);
|
|
461
|
-
|
|
462
|
-
|
|
592
|
+
let dlpIds = proofMap.get(fileId);
|
|
593
|
+
if (!dlpIds) {
|
|
594
|
+
dlpIds = [];
|
|
595
|
+
proofMap.set(fileId, dlpIds);
|
|
463
596
|
}
|
|
464
|
-
const dlpIds = proofMap.get(fileId);
|
|
465
597
|
if (!dlpIds.includes(dlpId)) {
|
|
466
598
|
dlpIds.push(dlpId);
|
|
467
599
|
}
|
|
@@ -479,7 +611,7 @@ class DataController {
|
|
|
479
611
|
* @returns Map of file IDs to their associated DLP IDs
|
|
480
612
|
*/
|
|
481
613
|
async _fetchProofsFromChain(fileIds) {
|
|
482
|
-
const chainId = this.context.
|
|
614
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
483
615
|
if (!chainId) {
|
|
484
616
|
throw new Error("Chain ID not available");
|
|
485
617
|
}
|
|
@@ -536,7 +668,10 @@ class DataController {
|
|
|
536
668
|
* ```
|
|
537
669
|
*/
|
|
538
670
|
async getDLP(dlpId, options = {}) {
|
|
539
|
-
const subgraphUrl = options.subgraphUrl
|
|
671
|
+
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
672
|
+
if (subgraphUrl && (options.minBlock || options.waitForSync)) {
|
|
673
|
+
await (0, import_subgraphConsistency.checkSubgraphConsistency)(subgraphUrl, options);
|
|
674
|
+
}
|
|
540
675
|
if (subgraphUrl) {
|
|
541
676
|
try {
|
|
542
677
|
const response = await fetch(subgraphUrl, {
|
|
@@ -567,18 +702,18 @@ class DataController {
|
|
|
567
702
|
}
|
|
568
703
|
return {
|
|
569
704
|
id: parseInt(result.data.dlp.id),
|
|
570
|
-
name: result.data.dlp.name
|
|
571
|
-
metadata: result.data.dlp.metadata
|
|
705
|
+
name: result.data.dlp.name ?? "",
|
|
706
|
+
metadata: result.data.dlp.metadata ?? void 0,
|
|
572
707
|
status: result.data.dlp.status ? parseInt(result.data.dlp.status) : void 0,
|
|
573
|
-
address: result.data.dlp.address,
|
|
574
|
-
owner: result.data.dlp.owner
|
|
708
|
+
address: result.data.dlp.address ? result.data.dlp.address : void 0,
|
|
709
|
+
owner: result.data.dlp.owner ? result.data.dlp.owner : void 0
|
|
575
710
|
};
|
|
576
711
|
} catch (error) {
|
|
577
712
|
console.debug("Subgraph query failed, falling back to chain:", error);
|
|
578
713
|
}
|
|
579
714
|
}
|
|
580
715
|
try {
|
|
581
|
-
const chainId = this.context.
|
|
716
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
582
717
|
if (!chainId) {
|
|
583
718
|
throw new Error("Chain ID not available");
|
|
584
719
|
}
|
|
@@ -590,7 +725,7 @@ class DataController {
|
|
|
590
725
|
functionName: "dlps",
|
|
591
726
|
args: [BigInt(dlpId)]
|
|
592
727
|
});
|
|
593
|
-
if (!dlpData
|
|
728
|
+
if (!dlpData?.name) {
|
|
594
729
|
throw new Error(`DLP not found: ${dlpId}`);
|
|
595
730
|
}
|
|
596
731
|
return {
|
|
@@ -632,7 +767,7 @@ class DataController {
|
|
|
632
767
|
*/
|
|
633
768
|
async listDLPs(options = {}) {
|
|
634
769
|
const { limit = 100, offset = 0 } = options;
|
|
635
|
-
const subgraphUrl = options.subgraphUrl
|
|
770
|
+
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
636
771
|
if (subgraphUrl) {
|
|
637
772
|
try {
|
|
638
773
|
const query = `
|
|
@@ -671,21 +806,21 @@ class DataController {
|
|
|
671
806
|
`Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
672
807
|
);
|
|
673
808
|
}
|
|
674
|
-
const dlps = result.data?.dlps
|
|
809
|
+
const dlps = result.data?.dlps ?? [];
|
|
675
810
|
return dlps.map((dlp) => ({
|
|
676
811
|
id: parseInt(dlp.id),
|
|
677
|
-
name: dlp.name
|
|
812
|
+
name: dlp.name ?? "",
|
|
678
813
|
metadata: dlp.metadata,
|
|
679
814
|
status: dlp.status ? parseInt(dlp.status) : void 0,
|
|
680
|
-
address: dlp.address,
|
|
681
|
-
owner: dlp.owner
|
|
815
|
+
address: dlp.address ? dlp.address : void 0,
|
|
816
|
+
owner: dlp.owner ? dlp.owner : void 0
|
|
682
817
|
}));
|
|
683
818
|
} catch (error) {
|
|
684
819
|
console.debug("Subgraph query failed, falling back to chain:", error);
|
|
685
820
|
}
|
|
686
821
|
}
|
|
687
822
|
try {
|
|
688
|
-
const chainId = this.context.
|
|
823
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
689
824
|
if (!chainId) {
|
|
690
825
|
throw new Error("Chain ID not available");
|
|
691
826
|
}
|
|
@@ -755,21 +890,33 @@ class DataController {
|
|
|
755
890
|
* @returns Promise resolving to an array of permission objects
|
|
756
891
|
* @throws Error if both subgraph and RPC queries fail
|
|
757
892
|
*/
|
|
758
|
-
async getUserPermissions(params) {
|
|
893
|
+
async getUserPermissions(params, options) {
|
|
759
894
|
const { user, subgraphUrl } = params;
|
|
760
|
-
const endpoint = subgraphUrl
|
|
895
|
+
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
896
|
+
if (endpoint && (options?.minBlock || options?.waitForSync)) {
|
|
897
|
+
await (0, import_subgraphConsistency.checkSubgraphConsistency)(endpoint, options);
|
|
898
|
+
}
|
|
761
899
|
if (endpoint) {
|
|
762
900
|
try {
|
|
763
|
-
const permissions = await this._getUserPermissionsViaSubgraph(
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
901
|
+
const permissions = await this._getUserPermissionsViaSubgraph(
|
|
902
|
+
{
|
|
903
|
+
user,
|
|
904
|
+
subgraphUrl: endpoint
|
|
905
|
+
},
|
|
906
|
+
options
|
|
907
|
+
);
|
|
767
908
|
return permissions;
|
|
768
909
|
} catch (error) {
|
|
769
910
|
console.warn("Subgraph query failed, falling back to RPC:", error);
|
|
770
911
|
}
|
|
771
912
|
}
|
|
772
|
-
|
|
913
|
+
const allPermissions = await this._getUserPermissionsViaRpc({ user });
|
|
914
|
+
if (options && !options.fetchAll) {
|
|
915
|
+
const limit = options.limit ?? 100;
|
|
916
|
+
const offset = options.offset ?? 0;
|
|
917
|
+
return allPermissions.slice(offset, offset + limit);
|
|
918
|
+
}
|
|
919
|
+
return allPermissions;
|
|
773
920
|
}
|
|
774
921
|
/**
|
|
775
922
|
* Internal method: Query user permissions via subgraph
|
|
@@ -779,46 +926,48 @@ class DataController {
|
|
|
779
926
|
* @param params.subgraphUrl - The subgraph URL endpoint to query
|
|
780
927
|
* @returns Promise resolving to an array of permission objects
|
|
781
928
|
*/
|
|
782
|
-
async _getUserPermissionsViaSubgraph(params) {
|
|
929
|
+
async _getUserPermissionsViaSubgraph(params, options) {
|
|
783
930
|
const { user, subgraphUrl } = params;
|
|
784
931
|
try {
|
|
785
|
-
const
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
932
|
+
const orderByMap = {
|
|
933
|
+
id: "id",
|
|
934
|
+
addedAtBlock: "addedAtBlock",
|
|
935
|
+
addedAtTimestamp: "addedAtTimestamp",
|
|
936
|
+
grant: "grant",
|
|
937
|
+
nonce: "nonce",
|
|
938
|
+
startBlock: "startBlock",
|
|
939
|
+
endBlock: "endBlock"
|
|
940
|
+
};
|
|
941
|
+
const permissions = await (0, import_subgraphPagination.executePaginatedQuery)({
|
|
942
|
+
endpoint: subgraphUrl,
|
|
943
|
+
document: import_subgraph.GetUserPermissionsPaginatedDocument,
|
|
944
|
+
baseVariables: {
|
|
945
|
+
userId: user.toLowerCase(),
|
|
946
|
+
orderBy: (0, import_subgraphPagination.mapOrderByToEnum)(
|
|
947
|
+
options?.orderBy,
|
|
948
|
+
orderByMap,
|
|
949
|
+
"addedAtTimestamp"
|
|
950
|
+
),
|
|
951
|
+
orderDirection: (0, import_subgraphPagination.mapOrderDirection)(
|
|
952
|
+
options?.orderDirection,
|
|
953
|
+
"desc",
|
|
954
|
+
"asc"
|
|
955
|
+
)
|
|
789
956
|
},
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
957
|
+
options,
|
|
958
|
+
extractItems: (data) => data?.user?.permissions,
|
|
959
|
+
transformItem: (permission) => ({
|
|
960
|
+
id: permission.id,
|
|
961
|
+
grant: permission.grant,
|
|
962
|
+
nonce: BigInt(permission.nonce),
|
|
963
|
+
signature: permission.signature,
|
|
964
|
+
addedAtBlock: BigInt(permission.addedAtBlock),
|
|
965
|
+
addedAtTimestamp: BigInt(permission.addedAtTimestamp),
|
|
966
|
+
transactionHash: permission.transactionHash,
|
|
967
|
+
user
|
|
795
968
|
})
|
|
796
969
|
});
|
|
797
|
-
|
|
798
|
-
throw new Error(
|
|
799
|
-
`Subgraph request failed: ${response.status} ${response.statusText}`
|
|
800
|
-
);
|
|
801
|
-
}
|
|
802
|
-
const result = await response.json();
|
|
803
|
-
if (result.errors) {
|
|
804
|
-
throw new Error(
|
|
805
|
-
`Subgraph query errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
806
|
-
);
|
|
807
|
-
}
|
|
808
|
-
const userData = result.data?.user;
|
|
809
|
-
if (!userData || !userData.permissions?.length) {
|
|
810
|
-
return [];
|
|
811
|
-
}
|
|
812
|
-
return userData.permissions.map((permission) => ({
|
|
813
|
-
id: permission.id,
|
|
814
|
-
grant: permission.grant,
|
|
815
|
-
nonce: BigInt(permission.nonce),
|
|
816
|
-
signature: permission.signature,
|
|
817
|
-
addedAtBlock: BigInt(permission.addedAtBlock),
|
|
818
|
-
addedAtTimestamp: BigInt(permission.addedAtTimestamp),
|
|
819
|
-
transactionHash: permission.transactionHash,
|
|
820
|
-
user
|
|
821
|
-
})).sort((a, b) => Number(b.addedAtTimestamp - a.addedAtTimestamp));
|
|
970
|
+
return permissions;
|
|
822
971
|
} catch (error) {
|
|
823
972
|
console.error("Failed to query user permissions from subgraph:", error);
|
|
824
973
|
throw error;
|
|
@@ -834,7 +983,7 @@ class DataController {
|
|
|
834
983
|
async _getUserPermissionsViaRpc(params) {
|
|
835
984
|
const { user } = params;
|
|
836
985
|
try {
|
|
837
|
-
const chainId = this.context.
|
|
986
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
838
987
|
if (!chainId) {
|
|
839
988
|
throw new Error("Chain ID not available");
|
|
840
989
|
}
|
|
@@ -951,20 +1100,28 @@ class DataController {
|
|
|
951
1100
|
* });
|
|
952
1101
|
* ```
|
|
953
1102
|
*/
|
|
954
|
-
async getUserTrustedServers(params) {
|
|
955
|
-
const { user
|
|
956
|
-
const subgraphUrl = params.subgraphUrl
|
|
1103
|
+
async getUserTrustedServers(params, options) {
|
|
1104
|
+
const { user } = params;
|
|
1105
|
+
const subgraphUrl = params.subgraphUrl ?? this.context.subgraphUrl;
|
|
1106
|
+
if (subgraphUrl && (options?.minBlock || options?.waitForSync)) {
|
|
1107
|
+
await (0, import_subgraphConsistency.checkSubgraphConsistency)(subgraphUrl, options);
|
|
1108
|
+
}
|
|
957
1109
|
if (subgraphUrl) {
|
|
958
1110
|
try {
|
|
959
|
-
const servers = await this._getUserTrustedServersViaSubgraph(
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
1111
|
+
const servers = await this._getUserTrustedServersViaSubgraph(
|
|
1112
|
+
{
|
|
1113
|
+
user,
|
|
1114
|
+
subgraphUrl
|
|
1115
|
+
},
|
|
1116
|
+
options
|
|
1117
|
+
);
|
|
1118
|
+
return servers;
|
|
964
1119
|
} catch (error) {
|
|
965
1120
|
console.warn("Subgraph query failed, falling back to RPC:", error);
|
|
966
1121
|
}
|
|
967
1122
|
}
|
|
1123
|
+
const limit = options?.fetchAll ? Number.MAX_SAFE_INTEGER : options?.limit ?? 100;
|
|
1124
|
+
const offset = options?.offset ?? 0;
|
|
968
1125
|
const rpcResult = await this._getUserTrustedServersViaRpc({
|
|
969
1126
|
user,
|
|
970
1127
|
limit,
|
|
@@ -980,7 +1137,7 @@ class DataController {
|
|
|
980
1137
|
* @param params.subgraphUrl - The subgraph URL endpoint to query
|
|
981
1138
|
* @returns Promise resolving to an array of trusted server objects
|
|
982
1139
|
*/
|
|
983
|
-
async _getUserTrustedServersViaSubgraph(params) {
|
|
1140
|
+
async _getUserTrustedServersViaSubgraph(params, options) {
|
|
984
1141
|
const { user, subgraphUrl } = params;
|
|
985
1142
|
const graphqlEndpoint = subgraphUrl;
|
|
986
1143
|
if (!graphqlEndpoint) {
|
|
@@ -989,42 +1146,46 @@ class DataController {
|
|
|
989
1146
|
);
|
|
990
1147
|
}
|
|
991
1148
|
try {
|
|
992
|
-
const
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
1149
|
+
const orderByMap = {
|
|
1150
|
+
id: "id",
|
|
1151
|
+
trustedAt: "trustedAt",
|
|
1152
|
+
trustedAtBlock: "trustedAtBlock",
|
|
1153
|
+
server: "server",
|
|
1154
|
+
user: "user"
|
|
1155
|
+
};
|
|
1156
|
+
const serverTrusts = await (0, import_subgraphPagination.executePaginatedQuery)({
|
|
1157
|
+
endpoint: graphqlEndpoint,
|
|
1158
|
+
document: import_subgraph.GetUserTrustedServersPaginatedDocument,
|
|
1159
|
+
baseVariables: {
|
|
1160
|
+
userId: user.toLowerCase(),
|
|
1161
|
+
// Subgraph requires lowercase addresses
|
|
1162
|
+
orderBy: (0, import_subgraphPagination.mapOrderByToEnum)(
|
|
1163
|
+
options?.orderBy,
|
|
1164
|
+
orderByMap,
|
|
1165
|
+
"trustedAtBlock"
|
|
1166
|
+
),
|
|
1167
|
+
orderDirection: (0, import_subgraphPagination.mapOrderDirection)(
|
|
1168
|
+
options?.orderDirection,
|
|
1169
|
+
"desc",
|
|
1170
|
+
"asc"
|
|
1171
|
+
)
|
|
996
1172
|
},
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1173
|
+
options,
|
|
1174
|
+
extractItems: (data) => {
|
|
1175
|
+
const trusts = data?.user?.serverTrusts ?? [];
|
|
1176
|
+
return trusts.filter((trust) => !trust.untrustedAtBlock);
|
|
1177
|
+
},
|
|
1178
|
+
transformItem: (trust) => ({
|
|
1179
|
+
id: trust.server.id,
|
|
1180
|
+
serverAddress: trust.server.serverAddress,
|
|
1181
|
+
serverUrl: trust.server.url,
|
|
1182
|
+
trustedAt: BigInt(trust.trustedAt),
|
|
1183
|
+
user,
|
|
1184
|
+
name: ""
|
|
1185
|
+
// Not available in new schema, will be empty
|
|
1003
1186
|
})
|
|
1004
1187
|
});
|
|
1005
|
-
|
|
1006
|
-
throw new Error(
|
|
1007
|
-
`Subgraph request failed: ${response.status} ${response.statusText}`
|
|
1008
|
-
);
|
|
1009
|
-
}
|
|
1010
|
-
const result = await response.json();
|
|
1011
|
-
if (result.errors) {
|
|
1012
|
-
throw new Error(
|
|
1013
|
-
`Subgraph query errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
1014
|
-
);
|
|
1015
|
-
}
|
|
1016
|
-
if (!result.data?.user) {
|
|
1017
|
-
return [];
|
|
1018
|
-
}
|
|
1019
|
-
return (result.data.user.serverTrusts || []).filter((trust) => !trust.untrustedAtBlock).map((trust) => ({
|
|
1020
|
-
id: trust.server.id,
|
|
1021
|
-
serverAddress: trust.server.serverAddress,
|
|
1022
|
-
serverUrl: trust.server.url,
|
|
1023
|
-
trustedAt: BigInt(trust.trustedAt),
|
|
1024
|
-
user,
|
|
1025
|
-
name: ""
|
|
1026
|
-
// Not available in new schema, will be empty
|
|
1027
|
-
}));
|
|
1188
|
+
return serverTrusts;
|
|
1028
1189
|
} catch (error) {
|
|
1029
1190
|
console.error("Failed to query trusted servers from subgraph:", error);
|
|
1030
1191
|
throw error;
|
|
@@ -1042,7 +1203,7 @@ class DataController {
|
|
|
1042
1203
|
async _getUserTrustedServersViaRpc(params) {
|
|
1043
1204
|
const { user, limit, offset } = params;
|
|
1044
1205
|
try {
|
|
1045
|
-
const chainId = this.context.
|
|
1206
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1046
1207
|
if (!chainId) {
|
|
1047
1208
|
throw new Error("Chain ID not available");
|
|
1048
1209
|
}
|
|
@@ -1126,23 +1287,31 @@ class DataController {
|
|
|
1126
1287
|
}
|
|
1127
1288
|
}
|
|
1128
1289
|
/**
|
|
1129
|
-
*
|
|
1290
|
+
* Retrieves total file count from Data Registry.
|
|
1291
|
+
*
|
|
1292
|
+
* @remarks
|
|
1293
|
+
* Queries blockchain for complete file count across all users.
|
|
1294
|
+
* Useful for pagination and network statistics.
|
|
1295
|
+
*
|
|
1296
|
+
* @returns Total number of registered files
|
|
1297
|
+
*
|
|
1298
|
+
* @throws {Error} Chain ID not available.
|
|
1299
|
+
* Ensure network connection.
|
|
1300
|
+
* @throws {Error} Contract read failed.
|
|
1301
|
+
* Check RPC availability.
|
|
1130
1302
|
*
|
|
1131
|
-
* @returns Promise resolving to the total file count
|
|
1132
1303
|
* @example
|
|
1133
1304
|
* ```typescript
|
|
1134
|
-
* const
|
|
1135
|
-
* console.log(`Total files
|
|
1305
|
+
* const total = await vana.data.getTotalFilesCount();
|
|
1306
|
+
* console.log(`Total files: ${total}`);
|
|
1136
1307
|
*
|
|
1137
|
-
* //
|
|
1138
|
-
* const
|
|
1139
|
-
* const totalPages = Math.ceil(totalFiles / filesPerPage);
|
|
1140
|
-
* console.log(`Total pages: ${totalPages}`);
|
|
1308
|
+
* // Calculate pagination
|
|
1309
|
+
* const pages = Math.ceil(total / 20);
|
|
1141
1310
|
* ```
|
|
1142
1311
|
*/
|
|
1143
1312
|
async getTotalFilesCount() {
|
|
1144
1313
|
try {
|
|
1145
|
-
const chainId = this.context.
|
|
1314
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1146
1315
|
if (!chainId) {
|
|
1147
1316
|
throw new Error("Chain ID not available");
|
|
1148
1317
|
}
|
|
@@ -1151,7 +1320,7 @@ class DataController {
|
|
|
1151
1320
|
const dataRegistry = (0, import_viem.getContract)({
|
|
1152
1321
|
address: dataRegistryAddress,
|
|
1153
1322
|
abi: dataRegistryAbi,
|
|
1154
|
-
client: this.context.
|
|
1323
|
+
client: this.context.publicClient
|
|
1155
1324
|
});
|
|
1156
1325
|
const count = await dataRegistry.read.filesCount();
|
|
1157
1326
|
return Number(count);
|
|
@@ -1164,36 +1333,36 @@ class DataController {
|
|
|
1164
1333
|
}
|
|
1165
1334
|
}
|
|
1166
1335
|
/**
|
|
1167
|
-
* Retrieves
|
|
1336
|
+
* Retrieves file metadata by ID from the blockchain.
|
|
1337
|
+
*
|
|
1338
|
+
* @remarks
|
|
1339
|
+
* Queries DataRegistry contract directly for file details.
|
|
1340
|
+
* Works for any file ID regardless of ownership, enabling
|
|
1341
|
+
* cross-user file discovery and verification.
|
|
1342
|
+
*
|
|
1343
|
+
* @param fileId - Numeric file ID to retrieve
|
|
1344
|
+
*
|
|
1345
|
+
* @returns UserFile object with metadata
|
|
1346
|
+
*
|
|
1347
|
+
* @throws {Error} Chain ID not available.
|
|
1348
|
+
* Ensure proper network connection.
|
|
1349
|
+
* @throws {Error} File not found.
|
|
1350
|
+
* Verify file ID exists on-chain.
|
|
1351
|
+
* @throws {Error} Contract call failed.
|
|
1352
|
+
* Check network and RPC availability.
|
|
1168
1353
|
*
|
|
1169
|
-
* @param fileId - The file ID to look up
|
|
1170
|
-
* @returns Promise resolving to UserFile object
|
|
1171
|
-
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1172
|
-
* @throws {Error} "File not found" - When file ID doesn't exist or returns empty data
|
|
1173
|
-
* @throws {Error} "Failed to fetch file {fileId}: {error}" - General contract read failures
|
|
1174
1354
|
* @example
|
|
1175
1355
|
* ```typescript
|
|
1176
|
-
*
|
|
1177
|
-
*
|
|
1178
|
-
*
|
|
1179
|
-
*
|
|
1180
|
-
*
|
|
1181
|
-
* owner: file.ownerAddress,
|
|
1182
|
-
* addedAt: file.addedAtBlock
|
|
1183
|
-
* });
|
|
1184
|
-
* } catch (error) {
|
|
1185
|
-
* console.error('File not found or error retrieving file:', error);
|
|
1186
|
-
* }
|
|
1356
|
+
* const file = await vana.data.getFileById(123);
|
|
1357
|
+
* console.log(`File ${file.id}:`);
|
|
1358
|
+
* console.log(` URL: ${file.url}`);
|
|
1359
|
+
* console.log(` Owner: ${file.ownerAddress}`);
|
|
1360
|
+
* console.log(` Block: ${file.addedAtBlock}`);
|
|
1187
1361
|
* ```
|
|
1188
|
-
*
|
|
1189
|
-
* This method queries the DataRegistry contract directly
|
|
1190
|
-
* to get file details for any file ID, regardless of user ownership.
|
|
1191
|
-
* This is useful for file lookup functionality where users can search
|
|
1192
|
-
* for specific files by ID.
|
|
1193
1362
|
*/
|
|
1194
1363
|
async getFileById(fileId) {
|
|
1195
1364
|
try {
|
|
1196
|
-
const chainId = this.context.
|
|
1365
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1197
1366
|
if (!chainId) {
|
|
1198
1367
|
throw new Error("Chain ID not available");
|
|
1199
1368
|
}
|
|
@@ -1202,7 +1371,7 @@ class DataController {
|
|
|
1202
1371
|
const dataRegistry = (0, import_viem.getContract)({
|
|
1203
1372
|
address: dataRegistryAddress,
|
|
1204
1373
|
abi: dataRegistryAbi,
|
|
1205
|
-
client: this.context.
|
|
1374
|
+
client: this.context.publicClient
|
|
1206
1375
|
});
|
|
1207
1376
|
const fileDetails = await dataRegistry.read.files([BigInt(fileId)]);
|
|
1208
1377
|
if (!fileDetails) {
|
|
@@ -1260,15 +1429,17 @@ class DataController {
|
|
|
1260
1429
|
* console.log(`File ${fileId} registered with schema in tx ${transactionHash}`);
|
|
1261
1430
|
* ```
|
|
1262
1431
|
*/
|
|
1263
|
-
async registerFileWithSchema(url, schemaId) {
|
|
1432
|
+
async registerFileWithSchema(url, schemaId, options) {
|
|
1433
|
+
this.assertWallet();
|
|
1264
1434
|
try {
|
|
1265
|
-
const chainId = this.context.
|
|
1435
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1266
1436
|
if (!chainId) {
|
|
1267
1437
|
throw new Error("Chain ID not available");
|
|
1268
1438
|
}
|
|
1439
|
+
this.assertWallet();
|
|
1269
1440
|
const dataRegistryAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
1270
1441
|
const dataRegistryAbi = (0, import_abi.getAbi)("DataRegistry");
|
|
1271
|
-
const account = this.context.walletClient.account
|
|
1442
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1272
1443
|
const from = typeof account === "string" ? account : account.address;
|
|
1273
1444
|
const hash = await this.context.walletClient.writeContract({
|
|
1274
1445
|
address: dataRegistryAddress,
|
|
@@ -1276,7 +1447,8 @@ class DataController {
|
|
|
1276
1447
|
functionName: "addFileWithSchema",
|
|
1277
1448
|
args: [url, BigInt(schemaId)],
|
|
1278
1449
|
account,
|
|
1279
|
-
chain: this.context.walletClient.chain
|
|
1450
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1451
|
+
...this.spreadTransactionOptions(options)
|
|
1280
1452
|
});
|
|
1281
1453
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1282
1454
|
return tx({
|
|
@@ -1298,13 +1470,6 @@ class DataController {
|
|
|
1298
1470
|
* @returns Promise resolving to the user's wallet address
|
|
1299
1471
|
* @throws {Error} When no addresses are available in wallet client
|
|
1300
1472
|
*/
|
|
1301
|
-
async getUserAddress() {
|
|
1302
|
-
const addresses = await this.context.walletClient.getAddresses();
|
|
1303
|
-
if (addresses.length === 0) {
|
|
1304
|
-
throw new Error("No addresses available in wallet client");
|
|
1305
|
-
}
|
|
1306
|
-
return addresses[0];
|
|
1307
|
-
}
|
|
1308
1473
|
/**
|
|
1309
1474
|
* Adds a file with permissions to the DataRegistry contract.
|
|
1310
1475
|
*
|
|
@@ -1321,15 +1486,17 @@ class DataController {
|
|
|
1321
1486
|
* with specific permissions on the DataRegistry contract. It can be used
|
|
1322
1487
|
* by both direct transactions and relayer services.
|
|
1323
1488
|
*/
|
|
1324
|
-
async addFileWithPermissions(url, ownerAddress, permissions = []) {
|
|
1489
|
+
async addFileWithPermissions(url, ownerAddress, permissions = [], options) {
|
|
1490
|
+
this.assertWallet();
|
|
1325
1491
|
try {
|
|
1326
|
-
const chainId = this.context.
|
|
1492
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1327
1493
|
if (!chainId) {
|
|
1328
1494
|
throw new Error("Chain ID not available");
|
|
1329
1495
|
}
|
|
1496
|
+
this.assertWallet();
|
|
1330
1497
|
const dataRegistryAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
1331
1498
|
const dataRegistryAbi = (0, import_abi.getAbi)("DataRegistry");
|
|
1332
|
-
const account = this.context.walletClient.account
|
|
1499
|
+
const account = this.context.walletClient.account ?? ownerAddress;
|
|
1333
1500
|
const from = typeof account === "string" ? account : account.address;
|
|
1334
1501
|
const hash = await this.context.walletClient.writeContract({
|
|
1335
1502
|
address: dataRegistryAddress,
|
|
@@ -1337,7 +1504,8 @@ class DataController {
|
|
|
1337
1504
|
functionName: "addFileWithPermissions",
|
|
1338
1505
|
args: [url, ownerAddress, permissions],
|
|
1339
1506
|
account,
|
|
1340
|
-
chain: this.context.walletClient.chain
|
|
1507
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1508
|
+
...this.spreadTransactionOptions(options)
|
|
1341
1509
|
});
|
|
1342
1510
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1343
1511
|
return tx({
|
|
@@ -1357,25 +1525,133 @@ class DataController {
|
|
|
1357
1525
|
* Adds a file to the registry with permissions and schema.
|
|
1358
1526
|
* This combines the functionality of addFileWithPermissions and schema validation.
|
|
1359
1527
|
*
|
|
1528
|
+
* @remarks
|
|
1529
|
+
* This method automatically encrypts permissions when a publicKey is provided.
|
|
1530
|
+
* It generates the user's encryption key and encrypts it with each recipient's
|
|
1531
|
+
* public key before registering on the blockchain.
|
|
1532
|
+
*
|
|
1360
1533
|
* @param url - The URL of the file to register
|
|
1361
1534
|
* @param ownerAddress - The address of the file owner
|
|
1362
|
-
* @param permissions - Array of permissions to grant
|
|
1535
|
+
* @param permissions - Array of permissions to grant, each with account and publicKey properties
|
|
1363
1536
|
* @param schemaId - The schema ID to associate with the file (0 for no schema)
|
|
1364
|
-
* @returns Promise resolving to
|
|
1537
|
+
* @returns Promise resolving to TransactionResult with fileId and transactionHash
|
|
1538
|
+
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1539
|
+
* @throws {Error} "Failed to generate encryption key" - When encryption key generation fails
|
|
1540
|
+
* @throws {Error} "Permission for {account} must include 'publicKey'" - When publicKey is missing
|
|
1541
|
+
* @throws {Error} "Failed to add file with permissions and schema: {error}" - When transaction fails
|
|
1542
|
+
* @example
|
|
1543
|
+
* ```typescript
|
|
1544
|
+
* // Get server's public key
|
|
1545
|
+
* const serverIdentity = await vana.server.getIdentity({
|
|
1546
|
+
* userAddress: "0x..."
|
|
1547
|
+
* });
|
|
1548
|
+
*
|
|
1549
|
+
* // Add file with permissions and schema
|
|
1550
|
+
* const result = await vana.data.addFileWithPermissionsAndSchema(
|
|
1551
|
+
* "ipfs://QmXxx...",
|
|
1552
|
+
* ownerAddress,
|
|
1553
|
+
* [{
|
|
1554
|
+
* account: serverIdentity.address,
|
|
1555
|
+
* publicKey: serverIdentity.publicKey
|
|
1556
|
+
* }],
|
|
1557
|
+
* schemaId
|
|
1558
|
+
* );
|
|
1559
|
+
*
|
|
1560
|
+
* console.log(`File ${result.fileId} registered in tx ${result.hash}`);
|
|
1561
|
+
* ```
|
|
1562
|
+
*/
|
|
1563
|
+
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
|
|
1564
|
+
this.assertWallet();
|
|
1565
|
+
try {
|
|
1566
|
+
let encryptedPermissions = [];
|
|
1567
|
+
if (permissions.length > 0) {
|
|
1568
|
+
this.assertWallet();
|
|
1569
|
+
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
1570
|
+
this.context.walletClient,
|
|
1571
|
+
this.context.platform,
|
|
1572
|
+
import_encryption.DEFAULT_ENCRYPTION_SEED
|
|
1573
|
+
);
|
|
1574
|
+
encryptedPermissions = await Promise.all(
|
|
1575
|
+
permissions.map(async (permission) => {
|
|
1576
|
+
if (!permission.publicKey) {
|
|
1577
|
+
throw new Error(
|
|
1578
|
+
`Permission for ${permission.account} must include 'publicKey'`
|
|
1579
|
+
);
|
|
1580
|
+
}
|
|
1581
|
+
const encryptedKey = await (0, import_encryption.encryptWithWalletPublicKey)(
|
|
1582
|
+
userEncryptionKey,
|
|
1583
|
+
permission.publicKey,
|
|
1584
|
+
this.context.platform
|
|
1585
|
+
);
|
|
1586
|
+
return {
|
|
1587
|
+
account: permission.account,
|
|
1588
|
+
key: encryptedKey
|
|
1589
|
+
};
|
|
1590
|
+
})
|
|
1591
|
+
);
|
|
1592
|
+
}
|
|
1593
|
+
return await this.addFileWithEncryptedPermissionsAndSchema(
|
|
1594
|
+
url,
|
|
1595
|
+
ownerAddress,
|
|
1596
|
+
encryptedPermissions,
|
|
1597
|
+
schemaId,
|
|
1598
|
+
options
|
|
1599
|
+
);
|
|
1600
|
+
} catch (error) {
|
|
1601
|
+
console.error("Failed to add file with permissions and schema:", error);
|
|
1602
|
+
throw new Error(
|
|
1603
|
+
`Failed to add file with permissions and schema: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
1604
|
+
);
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
/**
|
|
1608
|
+
* Adds a file with pre-encrypted permissions and schema to the DataRegistry.
|
|
1609
|
+
*
|
|
1610
|
+
* @remarks
|
|
1611
|
+
* This method is designed for relay services and advanced use cases where permissions
|
|
1612
|
+
* have already been encrypted client-side. Unlike `addFileWithPermissionsAndSchema()`,
|
|
1613
|
+
* this method expects permissions in the encrypted format with a 'key' field instead
|
|
1614
|
+
* of 'publicKey'.
|
|
1615
|
+
*
|
|
1616
|
+
* This is typically used by relay endpoints that receive pre-encrypted data from
|
|
1617
|
+
* the client SDK's `upload()` method, avoiding double encryption.
|
|
1618
|
+
*
|
|
1619
|
+
* @param url - The storage URL of the file (e.g., IPFS URL)
|
|
1620
|
+
* @param ownerAddress - The address that will own this file
|
|
1621
|
+
* @param permissions - Array of pre-encrypted permissions with 'account' and 'key' fields
|
|
1622
|
+
* @param schemaId - Optional schema ID for data validation (defaults to 0)
|
|
1623
|
+
* @returns Promise resolving to transaction result with hash and contract details
|
|
1365
1624
|
* @throws {Error} When chain ID is not available
|
|
1366
|
-
* @throws {
|
|
1367
|
-
* @throws {Error} When transaction
|
|
1368
|
-
* @
|
|
1625
|
+
* @throws {Error} When wallet is not connected
|
|
1626
|
+
* @throws {Error} When transaction fails
|
|
1627
|
+
* @example
|
|
1628
|
+
* ```typescript
|
|
1629
|
+
* // In a relay endpoint that receives pre-encrypted permissions
|
|
1630
|
+
* const result = await vana.data.addFileWithEncryptedPermissionsAndSchema(
|
|
1631
|
+
* "ipfs://QmXxx...",
|
|
1632
|
+
* ownerAddress,
|
|
1633
|
+
* [
|
|
1634
|
+
* {
|
|
1635
|
+
* account: "0xServerAddress...",
|
|
1636
|
+
* key: "encrypted_key_string" // Already encrypted by client
|
|
1637
|
+
* }
|
|
1638
|
+
* ],
|
|
1639
|
+
* schemaId
|
|
1640
|
+
* );
|
|
1641
|
+
*
|
|
1642
|
+
* console.log(`File registered in tx ${result.hash}`);
|
|
1643
|
+
* ```
|
|
1369
1644
|
*/
|
|
1370
|
-
async
|
|
1645
|
+
async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
|
|
1371
1646
|
try {
|
|
1372
|
-
const chainId = this.context.
|
|
1647
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1373
1648
|
if (!chainId) {
|
|
1374
1649
|
throw new Error("Chain ID not available");
|
|
1375
1650
|
}
|
|
1651
|
+
this.assertWallet();
|
|
1376
1652
|
const dataRegistryAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
1377
1653
|
const dataRegistryAbi = (0, import_abi.getAbi)("DataRegistry");
|
|
1378
|
-
const account = this.context.walletClient.account
|
|
1654
|
+
const account = this.context.walletClient.account ?? ownerAddress;
|
|
1379
1655
|
const from = typeof account === "string" ? account : account.address;
|
|
1380
1656
|
const hash = await this.context.walletClient.writeContract({
|
|
1381
1657
|
address: dataRegistryAddress,
|
|
@@ -1383,7 +1659,8 @@ class DataController {
|
|
|
1383
1659
|
functionName: "addFileWithPermissionsAndSchema",
|
|
1384
1660
|
args: [url, ownerAddress, permissions, BigInt(schemaId)],
|
|
1385
1661
|
account,
|
|
1386
|
-
chain: this.context.walletClient.chain
|
|
1662
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1663
|
+
...this.spreadTransactionOptions(options)
|
|
1387
1664
|
});
|
|
1388
1665
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1389
1666
|
return tx({
|
|
@@ -1400,36 +1677,41 @@ class DataController {
|
|
|
1400
1677
|
}
|
|
1401
1678
|
}
|
|
1402
1679
|
/**
|
|
1403
|
-
*
|
|
1680
|
+
* Registers a data refiner for processing templates.
|
|
1404
1681
|
*
|
|
1405
1682
|
* @remarks
|
|
1406
|
-
* Refiners
|
|
1407
|
-
*
|
|
1408
|
-
*
|
|
1409
|
-
*
|
|
1410
|
-
*
|
|
1411
|
-
* @param params - Refiner
|
|
1412
|
-
* @param params.
|
|
1413
|
-
*
|
|
1414
|
-
* @param params.
|
|
1415
|
-
*
|
|
1416
|
-
* @returns
|
|
1417
|
-
*
|
|
1418
|
-
* @throws {Error}
|
|
1683
|
+
* Refiners define data transformation rules for DLPs.
|
|
1684
|
+
* Associates schema, instructions, and processing logic.
|
|
1685
|
+
*
|
|
1686
|
+
* @param params - Refiner configuration
|
|
1687
|
+
* @param params.dlpId - Data Liquidity Pool ID
|
|
1688
|
+
* @param params.name - Refiner display name
|
|
1689
|
+
* @param params.schemaId - Output schema ID.
|
|
1690
|
+
* Obtain via `vana.schemas.list()`.
|
|
1691
|
+
* @param params.refinementInstructionUrl - Processing instructions URL
|
|
1692
|
+
*
|
|
1693
|
+
* @returns Refiner ID and transaction hash
|
|
1694
|
+
*
|
|
1695
|
+
* @throws {Error} Chain ID not available.
|
|
1696
|
+
* Ensure network connection.
|
|
1697
|
+
* @throws {Error} Transaction failed.
|
|
1698
|
+
* Check wallet balance and network status.
|
|
1699
|
+
*
|
|
1419
1700
|
* @example
|
|
1420
1701
|
* ```typescript
|
|
1421
1702
|
* const result = await vana.data.addRefiner({
|
|
1422
1703
|
* dlpId: 1,
|
|
1423
|
-
* name: "
|
|
1704
|
+
* name: "Sentiment Analyzer",
|
|
1424
1705
|
* schemaId: 42,
|
|
1425
1706
|
* refinementInstructionUrl: "ipfs://QmXxx..."
|
|
1426
1707
|
* });
|
|
1427
|
-
* console.log(`
|
|
1708
|
+
* console.log(`Refiner ${result.refinerId} created`);
|
|
1428
1709
|
* ```
|
|
1429
1710
|
*/
|
|
1430
|
-
async addRefiner(params) {
|
|
1711
|
+
async addRefiner(params, options) {
|
|
1712
|
+
this.assertWallet();
|
|
1431
1713
|
try {
|
|
1432
|
-
const chainId = this.context.
|
|
1714
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1433
1715
|
if (!chainId) {
|
|
1434
1716
|
throw new Error("Chain ID not available");
|
|
1435
1717
|
}
|
|
@@ -1438,7 +1720,8 @@ class DataController {
|
|
|
1438
1720
|
"DataRefinerRegistry"
|
|
1439
1721
|
);
|
|
1440
1722
|
const dataRefinerRegistryAbi = (0, import_abi.getAbi)("DataRefinerRegistry");
|
|
1441
|
-
|
|
1723
|
+
this.assertWallet();
|
|
1724
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1442
1725
|
const from = typeof account === "string" ? account : account.address;
|
|
1443
1726
|
const hash = await this.context.walletClient.writeContract({
|
|
1444
1727
|
address: dataRefinerRegistryAddress,
|
|
@@ -1451,7 +1734,8 @@ class DataController {
|
|
|
1451
1734
|
params.refinementInstructionUrl
|
|
1452
1735
|
],
|
|
1453
1736
|
account,
|
|
1454
|
-
chain: this.context.walletClient.chain
|
|
1737
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1738
|
+
...this.spreadTransactionOptions(options)
|
|
1455
1739
|
});
|
|
1456
1740
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1457
1741
|
const txResult = tx({
|
|
@@ -1480,31 +1764,34 @@ class DataController {
|
|
|
1480
1764
|
}
|
|
1481
1765
|
}
|
|
1482
1766
|
/**
|
|
1483
|
-
* Retrieves
|
|
1767
|
+
* Retrieves refiner configuration by ID.
|
|
1484
1768
|
*
|
|
1485
1769
|
* @remarks
|
|
1486
|
-
* Queries
|
|
1487
|
-
*
|
|
1770
|
+
* Queries DataRefinerRegistry for refiner details.
|
|
1771
|
+
* Returns DLP association, schema, and processing instructions.
|
|
1772
|
+
*
|
|
1773
|
+
* @param refinerId - Numeric refiner ID
|
|
1774
|
+
*
|
|
1775
|
+
* @returns Refiner configuration object
|
|
1776
|
+
*
|
|
1777
|
+
* @throws {Error} Chain ID not available.
|
|
1778
|
+
* Ensure network connection.
|
|
1779
|
+
* @throws {Error} Refiner not found.
|
|
1780
|
+
* Verify refiner ID exists.
|
|
1781
|
+
* @throws {Error} Contract read failed.
|
|
1782
|
+
* Check network and RPC status.
|
|
1488
1783
|
*
|
|
1489
|
-
* @param refinerId - The numeric refiner ID to retrieve
|
|
1490
|
-
* @returns Promise resolving to the refiner information object
|
|
1491
|
-
* @throws {Error} When chain ID is not available - "Chain ID not available"
|
|
1492
|
-
* @throws {Error} When refiner doesn't exist - "Refiner with ID {refinerId} does not exist"
|
|
1493
|
-
* @throws {Error} When contract read fails - "Failed to fetch refiner: {error}"
|
|
1494
1784
|
* @example
|
|
1495
1785
|
* ```typescript
|
|
1496
1786
|
* const refiner = await vana.data.getRefiner(1);
|
|
1497
|
-
* console.log({
|
|
1498
|
-
*
|
|
1499
|
-
*
|
|
1500
|
-
* schema: refiner.schemaId,
|
|
1501
|
-
* instructions: refiner.refinementInstructionUrl
|
|
1502
|
-
* });
|
|
1787
|
+
* console.log(`Refiner: ${refiner.name}`);
|
|
1788
|
+
* console.log(`DLP: ${refiner.dlpId}`);
|
|
1789
|
+
* console.log(`Schema: ${refiner.schemaId}`);
|
|
1503
1790
|
* ```
|
|
1504
1791
|
*/
|
|
1505
1792
|
async getRefiner(refinerId) {
|
|
1506
1793
|
try {
|
|
1507
|
-
const chainId = this.context.
|
|
1794
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1508
1795
|
if (!chainId) {
|
|
1509
1796
|
throw new Error("Chain ID not available");
|
|
1510
1797
|
}
|
|
@@ -1516,7 +1803,7 @@ class DataController {
|
|
|
1516
1803
|
const dataRefinerRegistry = (0, import_viem.getContract)({
|
|
1517
1804
|
address: dataRefinerRegistryAddress,
|
|
1518
1805
|
abi: dataRefinerRegistryAbi,
|
|
1519
|
-
client: this.context.
|
|
1806
|
+
client: this.context.publicClient
|
|
1520
1807
|
});
|
|
1521
1808
|
const refinerData = await dataRefinerRegistry.read.refiners([
|
|
1522
1809
|
BigInt(refinerId)
|
|
@@ -1540,27 +1827,33 @@ class DataController {
|
|
|
1540
1827
|
}
|
|
1541
1828
|
}
|
|
1542
1829
|
/**
|
|
1543
|
-
* Validates
|
|
1830
|
+
* Validates schema ID existence.
|
|
1544
1831
|
*
|
|
1545
1832
|
* @remarks
|
|
1546
|
-
*
|
|
1547
|
-
*
|
|
1833
|
+
* Verifies schema registration in DataRegistry.
|
|
1834
|
+
* Check before using schemas for uploads.
|
|
1835
|
+
*
|
|
1836
|
+
* @param schemaId - Numeric schema ID to validate
|
|
1837
|
+
*
|
|
1838
|
+
* @returns True if schema exists, false otherwise
|
|
1839
|
+
*
|
|
1840
|
+
* @throws {Error} Chain ID not available.
|
|
1841
|
+
* Ensure network connection.
|
|
1842
|
+
* @throws {Error} Contract read failed.
|
|
1843
|
+
* Check RPC availability.
|
|
1548
1844
|
*
|
|
1549
|
-
* @param schemaId - The numeric schema ID to validate
|
|
1550
|
-
* @returns Promise resolving to true if schema exists, false otherwise
|
|
1551
1845
|
* @example
|
|
1552
1846
|
* ```typescript
|
|
1553
|
-
* const
|
|
1554
|
-
* if (
|
|
1555
|
-
*
|
|
1556
|
-
*
|
|
1557
|
-
* console.log('Schema 42 does not exist');
|
|
1847
|
+
* const valid = await vana.data.isValidSchemaId(42);
|
|
1848
|
+
* if (valid) {
|
|
1849
|
+
* // Safe to use schema 42
|
|
1850
|
+
* await vana.data.upload({ schemaId: 42, ... });
|
|
1558
1851
|
* }
|
|
1559
1852
|
* ```
|
|
1560
1853
|
*/
|
|
1561
1854
|
async isValidSchemaId(schemaId) {
|
|
1562
1855
|
try {
|
|
1563
|
-
const chainId = this.context.
|
|
1856
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1564
1857
|
if (!chainId) {
|
|
1565
1858
|
throw new Error("Chain ID not available");
|
|
1566
1859
|
}
|
|
@@ -1572,7 +1865,7 @@ class DataController {
|
|
|
1572
1865
|
const dataRefinerRegistry = (0, import_viem.getContract)({
|
|
1573
1866
|
address: dataRefinerRegistryAddress,
|
|
1574
1867
|
abi: dataRefinerRegistryAbi,
|
|
1575
|
-
client: this.context.
|
|
1868
|
+
client: this.context.publicClient
|
|
1576
1869
|
});
|
|
1577
1870
|
const isValid = await dataRefinerRegistry.read.isValidSchemaId([
|
|
1578
1871
|
BigInt(schemaId)
|
|
@@ -1599,7 +1892,7 @@ class DataController {
|
|
|
1599
1892
|
*/
|
|
1600
1893
|
async getRefinersCount() {
|
|
1601
1894
|
try {
|
|
1602
|
-
const chainId = this.context.
|
|
1895
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1603
1896
|
if (!chainId) {
|
|
1604
1897
|
throw new Error("Chain ID not available");
|
|
1605
1898
|
}
|
|
@@ -1611,7 +1904,7 @@ class DataController {
|
|
|
1611
1904
|
const dataRefinerRegistry = (0, import_viem.getContract)({
|
|
1612
1905
|
address: dataRefinerRegistryAddress,
|
|
1613
1906
|
abi: dataRefinerRegistryAbi,
|
|
1614
|
-
client: this.context.
|
|
1907
|
+
client: this.context.publicClient
|
|
1615
1908
|
});
|
|
1616
1909
|
const count = await dataRefinerRegistry.read.refinersCount();
|
|
1617
1910
|
return Number(count);
|
|
@@ -1642,9 +1935,10 @@ class DataController {
|
|
|
1642
1935
|
* console.log(`Schema updated in tx ${result.transactionHash}`);
|
|
1643
1936
|
* ```
|
|
1644
1937
|
*/
|
|
1645
|
-
async updateSchemaId(params) {
|
|
1938
|
+
async updateSchemaId(params, options) {
|
|
1939
|
+
this.assertWallet();
|
|
1646
1940
|
try {
|
|
1647
|
-
const chainId = this.context.
|
|
1941
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1648
1942
|
if (!chainId) {
|
|
1649
1943
|
throw new Error("Chain ID not available");
|
|
1650
1944
|
}
|
|
@@ -1653,14 +1947,16 @@ class DataController {
|
|
|
1653
1947
|
"DataRefinerRegistry"
|
|
1654
1948
|
);
|
|
1655
1949
|
const dataRefinerRegistryAbi = (0, import_abi.getAbi)("DataRefinerRegistry");
|
|
1656
|
-
|
|
1950
|
+
this.assertWallet();
|
|
1951
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1657
1952
|
const hash = await this.context.walletClient.writeContract({
|
|
1658
1953
|
address: dataRefinerRegistryAddress,
|
|
1659
1954
|
abi: dataRefinerRegistryAbi,
|
|
1660
1955
|
functionName: "updateSchemaId",
|
|
1661
1956
|
args: [BigInt(params.refinerId), BigInt(params.newSchemaId)],
|
|
1662
1957
|
account,
|
|
1663
|
-
chain: this.context.walletClient.chain
|
|
1958
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1959
|
+
...this.spreadTransactionOptions(options)
|
|
1664
1960
|
});
|
|
1665
1961
|
await this.context.publicClient.waitForTransactionReceipt({ hash });
|
|
1666
1962
|
return {
|
|
@@ -1682,13 +1978,12 @@ class DataController {
|
|
|
1682
1978
|
* 3. Encrypts the user's encryption key with the provided public key
|
|
1683
1979
|
* 4. Registers the file with permissions
|
|
1684
1980
|
*
|
|
1685
|
-
* @param
|
|
1686
|
-
* @param permissions - Array of permissions to grant, each with account address and public key
|
|
1687
|
-
* @param filename - Optional filename for the upload
|
|
1688
|
-
* @param providerName - Optional storage provider to use
|
|
1981
|
+
* @param params - Upload parameters including data, permissions, and options
|
|
1689
1982
|
* @returns Promise resolving to upload result with file ID and storage URL
|
|
1690
1983
|
*/
|
|
1691
|
-
async uploadFileWithPermissions(
|
|
1984
|
+
async uploadFileWithPermissions(params) {
|
|
1985
|
+
this.assertWallet();
|
|
1986
|
+
const { data, permissions, filename, providerName } = params;
|
|
1692
1987
|
try {
|
|
1693
1988
|
const uploadResult = await this.uploadToStorage(
|
|
1694
1989
|
data,
|
|
@@ -1697,7 +1992,7 @@ class DataController {
|
|
|
1697
1992
|
// Always encrypt for uploadFileWithPermissions
|
|
1698
1993
|
providerName
|
|
1699
1994
|
);
|
|
1700
|
-
const userAddress =
|
|
1995
|
+
const userAddress = this.context.userAddress;
|
|
1701
1996
|
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
1702
1997
|
this.context.walletClient,
|
|
1703
1998
|
this.context.platform,
|
|
@@ -1716,12 +2011,24 @@ class DataController {
|
|
|
1716
2011
|
};
|
|
1717
2012
|
})
|
|
1718
2013
|
);
|
|
1719
|
-
if (this.context.
|
|
1720
|
-
const
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
2014
|
+
if (this.context.relayer) {
|
|
2015
|
+
const request = {
|
|
2016
|
+
type: "direct",
|
|
2017
|
+
operation: "submitFileAdditionWithPermissions",
|
|
2018
|
+
params: {
|
|
2019
|
+
url: uploadResult.url,
|
|
2020
|
+
userAddress,
|
|
2021
|
+
permissions: encryptedPermissions
|
|
2022
|
+
}
|
|
2023
|
+
};
|
|
2024
|
+
const response = await this.context.relayer(request);
|
|
2025
|
+
if (response.type === "error") {
|
|
2026
|
+
throw new Error(response.error);
|
|
2027
|
+
}
|
|
2028
|
+
if (response.type !== "direct" || typeof response.result !== "object" || response.result === null || !("fileId" in response.result)) {
|
|
2029
|
+
throw new Error("Invalid response from relayer");
|
|
2030
|
+
}
|
|
2031
|
+
const result = response.result;
|
|
1725
2032
|
return {
|
|
1726
2033
|
fileId: result.fileId,
|
|
1727
2034
|
url: uploadResult.url,
|
|
@@ -1734,9 +2041,18 @@ class DataController {
|
|
|
1734
2041
|
userAddress,
|
|
1735
2042
|
encryptedPermissions
|
|
1736
2043
|
);
|
|
2044
|
+
if (!this.context.waitForTransactionEvents) {
|
|
2045
|
+
throw new Error(
|
|
2046
|
+
"Cannot upload without relay: waitForTransactionEvents not configured"
|
|
2047
|
+
);
|
|
2048
|
+
}
|
|
2049
|
+
const eventResult = await this.context.waitForTransactionEvents(txResult);
|
|
2050
|
+
const fileAddedEvent = eventResult.expectedEvents.FileAdded;
|
|
2051
|
+
if (!fileAddedEvent) {
|
|
2052
|
+
throw new Error("FileAdded event not found in transaction");
|
|
2053
|
+
}
|
|
1737
2054
|
return {
|
|
1738
|
-
fileId:
|
|
1739
|
-
// Placeholder - user must wait for events to get actual fileId
|
|
2055
|
+
fileId: Number(fileAddedEvent.fileId),
|
|
1740
2056
|
url: uploadResult.url,
|
|
1741
2057
|
size: uploadResult.size,
|
|
1742
2058
|
transactionHash: txResult.hash
|
|
@@ -1779,6 +2095,7 @@ class DataController {
|
|
|
1779
2095
|
}
|
|
1780
2096
|
let finalBlob = blob;
|
|
1781
2097
|
if (encrypt) {
|
|
2098
|
+
this.assertWallet();
|
|
1782
2099
|
const encryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
1783
2100
|
this.context.walletClient,
|
|
1784
2101
|
this.context.platform,
|
|
@@ -1800,7 +2117,7 @@ class DataController {
|
|
|
1800
2117
|
);
|
|
1801
2118
|
}
|
|
1802
2119
|
}
|
|
1803
|
-
const finalFilename = filename
|
|
2120
|
+
const finalFilename = filename ?? (encrypt ? `upload-${Date.now()}.enc` : `upload-${Date.now()}.dat`);
|
|
1804
2121
|
const uploadResult = await this.context.storageManager.upload(
|
|
1805
2122
|
finalBlob,
|
|
1806
2123
|
finalFilename,
|
|
@@ -1825,22 +2142,30 @@ class DataController {
|
|
|
1825
2142
|
* For advanced users who need more control over transaction timing,
|
|
1826
2143
|
* use `submitFilePermission()` instead.
|
|
1827
2144
|
*
|
|
1828
|
-
* @param
|
|
1829
|
-
* @param
|
|
1830
|
-
* @param
|
|
2145
|
+
* @param params - Parameters for adding file permission
|
|
2146
|
+
* @param params.fileId - The ID of the file to grant permission for
|
|
2147
|
+
* @param params.account - The recipient's wallet address that will access the file
|
|
2148
|
+
* @param params.publicKey - The recipient's public key for encryption.
|
|
2149
|
+
* Obtain via `vana.server.getIdentity(account).publicKey`
|
|
1831
2150
|
* @returns Promise resolving to permission data from PermissionGranted event
|
|
1832
2151
|
* @throws {Error} "No addresses available in wallet client" - When wallet is not connected
|
|
1833
2152
|
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1834
2153
|
* @throws {Error} "Failed to add permission to file: {error}" - When transaction fails or user doesn't own file
|
|
1835
2154
|
* @example
|
|
1836
2155
|
* ```typescript
|
|
1837
|
-
* const result = await vana.data.addPermissionToFile(
|
|
2156
|
+
* const result = await vana.data.addPermissionToFile({
|
|
2157
|
+
* fileId: 123,
|
|
2158
|
+
* account: "0xRecipientAddress...",
|
|
2159
|
+
* publicKey: "0xRecipientPublicKey..."
|
|
2160
|
+
* });
|
|
1838
2161
|
* console.log(`Permission granted to ${result.account} for file ${result.fileId}`);
|
|
1839
2162
|
* console.log(`Transaction: ${result.transactionHash}`);
|
|
1840
2163
|
* ```
|
|
1841
2164
|
*/
|
|
1842
|
-
async addPermissionToFile(
|
|
1843
|
-
|
|
2165
|
+
async addPermissionToFile(params, options) {
|
|
2166
|
+
this.assertWallet();
|
|
2167
|
+
const { fileId, account, publicKey } = params;
|
|
2168
|
+
return await this.submitFilePermission(fileId, account, publicKey, options);
|
|
1844
2169
|
}
|
|
1845
2170
|
/**
|
|
1846
2171
|
* Submits a file permission transaction to the blockchain.
|
|
@@ -1853,7 +2178,7 @@ class DataController {
|
|
|
1853
2178
|
* @param fileId - The ID of the file to grant permission for
|
|
1854
2179
|
* @param account - The recipient's wallet address that will access the file
|
|
1855
2180
|
* @param publicKey - The recipient's public key for encryption.
|
|
1856
|
-
* Obtain via `vana.server.getIdentity(account).
|
|
2181
|
+
* Obtain via `vana.server.getIdentity(account).publicKey`
|
|
1857
2182
|
* @returns Promise resolving to TransactionResult for tracking the transaction
|
|
1858
2183
|
* @throws {Error} When chain ID is not available
|
|
1859
2184
|
* @throws {Error} When encryption key generation fails
|
|
@@ -1870,7 +2195,8 @@ class DataController {
|
|
|
1870
2195
|
* console.log(`Permission granted with ID: ${result.permissionId}`);
|
|
1871
2196
|
* ```
|
|
1872
2197
|
*/
|
|
1873
|
-
async submitFilePermission(fileId, account, publicKey) {
|
|
2198
|
+
async submitFilePermission(fileId, account, publicKey, options) {
|
|
2199
|
+
this.assertWallet();
|
|
1874
2200
|
try {
|
|
1875
2201
|
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
1876
2202
|
this.context.walletClient,
|
|
@@ -1882,20 +2208,22 @@ class DataController {
|
|
|
1882
2208
|
publicKey,
|
|
1883
2209
|
this.context.platform
|
|
1884
2210
|
);
|
|
1885
|
-
const chainId = this.context.
|
|
2211
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1886
2212
|
if (!chainId) {
|
|
1887
2213
|
throw new Error("Chain ID not available");
|
|
1888
2214
|
}
|
|
1889
2215
|
const dataRegistryAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
1890
2216
|
const dataRegistryAbi = (0, import_abi.getAbi)("DataRegistry");
|
|
1891
|
-
|
|
2217
|
+
this.assertWallet();
|
|
2218
|
+
const walletAccount = this.context.walletClient.account ?? this.context.userAddress;
|
|
1892
2219
|
const txHash = await this.context.walletClient.writeContract({
|
|
1893
2220
|
address: dataRegistryAddress,
|
|
1894
2221
|
abi: dataRegistryAbi,
|
|
1895
2222
|
functionName: "addFilePermission",
|
|
1896
2223
|
args: [BigInt(fileId), account, encryptedKey],
|
|
1897
2224
|
account: walletAccount,
|
|
1898
|
-
chain: this.context.walletClient.chain
|
|
2225
|
+
chain: this.context.walletClient.chain ?? null,
|
|
2226
|
+
...this.spreadTransactionOptions(options)
|
|
1899
2227
|
});
|
|
1900
2228
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1901
2229
|
return tx({
|
|
@@ -1920,7 +2248,7 @@ class DataController {
|
|
|
1920
2248
|
*/
|
|
1921
2249
|
async getFilePermission(fileId, account) {
|
|
1922
2250
|
try {
|
|
1923
|
-
const chainId = this.context.
|
|
2251
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1924
2252
|
if (!chainId) {
|
|
1925
2253
|
throw new Error("Chain ID not available");
|
|
1926
2254
|
}
|
|
@@ -1929,7 +2257,7 @@ class DataController {
|
|
|
1929
2257
|
const dataRegistry = (0, import_viem.getContract)({
|
|
1930
2258
|
address: dataRegistryAddress,
|
|
1931
2259
|
abi: dataRegistryAbi,
|
|
1932
|
-
client: this.context.
|
|
2260
|
+
client: this.context.publicClient
|
|
1933
2261
|
});
|
|
1934
2262
|
const encryptedKey = await dataRegistry.read.filePermissions([
|
|
1935
2263
|
BigInt(fileId),
|
|
@@ -1953,12 +2281,13 @@ class DataController {
|
|
|
1953
2281
|
*
|
|
1954
2282
|
* @param file - The file to decrypt
|
|
1955
2283
|
* @param privateKey - The private key to decrypt the user's encryption key
|
|
1956
|
-
* @param
|
|
2284
|
+
* @param options - Optional decryption configuration
|
|
2285
|
+
* @param options.account - The account address that has permission (defaults to current wallet account)
|
|
1957
2286
|
* @returns Promise resolving to the decrypted file data
|
|
1958
2287
|
*/
|
|
1959
|
-
async decryptFileWithPermission(file, privateKey,
|
|
2288
|
+
async decryptFileWithPermission(file, privateKey, options) {
|
|
1960
2289
|
try {
|
|
1961
|
-
const permissionAccount = account
|
|
2290
|
+
const permissionAccount = options?.account ?? this.context.userAddress;
|
|
1962
2291
|
const encryptedKey = await this.getFilePermission(
|
|
1963
2292
|
file.id,
|
|
1964
2293
|
permissionAccount
|
|
@@ -2022,11 +2351,8 @@ class DataController {
|
|
|
2022
2351
|
*/
|
|
2023
2352
|
async fetch(url) {
|
|
2024
2353
|
try {
|
|
2025
|
-
const {
|
|
2026
|
-
const response = await
|
|
2027
|
-
url,
|
|
2028
|
-
this.context.downloadRelayer
|
|
2029
|
-
);
|
|
2354
|
+
const { universalFetch } = await import("../utils/download");
|
|
2355
|
+
const response = await universalFetch(url, this.context.downloadRelayer);
|
|
2030
2356
|
if (!response.ok) {
|
|
2031
2357
|
throw new Error(
|
|
2032
2358
|
`HTTP error! status: ${response.status} ${response.statusText}`
|
|
@@ -2091,7 +2417,7 @@ class DataController {
|
|
|
2091
2417
|
"https://dweb.link/ipfs/",
|
|
2092
2418
|
"https://ipfs.io/ipfs/"
|
|
2093
2419
|
];
|
|
2094
|
-
const gateways = options?.gateways
|
|
2420
|
+
const gateways = options?.gateways ?? this.context.ipfsGateways ?? defaultGateways;
|
|
2095
2421
|
const { extractIpfsHash } = await import("../utils/ipfs");
|
|
2096
2422
|
const cid = extractIpfsHash(url);
|
|
2097
2423
|
if (!cid) {
|
|
@@ -2220,7 +2546,7 @@ class DataController {
|
|
|
2220
2546
|
* ```
|
|
2221
2547
|
*/
|
|
2222
2548
|
validateDataAgainstSchema(data, schema) {
|
|
2223
|
-
|
|
2549
|
+
(0, import_schemaValidation.validateDataAgainstSchema)(data, schema);
|
|
2224
2550
|
}
|
|
2225
2551
|
/**
|
|
2226
2552
|
* Fetches and validates a data schema from a URL, then returns the parsed data schema.
|