@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
|
@@ -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,29 @@ 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
|
-
|
|
79
|
-
|
|
86
|
+
if (error instanceof Error) {
|
|
87
|
+
const errorDetails = error.errors;
|
|
88
|
+
if (errorDetails && Array.isArray(errorDetails)) {
|
|
89
|
+
validationErrors = errorDetails;
|
|
90
|
+
} else {
|
|
91
|
+
validationErrors = [error.message];
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
validationErrors = ["Schema validation failed"];
|
|
95
|
+
}
|
|
80
96
|
}
|
|
81
97
|
}
|
|
82
98
|
const uploadResult = await this.uploadToStorage(
|
|
@@ -85,9 +101,10 @@ class DataController {
|
|
|
85
101
|
encrypt,
|
|
86
102
|
providerName
|
|
87
103
|
);
|
|
88
|
-
const userAddress = owner
|
|
104
|
+
const userAddress = owner ?? this.context.userAddress;
|
|
89
105
|
let encryptedPermissions = [];
|
|
90
106
|
if (permissions.length > 0 && encrypt) {
|
|
107
|
+
this.assertWallet();
|
|
91
108
|
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
92
109
|
this.context.walletClient,
|
|
93
110
|
this.context.platform,
|
|
@@ -114,7 +131,7 @@ class DataController {
|
|
|
114
131
|
url: uploadResult.url,
|
|
115
132
|
userAddress,
|
|
116
133
|
permissions: encryptedPermissions,
|
|
117
|
-
schemaId: schemaId
|
|
134
|
+
schemaId: schemaId ?? 0,
|
|
118
135
|
ownerAddress: owner
|
|
119
136
|
}
|
|
120
137
|
);
|
|
@@ -130,15 +147,24 @@ class DataController {
|
|
|
130
147
|
userAddress
|
|
131
148
|
);
|
|
132
149
|
} else {
|
|
133
|
-
const txResult = await this.
|
|
150
|
+
const txResult = await this.addFileWithEncryptedPermissionsAndSchema(
|
|
134
151
|
uploadResult.url,
|
|
135
152
|
userAddress,
|
|
136
153
|
encryptedPermissions,
|
|
137
|
-
schemaId
|
|
154
|
+
schemaId ?? 0
|
|
138
155
|
);
|
|
156
|
+
if (!this.context.waitForTransactionEvents) {
|
|
157
|
+
throw new Error(
|
|
158
|
+
"Cannot upload without relay: waitForTransactionEvents not configured"
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
const eventResult = await this.context.waitForTransactionEvents(txResult);
|
|
162
|
+
const fileAddedEvent = eventResult.expectedEvents.FileAdded;
|
|
163
|
+
if (!fileAddedEvent) {
|
|
164
|
+
throw new Error("FileAdded event not found in transaction");
|
|
165
|
+
}
|
|
139
166
|
result = {
|
|
140
|
-
fileId:
|
|
141
|
-
// Placeholder - actual fileId available after waiting for events
|
|
167
|
+
fileId: Number(fileAddedEvent.fileId),
|
|
142
168
|
transactionHash: txResult.hash
|
|
143
169
|
};
|
|
144
170
|
}
|
|
@@ -156,6 +182,83 @@ class DataController {
|
|
|
156
182
|
);
|
|
157
183
|
}
|
|
158
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Encrypts data using wallet-derived encryption.
|
|
187
|
+
*
|
|
188
|
+
* @remarks
|
|
189
|
+
* This method provides secure, wallet-based encryption for data before uploading
|
|
190
|
+
* to the Vana network. It's the counterpart to decryptFile for preparing data
|
|
191
|
+
* for secure storage.
|
|
192
|
+
*
|
|
193
|
+
* The method automatically:
|
|
194
|
+
* - Generates an encryption key from the user's wallet signature
|
|
195
|
+
* - Converts the input data to a Blob if necessary
|
|
196
|
+
* - Encrypts the data using the generated key
|
|
197
|
+
* - Returns both the encrypted data and the encryption key
|
|
198
|
+
*
|
|
199
|
+
* The encryption key returned can be stored and later used for decryption,
|
|
200
|
+
* or shared with others to grant them decryption access.
|
|
201
|
+
*
|
|
202
|
+
* @param data - The data to encrypt (Blob, string, or object)
|
|
203
|
+
* @param options - Optional encryption configuration
|
|
204
|
+
* @returns Promise resolving to encrypted data and the encryption key used
|
|
205
|
+
* @throws {Error} When wallet is not connected or encryption fails
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* // Encrypt a string
|
|
209
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
210
|
+
* "My secret data"
|
|
211
|
+
* );
|
|
212
|
+
*
|
|
213
|
+
* // Encrypt JSON with custom MIME type
|
|
214
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
215
|
+
* { name: "Alice", age: 30 },
|
|
216
|
+
* { mimeType: "application/json" }
|
|
217
|
+
* );
|
|
218
|
+
*
|
|
219
|
+
* // With custom encryption seed
|
|
220
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
221
|
+
* "Secret message",
|
|
222
|
+
* { seed: "My custom encryption seed" }
|
|
223
|
+
* );
|
|
224
|
+
*
|
|
225
|
+
* // Upload the encrypted data
|
|
226
|
+
* const result = await vana.data.uploadToStorage(encryptedData);
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
async encryptFile(data, options) {
|
|
230
|
+
this.assertWallet();
|
|
231
|
+
try {
|
|
232
|
+
const encryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
233
|
+
this.context.walletClient,
|
|
234
|
+
this.context.platform,
|
|
235
|
+
options?.seed ?? import_encryption.DEFAULT_ENCRYPTION_SEED
|
|
236
|
+
);
|
|
237
|
+
let blob;
|
|
238
|
+
if (data instanceof Blob) {
|
|
239
|
+
blob = data;
|
|
240
|
+
} else if (typeof data === "string") {
|
|
241
|
+
blob = new Blob([data], { type: options?.mimeType ?? "text/plain" });
|
|
242
|
+
} else {
|
|
243
|
+
blob = new Blob([JSON.stringify(data)], {
|
|
244
|
+
type: options?.mimeType ?? "application/json"
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
const encryptedData = await (0, import_encryption.encryptBlobWithSignedKey)(
|
|
248
|
+
blob,
|
|
249
|
+
encryptionKey,
|
|
250
|
+
this.context.platform
|
|
251
|
+
);
|
|
252
|
+
return {
|
|
253
|
+
encryptedData,
|
|
254
|
+
encryptionKey
|
|
255
|
+
};
|
|
256
|
+
} catch (error) {
|
|
257
|
+
throw new Error(
|
|
258
|
+
`Failed to encrypt file: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
159
262
|
/**
|
|
160
263
|
* Decrypts a file owned by the user using their wallet signature.
|
|
161
264
|
*
|
|
@@ -211,12 +314,14 @@ class DataController {
|
|
|
211
314
|
* fs.writeFileSync('decrypted-file.txt', Buffer.from(buffer));
|
|
212
315
|
* ```
|
|
213
316
|
*/
|
|
214
|
-
async decryptFile(file,
|
|
317
|
+
async decryptFile(file, options) {
|
|
318
|
+
this.assertWallet();
|
|
215
319
|
try {
|
|
320
|
+
this.assertWallet();
|
|
216
321
|
const encryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
217
322
|
this.context.walletClient,
|
|
218
323
|
this.context.platform,
|
|
219
|
-
|
|
324
|
+
options?.seed ?? import_encryption.DEFAULT_ENCRYPTION_SEED
|
|
220
325
|
);
|
|
221
326
|
let encryptedBlob;
|
|
222
327
|
try {
|
|
@@ -333,7 +438,7 @@ class DataController {
|
|
|
333
438
|
*/
|
|
334
439
|
async getUserFiles(params) {
|
|
335
440
|
const { owner, subgraphUrl } = params;
|
|
336
|
-
const endpoint = subgraphUrl
|
|
441
|
+
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
337
442
|
if (!endpoint) {
|
|
338
443
|
throw new Error(
|
|
339
444
|
"subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor."
|
|
@@ -365,7 +470,7 @@ class DataController {
|
|
|
365
470
|
);
|
|
366
471
|
}
|
|
367
472
|
const user = result.data?.user;
|
|
368
|
-
if (!user
|
|
473
|
+
if (!user?.files?.length) {
|
|
369
474
|
console.warn("No files found for user:", owner);
|
|
370
475
|
return [];
|
|
371
476
|
}
|
|
@@ -387,7 +492,7 @@ class DataController {
|
|
|
387
492
|
}
|
|
388
493
|
});
|
|
389
494
|
const userFiles = Array.from(fileMap.values()).sort(
|
|
390
|
-
(a, b) => Number((b.addedAtTimestamp
|
|
495
|
+
(a, b) => Number((b.addedAtTimestamp ?? 0n) - (a.addedAtTimestamp ?? 0n))
|
|
391
496
|
);
|
|
392
497
|
if (userFiles.length > 0) {
|
|
393
498
|
try {
|
|
@@ -458,10 +563,11 @@ class DataController {
|
|
|
458
563
|
if (proof.dlp?.id) {
|
|
459
564
|
const fileId = parseInt(proof.fileId);
|
|
460
565
|
const dlpId = parseInt(proof.dlp.id);
|
|
461
|
-
|
|
462
|
-
|
|
566
|
+
let dlpIds = proofMap.get(fileId);
|
|
567
|
+
if (!dlpIds) {
|
|
568
|
+
dlpIds = [];
|
|
569
|
+
proofMap.set(fileId, dlpIds);
|
|
463
570
|
}
|
|
464
|
-
const dlpIds = proofMap.get(fileId);
|
|
465
571
|
if (!dlpIds.includes(dlpId)) {
|
|
466
572
|
dlpIds.push(dlpId);
|
|
467
573
|
}
|
|
@@ -479,7 +585,7 @@ class DataController {
|
|
|
479
585
|
* @returns Map of file IDs to their associated DLP IDs
|
|
480
586
|
*/
|
|
481
587
|
async _fetchProofsFromChain(fileIds) {
|
|
482
|
-
const chainId = this.context.
|
|
588
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
483
589
|
if (!chainId) {
|
|
484
590
|
throw new Error("Chain ID not available");
|
|
485
591
|
}
|
|
@@ -536,7 +642,7 @@ class DataController {
|
|
|
536
642
|
* ```
|
|
537
643
|
*/
|
|
538
644
|
async getDLP(dlpId, options = {}) {
|
|
539
|
-
const subgraphUrl = options.subgraphUrl
|
|
645
|
+
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
540
646
|
if (subgraphUrl) {
|
|
541
647
|
try {
|
|
542
648
|
const response = await fetch(subgraphUrl, {
|
|
@@ -567,18 +673,18 @@ class DataController {
|
|
|
567
673
|
}
|
|
568
674
|
return {
|
|
569
675
|
id: parseInt(result.data.dlp.id),
|
|
570
|
-
name: result.data.dlp.name
|
|
571
|
-
metadata: result.data.dlp.metadata
|
|
676
|
+
name: result.data.dlp.name ?? "",
|
|
677
|
+
metadata: result.data.dlp.metadata ?? void 0,
|
|
572
678
|
status: result.data.dlp.status ? parseInt(result.data.dlp.status) : void 0,
|
|
573
|
-
address: result.data.dlp.address,
|
|
574
|
-
owner: result.data.dlp.owner
|
|
679
|
+
address: result.data.dlp.address ? result.data.dlp.address : void 0,
|
|
680
|
+
owner: result.data.dlp.owner ? result.data.dlp.owner : void 0
|
|
575
681
|
};
|
|
576
682
|
} catch (error) {
|
|
577
683
|
console.debug("Subgraph query failed, falling back to chain:", error);
|
|
578
684
|
}
|
|
579
685
|
}
|
|
580
686
|
try {
|
|
581
|
-
const chainId = this.context.
|
|
687
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
582
688
|
if (!chainId) {
|
|
583
689
|
throw new Error("Chain ID not available");
|
|
584
690
|
}
|
|
@@ -590,7 +696,7 @@ class DataController {
|
|
|
590
696
|
functionName: "dlps",
|
|
591
697
|
args: [BigInt(dlpId)]
|
|
592
698
|
});
|
|
593
|
-
if (!dlpData
|
|
699
|
+
if (!dlpData?.name) {
|
|
594
700
|
throw new Error(`DLP not found: ${dlpId}`);
|
|
595
701
|
}
|
|
596
702
|
return {
|
|
@@ -632,7 +738,7 @@ class DataController {
|
|
|
632
738
|
*/
|
|
633
739
|
async listDLPs(options = {}) {
|
|
634
740
|
const { limit = 100, offset = 0 } = options;
|
|
635
|
-
const subgraphUrl = options.subgraphUrl
|
|
741
|
+
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
636
742
|
if (subgraphUrl) {
|
|
637
743
|
try {
|
|
638
744
|
const query = `
|
|
@@ -671,21 +777,21 @@ class DataController {
|
|
|
671
777
|
`Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
672
778
|
);
|
|
673
779
|
}
|
|
674
|
-
const dlps = result.data?.dlps
|
|
780
|
+
const dlps = result.data?.dlps ?? [];
|
|
675
781
|
return dlps.map((dlp) => ({
|
|
676
782
|
id: parseInt(dlp.id),
|
|
677
|
-
name: dlp.name
|
|
783
|
+
name: dlp.name ?? "",
|
|
678
784
|
metadata: dlp.metadata,
|
|
679
785
|
status: dlp.status ? parseInt(dlp.status) : void 0,
|
|
680
|
-
address: dlp.address,
|
|
681
|
-
owner: dlp.owner
|
|
786
|
+
address: dlp.address ? dlp.address : void 0,
|
|
787
|
+
owner: dlp.owner ? dlp.owner : void 0
|
|
682
788
|
}));
|
|
683
789
|
} catch (error) {
|
|
684
790
|
console.debug("Subgraph query failed, falling back to chain:", error);
|
|
685
791
|
}
|
|
686
792
|
}
|
|
687
793
|
try {
|
|
688
|
-
const chainId = this.context.
|
|
794
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
689
795
|
if (!chainId) {
|
|
690
796
|
throw new Error("Chain ID not available");
|
|
691
797
|
}
|
|
@@ -757,7 +863,7 @@ class DataController {
|
|
|
757
863
|
*/
|
|
758
864
|
async getUserPermissions(params) {
|
|
759
865
|
const { user, subgraphUrl } = params;
|
|
760
|
-
const endpoint = subgraphUrl
|
|
866
|
+
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
761
867
|
if (endpoint) {
|
|
762
868
|
try {
|
|
763
869
|
const permissions = await this._getUserPermissionsViaSubgraph({
|
|
@@ -806,7 +912,7 @@ class DataController {
|
|
|
806
912
|
);
|
|
807
913
|
}
|
|
808
914
|
const userData = result.data?.user;
|
|
809
|
-
if (!userData
|
|
915
|
+
if (!userData?.permissions?.length) {
|
|
810
916
|
return [];
|
|
811
917
|
}
|
|
812
918
|
return userData.permissions.map((permission) => ({
|
|
@@ -834,7 +940,7 @@ class DataController {
|
|
|
834
940
|
async _getUserPermissionsViaRpc(params) {
|
|
835
941
|
const { user } = params;
|
|
836
942
|
try {
|
|
837
|
-
const chainId = this.context.
|
|
943
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
838
944
|
if (!chainId) {
|
|
839
945
|
throw new Error("Chain ID not available");
|
|
840
946
|
}
|
|
@@ -953,7 +1059,7 @@ class DataController {
|
|
|
953
1059
|
*/
|
|
954
1060
|
async getUserTrustedServers(params) {
|
|
955
1061
|
const { user, limit = 50, offset = 0 } = params;
|
|
956
|
-
const subgraphUrl = params.subgraphUrl
|
|
1062
|
+
const subgraphUrl = params.subgraphUrl ?? this.context.subgraphUrl;
|
|
957
1063
|
if (subgraphUrl) {
|
|
958
1064
|
try {
|
|
959
1065
|
const servers = await this._getUserTrustedServersViaSubgraph({
|
|
@@ -1016,7 +1122,7 @@ class DataController {
|
|
|
1016
1122
|
if (!result.data?.user) {
|
|
1017
1123
|
return [];
|
|
1018
1124
|
}
|
|
1019
|
-
return (result.data.user.serverTrusts
|
|
1125
|
+
return (result.data.user.serverTrusts ?? []).filter((trust) => !trust.untrustedAtBlock).map((trust) => ({
|
|
1020
1126
|
id: trust.server.id,
|
|
1021
1127
|
serverAddress: trust.server.serverAddress,
|
|
1022
1128
|
serverUrl: trust.server.url,
|
|
@@ -1042,7 +1148,7 @@ class DataController {
|
|
|
1042
1148
|
async _getUserTrustedServersViaRpc(params) {
|
|
1043
1149
|
const { user, limit, offset } = params;
|
|
1044
1150
|
try {
|
|
1045
|
-
const chainId = this.context.
|
|
1151
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1046
1152
|
if (!chainId) {
|
|
1047
1153
|
throw new Error("Chain ID not available");
|
|
1048
1154
|
}
|
|
@@ -1142,7 +1248,7 @@ class DataController {
|
|
|
1142
1248
|
*/
|
|
1143
1249
|
async getTotalFilesCount() {
|
|
1144
1250
|
try {
|
|
1145
|
-
const chainId = this.context.
|
|
1251
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1146
1252
|
if (!chainId) {
|
|
1147
1253
|
throw new Error("Chain ID not available");
|
|
1148
1254
|
}
|
|
@@ -1151,7 +1257,7 @@ class DataController {
|
|
|
1151
1257
|
const dataRegistry = (0, import_viem.getContract)({
|
|
1152
1258
|
address: dataRegistryAddress,
|
|
1153
1259
|
abi: dataRegistryAbi,
|
|
1154
|
-
client: this.context.
|
|
1260
|
+
client: this.context.publicClient
|
|
1155
1261
|
});
|
|
1156
1262
|
const count = await dataRegistry.read.filesCount();
|
|
1157
1263
|
return Number(count);
|
|
@@ -1193,7 +1299,7 @@ class DataController {
|
|
|
1193
1299
|
*/
|
|
1194
1300
|
async getFileById(fileId) {
|
|
1195
1301
|
try {
|
|
1196
|
-
const chainId = this.context.
|
|
1302
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1197
1303
|
if (!chainId) {
|
|
1198
1304
|
throw new Error("Chain ID not available");
|
|
1199
1305
|
}
|
|
@@ -1202,7 +1308,7 @@ class DataController {
|
|
|
1202
1308
|
const dataRegistry = (0, import_viem.getContract)({
|
|
1203
1309
|
address: dataRegistryAddress,
|
|
1204
1310
|
abi: dataRegistryAbi,
|
|
1205
|
-
client: this.context.
|
|
1311
|
+
client: this.context.publicClient
|
|
1206
1312
|
});
|
|
1207
1313
|
const fileDetails = await dataRegistry.read.files([BigInt(fileId)]);
|
|
1208
1314
|
if (!fileDetails) {
|
|
@@ -1261,14 +1367,16 @@ class DataController {
|
|
|
1261
1367
|
* ```
|
|
1262
1368
|
*/
|
|
1263
1369
|
async registerFileWithSchema(url, schemaId) {
|
|
1370
|
+
this.assertWallet();
|
|
1264
1371
|
try {
|
|
1265
|
-
const chainId = this.context.
|
|
1372
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1266
1373
|
if (!chainId) {
|
|
1267
1374
|
throw new Error("Chain ID not available");
|
|
1268
1375
|
}
|
|
1376
|
+
this.assertWallet();
|
|
1269
1377
|
const dataRegistryAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
1270
1378
|
const dataRegistryAbi = (0, import_abi.getAbi)("DataRegistry");
|
|
1271
|
-
const account = this.context.walletClient.account
|
|
1379
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1272
1380
|
const from = typeof account === "string" ? account : account.address;
|
|
1273
1381
|
const hash = await this.context.walletClient.writeContract({
|
|
1274
1382
|
address: dataRegistryAddress,
|
|
@@ -1276,7 +1384,7 @@ class DataController {
|
|
|
1276
1384
|
functionName: "addFileWithSchema",
|
|
1277
1385
|
args: [url, BigInt(schemaId)],
|
|
1278
1386
|
account,
|
|
1279
|
-
chain: this.context.walletClient.chain
|
|
1387
|
+
chain: this.context.walletClient.chain ?? null
|
|
1280
1388
|
});
|
|
1281
1389
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1282
1390
|
return tx({
|
|
@@ -1298,13 +1406,6 @@ class DataController {
|
|
|
1298
1406
|
* @returns Promise resolving to the user's wallet address
|
|
1299
1407
|
* @throws {Error} When no addresses are available in wallet client
|
|
1300
1408
|
*/
|
|
1301
|
-
async getUserAddress() {
|
|
1302
|
-
const addresses = await this.context.walletClient.getAddresses();
|
|
1303
|
-
if (addresses.length === 0) {
|
|
1304
|
-
throw new Error("No addresses available in wallet client");
|
|
1305
|
-
}
|
|
1306
|
-
return addresses[0];
|
|
1307
|
-
}
|
|
1308
1409
|
/**
|
|
1309
1410
|
* Adds a file with permissions to the DataRegistry contract.
|
|
1310
1411
|
*
|
|
@@ -1322,14 +1423,16 @@ class DataController {
|
|
|
1322
1423
|
* by both direct transactions and relayer services.
|
|
1323
1424
|
*/
|
|
1324
1425
|
async addFileWithPermissions(url, ownerAddress, permissions = []) {
|
|
1426
|
+
this.assertWallet();
|
|
1325
1427
|
try {
|
|
1326
|
-
const chainId = this.context.
|
|
1428
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1327
1429
|
if (!chainId) {
|
|
1328
1430
|
throw new Error("Chain ID not available");
|
|
1329
1431
|
}
|
|
1432
|
+
this.assertWallet();
|
|
1330
1433
|
const dataRegistryAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
1331
1434
|
const dataRegistryAbi = (0, import_abi.getAbi)("DataRegistry");
|
|
1332
|
-
const account = this.context.walletClient.account
|
|
1435
|
+
const account = this.context.walletClient.account ?? ownerAddress;
|
|
1333
1436
|
const from = typeof account === "string" ? account : account.address;
|
|
1334
1437
|
const hash = await this.context.walletClient.writeContract({
|
|
1335
1438
|
address: dataRegistryAddress,
|
|
@@ -1337,7 +1440,7 @@ class DataController {
|
|
|
1337
1440
|
functionName: "addFileWithPermissions",
|
|
1338
1441
|
args: [url, ownerAddress, permissions],
|
|
1339
1442
|
account,
|
|
1340
|
-
chain: this.context.walletClient.chain
|
|
1443
|
+
chain: this.context.walletClient.chain ?? null
|
|
1341
1444
|
});
|
|
1342
1445
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1343
1446
|
return tx({
|
|
@@ -1357,25 +1460,132 @@ class DataController {
|
|
|
1357
1460
|
* Adds a file to the registry with permissions and schema.
|
|
1358
1461
|
* This combines the functionality of addFileWithPermissions and schema validation.
|
|
1359
1462
|
*
|
|
1463
|
+
* @remarks
|
|
1464
|
+
* This method automatically encrypts permissions when a publicKey is provided.
|
|
1465
|
+
* It generates the user's encryption key and encrypts it with each recipient's
|
|
1466
|
+
* public key before registering on the blockchain.
|
|
1467
|
+
*
|
|
1360
1468
|
* @param url - The URL of the file to register
|
|
1361
1469
|
* @param ownerAddress - The address of the file owner
|
|
1362
|
-
* @param permissions - Array of permissions to grant
|
|
1470
|
+
* @param permissions - Array of permissions to grant, each with account and publicKey properties
|
|
1363
1471
|
* @param schemaId - The schema ID to associate with the file (0 for no schema)
|
|
1364
|
-
* @returns Promise resolving to
|
|
1365
|
-
* @throws {Error} When chain
|
|
1366
|
-
* @throws {
|
|
1367
|
-
* @throws {Error} When
|
|
1368
|
-
* @throws {Error}
|
|
1472
|
+
* @returns Promise resolving to TransactionResult with fileId and transactionHash
|
|
1473
|
+
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1474
|
+
* @throws {Error} "Failed to generate encryption key" - When encryption key generation fails
|
|
1475
|
+
* @throws {Error} "Permission for {account} must include 'publicKey'" - When publicKey is missing
|
|
1476
|
+
* @throws {Error} "Failed to add file with permissions and schema: {error}" - When transaction fails
|
|
1477
|
+
* @example
|
|
1478
|
+
* ```typescript
|
|
1479
|
+
* // Get server's public key
|
|
1480
|
+
* const serverIdentity = await vana.server.getIdentity({
|
|
1481
|
+
* userAddress: "0x..."
|
|
1482
|
+
* });
|
|
1483
|
+
*
|
|
1484
|
+
* // Add file with permissions and schema
|
|
1485
|
+
* const result = await vana.data.addFileWithPermissionsAndSchema(
|
|
1486
|
+
* "ipfs://QmXxx...",
|
|
1487
|
+
* ownerAddress,
|
|
1488
|
+
* [{
|
|
1489
|
+
* account: serverIdentity.address,
|
|
1490
|
+
* publicKey: serverIdentity.publicKey
|
|
1491
|
+
* }],
|
|
1492
|
+
* schemaId
|
|
1493
|
+
* );
|
|
1494
|
+
*
|
|
1495
|
+
* console.log(`File ${result.fileId} registered in tx ${result.hash}`);
|
|
1496
|
+
* ```
|
|
1369
1497
|
*/
|
|
1370
1498
|
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1499
|
+
this.assertWallet();
|
|
1371
1500
|
try {
|
|
1372
|
-
|
|
1501
|
+
let encryptedPermissions = [];
|
|
1502
|
+
if (permissions.length > 0) {
|
|
1503
|
+
this.assertWallet();
|
|
1504
|
+
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
1505
|
+
this.context.walletClient,
|
|
1506
|
+
this.context.platform,
|
|
1507
|
+
import_encryption.DEFAULT_ENCRYPTION_SEED
|
|
1508
|
+
);
|
|
1509
|
+
encryptedPermissions = await Promise.all(
|
|
1510
|
+
permissions.map(async (permission) => {
|
|
1511
|
+
if (!permission.publicKey) {
|
|
1512
|
+
throw new Error(
|
|
1513
|
+
`Permission for ${permission.account} must include 'publicKey'`
|
|
1514
|
+
);
|
|
1515
|
+
}
|
|
1516
|
+
const encryptedKey = await (0, import_encryption.encryptWithWalletPublicKey)(
|
|
1517
|
+
userEncryptionKey,
|
|
1518
|
+
permission.publicKey,
|
|
1519
|
+
this.context.platform
|
|
1520
|
+
);
|
|
1521
|
+
return {
|
|
1522
|
+
account: permission.account,
|
|
1523
|
+
key: encryptedKey
|
|
1524
|
+
};
|
|
1525
|
+
})
|
|
1526
|
+
);
|
|
1527
|
+
}
|
|
1528
|
+
return await this.addFileWithEncryptedPermissionsAndSchema(
|
|
1529
|
+
url,
|
|
1530
|
+
ownerAddress,
|
|
1531
|
+
encryptedPermissions,
|
|
1532
|
+
schemaId
|
|
1533
|
+
);
|
|
1534
|
+
} catch (error) {
|
|
1535
|
+
console.error("Failed to add file with permissions and schema:", error);
|
|
1536
|
+
throw new Error(
|
|
1537
|
+
`Failed to add file with permissions and schema: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
1538
|
+
);
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
/**
|
|
1542
|
+
* Adds a file with pre-encrypted permissions and schema to the DataRegistry.
|
|
1543
|
+
*
|
|
1544
|
+
* @remarks
|
|
1545
|
+
* This method is designed for relay services and advanced use cases where permissions
|
|
1546
|
+
* have already been encrypted client-side. Unlike `addFileWithPermissionsAndSchema()`,
|
|
1547
|
+
* this method expects permissions in the encrypted format with a 'key' field instead
|
|
1548
|
+
* of 'publicKey'.
|
|
1549
|
+
*
|
|
1550
|
+
* This is typically used by relay endpoints that receive pre-encrypted data from
|
|
1551
|
+
* the client SDK's `upload()` method, avoiding double encryption.
|
|
1552
|
+
*
|
|
1553
|
+
* @param url - The storage URL of the file (e.g., IPFS URL)
|
|
1554
|
+
* @param ownerAddress - The address that will own this file
|
|
1555
|
+
* @param permissions - Array of pre-encrypted permissions with 'account' and 'key' fields
|
|
1556
|
+
* @param schemaId - Optional schema ID for data validation (defaults to 0)
|
|
1557
|
+
* @returns Promise resolving to transaction result with hash and contract details
|
|
1558
|
+
* @throws {Error} When chain ID is not available
|
|
1559
|
+
* @throws {Error} When wallet is not connected
|
|
1560
|
+
* @throws {Error} When transaction fails
|
|
1561
|
+
* @example
|
|
1562
|
+
* ```typescript
|
|
1563
|
+
* // In a relay endpoint that receives pre-encrypted permissions
|
|
1564
|
+
* const result = await vana.data.addFileWithEncryptedPermissionsAndSchema(
|
|
1565
|
+
* "ipfs://QmXxx...",
|
|
1566
|
+
* ownerAddress,
|
|
1567
|
+
* [
|
|
1568
|
+
* {
|
|
1569
|
+
* account: "0xServerAddress...",
|
|
1570
|
+
* key: "encrypted_key_string" // Already encrypted by client
|
|
1571
|
+
* }
|
|
1572
|
+
* ],
|
|
1573
|
+
* schemaId
|
|
1574
|
+
* );
|
|
1575
|
+
*
|
|
1576
|
+
* console.log(`File registered in tx ${result.hash}`);
|
|
1577
|
+
* ```
|
|
1578
|
+
*/
|
|
1579
|
+
async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1580
|
+
try {
|
|
1581
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1373
1582
|
if (!chainId) {
|
|
1374
1583
|
throw new Error("Chain ID not available");
|
|
1375
1584
|
}
|
|
1585
|
+
this.assertWallet();
|
|
1376
1586
|
const dataRegistryAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
1377
1587
|
const dataRegistryAbi = (0, import_abi.getAbi)("DataRegistry");
|
|
1378
|
-
const account = this.context.walletClient.account
|
|
1588
|
+
const account = this.context.walletClient.account ?? ownerAddress;
|
|
1379
1589
|
const from = typeof account === "string" ? account : account.address;
|
|
1380
1590
|
const hash = await this.context.walletClient.writeContract({
|
|
1381
1591
|
address: dataRegistryAddress,
|
|
@@ -1383,7 +1593,7 @@ class DataController {
|
|
|
1383
1593
|
functionName: "addFileWithPermissionsAndSchema",
|
|
1384
1594
|
args: [url, ownerAddress, permissions, BigInt(schemaId)],
|
|
1385
1595
|
account,
|
|
1386
|
-
chain: this.context.walletClient.chain
|
|
1596
|
+
chain: this.context.walletClient.chain ?? null
|
|
1387
1597
|
});
|
|
1388
1598
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1389
1599
|
return tx({
|
|
@@ -1428,8 +1638,9 @@ class DataController {
|
|
|
1428
1638
|
* ```
|
|
1429
1639
|
*/
|
|
1430
1640
|
async addRefiner(params) {
|
|
1641
|
+
this.assertWallet();
|
|
1431
1642
|
try {
|
|
1432
|
-
const chainId = this.context.
|
|
1643
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1433
1644
|
if (!chainId) {
|
|
1434
1645
|
throw new Error("Chain ID not available");
|
|
1435
1646
|
}
|
|
@@ -1438,7 +1649,8 @@ class DataController {
|
|
|
1438
1649
|
"DataRefinerRegistry"
|
|
1439
1650
|
);
|
|
1440
1651
|
const dataRefinerRegistryAbi = (0, import_abi.getAbi)("DataRefinerRegistry");
|
|
1441
|
-
|
|
1652
|
+
this.assertWallet();
|
|
1653
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1442
1654
|
const from = typeof account === "string" ? account : account.address;
|
|
1443
1655
|
const hash = await this.context.walletClient.writeContract({
|
|
1444
1656
|
address: dataRefinerRegistryAddress,
|
|
@@ -1451,7 +1663,7 @@ class DataController {
|
|
|
1451
1663
|
params.refinementInstructionUrl
|
|
1452
1664
|
],
|
|
1453
1665
|
account,
|
|
1454
|
-
chain: this.context.walletClient.chain
|
|
1666
|
+
chain: this.context.walletClient.chain ?? null
|
|
1455
1667
|
});
|
|
1456
1668
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1457
1669
|
const txResult = tx({
|
|
@@ -1504,7 +1716,7 @@ class DataController {
|
|
|
1504
1716
|
*/
|
|
1505
1717
|
async getRefiner(refinerId) {
|
|
1506
1718
|
try {
|
|
1507
|
-
const chainId = this.context.
|
|
1719
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1508
1720
|
if (!chainId) {
|
|
1509
1721
|
throw new Error("Chain ID not available");
|
|
1510
1722
|
}
|
|
@@ -1516,7 +1728,7 @@ class DataController {
|
|
|
1516
1728
|
const dataRefinerRegistry = (0, import_viem.getContract)({
|
|
1517
1729
|
address: dataRefinerRegistryAddress,
|
|
1518
1730
|
abi: dataRefinerRegistryAbi,
|
|
1519
|
-
client: this.context.
|
|
1731
|
+
client: this.context.publicClient
|
|
1520
1732
|
});
|
|
1521
1733
|
const refinerData = await dataRefinerRegistry.read.refiners([
|
|
1522
1734
|
BigInt(refinerId)
|
|
@@ -1560,7 +1772,7 @@ class DataController {
|
|
|
1560
1772
|
*/
|
|
1561
1773
|
async isValidSchemaId(schemaId) {
|
|
1562
1774
|
try {
|
|
1563
|
-
const chainId = this.context.
|
|
1775
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1564
1776
|
if (!chainId) {
|
|
1565
1777
|
throw new Error("Chain ID not available");
|
|
1566
1778
|
}
|
|
@@ -1572,7 +1784,7 @@ class DataController {
|
|
|
1572
1784
|
const dataRefinerRegistry = (0, import_viem.getContract)({
|
|
1573
1785
|
address: dataRefinerRegistryAddress,
|
|
1574
1786
|
abi: dataRefinerRegistryAbi,
|
|
1575
|
-
client: this.context.
|
|
1787
|
+
client: this.context.publicClient
|
|
1576
1788
|
});
|
|
1577
1789
|
const isValid = await dataRefinerRegistry.read.isValidSchemaId([
|
|
1578
1790
|
BigInt(schemaId)
|
|
@@ -1599,7 +1811,7 @@ class DataController {
|
|
|
1599
1811
|
*/
|
|
1600
1812
|
async getRefinersCount() {
|
|
1601
1813
|
try {
|
|
1602
|
-
const chainId = this.context.
|
|
1814
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1603
1815
|
if (!chainId) {
|
|
1604
1816
|
throw new Error("Chain ID not available");
|
|
1605
1817
|
}
|
|
@@ -1611,7 +1823,7 @@ class DataController {
|
|
|
1611
1823
|
const dataRefinerRegistry = (0, import_viem.getContract)({
|
|
1612
1824
|
address: dataRefinerRegistryAddress,
|
|
1613
1825
|
abi: dataRefinerRegistryAbi,
|
|
1614
|
-
client: this.context.
|
|
1826
|
+
client: this.context.publicClient
|
|
1615
1827
|
});
|
|
1616
1828
|
const count = await dataRefinerRegistry.read.refinersCount();
|
|
1617
1829
|
return Number(count);
|
|
@@ -1643,8 +1855,9 @@ class DataController {
|
|
|
1643
1855
|
* ```
|
|
1644
1856
|
*/
|
|
1645
1857
|
async updateSchemaId(params) {
|
|
1858
|
+
this.assertWallet();
|
|
1646
1859
|
try {
|
|
1647
|
-
const chainId = this.context.
|
|
1860
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1648
1861
|
if (!chainId) {
|
|
1649
1862
|
throw new Error("Chain ID not available");
|
|
1650
1863
|
}
|
|
@@ -1653,14 +1866,15 @@ class DataController {
|
|
|
1653
1866
|
"DataRefinerRegistry"
|
|
1654
1867
|
);
|
|
1655
1868
|
const dataRefinerRegistryAbi = (0, import_abi.getAbi)("DataRefinerRegistry");
|
|
1656
|
-
|
|
1869
|
+
this.assertWallet();
|
|
1870
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1657
1871
|
const hash = await this.context.walletClient.writeContract({
|
|
1658
1872
|
address: dataRefinerRegistryAddress,
|
|
1659
1873
|
abi: dataRefinerRegistryAbi,
|
|
1660
1874
|
functionName: "updateSchemaId",
|
|
1661
1875
|
args: [BigInt(params.refinerId), BigInt(params.newSchemaId)],
|
|
1662
1876
|
account,
|
|
1663
|
-
chain: this.context.walletClient.chain
|
|
1877
|
+
chain: this.context.walletClient.chain ?? null
|
|
1664
1878
|
});
|
|
1665
1879
|
await this.context.publicClient.waitForTransactionReceipt({ hash });
|
|
1666
1880
|
return {
|
|
@@ -1682,13 +1896,12 @@ class DataController {
|
|
|
1682
1896
|
* 3. Encrypts the user's encryption key with the provided public key
|
|
1683
1897
|
* 4. Registers the file with permissions
|
|
1684
1898
|
*
|
|
1685
|
-
* @param
|
|
1686
|
-
* @param permissions - Array of permissions to grant, each with account address and public key
|
|
1687
|
-
* @param filename - Optional filename for the upload
|
|
1688
|
-
* @param providerName - Optional storage provider to use
|
|
1899
|
+
* @param params - Upload parameters including data, permissions, and options
|
|
1689
1900
|
* @returns Promise resolving to upload result with file ID and storage URL
|
|
1690
1901
|
*/
|
|
1691
|
-
async uploadFileWithPermissions(
|
|
1902
|
+
async uploadFileWithPermissions(params) {
|
|
1903
|
+
this.assertWallet();
|
|
1904
|
+
const { data, permissions, filename, providerName } = params;
|
|
1692
1905
|
try {
|
|
1693
1906
|
const uploadResult = await this.uploadToStorage(
|
|
1694
1907
|
data,
|
|
@@ -1697,7 +1910,7 @@ class DataController {
|
|
|
1697
1910
|
// Always encrypt for uploadFileWithPermissions
|
|
1698
1911
|
providerName
|
|
1699
1912
|
);
|
|
1700
|
-
const userAddress =
|
|
1913
|
+
const userAddress = this.context.userAddress;
|
|
1701
1914
|
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
1702
1915
|
this.context.walletClient,
|
|
1703
1916
|
this.context.platform,
|
|
@@ -1734,9 +1947,18 @@ class DataController {
|
|
|
1734
1947
|
userAddress,
|
|
1735
1948
|
encryptedPermissions
|
|
1736
1949
|
);
|
|
1950
|
+
if (!this.context.waitForTransactionEvents) {
|
|
1951
|
+
throw new Error(
|
|
1952
|
+
"Cannot upload without relay: waitForTransactionEvents not configured"
|
|
1953
|
+
);
|
|
1954
|
+
}
|
|
1955
|
+
const eventResult = await this.context.waitForTransactionEvents(txResult);
|
|
1956
|
+
const fileAddedEvent = eventResult.expectedEvents.FileAdded;
|
|
1957
|
+
if (!fileAddedEvent) {
|
|
1958
|
+
throw new Error("FileAdded event not found in transaction");
|
|
1959
|
+
}
|
|
1737
1960
|
return {
|
|
1738
|
-
fileId:
|
|
1739
|
-
// Placeholder - user must wait for events to get actual fileId
|
|
1961
|
+
fileId: Number(fileAddedEvent.fileId),
|
|
1740
1962
|
url: uploadResult.url,
|
|
1741
1963
|
size: uploadResult.size,
|
|
1742
1964
|
transactionHash: txResult.hash
|
|
@@ -1779,6 +2001,7 @@ class DataController {
|
|
|
1779
2001
|
}
|
|
1780
2002
|
let finalBlob = blob;
|
|
1781
2003
|
if (encrypt) {
|
|
2004
|
+
this.assertWallet();
|
|
1782
2005
|
const encryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
1783
2006
|
this.context.walletClient,
|
|
1784
2007
|
this.context.platform,
|
|
@@ -1800,7 +2023,7 @@ class DataController {
|
|
|
1800
2023
|
);
|
|
1801
2024
|
}
|
|
1802
2025
|
}
|
|
1803
|
-
const finalFilename = filename
|
|
2026
|
+
const finalFilename = filename ?? `upload-${Date.now()}.dat`;
|
|
1804
2027
|
const uploadResult = await this.context.storageManager.upload(
|
|
1805
2028
|
finalBlob,
|
|
1806
2029
|
finalFilename,
|
|
@@ -1825,21 +2048,29 @@ class DataController {
|
|
|
1825
2048
|
* For advanced users who need more control over transaction timing,
|
|
1826
2049
|
* use `submitFilePermission()` instead.
|
|
1827
2050
|
*
|
|
1828
|
-
* @param
|
|
1829
|
-
* @param
|
|
1830
|
-
* @param
|
|
2051
|
+
* @param params - Parameters for adding file permission
|
|
2052
|
+
* @param params.fileId - The ID of the file to grant permission for
|
|
2053
|
+
* @param params.account - The recipient's wallet address that will access the file
|
|
2054
|
+
* @param params.publicKey - The recipient's public key for encryption.
|
|
2055
|
+
* Obtain via `vana.server.getIdentity(account).publicKey`
|
|
1831
2056
|
* @returns Promise resolving to permission data from PermissionGranted event
|
|
1832
2057
|
* @throws {Error} "No addresses available in wallet client" - When wallet is not connected
|
|
1833
2058
|
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1834
2059
|
* @throws {Error} "Failed to add permission to file: {error}" - When transaction fails or user doesn't own file
|
|
1835
2060
|
* @example
|
|
1836
2061
|
* ```typescript
|
|
1837
|
-
* const result = await vana.data.addPermissionToFile(
|
|
2062
|
+
* const result = await vana.data.addPermissionToFile({
|
|
2063
|
+
* fileId: 123,
|
|
2064
|
+
* account: "0xRecipientAddress...",
|
|
2065
|
+
* publicKey: "0xRecipientPublicKey..."
|
|
2066
|
+
* });
|
|
1838
2067
|
* console.log(`Permission granted to ${result.account} for file ${result.fileId}`);
|
|
1839
2068
|
* console.log(`Transaction: ${result.transactionHash}`);
|
|
1840
2069
|
* ```
|
|
1841
2070
|
*/
|
|
1842
|
-
async addPermissionToFile(
|
|
2071
|
+
async addPermissionToFile(params) {
|
|
2072
|
+
this.assertWallet();
|
|
2073
|
+
const { fileId, account, publicKey } = params;
|
|
1843
2074
|
return await this.submitFilePermission(fileId, account, publicKey);
|
|
1844
2075
|
}
|
|
1845
2076
|
/**
|
|
@@ -1853,7 +2084,7 @@ class DataController {
|
|
|
1853
2084
|
* @param fileId - The ID of the file to grant permission for
|
|
1854
2085
|
* @param account - The recipient's wallet address that will access the file
|
|
1855
2086
|
* @param publicKey - The recipient's public key for encryption.
|
|
1856
|
-
* Obtain via `vana.server.getIdentity(account).
|
|
2087
|
+
* Obtain via `vana.server.getIdentity(account).publicKey`
|
|
1857
2088
|
* @returns Promise resolving to TransactionResult for tracking the transaction
|
|
1858
2089
|
* @throws {Error} When chain ID is not available
|
|
1859
2090
|
* @throws {Error} When encryption key generation fails
|
|
@@ -1871,6 +2102,7 @@ class DataController {
|
|
|
1871
2102
|
* ```
|
|
1872
2103
|
*/
|
|
1873
2104
|
async submitFilePermission(fileId, account, publicKey) {
|
|
2105
|
+
this.assertWallet();
|
|
1874
2106
|
try {
|
|
1875
2107
|
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
1876
2108
|
this.context.walletClient,
|
|
@@ -1882,20 +2114,21 @@ class DataController {
|
|
|
1882
2114
|
publicKey,
|
|
1883
2115
|
this.context.platform
|
|
1884
2116
|
);
|
|
1885
|
-
const chainId = this.context.
|
|
2117
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1886
2118
|
if (!chainId) {
|
|
1887
2119
|
throw new Error("Chain ID not available");
|
|
1888
2120
|
}
|
|
1889
2121
|
const dataRegistryAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
1890
2122
|
const dataRegistryAbi = (0, import_abi.getAbi)("DataRegistry");
|
|
1891
|
-
|
|
2123
|
+
this.assertWallet();
|
|
2124
|
+
const walletAccount = this.context.walletClient.account ?? this.context.userAddress;
|
|
1892
2125
|
const txHash = await this.context.walletClient.writeContract({
|
|
1893
2126
|
address: dataRegistryAddress,
|
|
1894
2127
|
abi: dataRegistryAbi,
|
|
1895
2128
|
functionName: "addFilePermission",
|
|
1896
2129
|
args: [BigInt(fileId), account, encryptedKey],
|
|
1897
2130
|
account: walletAccount,
|
|
1898
|
-
chain: this.context.walletClient.chain
|
|
2131
|
+
chain: this.context.walletClient.chain ?? null
|
|
1899
2132
|
});
|
|
1900
2133
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1901
2134
|
return tx({
|
|
@@ -1920,7 +2153,7 @@ class DataController {
|
|
|
1920
2153
|
*/
|
|
1921
2154
|
async getFilePermission(fileId, account) {
|
|
1922
2155
|
try {
|
|
1923
|
-
const chainId = this.context.
|
|
2156
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1924
2157
|
if (!chainId) {
|
|
1925
2158
|
throw new Error("Chain ID not available");
|
|
1926
2159
|
}
|
|
@@ -1929,7 +2162,7 @@ class DataController {
|
|
|
1929
2162
|
const dataRegistry = (0, import_viem.getContract)({
|
|
1930
2163
|
address: dataRegistryAddress,
|
|
1931
2164
|
abi: dataRegistryAbi,
|
|
1932
|
-
client: this.context.
|
|
2165
|
+
client: this.context.publicClient
|
|
1933
2166
|
});
|
|
1934
2167
|
const encryptedKey = await dataRegistry.read.filePermissions([
|
|
1935
2168
|
BigInt(fileId),
|
|
@@ -1953,12 +2186,13 @@ class DataController {
|
|
|
1953
2186
|
*
|
|
1954
2187
|
* @param file - The file to decrypt
|
|
1955
2188
|
* @param privateKey - The private key to decrypt the user's encryption key
|
|
1956
|
-
* @param
|
|
2189
|
+
* @param options - Optional decryption configuration
|
|
2190
|
+
* @param options.account - The account address that has permission (defaults to current wallet account)
|
|
1957
2191
|
* @returns Promise resolving to the decrypted file data
|
|
1958
2192
|
*/
|
|
1959
|
-
async decryptFileWithPermission(file, privateKey,
|
|
2193
|
+
async decryptFileWithPermission(file, privateKey, options) {
|
|
1960
2194
|
try {
|
|
1961
|
-
const permissionAccount = account
|
|
2195
|
+
const permissionAccount = options?.account ?? this.context.userAddress;
|
|
1962
2196
|
const encryptedKey = await this.getFilePermission(
|
|
1963
2197
|
file.id,
|
|
1964
2198
|
permissionAccount
|
|
@@ -2022,11 +2256,8 @@ class DataController {
|
|
|
2022
2256
|
*/
|
|
2023
2257
|
async fetch(url) {
|
|
2024
2258
|
try {
|
|
2025
|
-
const {
|
|
2026
|
-
const response = await
|
|
2027
|
-
url,
|
|
2028
|
-
this.context.downloadRelayer
|
|
2029
|
-
);
|
|
2259
|
+
const { universalFetch } = await import("../utils/download");
|
|
2260
|
+
const response = await universalFetch(url, this.context.downloadRelayer);
|
|
2030
2261
|
if (!response.ok) {
|
|
2031
2262
|
throw new Error(
|
|
2032
2263
|
`HTTP error! status: ${response.status} ${response.statusText}`
|
|
@@ -2091,7 +2322,7 @@ class DataController {
|
|
|
2091
2322
|
"https://dweb.link/ipfs/",
|
|
2092
2323
|
"https://ipfs.io/ipfs/"
|
|
2093
2324
|
];
|
|
2094
|
-
const gateways = options?.gateways
|
|
2325
|
+
const gateways = options?.gateways ?? this.context.ipfsGateways ?? defaultGateways;
|
|
2095
2326
|
const { extractIpfsHash } = await import("../utils/ipfs");
|
|
2096
2327
|
const cid = extractIpfsHash(url);
|
|
2097
2328
|
if (!cid) {
|
|
@@ -2220,7 +2451,7 @@ class DataController {
|
|
|
2220
2451
|
* ```
|
|
2221
2452
|
*/
|
|
2222
2453
|
validateDataAgainstSchema(data, schema) {
|
|
2223
|
-
|
|
2454
|
+
(0, import_schemaValidation.validateDataAgainstSchema)(data, schema);
|
|
2224
2455
|
}
|
|
2225
2456
|
/**
|
|
2226
2457
|
* Fetches and validates a data schema from a URL, then returns the parsed data schema.
|