@opendatalabs/vana-sdk 0.1.0-alpha.d7fc764 → 0.1.0-alpha.dc68f39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/waitForTransactionEvents.test.d.ts +1 -0
- package/dist/browser.d.ts +4 -2
- package/dist/chains/definitions.cjs +9 -6
- package/dist/chains/definitions.cjs.map +1 -1
- package/dist/chains/definitions.d.ts +9 -11
- package/dist/chains/definitions.js +9 -6
- package/dist/chains/definitions.js.map +1 -1
- package/dist/chains/index.d.ts +5 -2
- package/dist/chains.browser.d.ts +8 -2
- package/dist/chains.d.ts +8 -2
- package/dist/chains.node.d.ts +8 -2
- package/dist/config/addresses.d.ts +8 -24
- package/dist/config/chains.d.ts +9 -13
- package/dist/config/default-services.cjs +60 -0
- package/dist/config/default-services.cjs.map +1 -0
- package/dist/config/default-services.d.ts +46 -0
- package/dist/config/default-services.js +33 -0
- package/dist/config/default-services.js.map +1 -0
- package/dist/config/default-services.test.d.ts +1 -0
- package/dist/config/features.d.ts +1 -3
- package/dist/config/tests/addresses.test.d.ts +1 -0
- package/dist/contracts/contractController.cjs +3 -3
- package/dist/contracts/contractController.cjs.map +1 -1
- package/dist/contracts/contractController.d.ts +11 -28
- package/dist/contracts/contractController.js +4 -7
- package/dist/contracts/contractController.js.map +1 -1
- package/dist/contracts/tests/contractController.test.d.ts +1 -0
- package/dist/controllers/__tests__/schemas-edge-cases.test.d.ts +1 -0
- package/dist/controllers/base.cjs +83 -0
- package/dist/controllers/base.cjs.map +1 -0
- package/dist/controllers/base.d.ts +84 -0
- package/dist/controllers/base.js +59 -0
- package/dist/controllers/base.js.map +1 -0
- package/dist/controllers/data-error-handling.test.d.ts +1 -0
- package/dist/controllers/data.cjs +415 -172
- package/dist/controllers/data.cjs.map +1 -1
- package/dist/controllers/data.d.ts +149 -76
- package/dist/controllers/data.js +415 -172
- package/dist/controllers/data.js.map +1 -1
- package/dist/controllers/permissions.cjs +508 -257
- package/dist/controllers/permissions.cjs.map +1 -1
- package/dist/controllers/permissions.d.ts +1348 -25
- package/dist/controllers/permissions.js +508 -257
- package/dist/controllers/permissions.js.map +1 -1
- package/dist/controllers/protocol.cjs +15 -11
- package/dist/controllers/protocol.cjs.map +1 -1
- package/dist/controllers/protocol.d.ts +7 -35
- package/dist/controllers/protocol.js +15 -14
- package/dist/controllers/protocol.js.map +1 -1
- package/dist/controllers/schemas.cjs +69 -54
- package/dist/controllers/schemas.cjs.map +1 -1
- package/dist/controllers/schemas.d.ts +9 -36
- package/dist/controllers/schemas.js +69 -54
- package/dist/controllers/schemas.js.map +1 -1
- package/dist/controllers/server-additional.test.d.ts +1 -0
- package/dist/controllers/server.cjs +15 -10
- package/dist/controllers/server.cjs.map +1 -1
- package/dist/controllers/server.d.ts +7 -33
- package/dist/controllers/server.js +15 -10
- package/dist/controllers/server.js.map +1 -1
- package/dist/core/apiClient.cjs +15 -12
- package/dist/core/apiClient.cjs.map +1 -1
- package/dist/core/apiClient.d.ts +5 -9
- package/dist/core/apiClient.js +19 -19
- package/dist/core/apiClient.js.map +1 -1
- package/dist/core/client.cjs +7 -7
- package/dist/core/client.cjs.map +1 -1
- package/dist/core/client.d.ts +6 -9
- package/dist/core/client.js +7 -7
- package/dist/core/client.js.map +1 -1
- package/dist/core/core.test.d.ts +1 -0
- package/dist/core/generics.cjs +11 -9
- package/dist/core/generics.cjs.map +1 -1
- package/dist/core/generics.d.ts +9 -13
- package/dist/core/generics.js +22 -29
- package/dist/core/generics.js.map +1 -1
- package/dist/core/tests/apiClient.test.d.ts +1 -0
- package/dist/core/tests/client.test.d.ts +1 -0
- package/dist/core/tests/generics.test.d.ts +1 -0
- package/dist/core.cjs +114 -48
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +40 -65
- package/dist/core.js +127 -74
- 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/test-vectors/eccrypto-vectors.json +72 -0
- package/dist/crypto/ecies/utils.cjs +2 -41
- package/dist/crypto/ecies/utils.cjs.map +1 -1
- package/dist/crypto/ecies/utils.d.ts +3 -40
- package/dist/crypto/ecies/utils.js +1 -35
- package/dist/crypto/ecies/utils.js.map +1 -1
- package/dist/crypto/services/WalletKeyEncryptionService.cjs +2 -2
- package/dist/crypto/services/WalletKeyEncryptionService.cjs.map +1 -1
- package/dist/crypto/services/WalletKeyEncryptionService.d.ts +3 -7
- package/dist/crypto/services/WalletKeyEncryptionService.js +5 -9
- package/dist/crypto/services/WalletKeyEncryptionService.js.map +1 -1
- package/dist/crypto/services/WalletKeyEncryptionService.test.d.ts +1 -0
- package/dist/diagnostics.d.ts +1 -3
- package/dist/diagnostics.test.d.ts +1 -0
- package/dist/errors.cjs +16 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +53 -15
- package/dist/errors.js +18 -6
- package/dist/errors.js.map +1 -1
- package/dist/generated/abi/ComputeEngineImplementation.d.ts +2 -3
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.d.ts +2 -3
- package/dist/generated/abi/DATFactoryImplementation.d.ts +2 -3
- package/dist/generated/abi/DATImplementation.d.ts +2 -3
- package/dist/generated/abi/DATPausableImplementation.d.ts +2 -3
- package/dist/generated/abi/DATVotesImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPPerformanceImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRegistryImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRegistryTreasuryImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRewardDeployerImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRewardSwapImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRootImplementation.d.ts +1 -3
- package/dist/generated/abi/DLPTreasuryImplementation.d.ts +2 -3
- package/dist/generated/abi/DataLiquidityPoolImplementation.d.ts +1 -3
- package/dist/generated/abi/DataPortabilityGranteesImplementation.d.ts +2 -3
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.ts +2 -3
- package/dist/generated/abi/DataPortabilityServersImplementation.d.ts +2 -3
- package/dist/generated/abi/DataRefinerRegistryImplementation.d.ts +2 -3
- package/dist/generated/abi/DataRegistryImplementation.cjs +13 -0
- package/dist/generated/abi/DataRegistryImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataRegistryImplementation.d.ts +12 -3
- package/dist/generated/abi/DataRegistryImplementation.js +13 -0
- package/dist/generated/abi/DataRegistryImplementation.js.map +1 -1
- package/dist/generated/abi/QueryEngineImplementation.d.ts +2 -3
- package/dist/generated/abi/SwapHelperImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolDedicatedGpuImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolDedicatedStandardImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolEphemeralStandardImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolPersistentGpuImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolPersistentStandardImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolPhalaImplementation.d.ts +2 -3
- package/dist/generated/abi/VanaEpochImplementation.d.ts +2 -3
- package/dist/generated/abi/VanaPoolEntityImplementation.d.ts +2 -3
- package/dist/generated/abi/VanaPoolStakingImplementation.d.ts +2 -3
- package/dist/generated/abi/VanaPoolTreasuryImplementation.d.ts +2 -3
- package/dist/generated/abi/index.cjs +42 -0
- package/dist/generated/abi/index.cjs.map +1 -1
- package/dist/generated/abi/index.d.ts +47 -18
- package/dist/generated/abi/index.js +21 -0
- package/dist/generated/abi/index.js.map +1 -1
- package/dist/generated/event-types.cjs +17 -0
- package/dist/generated/event-types.cjs.map +1 -0
- package/dist/generated/event-types.d.ts +854 -0
- package/dist/generated/event-types.js +1 -0
- package/dist/generated/event-types.js.map +1 -0
- package/dist/generated/eventRegistry.cjs +3351 -0
- package/dist/generated/eventRegistry.cjs.map +1 -0
- package/dist/generated/eventRegistry.d.ts +14 -0
- package/dist/generated/eventRegistry.js +3326 -0
- package/dist/generated/eventRegistry.js.map +1 -0
- package/dist/generated/server/server-exports.d.ts +19 -21
- package/dist/generated/server/server.cjs.map +1 -1
- package/dist/generated/server/server.d.ts +113 -87
- package/dist/generated/subgraph.d.ts +329 -332
- package/dist/index.browser.d.ts +48 -73
- package/dist/index.browser.js +12 -0
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/index.node.cjs +9 -0
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.ts +181 -64
- 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/schemas/dataSchema.schema.json +53 -0
- package/dist/schemas/grantFile.schema.json +43 -0
- package/dist/server/handler.cjs.map +1 -1
- package/dist/server/handler.d.ts +8 -203
- package/dist/server/handler.js.map +1 -1
- package/dist/storage/index.d.ts +56 -10
- package/dist/storage/manager.cjs +6 -6
- 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-transaction-options.test.d.ts +1 -0
- package/dist/tests/permissions-trust-servers.test.d.ts +1 -0
- package/dist/tests/permissions.test.d.ts +1 -0
- package/dist/tests/personal.test.d.ts +1 -0
- package/dist/tests/platform-browser.test.d.ts +1 -0
- package/dist/tests/platform-crypto-expanded.test.d.ts +1 -0
- package/dist/tests/platform-crypto.test.d.ts +1 -0
- package/dist/tests/platform-index.test.d.ts +1 -0
- package/dist/tests/platform-node.test.d.ts +1 -0
- package/dist/tests/platform-shared-utils.test.d.ts +1 -0
- package/dist/tests/platform-updated.test.d.ts +1 -0
- package/dist/tests/protocol-additional-methods.test.d.ts +1 -0
- package/dist/tests/protocol.test.d.ts +1 -0
- package/dist/tests/read-only-mode.test.d.ts +1 -0
- package/dist/tests/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 +17 -0
- package/dist/types/blockchain.cjs.map +1 -0
- package/dist/types/blockchain.d.ts +57 -0
- package/dist/types/blockchain.js +1 -0
- package/dist/types/blockchain.js.map +1 -0
- package/dist/types/chains-additional.test.d.ts +1 -0
- package/dist/types/chains.d.ts +6 -9
- package/dist/types/config.cjs +10 -0
- package/dist/types/config.cjs.map +1 -1
- package/dist/types/config.d.ts +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 +17 -0
- package/dist/types/controller-context.cjs.map +1 -0
- package/dist/types/controller-context.d.ts +64 -0
- package/dist/types/controller-context.js +1 -0
- package/dist/types/controller-context.js.map +1 -0
- package/dist/types/data.cjs.map +1 -1
- package/dist/types/data.d.ts +107 -39
- package/dist/types/external-apis.d.ts +10 -12
- package/dist/types/generics.d.ts +35 -38
- package/dist/types/index.cjs +5 -4
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.ts +20 -34
- package/dist/types/index.js +9 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/operations.cjs +2 -2
- package/dist/types/operations.cjs.map +1 -1
- package/dist/types/operations.d.ts +32 -28
- package/dist/types/operations.js +2 -2
- package/dist/types/operations.js.map +1 -1
- package/dist/types/permissions.d.ts +55 -58
- package/dist/types/personal.cjs.map +1 -1
- package/dist/types/personal.d.ts +6 -8
- package/dist/types/relayer.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.cjs.map +1 -1
- package/dist/types/transactionResults.d.ts +193 -25
- package/dist/types/utils.cjs.map +1 -1
- package/dist/types/utils.d.ts +26 -25
- package/dist/types.d.ts +4 -40
- package/dist/utils/__tests__/parseTransaction.test.d.ts +1 -0
- package/dist/utils/__tests__/pojo-serialization.test.d.ts +1 -0
- package/dist/utils/__tests__/signatureCache.test.d.ts +1 -0
- package/dist/utils/__tests__/transaction-edge-cases.test.d.ts +1 -0
- package/dist/utils/__tests__/transactionHelpers.test.d.ts +1 -0
- package/dist/utils/__tests__/urlResolver.test.d.ts +4 -0
- package/dist/utils/blockchain/registry.cjs +2 -2
- package/dist/utils/blockchain/registry.cjs.map +1 -1
- package/dist/utils/blockchain/registry.d.ts +6 -8
- package/dist/utils/blockchain/registry.js +2 -2
- package/dist/utils/blockchain/registry.js.map +1 -1
- package/dist/utils/blockchain/registry.test.d.ts +1 -0
- package/dist/utils/crypto-utils.cjs +0 -12
- package/dist/utils/crypto-utils.cjs.map +1 -1
- package/dist/utils/crypto-utils.d.ts +9 -27
- package/dist/utils/crypto-utils.js +0 -11
- package/dist/utils/crypto-utils.js.map +1 -1
- package/dist/utils/crypto-utils.test.d.ts +1 -0
- package/dist/utils/download.cjs +3 -3
- package/dist/utils/download.cjs.map +1 -1
- package/dist/utils/download.d.ts +13 -14
- package/dist/utils/download.js +2 -2
- package/dist/utils/download.js.map +1 -1
- package/dist/utils/encoding.cjs +1 -1
- package/dist/utils/encoding.cjs.map +1 -1
- package/dist/utils/encoding.d.ts +4 -6
- package/dist/utils/encoding.js +1 -1
- package/dist/utils/encoding.js.map +1 -1
- package/dist/utils/encoding.test.d.ts +1 -0
- package/dist/utils/encryption.cjs +16 -10
- package/dist/utils/encryption.cjs.map +1 -1
- package/dist/utils/encryption.d.ts +13 -17
- package/dist/utils/encryption.js +16 -10
- package/dist/utils/encryption.js.map +1 -1
- package/dist/utils/formatters.cjs +4 -2
- package/dist/utils/formatters.cjs.map +1 -1
- package/dist/utils/formatters.d.ts +4 -6
- package/dist/utils/formatters.js +4 -2
- package/dist/utils/formatters.js.map +1 -1
- package/dist/utils/grantFiles.cjs +7 -4
- package/dist/utils/grantFiles.cjs.map +1 -1
- package/dist/utils/grantFiles.d.ts +6 -10
- package/dist/utils/grantFiles.js +7 -4
- package/dist/utils/grantFiles.js.map +1 -1
- package/dist/utils/grantValidation.cjs +1 -1
- package/dist/utils/grantValidation.cjs.map +1 -1
- package/dist/utils/grantValidation.d.ts +14 -17
- package/dist/utils/grantValidation.js +1 -1
- package/dist/utils/grantValidation.js.map +1 -1
- package/dist/utils/grants.cjs +1 -1
- package/dist/utils/grants.cjs.map +1 -1
- package/dist/utils/grants.d.ts +10 -13
- package/dist/utils/grants.js +1 -1
- package/dist/utils/grants.js.map +1 -1
- package/dist/utils/ipfs.d.ts +8 -10
- package/dist/utils/lazy-import.cjs +4 -6
- package/dist/utils/lazy-import.cjs.map +1 -1
- package/dist/utils/lazy-import.d.ts +1 -3
- package/dist/utils/lazy-import.js +4 -6
- package/dist/utils/lazy-import.js.map +1 -1
- package/dist/utils/multicall.cjs +4 -2
- package/dist/utils/multicall.cjs.map +1 -1
- package/dist/utils/multicall.d.ts +5 -8
- package/dist/utils/multicall.js +4 -2
- package/dist/utils/multicall.js.map +1 -1
- package/dist/utils/parseTransactionPojo.cjs +87 -0
- package/dist/utils/parseTransactionPojo.cjs.map +1 -0
- package/dist/utils/parseTransactionPojo.d.ts +31 -0
- package/dist/utils/parseTransactionPojo.js +63 -0
- package/dist/utils/parseTransactionPojo.js.map +1 -0
- package/dist/utils/schemaValidation.cjs +5 -5
- package/dist/utils/schemaValidation.cjs.map +1 -1
- package/dist/utils/schemaValidation.d.ts +8 -12
- package/dist/utils/schemaValidation.js +7 -10
- package/dist/utils/schemaValidation.js.map +1 -1
- package/dist/utils/signatureCache.cjs +1 -2
- package/dist/utils/signatureCache.cjs.map +1 -1
- package/dist/utils/signatureCache.d.ts +4 -7
- package/dist/utils/signatureCache.js +4 -8
- package/dist/utils/signatureCache.js.map +1 -1
- package/dist/utils/signatureFormatter.cjs +6 -9
- package/dist/utils/signatureFormatter.cjs.map +1 -1
- package/dist/utils/signatureFormatter.d.ts +2 -5
- package/dist/utils/signatureFormatter.js +6 -9
- package/dist/utils/signatureFormatter.js.map +1 -1
- package/dist/utils/tests/multicall.test.d.ts +1 -0
- package/dist/utils/transactionHelpers.cjs +54 -0
- package/dist/utils/transactionHelpers.cjs.map +1 -0
- package/dist/utils/transactionHelpers.d.ts +80 -0
- package/dist/utils/transactionHelpers.js +29 -0
- package/dist/utils/transactionHelpers.js.map +1 -0
- package/dist/utils/typeGuards.cjs +109 -0
- package/dist/utils/typeGuards.cjs.map +1 -0
- package/dist/utils/typeGuards.d.ts +138 -0
- package/dist/utils/typeGuards.js +74 -0
- package/dist/utils/typeGuards.js.map +1 -0
- package/dist/utils/typedDataConverter.d.ts +3 -6
- package/dist/utils/urlResolver.cjs +1 -1
- package/dist/utils/urlResolver.cjs.map +1 -1
- package/dist/utils/urlResolver.d.ts +2 -4
- package/dist/utils/urlResolver.js +2 -2
- package/dist/utils/urlResolver.js.map +1 -1
- package/dist/utils/wallet.cjs +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/{chains.browser.cjs → utils/withEvents.cjs} +22 -15
- package/dist/utils/withEvents.cjs.map +1 -0
- package/dist/utils/withEvents.d.ts +56 -0
- package/dist/utils/withEvents.js +18 -0
- package/dist/utils/withEvents.js.map +1 -0
- package/package.json +23 -13
- package/dist/browser.d.cts +0 -2
- package/dist/chains/definitions.d.cts +0 -53
- package/dist/chains/index.d.cts +0 -2
- package/dist/chains.browser.cjs.map +0 -1
- package/dist/chains.browser.d.cts +0 -2
- package/dist/chains.d.cts +0 -2
- package/dist/chains.node.d.cts +0 -2
- package/dist/config/addresses.d.cts +0 -380
- package/dist/config/chains.d.cts +0 -85
- package/dist/config/eventMappings.cjs +0 -114
- package/dist/config/eventMappings.cjs.map +0 -1
- package/dist/config/eventMappings.d.cts +0 -108
- package/dist/config/eventMappings.d.ts +0 -108
- package/dist/config/eventMappings.js +0 -90
- package/dist/config/eventMappings.js.map +0 -1
- package/dist/config/features.d.cts +0 -64
- package/dist/contracts/contractController.d.cts +0 -96
- package/dist/controllers/data.d.cts +0 -941
- package/dist/controllers/permissions.d.cts +0 -25
- package/dist/controllers/protocol.d.cts +0 -167
- package/dist/controllers/schemas.d.cts +0 -272
- package/dist/controllers/server.d.cts +0 -243
- package/dist/core/apiClient.d.cts +0 -165
- package/dist/core/client.d.cts +0 -92
- package/dist/core/generics.d.cts +0 -120
- package/dist/core.d.cts +0 -466
- package/dist/crypto/ecies/__tests__/test-vectors.d.cts +0 -40
- package/dist/crypto/ecies/base.d.cts +0 -143
- package/dist/crypto/ecies/browser.d.cts +0 -48
- package/dist/crypto/ecies/constants.d.cts +0 -122
- package/dist/crypto/ecies/index.d.cts +0 -1
- package/dist/crypto/ecies/interface.d.cts +0 -176
- package/dist/crypto/ecies/node.d.cts +0 -50
- package/dist/crypto/ecies/utils.d.cts +0 -67
- package/dist/crypto/services/WalletKeyEncryptionService.d.cts +0 -92
- package/dist/diagnostics.d.cts +0 -26
- package/dist/errors.d.cts +0 -350
- package/dist/generated/abi/ComputeEngineImplementation.d.cts +0 -996
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.d.cts +0 -545
- package/dist/generated/abi/DATFactoryImplementation.d.cts +0 -661
- package/dist/generated/abi/DATImplementation.d.cts +0 -693
- package/dist/generated/abi/DATPausableImplementation.d.cts +0 -1145
- package/dist/generated/abi/DATVotesImplementation.d.cts +0 -1095
- package/dist/generated/abi/DLPPerformanceImplementation.d.cts +0 -883
- package/dist/generated/abi/DLPRegistryImplementation.d.cts +0 -1123
- package/dist/generated/abi/DLPRegistryTreasuryImplementation.d.cts +0 -452
- package/dist/generated/abi/DLPRewardDeployerImplementation.d.cts +0 -714
- package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.d.cts +0 -452
- package/dist/generated/abi/DLPRewardSwapImplementation.d.cts +0 -706
- package/dist/generated/abi/DLPRootImplementation.d.cts +0 -1248
- package/dist/generated/abi/DLPTreasuryImplementation.d.cts +0 -452
- package/dist/generated/abi/DataLiquidityPoolImplementation.d.cts +0 -737
- package/dist/generated/abi/DataPortabilityGranteesImplementation.d.cts +0 -661
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.cts +0 -989
- package/dist/generated/abi/DataPortabilityServersImplementation.d.cts +0 -1086
- package/dist/generated/abi/DataRefinerRegistryImplementation.d.cts +0 -737
- package/dist/generated/abi/DataRegistryImplementation.d.cts +0 -1004
- package/dist/generated/abi/QueryEngineImplementation.d.cts +0 -1001
- package/dist/generated/abi/SwapHelperImplementation.d.cts +0 -764
- package/dist/generated/abi/TeePoolDedicatedGpuImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolDedicatedStandardImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolEphemeralStandardImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolImplementation.d.cts +0 -993
- package/dist/generated/abi/TeePoolPersistentGpuImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolPersistentStandardImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolPhalaImplementation.d.cts +0 -993
- package/dist/generated/abi/VanaEpochImplementation.d.cts +0 -900
- package/dist/generated/abi/VanaPoolEntityImplementation.d.cts +0 -934
- package/dist/generated/abi/VanaPoolStakingImplementation.d.cts +0 -693
- package/dist/generated/abi/VanaPoolTreasuryImplementation.d.cts +0 -394
- package/dist/generated/abi/index.d.cts +0 -26516
- package/dist/generated/server/server-exports.d.cts +0 -21
- package/dist/generated/server/server.d.cts +0 -512
- package/dist/generated/subgraph.d.cts +0 -5981
- package/dist/index.browser.cjs +0 -151
- package/dist/index.browser.cjs.map +0 -1
- package/dist/index.browser.d.cts +0 -177
- package/dist/index.d.cts +0 -2
- package/dist/index.node.d.cts +0 -64
- package/dist/node.d.cts +0 -2
- package/dist/permissions-DNKPu_G0.d.cts +0 -1666
- package/dist/permissions-eo8YeLGf.d.ts +0 -1666
- package/dist/platform/browser-only.d.cts +0 -25
- package/dist/platform/browser-safe.d.cts +0 -32
- package/dist/platform/browser.d.cts +0 -74
- package/dist/platform/index.d.cts +0 -5
- package/dist/platform/interface.d.cts +0 -218
- package/dist/platform/node.d.cts +0 -27
- package/dist/platform/shared/error-utils.d.cts +0 -25
- package/dist/platform/shared/pgp-utils.d.cts +0 -61
- package/dist/platform/shared/stream-utils.d.cts +0 -16
- package/dist/platform/utils.d.cts +0 -53
- package/dist/platform.browser.cjs +0 -41
- package/dist/platform.browser.cjs.map +0 -1
- package/dist/platform.browser.d.cts +0 -4
- package/dist/platform.d.cts +0 -5
- package/dist/platform.node.d.cts +0 -5
- package/dist/server/handler.d.cts +0 -282
- package/dist/storage/index.d.cts +0 -10
- package/dist/storage/manager.d.cts +0 -150
- package/dist/storage/providers/callback-storage.d.cts +0 -100
- package/dist/storage/providers/google-drive.d.cts +0 -156
- package/dist/storage/providers/ipfs.d.cts +0 -163
- package/dist/storage/providers/pinata.d.cts +0 -173
- package/dist/types/chains.d.cts +0 -34
- package/dist/types/config.d.cts +0 -726
- package/dist/types/contracts.d.cts +0 -68
- package/dist/types/data.d.cts +0 -694
- package/dist/types/eccrypto-js.d.d.cts +0 -13
- package/dist/types/eccrypto-js.d.d.ts +0 -13
- package/dist/types/external-apis.d.cts +0 -186
- package/dist/types/generics.d.cts +0 -450
- package/dist/types/index.d.cts +0 -34
- package/dist/types/operations.d.cts +0 -108
- package/dist/types/permissions.d.cts +0 -957
- package/dist/types/personal.d.cts +0 -40
- package/dist/types/relayer.d.cts +0 -284
- package/dist/types/storage.d.cts +0 -131
- package/dist/types/transactionResults.d.cts +0 -25
- package/dist/types/utils.d.cts +0 -819
- package/dist/types.d.cts +0 -66
- package/dist/utils/blockchain/registry.d.cts +0 -34
- package/dist/utils/crypto-utils.d.cts +0 -118
- package/dist/utils/download.d.cts +0 -41
- package/dist/utils/encoding.d.cts +0 -54
- package/dist/utils/encryption.d.cts +0 -275
- package/dist/utils/eventParsing.cjs +0 -111
- package/dist/utils/eventParsing.cjs.map +0 -1
- package/dist/utils/eventParsing.d.cts +0 -60
- package/dist/utils/eventParsing.d.ts +0 -60
- package/dist/utils/eventParsing.js +0 -86
- package/dist/utils/eventParsing.js.map +0 -1
- package/dist/utils/formatters.d.cts +0 -120
- package/dist/utils/grantFiles.d.cts +0 -186
- package/dist/utils/grantValidation.d.cts +0 -150
- package/dist/utils/grants.d.cts +0 -70
- package/dist/utils/ipfs.d.cts +0 -90
- package/dist/utils/lazy-import.d.cts +0 -20
- package/dist/utils/multicall.d.cts +0 -129
- package/dist/utils/schemaValidation.d.cts +0 -172
- package/dist/utils/signatureCache.d.cts +0 -134
- package/dist/utils/signatureFormatter.d.cts +0 -39
- package/dist/utils/transactionParsing.cjs +0 -84
- package/dist/utils/transactionParsing.cjs.map +0 -1
- package/dist/utils/transactionParsing.d.cts +0 -25
- package/dist/utils/transactionParsing.d.ts +0 -25
- package/dist/utils/transactionParsing.js +0 -62
- package/dist/utils/transactionParsing.js.map +0 -1
- package/dist/utils/typedDataConverter.d.cts +0 -13
- package/dist/utils/urlResolver.d.cts +0 -40
|
@@ -32,6 +32,7 @@ __export(data_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(data_exports);
|
|
34
34
|
var import_viem = require("viem");
|
|
35
|
+
var import_base = require("./base");
|
|
35
36
|
var import_addresses = require("../config/addresses");
|
|
36
37
|
var import_abi = require("../generated/abi");
|
|
37
38
|
var import_subgraph = require("../generated/subgraph");
|
|
@@ -39,11 +40,12 @@ var import_graphql = require("graphql");
|
|
|
39
40
|
var import_encryption = require("../utils/encryption");
|
|
40
41
|
var import_schemaValidation = require("../utils/schemaValidation");
|
|
41
42
|
var import_multicall = require("../utils/multicall");
|
|
42
|
-
class DataController {
|
|
43
|
+
class DataController extends import_base.BaseController {
|
|
43
44
|
constructor(context) {
|
|
44
|
-
|
|
45
|
+
super(context);
|
|
45
46
|
}
|
|
46
47
|
async upload(params) {
|
|
48
|
+
this.assertWallet();
|
|
47
49
|
const {
|
|
48
50
|
content,
|
|
49
51
|
filename,
|
|
@@ -68,15 +70,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,12 +147,26 @@ class DataController {
|
|
|
130
147
|
userAddress
|
|
131
148
|
);
|
|
132
149
|
} else {
|
|
133
|
-
|
|
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
|
+
}
|
|
166
|
+
result = {
|
|
167
|
+
fileId: Number(fileAddedEvent.fileId),
|
|
168
|
+
transactionHash: txResult.hash
|
|
169
|
+
};
|
|
139
170
|
}
|
|
140
171
|
return {
|
|
141
172
|
fileId: result.fileId,
|
|
@@ -151,6 +182,83 @@ class DataController {
|
|
|
151
182
|
);
|
|
152
183
|
}
|
|
153
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
|
+
}
|
|
154
262
|
/**
|
|
155
263
|
* Decrypts a file owned by the user using their wallet signature.
|
|
156
264
|
*
|
|
@@ -206,12 +314,14 @@ class DataController {
|
|
|
206
314
|
* fs.writeFileSync('decrypted-file.txt', Buffer.from(buffer));
|
|
207
315
|
* ```
|
|
208
316
|
*/
|
|
209
|
-
async decryptFile(file,
|
|
317
|
+
async decryptFile(file, options) {
|
|
318
|
+
this.assertWallet();
|
|
210
319
|
try {
|
|
320
|
+
this.assertWallet();
|
|
211
321
|
const encryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
212
322
|
this.context.walletClient,
|
|
213
323
|
this.context.platform,
|
|
214
|
-
|
|
324
|
+
options?.seed ?? import_encryption.DEFAULT_ENCRYPTION_SEED
|
|
215
325
|
);
|
|
216
326
|
let encryptedBlob;
|
|
217
327
|
try {
|
|
@@ -328,7 +438,7 @@ class DataController {
|
|
|
328
438
|
*/
|
|
329
439
|
async getUserFiles(params) {
|
|
330
440
|
const { owner, subgraphUrl } = params;
|
|
331
|
-
const endpoint = subgraphUrl
|
|
441
|
+
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
332
442
|
if (!endpoint) {
|
|
333
443
|
throw new Error(
|
|
334
444
|
"subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor."
|
|
@@ -360,7 +470,7 @@ class DataController {
|
|
|
360
470
|
);
|
|
361
471
|
}
|
|
362
472
|
const user = result.data?.user;
|
|
363
|
-
if (!user
|
|
473
|
+
if (!user?.files?.length) {
|
|
364
474
|
console.warn("No files found for user:", owner);
|
|
365
475
|
return [];
|
|
366
476
|
}
|
|
@@ -382,7 +492,7 @@ class DataController {
|
|
|
382
492
|
}
|
|
383
493
|
});
|
|
384
494
|
const userFiles = Array.from(fileMap.values()).sort(
|
|
385
|
-
(a, b) => Number((b.addedAtTimestamp
|
|
495
|
+
(a, b) => Number((b.addedAtTimestamp ?? 0n) - (a.addedAtTimestamp ?? 0n))
|
|
386
496
|
);
|
|
387
497
|
if (userFiles.length > 0) {
|
|
388
498
|
try {
|
|
@@ -453,10 +563,11 @@ class DataController {
|
|
|
453
563
|
if (proof.dlp?.id) {
|
|
454
564
|
const fileId = parseInt(proof.fileId);
|
|
455
565
|
const dlpId = parseInt(proof.dlp.id);
|
|
456
|
-
|
|
457
|
-
|
|
566
|
+
let dlpIds = proofMap.get(fileId);
|
|
567
|
+
if (!dlpIds) {
|
|
568
|
+
dlpIds = [];
|
|
569
|
+
proofMap.set(fileId, dlpIds);
|
|
458
570
|
}
|
|
459
|
-
const dlpIds = proofMap.get(fileId);
|
|
460
571
|
if (!dlpIds.includes(dlpId)) {
|
|
461
572
|
dlpIds.push(dlpId);
|
|
462
573
|
}
|
|
@@ -474,7 +585,7 @@ class DataController {
|
|
|
474
585
|
* @returns Map of file IDs to their associated DLP IDs
|
|
475
586
|
*/
|
|
476
587
|
async _fetchProofsFromChain(fileIds) {
|
|
477
|
-
const chainId = this.context.
|
|
588
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
478
589
|
if (!chainId) {
|
|
479
590
|
throw new Error("Chain ID not available");
|
|
480
591
|
}
|
|
@@ -531,7 +642,7 @@ class DataController {
|
|
|
531
642
|
* ```
|
|
532
643
|
*/
|
|
533
644
|
async getDLP(dlpId, options = {}) {
|
|
534
|
-
const subgraphUrl = options.subgraphUrl
|
|
645
|
+
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
535
646
|
if (subgraphUrl) {
|
|
536
647
|
try {
|
|
537
648
|
const response = await fetch(subgraphUrl, {
|
|
@@ -562,18 +673,18 @@ class DataController {
|
|
|
562
673
|
}
|
|
563
674
|
return {
|
|
564
675
|
id: parseInt(result.data.dlp.id),
|
|
565
|
-
name: result.data.dlp.name
|
|
566
|
-
metadata: result.data.dlp.metadata
|
|
676
|
+
name: result.data.dlp.name ?? "",
|
|
677
|
+
metadata: result.data.dlp.metadata ?? void 0,
|
|
567
678
|
status: result.data.dlp.status ? parseInt(result.data.dlp.status) : void 0,
|
|
568
|
-
address: result.data.dlp.address,
|
|
569
|
-
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
|
|
570
681
|
};
|
|
571
682
|
} catch (error) {
|
|
572
683
|
console.debug("Subgraph query failed, falling back to chain:", error);
|
|
573
684
|
}
|
|
574
685
|
}
|
|
575
686
|
try {
|
|
576
|
-
const chainId = this.context.
|
|
687
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
577
688
|
if (!chainId) {
|
|
578
689
|
throw new Error("Chain ID not available");
|
|
579
690
|
}
|
|
@@ -585,7 +696,7 @@ class DataController {
|
|
|
585
696
|
functionName: "dlps",
|
|
586
697
|
args: [BigInt(dlpId)]
|
|
587
698
|
});
|
|
588
|
-
if (!dlpData
|
|
699
|
+
if (!dlpData?.name) {
|
|
589
700
|
throw new Error(`DLP not found: ${dlpId}`);
|
|
590
701
|
}
|
|
591
702
|
return {
|
|
@@ -627,7 +738,7 @@ class DataController {
|
|
|
627
738
|
*/
|
|
628
739
|
async listDLPs(options = {}) {
|
|
629
740
|
const { limit = 100, offset = 0 } = options;
|
|
630
|
-
const subgraphUrl = options.subgraphUrl
|
|
741
|
+
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
631
742
|
if (subgraphUrl) {
|
|
632
743
|
try {
|
|
633
744
|
const query = `
|
|
@@ -666,21 +777,21 @@ class DataController {
|
|
|
666
777
|
`Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
667
778
|
);
|
|
668
779
|
}
|
|
669
|
-
const dlps = result.data?.dlps
|
|
780
|
+
const dlps = result.data?.dlps ?? [];
|
|
670
781
|
return dlps.map((dlp) => ({
|
|
671
782
|
id: parseInt(dlp.id),
|
|
672
|
-
name: dlp.name
|
|
783
|
+
name: dlp.name ?? "",
|
|
673
784
|
metadata: dlp.metadata,
|
|
674
785
|
status: dlp.status ? parseInt(dlp.status) : void 0,
|
|
675
|
-
address: dlp.address,
|
|
676
|
-
owner: dlp.owner
|
|
786
|
+
address: dlp.address ? dlp.address : void 0,
|
|
787
|
+
owner: dlp.owner ? dlp.owner : void 0
|
|
677
788
|
}));
|
|
678
789
|
} catch (error) {
|
|
679
790
|
console.debug("Subgraph query failed, falling back to chain:", error);
|
|
680
791
|
}
|
|
681
792
|
}
|
|
682
793
|
try {
|
|
683
|
-
const chainId = this.context.
|
|
794
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
684
795
|
if (!chainId) {
|
|
685
796
|
throw new Error("Chain ID not available");
|
|
686
797
|
}
|
|
@@ -752,7 +863,7 @@ class DataController {
|
|
|
752
863
|
*/
|
|
753
864
|
async getUserPermissions(params) {
|
|
754
865
|
const { user, subgraphUrl } = params;
|
|
755
|
-
const endpoint = subgraphUrl
|
|
866
|
+
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
756
867
|
if (endpoint) {
|
|
757
868
|
try {
|
|
758
869
|
const permissions = await this._getUserPermissionsViaSubgraph({
|
|
@@ -801,7 +912,7 @@ class DataController {
|
|
|
801
912
|
);
|
|
802
913
|
}
|
|
803
914
|
const userData = result.data?.user;
|
|
804
|
-
if (!userData
|
|
915
|
+
if (!userData?.permissions?.length) {
|
|
805
916
|
return [];
|
|
806
917
|
}
|
|
807
918
|
return userData.permissions.map((permission) => ({
|
|
@@ -829,7 +940,7 @@ class DataController {
|
|
|
829
940
|
async _getUserPermissionsViaRpc(params) {
|
|
830
941
|
const { user } = params;
|
|
831
942
|
try {
|
|
832
|
-
const chainId = this.context.
|
|
943
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
833
944
|
if (!chainId) {
|
|
834
945
|
throw new Error("Chain ID not available");
|
|
835
946
|
}
|
|
@@ -948,7 +1059,7 @@ class DataController {
|
|
|
948
1059
|
*/
|
|
949
1060
|
async getUserTrustedServers(params) {
|
|
950
1061
|
const { user, limit = 50, offset = 0 } = params;
|
|
951
|
-
const subgraphUrl = params.subgraphUrl
|
|
1062
|
+
const subgraphUrl = params.subgraphUrl ?? this.context.subgraphUrl;
|
|
952
1063
|
if (subgraphUrl) {
|
|
953
1064
|
try {
|
|
954
1065
|
const servers = await this._getUserTrustedServersViaSubgraph({
|
|
@@ -1011,7 +1122,7 @@ class DataController {
|
|
|
1011
1122
|
if (!result.data?.user) {
|
|
1012
1123
|
return [];
|
|
1013
1124
|
}
|
|
1014
|
-
return (result.data.user.serverTrusts
|
|
1125
|
+
return (result.data.user.serverTrusts ?? []).filter((trust) => !trust.untrustedAtBlock).map((trust) => ({
|
|
1015
1126
|
id: trust.server.id,
|
|
1016
1127
|
serverAddress: trust.server.serverAddress,
|
|
1017
1128
|
serverUrl: trust.server.url,
|
|
@@ -1037,7 +1148,7 @@ class DataController {
|
|
|
1037
1148
|
async _getUserTrustedServersViaRpc(params) {
|
|
1038
1149
|
const { user, limit, offset } = params;
|
|
1039
1150
|
try {
|
|
1040
|
-
const chainId = this.context.
|
|
1151
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1041
1152
|
if (!chainId) {
|
|
1042
1153
|
throw new Error("Chain ID not available");
|
|
1043
1154
|
}
|
|
@@ -1137,7 +1248,7 @@ class DataController {
|
|
|
1137
1248
|
*/
|
|
1138
1249
|
async getTotalFilesCount() {
|
|
1139
1250
|
try {
|
|
1140
|
-
const chainId = this.context.
|
|
1251
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1141
1252
|
if (!chainId) {
|
|
1142
1253
|
throw new Error("Chain ID not available");
|
|
1143
1254
|
}
|
|
@@ -1146,7 +1257,7 @@ class DataController {
|
|
|
1146
1257
|
const dataRegistry = (0, import_viem.getContract)({
|
|
1147
1258
|
address: dataRegistryAddress,
|
|
1148
1259
|
abi: dataRegistryAbi,
|
|
1149
|
-
client: this.context.
|
|
1260
|
+
client: this.context.publicClient
|
|
1150
1261
|
});
|
|
1151
1262
|
const count = await dataRegistry.read.filesCount();
|
|
1152
1263
|
return Number(count);
|
|
@@ -1188,7 +1299,7 @@ class DataController {
|
|
|
1188
1299
|
*/
|
|
1189
1300
|
async getFileById(fileId) {
|
|
1190
1301
|
try {
|
|
1191
|
-
const chainId = this.context.
|
|
1302
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1192
1303
|
if (!chainId) {
|
|
1193
1304
|
throw new Error("Chain ID not available");
|
|
1194
1305
|
}
|
|
@@ -1197,7 +1308,7 @@ class DataController {
|
|
|
1197
1308
|
const dataRegistry = (0, import_viem.getContract)({
|
|
1198
1309
|
address: dataRegistryAddress,
|
|
1199
1310
|
abi: dataRegistryAbi,
|
|
1200
|
-
client: this.context.
|
|
1311
|
+
client: this.context.publicClient
|
|
1201
1312
|
});
|
|
1202
1313
|
const fileDetails = await dataRegistry.read.files([BigInt(fileId)]);
|
|
1203
1314
|
if (!fileDetails) {
|
|
@@ -1256,34 +1367,32 @@ class DataController {
|
|
|
1256
1367
|
* ```
|
|
1257
1368
|
*/
|
|
1258
1369
|
async registerFileWithSchema(url, schemaId) {
|
|
1370
|
+
this.assertWallet();
|
|
1259
1371
|
try {
|
|
1260
|
-
const chainId = this.context.
|
|
1372
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1261
1373
|
if (!chainId) {
|
|
1262
1374
|
throw new Error("Chain ID not available");
|
|
1263
1375
|
}
|
|
1376
|
+
this.assertWallet();
|
|
1264
1377
|
const dataRegistryAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
1265
1378
|
const dataRegistryAbi = (0, import_abi.getAbi)("DataRegistry");
|
|
1266
|
-
const
|
|
1267
|
-
const
|
|
1379
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1380
|
+
const from = typeof account === "string" ? account : account.address;
|
|
1381
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1268
1382
|
address: dataRegistryAddress,
|
|
1269
1383
|
abi: dataRegistryAbi,
|
|
1270
1384
|
functionName: "addFileWithSchema",
|
|
1271
1385
|
args: [url, BigInt(schemaId)],
|
|
1272
|
-
account
|
|
1273
|
-
chain: this.context.walletClient.chain
|
|
1386
|
+
account,
|
|
1387
|
+
chain: this.context.walletClient.chain ?? null
|
|
1388
|
+
});
|
|
1389
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
1390
|
+
return tx({
|
|
1391
|
+
hash,
|
|
1392
|
+
from,
|
|
1393
|
+
contract: "DataRegistry",
|
|
1394
|
+
fn: "addFileWithSchema"
|
|
1274
1395
|
});
|
|
1275
|
-
const receipt = await this.context.publicClient.waitForTransactionReceipt(
|
|
1276
|
-
{
|
|
1277
|
-
hash: txHash,
|
|
1278
|
-
confirmations: 1
|
|
1279
|
-
}
|
|
1280
|
-
);
|
|
1281
|
-
const { parseFileAddedEvent } = await import("../utils/eventParsing");
|
|
1282
|
-
const eventData = parseFileAddedEvent(receipt);
|
|
1283
|
-
return {
|
|
1284
|
-
fileId: Number(eventData.fileId),
|
|
1285
|
-
transactionHash: txHash
|
|
1286
|
-
};
|
|
1287
1396
|
} catch (error) {
|
|
1288
1397
|
console.error("Failed to register file with schema:", error);
|
|
1289
1398
|
throw new Error(
|
|
@@ -1297,13 +1406,6 @@ class DataController {
|
|
|
1297
1406
|
* @returns Promise resolving to the user's wallet address
|
|
1298
1407
|
* @throws {Error} When no addresses are available in wallet client
|
|
1299
1408
|
*/
|
|
1300
|
-
async getUserAddress() {
|
|
1301
|
-
const addresses = await this.context.walletClient.getAddresses();
|
|
1302
|
-
if (addresses.length === 0) {
|
|
1303
|
-
throw new Error("No addresses available in wallet client");
|
|
1304
|
-
}
|
|
1305
|
-
return addresses[0];
|
|
1306
|
-
}
|
|
1307
1409
|
/**
|
|
1308
1410
|
* Adds a file with permissions to the DataRegistry contract.
|
|
1309
1411
|
*
|
|
@@ -1321,33 +1423,32 @@ class DataController {
|
|
|
1321
1423
|
* by both direct transactions and relayer services.
|
|
1322
1424
|
*/
|
|
1323
1425
|
async addFileWithPermissions(url, ownerAddress, permissions = []) {
|
|
1426
|
+
this.assertWallet();
|
|
1324
1427
|
try {
|
|
1325
|
-
const chainId = this.context.
|
|
1428
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1326
1429
|
if (!chainId) {
|
|
1327
1430
|
throw new Error("Chain ID not available");
|
|
1328
1431
|
}
|
|
1432
|
+
this.assertWallet();
|
|
1329
1433
|
const dataRegistryAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
1330
1434
|
const dataRegistryAbi = (0, import_abi.getAbi)("DataRegistry");
|
|
1331
|
-
const
|
|
1435
|
+
const account = this.context.walletClient.account ?? ownerAddress;
|
|
1436
|
+
const from = typeof account === "string" ? account : account.address;
|
|
1437
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1332
1438
|
address: dataRegistryAddress,
|
|
1333
1439
|
abi: dataRegistryAbi,
|
|
1334
1440
|
functionName: "addFileWithPermissions",
|
|
1335
1441
|
args: [url, ownerAddress, permissions],
|
|
1336
|
-
account
|
|
1337
|
-
chain: this.context.walletClient.chain
|
|
1442
|
+
account,
|
|
1443
|
+
chain: this.context.walletClient.chain ?? null
|
|
1444
|
+
});
|
|
1445
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
1446
|
+
return tx({
|
|
1447
|
+
hash,
|
|
1448
|
+
from,
|
|
1449
|
+
contract: "DataRegistry",
|
|
1450
|
+
fn: "addFileWithPermissions"
|
|
1338
1451
|
});
|
|
1339
|
-
const receipt = await this.context.publicClient.waitForTransactionReceipt(
|
|
1340
|
-
{
|
|
1341
|
-
hash: txHash,
|
|
1342
|
-
confirmations: 1
|
|
1343
|
-
}
|
|
1344
|
-
);
|
|
1345
|
-
const { parseFileAddedEvent } = await import("../utils/eventParsing");
|
|
1346
|
-
const eventData = parseFileAddedEvent(receipt);
|
|
1347
|
-
return {
|
|
1348
|
-
fileId: Number(eventData.fileId),
|
|
1349
|
-
transactionHash: txHash
|
|
1350
|
-
};
|
|
1351
1452
|
} catch (error) {
|
|
1352
1453
|
console.error("Failed to add file with permissions:", error);
|
|
1353
1454
|
throw new Error(
|
|
@@ -1359,44 +1460,148 @@ class DataController {
|
|
|
1359
1460
|
* Adds a file to the registry with permissions and schema.
|
|
1360
1461
|
* This combines the functionality of addFileWithPermissions and schema validation.
|
|
1361
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
|
+
*
|
|
1362
1468
|
* @param url - The URL of the file to register
|
|
1363
1469
|
* @param ownerAddress - The address of the file owner
|
|
1364
|
-
* @param permissions - Array of permissions to grant
|
|
1470
|
+
* @param permissions - Array of permissions to grant, each with account and publicKey properties
|
|
1365
1471
|
* @param schemaId - The schema ID to associate with the file (0 for no schema)
|
|
1366
|
-
* @returns Promise resolving to
|
|
1367
|
-
* @throws {Error} When chain
|
|
1368
|
-
* @throws {
|
|
1369
|
-
* @throws {Error} When
|
|
1370
|
-
* @throws {Error}
|
|
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
|
+
* ```
|
|
1371
1497
|
*/
|
|
1372
1498
|
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1499
|
+
this.assertWallet();
|
|
1500
|
+
try {
|
|
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) {
|
|
1373
1580
|
try {
|
|
1374
|
-
const chainId = this.context.
|
|
1581
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1375
1582
|
if (!chainId) {
|
|
1376
1583
|
throw new Error("Chain ID not available");
|
|
1377
1584
|
}
|
|
1585
|
+
this.assertWallet();
|
|
1378
1586
|
const dataRegistryAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
1379
1587
|
const dataRegistryAbi = (0, import_abi.getAbi)("DataRegistry");
|
|
1380
|
-
const
|
|
1588
|
+
const account = this.context.walletClient.account ?? ownerAddress;
|
|
1589
|
+
const from = typeof account === "string" ? account : account.address;
|
|
1590
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1381
1591
|
address: dataRegistryAddress,
|
|
1382
1592
|
abi: dataRegistryAbi,
|
|
1383
1593
|
functionName: "addFileWithPermissionsAndSchema",
|
|
1384
1594
|
args: [url, ownerAddress, permissions, BigInt(schemaId)],
|
|
1385
|
-
account
|
|
1386
|
-
chain: this.context.walletClient.chain
|
|
1595
|
+
account,
|
|
1596
|
+
chain: this.context.walletClient.chain ?? null
|
|
1597
|
+
});
|
|
1598
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
1599
|
+
return tx({
|
|
1600
|
+
hash,
|
|
1601
|
+
from,
|
|
1602
|
+
contract: "DataRegistry",
|
|
1603
|
+
fn: "addFileWithPermissionsAndSchema"
|
|
1387
1604
|
});
|
|
1388
|
-
const receipt = await this.context.publicClient.waitForTransactionReceipt(
|
|
1389
|
-
{
|
|
1390
|
-
hash: txHash,
|
|
1391
|
-
confirmations: 1
|
|
1392
|
-
}
|
|
1393
|
-
);
|
|
1394
|
-
const { parseFileAddedEvent } = await import("../utils/eventParsing");
|
|
1395
|
-
const eventData = parseFileAddedEvent(receipt);
|
|
1396
|
-
return {
|
|
1397
|
-
fileId: Number(eventData.fileId),
|
|
1398
|
-
transactionHash: txHash
|
|
1399
|
-
};
|
|
1400
1605
|
} catch (error) {
|
|
1401
1606
|
console.error("Failed to add file with permissions and schema:", error);
|
|
1402
1607
|
throw new Error(
|
|
@@ -1433,8 +1638,9 @@ class DataController {
|
|
|
1433
1638
|
* ```
|
|
1434
1639
|
*/
|
|
1435
1640
|
async addRefiner(params) {
|
|
1641
|
+
this.assertWallet();
|
|
1436
1642
|
try {
|
|
1437
|
-
const chainId = this.context.
|
|
1643
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1438
1644
|
if (!chainId) {
|
|
1439
1645
|
throw new Error("Chain ID not available");
|
|
1440
1646
|
}
|
|
@@ -1443,7 +1649,10 @@ class DataController {
|
|
|
1443
1649
|
"DataRefinerRegistry"
|
|
1444
1650
|
);
|
|
1445
1651
|
const dataRefinerRegistryAbi = (0, import_abi.getAbi)("DataRefinerRegistry");
|
|
1446
|
-
|
|
1652
|
+
this.assertWallet();
|
|
1653
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1654
|
+
const from = typeof account === "string" ? account : account.address;
|
|
1655
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1447
1656
|
address: dataRefinerRegistryAddress,
|
|
1448
1657
|
abi: dataRefinerRegistryAbi,
|
|
1449
1658
|
functionName: "addRefinerWithSchemaId",
|
|
@@ -1453,20 +1662,27 @@ class DataController {
|
|
|
1453
1662
|
BigInt(params.schemaId),
|
|
1454
1663
|
params.refinementInstructionUrl
|
|
1455
1664
|
],
|
|
1456
|
-
account
|
|
1457
|
-
chain: this.context.walletClient.chain
|
|
1665
|
+
account,
|
|
1666
|
+
chain: this.context.walletClient.chain ?? null
|
|
1458
1667
|
});
|
|
1459
|
-
const
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1668
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
1669
|
+
const txResult = tx({
|
|
1670
|
+
hash,
|
|
1671
|
+
from,
|
|
1672
|
+
contract: "DataRefinerRegistry",
|
|
1673
|
+
fn: "addRefinerWithSchemaId"
|
|
1674
|
+
});
|
|
1675
|
+
if (!this.context.waitForTransactionEvents) {
|
|
1676
|
+
throw new Error("waitForTransactionEvents not configured");
|
|
1677
|
+
}
|
|
1678
|
+
const result = await this.context.waitForTransactionEvents(txResult);
|
|
1679
|
+
const event = result.expectedEvents.RefinerAdded;
|
|
1680
|
+
if (!event) {
|
|
1681
|
+
throw new Error("RefinerAdded event not found in transaction");
|
|
1682
|
+
}
|
|
1467
1683
|
return {
|
|
1468
|
-
refinerId: Number(
|
|
1469
|
-
transactionHash:
|
|
1684
|
+
refinerId: Number(event.refinerId),
|
|
1685
|
+
transactionHash: hash
|
|
1470
1686
|
};
|
|
1471
1687
|
} catch (error) {
|
|
1472
1688
|
console.error("Failed to add refiner:", error);
|
|
@@ -1500,7 +1716,7 @@ class DataController {
|
|
|
1500
1716
|
*/
|
|
1501
1717
|
async getRefiner(refinerId) {
|
|
1502
1718
|
try {
|
|
1503
|
-
const chainId = this.context.
|
|
1719
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1504
1720
|
if (!chainId) {
|
|
1505
1721
|
throw new Error("Chain ID not available");
|
|
1506
1722
|
}
|
|
@@ -1512,7 +1728,7 @@ class DataController {
|
|
|
1512
1728
|
const dataRefinerRegistry = (0, import_viem.getContract)({
|
|
1513
1729
|
address: dataRefinerRegistryAddress,
|
|
1514
1730
|
abi: dataRefinerRegistryAbi,
|
|
1515
|
-
client: this.context.
|
|
1731
|
+
client: this.context.publicClient
|
|
1516
1732
|
});
|
|
1517
1733
|
const refinerData = await dataRefinerRegistry.read.refiners([
|
|
1518
1734
|
BigInt(refinerId)
|
|
@@ -1556,7 +1772,7 @@ class DataController {
|
|
|
1556
1772
|
*/
|
|
1557
1773
|
async isValidSchemaId(schemaId) {
|
|
1558
1774
|
try {
|
|
1559
|
-
const chainId = this.context.
|
|
1775
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1560
1776
|
if (!chainId) {
|
|
1561
1777
|
throw new Error("Chain ID not available");
|
|
1562
1778
|
}
|
|
@@ -1568,7 +1784,7 @@ class DataController {
|
|
|
1568
1784
|
const dataRefinerRegistry = (0, import_viem.getContract)({
|
|
1569
1785
|
address: dataRefinerRegistryAddress,
|
|
1570
1786
|
abi: dataRefinerRegistryAbi,
|
|
1571
|
-
client: this.context.
|
|
1787
|
+
client: this.context.publicClient
|
|
1572
1788
|
});
|
|
1573
1789
|
const isValid = await dataRefinerRegistry.read.isValidSchemaId([
|
|
1574
1790
|
BigInt(schemaId)
|
|
@@ -1595,7 +1811,7 @@ class DataController {
|
|
|
1595
1811
|
*/
|
|
1596
1812
|
async getRefinersCount() {
|
|
1597
1813
|
try {
|
|
1598
|
-
const chainId = this.context.
|
|
1814
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1599
1815
|
if (!chainId) {
|
|
1600
1816
|
throw new Error("Chain ID not available");
|
|
1601
1817
|
}
|
|
@@ -1607,7 +1823,7 @@ class DataController {
|
|
|
1607
1823
|
const dataRefinerRegistry = (0, import_viem.getContract)({
|
|
1608
1824
|
address: dataRefinerRegistryAddress,
|
|
1609
1825
|
abi: dataRefinerRegistryAbi,
|
|
1610
|
-
client: this.context.
|
|
1826
|
+
client: this.context.publicClient
|
|
1611
1827
|
});
|
|
1612
1828
|
const count = await dataRefinerRegistry.read.refinersCount();
|
|
1613
1829
|
return Number(count);
|
|
@@ -1639,8 +1855,9 @@ class DataController {
|
|
|
1639
1855
|
* ```
|
|
1640
1856
|
*/
|
|
1641
1857
|
async updateSchemaId(params) {
|
|
1858
|
+
this.assertWallet();
|
|
1642
1859
|
try {
|
|
1643
|
-
const chainId = this.context.
|
|
1860
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1644
1861
|
if (!chainId) {
|
|
1645
1862
|
throw new Error("Chain ID not available");
|
|
1646
1863
|
}
|
|
@@ -1649,20 +1866,19 @@ class DataController {
|
|
|
1649
1866
|
"DataRefinerRegistry"
|
|
1650
1867
|
);
|
|
1651
1868
|
const dataRefinerRegistryAbi = (0, import_abi.getAbi)("DataRefinerRegistry");
|
|
1652
|
-
|
|
1869
|
+
this.assertWallet();
|
|
1870
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1871
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1653
1872
|
address: dataRefinerRegistryAddress,
|
|
1654
1873
|
abi: dataRefinerRegistryAbi,
|
|
1655
1874
|
functionName: "updateSchemaId",
|
|
1656
1875
|
args: [BigInt(params.refinerId), BigInt(params.newSchemaId)],
|
|
1657
|
-
account
|
|
1658
|
-
chain: this.context.walletClient.chain
|
|
1659
|
-
});
|
|
1660
|
-
await this.context.publicClient.waitForTransactionReceipt({
|
|
1661
|
-
hash: txHash,
|
|
1662
|
-
timeout: 3e4
|
|
1876
|
+
account,
|
|
1877
|
+
chain: this.context.walletClient.chain ?? null
|
|
1663
1878
|
});
|
|
1879
|
+
await this.context.publicClient.waitForTransactionReceipt({ hash });
|
|
1664
1880
|
return {
|
|
1665
|
-
transactionHash:
|
|
1881
|
+
transactionHash: hash
|
|
1666
1882
|
};
|
|
1667
1883
|
} catch (error) {
|
|
1668
1884
|
console.error("Failed to update schema ID:", error);
|
|
@@ -1680,13 +1896,12 @@ class DataController {
|
|
|
1680
1896
|
* 3. Encrypts the user's encryption key with the provided public key
|
|
1681
1897
|
* 4. Registers the file with permissions
|
|
1682
1898
|
*
|
|
1683
|
-
* @param
|
|
1684
|
-
* @param permissions - Array of permissions to grant, each with account address and public key
|
|
1685
|
-
* @param filename - Optional filename for the upload
|
|
1686
|
-
* @param providerName - Optional storage provider to use
|
|
1899
|
+
* @param params - Upload parameters including data, permissions, and options
|
|
1687
1900
|
* @returns Promise resolving to upload result with file ID and storage URL
|
|
1688
1901
|
*/
|
|
1689
|
-
async uploadFileWithPermissions(
|
|
1902
|
+
async uploadFileWithPermissions(params) {
|
|
1903
|
+
this.assertWallet();
|
|
1904
|
+
const { data, permissions, filename, providerName } = params;
|
|
1690
1905
|
try {
|
|
1691
1906
|
const uploadResult = await this.uploadToStorage(
|
|
1692
1907
|
data,
|
|
@@ -1695,7 +1910,7 @@ class DataController {
|
|
|
1695
1910
|
// Always encrypt for uploadFileWithPermissions
|
|
1696
1911
|
providerName
|
|
1697
1912
|
);
|
|
1698
|
-
const userAddress =
|
|
1913
|
+
const userAddress = this.context.userAddress;
|
|
1699
1914
|
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
1700
1915
|
this.context.walletClient,
|
|
1701
1916
|
this.context.platform,
|
|
@@ -1714,26 +1929,41 @@ class DataController {
|
|
|
1714
1929
|
};
|
|
1715
1930
|
})
|
|
1716
1931
|
);
|
|
1717
|
-
let result;
|
|
1718
1932
|
if (this.context.relayerCallbacks?.submitFileAdditionWithPermissions) {
|
|
1719
|
-
result = await this.context.relayerCallbacks.submitFileAdditionWithPermissions(
|
|
1933
|
+
const result = await this.context.relayerCallbacks.submitFileAdditionWithPermissions(
|
|
1720
1934
|
uploadResult.url,
|
|
1721
1935
|
userAddress,
|
|
1722
1936
|
encryptedPermissions
|
|
1723
1937
|
);
|
|
1938
|
+
return {
|
|
1939
|
+
fileId: result.fileId,
|
|
1940
|
+
url: uploadResult.url,
|
|
1941
|
+
size: uploadResult.size,
|
|
1942
|
+
transactionHash: result.transactionHash
|
|
1943
|
+
};
|
|
1724
1944
|
} else {
|
|
1725
|
-
|
|
1945
|
+
const txResult = await this.addFileWithPermissions(
|
|
1726
1946
|
uploadResult.url,
|
|
1727
1947
|
userAddress,
|
|
1728
1948
|
encryptedPermissions
|
|
1729
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
|
+
}
|
|
1960
|
+
return {
|
|
1961
|
+
fileId: Number(fileAddedEvent.fileId),
|
|
1962
|
+
url: uploadResult.url,
|
|
1963
|
+
size: uploadResult.size,
|
|
1964
|
+
transactionHash: txResult.hash
|
|
1965
|
+
};
|
|
1730
1966
|
}
|
|
1731
|
-
return {
|
|
1732
|
-
fileId: result.fileId,
|
|
1733
|
-
url: uploadResult.url,
|
|
1734
|
-
size: uploadResult.size,
|
|
1735
|
-
transactionHash: result.transactionHash
|
|
1736
|
-
};
|
|
1737
1967
|
} catch (error) {
|
|
1738
1968
|
console.error("Failed to upload file with permissions:", error);
|
|
1739
1969
|
throw new Error(
|
|
@@ -1771,6 +2001,7 @@ class DataController {
|
|
|
1771
2001
|
}
|
|
1772
2002
|
let finalBlob = blob;
|
|
1773
2003
|
if (encrypt) {
|
|
2004
|
+
this.assertWallet();
|
|
1774
2005
|
const encryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
1775
2006
|
this.context.walletClient,
|
|
1776
2007
|
this.context.platform,
|
|
@@ -1792,7 +2023,7 @@ class DataController {
|
|
|
1792
2023
|
);
|
|
1793
2024
|
}
|
|
1794
2025
|
}
|
|
1795
|
-
const finalFilename = filename
|
|
2026
|
+
const finalFilename = filename ?? `upload-${Date.now()}.dat`;
|
|
1796
2027
|
const uploadResult = await this.context.storageManager.upload(
|
|
1797
2028
|
finalBlob,
|
|
1798
2029
|
finalFilename,
|
|
@@ -1817,21 +2048,29 @@ class DataController {
|
|
|
1817
2048
|
* For advanced users who need more control over transaction timing,
|
|
1818
2049
|
* use `submitFilePermission()` instead.
|
|
1819
2050
|
*
|
|
1820
|
-
* @param
|
|
1821
|
-
* @param
|
|
1822
|
-
* @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`
|
|
1823
2056
|
* @returns Promise resolving to permission data from PermissionGranted event
|
|
1824
2057
|
* @throws {Error} "No addresses available in wallet client" - When wallet is not connected
|
|
1825
2058
|
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1826
2059
|
* @throws {Error} "Failed to add permission to file: {error}" - When transaction fails or user doesn't own file
|
|
1827
2060
|
* @example
|
|
1828
2061
|
* ```typescript
|
|
1829
|
-
* const result = await vana.data.addPermissionToFile(
|
|
2062
|
+
* const result = await vana.data.addPermissionToFile({
|
|
2063
|
+
* fileId: 123,
|
|
2064
|
+
* account: "0xRecipientAddress...",
|
|
2065
|
+
* publicKey: "0xRecipientPublicKey..."
|
|
2066
|
+
* });
|
|
1830
2067
|
* console.log(`Permission granted to ${result.account} for file ${result.fileId}`);
|
|
1831
2068
|
* console.log(`Transaction: ${result.transactionHash}`);
|
|
1832
2069
|
* ```
|
|
1833
2070
|
*/
|
|
1834
|
-
async addPermissionToFile(
|
|
2071
|
+
async addPermissionToFile(params) {
|
|
2072
|
+
this.assertWallet();
|
|
2073
|
+
const { fileId, account, publicKey } = params;
|
|
1835
2074
|
return await this.submitFilePermission(fileId, account, publicKey);
|
|
1836
2075
|
}
|
|
1837
2076
|
/**
|
|
@@ -1845,7 +2084,7 @@ class DataController {
|
|
|
1845
2084
|
* @param fileId - The ID of the file to grant permission for
|
|
1846
2085
|
* @param account - The recipient's wallet address that will access the file
|
|
1847
2086
|
* @param publicKey - The recipient's public key for encryption.
|
|
1848
|
-
* Obtain via `vana.server.getIdentity(account).
|
|
2087
|
+
* Obtain via `vana.server.getIdentity(account).publicKey`
|
|
1849
2088
|
* @returns Promise resolving to TransactionResult for tracking the transaction
|
|
1850
2089
|
* @throws {Error} When chain ID is not available
|
|
1851
2090
|
* @throws {Error} When encryption key generation fails
|
|
@@ -1863,6 +2102,7 @@ class DataController {
|
|
|
1863
2102
|
* ```
|
|
1864
2103
|
*/
|
|
1865
2104
|
async submitFilePermission(fileId, account, publicKey) {
|
|
2105
|
+
this.assertWallet();
|
|
1866
2106
|
try {
|
|
1867
2107
|
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
1868
2108
|
this.context.walletClient,
|
|
@@ -1874,24 +2114,29 @@ class DataController {
|
|
|
1874
2114
|
publicKey,
|
|
1875
2115
|
this.context.platform
|
|
1876
2116
|
);
|
|
1877
|
-
const chainId = this.context.
|
|
2117
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1878
2118
|
if (!chainId) {
|
|
1879
2119
|
throw new Error("Chain ID not available");
|
|
1880
2120
|
}
|
|
1881
2121
|
const dataRegistryAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
1882
2122
|
const dataRegistryAbi = (0, import_abi.getAbi)("DataRegistry");
|
|
2123
|
+
this.assertWallet();
|
|
2124
|
+
const walletAccount = this.context.walletClient.account ?? this.context.userAddress;
|
|
1883
2125
|
const txHash = await this.context.walletClient.writeContract({
|
|
1884
2126
|
address: dataRegistryAddress,
|
|
1885
2127
|
abi: dataRegistryAbi,
|
|
1886
2128
|
functionName: "addFilePermission",
|
|
1887
2129
|
args: [BigInt(fileId), account, encryptedKey],
|
|
1888
|
-
account:
|
|
1889
|
-
chain: this.context.walletClient.chain
|
|
2130
|
+
account: walletAccount,
|
|
2131
|
+
chain: this.context.walletClient.chain ?? null
|
|
1890
2132
|
});
|
|
1891
|
-
|
|
2133
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
2134
|
+
return tx({
|
|
1892
2135
|
hash: txHash,
|
|
1893
|
-
from:
|
|
1894
|
-
|
|
2136
|
+
from: typeof walletAccount === "string" ? walletAccount : walletAccount.address,
|
|
2137
|
+
contract: "DataRegistry",
|
|
2138
|
+
fn: "addFilePermission"
|
|
2139
|
+
});
|
|
1895
2140
|
} catch (error) {
|
|
1896
2141
|
console.error("Failed to add permission to file:", error);
|
|
1897
2142
|
throw new Error(
|
|
@@ -1908,7 +2153,7 @@ class DataController {
|
|
|
1908
2153
|
*/
|
|
1909
2154
|
async getFilePermission(fileId, account) {
|
|
1910
2155
|
try {
|
|
1911
|
-
const chainId = this.context.
|
|
2156
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1912
2157
|
if (!chainId) {
|
|
1913
2158
|
throw new Error("Chain ID not available");
|
|
1914
2159
|
}
|
|
@@ -1917,7 +2162,7 @@ class DataController {
|
|
|
1917
2162
|
const dataRegistry = (0, import_viem.getContract)({
|
|
1918
2163
|
address: dataRegistryAddress,
|
|
1919
2164
|
abi: dataRegistryAbi,
|
|
1920
|
-
client: this.context.
|
|
2165
|
+
client: this.context.publicClient
|
|
1921
2166
|
});
|
|
1922
2167
|
const encryptedKey = await dataRegistry.read.filePermissions([
|
|
1923
2168
|
BigInt(fileId),
|
|
@@ -1941,12 +2186,13 @@ class DataController {
|
|
|
1941
2186
|
*
|
|
1942
2187
|
* @param file - The file to decrypt
|
|
1943
2188
|
* @param privateKey - The private key to decrypt the user's encryption key
|
|
1944
|
-
* @param
|
|
2189
|
+
* @param options - Optional decryption configuration
|
|
2190
|
+
* @param options.account - The account address that has permission (defaults to current wallet account)
|
|
1945
2191
|
* @returns Promise resolving to the decrypted file data
|
|
1946
2192
|
*/
|
|
1947
|
-
async decryptFileWithPermission(file, privateKey,
|
|
2193
|
+
async decryptFileWithPermission(file, privateKey, options) {
|
|
1948
2194
|
try {
|
|
1949
|
-
const permissionAccount = account
|
|
2195
|
+
const permissionAccount = options?.account ?? this.context.userAddress;
|
|
1950
2196
|
const encryptedKey = await this.getFilePermission(
|
|
1951
2197
|
file.id,
|
|
1952
2198
|
permissionAccount
|
|
@@ -2010,11 +2256,8 @@ class DataController {
|
|
|
2010
2256
|
*/
|
|
2011
2257
|
async fetch(url) {
|
|
2012
2258
|
try {
|
|
2013
|
-
const {
|
|
2014
|
-
const response = await
|
|
2015
|
-
url,
|
|
2016
|
-
this.context.downloadRelayer
|
|
2017
|
-
);
|
|
2259
|
+
const { universalFetch } = await import("../utils/download");
|
|
2260
|
+
const response = await universalFetch(url, this.context.downloadRelayer);
|
|
2018
2261
|
if (!response.ok) {
|
|
2019
2262
|
throw new Error(
|
|
2020
2263
|
`HTTP error! status: ${response.status} ${response.statusText}`
|
|
@@ -2079,7 +2322,7 @@ class DataController {
|
|
|
2079
2322
|
"https://dweb.link/ipfs/",
|
|
2080
2323
|
"https://ipfs.io/ipfs/"
|
|
2081
2324
|
];
|
|
2082
|
-
const gateways = options?.gateways
|
|
2325
|
+
const gateways = options?.gateways ?? this.context.ipfsGateways ?? defaultGateways;
|
|
2083
2326
|
const { extractIpfsHash } = await import("../utils/ipfs");
|
|
2084
2327
|
const cid = extractIpfsHash(url);
|
|
2085
2328
|
if (!cid) {
|
|
@@ -2208,7 +2451,7 @@ class DataController {
|
|
|
2208
2451
|
* ```
|
|
2209
2452
|
*/
|
|
2210
2453
|
validateDataAgainstSchema(data, schema) {
|
|
2211
|
-
|
|
2454
|
+
(0, import_schemaValidation.validateDataAgainstSchema)(data, schema);
|
|
2212
2455
|
}
|
|
2213
2456
|
/**
|
|
2214
2457
|
* Fetches and validates a data schema from a URL, then returns the parsed data schema.
|