@opendatalabs/vana-sdk 0.1.0-alpha.7ee7635 → 0.1.0-alpha.80df35f
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 -45
- 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 -49
- 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 +338 -107
- package/dist/controllers/data.cjs.map +1 -1
- package/dist/controllers/data.d.ts +145 -46
- package/dist/controllers/data.js +338 -107
- package/dist/controllers/data.js.map +1 -1
- package/dist/controllers/permissions.cjs +162 -223
- package/dist/controllers/permissions.cjs.map +1 -1
- package/dist/controllers/permissions.d.ts +24 -78
- package/dist/controllers/permissions.js +162 -223
- 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 -56
- package/dist/controllers/protocol.js +15 -14
- package/dist/controllers/protocol.js.map +1 -1
- package/dist/controllers/schemas.cjs +29 -36
- package/dist/controllers/schemas.cjs.map +1 -1
- package/dist/controllers/schemas.d.ts +8 -23
- package/dist/controllers/schemas.js +29 -36
- 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 -20
- 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 +82 -34
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +21 -73
- package/dist/core.js +105 -60
- package/dist/core.js.map +1 -1
- package/dist/crypto/ecies/__tests__/base.test.d.ts +4 -0
- package/dist/crypto/ecies/__tests__/compatibility.test.d.ts +8 -0
- package/dist/crypto/ecies/__tests__/constants.test.d.ts +4 -0
- package/dist/crypto/ecies/__tests__/native-parity.test.d.ts +7 -0
- package/dist/crypto/ecies/__tests__/normalization.test.d.ts +1 -0
- package/dist/crypto/ecies/__tests__/test-vectors.d.ts +2 -4
- package/dist/crypto/ecies/base.cjs +4 -3
- package/dist/crypto/ecies/base.cjs.map +1 -1
- package/dist/crypto/ecies/base.d.ts +2 -5
- package/dist/crypto/ecies/base.js +12 -15
- package/dist/crypto/ecies/base.js.map +1 -1
- package/dist/crypto/ecies/browser.cjs +2 -1
- package/dist/crypto/ecies/browser.cjs.map +1 -1
- package/dist/crypto/ecies/browser.d.ts +2 -7
- package/dist/crypto/ecies/browser.js +2 -1
- package/dist/crypto/ecies/browser.js.map +1 -1
- package/dist/crypto/ecies/constants.d.ts +7 -9
- package/dist/crypto/ecies/index.d.ts +8 -1
- package/dist/crypto/ecies/interface.cjs +4 -5
- package/dist/crypto/ecies/interface.cjs.map +1 -1
- package/dist/crypto/ecies/interface.d.ts +9 -11
- package/dist/crypto/ecies/interface.js +4 -5
- package/dist/crypto/ecies/interface.js.map +1 -1
- package/dist/crypto/ecies/node.cjs +3 -2
- package/dist/crypto/ecies/node.cjs.map +1 -1
- package/dist/crypto/ecies/node.d.ts +2 -7
- package/dist/crypto/ecies/node.js +11 -16
- package/dist/crypto/ecies/node.js.map +1 -1
- package/dist/crypto/ecies/utils.cjs +2 -41
- package/dist/crypto/ecies/utils.cjs.map +1 -1
- package/dist/crypto/ecies/utils.d.ts +3 -40
- package/dist/crypto/ecies/utils.js +1 -35
- package/dist/crypto/ecies/utils.js.map +1 -1
- package/dist/crypto/services/WalletKeyEncryptionService.cjs +2 -2
- package/dist/crypto/services/WalletKeyEncryptionService.cjs.map +1 -1
- package/dist/crypto/services/WalletKeyEncryptionService.d.ts +3 -7
- package/dist/crypto/services/WalletKeyEncryptionService.js +5 -9
- package/dist/crypto/services/WalletKeyEncryptionService.js.map +1 -1
- package/dist/crypto/services/WalletKeyEncryptionService.test.d.ts +1 -0
- package/dist/diagnostics.d.ts +1 -3
- package/dist/diagnostics.test.d.ts +1 -0
- package/dist/errors.cjs +16 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +53 -15
- package/dist/errors.js +18 -6
- package/dist/errors.js.map +1 -1
- package/dist/generated/abi/ComputeEngineImplementation.d.ts +2 -3
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.cjs.map +1 -1
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.d.ts +2 -3
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.js.map +1 -1
- package/dist/generated/abi/DATFactoryImplementation.d.ts +2 -3
- package/dist/generated/abi/DATImplementation.d.ts +2 -3
- package/dist/generated/abi/DATPausableImplementation.d.ts +2 -3
- package/dist/generated/abi/DATVotesImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPPerformanceImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRegistryImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRegistryTreasuryImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRewardDeployerImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRewardSwapImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRootImplementation.d.ts +1 -3
- package/dist/generated/abi/DLPTreasuryImplementation.d.ts +2 -3
- package/dist/generated/abi/DataLiquidityPoolImplementation.d.ts +1 -3
- package/dist/generated/abi/DataPortabilityGranteesImplementation.d.ts +2 -3
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.ts +2 -3
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.js.map +1 -1
- package/dist/generated/abi/DataPortabilityServersImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataPortabilityServersImplementation.d.ts +2 -3
- package/dist/generated/abi/DataPortabilityServersImplementation.js.map +1 -1
- package/dist/generated/abi/DataRefinerRegistryImplementation.d.ts +2 -3
- package/dist/generated/abi/DataRegistryImplementation.d.ts +2 -3
- package/dist/generated/abi/QueryEngineImplementation.d.ts +2 -3
- package/dist/generated/abi/SwapHelperImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolDedicatedGpuImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolDedicatedStandardImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolEphemeralStandardImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolPersistentGpuImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolPersistentStandardImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolPhalaImplementation.d.ts +2 -3
- package/dist/generated/abi/VanaEpochImplementation.d.ts +2 -3
- package/dist/generated/abi/VanaPoolEntityImplementation.d.ts +2 -3
- package/dist/generated/abi/VanaPoolStakingImplementation.d.ts +2 -3
- package/dist/generated/abi/VanaPoolTreasuryImplementation.d.ts +2 -3
- package/dist/generated/abi/index.d.ts +37 -39
- package/dist/generated/event-types.d.ts +9 -10
- package/dist/generated/eventRegistry.d.ts +3 -7
- package/dist/generated/server/server-exports.d.ts +19 -21
- package/dist/generated/server/server.cjs.map +1 -1
- package/dist/generated/server/server.d.ts +113 -87
- package/dist/generated/subgraph.d.ts +329 -332
- package/dist/index.browser.d.ts +47 -96
- package/dist/index.browser.js +12 -0
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/index.node.cjs +9 -0
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.ts +181 -87
- package/dist/index.node.js +10 -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.map +1 -1
- package/dist/server/handler.d.ts +8 -227
- package/dist/server/handler.js.map +1 -1
- 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-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/schemas.test.d.ts +1 -0
- package/dist/tests/server-handler.test.d.ts +1 -0
- package/dist/tests/setup.d.ts +7 -0
- package/dist/tests/signatureFormatter.test.d.ts +1 -0
- package/dist/tests/trusted-server-queries.test.d.ts +1 -0
- package/dist/tests/typedDataConverter.test.d.ts +1 -0
- package/dist/tests/types-contracts.test.d.ts +1 -0
- package/dist/tests/types-data.test.d.ts +1 -0
- package/dist/tests/types-external-apis.test.d.ts +1 -0
- package/dist/tests/types-generics.test.d.ts +1 -0
- package/dist/tests/types-permissions.test.d.ts +1 -0
- package/dist/tests/types-upload-params.test.d.ts +1 -0
- package/dist/tests/types.test.d.ts +1 -0
- package/dist/tests/utils-formatters.test.d.ts +1 -0
- package/dist/tests/utils-grantFiles-edge-cases.test.d.ts +1 -0
- package/dist/tests/utils-grantFiles-validation.test.d.ts +1 -0
- package/dist/tests/utils-grantFiles.test.d.ts +1 -0
- package/dist/tests/utils-grantValidation-consolidated.test.d.ts +1 -0
- package/dist/tests/utils-grants.test.d.ts +1 -0
- package/dist/tests/utils-ipfs-additional.test.d.ts +1 -0
- package/dist/tests/utils-ipfs.test.d.ts +4 -0
- package/dist/tests/utils-schemaValidation.test.d.ts +1 -0
- package/dist/tests/vana.test.d.ts +1 -0
- package/dist/tests/wallet-crypto-compatibility.test.d.ts +1 -0
- package/dist/types/blockchain.cjs.map +1 -1
- package/dist/types/blockchain.d.ts +13 -8
- 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 +161 -54
- 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.map +1 -1
- package/dist/types/controller-context.d.ts +13 -20
- 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 -22
- package/dist/types/index.js +9 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/operations.cjs +2 -2
- package/dist/types/operations.cjs.map +1 -1
- package/dist/types/operations.d.ts +13 -17
- 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.d.ts +15 -18
- 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.d.ts +16 -18
- package/dist/types/utils.d.ts +21 -24
- package/dist/types.d.ts +4 -28
- package/dist/utils/__tests__/parseTransaction.test.d.ts +1 -0
- package/dist/utils/__tests__/pojo-serialization.test.d.ts +1 -0
- package/dist/utils/__tests__/signatureCache.test.d.ts +1 -0
- package/dist/utils/__tests__/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.map +1 -1
- package/dist/utils/parseTransactionPojo.d.ts +4 -10
- package/dist/utils/parseTransactionPojo.js.map +1 -1
- package/dist/utils/schemaValidation.cjs +5 -5
- package/dist/utils/schemaValidation.cjs.map +1 -1
- package/dist/utils/schemaValidation.d.ts +8 -12
- package/dist/utils/schemaValidation.js +7 -10
- package/dist/utils/schemaValidation.js.map +1 -1
- package/dist/utils/signatureCache.cjs +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.map +1 -1
- package/dist/utils/transactionHelpers.d.ts +5 -11
- package/dist/utils/transactionHelpers.js.map +1 -1
- package/dist/utils/typeGuards.cjs +109 -0
- package/dist/utils/typeGuards.cjs.map +1 -0
- package/dist/utils/typeGuards.d.ts +138 -0
- package/dist/utils/typeGuards.js +74 -0
- package/dist/utils/typeGuards.js.map +1 -0
- package/dist/utils/typedDataConverter.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 +62 -0
- package/dist/utils/wallet.cjs.map +1 -0
- package/dist/utils/wallet.d.ts +32 -0
- package/dist/utils/wallet.js +36 -0
- package/dist/utils/wallet.js.map +1 -0
- package/dist/utils/withEvents.cjs.map +1 -1
- package/dist/utils/withEvents.d.ts +5 -12
- package/dist/utils/withEvents.js.map +1 -1
- package/package.json +22 -16
- package/dist/browser.d.cts +0 -2
- package/dist/chains/definitions.d.cts +0 -53
- package/dist/chains/index.d.cts +0 -2
- package/dist/chains.browser.cjs +0 -37
- package/dist/chains.browser.cjs.map +0 -1
- package/dist/chains.browser.d.cts +0 -2
- package/dist/chains.d.cts +0 -2
- package/dist/chains.node.d.cts +0 -2
- package/dist/config/addresses.d.cts +0 -401
- package/dist/config/chains.d.cts +0 -85
- package/dist/config/features.d.cts +0 -64
- package/dist/contracts/contractController.d.cts +0 -117
- package/dist/controllers/data.d.cts +0 -915
- package/dist/controllers/permissions.d.cts +0 -1383
- package/dist/controllers/protocol.d.cts +0 -188
- package/dist/controllers/schemas.d.cts +0 -260
- package/dist/controllers/server.d.cts +0 -230
- package/dist/core/apiClient.d.cts +0 -165
- package/dist/core/client.d.cts +0 -92
- package/dist/core/generics.d.cts +0 -120
- package/dist/core.d.cts +0 -493
- package/dist/crypto/ecies/__tests__/test-vectors.d.cts +0 -40
- package/dist/crypto/ecies/base.d.cts +0 -143
- package/dist/crypto/ecies/browser.d.cts +0 -48
- package/dist/crypto/ecies/constants.d.cts +0 -122
- package/dist/crypto/ecies/index.d.cts +0 -1
- package/dist/crypto/ecies/interface.d.cts +0 -176
- package/dist/crypto/ecies/node.d.cts +0 -50
- package/dist/crypto/ecies/test-vectors/eccrypto-vectors.d.cts +0 -76
- package/dist/crypto/ecies/test-vectors/eccrypto-vectors.d.ts +0 -76
- package/dist/crypto/ecies/utils.d.cts +0 -67
- package/dist/crypto/services/WalletKeyEncryptionService.d.cts +0 -92
- package/dist/diagnostics.d.cts +0 -26
- package/dist/errors.d.cts +0 -350
- package/dist/generated/abi/ComputeEngineImplementation.d.cts +0 -996
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.d.cts +0 -545
- package/dist/generated/abi/DATFactoryImplementation.d.cts +0 -661
- package/dist/generated/abi/DATImplementation.d.cts +0 -693
- package/dist/generated/abi/DATPausableImplementation.d.cts +0 -1145
- package/dist/generated/abi/DATVotesImplementation.d.cts +0 -1095
- package/dist/generated/abi/DLPPerformanceImplementation.d.cts +0 -883
- package/dist/generated/abi/DLPRegistryImplementation.d.cts +0 -1123
- package/dist/generated/abi/DLPRegistryTreasuryImplementation.d.cts +0 -452
- package/dist/generated/abi/DLPRewardDeployerImplementation.d.cts +0 -714
- package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.d.cts +0 -452
- package/dist/generated/abi/DLPRewardSwapImplementation.d.cts +0 -706
- package/dist/generated/abi/DLPRootImplementation.d.cts +0 -1248
- package/dist/generated/abi/DLPTreasuryImplementation.d.cts +0 -452
- package/dist/generated/abi/DataLiquidityPoolImplementation.d.cts +0 -737
- package/dist/generated/abi/DataPortabilityGranteesImplementation.d.cts +0 -661
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.cts +0 -989
- package/dist/generated/abi/DataPortabilityServersImplementation.d.cts +0 -1086
- package/dist/generated/abi/DataRefinerRegistryImplementation.d.cts +0 -737
- package/dist/generated/abi/DataRegistryImplementation.d.cts +0 -1014
- package/dist/generated/abi/QueryEngineImplementation.d.cts +0 -1001
- package/dist/generated/abi/SwapHelperImplementation.d.cts +0 -764
- package/dist/generated/abi/TeePoolDedicatedGpuImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolDedicatedStandardImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolEphemeralStandardImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolImplementation.d.cts +0 -993
- package/dist/generated/abi/TeePoolPersistentGpuImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolPersistentStandardImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolPhalaImplementation.d.cts +0 -993
- package/dist/generated/abi/VanaEpochImplementation.d.cts +0 -900
- package/dist/generated/abi/VanaPoolEntityImplementation.d.cts +0 -934
- package/dist/generated/abi/VanaPoolStakingImplementation.d.cts +0 -693
- package/dist/generated/abi/VanaPoolTreasuryImplementation.d.cts +0 -394
- package/dist/generated/abi/index.d.cts +0 -26547
- package/dist/generated/event-types.d.cts +0 -855
- package/dist/generated/eventRegistry.d.cts +0 -18
- package/dist/generated/server/server-exports.d.cts +0 -21
- package/dist/generated/server/server.d.cts +0 -512
- package/dist/generated/subgraph.d.cts +0 -5981
- package/dist/index.browser.cjs +0 -151
- package/dist/index.browser.cjs.map +0 -1
- package/dist/index.browser.d.cts +0 -201
- package/dist/index.d.cts +0 -2
- package/dist/index.node.d.cts +0 -87
- package/dist/node.d.cts +0 -2
- package/dist/platform/browser-only.d.cts +0 -25
- package/dist/platform/browser-safe.d.cts +0 -32
- package/dist/platform/browser.d.cts +0 -74
- package/dist/platform/index.d.cts +0 -5
- package/dist/platform/interface.d.cts +0 -218
- package/dist/platform/node.d.cts +0 -27
- package/dist/platform/shared/error-utils.d.cts +0 -25
- package/dist/platform/shared/pgp-utils.d.cts +0 -61
- package/dist/platform/shared/stream-utils.d.cts +0 -16
- package/dist/platform/utils.d.cts +0 -53
- package/dist/platform.browser.cjs +0 -41
- package/dist/platform.browser.cjs.map +0 -1
- package/dist/platform.browser.d.cts +0 -4
- package/dist/platform.d.cts +0 -5
- package/dist/platform.node.d.cts +0 -5
- package/dist/schemas/dataSchema.schema.d.cts +0 -88
- package/dist/schemas/dataSchema.schema.d.ts +0 -88
- package/dist/schemas/grantFile.schema.d.cts +0 -57
- package/dist/schemas/grantFile.schema.d.ts +0 -57
- package/dist/server/handler.d.cts +0 -306
- package/dist/storage/index.d.cts +0 -10
- package/dist/storage/manager.d.cts +0 -150
- package/dist/storage/providers/callback-storage.d.cts +0 -100
- package/dist/storage/providers/google-drive.d.cts +0 -156
- package/dist/storage/providers/ipfs.d.cts +0 -163
- package/dist/storage/providers/pinata.d.cts +0 -173
- package/dist/types/blockchain.d.cts +0 -52
- package/dist/types/chains.d.cts +0 -34
- package/dist/types/config.d.cts +0 -726
- package/dist/types/contracts.d.cts +0 -68
- package/dist/types/controller-context.d.cts +0 -71
- package/dist/types/data.d.cts +0 -694
- package/dist/types/eccrypto-js.d.d.cts +0 -13
- package/dist/types/eccrypto-js.d.d.ts +0 -13
- package/dist/types/external-apis.d.cts +0 -186
- package/dist/types/generics.d.cts +0 -450
- package/dist/types/index.d.cts +0 -22
- package/dist/types/operations.d.cts +0 -116
- package/dist/types/permissions.d.cts +0 -957
- package/dist/types/personal.d.cts +0 -40
- package/dist/types/relayer.d.cts +0 -284
- package/dist/types/storage.d.cts +0 -131
- package/dist/types/transactionResults.d.cts +0 -195
- package/dist/types/utils.d.cts +0 -819
- package/dist/types.d.cts +0 -54
- package/dist/utils/blockchain/registry.d.cts +0 -34
- package/dist/utils/crypto-utils.d.cts +0 -118
- package/dist/utils/download.d.cts +0 -41
- package/dist/utils/encoding.d.cts +0 -54
- package/dist/utils/encryption.d.cts +0 -275
- package/dist/utils/formatters.d.cts +0 -120
- package/dist/utils/grantFiles.d.cts +0 -186
- package/dist/utils/grantValidation.d.cts +0 -150
- package/dist/utils/grants.d.cts +0 -70
- package/dist/utils/ipfs.d.cts +0 -90
- package/dist/utils/lazy-import.d.cts +0 -20
- package/dist/utils/multicall.d.cts +0 -129
- package/dist/utils/parseTransactionPojo.d.cts +0 -37
- package/dist/utils/schemaValidation.d.cts +0 -172
- package/dist/utils/signatureCache.d.cts +0 -134
- package/dist/utils/signatureFormatter.d.cts +0 -39
- package/dist/utils/transactionHelpers.d.cts +0 -86
- package/dist/utils/typedDataConverter.d.cts +0 -13
- package/dist/utils/urlResolver.d.cts +0 -40
- package/dist/utils/withEvents.d.cts +0 -63
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,29 @@ 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
|
-
|
|
63
|
-
|
|
70
|
+
if (error instanceof Error) {
|
|
71
|
+
const errorDetails = error.errors;
|
|
72
|
+
if (errorDetails && Array.isArray(errorDetails)) {
|
|
73
|
+
validationErrors = errorDetails;
|
|
74
|
+
} else {
|
|
75
|
+
validationErrors = [error.message];
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
validationErrors = ["Schema validation failed"];
|
|
79
|
+
}
|
|
64
80
|
}
|
|
65
81
|
}
|
|
66
82
|
const uploadResult = await this.uploadToStorage(
|
|
@@ -69,9 +85,10 @@ class DataController {
|
|
|
69
85
|
encrypt,
|
|
70
86
|
providerName
|
|
71
87
|
);
|
|
72
|
-
const userAddress = owner
|
|
88
|
+
const userAddress = owner ?? this.context.userAddress;
|
|
73
89
|
let encryptedPermissions = [];
|
|
74
90
|
if (permissions.length > 0 && encrypt) {
|
|
91
|
+
this.assertWallet();
|
|
75
92
|
const userEncryptionKey = await generateEncryptionKey(
|
|
76
93
|
this.context.walletClient,
|
|
77
94
|
this.context.platform,
|
|
@@ -98,7 +115,7 @@ class DataController {
|
|
|
98
115
|
url: uploadResult.url,
|
|
99
116
|
userAddress,
|
|
100
117
|
permissions: encryptedPermissions,
|
|
101
|
-
schemaId: schemaId
|
|
118
|
+
schemaId: schemaId ?? 0,
|
|
102
119
|
ownerAddress: owner
|
|
103
120
|
}
|
|
104
121
|
);
|
|
@@ -114,15 +131,24 @@ class DataController {
|
|
|
114
131
|
userAddress
|
|
115
132
|
);
|
|
116
133
|
} else {
|
|
117
|
-
const txResult = await this.
|
|
134
|
+
const txResult = await this.addFileWithEncryptedPermissionsAndSchema(
|
|
118
135
|
uploadResult.url,
|
|
119
136
|
userAddress,
|
|
120
137
|
encryptedPermissions,
|
|
121
|
-
schemaId
|
|
138
|
+
schemaId ?? 0
|
|
122
139
|
);
|
|
140
|
+
if (!this.context.waitForTransactionEvents) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
"Cannot upload without relay: waitForTransactionEvents not configured"
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
const eventResult = await this.context.waitForTransactionEvents(txResult);
|
|
146
|
+
const fileAddedEvent = eventResult.expectedEvents.FileAdded;
|
|
147
|
+
if (!fileAddedEvent) {
|
|
148
|
+
throw new Error("FileAdded event not found in transaction");
|
|
149
|
+
}
|
|
123
150
|
result = {
|
|
124
|
-
fileId:
|
|
125
|
-
// Placeholder - actual fileId available after waiting for events
|
|
151
|
+
fileId: Number(fileAddedEvent.fileId),
|
|
126
152
|
transactionHash: txResult.hash
|
|
127
153
|
};
|
|
128
154
|
}
|
|
@@ -140,6 +166,83 @@ class DataController {
|
|
|
140
166
|
);
|
|
141
167
|
}
|
|
142
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Encrypts data using wallet-derived encryption.
|
|
171
|
+
*
|
|
172
|
+
* @remarks
|
|
173
|
+
* This method provides secure, wallet-based encryption for data before uploading
|
|
174
|
+
* to the Vana network. It's the counterpart to decryptFile for preparing data
|
|
175
|
+
* for secure storage.
|
|
176
|
+
*
|
|
177
|
+
* The method automatically:
|
|
178
|
+
* - Generates an encryption key from the user's wallet signature
|
|
179
|
+
* - Converts the input data to a Blob if necessary
|
|
180
|
+
* - Encrypts the data using the generated key
|
|
181
|
+
* - Returns both the encrypted data and the encryption key
|
|
182
|
+
*
|
|
183
|
+
* The encryption key returned can be stored and later used for decryption,
|
|
184
|
+
* or shared with others to grant them decryption access.
|
|
185
|
+
*
|
|
186
|
+
* @param data - The data to encrypt (Blob, string, or object)
|
|
187
|
+
* @param options - Optional encryption configuration
|
|
188
|
+
* @returns Promise resolving to encrypted data and the encryption key used
|
|
189
|
+
* @throws {Error} When wallet is not connected or encryption fails
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* // Encrypt a string
|
|
193
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
194
|
+
* "My secret data"
|
|
195
|
+
* );
|
|
196
|
+
*
|
|
197
|
+
* // Encrypt JSON with custom MIME type
|
|
198
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
199
|
+
* { name: "Alice", age: 30 },
|
|
200
|
+
* { mimeType: "application/json" }
|
|
201
|
+
* );
|
|
202
|
+
*
|
|
203
|
+
* // With custom encryption seed
|
|
204
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
205
|
+
* "Secret message",
|
|
206
|
+
* { seed: "My custom encryption seed" }
|
|
207
|
+
* );
|
|
208
|
+
*
|
|
209
|
+
* // Upload the encrypted data
|
|
210
|
+
* const result = await vana.data.uploadToStorage(encryptedData);
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
async encryptFile(data, options) {
|
|
214
|
+
this.assertWallet();
|
|
215
|
+
try {
|
|
216
|
+
const encryptionKey = await generateEncryptionKey(
|
|
217
|
+
this.context.walletClient,
|
|
218
|
+
this.context.platform,
|
|
219
|
+
options?.seed ?? DEFAULT_ENCRYPTION_SEED
|
|
220
|
+
);
|
|
221
|
+
let blob;
|
|
222
|
+
if (data instanceof Blob) {
|
|
223
|
+
blob = data;
|
|
224
|
+
} else if (typeof data === "string") {
|
|
225
|
+
blob = new Blob([data], { type: options?.mimeType ?? "text/plain" });
|
|
226
|
+
} else {
|
|
227
|
+
blob = new Blob([JSON.stringify(data)], {
|
|
228
|
+
type: options?.mimeType ?? "application/json"
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
const encryptedData = await encryptBlobWithSignedKey(
|
|
232
|
+
blob,
|
|
233
|
+
encryptionKey,
|
|
234
|
+
this.context.platform
|
|
235
|
+
);
|
|
236
|
+
return {
|
|
237
|
+
encryptedData,
|
|
238
|
+
encryptionKey
|
|
239
|
+
};
|
|
240
|
+
} catch (error) {
|
|
241
|
+
throw new Error(
|
|
242
|
+
`Failed to encrypt file: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
143
246
|
/**
|
|
144
247
|
* Decrypts a file owned by the user using their wallet signature.
|
|
145
248
|
*
|
|
@@ -195,12 +298,14 @@ class DataController {
|
|
|
195
298
|
* fs.writeFileSync('decrypted-file.txt', Buffer.from(buffer));
|
|
196
299
|
* ```
|
|
197
300
|
*/
|
|
198
|
-
async decryptFile(file,
|
|
301
|
+
async decryptFile(file, options) {
|
|
302
|
+
this.assertWallet();
|
|
199
303
|
try {
|
|
304
|
+
this.assertWallet();
|
|
200
305
|
const encryptionKey = await generateEncryptionKey(
|
|
201
306
|
this.context.walletClient,
|
|
202
307
|
this.context.platform,
|
|
203
|
-
|
|
308
|
+
options?.seed ?? DEFAULT_ENCRYPTION_SEED
|
|
204
309
|
);
|
|
205
310
|
let encryptedBlob;
|
|
206
311
|
try {
|
|
@@ -317,7 +422,7 @@ class DataController {
|
|
|
317
422
|
*/
|
|
318
423
|
async getUserFiles(params) {
|
|
319
424
|
const { owner, subgraphUrl } = params;
|
|
320
|
-
const endpoint = subgraphUrl
|
|
425
|
+
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
321
426
|
if (!endpoint) {
|
|
322
427
|
throw new Error(
|
|
323
428
|
"subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor."
|
|
@@ -349,7 +454,7 @@ class DataController {
|
|
|
349
454
|
);
|
|
350
455
|
}
|
|
351
456
|
const user = result.data?.user;
|
|
352
|
-
if (!user
|
|
457
|
+
if (!user?.files?.length) {
|
|
353
458
|
console.warn("No files found for user:", owner);
|
|
354
459
|
return [];
|
|
355
460
|
}
|
|
@@ -371,7 +476,7 @@ class DataController {
|
|
|
371
476
|
}
|
|
372
477
|
});
|
|
373
478
|
const userFiles = Array.from(fileMap.values()).sort(
|
|
374
|
-
(a, b) => Number((b.addedAtTimestamp
|
|
479
|
+
(a, b) => Number((b.addedAtTimestamp ?? 0n) - (a.addedAtTimestamp ?? 0n))
|
|
375
480
|
);
|
|
376
481
|
if (userFiles.length > 0) {
|
|
377
482
|
try {
|
|
@@ -442,10 +547,11 @@ class DataController {
|
|
|
442
547
|
if (proof.dlp?.id) {
|
|
443
548
|
const fileId = parseInt(proof.fileId);
|
|
444
549
|
const dlpId = parseInt(proof.dlp.id);
|
|
445
|
-
|
|
446
|
-
|
|
550
|
+
let dlpIds = proofMap.get(fileId);
|
|
551
|
+
if (!dlpIds) {
|
|
552
|
+
dlpIds = [];
|
|
553
|
+
proofMap.set(fileId, dlpIds);
|
|
447
554
|
}
|
|
448
|
-
const dlpIds = proofMap.get(fileId);
|
|
449
555
|
if (!dlpIds.includes(dlpId)) {
|
|
450
556
|
dlpIds.push(dlpId);
|
|
451
557
|
}
|
|
@@ -463,7 +569,7 @@ class DataController {
|
|
|
463
569
|
* @returns Map of file IDs to their associated DLP IDs
|
|
464
570
|
*/
|
|
465
571
|
async _fetchProofsFromChain(fileIds) {
|
|
466
|
-
const chainId = this.context.
|
|
572
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
467
573
|
if (!chainId) {
|
|
468
574
|
throw new Error("Chain ID not available");
|
|
469
575
|
}
|
|
@@ -520,7 +626,7 @@ class DataController {
|
|
|
520
626
|
* ```
|
|
521
627
|
*/
|
|
522
628
|
async getDLP(dlpId, options = {}) {
|
|
523
|
-
const subgraphUrl = options.subgraphUrl
|
|
629
|
+
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
524
630
|
if (subgraphUrl) {
|
|
525
631
|
try {
|
|
526
632
|
const response = await fetch(subgraphUrl, {
|
|
@@ -551,18 +657,18 @@ class DataController {
|
|
|
551
657
|
}
|
|
552
658
|
return {
|
|
553
659
|
id: parseInt(result.data.dlp.id),
|
|
554
|
-
name: result.data.dlp.name
|
|
555
|
-
metadata: result.data.dlp.metadata
|
|
660
|
+
name: result.data.dlp.name ?? "",
|
|
661
|
+
metadata: result.data.dlp.metadata ?? void 0,
|
|
556
662
|
status: result.data.dlp.status ? parseInt(result.data.dlp.status) : void 0,
|
|
557
|
-
address: result.data.dlp.address,
|
|
558
|
-
owner: result.data.dlp.owner
|
|
663
|
+
address: result.data.dlp.address ? result.data.dlp.address : void 0,
|
|
664
|
+
owner: result.data.dlp.owner ? result.data.dlp.owner : void 0
|
|
559
665
|
};
|
|
560
666
|
} catch (error) {
|
|
561
667
|
console.debug("Subgraph query failed, falling back to chain:", error);
|
|
562
668
|
}
|
|
563
669
|
}
|
|
564
670
|
try {
|
|
565
|
-
const chainId = this.context.
|
|
671
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
566
672
|
if (!chainId) {
|
|
567
673
|
throw new Error("Chain ID not available");
|
|
568
674
|
}
|
|
@@ -574,7 +680,7 @@ class DataController {
|
|
|
574
680
|
functionName: "dlps",
|
|
575
681
|
args: [BigInt(dlpId)]
|
|
576
682
|
});
|
|
577
|
-
if (!dlpData
|
|
683
|
+
if (!dlpData?.name) {
|
|
578
684
|
throw new Error(`DLP not found: ${dlpId}`);
|
|
579
685
|
}
|
|
580
686
|
return {
|
|
@@ -616,7 +722,7 @@ class DataController {
|
|
|
616
722
|
*/
|
|
617
723
|
async listDLPs(options = {}) {
|
|
618
724
|
const { limit = 100, offset = 0 } = options;
|
|
619
|
-
const subgraphUrl = options.subgraphUrl
|
|
725
|
+
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
620
726
|
if (subgraphUrl) {
|
|
621
727
|
try {
|
|
622
728
|
const query = `
|
|
@@ -655,21 +761,21 @@ class DataController {
|
|
|
655
761
|
`Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
656
762
|
);
|
|
657
763
|
}
|
|
658
|
-
const dlps = result.data?.dlps
|
|
764
|
+
const dlps = result.data?.dlps ?? [];
|
|
659
765
|
return dlps.map((dlp) => ({
|
|
660
766
|
id: parseInt(dlp.id),
|
|
661
|
-
name: dlp.name
|
|
767
|
+
name: dlp.name ?? "",
|
|
662
768
|
metadata: dlp.metadata,
|
|
663
769
|
status: dlp.status ? parseInt(dlp.status) : void 0,
|
|
664
|
-
address: dlp.address,
|
|
665
|
-
owner: dlp.owner
|
|
770
|
+
address: dlp.address ? dlp.address : void 0,
|
|
771
|
+
owner: dlp.owner ? dlp.owner : void 0
|
|
666
772
|
}));
|
|
667
773
|
} catch (error) {
|
|
668
774
|
console.debug("Subgraph query failed, falling back to chain:", error);
|
|
669
775
|
}
|
|
670
776
|
}
|
|
671
777
|
try {
|
|
672
|
-
const chainId = this.context.
|
|
778
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
673
779
|
if (!chainId) {
|
|
674
780
|
throw new Error("Chain ID not available");
|
|
675
781
|
}
|
|
@@ -741,7 +847,7 @@ class DataController {
|
|
|
741
847
|
*/
|
|
742
848
|
async getUserPermissions(params) {
|
|
743
849
|
const { user, subgraphUrl } = params;
|
|
744
|
-
const endpoint = subgraphUrl
|
|
850
|
+
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
745
851
|
if (endpoint) {
|
|
746
852
|
try {
|
|
747
853
|
const permissions = await this._getUserPermissionsViaSubgraph({
|
|
@@ -790,7 +896,7 @@ class DataController {
|
|
|
790
896
|
);
|
|
791
897
|
}
|
|
792
898
|
const userData = result.data?.user;
|
|
793
|
-
if (!userData
|
|
899
|
+
if (!userData?.permissions?.length) {
|
|
794
900
|
return [];
|
|
795
901
|
}
|
|
796
902
|
return userData.permissions.map((permission) => ({
|
|
@@ -818,7 +924,7 @@ class DataController {
|
|
|
818
924
|
async _getUserPermissionsViaRpc(params) {
|
|
819
925
|
const { user } = params;
|
|
820
926
|
try {
|
|
821
|
-
const chainId = this.context.
|
|
927
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
822
928
|
if (!chainId) {
|
|
823
929
|
throw new Error("Chain ID not available");
|
|
824
930
|
}
|
|
@@ -937,7 +1043,7 @@ class DataController {
|
|
|
937
1043
|
*/
|
|
938
1044
|
async getUserTrustedServers(params) {
|
|
939
1045
|
const { user, limit = 50, offset = 0 } = params;
|
|
940
|
-
const subgraphUrl = params.subgraphUrl
|
|
1046
|
+
const subgraphUrl = params.subgraphUrl ?? this.context.subgraphUrl;
|
|
941
1047
|
if (subgraphUrl) {
|
|
942
1048
|
try {
|
|
943
1049
|
const servers = await this._getUserTrustedServersViaSubgraph({
|
|
@@ -1000,7 +1106,7 @@ class DataController {
|
|
|
1000
1106
|
if (!result.data?.user) {
|
|
1001
1107
|
return [];
|
|
1002
1108
|
}
|
|
1003
|
-
return (result.data.user.serverTrusts
|
|
1109
|
+
return (result.data.user.serverTrusts ?? []).filter((trust) => !trust.untrustedAtBlock).map((trust) => ({
|
|
1004
1110
|
id: trust.server.id,
|
|
1005
1111
|
serverAddress: trust.server.serverAddress,
|
|
1006
1112
|
serverUrl: trust.server.url,
|
|
@@ -1026,7 +1132,7 @@ class DataController {
|
|
|
1026
1132
|
async _getUserTrustedServersViaRpc(params) {
|
|
1027
1133
|
const { user, limit, offset } = params;
|
|
1028
1134
|
try {
|
|
1029
|
-
const chainId = this.context.
|
|
1135
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1030
1136
|
if (!chainId) {
|
|
1031
1137
|
throw new Error("Chain ID not available");
|
|
1032
1138
|
}
|
|
@@ -1126,7 +1232,7 @@ class DataController {
|
|
|
1126
1232
|
*/
|
|
1127
1233
|
async getTotalFilesCount() {
|
|
1128
1234
|
try {
|
|
1129
|
-
const chainId = this.context.
|
|
1235
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1130
1236
|
if (!chainId) {
|
|
1131
1237
|
throw new Error("Chain ID not available");
|
|
1132
1238
|
}
|
|
@@ -1135,7 +1241,7 @@ class DataController {
|
|
|
1135
1241
|
const dataRegistry = getContract({
|
|
1136
1242
|
address: dataRegistryAddress,
|
|
1137
1243
|
abi: dataRegistryAbi,
|
|
1138
|
-
client: this.context.
|
|
1244
|
+
client: this.context.publicClient
|
|
1139
1245
|
});
|
|
1140
1246
|
const count = await dataRegistry.read.filesCount();
|
|
1141
1247
|
return Number(count);
|
|
@@ -1177,7 +1283,7 @@ class DataController {
|
|
|
1177
1283
|
*/
|
|
1178
1284
|
async getFileById(fileId) {
|
|
1179
1285
|
try {
|
|
1180
|
-
const chainId = this.context.
|
|
1286
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1181
1287
|
if (!chainId) {
|
|
1182
1288
|
throw new Error("Chain ID not available");
|
|
1183
1289
|
}
|
|
@@ -1186,7 +1292,7 @@ class DataController {
|
|
|
1186
1292
|
const dataRegistry = getContract({
|
|
1187
1293
|
address: dataRegistryAddress,
|
|
1188
1294
|
abi: dataRegistryAbi,
|
|
1189
|
-
client: this.context.
|
|
1295
|
+
client: this.context.publicClient
|
|
1190
1296
|
});
|
|
1191
1297
|
const fileDetails = await dataRegistry.read.files([BigInt(fileId)]);
|
|
1192
1298
|
if (!fileDetails) {
|
|
@@ -1245,14 +1351,16 @@ class DataController {
|
|
|
1245
1351
|
* ```
|
|
1246
1352
|
*/
|
|
1247
1353
|
async registerFileWithSchema(url, schemaId) {
|
|
1354
|
+
this.assertWallet();
|
|
1248
1355
|
try {
|
|
1249
|
-
const chainId = this.context.
|
|
1356
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1250
1357
|
if (!chainId) {
|
|
1251
1358
|
throw new Error("Chain ID not available");
|
|
1252
1359
|
}
|
|
1360
|
+
this.assertWallet();
|
|
1253
1361
|
const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
|
|
1254
1362
|
const dataRegistryAbi = getAbi("DataRegistry");
|
|
1255
|
-
const account = this.context.walletClient.account
|
|
1363
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1256
1364
|
const from = typeof account === "string" ? account : account.address;
|
|
1257
1365
|
const hash = await this.context.walletClient.writeContract({
|
|
1258
1366
|
address: dataRegistryAddress,
|
|
@@ -1260,7 +1368,7 @@ class DataController {
|
|
|
1260
1368
|
functionName: "addFileWithSchema",
|
|
1261
1369
|
args: [url, BigInt(schemaId)],
|
|
1262
1370
|
account,
|
|
1263
|
-
chain: this.context.walletClient.chain
|
|
1371
|
+
chain: this.context.walletClient.chain ?? null
|
|
1264
1372
|
});
|
|
1265
1373
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1266
1374
|
return tx({
|
|
@@ -1282,13 +1390,6 @@ class DataController {
|
|
|
1282
1390
|
* @returns Promise resolving to the user's wallet address
|
|
1283
1391
|
* @throws {Error} When no addresses are available in wallet client
|
|
1284
1392
|
*/
|
|
1285
|
-
async getUserAddress() {
|
|
1286
|
-
const addresses = await this.context.walletClient.getAddresses();
|
|
1287
|
-
if (addresses.length === 0) {
|
|
1288
|
-
throw new Error("No addresses available in wallet client");
|
|
1289
|
-
}
|
|
1290
|
-
return addresses[0];
|
|
1291
|
-
}
|
|
1292
1393
|
/**
|
|
1293
1394
|
* Adds a file with permissions to the DataRegistry contract.
|
|
1294
1395
|
*
|
|
@@ -1306,14 +1407,16 @@ class DataController {
|
|
|
1306
1407
|
* by both direct transactions and relayer services.
|
|
1307
1408
|
*/
|
|
1308
1409
|
async addFileWithPermissions(url, ownerAddress, permissions = []) {
|
|
1410
|
+
this.assertWallet();
|
|
1309
1411
|
try {
|
|
1310
|
-
const chainId = this.context.
|
|
1412
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1311
1413
|
if (!chainId) {
|
|
1312
1414
|
throw new Error("Chain ID not available");
|
|
1313
1415
|
}
|
|
1416
|
+
this.assertWallet();
|
|
1314
1417
|
const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
|
|
1315
1418
|
const dataRegistryAbi = getAbi("DataRegistry");
|
|
1316
|
-
const account = this.context.walletClient.account
|
|
1419
|
+
const account = this.context.walletClient.account ?? ownerAddress;
|
|
1317
1420
|
const from = typeof account === "string" ? account : account.address;
|
|
1318
1421
|
const hash = await this.context.walletClient.writeContract({
|
|
1319
1422
|
address: dataRegistryAddress,
|
|
@@ -1321,7 +1424,7 @@ class DataController {
|
|
|
1321
1424
|
functionName: "addFileWithPermissions",
|
|
1322
1425
|
args: [url, ownerAddress, permissions],
|
|
1323
1426
|
account,
|
|
1324
|
-
chain: this.context.walletClient.chain
|
|
1427
|
+
chain: this.context.walletClient.chain ?? null
|
|
1325
1428
|
});
|
|
1326
1429
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1327
1430
|
return tx({
|
|
@@ -1341,25 +1444,132 @@ class DataController {
|
|
|
1341
1444
|
* Adds a file to the registry with permissions and schema.
|
|
1342
1445
|
* This combines the functionality of addFileWithPermissions and schema validation.
|
|
1343
1446
|
*
|
|
1447
|
+
* @remarks
|
|
1448
|
+
* This method automatically encrypts permissions when a publicKey is provided.
|
|
1449
|
+
* It generates the user's encryption key and encrypts it with each recipient's
|
|
1450
|
+
* public key before registering on the blockchain.
|
|
1451
|
+
*
|
|
1344
1452
|
* @param url - The URL of the file to register
|
|
1345
1453
|
* @param ownerAddress - The address of the file owner
|
|
1346
|
-
* @param permissions - Array of permissions to grant
|
|
1454
|
+
* @param permissions - Array of permissions to grant, each with account and publicKey properties
|
|
1347
1455
|
* @param schemaId - The schema ID to associate with the file (0 for no schema)
|
|
1348
|
-
* @returns Promise resolving to
|
|
1349
|
-
* @throws {Error} When chain
|
|
1350
|
-
* @throws {
|
|
1351
|
-
* @throws {Error} When
|
|
1352
|
-
* @throws {Error}
|
|
1456
|
+
* @returns Promise resolving to TransactionResult with fileId and transactionHash
|
|
1457
|
+
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1458
|
+
* @throws {Error} "Failed to generate encryption key" - When encryption key generation fails
|
|
1459
|
+
* @throws {Error} "Permission for {account} must include 'publicKey'" - When publicKey is missing
|
|
1460
|
+
* @throws {Error} "Failed to add file with permissions and schema: {error}" - When transaction fails
|
|
1461
|
+
* @example
|
|
1462
|
+
* ```typescript
|
|
1463
|
+
* // Get server's public key
|
|
1464
|
+
* const serverIdentity = await vana.server.getIdentity({
|
|
1465
|
+
* userAddress: "0x..."
|
|
1466
|
+
* });
|
|
1467
|
+
*
|
|
1468
|
+
* // Add file with permissions and schema
|
|
1469
|
+
* const result = await vana.data.addFileWithPermissionsAndSchema(
|
|
1470
|
+
* "ipfs://QmXxx...",
|
|
1471
|
+
* ownerAddress,
|
|
1472
|
+
* [{
|
|
1473
|
+
* account: serverIdentity.address,
|
|
1474
|
+
* publicKey: serverIdentity.publicKey
|
|
1475
|
+
* }],
|
|
1476
|
+
* schemaId
|
|
1477
|
+
* );
|
|
1478
|
+
*
|
|
1479
|
+
* console.log(`File ${result.fileId} registered in tx ${result.hash}`);
|
|
1480
|
+
* ```
|
|
1353
1481
|
*/
|
|
1354
1482
|
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1483
|
+
this.assertWallet();
|
|
1355
1484
|
try {
|
|
1356
|
-
|
|
1485
|
+
let encryptedPermissions = [];
|
|
1486
|
+
if (permissions.length > 0) {
|
|
1487
|
+
this.assertWallet();
|
|
1488
|
+
const userEncryptionKey = await generateEncryptionKey(
|
|
1489
|
+
this.context.walletClient,
|
|
1490
|
+
this.context.platform,
|
|
1491
|
+
DEFAULT_ENCRYPTION_SEED
|
|
1492
|
+
);
|
|
1493
|
+
encryptedPermissions = await Promise.all(
|
|
1494
|
+
permissions.map(async (permission) => {
|
|
1495
|
+
if (!permission.publicKey) {
|
|
1496
|
+
throw new Error(
|
|
1497
|
+
`Permission for ${permission.account} must include 'publicKey'`
|
|
1498
|
+
);
|
|
1499
|
+
}
|
|
1500
|
+
const encryptedKey = await encryptWithWalletPublicKey(
|
|
1501
|
+
userEncryptionKey,
|
|
1502
|
+
permission.publicKey,
|
|
1503
|
+
this.context.platform
|
|
1504
|
+
);
|
|
1505
|
+
return {
|
|
1506
|
+
account: permission.account,
|
|
1507
|
+
key: encryptedKey
|
|
1508
|
+
};
|
|
1509
|
+
})
|
|
1510
|
+
);
|
|
1511
|
+
}
|
|
1512
|
+
return await this.addFileWithEncryptedPermissionsAndSchema(
|
|
1513
|
+
url,
|
|
1514
|
+
ownerAddress,
|
|
1515
|
+
encryptedPermissions,
|
|
1516
|
+
schemaId
|
|
1517
|
+
);
|
|
1518
|
+
} catch (error) {
|
|
1519
|
+
console.error("Failed to add file with permissions and schema:", error);
|
|
1520
|
+
throw new Error(
|
|
1521
|
+
`Failed to add file with permissions and schema: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
1522
|
+
);
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
/**
|
|
1526
|
+
* Adds a file with pre-encrypted permissions and schema to the DataRegistry.
|
|
1527
|
+
*
|
|
1528
|
+
* @remarks
|
|
1529
|
+
* This method is designed for relay services and advanced use cases where permissions
|
|
1530
|
+
* have already been encrypted client-side. Unlike `addFileWithPermissionsAndSchema()`,
|
|
1531
|
+
* this method expects permissions in the encrypted format with a 'key' field instead
|
|
1532
|
+
* of 'publicKey'.
|
|
1533
|
+
*
|
|
1534
|
+
* This is typically used by relay endpoints that receive pre-encrypted data from
|
|
1535
|
+
* the client SDK's `upload()` method, avoiding double encryption.
|
|
1536
|
+
*
|
|
1537
|
+
* @param url - The storage URL of the file (e.g., IPFS URL)
|
|
1538
|
+
* @param ownerAddress - The address that will own this file
|
|
1539
|
+
* @param permissions - Array of pre-encrypted permissions with 'account' and 'key' fields
|
|
1540
|
+
* @param schemaId - Optional schema ID for data validation (defaults to 0)
|
|
1541
|
+
* @returns Promise resolving to transaction result with hash and contract details
|
|
1542
|
+
* @throws {Error} When chain ID is not available
|
|
1543
|
+
* @throws {Error} When wallet is not connected
|
|
1544
|
+
* @throws {Error} When transaction fails
|
|
1545
|
+
* @example
|
|
1546
|
+
* ```typescript
|
|
1547
|
+
* // In a relay endpoint that receives pre-encrypted permissions
|
|
1548
|
+
* const result = await vana.data.addFileWithEncryptedPermissionsAndSchema(
|
|
1549
|
+
* "ipfs://QmXxx...",
|
|
1550
|
+
* ownerAddress,
|
|
1551
|
+
* [
|
|
1552
|
+
* {
|
|
1553
|
+
* account: "0xServerAddress...",
|
|
1554
|
+
* key: "encrypted_key_string" // Already encrypted by client
|
|
1555
|
+
* }
|
|
1556
|
+
* ],
|
|
1557
|
+
* schemaId
|
|
1558
|
+
* );
|
|
1559
|
+
*
|
|
1560
|
+
* console.log(`File registered in tx ${result.hash}`);
|
|
1561
|
+
* ```
|
|
1562
|
+
*/
|
|
1563
|
+
async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1564
|
+
try {
|
|
1565
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1357
1566
|
if (!chainId) {
|
|
1358
1567
|
throw new Error("Chain ID not available");
|
|
1359
1568
|
}
|
|
1569
|
+
this.assertWallet();
|
|
1360
1570
|
const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
|
|
1361
1571
|
const dataRegistryAbi = getAbi("DataRegistry");
|
|
1362
|
-
const account = this.context.walletClient.account
|
|
1572
|
+
const account = this.context.walletClient.account ?? ownerAddress;
|
|
1363
1573
|
const from = typeof account === "string" ? account : account.address;
|
|
1364
1574
|
const hash = await this.context.walletClient.writeContract({
|
|
1365
1575
|
address: dataRegistryAddress,
|
|
@@ -1367,7 +1577,7 @@ class DataController {
|
|
|
1367
1577
|
functionName: "addFileWithPermissionsAndSchema",
|
|
1368
1578
|
args: [url, ownerAddress, permissions, BigInt(schemaId)],
|
|
1369
1579
|
account,
|
|
1370
|
-
chain: this.context.walletClient.chain
|
|
1580
|
+
chain: this.context.walletClient.chain ?? null
|
|
1371
1581
|
});
|
|
1372
1582
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1373
1583
|
return tx({
|
|
@@ -1412,8 +1622,9 @@ class DataController {
|
|
|
1412
1622
|
* ```
|
|
1413
1623
|
*/
|
|
1414
1624
|
async addRefiner(params) {
|
|
1625
|
+
this.assertWallet();
|
|
1415
1626
|
try {
|
|
1416
|
-
const chainId = this.context.
|
|
1627
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1417
1628
|
if (!chainId) {
|
|
1418
1629
|
throw new Error("Chain ID not available");
|
|
1419
1630
|
}
|
|
@@ -1422,7 +1633,8 @@ class DataController {
|
|
|
1422
1633
|
"DataRefinerRegistry"
|
|
1423
1634
|
);
|
|
1424
1635
|
const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
|
|
1425
|
-
|
|
1636
|
+
this.assertWallet();
|
|
1637
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1426
1638
|
const from = typeof account === "string" ? account : account.address;
|
|
1427
1639
|
const hash = await this.context.walletClient.writeContract({
|
|
1428
1640
|
address: dataRefinerRegistryAddress,
|
|
@@ -1435,7 +1647,7 @@ class DataController {
|
|
|
1435
1647
|
params.refinementInstructionUrl
|
|
1436
1648
|
],
|
|
1437
1649
|
account,
|
|
1438
|
-
chain: this.context.walletClient.chain
|
|
1650
|
+
chain: this.context.walletClient.chain ?? null
|
|
1439
1651
|
});
|
|
1440
1652
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1441
1653
|
const txResult = tx({
|
|
@@ -1488,7 +1700,7 @@ class DataController {
|
|
|
1488
1700
|
*/
|
|
1489
1701
|
async getRefiner(refinerId) {
|
|
1490
1702
|
try {
|
|
1491
|
-
const chainId = this.context.
|
|
1703
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1492
1704
|
if (!chainId) {
|
|
1493
1705
|
throw new Error("Chain ID not available");
|
|
1494
1706
|
}
|
|
@@ -1500,7 +1712,7 @@ class DataController {
|
|
|
1500
1712
|
const dataRefinerRegistry = getContract({
|
|
1501
1713
|
address: dataRefinerRegistryAddress,
|
|
1502
1714
|
abi: dataRefinerRegistryAbi,
|
|
1503
|
-
client: this.context.
|
|
1715
|
+
client: this.context.publicClient
|
|
1504
1716
|
});
|
|
1505
1717
|
const refinerData = await dataRefinerRegistry.read.refiners([
|
|
1506
1718
|
BigInt(refinerId)
|
|
@@ -1544,7 +1756,7 @@ class DataController {
|
|
|
1544
1756
|
*/
|
|
1545
1757
|
async isValidSchemaId(schemaId) {
|
|
1546
1758
|
try {
|
|
1547
|
-
const chainId = this.context.
|
|
1759
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1548
1760
|
if (!chainId) {
|
|
1549
1761
|
throw new Error("Chain ID not available");
|
|
1550
1762
|
}
|
|
@@ -1556,7 +1768,7 @@ class DataController {
|
|
|
1556
1768
|
const dataRefinerRegistry = getContract({
|
|
1557
1769
|
address: dataRefinerRegistryAddress,
|
|
1558
1770
|
abi: dataRefinerRegistryAbi,
|
|
1559
|
-
client: this.context.
|
|
1771
|
+
client: this.context.publicClient
|
|
1560
1772
|
});
|
|
1561
1773
|
const isValid = await dataRefinerRegistry.read.isValidSchemaId([
|
|
1562
1774
|
BigInt(schemaId)
|
|
@@ -1583,7 +1795,7 @@ class DataController {
|
|
|
1583
1795
|
*/
|
|
1584
1796
|
async getRefinersCount() {
|
|
1585
1797
|
try {
|
|
1586
|
-
const chainId = this.context.
|
|
1798
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1587
1799
|
if (!chainId) {
|
|
1588
1800
|
throw new Error("Chain ID not available");
|
|
1589
1801
|
}
|
|
@@ -1595,7 +1807,7 @@ class DataController {
|
|
|
1595
1807
|
const dataRefinerRegistry = getContract({
|
|
1596
1808
|
address: dataRefinerRegistryAddress,
|
|
1597
1809
|
abi: dataRefinerRegistryAbi,
|
|
1598
|
-
client: this.context.
|
|
1810
|
+
client: this.context.publicClient
|
|
1599
1811
|
});
|
|
1600
1812
|
const count = await dataRefinerRegistry.read.refinersCount();
|
|
1601
1813
|
return Number(count);
|
|
@@ -1627,8 +1839,9 @@ class DataController {
|
|
|
1627
1839
|
* ```
|
|
1628
1840
|
*/
|
|
1629
1841
|
async updateSchemaId(params) {
|
|
1842
|
+
this.assertWallet();
|
|
1630
1843
|
try {
|
|
1631
|
-
const chainId = this.context.
|
|
1844
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1632
1845
|
if (!chainId) {
|
|
1633
1846
|
throw new Error("Chain ID not available");
|
|
1634
1847
|
}
|
|
@@ -1637,14 +1850,15 @@ class DataController {
|
|
|
1637
1850
|
"DataRefinerRegistry"
|
|
1638
1851
|
);
|
|
1639
1852
|
const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
|
|
1640
|
-
|
|
1853
|
+
this.assertWallet();
|
|
1854
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1641
1855
|
const hash = await this.context.walletClient.writeContract({
|
|
1642
1856
|
address: dataRefinerRegistryAddress,
|
|
1643
1857
|
abi: dataRefinerRegistryAbi,
|
|
1644
1858
|
functionName: "updateSchemaId",
|
|
1645
1859
|
args: [BigInt(params.refinerId), BigInt(params.newSchemaId)],
|
|
1646
1860
|
account,
|
|
1647
|
-
chain: this.context.walletClient.chain
|
|
1861
|
+
chain: this.context.walletClient.chain ?? null
|
|
1648
1862
|
});
|
|
1649
1863
|
await this.context.publicClient.waitForTransactionReceipt({ hash });
|
|
1650
1864
|
return {
|
|
@@ -1666,13 +1880,12 @@ class DataController {
|
|
|
1666
1880
|
* 3. Encrypts the user's encryption key with the provided public key
|
|
1667
1881
|
* 4. Registers the file with permissions
|
|
1668
1882
|
*
|
|
1669
|
-
* @param
|
|
1670
|
-
* @param permissions - Array of permissions to grant, each with account address and public key
|
|
1671
|
-
* @param filename - Optional filename for the upload
|
|
1672
|
-
* @param providerName - Optional storage provider to use
|
|
1883
|
+
* @param params - Upload parameters including data, permissions, and options
|
|
1673
1884
|
* @returns Promise resolving to upload result with file ID and storage URL
|
|
1674
1885
|
*/
|
|
1675
|
-
async uploadFileWithPermissions(
|
|
1886
|
+
async uploadFileWithPermissions(params) {
|
|
1887
|
+
this.assertWallet();
|
|
1888
|
+
const { data, permissions, filename, providerName } = params;
|
|
1676
1889
|
try {
|
|
1677
1890
|
const uploadResult = await this.uploadToStorage(
|
|
1678
1891
|
data,
|
|
@@ -1681,7 +1894,7 @@ class DataController {
|
|
|
1681
1894
|
// Always encrypt for uploadFileWithPermissions
|
|
1682
1895
|
providerName
|
|
1683
1896
|
);
|
|
1684
|
-
const userAddress =
|
|
1897
|
+
const userAddress = this.context.userAddress;
|
|
1685
1898
|
const userEncryptionKey = await generateEncryptionKey(
|
|
1686
1899
|
this.context.walletClient,
|
|
1687
1900
|
this.context.platform,
|
|
@@ -1718,9 +1931,18 @@ class DataController {
|
|
|
1718
1931
|
userAddress,
|
|
1719
1932
|
encryptedPermissions
|
|
1720
1933
|
);
|
|
1934
|
+
if (!this.context.waitForTransactionEvents) {
|
|
1935
|
+
throw new Error(
|
|
1936
|
+
"Cannot upload without relay: waitForTransactionEvents not configured"
|
|
1937
|
+
);
|
|
1938
|
+
}
|
|
1939
|
+
const eventResult = await this.context.waitForTransactionEvents(txResult);
|
|
1940
|
+
const fileAddedEvent = eventResult.expectedEvents.FileAdded;
|
|
1941
|
+
if (!fileAddedEvent) {
|
|
1942
|
+
throw new Error("FileAdded event not found in transaction");
|
|
1943
|
+
}
|
|
1721
1944
|
return {
|
|
1722
|
-
fileId:
|
|
1723
|
-
// Placeholder - user must wait for events to get actual fileId
|
|
1945
|
+
fileId: Number(fileAddedEvent.fileId),
|
|
1724
1946
|
url: uploadResult.url,
|
|
1725
1947
|
size: uploadResult.size,
|
|
1726
1948
|
transactionHash: txResult.hash
|
|
@@ -1763,6 +1985,7 @@ class DataController {
|
|
|
1763
1985
|
}
|
|
1764
1986
|
let finalBlob = blob;
|
|
1765
1987
|
if (encrypt) {
|
|
1988
|
+
this.assertWallet();
|
|
1766
1989
|
const encryptionKey = await generateEncryptionKey(
|
|
1767
1990
|
this.context.walletClient,
|
|
1768
1991
|
this.context.platform,
|
|
@@ -1784,7 +2007,7 @@ class DataController {
|
|
|
1784
2007
|
);
|
|
1785
2008
|
}
|
|
1786
2009
|
}
|
|
1787
|
-
const finalFilename = filename
|
|
2010
|
+
const finalFilename = filename ?? `upload-${Date.now()}.dat`;
|
|
1788
2011
|
const uploadResult = await this.context.storageManager.upload(
|
|
1789
2012
|
finalBlob,
|
|
1790
2013
|
finalFilename,
|
|
@@ -1809,21 +2032,29 @@ class DataController {
|
|
|
1809
2032
|
* For advanced users who need more control over transaction timing,
|
|
1810
2033
|
* use `submitFilePermission()` instead.
|
|
1811
2034
|
*
|
|
1812
|
-
* @param
|
|
1813
|
-
* @param
|
|
1814
|
-
* @param
|
|
2035
|
+
* @param params - Parameters for adding file permission
|
|
2036
|
+
* @param params.fileId - The ID of the file to grant permission for
|
|
2037
|
+
* @param params.account - The recipient's wallet address that will access the file
|
|
2038
|
+
* @param params.publicKey - The recipient's public key for encryption.
|
|
2039
|
+
* Obtain via `vana.server.getIdentity(account).publicKey`
|
|
1815
2040
|
* @returns Promise resolving to permission data from PermissionGranted event
|
|
1816
2041
|
* @throws {Error} "No addresses available in wallet client" - When wallet is not connected
|
|
1817
2042
|
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1818
2043
|
* @throws {Error} "Failed to add permission to file: {error}" - When transaction fails or user doesn't own file
|
|
1819
2044
|
* @example
|
|
1820
2045
|
* ```typescript
|
|
1821
|
-
* const result = await vana.data.addPermissionToFile(
|
|
2046
|
+
* const result = await vana.data.addPermissionToFile({
|
|
2047
|
+
* fileId: 123,
|
|
2048
|
+
* account: "0xRecipientAddress...",
|
|
2049
|
+
* publicKey: "0xRecipientPublicKey..."
|
|
2050
|
+
* });
|
|
1822
2051
|
* console.log(`Permission granted to ${result.account} for file ${result.fileId}`);
|
|
1823
2052
|
* console.log(`Transaction: ${result.transactionHash}`);
|
|
1824
2053
|
* ```
|
|
1825
2054
|
*/
|
|
1826
|
-
async addPermissionToFile(
|
|
2055
|
+
async addPermissionToFile(params) {
|
|
2056
|
+
this.assertWallet();
|
|
2057
|
+
const { fileId, account, publicKey } = params;
|
|
1827
2058
|
return await this.submitFilePermission(fileId, account, publicKey);
|
|
1828
2059
|
}
|
|
1829
2060
|
/**
|
|
@@ -1837,7 +2068,7 @@ class DataController {
|
|
|
1837
2068
|
* @param fileId - The ID of the file to grant permission for
|
|
1838
2069
|
* @param account - The recipient's wallet address that will access the file
|
|
1839
2070
|
* @param publicKey - The recipient's public key for encryption.
|
|
1840
|
-
* Obtain via `vana.server.getIdentity(account).
|
|
2071
|
+
* Obtain via `vana.server.getIdentity(account).publicKey`
|
|
1841
2072
|
* @returns Promise resolving to TransactionResult for tracking the transaction
|
|
1842
2073
|
* @throws {Error} When chain ID is not available
|
|
1843
2074
|
* @throws {Error} When encryption key generation fails
|
|
@@ -1855,6 +2086,7 @@ class DataController {
|
|
|
1855
2086
|
* ```
|
|
1856
2087
|
*/
|
|
1857
2088
|
async submitFilePermission(fileId, account, publicKey) {
|
|
2089
|
+
this.assertWallet();
|
|
1858
2090
|
try {
|
|
1859
2091
|
const userEncryptionKey = await generateEncryptionKey(
|
|
1860
2092
|
this.context.walletClient,
|
|
@@ -1866,20 +2098,21 @@ class DataController {
|
|
|
1866
2098
|
publicKey,
|
|
1867
2099
|
this.context.platform
|
|
1868
2100
|
);
|
|
1869
|
-
const chainId = this.context.
|
|
2101
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1870
2102
|
if (!chainId) {
|
|
1871
2103
|
throw new Error("Chain ID not available");
|
|
1872
2104
|
}
|
|
1873
2105
|
const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
|
|
1874
2106
|
const dataRegistryAbi = getAbi("DataRegistry");
|
|
1875
|
-
|
|
2107
|
+
this.assertWallet();
|
|
2108
|
+
const walletAccount = this.context.walletClient.account ?? this.context.userAddress;
|
|
1876
2109
|
const txHash = await this.context.walletClient.writeContract({
|
|
1877
2110
|
address: dataRegistryAddress,
|
|
1878
2111
|
abi: dataRegistryAbi,
|
|
1879
2112
|
functionName: "addFilePermission",
|
|
1880
2113
|
args: [BigInt(fileId), account, encryptedKey],
|
|
1881
2114
|
account: walletAccount,
|
|
1882
|
-
chain: this.context.walletClient.chain
|
|
2115
|
+
chain: this.context.walletClient.chain ?? null
|
|
1883
2116
|
});
|
|
1884
2117
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1885
2118
|
return tx({
|
|
@@ -1904,7 +2137,7 @@ class DataController {
|
|
|
1904
2137
|
*/
|
|
1905
2138
|
async getFilePermission(fileId, account) {
|
|
1906
2139
|
try {
|
|
1907
|
-
const chainId = this.context.
|
|
2140
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1908
2141
|
if (!chainId) {
|
|
1909
2142
|
throw new Error("Chain ID not available");
|
|
1910
2143
|
}
|
|
@@ -1913,7 +2146,7 @@ class DataController {
|
|
|
1913
2146
|
const dataRegistry = getContract({
|
|
1914
2147
|
address: dataRegistryAddress,
|
|
1915
2148
|
abi: dataRegistryAbi,
|
|
1916
|
-
client: this.context.
|
|
2149
|
+
client: this.context.publicClient
|
|
1917
2150
|
});
|
|
1918
2151
|
const encryptedKey = await dataRegistry.read.filePermissions([
|
|
1919
2152
|
BigInt(fileId),
|
|
@@ -1937,12 +2170,13 @@ class DataController {
|
|
|
1937
2170
|
*
|
|
1938
2171
|
* @param file - The file to decrypt
|
|
1939
2172
|
* @param privateKey - The private key to decrypt the user's encryption key
|
|
1940
|
-
* @param
|
|
2173
|
+
* @param options - Optional decryption configuration
|
|
2174
|
+
* @param options.account - The account address that has permission (defaults to current wallet account)
|
|
1941
2175
|
* @returns Promise resolving to the decrypted file data
|
|
1942
2176
|
*/
|
|
1943
|
-
async decryptFileWithPermission(file, privateKey,
|
|
2177
|
+
async decryptFileWithPermission(file, privateKey, options) {
|
|
1944
2178
|
try {
|
|
1945
|
-
const permissionAccount = account
|
|
2179
|
+
const permissionAccount = options?.account ?? this.context.userAddress;
|
|
1946
2180
|
const encryptedKey = await this.getFilePermission(
|
|
1947
2181
|
file.id,
|
|
1948
2182
|
permissionAccount
|
|
@@ -2006,11 +2240,8 @@ class DataController {
|
|
|
2006
2240
|
*/
|
|
2007
2241
|
async fetch(url) {
|
|
2008
2242
|
try {
|
|
2009
|
-
const {
|
|
2010
|
-
const response = await
|
|
2011
|
-
url,
|
|
2012
|
-
this.context.downloadRelayer
|
|
2013
|
-
);
|
|
2243
|
+
const { universalFetch } = await import("../utils/download");
|
|
2244
|
+
const response = await universalFetch(url, this.context.downloadRelayer);
|
|
2014
2245
|
if (!response.ok) {
|
|
2015
2246
|
throw new Error(
|
|
2016
2247
|
`HTTP error! status: ${response.status} ${response.statusText}`
|
|
@@ -2075,7 +2306,7 @@ class DataController {
|
|
|
2075
2306
|
"https://dweb.link/ipfs/",
|
|
2076
2307
|
"https://ipfs.io/ipfs/"
|
|
2077
2308
|
];
|
|
2078
|
-
const gateways = options?.gateways
|
|
2309
|
+
const gateways = options?.gateways ?? this.context.ipfsGateways ?? defaultGateways;
|
|
2079
2310
|
const { extractIpfsHash } = await import("../utils/ipfs");
|
|
2080
2311
|
const cid = extractIpfsHash(url);
|
|
2081
2312
|
if (!cid) {
|
|
@@ -2204,7 +2435,7 @@ class DataController {
|
|
|
2204
2435
|
* ```
|
|
2205
2436
|
*/
|
|
2206
2437
|
validateDataAgainstSchema(data, schema) {
|
|
2207
|
-
|
|
2438
|
+
validateDataAgainstSchema(data, schema);
|
|
2208
2439
|
}
|
|
2209
2440
|
/**
|
|
2210
2441
|
* Fetches and validates a data schema from a URL, then returns the parsed data schema.
|