@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
|
@@ -32,6 +32,7 @@ __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");
|
|
@@ -39,11 +40,12 @@ var import_graphql = require("graphql");
|
|
|
39
40
|
var import_encryption = require("../utils/encryption");
|
|
40
41
|
var import_schemaValidation = require("../utils/schemaValidation");
|
|
41
42
|
var import_multicall = require("../utils/multicall");
|
|
42
|
-
class DataController {
|
|
43
|
+
class DataController extends import_base.BaseController {
|
|
43
44
|
constructor(context) {
|
|
44
|
-
|
|
45
|
+
super(context);
|
|
45
46
|
}
|
|
46
47
|
async upload(params) {
|
|
48
|
+
this.assertWallet();
|
|
47
49
|
const {
|
|
48
50
|
content,
|
|
49
51
|
filename,
|
|
@@ -68,15 +70,28 @@ class DataController {
|
|
|
68
70
|
} catch {
|
|
69
71
|
parsedContent = content;
|
|
70
72
|
}
|
|
73
|
+
} else if (content instanceof Blob) {
|
|
74
|
+
const text = await content.text();
|
|
75
|
+
try {
|
|
76
|
+
parsedContent = JSON.parse(text);
|
|
77
|
+
} catch {
|
|
78
|
+
parsedContent = text;
|
|
79
|
+
}
|
|
71
80
|
} else {
|
|
72
81
|
parsedContent = content;
|
|
73
82
|
}
|
|
74
83
|
(0, import_schemaValidation.validateDataAgainstSchema)(parsedContent, schema);
|
|
75
84
|
} catch (error) {
|
|
76
85
|
isValid = false;
|
|
77
|
-
|
|
78
|
-
error
|
|
79
|
-
|
|
86
|
+
if (error instanceof Error) {
|
|
87
|
+
if (typeof error === "object" && "errors" in error && Array.isArray(error.errors)) {
|
|
88
|
+
validationErrors = error.errors;
|
|
89
|
+
} else {
|
|
90
|
+
validationErrors = [error.message];
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
validationErrors = ["Schema validation failed"];
|
|
94
|
+
}
|
|
80
95
|
}
|
|
81
96
|
}
|
|
82
97
|
const uploadResult = await this.uploadToStorage(
|
|
@@ -85,9 +100,10 @@ class DataController {
|
|
|
85
100
|
encrypt,
|
|
86
101
|
providerName
|
|
87
102
|
);
|
|
88
|
-
const userAddress = owner
|
|
103
|
+
const userAddress = owner ?? this.context.userAddress;
|
|
89
104
|
let encryptedPermissions = [];
|
|
90
105
|
if (permissions.length > 0 && encrypt) {
|
|
106
|
+
this.assertWallet();
|
|
91
107
|
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
92
108
|
this.context.walletClient,
|
|
93
109
|
this.context.platform,
|
|
@@ -108,34 +124,47 @@ class DataController {
|
|
|
108
124
|
);
|
|
109
125
|
}
|
|
110
126
|
let result;
|
|
111
|
-
if (this.context.
|
|
112
|
-
|
|
113
|
-
|
|
127
|
+
if (this.context.relayer) {
|
|
128
|
+
const request = {
|
|
129
|
+
type: "direct",
|
|
130
|
+
operation: "submitFileAdditionComplete",
|
|
131
|
+
params: {
|
|
114
132
|
url: uploadResult.url,
|
|
115
133
|
userAddress,
|
|
116
134
|
permissions: encryptedPermissions,
|
|
117
|
-
schemaId: schemaId
|
|
135
|
+
schemaId: schemaId ?? 0,
|
|
118
136
|
ownerAddress: owner
|
|
119
137
|
}
|
|
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
|
-
);
|
|
138
|
+
};
|
|
139
|
+
const response = await this.context.relayer(request);
|
|
140
|
+
if (response.type === "error") {
|
|
141
|
+
throw new Error(response.error);
|
|
127
142
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
143
|
+
if (response.type !== "direct" || !("fileId" in response.result)) {
|
|
144
|
+
throw new Error("Invalid response from relayer");
|
|
145
|
+
}
|
|
146
|
+
result = response.result;
|
|
132
147
|
} else {
|
|
133
|
-
|
|
148
|
+
const txResult = await this.addFileWithEncryptedPermissionsAndSchema(
|
|
134
149
|
uploadResult.url,
|
|
135
150
|
userAddress,
|
|
136
151
|
encryptedPermissions,
|
|
137
|
-
schemaId
|
|
152
|
+
schemaId ?? 0
|
|
138
153
|
);
|
|
154
|
+
if (!this.context.waitForTransactionEvents) {
|
|
155
|
+
throw new Error(
|
|
156
|
+
"Cannot upload without relay: waitForTransactionEvents not configured"
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
const eventResult = await this.context.waitForTransactionEvents(txResult);
|
|
160
|
+
const fileAddedEvent = eventResult.expectedEvents.FileAdded;
|
|
161
|
+
if (!fileAddedEvent) {
|
|
162
|
+
throw new Error("FileAdded event not found in transaction");
|
|
163
|
+
}
|
|
164
|
+
result = {
|
|
165
|
+
fileId: Number(fileAddedEvent.fileId),
|
|
166
|
+
transactionHash: txResult.hash
|
|
167
|
+
};
|
|
139
168
|
}
|
|
140
169
|
return {
|
|
141
170
|
fileId: result.fileId,
|
|
@@ -151,6 +180,83 @@ class DataController {
|
|
|
151
180
|
);
|
|
152
181
|
}
|
|
153
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* Encrypts data using wallet-derived encryption.
|
|
185
|
+
*
|
|
186
|
+
* @remarks
|
|
187
|
+
* This method provides secure, wallet-based encryption for data before uploading
|
|
188
|
+
* to the Vana network. It's the counterpart to decryptFile for preparing data
|
|
189
|
+
* for secure storage.
|
|
190
|
+
*
|
|
191
|
+
* The method automatically:
|
|
192
|
+
* - Generates an encryption key from the user's wallet signature
|
|
193
|
+
* - Converts the input data to a Blob if necessary
|
|
194
|
+
* - Encrypts the data using the generated key
|
|
195
|
+
* - Returns both the encrypted data and the encryption key
|
|
196
|
+
*
|
|
197
|
+
* The encryption key returned can be stored and later used for decryption,
|
|
198
|
+
* or shared with others to grant them decryption access.
|
|
199
|
+
*
|
|
200
|
+
* @param data - The data to encrypt (Blob, string, or object)
|
|
201
|
+
* @param options - Optional encryption configuration
|
|
202
|
+
* @returns Promise resolving to encrypted data and the encryption key used
|
|
203
|
+
* @throws {Error} When wallet is not connected or encryption fails
|
|
204
|
+
* @example
|
|
205
|
+
* ```typescript
|
|
206
|
+
* // Encrypt a string
|
|
207
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
208
|
+
* "My secret data"
|
|
209
|
+
* );
|
|
210
|
+
*
|
|
211
|
+
* // Encrypt JSON with custom MIME type
|
|
212
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
213
|
+
* { name: "Alice", age: 30 },
|
|
214
|
+
* { mimeType: "application/json" }
|
|
215
|
+
* );
|
|
216
|
+
*
|
|
217
|
+
* // With custom encryption seed
|
|
218
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
219
|
+
* "Secret message",
|
|
220
|
+
* { seed: "My custom encryption seed" }
|
|
221
|
+
* );
|
|
222
|
+
*
|
|
223
|
+
* // Upload the encrypted data
|
|
224
|
+
* const result = await vana.data.uploadToStorage(encryptedData);
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
async encryptFile(data, options) {
|
|
228
|
+
this.assertWallet();
|
|
229
|
+
try {
|
|
230
|
+
const encryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
231
|
+
this.context.walletClient,
|
|
232
|
+
this.context.platform,
|
|
233
|
+
options?.seed ?? import_encryption.DEFAULT_ENCRYPTION_SEED
|
|
234
|
+
);
|
|
235
|
+
let blob;
|
|
236
|
+
if (data instanceof Blob) {
|
|
237
|
+
blob = data;
|
|
238
|
+
} else if (typeof data === "string") {
|
|
239
|
+
blob = new Blob([data], { type: options?.mimeType ?? "text/plain" });
|
|
240
|
+
} else {
|
|
241
|
+
blob = new Blob([JSON.stringify(data)], {
|
|
242
|
+
type: options?.mimeType ?? "application/json"
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
const encryptedData = await (0, import_encryption.encryptBlobWithSignedKey)(
|
|
246
|
+
blob,
|
|
247
|
+
encryptionKey,
|
|
248
|
+
this.context.platform
|
|
249
|
+
);
|
|
250
|
+
return {
|
|
251
|
+
encryptedData,
|
|
252
|
+
encryptionKey
|
|
253
|
+
};
|
|
254
|
+
} catch (error) {
|
|
255
|
+
throw new Error(
|
|
256
|
+
`Failed to encrypt file: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
154
260
|
/**
|
|
155
261
|
* Decrypts a file owned by the user using their wallet signature.
|
|
156
262
|
*
|
|
@@ -206,12 +312,14 @@ class DataController {
|
|
|
206
312
|
* fs.writeFileSync('decrypted-file.txt', Buffer.from(buffer));
|
|
207
313
|
* ```
|
|
208
314
|
*/
|
|
209
|
-
async decryptFile(file,
|
|
315
|
+
async decryptFile(file, options) {
|
|
316
|
+
this.assertWallet();
|
|
210
317
|
try {
|
|
318
|
+
this.assertWallet();
|
|
211
319
|
const encryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
212
320
|
this.context.walletClient,
|
|
213
321
|
this.context.platform,
|
|
214
|
-
|
|
322
|
+
options?.seed ?? import_encryption.DEFAULT_ENCRYPTION_SEED
|
|
215
323
|
);
|
|
216
324
|
let encryptedBlob;
|
|
217
325
|
try {
|
|
@@ -328,7 +436,7 @@ class DataController {
|
|
|
328
436
|
*/
|
|
329
437
|
async getUserFiles(params) {
|
|
330
438
|
const { owner, subgraphUrl } = params;
|
|
331
|
-
const endpoint = subgraphUrl
|
|
439
|
+
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
332
440
|
if (!endpoint) {
|
|
333
441
|
throw new Error(
|
|
334
442
|
"subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor."
|
|
@@ -360,7 +468,7 @@ class DataController {
|
|
|
360
468
|
);
|
|
361
469
|
}
|
|
362
470
|
const user = result.data?.user;
|
|
363
|
-
if (!user
|
|
471
|
+
if (!user?.files?.length) {
|
|
364
472
|
console.warn("No files found for user:", owner);
|
|
365
473
|
return [];
|
|
366
474
|
}
|
|
@@ -382,7 +490,7 @@ class DataController {
|
|
|
382
490
|
}
|
|
383
491
|
});
|
|
384
492
|
const userFiles = Array.from(fileMap.values()).sort(
|
|
385
|
-
(a, b) => Number((b.addedAtTimestamp
|
|
493
|
+
(a, b) => Number((b.addedAtTimestamp ?? 0n) - (a.addedAtTimestamp ?? 0n))
|
|
386
494
|
);
|
|
387
495
|
if (userFiles.length > 0) {
|
|
388
496
|
try {
|
|
@@ -453,10 +561,11 @@ class DataController {
|
|
|
453
561
|
if (proof.dlp?.id) {
|
|
454
562
|
const fileId = parseInt(proof.fileId);
|
|
455
563
|
const dlpId = parseInt(proof.dlp.id);
|
|
456
|
-
|
|
457
|
-
|
|
564
|
+
let dlpIds = proofMap.get(fileId);
|
|
565
|
+
if (!dlpIds) {
|
|
566
|
+
dlpIds = [];
|
|
567
|
+
proofMap.set(fileId, dlpIds);
|
|
458
568
|
}
|
|
459
|
-
const dlpIds = proofMap.get(fileId);
|
|
460
569
|
if (!dlpIds.includes(dlpId)) {
|
|
461
570
|
dlpIds.push(dlpId);
|
|
462
571
|
}
|
|
@@ -474,7 +583,7 @@ class DataController {
|
|
|
474
583
|
* @returns Map of file IDs to their associated DLP IDs
|
|
475
584
|
*/
|
|
476
585
|
async _fetchProofsFromChain(fileIds) {
|
|
477
|
-
const chainId = this.context.
|
|
586
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
478
587
|
if (!chainId) {
|
|
479
588
|
throw new Error("Chain ID not available");
|
|
480
589
|
}
|
|
@@ -531,7 +640,7 @@ class DataController {
|
|
|
531
640
|
* ```
|
|
532
641
|
*/
|
|
533
642
|
async getDLP(dlpId, options = {}) {
|
|
534
|
-
const subgraphUrl = options.subgraphUrl
|
|
643
|
+
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
535
644
|
if (subgraphUrl) {
|
|
536
645
|
try {
|
|
537
646
|
const response = await fetch(subgraphUrl, {
|
|
@@ -562,18 +671,18 @@ class DataController {
|
|
|
562
671
|
}
|
|
563
672
|
return {
|
|
564
673
|
id: parseInt(result.data.dlp.id),
|
|
565
|
-
name: result.data.dlp.name
|
|
566
|
-
metadata: result.data.dlp.metadata
|
|
674
|
+
name: result.data.dlp.name ?? "",
|
|
675
|
+
metadata: result.data.dlp.metadata ?? void 0,
|
|
567
676
|
status: result.data.dlp.status ? parseInt(result.data.dlp.status) : void 0,
|
|
568
|
-
address: result.data.dlp.address,
|
|
569
|
-
owner: result.data.dlp.owner
|
|
677
|
+
address: result.data.dlp.address ? result.data.dlp.address : void 0,
|
|
678
|
+
owner: result.data.dlp.owner ? result.data.dlp.owner : void 0
|
|
570
679
|
};
|
|
571
680
|
} catch (error) {
|
|
572
681
|
console.debug("Subgraph query failed, falling back to chain:", error);
|
|
573
682
|
}
|
|
574
683
|
}
|
|
575
684
|
try {
|
|
576
|
-
const chainId = this.context.
|
|
685
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
577
686
|
if (!chainId) {
|
|
578
687
|
throw new Error("Chain ID not available");
|
|
579
688
|
}
|
|
@@ -585,7 +694,7 @@ class DataController {
|
|
|
585
694
|
functionName: "dlps",
|
|
586
695
|
args: [BigInt(dlpId)]
|
|
587
696
|
});
|
|
588
|
-
if (!dlpData
|
|
697
|
+
if (!dlpData?.name) {
|
|
589
698
|
throw new Error(`DLP not found: ${dlpId}`);
|
|
590
699
|
}
|
|
591
700
|
return {
|
|
@@ -627,7 +736,7 @@ class DataController {
|
|
|
627
736
|
*/
|
|
628
737
|
async listDLPs(options = {}) {
|
|
629
738
|
const { limit = 100, offset = 0 } = options;
|
|
630
|
-
const subgraphUrl = options.subgraphUrl
|
|
739
|
+
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
631
740
|
if (subgraphUrl) {
|
|
632
741
|
try {
|
|
633
742
|
const query = `
|
|
@@ -666,21 +775,21 @@ class DataController {
|
|
|
666
775
|
`Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
667
776
|
);
|
|
668
777
|
}
|
|
669
|
-
const dlps = result.data?.dlps
|
|
778
|
+
const dlps = result.data?.dlps ?? [];
|
|
670
779
|
return dlps.map((dlp) => ({
|
|
671
780
|
id: parseInt(dlp.id),
|
|
672
|
-
name: dlp.name
|
|
781
|
+
name: dlp.name ?? "",
|
|
673
782
|
metadata: dlp.metadata,
|
|
674
783
|
status: dlp.status ? parseInt(dlp.status) : void 0,
|
|
675
|
-
address: dlp.address,
|
|
676
|
-
owner: dlp.owner
|
|
784
|
+
address: dlp.address ? dlp.address : void 0,
|
|
785
|
+
owner: dlp.owner ? dlp.owner : void 0
|
|
677
786
|
}));
|
|
678
787
|
} catch (error) {
|
|
679
788
|
console.debug("Subgraph query failed, falling back to chain:", error);
|
|
680
789
|
}
|
|
681
790
|
}
|
|
682
791
|
try {
|
|
683
|
-
const chainId = this.context.
|
|
792
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
684
793
|
if (!chainId) {
|
|
685
794
|
throw new Error("Chain ID not available");
|
|
686
795
|
}
|
|
@@ -752,7 +861,7 @@ class DataController {
|
|
|
752
861
|
*/
|
|
753
862
|
async getUserPermissions(params) {
|
|
754
863
|
const { user, subgraphUrl } = params;
|
|
755
|
-
const endpoint = subgraphUrl
|
|
864
|
+
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
756
865
|
if (endpoint) {
|
|
757
866
|
try {
|
|
758
867
|
const permissions = await this._getUserPermissionsViaSubgraph({
|
|
@@ -801,7 +910,7 @@ class DataController {
|
|
|
801
910
|
);
|
|
802
911
|
}
|
|
803
912
|
const userData = result.data?.user;
|
|
804
|
-
if (!userData
|
|
913
|
+
if (!userData?.permissions?.length) {
|
|
805
914
|
return [];
|
|
806
915
|
}
|
|
807
916
|
return userData.permissions.map((permission) => ({
|
|
@@ -829,7 +938,7 @@ class DataController {
|
|
|
829
938
|
async _getUserPermissionsViaRpc(params) {
|
|
830
939
|
const { user } = params;
|
|
831
940
|
try {
|
|
832
|
-
const chainId = this.context.
|
|
941
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
833
942
|
if (!chainId) {
|
|
834
943
|
throw new Error("Chain ID not available");
|
|
835
944
|
}
|
|
@@ -948,7 +1057,7 @@ class DataController {
|
|
|
948
1057
|
*/
|
|
949
1058
|
async getUserTrustedServers(params) {
|
|
950
1059
|
const { user, limit = 50, offset = 0 } = params;
|
|
951
|
-
const subgraphUrl = params.subgraphUrl
|
|
1060
|
+
const subgraphUrl = params.subgraphUrl ?? this.context.subgraphUrl;
|
|
952
1061
|
if (subgraphUrl) {
|
|
953
1062
|
try {
|
|
954
1063
|
const servers = await this._getUserTrustedServersViaSubgraph({
|
|
@@ -1011,7 +1120,7 @@ class DataController {
|
|
|
1011
1120
|
if (!result.data?.user) {
|
|
1012
1121
|
return [];
|
|
1013
1122
|
}
|
|
1014
|
-
return (result.data.user.serverTrusts
|
|
1123
|
+
return (result.data.user.serverTrusts ?? []).filter((trust) => !trust.untrustedAtBlock).map((trust) => ({
|
|
1015
1124
|
id: trust.server.id,
|
|
1016
1125
|
serverAddress: trust.server.serverAddress,
|
|
1017
1126
|
serverUrl: trust.server.url,
|
|
@@ -1037,7 +1146,7 @@ class DataController {
|
|
|
1037
1146
|
async _getUserTrustedServersViaRpc(params) {
|
|
1038
1147
|
const { user, limit, offset } = params;
|
|
1039
1148
|
try {
|
|
1040
|
-
const chainId = this.context.
|
|
1149
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1041
1150
|
if (!chainId) {
|
|
1042
1151
|
throw new Error("Chain ID not available");
|
|
1043
1152
|
}
|
|
@@ -1137,7 +1246,7 @@ class DataController {
|
|
|
1137
1246
|
*/
|
|
1138
1247
|
async getTotalFilesCount() {
|
|
1139
1248
|
try {
|
|
1140
|
-
const chainId = this.context.
|
|
1249
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1141
1250
|
if (!chainId) {
|
|
1142
1251
|
throw new Error("Chain ID not available");
|
|
1143
1252
|
}
|
|
@@ -1146,7 +1255,7 @@ class DataController {
|
|
|
1146
1255
|
const dataRegistry = (0, import_viem.getContract)({
|
|
1147
1256
|
address: dataRegistryAddress,
|
|
1148
1257
|
abi: dataRegistryAbi,
|
|
1149
|
-
client: this.context.
|
|
1258
|
+
client: this.context.publicClient
|
|
1150
1259
|
});
|
|
1151
1260
|
const count = await dataRegistry.read.filesCount();
|
|
1152
1261
|
return Number(count);
|
|
@@ -1188,7 +1297,7 @@ class DataController {
|
|
|
1188
1297
|
*/
|
|
1189
1298
|
async getFileById(fileId) {
|
|
1190
1299
|
try {
|
|
1191
|
-
const chainId = this.context.
|
|
1300
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1192
1301
|
if (!chainId) {
|
|
1193
1302
|
throw new Error("Chain ID not available");
|
|
1194
1303
|
}
|
|
@@ -1197,7 +1306,7 @@ class DataController {
|
|
|
1197
1306
|
const dataRegistry = (0, import_viem.getContract)({
|
|
1198
1307
|
address: dataRegistryAddress,
|
|
1199
1308
|
abi: dataRegistryAbi,
|
|
1200
|
-
client: this.context.
|
|
1309
|
+
client: this.context.publicClient
|
|
1201
1310
|
});
|
|
1202
1311
|
const fileDetails = await dataRegistry.read.files([BigInt(fileId)]);
|
|
1203
1312
|
if (!fileDetails) {
|
|
@@ -1256,34 +1365,32 @@ class DataController {
|
|
|
1256
1365
|
* ```
|
|
1257
1366
|
*/
|
|
1258
1367
|
async registerFileWithSchema(url, schemaId) {
|
|
1368
|
+
this.assertWallet();
|
|
1259
1369
|
try {
|
|
1260
|
-
const chainId = this.context.
|
|
1370
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1261
1371
|
if (!chainId) {
|
|
1262
1372
|
throw new Error("Chain ID not available");
|
|
1263
1373
|
}
|
|
1374
|
+
this.assertWallet();
|
|
1264
1375
|
const dataRegistryAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
1265
1376
|
const dataRegistryAbi = (0, import_abi.getAbi)("DataRegistry");
|
|
1266
|
-
const
|
|
1267
|
-
const
|
|
1377
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1378
|
+
const from = typeof account === "string" ? account : account.address;
|
|
1379
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1268
1380
|
address: dataRegistryAddress,
|
|
1269
1381
|
abi: dataRegistryAbi,
|
|
1270
1382
|
functionName: "addFileWithSchema",
|
|
1271
1383
|
args: [url, BigInt(schemaId)],
|
|
1272
|
-
account
|
|
1273
|
-
chain: this.context.walletClient.chain
|
|
1384
|
+
account,
|
|
1385
|
+
chain: this.context.walletClient.chain ?? null
|
|
1386
|
+
});
|
|
1387
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
1388
|
+
return tx({
|
|
1389
|
+
hash,
|
|
1390
|
+
from,
|
|
1391
|
+
contract: "DataRegistry",
|
|
1392
|
+
fn: "addFileWithSchema"
|
|
1274
1393
|
});
|
|
1275
|
-
const receipt = await this.context.publicClient.waitForTransactionReceipt(
|
|
1276
|
-
{
|
|
1277
|
-
hash: txHash,
|
|
1278
|
-
confirmations: 1
|
|
1279
|
-
}
|
|
1280
|
-
);
|
|
1281
|
-
const { parseFileAddedEvent } = await import("../utils/eventParsing");
|
|
1282
|
-
const eventData = parseFileAddedEvent(receipt);
|
|
1283
|
-
return {
|
|
1284
|
-
fileId: Number(eventData.fileId),
|
|
1285
|
-
transactionHash: txHash
|
|
1286
|
-
};
|
|
1287
1394
|
} catch (error) {
|
|
1288
1395
|
console.error("Failed to register file with schema:", error);
|
|
1289
1396
|
throw new Error(
|
|
@@ -1297,13 +1404,6 @@ class DataController {
|
|
|
1297
1404
|
* @returns Promise resolving to the user's wallet address
|
|
1298
1405
|
* @throws {Error} When no addresses are available in wallet client
|
|
1299
1406
|
*/
|
|
1300
|
-
async getUserAddress() {
|
|
1301
|
-
const addresses = await this.context.walletClient.getAddresses();
|
|
1302
|
-
if (addresses.length === 0) {
|
|
1303
|
-
throw new Error("No addresses available in wallet client");
|
|
1304
|
-
}
|
|
1305
|
-
return addresses[0];
|
|
1306
|
-
}
|
|
1307
1407
|
/**
|
|
1308
1408
|
* Adds a file with permissions to the DataRegistry contract.
|
|
1309
1409
|
*
|
|
@@ -1321,33 +1421,32 @@ class DataController {
|
|
|
1321
1421
|
* by both direct transactions and relayer services.
|
|
1322
1422
|
*/
|
|
1323
1423
|
async addFileWithPermissions(url, ownerAddress, permissions = []) {
|
|
1424
|
+
this.assertWallet();
|
|
1324
1425
|
try {
|
|
1325
|
-
const chainId = this.context.
|
|
1426
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1326
1427
|
if (!chainId) {
|
|
1327
1428
|
throw new Error("Chain ID not available");
|
|
1328
1429
|
}
|
|
1430
|
+
this.assertWallet();
|
|
1329
1431
|
const dataRegistryAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
1330
1432
|
const dataRegistryAbi = (0, import_abi.getAbi)("DataRegistry");
|
|
1331
|
-
const
|
|
1433
|
+
const account = this.context.walletClient.account ?? ownerAddress;
|
|
1434
|
+
const from = typeof account === "string" ? account : account.address;
|
|
1435
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1332
1436
|
address: dataRegistryAddress,
|
|
1333
1437
|
abi: dataRegistryAbi,
|
|
1334
1438
|
functionName: "addFileWithPermissions",
|
|
1335
1439
|
args: [url, ownerAddress, permissions],
|
|
1336
|
-
account
|
|
1337
|
-
chain: this.context.walletClient.chain
|
|
1440
|
+
account,
|
|
1441
|
+
chain: this.context.walletClient.chain ?? null
|
|
1442
|
+
});
|
|
1443
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
1444
|
+
return tx({
|
|
1445
|
+
hash,
|
|
1446
|
+
from,
|
|
1447
|
+
contract: "DataRegistry",
|
|
1448
|
+
fn: "addFileWithPermissions"
|
|
1338
1449
|
});
|
|
1339
|
-
const receipt = await this.context.publicClient.waitForTransactionReceipt(
|
|
1340
|
-
{
|
|
1341
|
-
hash: txHash,
|
|
1342
|
-
confirmations: 1
|
|
1343
|
-
}
|
|
1344
|
-
);
|
|
1345
|
-
const { parseFileAddedEvent } = await import("../utils/eventParsing");
|
|
1346
|
-
const eventData = parseFileAddedEvent(receipt);
|
|
1347
|
-
return {
|
|
1348
|
-
fileId: Number(eventData.fileId),
|
|
1349
|
-
transactionHash: txHash
|
|
1350
|
-
};
|
|
1351
1450
|
} catch (error) {
|
|
1352
1451
|
console.error("Failed to add file with permissions:", error);
|
|
1353
1452
|
throw new Error(
|
|
@@ -1359,44 +1458,148 @@ class DataController {
|
|
|
1359
1458
|
* Adds a file to the registry with permissions and schema.
|
|
1360
1459
|
* This combines the functionality of addFileWithPermissions and schema validation.
|
|
1361
1460
|
*
|
|
1461
|
+
* @remarks
|
|
1462
|
+
* This method automatically encrypts permissions when a publicKey is provided.
|
|
1463
|
+
* It generates the user's encryption key and encrypts it with each recipient's
|
|
1464
|
+
* public key before registering on the blockchain.
|
|
1465
|
+
*
|
|
1362
1466
|
* @param url - The URL of the file to register
|
|
1363
1467
|
* @param ownerAddress - The address of the file owner
|
|
1364
|
-
* @param permissions - Array of permissions to grant
|
|
1468
|
+
* @param permissions - Array of permissions to grant, each with account and publicKey properties
|
|
1365
1469
|
* @param schemaId - The schema ID to associate with the file (0 for no schema)
|
|
1366
|
-
* @returns Promise resolving to
|
|
1367
|
-
* @throws {Error} When chain
|
|
1368
|
-
* @throws {
|
|
1369
|
-
* @throws {Error} When
|
|
1370
|
-
* @throws {Error}
|
|
1470
|
+
* @returns Promise resolving to TransactionResult with fileId and transactionHash
|
|
1471
|
+
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1472
|
+
* @throws {Error} "Failed to generate encryption key" - When encryption key generation fails
|
|
1473
|
+
* @throws {Error} "Permission for {account} must include 'publicKey'" - When publicKey is missing
|
|
1474
|
+
* @throws {Error} "Failed to add file with permissions and schema: {error}" - When transaction fails
|
|
1475
|
+
* @example
|
|
1476
|
+
* ```typescript
|
|
1477
|
+
* // Get server's public key
|
|
1478
|
+
* const serverIdentity = await vana.server.getIdentity({
|
|
1479
|
+
* userAddress: "0x..."
|
|
1480
|
+
* });
|
|
1481
|
+
*
|
|
1482
|
+
* // Add file with permissions and schema
|
|
1483
|
+
* const result = await vana.data.addFileWithPermissionsAndSchema(
|
|
1484
|
+
* "ipfs://QmXxx...",
|
|
1485
|
+
* ownerAddress,
|
|
1486
|
+
* [{
|
|
1487
|
+
* account: serverIdentity.address,
|
|
1488
|
+
* publicKey: serverIdentity.publicKey
|
|
1489
|
+
* }],
|
|
1490
|
+
* schemaId
|
|
1491
|
+
* );
|
|
1492
|
+
*
|
|
1493
|
+
* console.log(`File ${result.fileId} registered in tx ${result.hash}`);
|
|
1494
|
+
* ```
|
|
1371
1495
|
*/
|
|
1372
1496
|
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1497
|
+
this.assertWallet();
|
|
1373
1498
|
try {
|
|
1374
|
-
|
|
1499
|
+
let encryptedPermissions = [];
|
|
1500
|
+
if (permissions.length > 0) {
|
|
1501
|
+
this.assertWallet();
|
|
1502
|
+
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
1503
|
+
this.context.walletClient,
|
|
1504
|
+
this.context.platform,
|
|
1505
|
+
import_encryption.DEFAULT_ENCRYPTION_SEED
|
|
1506
|
+
);
|
|
1507
|
+
encryptedPermissions = await Promise.all(
|
|
1508
|
+
permissions.map(async (permission) => {
|
|
1509
|
+
if (!permission.publicKey) {
|
|
1510
|
+
throw new Error(
|
|
1511
|
+
`Permission for ${permission.account} must include 'publicKey'`
|
|
1512
|
+
);
|
|
1513
|
+
}
|
|
1514
|
+
const encryptedKey = await (0, import_encryption.encryptWithWalletPublicKey)(
|
|
1515
|
+
userEncryptionKey,
|
|
1516
|
+
permission.publicKey,
|
|
1517
|
+
this.context.platform
|
|
1518
|
+
);
|
|
1519
|
+
return {
|
|
1520
|
+
account: permission.account,
|
|
1521
|
+
key: encryptedKey
|
|
1522
|
+
};
|
|
1523
|
+
})
|
|
1524
|
+
);
|
|
1525
|
+
}
|
|
1526
|
+
return await this.addFileWithEncryptedPermissionsAndSchema(
|
|
1527
|
+
url,
|
|
1528
|
+
ownerAddress,
|
|
1529
|
+
encryptedPermissions,
|
|
1530
|
+
schemaId
|
|
1531
|
+
);
|
|
1532
|
+
} catch (error) {
|
|
1533
|
+
console.error("Failed to add file with permissions and schema:", error);
|
|
1534
|
+
throw new Error(
|
|
1535
|
+
`Failed to add file with permissions and schema: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
1536
|
+
);
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
/**
|
|
1540
|
+
* Adds a file with pre-encrypted permissions and schema to the DataRegistry.
|
|
1541
|
+
*
|
|
1542
|
+
* @remarks
|
|
1543
|
+
* This method is designed for relay services and advanced use cases where permissions
|
|
1544
|
+
* have already been encrypted client-side. Unlike `addFileWithPermissionsAndSchema()`,
|
|
1545
|
+
* this method expects permissions in the encrypted format with a 'key' field instead
|
|
1546
|
+
* of 'publicKey'.
|
|
1547
|
+
*
|
|
1548
|
+
* This is typically used by relay endpoints that receive pre-encrypted data from
|
|
1549
|
+
* the client SDK's `upload()` method, avoiding double encryption.
|
|
1550
|
+
*
|
|
1551
|
+
* @param url - The storage URL of the file (e.g., IPFS URL)
|
|
1552
|
+
* @param ownerAddress - The address that will own this file
|
|
1553
|
+
* @param permissions - Array of pre-encrypted permissions with 'account' and 'key' fields
|
|
1554
|
+
* @param schemaId - Optional schema ID for data validation (defaults to 0)
|
|
1555
|
+
* @returns Promise resolving to transaction result with hash and contract details
|
|
1556
|
+
* @throws {Error} When chain ID is not available
|
|
1557
|
+
* @throws {Error} When wallet is not connected
|
|
1558
|
+
* @throws {Error} When transaction fails
|
|
1559
|
+
* @example
|
|
1560
|
+
* ```typescript
|
|
1561
|
+
* // In a relay endpoint that receives pre-encrypted permissions
|
|
1562
|
+
* const result = await vana.data.addFileWithEncryptedPermissionsAndSchema(
|
|
1563
|
+
* "ipfs://QmXxx...",
|
|
1564
|
+
* ownerAddress,
|
|
1565
|
+
* [
|
|
1566
|
+
* {
|
|
1567
|
+
* account: "0xServerAddress...",
|
|
1568
|
+
* key: "encrypted_key_string" // Already encrypted by client
|
|
1569
|
+
* }
|
|
1570
|
+
* ],
|
|
1571
|
+
* schemaId
|
|
1572
|
+
* );
|
|
1573
|
+
*
|
|
1574
|
+
* console.log(`File registered in tx ${result.hash}`);
|
|
1575
|
+
* ```
|
|
1576
|
+
*/
|
|
1577
|
+
async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1578
|
+
try {
|
|
1579
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1375
1580
|
if (!chainId) {
|
|
1376
1581
|
throw new Error("Chain ID not available");
|
|
1377
1582
|
}
|
|
1583
|
+
this.assertWallet();
|
|
1378
1584
|
const dataRegistryAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
1379
1585
|
const dataRegistryAbi = (0, import_abi.getAbi)("DataRegistry");
|
|
1380
|
-
const
|
|
1586
|
+
const account = this.context.walletClient.account ?? ownerAddress;
|
|
1587
|
+
const from = typeof account === "string" ? account : account.address;
|
|
1588
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1381
1589
|
address: dataRegistryAddress,
|
|
1382
1590
|
abi: dataRegistryAbi,
|
|
1383
1591
|
functionName: "addFileWithPermissionsAndSchema",
|
|
1384
1592
|
args: [url, ownerAddress, permissions, BigInt(schemaId)],
|
|
1385
|
-
account
|
|
1386
|
-
chain: this.context.walletClient.chain
|
|
1593
|
+
account,
|
|
1594
|
+
chain: this.context.walletClient.chain ?? null
|
|
1595
|
+
});
|
|
1596
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
1597
|
+
return tx({
|
|
1598
|
+
hash,
|
|
1599
|
+
from,
|
|
1600
|
+
contract: "DataRegistry",
|
|
1601
|
+
fn: "addFileWithPermissionsAndSchema"
|
|
1387
1602
|
});
|
|
1388
|
-
const receipt = await this.context.publicClient.waitForTransactionReceipt(
|
|
1389
|
-
{
|
|
1390
|
-
hash: txHash,
|
|
1391
|
-
confirmations: 1
|
|
1392
|
-
}
|
|
1393
|
-
);
|
|
1394
|
-
const { parseFileAddedEvent } = await import("../utils/eventParsing");
|
|
1395
|
-
const eventData = parseFileAddedEvent(receipt);
|
|
1396
|
-
return {
|
|
1397
|
-
fileId: Number(eventData.fileId),
|
|
1398
|
-
transactionHash: txHash
|
|
1399
|
-
};
|
|
1400
1603
|
} catch (error) {
|
|
1401
1604
|
console.error("Failed to add file with permissions and schema:", error);
|
|
1402
1605
|
throw new Error(
|
|
@@ -1433,8 +1636,9 @@ class DataController {
|
|
|
1433
1636
|
* ```
|
|
1434
1637
|
*/
|
|
1435
1638
|
async addRefiner(params) {
|
|
1639
|
+
this.assertWallet();
|
|
1436
1640
|
try {
|
|
1437
|
-
const chainId = this.context.
|
|
1641
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1438
1642
|
if (!chainId) {
|
|
1439
1643
|
throw new Error("Chain ID not available");
|
|
1440
1644
|
}
|
|
@@ -1443,7 +1647,10 @@ class DataController {
|
|
|
1443
1647
|
"DataRefinerRegistry"
|
|
1444
1648
|
);
|
|
1445
1649
|
const dataRefinerRegistryAbi = (0, import_abi.getAbi)("DataRefinerRegistry");
|
|
1446
|
-
|
|
1650
|
+
this.assertWallet();
|
|
1651
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1652
|
+
const from = typeof account === "string" ? account : account.address;
|
|
1653
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1447
1654
|
address: dataRefinerRegistryAddress,
|
|
1448
1655
|
abi: dataRefinerRegistryAbi,
|
|
1449
1656
|
functionName: "addRefinerWithSchemaId",
|
|
@@ -1453,20 +1660,27 @@ class DataController {
|
|
|
1453
1660
|
BigInt(params.schemaId),
|
|
1454
1661
|
params.refinementInstructionUrl
|
|
1455
1662
|
],
|
|
1456
|
-
account
|
|
1457
|
-
chain: this.context.walletClient.chain
|
|
1663
|
+
account,
|
|
1664
|
+
chain: this.context.walletClient.chain ?? null
|
|
1458
1665
|
});
|
|
1459
|
-
const
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1666
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
1667
|
+
const txResult = tx({
|
|
1668
|
+
hash,
|
|
1669
|
+
from,
|
|
1670
|
+
contract: "DataRefinerRegistry",
|
|
1671
|
+
fn: "addRefinerWithSchemaId"
|
|
1672
|
+
});
|
|
1673
|
+
if (!this.context.waitForTransactionEvents) {
|
|
1674
|
+
throw new Error("waitForTransactionEvents not configured");
|
|
1675
|
+
}
|
|
1676
|
+
const result = await this.context.waitForTransactionEvents(txResult);
|
|
1677
|
+
const event = result.expectedEvents.RefinerAdded;
|
|
1678
|
+
if (!event) {
|
|
1679
|
+
throw new Error("RefinerAdded event not found in transaction");
|
|
1680
|
+
}
|
|
1467
1681
|
return {
|
|
1468
|
-
refinerId: Number(
|
|
1469
|
-
transactionHash:
|
|
1682
|
+
refinerId: Number(event.refinerId),
|
|
1683
|
+
transactionHash: hash
|
|
1470
1684
|
};
|
|
1471
1685
|
} catch (error) {
|
|
1472
1686
|
console.error("Failed to add refiner:", error);
|
|
@@ -1500,7 +1714,7 @@ class DataController {
|
|
|
1500
1714
|
*/
|
|
1501
1715
|
async getRefiner(refinerId) {
|
|
1502
1716
|
try {
|
|
1503
|
-
const chainId = this.context.
|
|
1717
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1504
1718
|
if (!chainId) {
|
|
1505
1719
|
throw new Error("Chain ID not available");
|
|
1506
1720
|
}
|
|
@@ -1512,7 +1726,7 @@ class DataController {
|
|
|
1512
1726
|
const dataRefinerRegistry = (0, import_viem.getContract)({
|
|
1513
1727
|
address: dataRefinerRegistryAddress,
|
|
1514
1728
|
abi: dataRefinerRegistryAbi,
|
|
1515
|
-
client: this.context.
|
|
1729
|
+
client: this.context.publicClient
|
|
1516
1730
|
});
|
|
1517
1731
|
const refinerData = await dataRefinerRegistry.read.refiners([
|
|
1518
1732
|
BigInt(refinerId)
|
|
@@ -1556,7 +1770,7 @@ class DataController {
|
|
|
1556
1770
|
*/
|
|
1557
1771
|
async isValidSchemaId(schemaId) {
|
|
1558
1772
|
try {
|
|
1559
|
-
const chainId = this.context.
|
|
1773
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1560
1774
|
if (!chainId) {
|
|
1561
1775
|
throw new Error("Chain ID not available");
|
|
1562
1776
|
}
|
|
@@ -1568,7 +1782,7 @@ class DataController {
|
|
|
1568
1782
|
const dataRefinerRegistry = (0, import_viem.getContract)({
|
|
1569
1783
|
address: dataRefinerRegistryAddress,
|
|
1570
1784
|
abi: dataRefinerRegistryAbi,
|
|
1571
|
-
client: this.context.
|
|
1785
|
+
client: this.context.publicClient
|
|
1572
1786
|
});
|
|
1573
1787
|
const isValid = await dataRefinerRegistry.read.isValidSchemaId([
|
|
1574
1788
|
BigInt(schemaId)
|
|
@@ -1595,7 +1809,7 @@ class DataController {
|
|
|
1595
1809
|
*/
|
|
1596
1810
|
async getRefinersCount() {
|
|
1597
1811
|
try {
|
|
1598
|
-
const chainId = this.context.
|
|
1812
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1599
1813
|
if (!chainId) {
|
|
1600
1814
|
throw new Error("Chain ID not available");
|
|
1601
1815
|
}
|
|
@@ -1607,7 +1821,7 @@ class DataController {
|
|
|
1607
1821
|
const dataRefinerRegistry = (0, import_viem.getContract)({
|
|
1608
1822
|
address: dataRefinerRegistryAddress,
|
|
1609
1823
|
abi: dataRefinerRegistryAbi,
|
|
1610
|
-
client: this.context.
|
|
1824
|
+
client: this.context.publicClient
|
|
1611
1825
|
});
|
|
1612
1826
|
const count = await dataRefinerRegistry.read.refinersCount();
|
|
1613
1827
|
return Number(count);
|
|
@@ -1639,8 +1853,9 @@ class DataController {
|
|
|
1639
1853
|
* ```
|
|
1640
1854
|
*/
|
|
1641
1855
|
async updateSchemaId(params) {
|
|
1856
|
+
this.assertWallet();
|
|
1642
1857
|
try {
|
|
1643
|
-
const chainId = this.context.
|
|
1858
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1644
1859
|
if (!chainId) {
|
|
1645
1860
|
throw new Error("Chain ID not available");
|
|
1646
1861
|
}
|
|
@@ -1649,20 +1864,19 @@ class DataController {
|
|
|
1649
1864
|
"DataRefinerRegistry"
|
|
1650
1865
|
);
|
|
1651
1866
|
const dataRefinerRegistryAbi = (0, import_abi.getAbi)("DataRefinerRegistry");
|
|
1652
|
-
|
|
1867
|
+
this.assertWallet();
|
|
1868
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1869
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1653
1870
|
address: dataRefinerRegistryAddress,
|
|
1654
1871
|
abi: dataRefinerRegistryAbi,
|
|
1655
1872
|
functionName: "updateSchemaId",
|
|
1656
1873
|
args: [BigInt(params.refinerId), BigInt(params.newSchemaId)],
|
|
1657
|
-
account
|
|
1658
|
-
chain: this.context.walletClient.chain
|
|
1659
|
-
});
|
|
1660
|
-
await this.context.publicClient.waitForTransactionReceipt({
|
|
1661
|
-
hash: txHash,
|
|
1662
|
-
timeout: 3e4
|
|
1874
|
+
account,
|
|
1875
|
+
chain: this.context.walletClient.chain ?? null
|
|
1663
1876
|
});
|
|
1877
|
+
await this.context.publicClient.waitForTransactionReceipt({ hash });
|
|
1664
1878
|
return {
|
|
1665
|
-
transactionHash:
|
|
1879
|
+
transactionHash: hash
|
|
1666
1880
|
};
|
|
1667
1881
|
} catch (error) {
|
|
1668
1882
|
console.error("Failed to update schema ID:", error);
|
|
@@ -1680,13 +1894,12 @@ class DataController {
|
|
|
1680
1894
|
* 3. Encrypts the user's encryption key with the provided public key
|
|
1681
1895
|
* 4. Registers the file with permissions
|
|
1682
1896
|
*
|
|
1683
|
-
* @param
|
|
1684
|
-
* @param permissions - Array of permissions to grant, each with account address and public key
|
|
1685
|
-
* @param filename - Optional filename for the upload
|
|
1686
|
-
* @param providerName - Optional storage provider to use
|
|
1897
|
+
* @param params - Upload parameters including data, permissions, and options
|
|
1687
1898
|
* @returns Promise resolving to upload result with file ID and storage URL
|
|
1688
1899
|
*/
|
|
1689
|
-
async uploadFileWithPermissions(
|
|
1900
|
+
async uploadFileWithPermissions(params) {
|
|
1901
|
+
this.assertWallet();
|
|
1902
|
+
const { data, permissions, filename, providerName } = params;
|
|
1690
1903
|
try {
|
|
1691
1904
|
const uploadResult = await this.uploadToStorage(
|
|
1692
1905
|
data,
|
|
@@ -1695,7 +1908,7 @@ class DataController {
|
|
|
1695
1908
|
// Always encrypt for uploadFileWithPermissions
|
|
1696
1909
|
providerName
|
|
1697
1910
|
);
|
|
1698
|
-
const userAddress =
|
|
1911
|
+
const userAddress = this.context.userAddress;
|
|
1699
1912
|
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
1700
1913
|
this.context.walletClient,
|
|
1701
1914
|
this.context.platform,
|
|
@@ -1714,26 +1927,53 @@ class DataController {
|
|
|
1714
1927
|
};
|
|
1715
1928
|
})
|
|
1716
1929
|
);
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1930
|
+
if (this.context.relayer) {
|
|
1931
|
+
const request = {
|
|
1932
|
+
type: "direct",
|
|
1933
|
+
operation: "submitFileAdditionWithPermissions",
|
|
1934
|
+
params: {
|
|
1935
|
+
url: uploadResult.url,
|
|
1936
|
+
userAddress,
|
|
1937
|
+
permissions: encryptedPermissions
|
|
1938
|
+
}
|
|
1939
|
+
};
|
|
1940
|
+
const response = await this.context.relayer(request);
|
|
1941
|
+
if (response.type === "error") {
|
|
1942
|
+
throw new Error(response.error);
|
|
1943
|
+
}
|
|
1944
|
+
if (response.type !== "direct" || !("fileId" in response.result)) {
|
|
1945
|
+
throw new Error("Invalid response from relayer");
|
|
1946
|
+
}
|
|
1947
|
+
const result = response.result;
|
|
1948
|
+
return {
|
|
1949
|
+
fileId: result.fileId,
|
|
1950
|
+
url: uploadResult.url,
|
|
1951
|
+
size: uploadResult.size,
|
|
1952
|
+
transactionHash: result.transactionHash
|
|
1953
|
+
};
|
|
1724
1954
|
} else {
|
|
1725
|
-
|
|
1955
|
+
const txResult = await this.addFileWithPermissions(
|
|
1726
1956
|
uploadResult.url,
|
|
1727
1957
|
userAddress,
|
|
1728
1958
|
encryptedPermissions
|
|
1729
1959
|
);
|
|
1960
|
+
if (!this.context.waitForTransactionEvents) {
|
|
1961
|
+
throw new Error(
|
|
1962
|
+
"Cannot upload without relay: waitForTransactionEvents not configured"
|
|
1963
|
+
);
|
|
1964
|
+
}
|
|
1965
|
+
const eventResult = await this.context.waitForTransactionEvents(txResult);
|
|
1966
|
+
const fileAddedEvent = eventResult.expectedEvents.FileAdded;
|
|
1967
|
+
if (!fileAddedEvent) {
|
|
1968
|
+
throw new Error("FileAdded event not found in transaction");
|
|
1969
|
+
}
|
|
1970
|
+
return {
|
|
1971
|
+
fileId: Number(fileAddedEvent.fileId),
|
|
1972
|
+
url: uploadResult.url,
|
|
1973
|
+
size: uploadResult.size,
|
|
1974
|
+
transactionHash: txResult.hash
|
|
1975
|
+
};
|
|
1730
1976
|
}
|
|
1731
|
-
return {
|
|
1732
|
-
fileId: result.fileId,
|
|
1733
|
-
url: uploadResult.url,
|
|
1734
|
-
size: uploadResult.size,
|
|
1735
|
-
transactionHash: result.transactionHash
|
|
1736
|
-
};
|
|
1737
1977
|
} catch (error) {
|
|
1738
1978
|
console.error("Failed to upload file with permissions:", error);
|
|
1739
1979
|
throw new Error(
|
|
@@ -1771,6 +2011,7 @@ class DataController {
|
|
|
1771
2011
|
}
|
|
1772
2012
|
let finalBlob = blob;
|
|
1773
2013
|
if (encrypt) {
|
|
2014
|
+
this.assertWallet();
|
|
1774
2015
|
const encryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
1775
2016
|
this.context.walletClient,
|
|
1776
2017
|
this.context.platform,
|
|
@@ -1792,7 +2033,7 @@ class DataController {
|
|
|
1792
2033
|
);
|
|
1793
2034
|
}
|
|
1794
2035
|
}
|
|
1795
|
-
const finalFilename = filename
|
|
2036
|
+
const finalFilename = filename ?? `upload-${Date.now()}.dat`;
|
|
1796
2037
|
const uploadResult = await this.context.storageManager.upload(
|
|
1797
2038
|
finalBlob,
|
|
1798
2039
|
finalFilename,
|
|
@@ -1817,21 +2058,29 @@ class DataController {
|
|
|
1817
2058
|
* For advanced users who need more control over transaction timing,
|
|
1818
2059
|
* use `submitFilePermission()` instead.
|
|
1819
2060
|
*
|
|
1820
|
-
* @param
|
|
1821
|
-
* @param
|
|
1822
|
-
* @param
|
|
2061
|
+
* @param params - Parameters for adding file permission
|
|
2062
|
+
* @param params.fileId - The ID of the file to grant permission for
|
|
2063
|
+
* @param params.account - The recipient's wallet address that will access the file
|
|
2064
|
+
* @param params.publicKey - The recipient's public key for encryption.
|
|
2065
|
+
* Obtain via `vana.server.getIdentity(account).publicKey`
|
|
1823
2066
|
* @returns Promise resolving to permission data from PermissionGranted event
|
|
1824
2067
|
* @throws {Error} "No addresses available in wallet client" - When wallet is not connected
|
|
1825
2068
|
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1826
2069
|
* @throws {Error} "Failed to add permission to file: {error}" - When transaction fails or user doesn't own file
|
|
1827
2070
|
* @example
|
|
1828
2071
|
* ```typescript
|
|
1829
|
-
* const result = await vana.data.addPermissionToFile(
|
|
2072
|
+
* const result = await vana.data.addPermissionToFile({
|
|
2073
|
+
* fileId: 123,
|
|
2074
|
+
* account: "0xRecipientAddress...",
|
|
2075
|
+
* publicKey: "0xRecipientPublicKey..."
|
|
2076
|
+
* });
|
|
1830
2077
|
* console.log(`Permission granted to ${result.account} for file ${result.fileId}`);
|
|
1831
2078
|
* console.log(`Transaction: ${result.transactionHash}`);
|
|
1832
2079
|
* ```
|
|
1833
2080
|
*/
|
|
1834
|
-
async addPermissionToFile(
|
|
2081
|
+
async addPermissionToFile(params) {
|
|
2082
|
+
this.assertWallet();
|
|
2083
|
+
const { fileId, account, publicKey } = params;
|
|
1835
2084
|
return await this.submitFilePermission(fileId, account, publicKey);
|
|
1836
2085
|
}
|
|
1837
2086
|
/**
|
|
@@ -1845,7 +2094,7 @@ class DataController {
|
|
|
1845
2094
|
* @param fileId - The ID of the file to grant permission for
|
|
1846
2095
|
* @param account - The recipient's wallet address that will access the file
|
|
1847
2096
|
* @param publicKey - The recipient's public key for encryption.
|
|
1848
|
-
* Obtain via `vana.server.getIdentity(account).
|
|
2097
|
+
* Obtain via `vana.server.getIdentity(account).publicKey`
|
|
1849
2098
|
* @returns Promise resolving to TransactionResult for tracking the transaction
|
|
1850
2099
|
* @throws {Error} When chain ID is not available
|
|
1851
2100
|
* @throws {Error} When encryption key generation fails
|
|
@@ -1863,6 +2112,7 @@ class DataController {
|
|
|
1863
2112
|
* ```
|
|
1864
2113
|
*/
|
|
1865
2114
|
async submitFilePermission(fileId, account, publicKey) {
|
|
2115
|
+
this.assertWallet();
|
|
1866
2116
|
try {
|
|
1867
2117
|
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
1868
2118
|
this.context.walletClient,
|
|
@@ -1874,24 +2124,29 @@ class DataController {
|
|
|
1874
2124
|
publicKey,
|
|
1875
2125
|
this.context.platform
|
|
1876
2126
|
);
|
|
1877
|
-
const chainId = this.context.
|
|
2127
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1878
2128
|
if (!chainId) {
|
|
1879
2129
|
throw new Error("Chain ID not available");
|
|
1880
2130
|
}
|
|
1881
2131
|
const dataRegistryAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
1882
2132
|
const dataRegistryAbi = (0, import_abi.getAbi)("DataRegistry");
|
|
2133
|
+
this.assertWallet();
|
|
2134
|
+
const walletAccount = this.context.walletClient.account ?? this.context.userAddress;
|
|
1883
2135
|
const txHash = await this.context.walletClient.writeContract({
|
|
1884
2136
|
address: dataRegistryAddress,
|
|
1885
2137
|
abi: dataRegistryAbi,
|
|
1886
2138
|
functionName: "addFilePermission",
|
|
1887
2139
|
args: [BigInt(fileId), account, encryptedKey],
|
|
1888
|
-
account:
|
|
1889
|
-
chain: this.context.walletClient.chain
|
|
2140
|
+
account: walletAccount,
|
|
2141
|
+
chain: this.context.walletClient.chain ?? null
|
|
1890
2142
|
});
|
|
1891
|
-
|
|
2143
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
2144
|
+
return tx({
|
|
1892
2145
|
hash: txHash,
|
|
1893
|
-
from:
|
|
1894
|
-
|
|
2146
|
+
from: typeof walletAccount === "string" ? walletAccount : walletAccount.address,
|
|
2147
|
+
contract: "DataRegistry",
|
|
2148
|
+
fn: "addFilePermission"
|
|
2149
|
+
});
|
|
1895
2150
|
} catch (error) {
|
|
1896
2151
|
console.error("Failed to add permission to file:", error);
|
|
1897
2152
|
throw new Error(
|
|
@@ -1908,7 +2163,7 @@ class DataController {
|
|
|
1908
2163
|
*/
|
|
1909
2164
|
async getFilePermission(fileId, account) {
|
|
1910
2165
|
try {
|
|
1911
|
-
const chainId = this.context.
|
|
2166
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1912
2167
|
if (!chainId) {
|
|
1913
2168
|
throw new Error("Chain ID not available");
|
|
1914
2169
|
}
|
|
@@ -1917,7 +2172,7 @@ class DataController {
|
|
|
1917
2172
|
const dataRegistry = (0, import_viem.getContract)({
|
|
1918
2173
|
address: dataRegistryAddress,
|
|
1919
2174
|
abi: dataRegistryAbi,
|
|
1920
|
-
client: this.context.
|
|
2175
|
+
client: this.context.publicClient
|
|
1921
2176
|
});
|
|
1922
2177
|
const encryptedKey = await dataRegistry.read.filePermissions([
|
|
1923
2178
|
BigInt(fileId),
|
|
@@ -1941,12 +2196,13 @@ class DataController {
|
|
|
1941
2196
|
*
|
|
1942
2197
|
* @param file - The file to decrypt
|
|
1943
2198
|
* @param privateKey - The private key to decrypt the user's encryption key
|
|
1944
|
-
* @param
|
|
2199
|
+
* @param options - Optional decryption configuration
|
|
2200
|
+
* @param options.account - The account address that has permission (defaults to current wallet account)
|
|
1945
2201
|
* @returns Promise resolving to the decrypted file data
|
|
1946
2202
|
*/
|
|
1947
|
-
async decryptFileWithPermission(file, privateKey,
|
|
2203
|
+
async decryptFileWithPermission(file, privateKey, options) {
|
|
1948
2204
|
try {
|
|
1949
|
-
const permissionAccount = account
|
|
2205
|
+
const permissionAccount = options?.account ?? this.context.userAddress;
|
|
1950
2206
|
const encryptedKey = await this.getFilePermission(
|
|
1951
2207
|
file.id,
|
|
1952
2208
|
permissionAccount
|
|
@@ -2010,11 +2266,8 @@ class DataController {
|
|
|
2010
2266
|
*/
|
|
2011
2267
|
async fetch(url) {
|
|
2012
2268
|
try {
|
|
2013
|
-
const {
|
|
2014
|
-
const response = await
|
|
2015
|
-
url,
|
|
2016
|
-
this.context.downloadRelayer
|
|
2017
|
-
);
|
|
2269
|
+
const { universalFetch } = await import("../utils/download");
|
|
2270
|
+
const response = await universalFetch(url, this.context.downloadRelayer);
|
|
2018
2271
|
if (!response.ok) {
|
|
2019
2272
|
throw new Error(
|
|
2020
2273
|
`HTTP error! status: ${response.status} ${response.statusText}`
|
|
@@ -2079,7 +2332,7 @@ class DataController {
|
|
|
2079
2332
|
"https://dweb.link/ipfs/",
|
|
2080
2333
|
"https://ipfs.io/ipfs/"
|
|
2081
2334
|
];
|
|
2082
|
-
const gateways = options?.gateways
|
|
2335
|
+
const gateways = options?.gateways ?? this.context.ipfsGateways ?? defaultGateways;
|
|
2083
2336
|
const { extractIpfsHash } = await import("../utils/ipfs");
|
|
2084
2337
|
const cid = extractIpfsHash(url);
|
|
2085
2338
|
if (!cid) {
|
|
@@ -2208,7 +2461,7 @@ class DataController {
|
|
|
2208
2461
|
* ```
|
|
2209
2462
|
*/
|
|
2210
2463
|
validateDataAgainstSchema(data, schema) {
|
|
2211
|
-
|
|
2464
|
+
(0, import_schemaValidation.validateDataAgainstSchema)(data, schema);
|
|
2212
2465
|
}
|
|
2213
2466
|
/**
|
|
2214
2467
|
* Fetches and validates a data schema from a URL, then returns the parsed data schema.
|