@opendatalabs/vana-sdk 0.1.0-alpha.276ea01 → 0.1.0-alpha.2b6935d
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.d.ts +4 -2
- 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.d.ts +5 -2
- package/dist/chains.browser.d.ts +8 -2
- package/dist/chains.d.ts +8 -2
- package/dist/chains.node.d.ts +8 -2
- package/dist/config/addresses.d.ts +8 -24
- package/dist/config/chains.d.ts +9 -13
- 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 +11 -28
- 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__/schemas-edge-cases.test.d.ts +1 -0
- package/dist/controllers/base.cjs +83 -0
- package/dist/controllers/base.cjs.map +1 -0
- package/dist/controllers/base.d.ts +84 -0
- package/dist/controllers/base.js +59 -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 +444 -191
- package/dist/controllers/data.cjs.map +1 -1
- package/dist/controllers/data.d.ts +149 -76
- package/dist/controllers/data.js +444 -191
- package/dist/controllers/data.js.map +1 -1
- package/dist/controllers/permissions.cjs +551 -395
- package/dist/controllers/permissions.cjs.map +1 -1
- package/dist/controllers/permissions.d.ts +1283 -25
- package/dist/controllers/permissions.js +551 -395
- 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 +7 -35
- package/dist/controllers/protocol.js +15 -14
- package/dist/controllers/protocol.js.map +1 -1
- package/dist/controllers/schemas.cjs +69 -54
- package/dist/controllers/schemas.cjs.map +1 -1
- package/dist/controllers/schemas.d.ts +9 -36
- package/dist/controllers/schemas.js +69 -54
- package/dist/controllers/schemas.js.map +1 -1
- package/dist/controllers/server-additional.test.d.ts +1 -0
- package/dist/controllers/server.cjs +15 -10
- package/dist/controllers/server.cjs.map +1 -1
- package/dist/controllers/server.d.ts +7 -33
- package/dist/controllers/server.js +15 -10
- package/dist/controllers/server.js.map +1 -1
- package/dist/core/apiClient.cjs +15 -12
- package/dist/core/apiClient.cjs.map +1 -1
- package/dist/core/apiClient.d.ts +5 -9
- package/dist/core/apiClient.js +19 -19
- 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 +11 -9
- package/dist/core/generics.cjs.map +1 -1
- package/dist/core/generics.d.ts +9 -13
- package/dist/core/generics.js +22 -29
- 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 +143 -60
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +42 -66
- package/dist/core.js +155 -85
- 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.d.ts +2 -3
- package/dist/generated/abi/DATFactoryImplementation.d.ts +2 -3
- package/dist/generated/abi/DATImplementation.d.ts +2 -3
- package/dist/generated/abi/DATPausableImplementation.d.ts +2 -3
- package/dist/generated/abi/DATVotesImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPPerformanceImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRegistryImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRegistryTreasuryImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRewardDeployerImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRewardSwapImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRootImplementation.d.ts +1 -3
- package/dist/generated/abi/DLPTreasuryImplementation.d.ts +2 -3
- package/dist/generated/abi/DataLiquidityPoolImplementation.d.ts +1 -3
- package/dist/generated/abi/DataPortabilityGranteesImplementation.d.ts +2 -3
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.ts +2 -3
- package/dist/generated/abi/DataPortabilityServersImplementation.d.ts +2 -3
- package/dist/generated/abi/DataRefinerRegistryImplementation.d.ts +2 -3
- package/dist/generated/abi/DataRegistryImplementation.cjs +13 -0
- package/dist/generated/abi/DataRegistryImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataRegistryImplementation.d.ts +12 -3
- package/dist/generated/abi/DataRegistryImplementation.js +13 -0
- package/dist/generated/abi/DataRegistryImplementation.js.map +1 -1
- package/dist/generated/abi/QueryEngineImplementation.d.ts +2 -3
- package/dist/generated/abi/SwapHelperImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolDedicatedGpuImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolDedicatedStandardImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolEphemeralStandardImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolPersistentGpuImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolPersistentStandardImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolPhalaImplementation.d.ts +2 -3
- package/dist/generated/abi/VanaEpochImplementation.d.ts +2 -3
- package/dist/generated/abi/VanaPoolEntityImplementation.d.ts +2 -3
- package/dist/generated/abi/VanaPoolStakingImplementation.d.ts +2 -3
- package/dist/generated/abi/VanaPoolTreasuryImplementation.d.ts +2 -3
- package/dist/generated/abi/index.cjs +42 -0
- package/dist/generated/abi/index.cjs.map +1 -1
- package/dist/generated/abi/index.d.ts +47 -18
- package/dist/generated/abi/index.js +21 -0
- package/dist/generated/abi/index.js.map +1 -1
- package/dist/generated/event-types.cjs +17 -0
- package/dist/generated/event-types.cjs.map +1 -0
- package/dist/generated/event-types.d.ts +854 -0
- package/dist/generated/event-types.js +1 -0
- package/dist/generated/event-types.js.map +1 -0
- package/dist/generated/eventRegistry.cjs +3351 -0
- package/dist/generated/eventRegistry.cjs.map +1 -0
- package/dist/generated/eventRegistry.d.ts +14 -0
- package/dist/generated/eventRegistry.js +3326 -0
- package/dist/generated/eventRegistry.js.map +1 -0
- package/dist/generated/server/server-exports.d.ts +19 -21
- package/dist/generated/server/server.cjs.map +1 -1
- package/dist/generated/server/server.d.ts +113 -87
- package/dist/generated/subgraph.d.ts +329 -332
- package/dist/index.browser.d.ts +48 -73
- 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 +12 -0
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.ts +183 -64
- package/dist/index.node.js +12 -0
- package/dist/index.node.js.map +1 -1
- package/dist/node.d.ts +4 -2
- 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 +7 -6
- package/dist/platform/browser.cjs.map +1 -1
- package/dist/platform/browser.d.ts +3 -6
- package/dist/platform/browser.js +19 -27
- 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.d.ts +6 -8
- package/dist/platform/node.d.ts +3 -7
- package/dist/platform/node.js +12 -19
- 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/handler.cjs +7 -5
- package/dist/server/handler.cjs.map +1 -1
- package/dist/server/handler.d.ts +17 -204
- package/dist/server/handler.js +7 -5
- package/dist/server/handler.js.map +1 -1
- package/dist/server/relayerHandler.cjs +220 -0
- package/dist/server/relayerHandler.cjs.map +1 -0
- package/dist/server/relayerHandler.d.ts +37 -0
- package/dist/server/relayerHandler.js +195 -0
- package/dist/server/relayerHandler.js.map +1 -0
- package/dist/storage/index.d.ts +56 -10
- package/dist/storage/manager.cjs +2 -2
- package/dist/storage/manager.cjs.map +1 -1
- package/dist/storage/manager.d.ts +2 -5
- package/dist/storage/manager.js +5 -12
- package/dist/storage/manager.js.map +1 -1
- package/dist/storage/providers/callback-storage.cjs +3 -3
- package/dist/storage/providers/callback-storage.cjs.map +1 -1
- package/dist/storage/providers/callback-storage.d.ts +3 -9
- package/dist/storage/providers/callback-storage.js +3 -3
- 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 +5 -8
- 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-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-handler.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 +17 -0
- package/dist/types/blockchain.cjs.map +1 -0
- package/dist/types/blockchain.d.ts +57 -0
- package/dist/types/blockchain.js +1 -0
- package/dist/types/blockchain.js.map +1 -0
- package/dist/types/chains-additional.test.d.ts +1 -0
- package/dist/types/chains.d.ts +6 -9
- package/dist/types/config.cjs +10 -0
- package/dist/types/config.cjs.map +1 -1
- package/dist/types/config.d.ts +198 -238
- 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 +8 -11
- package/dist/types/controller-context.cjs +17 -0
- package/dist/types/controller-context.cjs.map +1 -0
- package/dist/types/controller-context.d.ts +65 -0
- package/dist/types/controller-context.js +1 -0
- package/dist/types/controller-context.js.map +1 -0
- package/dist/types/data.cjs.map +1 -1
- package/dist/types/data.d.ts +107 -39
- package/dist/types/external-apis.d.ts +10 -12
- package/dist/types/generics.d.ts +35 -38
- package/dist/types/index.cjs +5 -4
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.ts +20 -34
- 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 +32 -28
- package/dist/types/operations.js +2 -2
- package/dist/types/operations.js.map +1 -1
- package/dist/types/permissions.d.ts +55 -58
- package/dist/types/personal.cjs.map +1 -1
- package/dist/types/personal.d.ts +6 -8
- package/dist/types/relayer.cjs.map +1 -1
- package/dist/types/relayer.d.ts +186 -39
- package/dist/types/storage.d.ts +6 -8
- package/dist/types/storage.js +2 -5
- package/dist/types/storage.js.map +1 -1
- package/dist/types/transactionResults.cjs.map +1 -1
- package/dist/types/transactionResults.d.ts +193 -25
- package/dist/types/utils.d.ts +21 -24
- package/dist/types.d.ts +4 -40
- package/dist/utils/__tests__/parseTransaction.test.d.ts +1 -0
- package/dist/utils/__tests__/pojo-serialization.test.d.ts +1 -0
- package/dist/utils/__tests__/signatureCache.test.d.ts +1 -0
- package/dist/utils/__tests__/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/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 +6 -10
- 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 +14 -17
- 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 +10 -13
- package/dist/utils/grants.js +1 -1
- package/dist/utils/grants.js.map +1 -1
- package/dist/utils/ipfs.d.ts +8 -10
- package/dist/utils/lazy-import.cjs +4 -6
- package/dist/utils/lazy-import.cjs.map +1 -1
- package/dist/utils/lazy-import.d.ts +1 -3
- package/dist/utils/lazy-import.js +4 -6
- package/dist/utils/lazy-import.js.map +1 -1
- package/dist/utils/multicall.cjs +4 -2
- package/dist/utils/multicall.cjs.map +1 -1
- package/dist/utils/multicall.d.ts +5 -8
- package/dist/utils/multicall.js +4 -2
- package/dist/utils/multicall.js.map +1 -1
- package/dist/utils/parseTransactionPojo.cjs +87 -0
- package/dist/utils/parseTransactionPojo.cjs.map +1 -0
- package/dist/utils/parseTransactionPojo.d.ts +31 -0
- package/dist/utils/parseTransactionPojo.js +63 -0
- package/dist/utils/parseTransactionPojo.js.map +1 -0
- package/dist/utils/schemaValidation.cjs +5 -5
- package/dist/utils/schemaValidation.cjs.map +1 -1
- package/dist/utils/schemaValidation.d.ts +8 -12
- package/dist/utils/schemaValidation.js +7 -10
- package/dist/utils/schemaValidation.js.map +1 -1
- package/dist/utils/signatureCache.cjs +1 -2
- package/dist/utils/signatureCache.cjs.map +1 -1
- package/dist/utils/signatureCache.d.ts +4 -7
- package/dist/utils/signatureCache.js +4 -8
- 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/tests/multicall.test.d.ts +1 -0
- package/dist/utils/transactionHelpers.cjs +54 -0
- package/dist/utils/transactionHelpers.cjs.map +1 -0
- package/dist/utils/transactionHelpers.d.ts +80 -0
- package/dist/utils/transactionHelpers.js +29 -0
- package/dist/utils/transactionHelpers.js.map +1 -0
- package/dist/utils/typeGuards.cjs +109 -0
- package/dist/utils/typeGuards.cjs.map +1 -0
- package/dist/utils/typeGuards.d.ts +138 -0
- package/dist/utils/typeGuards.js +74 -0
- package/dist/utils/typeGuards.js.map +1 -0
- package/dist/utils/typedDataConverter.d.ts +3 -6
- package/dist/utils/urlResolver.cjs +1 -1
- package/dist/utils/urlResolver.cjs.map +1 -1
- package/dist/utils/urlResolver.d.ts +2 -4
- package/dist/utils/urlResolver.js +2 -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 +32 -0
- package/dist/utils/wallet.js +37 -0
- package/dist/utils/wallet.js.map +1 -0
- package/dist/{chains.browser.cjs → utils/withEvents.cjs} +22 -15
- package/dist/utils/withEvents.cjs.map +1 -0
- package/dist/utils/withEvents.d.ts +56 -0
- package/dist/utils/withEvents.js +18 -0
- package/dist/utils/withEvents.js.map +1 -0
- package/package.json +23 -14
- package/dist/browser.d.cts +0 -2
- package/dist/chains/definitions.d.cts +0 -53
- package/dist/chains/index.d.cts +0 -2
- package/dist/chains.browser.cjs.map +0 -1
- package/dist/chains.browser.d.cts +0 -2
- package/dist/chains.d.cts +0 -2
- package/dist/chains.node.d.cts +0 -2
- package/dist/config/addresses.d.cts +0 -380
- package/dist/config/chains.d.cts +0 -85
- package/dist/config/eventMappings.cjs +0 -114
- package/dist/config/eventMappings.cjs.map +0 -1
- package/dist/config/eventMappings.d.cts +0 -108
- package/dist/config/eventMappings.d.ts +0 -108
- package/dist/config/eventMappings.js +0 -90
- package/dist/config/eventMappings.js.map +0 -1
- package/dist/config/features.d.cts +0 -64
- package/dist/contracts/contractController.d.cts +0 -96
- package/dist/controllers/data.d.cts +0 -941
- package/dist/controllers/permissions.d.cts +0 -25
- package/dist/controllers/protocol.d.cts +0 -167
- package/dist/controllers/schemas.d.cts +0 -272
- package/dist/controllers/server.d.cts +0 -243
- package/dist/core/apiClient.d.cts +0 -165
- package/dist/core/client.d.cts +0 -92
- package/dist/core/generics.d.cts +0 -120
- package/dist/core.d.cts +0 -466
- package/dist/crypto/ecies/__tests__/test-vectors.d.cts +0 -40
- package/dist/crypto/ecies/base.d.cts +0 -143
- package/dist/crypto/ecies/browser.d.cts +0 -48
- package/dist/crypto/ecies/constants.d.cts +0 -122
- package/dist/crypto/ecies/index.d.cts +0 -1
- package/dist/crypto/ecies/interface.d.cts +0 -176
- package/dist/crypto/ecies/node.d.cts +0 -50
- package/dist/crypto/ecies/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 -1004
- package/dist/generated/abi/QueryEngineImplementation.d.cts +0 -1001
- package/dist/generated/abi/SwapHelperImplementation.d.cts +0 -764
- package/dist/generated/abi/TeePoolDedicatedGpuImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolDedicatedStandardImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolEphemeralStandardImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolImplementation.d.cts +0 -993
- package/dist/generated/abi/TeePoolPersistentGpuImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolPersistentStandardImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolPhalaImplementation.d.cts +0 -993
- package/dist/generated/abi/VanaEpochImplementation.d.cts +0 -900
- package/dist/generated/abi/VanaPoolEntityImplementation.d.cts +0 -934
- package/dist/generated/abi/VanaPoolStakingImplementation.d.cts +0 -693
- package/dist/generated/abi/VanaPoolTreasuryImplementation.d.cts +0 -394
- package/dist/generated/abi/index.d.cts +0 -26516
- package/dist/generated/server/server-exports.d.cts +0 -21
- package/dist/generated/server/server.d.cts +0 -512
- package/dist/generated/subgraph.d.cts +0 -5981
- package/dist/index.browser.cjs +0 -151
- package/dist/index.browser.cjs.map +0 -1
- package/dist/index.browser.d.cts +0 -177
- package/dist/index.d.cts +0 -2
- package/dist/index.node.d.cts +0 -64
- package/dist/node.d.cts +0 -2
- package/dist/permissions-DNKPu_G0.d.cts +0 -1666
- package/dist/permissions-eo8YeLGf.d.ts +0 -1666
- package/dist/platform/browser-only.d.cts +0 -25
- package/dist/platform/browser-safe.d.cts +0 -32
- package/dist/platform/browser.d.cts +0 -74
- package/dist/platform/index.d.cts +0 -5
- package/dist/platform/interface.d.cts +0 -218
- package/dist/platform/node.d.cts +0 -27
- package/dist/platform/shared/error-utils.d.cts +0 -25
- package/dist/platform/shared/pgp-utils.d.cts +0 -61
- package/dist/platform/shared/stream-utils.d.cts +0 -16
- package/dist/platform/utils.d.cts +0 -53
- package/dist/platform.browser.cjs +0 -41
- package/dist/platform.browser.cjs.map +0 -1
- package/dist/platform.browser.d.cts +0 -4
- package/dist/platform.d.cts +0 -5
- package/dist/platform.node.d.cts +0 -5
- package/dist/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.d.cts +0 -282
- package/dist/storage/index.d.cts +0 -10
- package/dist/storage/manager.d.cts +0 -150
- package/dist/storage/providers/callback-storage.d.cts +0 -100
- package/dist/storage/providers/google-drive.d.cts +0 -156
- package/dist/storage/providers/ipfs.d.cts +0 -163
- package/dist/storage/providers/pinata.d.cts +0 -173
- package/dist/types/chains.d.cts +0 -34
- package/dist/types/config.d.cts +0 -726
- package/dist/types/contracts.d.cts +0 -68
- package/dist/types/data.d.cts +0 -694
- package/dist/types/eccrypto-js.d.d.cts +0 -13
- package/dist/types/eccrypto-js.d.d.ts +0 -13
- package/dist/types/external-apis.d.cts +0 -186
- package/dist/types/generics.d.cts +0 -450
- package/dist/types/index.d.cts +0 -34
- package/dist/types/operations.d.cts +0 -108
- package/dist/types/permissions.d.cts +0 -957
- package/dist/types/personal.d.cts +0 -40
- package/dist/types/relayer.d.cts +0 -284
- package/dist/types/storage.d.cts +0 -131
- package/dist/types/transactionResults.d.cts +0 -25
- package/dist/types/utils.d.cts +0 -819
- package/dist/types.d.cts +0 -66
- package/dist/utils/blockchain/registry.d.cts +0 -34
- package/dist/utils/crypto-utils.d.cts +0 -118
- package/dist/utils/download.d.cts +0 -41
- package/dist/utils/encoding.d.cts +0 -54
- package/dist/utils/encryption.d.cts +0 -275
- package/dist/utils/eventParsing.cjs +0 -111
- package/dist/utils/eventParsing.cjs.map +0 -1
- package/dist/utils/eventParsing.d.cts +0 -60
- package/dist/utils/eventParsing.d.ts +0 -60
- package/dist/utils/eventParsing.js +0 -86
- package/dist/utils/eventParsing.js.map +0 -1
- package/dist/utils/formatters.d.cts +0 -120
- package/dist/utils/grantFiles.d.cts +0 -186
- package/dist/utils/grantValidation.d.cts +0 -150
- package/dist/utils/grants.d.cts +0 -70
- package/dist/utils/ipfs.d.cts +0 -90
- package/dist/utils/lazy-import.d.cts +0 -20
- package/dist/utils/multicall.d.cts +0 -129
- package/dist/utils/schemaValidation.d.cts +0 -172
- package/dist/utils/signatureCache.d.cts +0 -134
- package/dist/utils/signatureFormatter.d.cts +0 -39
- package/dist/utils/transactionParsing.cjs +0 -84
- package/dist/utils/transactionParsing.cjs.map +0 -1
- package/dist/utils/transactionParsing.d.cts +0 -25
- package/dist/utils/transactionParsing.d.ts +0 -25
- package/dist/utils/transactionParsing.js +0 -62
- package/dist/utils/transactionParsing.js.map +0 -1
- package/dist/utils/typedDataConverter.d.cts +0 -13
- package/dist/utils/urlResolver.d.cts +0 -40
package/dist/controllers/data.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getContract } from "viem";
|
|
2
|
+
import { BaseController } from "./base";
|
|
2
3
|
import { getContractAddress } from "../config/addresses";
|
|
3
4
|
import { getAbi } from "../generated/abi";
|
|
4
5
|
import {
|
|
@@ -23,11 +24,12 @@ import {
|
|
|
23
24
|
fetchAndValidateSchema
|
|
24
25
|
} from "../utils/schemaValidation";
|
|
25
26
|
import { gasAwareMulticall } from "../utils/multicall";
|
|
26
|
-
class DataController {
|
|
27
|
+
class DataController extends BaseController {
|
|
27
28
|
constructor(context) {
|
|
28
|
-
|
|
29
|
+
super(context);
|
|
29
30
|
}
|
|
30
31
|
async upload(params) {
|
|
32
|
+
this.assertWallet();
|
|
31
33
|
const {
|
|
32
34
|
content,
|
|
33
35
|
filename,
|
|
@@ -52,15 +54,28 @@ class DataController {
|
|
|
52
54
|
} catch {
|
|
53
55
|
parsedContent = content;
|
|
54
56
|
}
|
|
57
|
+
} else if (content instanceof Blob) {
|
|
58
|
+
const text = await content.text();
|
|
59
|
+
try {
|
|
60
|
+
parsedContent = JSON.parse(text);
|
|
61
|
+
} catch {
|
|
62
|
+
parsedContent = text;
|
|
63
|
+
}
|
|
55
64
|
} else {
|
|
56
65
|
parsedContent = content;
|
|
57
66
|
}
|
|
58
67
|
validateDataAgainstSchema(parsedContent, schema);
|
|
59
68
|
} catch (error) {
|
|
60
69
|
isValid = false;
|
|
61
|
-
|
|
62
|
-
error
|
|
63
|
-
|
|
70
|
+
if (error instanceof Error) {
|
|
71
|
+
if (typeof error === "object" && "errors" in error && Array.isArray(error.errors)) {
|
|
72
|
+
validationErrors = error.errors;
|
|
73
|
+
} else {
|
|
74
|
+
validationErrors = [error.message];
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
validationErrors = ["Schema validation failed"];
|
|
78
|
+
}
|
|
64
79
|
}
|
|
65
80
|
}
|
|
66
81
|
const uploadResult = await this.uploadToStorage(
|
|
@@ -69,9 +84,10 @@ class DataController {
|
|
|
69
84
|
encrypt,
|
|
70
85
|
providerName
|
|
71
86
|
);
|
|
72
|
-
const userAddress = owner
|
|
87
|
+
const userAddress = owner ?? this.context.userAddress;
|
|
73
88
|
let encryptedPermissions = [];
|
|
74
89
|
if (permissions.length > 0 && encrypt) {
|
|
90
|
+
this.assertWallet();
|
|
75
91
|
const userEncryptionKey = await generateEncryptionKey(
|
|
76
92
|
this.context.walletClient,
|
|
77
93
|
this.context.platform,
|
|
@@ -92,34 +108,47 @@ class DataController {
|
|
|
92
108
|
);
|
|
93
109
|
}
|
|
94
110
|
let result;
|
|
95
|
-
if (this.context.
|
|
96
|
-
|
|
97
|
-
|
|
111
|
+
if (this.context.relayer) {
|
|
112
|
+
const request = {
|
|
113
|
+
type: "direct",
|
|
114
|
+
operation: "submitFileAdditionComplete",
|
|
115
|
+
params: {
|
|
98
116
|
url: uploadResult.url,
|
|
99
117
|
userAddress,
|
|
100
118
|
permissions: encryptedPermissions,
|
|
101
|
-
schemaId: schemaId
|
|
119
|
+
schemaId: schemaId ?? 0,
|
|
102
120
|
ownerAddress: owner
|
|
103
121
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
throw new Error(
|
|
109
|
-
"The configured relay callback does not support schemas or permissions. Please update your relay server implementation to provide the `submitFileAdditionComplete` callback."
|
|
110
|
-
);
|
|
122
|
+
};
|
|
123
|
+
const response = await this.context.relayer(request);
|
|
124
|
+
if (response.type === "error") {
|
|
125
|
+
throw new Error(response.error);
|
|
111
126
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
127
|
+
if (response.type !== "direct" || !("fileId" in response.result)) {
|
|
128
|
+
throw new Error("Invalid response from relayer");
|
|
129
|
+
}
|
|
130
|
+
result = response.result;
|
|
116
131
|
} else {
|
|
117
|
-
|
|
132
|
+
const txResult = await this.addFileWithEncryptedPermissionsAndSchema(
|
|
118
133
|
uploadResult.url,
|
|
119
134
|
userAddress,
|
|
120
135
|
encryptedPermissions,
|
|
121
|
-
schemaId
|
|
136
|
+
schemaId ?? 0
|
|
122
137
|
);
|
|
138
|
+
if (!this.context.waitForTransactionEvents) {
|
|
139
|
+
throw new Error(
|
|
140
|
+
"Cannot upload without relay: waitForTransactionEvents not configured"
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
const eventResult = await this.context.waitForTransactionEvents(txResult);
|
|
144
|
+
const fileAddedEvent = eventResult.expectedEvents.FileAdded;
|
|
145
|
+
if (!fileAddedEvent) {
|
|
146
|
+
throw new Error("FileAdded event not found in transaction");
|
|
147
|
+
}
|
|
148
|
+
result = {
|
|
149
|
+
fileId: Number(fileAddedEvent.fileId),
|
|
150
|
+
transactionHash: txResult.hash
|
|
151
|
+
};
|
|
123
152
|
}
|
|
124
153
|
return {
|
|
125
154
|
fileId: result.fileId,
|
|
@@ -135,6 +164,83 @@ class DataController {
|
|
|
135
164
|
);
|
|
136
165
|
}
|
|
137
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Encrypts data using wallet-derived encryption.
|
|
169
|
+
*
|
|
170
|
+
* @remarks
|
|
171
|
+
* This method provides secure, wallet-based encryption for data before uploading
|
|
172
|
+
* to the Vana network. It's the counterpart to decryptFile for preparing data
|
|
173
|
+
* for secure storage.
|
|
174
|
+
*
|
|
175
|
+
* The method automatically:
|
|
176
|
+
* - Generates an encryption key from the user's wallet signature
|
|
177
|
+
* - Converts the input data to a Blob if necessary
|
|
178
|
+
* - Encrypts the data using the generated key
|
|
179
|
+
* - Returns both the encrypted data and the encryption key
|
|
180
|
+
*
|
|
181
|
+
* The encryption key returned can be stored and later used for decryption,
|
|
182
|
+
* or shared with others to grant them decryption access.
|
|
183
|
+
*
|
|
184
|
+
* @param data - The data to encrypt (Blob, string, or object)
|
|
185
|
+
* @param options - Optional encryption configuration
|
|
186
|
+
* @returns Promise resolving to encrypted data and the encryption key used
|
|
187
|
+
* @throws {Error} When wallet is not connected or encryption fails
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* // Encrypt a string
|
|
191
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
192
|
+
* "My secret data"
|
|
193
|
+
* );
|
|
194
|
+
*
|
|
195
|
+
* // Encrypt JSON with custom MIME type
|
|
196
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
197
|
+
* { name: "Alice", age: 30 },
|
|
198
|
+
* { mimeType: "application/json" }
|
|
199
|
+
* );
|
|
200
|
+
*
|
|
201
|
+
* // With custom encryption seed
|
|
202
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
203
|
+
* "Secret message",
|
|
204
|
+
* { seed: "My custom encryption seed" }
|
|
205
|
+
* );
|
|
206
|
+
*
|
|
207
|
+
* // Upload the encrypted data
|
|
208
|
+
* const result = await vana.data.uploadToStorage(encryptedData);
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
async encryptFile(data, options) {
|
|
212
|
+
this.assertWallet();
|
|
213
|
+
try {
|
|
214
|
+
const encryptionKey = await generateEncryptionKey(
|
|
215
|
+
this.context.walletClient,
|
|
216
|
+
this.context.platform,
|
|
217
|
+
options?.seed ?? DEFAULT_ENCRYPTION_SEED
|
|
218
|
+
);
|
|
219
|
+
let blob;
|
|
220
|
+
if (data instanceof Blob) {
|
|
221
|
+
blob = data;
|
|
222
|
+
} else if (typeof data === "string") {
|
|
223
|
+
blob = new Blob([data], { type: options?.mimeType ?? "text/plain" });
|
|
224
|
+
} else {
|
|
225
|
+
blob = new Blob([JSON.stringify(data)], {
|
|
226
|
+
type: options?.mimeType ?? "application/json"
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
const encryptedData = await encryptBlobWithSignedKey(
|
|
230
|
+
blob,
|
|
231
|
+
encryptionKey,
|
|
232
|
+
this.context.platform
|
|
233
|
+
);
|
|
234
|
+
return {
|
|
235
|
+
encryptedData,
|
|
236
|
+
encryptionKey
|
|
237
|
+
};
|
|
238
|
+
} catch (error) {
|
|
239
|
+
throw new Error(
|
|
240
|
+
`Failed to encrypt file: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
138
244
|
/**
|
|
139
245
|
* Decrypts a file owned by the user using their wallet signature.
|
|
140
246
|
*
|
|
@@ -190,12 +296,14 @@ class DataController {
|
|
|
190
296
|
* fs.writeFileSync('decrypted-file.txt', Buffer.from(buffer));
|
|
191
297
|
* ```
|
|
192
298
|
*/
|
|
193
|
-
async decryptFile(file,
|
|
299
|
+
async decryptFile(file, options) {
|
|
300
|
+
this.assertWallet();
|
|
194
301
|
try {
|
|
302
|
+
this.assertWallet();
|
|
195
303
|
const encryptionKey = await generateEncryptionKey(
|
|
196
304
|
this.context.walletClient,
|
|
197
305
|
this.context.platform,
|
|
198
|
-
|
|
306
|
+
options?.seed ?? DEFAULT_ENCRYPTION_SEED
|
|
199
307
|
);
|
|
200
308
|
let encryptedBlob;
|
|
201
309
|
try {
|
|
@@ -312,7 +420,7 @@ class DataController {
|
|
|
312
420
|
*/
|
|
313
421
|
async getUserFiles(params) {
|
|
314
422
|
const { owner, subgraphUrl } = params;
|
|
315
|
-
const endpoint = subgraphUrl
|
|
423
|
+
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
316
424
|
if (!endpoint) {
|
|
317
425
|
throw new Error(
|
|
318
426
|
"subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor."
|
|
@@ -344,7 +452,7 @@ class DataController {
|
|
|
344
452
|
);
|
|
345
453
|
}
|
|
346
454
|
const user = result.data?.user;
|
|
347
|
-
if (!user
|
|
455
|
+
if (!user?.files?.length) {
|
|
348
456
|
console.warn("No files found for user:", owner);
|
|
349
457
|
return [];
|
|
350
458
|
}
|
|
@@ -366,7 +474,7 @@ class DataController {
|
|
|
366
474
|
}
|
|
367
475
|
});
|
|
368
476
|
const userFiles = Array.from(fileMap.values()).sort(
|
|
369
|
-
(a, b) => Number((b.addedAtTimestamp
|
|
477
|
+
(a, b) => Number((b.addedAtTimestamp ?? 0n) - (a.addedAtTimestamp ?? 0n))
|
|
370
478
|
);
|
|
371
479
|
if (userFiles.length > 0) {
|
|
372
480
|
try {
|
|
@@ -437,10 +545,11 @@ class DataController {
|
|
|
437
545
|
if (proof.dlp?.id) {
|
|
438
546
|
const fileId = parseInt(proof.fileId);
|
|
439
547
|
const dlpId = parseInt(proof.dlp.id);
|
|
440
|
-
|
|
441
|
-
|
|
548
|
+
let dlpIds = proofMap.get(fileId);
|
|
549
|
+
if (!dlpIds) {
|
|
550
|
+
dlpIds = [];
|
|
551
|
+
proofMap.set(fileId, dlpIds);
|
|
442
552
|
}
|
|
443
|
-
const dlpIds = proofMap.get(fileId);
|
|
444
553
|
if (!dlpIds.includes(dlpId)) {
|
|
445
554
|
dlpIds.push(dlpId);
|
|
446
555
|
}
|
|
@@ -458,7 +567,7 @@ class DataController {
|
|
|
458
567
|
* @returns Map of file IDs to their associated DLP IDs
|
|
459
568
|
*/
|
|
460
569
|
async _fetchProofsFromChain(fileIds) {
|
|
461
|
-
const chainId = this.context.
|
|
570
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
462
571
|
if (!chainId) {
|
|
463
572
|
throw new Error("Chain ID not available");
|
|
464
573
|
}
|
|
@@ -515,7 +624,7 @@ class DataController {
|
|
|
515
624
|
* ```
|
|
516
625
|
*/
|
|
517
626
|
async getDLP(dlpId, options = {}) {
|
|
518
|
-
const subgraphUrl = options.subgraphUrl
|
|
627
|
+
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
519
628
|
if (subgraphUrl) {
|
|
520
629
|
try {
|
|
521
630
|
const response = await fetch(subgraphUrl, {
|
|
@@ -546,18 +655,18 @@ class DataController {
|
|
|
546
655
|
}
|
|
547
656
|
return {
|
|
548
657
|
id: parseInt(result.data.dlp.id),
|
|
549
|
-
name: result.data.dlp.name
|
|
550
|
-
metadata: result.data.dlp.metadata
|
|
658
|
+
name: result.data.dlp.name ?? "",
|
|
659
|
+
metadata: result.data.dlp.metadata ?? void 0,
|
|
551
660
|
status: result.data.dlp.status ? parseInt(result.data.dlp.status) : void 0,
|
|
552
|
-
address: result.data.dlp.address,
|
|
553
|
-
owner: result.data.dlp.owner
|
|
661
|
+
address: result.data.dlp.address ? result.data.dlp.address : void 0,
|
|
662
|
+
owner: result.data.dlp.owner ? result.data.dlp.owner : void 0
|
|
554
663
|
};
|
|
555
664
|
} catch (error) {
|
|
556
665
|
console.debug("Subgraph query failed, falling back to chain:", error);
|
|
557
666
|
}
|
|
558
667
|
}
|
|
559
668
|
try {
|
|
560
|
-
const chainId = this.context.
|
|
669
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
561
670
|
if (!chainId) {
|
|
562
671
|
throw new Error("Chain ID not available");
|
|
563
672
|
}
|
|
@@ -569,7 +678,7 @@ class DataController {
|
|
|
569
678
|
functionName: "dlps",
|
|
570
679
|
args: [BigInt(dlpId)]
|
|
571
680
|
});
|
|
572
|
-
if (!dlpData
|
|
681
|
+
if (!dlpData?.name) {
|
|
573
682
|
throw new Error(`DLP not found: ${dlpId}`);
|
|
574
683
|
}
|
|
575
684
|
return {
|
|
@@ -611,7 +720,7 @@ class DataController {
|
|
|
611
720
|
*/
|
|
612
721
|
async listDLPs(options = {}) {
|
|
613
722
|
const { limit = 100, offset = 0 } = options;
|
|
614
|
-
const subgraphUrl = options.subgraphUrl
|
|
723
|
+
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
615
724
|
if (subgraphUrl) {
|
|
616
725
|
try {
|
|
617
726
|
const query = `
|
|
@@ -650,21 +759,21 @@ class DataController {
|
|
|
650
759
|
`Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
651
760
|
);
|
|
652
761
|
}
|
|
653
|
-
const dlps = result.data?.dlps
|
|
762
|
+
const dlps = result.data?.dlps ?? [];
|
|
654
763
|
return dlps.map((dlp) => ({
|
|
655
764
|
id: parseInt(dlp.id),
|
|
656
|
-
name: dlp.name
|
|
765
|
+
name: dlp.name ?? "",
|
|
657
766
|
metadata: dlp.metadata,
|
|
658
767
|
status: dlp.status ? parseInt(dlp.status) : void 0,
|
|
659
|
-
address: dlp.address,
|
|
660
|
-
owner: dlp.owner
|
|
768
|
+
address: dlp.address ? dlp.address : void 0,
|
|
769
|
+
owner: dlp.owner ? dlp.owner : void 0
|
|
661
770
|
}));
|
|
662
771
|
} catch (error) {
|
|
663
772
|
console.debug("Subgraph query failed, falling back to chain:", error);
|
|
664
773
|
}
|
|
665
774
|
}
|
|
666
775
|
try {
|
|
667
|
-
const chainId = this.context.
|
|
776
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
668
777
|
if (!chainId) {
|
|
669
778
|
throw new Error("Chain ID not available");
|
|
670
779
|
}
|
|
@@ -736,7 +845,7 @@ class DataController {
|
|
|
736
845
|
*/
|
|
737
846
|
async getUserPermissions(params) {
|
|
738
847
|
const { user, subgraphUrl } = params;
|
|
739
|
-
const endpoint = subgraphUrl
|
|
848
|
+
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
740
849
|
if (endpoint) {
|
|
741
850
|
try {
|
|
742
851
|
const permissions = await this._getUserPermissionsViaSubgraph({
|
|
@@ -785,7 +894,7 @@ class DataController {
|
|
|
785
894
|
);
|
|
786
895
|
}
|
|
787
896
|
const userData = result.data?.user;
|
|
788
|
-
if (!userData
|
|
897
|
+
if (!userData?.permissions?.length) {
|
|
789
898
|
return [];
|
|
790
899
|
}
|
|
791
900
|
return userData.permissions.map((permission) => ({
|
|
@@ -813,7 +922,7 @@ class DataController {
|
|
|
813
922
|
async _getUserPermissionsViaRpc(params) {
|
|
814
923
|
const { user } = params;
|
|
815
924
|
try {
|
|
816
|
-
const chainId = this.context.
|
|
925
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
817
926
|
if (!chainId) {
|
|
818
927
|
throw new Error("Chain ID not available");
|
|
819
928
|
}
|
|
@@ -932,7 +1041,7 @@ class DataController {
|
|
|
932
1041
|
*/
|
|
933
1042
|
async getUserTrustedServers(params) {
|
|
934
1043
|
const { user, limit = 50, offset = 0 } = params;
|
|
935
|
-
const subgraphUrl = params.subgraphUrl
|
|
1044
|
+
const subgraphUrl = params.subgraphUrl ?? this.context.subgraphUrl;
|
|
936
1045
|
if (subgraphUrl) {
|
|
937
1046
|
try {
|
|
938
1047
|
const servers = await this._getUserTrustedServersViaSubgraph({
|
|
@@ -995,7 +1104,7 @@ class DataController {
|
|
|
995
1104
|
if (!result.data?.user) {
|
|
996
1105
|
return [];
|
|
997
1106
|
}
|
|
998
|
-
return (result.data.user.serverTrusts
|
|
1107
|
+
return (result.data.user.serverTrusts ?? []).filter((trust) => !trust.untrustedAtBlock).map((trust) => ({
|
|
999
1108
|
id: trust.server.id,
|
|
1000
1109
|
serverAddress: trust.server.serverAddress,
|
|
1001
1110
|
serverUrl: trust.server.url,
|
|
@@ -1021,7 +1130,7 @@ class DataController {
|
|
|
1021
1130
|
async _getUserTrustedServersViaRpc(params) {
|
|
1022
1131
|
const { user, limit, offset } = params;
|
|
1023
1132
|
try {
|
|
1024
|
-
const chainId = this.context.
|
|
1133
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1025
1134
|
if (!chainId) {
|
|
1026
1135
|
throw new Error("Chain ID not available");
|
|
1027
1136
|
}
|
|
@@ -1121,7 +1230,7 @@ class DataController {
|
|
|
1121
1230
|
*/
|
|
1122
1231
|
async getTotalFilesCount() {
|
|
1123
1232
|
try {
|
|
1124
|
-
const chainId = this.context.
|
|
1233
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1125
1234
|
if (!chainId) {
|
|
1126
1235
|
throw new Error("Chain ID not available");
|
|
1127
1236
|
}
|
|
@@ -1130,7 +1239,7 @@ class DataController {
|
|
|
1130
1239
|
const dataRegistry = getContract({
|
|
1131
1240
|
address: dataRegistryAddress,
|
|
1132
1241
|
abi: dataRegistryAbi,
|
|
1133
|
-
client: this.context.
|
|
1242
|
+
client: this.context.publicClient
|
|
1134
1243
|
});
|
|
1135
1244
|
const count = await dataRegistry.read.filesCount();
|
|
1136
1245
|
return Number(count);
|
|
@@ -1172,7 +1281,7 @@ class DataController {
|
|
|
1172
1281
|
*/
|
|
1173
1282
|
async getFileById(fileId) {
|
|
1174
1283
|
try {
|
|
1175
|
-
const chainId = this.context.
|
|
1284
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1176
1285
|
if (!chainId) {
|
|
1177
1286
|
throw new Error("Chain ID not available");
|
|
1178
1287
|
}
|
|
@@ -1181,7 +1290,7 @@ class DataController {
|
|
|
1181
1290
|
const dataRegistry = getContract({
|
|
1182
1291
|
address: dataRegistryAddress,
|
|
1183
1292
|
abi: dataRegistryAbi,
|
|
1184
|
-
client: this.context.
|
|
1293
|
+
client: this.context.publicClient
|
|
1185
1294
|
});
|
|
1186
1295
|
const fileDetails = await dataRegistry.read.files([BigInt(fileId)]);
|
|
1187
1296
|
if (!fileDetails) {
|
|
@@ -1240,34 +1349,32 @@ class DataController {
|
|
|
1240
1349
|
* ```
|
|
1241
1350
|
*/
|
|
1242
1351
|
async registerFileWithSchema(url, schemaId) {
|
|
1352
|
+
this.assertWallet();
|
|
1243
1353
|
try {
|
|
1244
|
-
const chainId = this.context.
|
|
1354
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1245
1355
|
if (!chainId) {
|
|
1246
1356
|
throw new Error("Chain ID not available");
|
|
1247
1357
|
}
|
|
1358
|
+
this.assertWallet();
|
|
1248
1359
|
const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
|
|
1249
1360
|
const dataRegistryAbi = getAbi("DataRegistry");
|
|
1250
|
-
const
|
|
1251
|
-
const
|
|
1361
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1362
|
+
const from = typeof account === "string" ? account : account.address;
|
|
1363
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1252
1364
|
address: dataRegistryAddress,
|
|
1253
1365
|
abi: dataRegistryAbi,
|
|
1254
1366
|
functionName: "addFileWithSchema",
|
|
1255
1367
|
args: [url, BigInt(schemaId)],
|
|
1256
|
-
account
|
|
1257
|
-
chain: this.context.walletClient.chain
|
|
1368
|
+
account,
|
|
1369
|
+
chain: this.context.walletClient.chain ?? null
|
|
1370
|
+
});
|
|
1371
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
1372
|
+
return tx({
|
|
1373
|
+
hash,
|
|
1374
|
+
from,
|
|
1375
|
+
contract: "DataRegistry",
|
|
1376
|
+
fn: "addFileWithSchema"
|
|
1258
1377
|
});
|
|
1259
|
-
const receipt = await this.context.publicClient.waitForTransactionReceipt(
|
|
1260
|
-
{
|
|
1261
|
-
hash: txHash,
|
|
1262
|
-
confirmations: 1
|
|
1263
|
-
}
|
|
1264
|
-
);
|
|
1265
|
-
const { parseFileAddedEvent } = await import("../utils/eventParsing");
|
|
1266
|
-
const eventData = parseFileAddedEvent(receipt);
|
|
1267
|
-
return {
|
|
1268
|
-
fileId: Number(eventData.fileId),
|
|
1269
|
-
transactionHash: txHash
|
|
1270
|
-
};
|
|
1271
1378
|
} catch (error) {
|
|
1272
1379
|
console.error("Failed to register file with schema:", error);
|
|
1273
1380
|
throw new Error(
|
|
@@ -1281,13 +1388,6 @@ class DataController {
|
|
|
1281
1388
|
* @returns Promise resolving to the user's wallet address
|
|
1282
1389
|
* @throws {Error} When no addresses are available in wallet client
|
|
1283
1390
|
*/
|
|
1284
|
-
async getUserAddress() {
|
|
1285
|
-
const addresses = await this.context.walletClient.getAddresses();
|
|
1286
|
-
if (addresses.length === 0) {
|
|
1287
|
-
throw new Error("No addresses available in wallet client");
|
|
1288
|
-
}
|
|
1289
|
-
return addresses[0];
|
|
1290
|
-
}
|
|
1291
1391
|
/**
|
|
1292
1392
|
* Adds a file with permissions to the DataRegistry contract.
|
|
1293
1393
|
*
|
|
@@ -1305,33 +1405,32 @@ class DataController {
|
|
|
1305
1405
|
* by both direct transactions and relayer services.
|
|
1306
1406
|
*/
|
|
1307
1407
|
async addFileWithPermissions(url, ownerAddress, permissions = []) {
|
|
1408
|
+
this.assertWallet();
|
|
1308
1409
|
try {
|
|
1309
|
-
const chainId = this.context.
|
|
1410
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1310
1411
|
if (!chainId) {
|
|
1311
1412
|
throw new Error("Chain ID not available");
|
|
1312
1413
|
}
|
|
1414
|
+
this.assertWallet();
|
|
1313
1415
|
const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
|
|
1314
1416
|
const dataRegistryAbi = getAbi("DataRegistry");
|
|
1315
|
-
const
|
|
1417
|
+
const account = this.context.walletClient.account ?? ownerAddress;
|
|
1418
|
+
const from = typeof account === "string" ? account : account.address;
|
|
1419
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1316
1420
|
address: dataRegistryAddress,
|
|
1317
1421
|
abi: dataRegistryAbi,
|
|
1318
1422
|
functionName: "addFileWithPermissions",
|
|
1319
1423
|
args: [url, ownerAddress, permissions],
|
|
1320
|
-
account
|
|
1321
|
-
chain: this.context.walletClient.chain
|
|
1424
|
+
account,
|
|
1425
|
+
chain: this.context.walletClient.chain ?? null
|
|
1426
|
+
});
|
|
1427
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
1428
|
+
return tx({
|
|
1429
|
+
hash,
|
|
1430
|
+
from,
|
|
1431
|
+
contract: "DataRegistry",
|
|
1432
|
+
fn: "addFileWithPermissions"
|
|
1322
1433
|
});
|
|
1323
|
-
const receipt = await this.context.publicClient.waitForTransactionReceipt(
|
|
1324
|
-
{
|
|
1325
|
-
hash: txHash,
|
|
1326
|
-
confirmations: 1
|
|
1327
|
-
}
|
|
1328
|
-
);
|
|
1329
|
-
const { parseFileAddedEvent } = await import("../utils/eventParsing");
|
|
1330
|
-
const eventData = parseFileAddedEvent(receipt);
|
|
1331
|
-
return {
|
|
1332
|
-
fileId: Number(eventData.fileId),
|
|
1333
|
-
transactionHash: txHash
|
|
1334
|
-
};
|
|
1335
1434
|
} catch (error) {
|
|
1336
1435
|
console.error("Failed to add file with permissions:", error);
|
|
1337
1436
|
throw new Error(
|
|
@@ -1343,44 +1442,148 @@ class DataController {
|
|
|
1343
1442
|
* Adds a file to the registry with permissions and schema.
|
|
1344
1443
|
* This combines the functionality of addFileWithPermissions and schema validation.
|
|
1345
1444
|
*
|
|
1445
|
+
* @remarks
|
|
1446
|
+
* This method automatically encrypts permissions when a publicKey is provided.
|
|
1447
|
+
* It generates the user's encryption key and encrypts it with each recipient's
|
|
1448
|
+
* public key before registering on the blockchain.
|
|
1449
|
+
*
|
|
1346
1450
|
* @param url - The URL of the file to register
|
|
1347
1451
|
* @param ownerAddress - The address of the file owner
|
|
1348
|
-
* @param permissions - Array of permissions to grant
|
|
1452
|
+
* @param permissions - Array of permissions to grant, each with account and publicKey properties
|
|
1349
1453
|
* @param schemaId - The schema ID to associate with the file (0 for no schema)
|
|
1350
|
-
* @returns Promise resolving to
|
|
1351
|
-
* @throws {Error} When chain
|
|
1352
|
-
* @throws {
|
|
1353
|
-
* @throws {Error} When
|
|
1354
|
-
* @throws {Error}
|
|
1454
|
+
* @returns Promise resolving to TransactionResult with fileId and transactionHash
|
|
1455
|
+
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1456
|
+
* @throws {Error} "Failed to generate encryption key" - When encryption key generation fails
|
|
1457
|
+
* @throws {Error} "Permission for {account} must include 'publicKey'" - When publicKey is missing
|
|
1458
|
+
* @throws {Error} "Failed to add file with permissions and schema: {error}" - When transaction fails
|
|
1459
|
+
* @example
|
|
1460
|
+
* ```typescript
|
|
1461
|
+
* // Get server's public key
|
|
1462
|
+
* const serverIdentity = await vana.server.getIdentity({
|
|
1463
|
+
* userAddress: "0x..."
|
|
1464
|
+
* });
|
|
1465
|
+
*
|
|
1466
|
+
* // Add file with permissions and schema
|
|
1467
|
+
* const result = await vana.data.addFileWithPermissionsAndSchema(
|
|
1468
|
+
* "ipfs://QmXxx...",
|
|
1469
|
+
* ownerAddress,
|
|
1470
|
+
* [{
|
|
1471
|
+
* account: serverIdentity.address,
|
|
1472
|
+
* publicKey: serverIdentity.publicKey
|
|
1473
|
+
* }],
|
|
1474
|
+
* schemaId
|
|
1475
|
+
* );
|
|
1476
|
+
*
|
|
1477
|
+
* console.log(`File ${result.fileId} registered in tx ${result.hash}`);
|
|
1478
|
+
* ```
|
|
1355
1479
|
*/
|
|
1356
1480
|
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1481
|
+
this.assertWallet();
|
|
1357
1482
|
try {
|
|
1358
|
-
|
|
1483
|
+
let encryptedPermissions = [];
|
|
1484
|
+
if (permissions.length > 0) {
|
|
1485
|
+
this.assertWallet();
|
|
1486
|
+
const userEncryptionKey = await generateEncryptionKey(
|
|
1487
|
+
this.context.walletClient,
|
|
1488
|
+
this.context.platform,
|
|
1489
|
+
DEFAULT_ENCRYPTION_SEED
|
|
1490
|
+
);
|
|
1491
|
+
encryptedPermissions = await Promise.all(
|
|
1492
|
+
permissions.map(async (permission) => {
|
|
1493
|
+
if (!permission.publicKey) {
|
|
1494
|
+
throw new Error(
|
|
1495
|
+
`Permission for ${permission.account} must include 'publicKey'`
|
|
1496
|
+
);
|
|
1497
|
+
}
|
|
1498
|
+
const encryptedKey = await encryptWithWalletPublicKey(
|
|
1499
|
+
userEncryptionKey,
|
|
1500
|
+
permission.publicKey,
|
|
1501
|
+
this.context.platform
|
|
1502
|
+
);
|
|
1503
|
+
return {
|
|
1504
|
+
account: permission.account,
|
|
1505
|
+
key: encryptedKey
|
|
1506
|
+
};
|
|
1507
|
+
})
|
|
1508
|
+
);
|
|
1509
|
+
}
|
|
1510
|
+
return await this.addFileWithEncryptedPermissionsAndSchema(
|
|
1511
|
+
url,
|
|
1512
|
+
ownerAddress,
|
|
1513
|
+
encryptedPermissions,
|
|
1514
|
+
schemaId
|
|
1515
|
+
);
|
|
1516
|
+
} catch (error) {
|
|
1517
|
+
console.error("Failed to add file with permissions and schema:", error);
|
|
1518
|
+
throw new Error(
|
|
1519
|
+
`Failed to add file with permissions and schema: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
1520
|
+
);
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
/**
|
|
1524
|
+
* Adds a file with pre-encrypted permissions and schema to the DataRegistry.
|
|
1525
|
+
*
|
|
1526
|
+
* @remarks
|
|
1527
|
+
* This method is designed for relay services and advanced use cases where permissions
|
|
1528
|
+
* have already been encrypted client-side. Unlike `addFileWithPermissionsAndSchema()`,
|
|
1529
|
+
* this method expects permissions in the encrypted format with a 'key' field instead
|
|
1530
|
+
* of 'publicKey'.
|
|
1531
|
+
*
|
|
1532
|
+
* This is typically used by relay endpoints that receive pre-encrypted data from
|
|
1533
|
+
* the client SDK's `upload()` method, avoiding double encryption.
|
|
1534
|
+
*
|
|
1535
|
+
* @param url - The storage URL of the file (e.g., IPFS URL)
|
|
1536
|
+
* @param ownerAddress - The address that will own this file
|
|
1537
|
+
* @param permissions - Array of pre-encrypted permissions with 'account' and 'key' fields
|
|
1538
|
+
* @param schemaId - Optional schema ID for data validation (defaults to 0)
|
|
1539
|
+
* @returns Promise resolving to transaction result with hash and contract details
|
|
1540
|
+
* @throws {Error} When chain ID is not available
|
|
1541
|
+
* @throws {Error} When wallet is not connected
|
|
1542
|
+
* @throws {Error} When transaction fails
|
|
1543
|
+
* @example
|
|
1544
|
+
* ```typescript
|
|
1545
|
+
* // In a relay endpoint that receives pre-encrypted permissions
|
|
1546
|
+
* const result = await vana.data.addFileWithEncryptedPermissionsAndSchema(
|
|
1547
|
+
* "ipfs://QmXxx...",
|
|
1548
|
+
* ownerAddress,
|
|
1549
|
+
* [
|
|
1550
|
+
* {
|
|
1551
|
+
* account: "0xServerAddress...",
|
|
1552
|
+
* key: "encrypted_key_string" // Already encrypted by client
|
|
1553
|
+
* }
|
|
1554
|
+
* ],
|
|
1555
|
+
* schemaId
|
|
1556
|
+
* );
|
|
1557
|
+
*
|
|
1558
|
+
* console.log(`File registered in tx ${result.hash}`);
|
|
1559
|
+
* ```
|
|
1560
|
+
*/
|
|
1561
|
+
async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1562
|
+
try {
|
|
1563
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1359
1564
|
if (!chainId) {
|
|
1360
1565
|
throw new Error("Chain ID not available");
|
|
1361
1566
|
}
|
|
1567
|
+
this.assertWallet();
|
|
1362
1568
|
const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
|
|
1363
1569
|
const dataRegistryAbi = getAbi("DataRegistry");
|
|
1364
|
-
const
|
|
1570
|
+
const account = this.context.walletClient.account ?? ownerAddress;
|
|
1571
|
+
const from = typeof account === "string" ? account : account.address;
|
|
1572
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1365
1573
|
address: dataRegistryAddress,
|
|
1366
1574
|
abi: dataRegistryAbi,
|
|
1367
1575
|
functionName: "addFileWithPermissionsAndSchema",
|
|
1368
1576
|
args: [url, ownerAddress, permissions, BigInt(schemaId)],
|
|
1369
|
-
account
|
|
1370
|
-
chain: this.context.walletClient.chain
|
|
1577
|
+
account,
|
|
1578
|
+
chain: this.context.walletClient.chain ?? null
|
|
1579
|
+
});
|
|
1580
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
1581
|
+
return tx({
|
|
1582
|
+
hash,
|
|
1583
|
+
from,
|
|
1584
|
+
contract: "DataRegistry",
|
|
1585
|
+
fn: "addFileWithPermissionsAndSchema"
|
|
1371
1586
|
});
|
|
1372
|
-
const receipt = await this.context.publicClient.waitForTransactionReceipt(
|
|
1373
|
-
{
|
|
1374
|
-
hash: txHash,
|
|
1375
|
-
confirmations: 1
|
|
1376
|
-
}
|
|
1377
|
-
);
|
|
1378
|
-
const { parseFileAddedEvent } = await import("../utils/eventParsing");
|
|
1379
|
-
const eventData = parseFileAddedEvent(receipt);
|
|
1380
|
-
return {
|
|
1381
|
-
fileId: Number(eventData.fileId),
|
|
1382
|
-
transactionHash: txHash
|
|
1383
|
-
};
|
|
1384
1587
|
} catch (error) {
|
|
1385
1588
|
console.error("Failed to add file with permissions and schema:", error);
|
|
1386
1589
|
throw new Error(
|
|
@@ -1417,8 +1620,9 @@ class DataController {
|
|
|
1417
1620
|
* ```
|
|
1418
1621
|
*/
|
|
1419
1622
|
async addRefiner(params) {
|
|
1623
|
+
this.assertWallet();
|
|
1420
1624
|
try {
|
|
1421
|
-
const chainId = this.context.
|
|
1625
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1422
1626
|
if (!chainId) {
|
|
1423
1627
|
throw new Error("Chain ID not available");
|
|
1424
1628
|
}
|
|
@@ -1427,7 +1631,10 @@ class DataController {
|
|
|
1427
1631
|
"DataRefinerRegistry"
|
|
1428
1632
|
);
|
|
1429
1633
|
const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
|
|
1430
|
-
|
|
1634
|
+
this.assertWallet();
|
|
1635
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1636
|
+
const from = typeof account === "string" ? account : account.address;
|
|
1637
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1431
1638
|
address: dataRefinerRegistryAddress,
|
|
1432
1639
|
abi: dataRefinerRegistryAbi,
|
|
1433
1640
|
functionName: "addRefinerWithSchemaId",
|
|
@@ -1437,20 +1644,27 @@ class DataController {
|
|
|
1437
1644
|
BigInt(params.schemaId),
|
|
1438
1645
|
params.refinementInstructionUrl
|
|
1439
1646
|
],
|
|
1440
|
-
account
|
|
1441
|
-
chain: this.context.walletClient.chain
|
|
1647
|
+
account,
|
|
1648
|
+
chain: this.context.walletClient.chain ?? null
|
|
1442
1649
|
});
|
|
1443
|
-
const
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1650
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
1651
|
+
const txResult = tx({
|
|
1652
|
+
hash,
|
|
1653
|
+
from,
|
|
1654
|
+
contract: "DataRefinerRegistry",
|
|
1655
|
+
fn: "addRefinerWithSchemaId"
|
|
1656
|
+
});
|
|
1657
|
+
if (!this.context.waitForTransactionEvents) {
|
|
1658
|
+
throw new Error("waitForTransactionEvents not configured");
|
|
1659
|
+
}
|
|
1660
|
+
const result = await this.context.waitForTransactionEvents(txResult);
|
|
1661
|
+
const event = result.expectedEvents.RefinerAdded;
|
|
1662
|
+
if (!event) {
|
|
1663
|
+
throw new Error("RefinerAdded event not found in transaction");
|
|
1664
|
+
}
|
|
1451
1665
|
return {
|
|
1452
|
-
refinerId: Number(
|
|
1453
|
-
transactionHash:
|
|
1666
|
+
refinerId: Number(event.refinerId),
|
|
1667
|
+
transactionHash: hash
|
|
1454
1668
|
};
|
|
1455
1669
|
} catch (error) {
|
|
1456
1670
|
console.error("Failed to add refiner:", error);
|
|
@@ -1484,7 +1698,7 @@ class DataController {
|
|
|
1484
1698
|
*/
|
|
1485
1699
|
async getRefiner(refinerId) {
|
|
1486
1700
|
try {
|
|
1487
|
-
const chainId = this.context.
|
|
1701
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1488
1702
|
if (!chainId) {
|
|
1489
1703
|
throw new Error("Chain ID not available");
|
|
1490
1704
|
}
|
|
@@ -1496,7 +1710,7 @@ class DataController {
|
|
|
1496
1710
|
const dataRefinerRegistry = getContract({
|
|
1497
1711
|
address: dataRefinerRegistryAddress,
|
|
1498
1712
|
abi: dataRefinerRegistryAbi,
|
|
1499
|
-
client: this.context.
|
|
1713
|
+
client: this.context.publicClient
|
|
1500
1714
|
});
|
|
1501
1715
|
const refinerData = await dataRefinerRegistry.read.refiners([
|
|
1502
1716
|
BigInt(refinerId)
|
|
@@ -1540,7 +1754,7 @@ class DataController {
|
|
|
1540
1754
|
*/
|
|
1541
1755
|
async isValidSchemaId(schemaId) {
|
|
1542
1756
|
try {
|
|
1543
|
-
const chainId = this.context.
|
|
1757
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1544
1758
|
if (!chainId) {
|
|
1545
1759
|
throw new Error("Chain ID not available");
|
|
1546
1760
|
}
|
|
@@ -1552,7 +1766,7 @@ class DataController {
|
|
|
1552
1766
|
const dataRefinerRegistry = getContract({
|
|
1553
1767
|
address: dataRefinerRegistryAddress,
|
|
1554
1768
|
abi: dataRefinerRegistryAbi,
|
|
1555
|
-
client: this.context.
|
|
1769
|
+
client: this.context.publicClient
|
|
1556
1770
|
});
|
|
1557
1771
|
const isValid = await dataRefinerRegistry.read.isValidSchemaId([
|
|
1558
1772
|
BigInt(schemaId)
|
|
@@ -1579,7 +1793,7 @@ class DataController {
|
|
|
1579
1793
|
*/
|
|
1580
1794
|
async getRefinersCount() {
|
|
1581
1795
|
try {
|
|
1582
|
-
const chainId = this.context.
|
|
1796
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1583
1797
|
if (!chainId) {
|
|
1584
1798
|
throw new Error("Chain ID not available");
|
|
1585
1799
|
}
|
|
@@ -1591,7 +1805,7 @@ class DataController {
|
|
|
1591
1805
|
const dataRefinerRegistry = getContract({
|
|
1592
1806
|
address: dataRefinerRegistryAddress,
|
|
1593
1807
|
abi: dataRefinerRegistryAbi,
|
|
1594
|
-
client: this.context.
|
|
1808
|
+
client: this.context.publicClient
|
|
1595
1809
|
});
|
|
1596
1810
|
const count = await dataRefinerRegistry.read.refinersCount();
|
|
1597
1811
|
return Number(count);
|
|
@@ -1623,8 +1837,9 @@ class DataController {
|
|
|
1623
1837
|
* ```
|
|
1624
1838
|
*/
|
|
1625
1839
|
async updateSchemaId(params) {
|
|
1840
|
+
this.assertWallet();
|
|
1626
1841
|
try {
|
|
1627
|
-
const chainId = this.context.
|
|
1842
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1628
1843
|
if (!chainId) {
|
|
1629
1844
|
throw new Error("Chain ID not available");
|
|
1630
1845
|
}
|
|
@@ -1633,20 +1848,19 @@ class DataController {
|
|
|
1633
1848
|
"DataRefinerRegistry"
|
|
1634
1849
|
);
|
|
1635
1850
|
const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
|
|
1636
|
-
|
|
1851
|
+
this.assertWallet();
|
|
1852
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1853
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1637
1854
|
address: dataRefinerRegistryAddress,
|
|
1638
1855
|
abi: dataRefinerRegistryAbi,
|
|
1639
1856
|
functionName: "updateSchemaId",
|
|
1640
1857
|
args: [BigInt(params.refinerId), BigInt(params.newSchemaId)],
|
|
1641
|
-
account
|
|
1642
|
-
chain: this.context.walletClient.chain
|
|
1643
|
-
});
|
|
1644
|
-
await this.context.publicClient.waitForTransactionReceipt({
|
|
1645
|
-
hash: txHash,
|
|
1646
|
-
timeout: 3e4
|
|
1858
|
+
account,
|
|
1859
|
+
chain: this.context.walletClient.chain ?? null
|
|
1647
1860
|
});
|
|
1861
|
+
await this.context.publicClient.waitForTransactionReceipt({ hash });
|
|
1648
1862
|
return {
|
|
1649
|
-
transactionHash:
|
|
1863
|
+
transactionHash: hash
|
|
1650
1864
|
};
|
|
1651
1865
|
} catch (error) {
|
|
1652
1866
|
console.error("Failed to update schema ID:", error);
|
|
@@ -1664,13 +1878,12 @@ class DataController {
|
|
|
1664
1878
|
* 3. Encrypts the user's encryption key with the provided public key
|
|
1665
1879
|
* 4. Registers the file with permissions
|
|
1666
1880
|
*
|
|
1667
|
-
* @param
|
|
1668
|
-
* @param permissions - Array of permissions to grant, each with account address and public key
|
|
1669
|
-
* @param filename - Optional filename for the upload
|
|
1670
|
-
* @param providerName - Optional storage provider to use
|
|
1881
|
+
* @param params - Upload parameters including data, permissions, and options
|
|
1671
1882
|
* @returns Promise resolving to upload result with file ID and storage URL
|
|
1672
1883
|
*/
|
|
1673
|
-
async uploadFileWithPermissions(
|
|
1884
|
+
async uploadFileWithPermissions(params) {
|
|
1885
|
+
this.assertWallet();
|
|
1886
|
+
const { data, permissions, filename, providerName } = params;
|
|
1674
1887
|
try {
|
|
1675
1888
|
const uploadResult = await this.uploadToStorage(
|
|
1676
1889
|
data,
|
|
@@ -1679,7 +1892,7 @@ class DataController {
|
|
|
1679
1892
|
// Always encrypt for uploadFileWithPermissions
|
|
1680
1893
|
providerName
|
|
1681
1894
|
);
|
|
1682
|
-
const userAddress =
|
|
1895
|
+
const userAddress = this.context.userAddress;
|
|
1683
1896
|
const userEncryptionKey = await generateEncryptionKey(
|
|
1684
1897
|
this.context.walletClient,
|
|
1685
1898
|
this.context.platform,
|
|
@@ -1698,26 +1911,53 @@ class DataController {
|
|
|
1698
1911
|
};
|
|
1699
1912
|
})
|
|
1700
1913
|
);
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1914
|
+
if (this.context.relayer) {
|
|
1915
|
+
const request = {
|
|
1916
|
+
type: "direct",
|
|
1917
|
+
operation: "submitFileAdditionWithPermissions",
|
|
1918
|
+
params: {
|
|
1919
|
+
url: uploadResult.url,
|
|
1920
|
+
userAddress,
|
|
1921
|
+
permissions: encryptedPermissions
|
|
1922
|
+
}
|
|
1923
|
+
};
|
|
1924
|
+
const response = await this.context.relayer(request);
|
|
1925
|
+
if (response.type === "error") {
|
|
1926
|
+
throw new Error(response.error);
|
|
1927
|
+
}
|
|
1928
|
+
if (response.type !== "direct" || !("fileId" in response.result)) {
|
|
1929
|
+
throw new Error("Invalid response from relayer");
|
|
1930
|
+
}
|
|
1931
|
+
const result = response.result;
|
|
1932
|
+
return {
|
|
1933
|
+
fileId: result.fileId,
|
|
1934
|
+
url: uploadResult.url,
|
|
1935
|
+
size: uploadResult.size,
|
|
1936
|
+
transactionHash: result.transactionHash
|
|
1937
|
+
};
|
|
1708
1938
|
} else {
|
|
1709
|
-
|
|
1939
|
+
const txResult = await this.addFileWithPermissions(
|
|
1710
1940
|
uploadResult.url,
|
|
1711
1941
|
userAddress,
|
|
1712
1942
|
encryptedPermissions
|
|
1713
1943
|
);
|
|
1944
|
+
if (!this.context.waitForTransactionEvents) {
|
|
1945
|
+
throw new Error(
|
|
1946
|
+
"Cannot upload without relay: waitForTransactionEvents not configured"
|
|
1947
|
+
);
|
|
1948
|
+
}
|
|
1949
|
+
const eventResult = await this.context.waitForTransactionEvents(txResult);
|
|
1950
|
+
const fileAddedEvent = eventResult.expectedEvents.FileAdded;
|
|
1951
|
+
if (!fileAddedEvent) {
|
|
1952
|
+
throw new Error("FileAdded event not found in transaction");
|
|
1953
|
+
}
|
|
1954
|
+
return {
|
|
1955
|
+
fileId: Number(fileAddedEvent.fileId),
|
|
1956
|
+
url: uploadResult.url,
|
|
1957
|
+
size: uploadResult.size,
|
|
1958
|
+
transactionHash: txResult.hash
|
|
1959
|
+
};
|
|
1714
1960
|
}
|
|
1715
|
-
return {
|
|
1716
|
-
fileId: result.fileId,
|
|
1717
|
-
url: uploadResult.url,
|
|
1718
|
-
size: uploadResult.size,
|
|
1719
|
-
transactionHash: result.transactionHash
|
|
1720
|
-
};
|
|
1721
1961
|
} catch (error) {
|
|
1722
1962
|
console.error("Failed to upload file with permissions:", error);
|
|
1723
1963
|
throw new Error(
|
|
@@ -1755,6 +1995,7 @@ class DataController {
|
|
|
1755
1995
|
}
|
|
1756
1996
|
let finalBlob = blob;
|
|
1757
1997
|
if (encrypt) {
|
|
1998
|
+
this.assertWallet();
|
|
1758
1999
|
const encryptionKey = await generateEncryptionKey(
|
|
1759
2000
|
this.context.walletClient,
|
|
1760
2001
|
this.context.platform,
|
|
@@ -1776,7 +2017,7 @@ class DataController {
|
|
|
1776
2017
|
);
|
|
1777
2018
|
}
|
|
1778
2019
|
}
|
|
1779
|
-
const finalFilename = filename
|
|
2020
|
+
const finalFilename = filename ?? `upload-${Date.now()}.dat`;
|
|
1780
2021
|
const uploadResult = await this.context.storageManager.upload(
|
|
1781
2022
|
finalBlob,
|
|
1782
2023
|
finalFilename,
|
|
@@ -1801,21 +2042,29 @@ class DataController {
|
|
|
1801
2042
|
* For advanced users who need more control over transaction timing,
|
|
1802
2043
|
* use `submitFilePermission()` instead.
|
|
1803
2044
|
*
|
|
1804
|
-
* @param
|
|
1805
|
-
* @param
|
|
1806
|
-
* @param
|
|
2045
|
+
* @param params - Parameters for adding file permission
|
|
2046
|
+
* @param params.fileId - The ID of the file to grant permission for
|
|
2047
|
+
* @param params.account - The recipient's wallet address that will access the file
|
|
2048
|
+
* @param params.publicKey - The recipient's public key for encryption.
|
|
2049
|
+
* Obtain via `vana.server.getIdentity(account).publicKey`
|
|
1807
2050
|
* @returns Promise resolving to permission data from PermissionGranted event
|
|
1808
2051
|
* @throws {Error} "No addresses available in wallet client" - When wallet is not connected
|
|
1809
2052
|
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1810
2053
|
* @throws {Error} "Failed to add permission to file: {error}" - When transaction fails or user doesn't own file
|
|
1811
2054
|
* @example
|
|
1812
2055
|
* ```typescript
|
|
1813
|
-
* const result = await vana.data.addPermissionToFile(
|
|
2056
|
+
* const result = await vana.data.addPermissionToFile({
|
|
2057
|
+
* fileId: 123,
|
|
2058
|
+
* account: "0xRecipientAddress...",
|
|
2059
|
+
* publicKey: "0xRecipientPublicKey..."
|
|
2060
|
+
* });
|
|
1814
2061
|
* console.log(`Permission granted to ${result.account} for file ${result.fileId}`);
|
|
1815
2062
|
* console.log(`Transaction: ${result.transactionHash}`);
|
|
1816
2063
|
* ```
|
|
1817
2064
|
*/
|
|
1818
|
-
async addPermissionToFile(
|
|
2065
|
+
async addPermissionToFile(params) {
|
|
2066
|
+
this.assertWallet();
|
|
2067
|
+
const { fileId, account, publicKey } = params;
|
|
1819
2068
|
return await this.submitFilePermission(fileId, account, publicKey);
|
|
1820
2069
|
}
|
|
1821
2070
|
/**
|
|
@@ -1829,7 +2078,7 @@ class DataController {
|
|
|
1829
2078
|
* @param fileId - The ID of the file to grant permission for
|
|
1830
2079
|
* @param account - The recipient's wallet address that will access the file
|
|
1831
2080
|
* @param publicKey - The recipient's public key for encryption.
|
|
1832
|
-
* Obtain via `vana.server.getIdentity(account).
|
|
2081
|
+
* Obtain via `vana.server.getIdentity(account).publicKey`
|
|
1833
2082
|
* @returns Promise resolving to TransactionResult for tracking the transaction
|
|
1834
2083
|
* @throws {Error} When chain ID is not available
|
|
1835
2084
|
* @throws {Error} When encryption key generation fails
|
|
@@ -1847,6 +2096,7 @@ class DataController {
|
|
|
1847
2096
|
* ```
|
|
1848
2097
|
*/
|
|
1849
2098
|
async submitFilePermission(fileId, account, publicKey) {
|
|
2099
|
+
this.assertWallet();
|
|
1850
2100
|
try {
|
|
1851
2101
|
const userEncryptionKey = await generateEncryptionKey(
|
|
1852
2102
|
this.context.walletClient,
|
|
@@ -1858,24 +2108,29 @@ class DataController {
|
|
|
1858
2108
|
publicKey,
|
|
1859
2109
|
this.context.platform
|
|
1860
2110
|
);
|
|
1861
|
-
const chainId = this.context.
|
|
2111
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1862
2112
|
if (!chainId) {
|
|
1863
2113
|
throw new Error("Chain ID not available");
|
|
1864
2114
|
}
|
|
1865
2115
|
const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
|
|
1866
2116
|
const dataRegistryAbi = getAbi("DataRegistry");
|
|
2117
|
+
this.assertWallet();
|
|
2118
|
+
const walletAccount = this.context.walletClient.account ?? this.context.userAddress;
|
|
1867
2119
|
const txHash = await this.context.walletClient.writeContract({
|
|
1868
2120
|
address: dataRegistryAddress,
|
|
1869
2121
|
abi: dataRegistryAbi,
|
|
1870
2122
|
functionName: "addFilePermission",
|
|
1871
2123
|
args: [BigInt(fileId), account, encryptedKey],
|
|
1872
|
-
account:
|
|
1873
|
-
chain: this.context.walletClient.chain
|
|
2124
|
+
account: walletAccount,
|
|
2125
|
+
chain: this.context.walletClient.chain ?? null
|
|
1874
2126
|
});
|
|
1875
|
-
|
|
2127
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
2128
|
+
return tx({
|
|
1876
2129
|
hash: txHash,
|
|
1877
|
-
from:
|
|
1878
|
-
|
|
2130
|
+
from: typeof walletAccount === "string" ? walletAccount : walletAccount.address,
|
|
2131
|
+
contract: "DataRegistry",
|
|
2132
|
+
fn: "addFilePermission"
|
|
2133
|
+
});
|
|
1879
2134
|
} catch (error) {
|
|
1880
2135
|
console.error("Failed to add permission to file:", error);
|
|
1881
2136
|
throw new Error(
|
|
@@ -1892,7 +2147,7 @@ class DataController {
|
|
|
1892
2147
|
*/
|
|
1893
2148
|
async getFilePermission(fileId, account) {
|
|
1894
2149
|
try {
|
|
1895
|
-
const chainId = this.context.
|
|
2150
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1896
2151
|
if (!chainId) {
|
|
1897
2152
|
throw new Error("Chain ID not available");
|
|
1898
2153
|
}
|
|
@@ -1901,7 +2156,7 @@ class DataController {
|
|
|
1901
2156
|
const dataRegistry = getContract({
|
|
1902
2157
|
address: dataRegistryAddress,
|
|
1903
2158
|
abi: dataRegistryAbi,
|
|
1904
|
-
client: this.context.
|
|
2159
|
+
client: this.context.publicClient
|
|
1905
2160
|
});
|
|
1906
2161
|
const encryptedKey = await dataRegistry.read.filePermissions([
|
|
1907
2162
|
BigInt(fileId),
|
|
@@ -1925,12 +2180,13 @@ class DataController {
|
|
|
1925
2180
|
*
|
|
1926
2181
|
* @param file - The file to decrypt
|
|
1927
2182
|
* @param privateKey - The private key to decrypt the user's encryption key
|
|
1928
|
-
* @param
|
|
2183
|
+
* @param options - Optional decryption configuration
|
|
2184
|
+
* @param options.account - The account address that has permission (defaults to current wallet account)
|
|
1929
2185
|
* @returns Promise resolving to the decrypted file data
|
|
1930
2186
|
*/
|
|
1931
|
-
async decryptFileWithPermission(file, privateKey,
|
|
2187
|
+
async decryptFileWithPermission(file, privateKey, options) {
|
|
1932
2188
|
try {
|
|
1933
|
-
const permissionAccount = account
|
|
2189
|
+
const permissionAccount = options?.account ?? this.context.userAddress;
|
|
1934
2190
|
const encryptedKey = await this.getFilePermission(
|
|
1935
2191
|
file.id,
|
|
1936
2192
|
permissionAccount
|
|
@@ -1994,11 +2250,8 @@ class DataController {
|
|
|
1994
2250
|
*/
|
|
1995
2251
|
async fetch(url) {
|
|
1996
2252
|
try {
|
|
1997
|
-
const {
|
|
1998
|
-
const response = await
|
|
1999
|
-
url,
|
|
2000
|
-
this.context.downloadRelayer
|
|
2001
|
-
);
|
|
2253
|
+
const { universalFetch } = await import("../utils/download");
|
|
2254
|
+
const response = await universalFetch(url, this.context.downloadRelayer);
|
|
2002
2255
|
if (!response.ok) {
|
|
2003
2256
|
throw new Error(
|
|
2004
2257
|
`HTTP error! status: ${response.status} ${response.statusText}`
|
|
@@ -2063,7 +2316,7 @@ class DataController {
|
|
|
2063
2316
|
"https://dweb.link/ipfs/",
|
|
2064
2317
|
"https://ipfs.io/ipfs/"
|
|
2065
2318
|
];
|
|
2066
|
-
const gateways = options?.gateways
|
|
2319
|
+
const gateways = options?.gateways ?? this.context.ipfsGateways ?? defaultGateways;
|
|
2067
2320
|
const { extractIpfsHash } = await import("../utils/ipfs");
|
|
2068
2321
|
const cid = extractIpfsHash(url);
|
|
2069
2322
|
if (!cid) {
|
|
@@ -2192,7 +2445,7 @@ class DataController {
|
|
|
2192
2445
|
* ```
|
|
2193
2446
|
*/
|
|
2194
2447
|
validateDataAgainstSchema(data, schema) {
|
|
2195
|
-
|
|
2448
|
+
validateDataAgainstSchema(data, schema);
|
|
2196
2449
|
}
|
|
2197
2450
|
/**
|
|
2198
2451
|
* Fetches and validates a data schema from a URL, then returns the parsed data schema.
|