@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
package/dist/controllers/data.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getContract } from "viem";
|
|
2
|
+
import { BaseController } from "./base";
|
|
2
3
|
import { getContractAddress } from "../config/addresses";
|
|
3
4
|
import { getAbi } from "../generated/abi";
|
|
4
5
|
import {
|
|
@@ -23,11 +24,12 @@ import {
|
|
|
23
24
|
fetchAndValidateSchema
|
|
24
25
|
} from "../utils/schemaValidation";
|
|
25
26
|
import { gasAwareMulticall } from "../utils/multicall";
|
|
26
|
-
class DataController {
|
|
27
|
+
class DataController extends BaseController {
|
|
27
28
|
constructor(context) {
|
|
28
|
-
|
|
29
|
+
super(context);
|
|
29
30
|
}
|
|
30
31
|
async upload(params) {
|
|
32
|
+
this.assertWallet();
|
|
31
33
|
const {
|
|
32
34
|
content,
|
|
33
35
|
filename,
|
|
@@ -52,15 +54,29 @@ class DataController {
|
|
|
52
54
|
} catch {
|
|
53
55
|
parsedContent = content;
|
|
54
56
|
}
|
|
57
|
+
} else if (content instanceof Blob) {
|
|
58
|
+
const text = await content.text();
|
|
59
|
+
try {
|
|
60
|
+
parsedContent = JSON.parse(text);
|
|
61
|
+
} catch {
|
|
62
|
+
parsedContent = text;
|
|
63
|
+
}
|
|
55
64
|
} else {
|
|
56
65
|
parsedContent = content;
|
|
57
66
|
}
|
|
58
67
|
validateDataAgainstSchema(parsedContent, schema);
|
|
59
68
|
} catch (error) {
|
|
60
69
|
isValid = false;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
if (error instanceof Error) {
|
|
71
|
+
const errorDetails = error.errors;
|
|
72
|
+
if (errorDetails && Array.isArray(errorDetails)) {
|
|
73
|
+
validationErrors = errorDetails;
|
|
74
|
+
} else {
|
|
75
|
+
validationErrors = [error.message];
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
validationErrors = ["Schema validation failed"];
|
|
79
|
+
}
|
|
64
80
|
}
|
|
65
81
|
}
|
|
66
82
|
const uploadResult = await this.uploadToStorage(
|
|
@@ -69,9 +85,10 @@ class DataController {
|
|
|
69
85
|
encrypt,
|
|
70
86
|
providerName
|
|
71
87
|
);
|
|
72
|
-
const userAddress = owner
|
|
88
|
+
const userAddress = owner ?? this.context.userAddress;
|
|
73
89
|
let encryptedPermissions = [];
|
|
74
90
|
if (permissions.length > 0 && encrypt) {
|
|
91
|
+
this.assertWallet();
|
|
75
92
|
const userEncryptionKey = await generateEncryptionKey(
|
|
76
93
|
this.context.walletClient,
|
|
77
94
|
this.context.platform,
|
|
@@ -98,7 +115,7 @@ class DataController {
|
|
|
98
115
|
url: uploadResult.url,
|
|
99
116
|
userAddress,
|
|
100
117
|
permissions: encryptedPermissions,
|
|
101
|
-
schemaId: schemaId
|
|
118
|
+
schemaId: schemaId ?? 0,
|
|
102
119
|
ownerAddress: owner
|
|
103
120
|
}
|
|
104
121
|
);
|
|
@@ -114,12 +131,26 @@ class DataController {
|
|
|
114
131
|
userAddress
|
|
115
132
|
);
|
|
116
133
|
} else {
|
|
117
|
-
|
|
134
|
+
const txResult = await this.addFileWithEncryptedPermissionsAndSchema(
|
|
118
135
|
uploadResult.url,
|
|
119
136
|
userAddress,
|
|
120
137
|
encryptedPermissions,
|
|
121
|
-
schemaId
|
|
138
|
+
schemaId ?? 0
|
|
122
139
|
);
|
|
140
|
+
if (!this.context.waitForTransactionEvents) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
"Cannot upload without relay: waitForTransactionEvents not configured"
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
const eventResult = await this.context.waitForTransactionEvents(txResult);
|
|
146
|
+
const fileAddedEvent = eventResult.expectedEvents.FileAdded;
|
|
147
|
+
if (!fileAddedEvent) {
|
|
148
|
+
throw new Error("FileAdded event not found in transaction");
|
|
149
|
+
}
|
|
150
|
+
result = {
|
|
151
|
+
fileId: Number(fileAddedEvent.fileId),
|
|
152
|
+
transactionHash: txResult.hash
|
|
153
|
+
};
|
|
123
154
|
}
|
|
124
155
|
return {
|
|
125
156
|
fileId: result.fileId,
|
|
@@ -135,6 +166,83 @@ class DataController {
|
|
|
135
166
|
);
|
|
136
167
|
}
|
|
137
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Encrypts data using wallet-derived encryption.
|
|
171
|
+
*
|
|
172
|
+
* @remarks
|
|
173
|
+
* This method provides secure, wallet-based encryption for data before uploading
|
|
174
|
+
* to the Vana network. It's the counterpart to decryptFile for preparing data
|
|
175
|
+
* for secure storage.
|
|
176
|
+
*
|
|
177
|
+
* The method automatically:
|
|
178
|
+
* - Generates an encryption key from the user's wallet signature
|
|
179
|
+
* - Converts the input data to a Blob if necessary
|
|
180
|
+
* - Encrypts the data using the generated key
|
|
181
|
+
* - Returns both the encrypted data and the encryption key
|
|
182
|
+
*
|
|
183
|
+
* The encryption key returned can be stored and later used for decryption,
|
|
184
|
+
* or shared with others to grant them decryption access.
|
|
185
|
+
*
|
|
186
|
+
* @param data - The data to encrypt (Blob, string, or object)
|
|
187
|
+
* @param options - Optional encryption configuration
|
|
188
|
+
* @returns Promise resolving to encrypted data and the encryption key used
|
|
189
|
+
* @throws {Error} When wallet is not connected or encryption fails
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* // Encrypt a string
|
|
193
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
194
|
+
* "My secret data"
|
|
195
|
+
* );
|
|
196
|
+
*
|
|
197
|
+
* // Encrypt JSON with custom MIME type
|
|
198
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
199
|
+
* { name: "Alice", age: 30 },
|
|
200
|
+
* { mimeType: "application/json" }
|
|
201
|
+
* );
|
|
202
|
+
*
|
|
203
|
+
* // With custom encryption seed
|
|
204
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
205
|
+
* "Secret message",
|
|
206
|
+
* { seed: "My custom encryption seed" }
|
|
207
|
+
* );
|
|
208
|
+
*
|
|
209
|
+
* // Upload the encrypted data
|
|
210
|
+
* const result = await vana.data.uploadToStorage(encryptedData);
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
async encryptFile(data, options) {
|
|
214
|
+
this.assertWallet();
|
|
215
|
+
try {
|
|
216
|
+
const encryptionKey = await generateEncryptionKey(
|
|
217
|
+
this.context.walletClient,
|
|
218
|
+
this.context.platform,
|
|
219
|
+
options?.seed ?? DEFAULT_ENCRYPTION_SEED
|
|
220
|
+
);
|
|
221
|
+
let blob;
|
|
222
|
+
if (data instanceof Blob) {
|
|
223
|
+
blob = data;
|
|
224
|
+
} else if (typeof data === "string") {
|
|
225
|
+
blob = new Blob([data], { type: options?.mimeType ?? "text/plain" });
|
|
226
|
+
} else {
|
|
227
|
+
blob = new Blob([JSON.stringify(data)], {
|
|
228
|
+
type: options?.mimeType ?? "application/json"
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
const encryptedData = await encryptBlobWithSignedKey(
|
|
232
|
+
blob,
|
|
233
|
+
encryptionKey,
|
|
234
|
+
this.context.platform
|
|
235
|
+
);
|
|
236
|
+
return {
|
|
237
|
+
encryptedData,
|
|
238
|
+
encryptionKey
|
|
239
|
+
};
|
|
240
|
+
} catch (error) {
|
|
241
|
+
throw new Error(
|
|
242
|
+
`Failed to encrypt file: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
138
246
|
/**
|
|
139
247
|
* Decrypts a file owned by the user using their wallet signature.
|
|
140
248
|
*
|
|
@@ -190,12 +298,14 @@ class DataController {
|
|
|
190
298
|
* fs.writeFileSync('decrypted-file.txt', Buffer.from(buffer));
|
|
191
299
|
* ```
|
|
192
300
|
*/
|
|
193
|
-
async decryptFile(file,
|
|
301
|
+
async decryptFile(file, options) {
|
|
302
|
+
this.assertWallet();
|
|
194
303
|
try {
|
|
304
|
+
this.assertWallet();
|
|
195
305
|
const encryptionKey = await generateEncryptionKey(
|
|
196
306
|
this.context.walletClient,
|
|
197
307
|
this.context.platform,
|
|
198
|
-
|
|
308
|
+
options?.seed ?? DEFAULT_ENCRYPTION_SEED
|
|
199
309
|
);
|
|
200
310
|
let encryptedBlob;
|
|
201
311
|
try {
|
|
@@ -312,7 +422,7 @@ class DataController {
|
|
|
312
422
|
*/
|
|
313
423
|
async getUserFiles(params) {
|
|
314
424
|
const { owner, subgraphUrl } = params;
|
|
315
|
-
const endpoint = subgraphUrl
|
|
425
|
+
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
316
426
|
if (!endpoint) {
|
|
317
427
|
throw new Error(
|
|
318
428
|
"subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor."
|
|
@@ -344,7 +454,7 @@ class DataController {
|
|
|
344
454
|
);
|
|
345
455
|
}
|
|
346
456
|
const user = result.data?.user;
|
|
347
|
-
if (!user
|
|
457
|
+
if (!user?.files?.length) {
|
|
348
458
|
console.warn("No files found for user:", owner);
|
|
349
459
|
return [];
|
|
350
460
|
}
|
|
@@ -366,7 +476,7 @@ class DataController {
|
|
|
366
476
|
}
|
|
367
477
|
});
|
|
368
478
|
const userFiles = Array.from(fileMap.values()).sort(
|
|
369
|
-
(a, b) => Number((b.addedAtTimestamp
|
|
479
|
+
(a, b) => Number((b.addedAtTimestamp ?? 0n) - (a.addedAtTimestamp ?? 0n))
|
|
370
480
|
);
|
|
371
481
|
if (userFiles.length > 0) {
|
|
372
482
|
try {
|
|
@@ -437,10 +547,11 @@ class DataController {
|
|
|
437
547
|
if (proof.dlp?.id) {
|
|
438
548
|
const fileId = parseInt(proof.fileId);
|
|
439
549
|
const dlpId = parseInt(proof.dlp.id);
|
|
440
|
-
|
|
441
|
-
|
|
550
|
+
let dlpIds = proofMap.get(fileId);
|
|
551
|
+
if (!dlpIds) {
|
|
552
|
+
dlpIds = [];
|
|
553
|
+
proofMap.set(fileId, dlpIds);
|
|
442
554
|
}
|
|
443
|
-
const dlpIds = proofMap.get(fileId);
|
|
444
555
|
if (!dlpIds.includes(dlpId)) {
|
|
445
556
|
dlpIds.push(dlpId);
|
|
446
557
|
}
|
|
@@ -458,7 +569,7 @@ class DataController {
|
|
|
458
569
|
* @returns Map of file IDs to their associated DLP IDs
|
|
459
570
|
*/
|
|
460
571
|
async _fetchProofsFromChain(fileIds) {
|
|
461
|
-
const chainId = this.context.
|
|
572
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
462
573
|
if (!chainId) {
|
|
463
574
|
throw new Error("Chain ID not available");
|
|
464
575
|
}
|
|
@@ -515,7 +626,7 @@ class DataController {
|
|
|
515
626
|
* ```
|
|
516
627
|
*/
|
|
517
628
|
async getDLP(dlpId, options = {}) {
|
|
518
|
-
const subgraphUrl = options.subgraphUrl
|
|
629
|
+
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
519
630
|
if (subgraphUrl) {
|
|
520
631
|
try {
|
|
521
632
|
const response = await fetch(subgraphUrl, {
|
|
@@ -546,18 +657,18 @@ class DataController {
|
|
|
546
657
|
}
|
|
547
658
|
return {
|
|
548
659
|
id: parseInt(result.data.dlp.id),
|
|
549
|
-
name: result.data.dlp.name
|
|
550
|
-
metadata: result.data.dlp.metadata
|
|
660
|
+
name: result.data.dlp.name ?? "",
|
|
661
|
+
metadata: result.data.dlp.metadata ?? void 0,
|
|
551
662
|
status: result.data.dlp.status ? parseInt(result.data.dlp.status) : void 0,
|
|
552
|
-
address: result.data.dlp.address,
|
|
553
|
-
owner: result.data.dlp.owner
|
|
663
|
+
address: result.data.dlp.address ? result.data.dlp.address : void 0,
|
|
664
|
+
owner: result.data.dlp.owner ? result.data.dlp.owner : void 0
|
|
554
665
|
};
|
|
555
666
|
} catch (error) {
|
|
556
667
|
console.debug("Subgraph query failed, falling back to chain:", error);
|
|
557
668
|
}
|
|
558
669
|
}
|
|
559
670
|
try {
|
|
560
|
-
const chainId = this.context.
|
|
671
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
561
672
|
if (!chainId) {
|
|
562
673
|
throw new Error("Chain ID not available");
|
|
563
674
|
}
|
|
@@ -569,7 +680,7 @@ class DataController {
|
|
|
569
680
|
functionName: "dlps",
|
|
570
681
|
args: [BigInt(dlpId)]
|
|
571
682
|
});
|
|
572
|
-
if (!dlpData
|
|
683
|
+
if (!dlpData?.name) {
|
|
573
684
|
throw new Error(`DLP not found: ${dlpId}`);
|
|
574
685
|
}
|
|
575
686
|
return {
|
|
@@ -611,7 +722,7 @@ class DataController {
|
|
|
611
722
|
*/
|
|
612
723
|
async listDLPs(options = {}) {
|
|
613
724
|
const { limit = 100, offset = 0 } = options;
|
|
614
|
-
const subgraphUrl = options.subgraphUrl
|
|
725
|
+
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
615
726
|
if (subgraphUrl) {
|
|
616
727
|
try {
|
|
617
728
|
const query = `
|
|
@@ -650,21 +761,21 @@ class DataController {
|
|
|
650
761
|
`Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
651
762
|
);
|
|
652
763
|
}
|
|
653
|
-
const dlps = result.data?.dlps
|
|
764
|
+
const dlps = result.data?.dlps ?? [];
|
|
654
765
|
return dlps.map((dlp) => ({
|
|
655
766
|
id: parseInt(dlp.id),
|
|
656
|
-
name: dlp.name
|
|
767
|
+
name: dlp.name ?? "",
|
|
657
768
|
metadata: dlp.metadata,
|
|
658
769
|
status: dlp.status ? parseInt(dlp.status) : void 0,
|
|
659
|
-
address: dlp.address,
|
|
660
|
-
owner: dlp.owner
|
|
770
|
+
address: dlp.address ? dlp.address : void 0,
|
|
771
|
+
owner: dlp.owner ? dlp.owner : void 0
|
|
661
772
|
}));
|
|
662
773
|
} catch (error) {
|
|
663
774
|
console.debug("Subgraph query failed, falling back to chain:", error);
|
|
664
775
|
}
|
|
665
776
|
}
|
|
666
777
|
try {
|
|
667
|
-
const chainId = this.context.
|
|
778
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
668
779
|
if (!chainId) {
|
|
669
780
|
throw new Error("Chain ID not available");
|
|
670
781
|
}
|
|
@@ -736,7 +847,7 @@ class DataController {
|
|
|
736
847
|
*/
|
|
737
848
|
async getUserPermissions(params) {
|
|
738
849
|
const { user, subgraphUrl } = params;
|
|
739
|
-
const endpoint = subgraphUrl
|
|
850
|
+
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
740
851
|
if (endpoint) {
|
|
741
852
|
try {
|
|
742
853
|
const permissions = await this._getUserPermissionsViaSubgraph({
|
|
@@ -785,7 +896,7 @@ class DataController {
|
|
|
785
896
|
);
|
|
786
897
|
}
|
|
787
898
|
const userData = result.data?.user;
|
|
788
|
-
if (!userData
|
|
899
|
+
if (!userData?.permissions?.length) {
|
|
789
900
|
return [];
|
|
790
901
|
}
|
|
791
902
|
return userData.permissions.map((permission) => ({
|
|
@@ -813,7 +924,7 @@ class DataController {
|
|
|
813
924
|
async _getUserPermissionsViaRpc(params) {
|
|
814
925
|
const { user } = params;
|
|
815
926
|
try {
|
|
816
|
-
const chainId = this.context.
|
|
927
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
817
928
|
if (!chainId) {
|
|
818
929
|
throw new Error("Chain ID not available");
|
|
819
930
|
}
|
|
@@ -932,7 +1043,7 @@ class DataController {
|
|
|
932
1043
|
*/
|
|
933
1044
|
async getUserTrustedServers(params) {
|
|
934
1045
|
const { user, limit = 50, offset = 0 } = params;
|
|
935
|
-
const subgraphUrl = params.subgraphUrl
|
|
1046
|
+
const subgraphUrl = params.subgraphUrl ?? this.context.subgraphUrl;
|
|
936
1047
|
if (subgraphUrl) {
|
|
937
1048
|
try {
|
|
938
1049
|
const servers = await this._getUserTrustedServersViaSubgraph({
|
|
@@ -995,7 +1106,7 @@ class DataController {
|
|
|
995
1106
|
if (!result.data?.user) {
|
|
996
1107
|
return [];
|
|
997
1108
|
}
|
|
998
|
-
return (result.data.user.serverTrusts
|
|
1109
|
+
return (result.data.user.serverTrusts ?? []).filter((trust) => !trust.untrustedAtBlock).map((trust) => ({
|
|
999
1110
|
id: trust.server.id,
|
|
1000
1111
|
serverAddress: trust.server.serverAddress,
|
|
1001
1112
|
serverUrl: trust.server.url,
|
|
@@ -1021,7 +1132,7 @@ class DataController {
|
|
|
1021
1132
|
async _getUserTrustedServersViaRpc(params) {
|
|
1022
1133
|
const { user, limit, offset } = params;
|
|
1023
1134
|
try {
|
|
1024
|
-
const chainId = this.context.
|
|
1135
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1025
1136
|
if (!chainId) {
|
|
1026
1137
|
throw new Error("Chain ID not available");
|
|
1027
1138
|
}
|
|
@@ -1121,7 +1232,7 @@ class DataController {
|
|
|
1121
1232
|
*/
|
|
1122
1233
|
async getTotalFilesCount() {
|
|
1123
1234
|
try {
|
|
1124
|
-
const chainId = this.context.
|
|
1235
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1125
1236
|
if (!chainId) {
|
|
1126
1237
|
throw new Error("Chain ID not available");
|
|
1127
1238
|
}
|
|
@@ -1130,7 +1241,7 @@ class DataController {
|
|
|
1130
1241
|
const dataRegistry = getContract({
|
|
1131
1242
|
address: dataRegistryAddress,
|
|
1132
1243
|
abi: dataRegistryAbi,
|
|
1133
|
-
client: this.context.
|
|
1244
|
+
client: this.context.publicClient
|
|
1134
1245
|
});
|
|
1135
1246
|
const count = await dataRegistry.read.filesCount();
|
|
1136
1247
|
return Number(count);
|
|
@@ -1172,7 +1283,7 @@ class DataController {
|
|
|
1172
1283
|
*/
|
|
1173
1284
|
async getFileById(fileId) {
|
|
1174
1285
|
try {
|
|
1175
|
-
const chainId = this.context.
|
|
1286
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1176
1287
|
if (!chainId) {
|
|
1177
1288
|
throw new Error("Chain ID not available");
|
|
1178
1289
|
}
|
|
@@ -1181,7 +1292,7 @@ class DataController {
|
|
|
1181
1292
|
const dataRegistry = getContract({
|
|
1182
1293
|
address: dataRegistryAddress,
|
|
1183
1294
|
abi: dataRegistryAbi,
|
|
1184
|
-
client: this.context.
|
|
1295
|
+
client: this.context.publicClient
|
|
1185
1296
|
});
|
|
1186
1297
|
const fileDetails = await dataRegistry.read.files([BigInt(fileId)]);
|
|
1187
1298
|
if (!fileDetails) {
|
|
@@ -1240,34 +1351,32 @@ class DataController {
|
|
|
1240
1351
|
* ```
|
|
1241
1352
|
*/
|
|
1242
1353
|
async registerFileWithSchema(url, schemaId) {
|
|
1354
|
+
this.assertWallet();
|
|
1243
1355
|
try {
|
|
1244
|
-
const chainId = this.context.
|
|
1356
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1245
1357
|
if (!chainId) {
|
|
1246
1358
|
throw new Error("Chain ID not available");
|
|
1247
1359
|
}
|
|
1360
|
+
this.assertWallet();
|
|
1248
1361
|
const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
|
|
1249
1362
|
const dataRegistryAbi = getAbi("DataRegistry");
|
|
1250
|
-
const
|
|
1251
|
-
const
|
|
1363
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1364
|
+
const from = typeof account === "string" ? account : account.address;
|
|
1365
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1252
1366
|
address: dataRegistryAddress,
|
|
1253
1367
|
abi: dataRegistryAbi,
|
|
1254
1368
|
functionName: "addFileWithSchema",
|
|
1255
1369
|
args: [url, BigInt(schemaId)],
|
|
1256
|
-
account
|
|
1257
|
-
chain: this.context.walletClient.chain
|
|
1370
|
+
account,
|
|
1371
|
+
chain: this.context.walletClient.chain ?? null
|
|
1372
|
+
});
|
|
1373
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
1374
|
+
return tx({
|
|
1375
|
+
hash,
|
|
1376
|
+
from,
|
|
1377
|
+
contract: "DataRegistry",
|
|
1378
|
+
fn: "addFileWithSchema"
|
|
1258
1379
|
});
|
|
1259
|
-
const receipt = await this.context.publicClient.waitForTransactionReceipt(
|
|
1260
|
-
{
|
|
1261
|
-
hash: txHash,
|
|
1262
|
-
confirmations: 1
|
|
1263
|
-
}
|
|
1264
|
-
);
|
|
1265
|
-
const { parseFileAddedEvent } = await import("../utils/eventParsing");
|
|
1266
|
-
const eventData = parseFileAddedEvent(receipt);
|
|
1267
|
-
return {
|
|
1268
|
-
fileId: Number(eventData.fileId),
|
|
1269
|
-
transactionHash: txHash
|
|
1270
|
-
};
|
|
1271
1380
|
} catch (error) {
|
|
1272
1381
|
console.error("Failed to register file with schema:", error);
|
|
1273
1382
|
throw new Error(
|
|
@@ -1281,13 +1390,6 @@ class DataController {
|
|
|
1281
1390
|
* @returns Promise resolving to the user's wallet address
|
|
1282
1391
|
* @throws {Error} When no addresses are available in wallet client
|
|
1283
1392
|
*/
|
|
1284
|
-
async getUserAddress() {
|
|
1285
|
-
const addresses = await this.context.walletClient.getAddresses();
|
|
1286
|
-
if (addresses.length === 0) {
|
|
1287
|
-
throw new Error("No addresses available in wallet client");
|
|
1288
|
-
}
|
|
1289
|
-
return addresses[0];
|
|
1290
|
-
}
|
|
1291
1393
|
/**
|
|
1292
1394
|
* Adds a file with permissions to the DataRegistry contract.
|
|
1293
1395
|
*
|
|
@@ -1305,33 +1407,32 @@ class DataController {
|
|
|
1305
1407
|
* by both direct transactions and relayer services.
|
|
1306
1408
|
*/
|
|
1307
1409
|
async addFileWithPermissions(url, ownerAddress, permissions = []) {
|
|
1410
|
+
this.assertWallet();
|
|
1308
1411
|
try {
|
|
1309
|
-
const chainId = this.context.
|
|
1412
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1310
1413
|
if (!chainId) {
|
|
1311
1414
|
throw new Error("Chain ID not available");
|
|
1312
1415
|
}
|
|
1416
|
+
this.assertWallet();
|
|
1313
1417
|
const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
|
|
1314
1418
|
const dataRegistryAbi = getAbi("DataRegistry");
|
|
1315
|
-
const
|
|
1419
|
+
const account = this.context.walletClient.account ?? ownerAddress;
|
|
1420
|
+
const from = typeof account === "string" ? account : account.address;
|
|
1421
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1316
1422
|
address: dataRegistryAddress,
|
|
1317
1423
|
abi: dataRegistryAbi,
|
|
1318
1424
|
functionName: "addFileWithPermissions",
|
|
1319
1425
|
args: [url, ownerAddress, permissions],
|
|
1320
|
-
account
|
|
1321
|
-
chain: this.context.walletClient.chain
|
|
1426
|
+
account,
|
|
1427
|
+
chain: this.context.walletClient.chain ?? null
|
|
1428
|
+
});
|
|
1429
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
1430
|
+
return tx({
|
|
1431
|
+
hash,
|
|
1432
|
+
from,
|
|
1433
|
+
contract: "DataRegistry",
|
|
1434
|
+
fn: "addFileWithPermissions"
|
|
1322
1435
|
});
|
|
1323
|
-
const receipt = await this.context.publicClient.waitForTransactionReceipt(
|
|
1324
|
-
{
|
|
1325
|
-
hash: txHash,
|
|
1326
|
-
confirmations: 1
|
|
1327
|
-
}
|
|
1328
|
-
);
|
|
1329
|
-
const { parseFileAddedEvent } = await import("../utils/eventParsing");
|
|
1330
|
-
const eventData = parseFileAddedEvent(receipt);
|
|
1331
|
-
return {
|
|
1332
|
-
fileId: Number(eventData.fileId),
|
|
1333
|
-
transactionHash: txHash
|
|
1334
|
-
};
|
|
1335
1436
|
} catch (error) {
|
|
1336
1437
|
console.error("Failed to add file with permissions:", error);
|
|
1337
1438
|
throw new Error(
|
|
@@ -1343,44 +1444,148 @@ class DataController {
|
|
|
1343
1444
|
* Adds a file to the registry with permissions and schema.
|
|
1344
1445
|
* This combines the functionality of addFileWithPermissions and schema validation.
|
|
1345
1446
|
*
|
|
1447
|
+
* @remarks
|
|
1448
|
+
* This method automatically encrypts permissions when a publicKey is provided.
|
|
1449
|
+
* It generates the user's encryption key and encrypts it with each recipient's
|
|
1450
|
+
* public key before registering on the blockchain.
|
|
1451
|
+
*
|
|
1346
1452
|
* @param url - The URL of the file to register
|
|
1347
1453
|
* @param ownerAddress - The address of the file owner
|
|
1348
|
-
* @param permissions - Array of permissions to grant
|
|
1454
|
+
* @param permissions - Array of permissions to grant, each with account and publicKey properties
|
|
1349
1455
|
* @param schemaId - The schema ID to associate with the file (0 for no schema)
|
|
1350
|
-
* @returns Promise resolving to
|
|
1351
|
-
* @throws {Error} When chain
|
|
1352
|
-
* @throws {
|
|
1353
|
-
* @throws {Error} When
|
|
1354
|
-
* @throws {Error}
|
|
1456
|
+
* @returns Promise resolving to TransactionResult with fileId and transactionHash
|
|
1457
|
+
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1458
|
+
* @throws {Error} "Failed to generate encryption key" - When encryption key generation fails
|
|
1459
|
+
* @throws {Error} "Permission for {account} must include 'publicKey'" - When publicKey is missing
|
|
1460
|
+
* @throws {Error} "Failed to add file with permissions and schema: {error}" - When transaction fails
|
|
1461
|
+
* @example
|
|
1462
|
+
* ```typescript
|
|
1463
|
+
* // Get server's public key
|
|
1464
|
+
* const serverIdentity = await vana.server.getIdentity({
|
|
1465
|
+
* userAddress: "0x..."
|
|
1466
|
+
* });
|
|
1467
|
+
*
|
|
1468
|
+
* // Add file with permissions and schema
|
|
1469
|
+
* const result = await vana.data.addFileWithPermissionsAndSchema(
|
|
1470
|
+
* "ipfs://QmXxx...",
|
|
1471
|
+
* ownerAddress,
|
|
1472
|
+
* [{
|
|
1473
|
+
* account: serverIdentity.address,
|
|
1474
|
+
* publicKey: serverIdentity.publicKey
|
|
1475
|
+
* }],
|
|
1476
|
+
* schemaId
|
|
1477
|
+
* );
|
|
1478
|
+
*
|
|
1479
|
+
* console.log(`File ${result.fileId} registered in tx ${result.hash}`);
|
|
1480
|
+
* ```
|
|
1355
1481
|
*/
|
|
1356
1482
|
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1483
|
+
this.assertWallet();
|
|
1484
|
+
try {
|
|
1485
|
+
let encryptedPermissions = [];
|
|
1486
|
+
if (permissions.length > 0) {
|
|
1487
|
+
this.assertWallet();
|
|
1488
|
+
const userEncryptionKey = await generateEncryptionKey(
|
|
1489
|
+
this.context.walletClient,
|
|
1490
|
+
this.context.platform,
|
|
1491
|
+
DEFAULT_ENCRYPTION_SEED
|
|
1492
|
+
);
|
|
1493
|
+
encryptedPermissions = await Promise.all(
|
|
1494
|
+
permissions.map(async (permission) => {
|
|
1495
|
+
if (!permission.publicKey) {
|
|
1496
|
+
throw new Error(
|
|
1497
|
+
`Permission for ${permission.account} must include 'publicKey'`
|
|
1498
|
+
);
|
|
1499
|
+
}
|
|
1500
|
+
const encryptedKey = await encryptWithWalletPublicKey(
|
|
1501
|
+
userEncryptionKey,
|
|
1502
|
+
permission.publicKey,
|
|
1503
|
+
this.context.platform
|
|
1504
|
+
);
|
|
1505
|
+
return {
|
|
1506
|
+
account: permission.account,
|
|
1507
|
+
key: encryptedKey
|
|
1508
|
+
};
|
|
1509
|
+
})
|
|
1510
|
+
);
|
|
1511
|
+
}
|
|
1512
|
+
return await this.addFileWithEncryptedPermissionsAndSchema(
|
|
1513
|
+
url,
|
|
1514
|
+
ownerAddress,
|
|
1515
|
+
encryptedPermissions,
|
|
1516
|
+
schemaId
|
|
1517
|
+
);
|
|
1518
|
+
} catch (error) {
|
|
1519
|
+
console.error("Failed to add file with permissions and schema:", error);
|
|
1520
|
+
throw new Error(
|
|
1521
|
+
`Failed to add file with permissions and schema: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
1522
|
+
);
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
/**
|
|
1526
|
+
* Adds a file with pre-encrypted permissions and schema to the DataRegistry.
|
|
1527
|
+
*
|
|
1528
|
+
* @remarks
|
|
1529
|
+
* This method is designed for relay services and advanced use cases where permissions
|
|
1530
|
+
* have already been encrypted client-side. Unlike `addFileWithPermissionsAndSchema()`,
|
|
1531
|
+
* this method expects permissions in the encrypted format with a 'key' field instead
|
|
1532
|
+
* of 'publicKey'.
|
|
1533
|
+
*
|
|
1534
|
+
* This is typically used by relay endpoints that receive pre-encrypted data from
|
|
1535
|
+
* the client SDK's `upload()` method, avoiding double encryption.
|
|
1536
|
+
*
|
|
1537
|
+
* @param url - The storage URL of the file (e.g., IPFS URL)
|
|
1538
|
+
* @param ownerAddress - The address that will own this file
|
|
1539
|
+
* @param permissions - Array of pre-encrypted permissions with 'account' and 'key' fields
|
|
1540
|
+
* @param schemaId - Optional schema ID for data validation (defaults to 0)
|
|
1541
|
+
* @returns Promise resolving to transaction result with hash and contract details
|
|
1542
|
+
* @throws {Error} When chain ID is not available
|
|
1543
|
+
* @throws {Error} When wallet is not connected
|
|
1544
|
+
* @throws {Error} When transaction fails
|
|
1545
|
+
* @example
|
|
1546
|
+
* ```typescript
|
|
1547
|
+
* // In a relay endpoint that receives pre-encrypted permissions
|
|
1548
|
+
* const result = await vana.data.addFileWithEncryptedPermissionsAndSchema(
|
|
1549
|
+
* "ipfs://QmXxx...",
|
|
1550
|
+
* ownerAddress,
|
|
1551
|
+
* [
|
|
1552
|
+
* {
|
|
1553
|
+
* account: "0xServerAddress...",
|
|
1554
|
+
* key: "encrypted_key_string" // Already encrypted by client
|
|
1555
|
+
* }
|
|
1556
|
+
* ],
|
|
1557
|
+
* schemaId
|
|
1558
|
+
* );
|
|
1559
|
+
*
|
|
1560
|
+
* console.log(`File registered in tx ${result.hash}`);
|
|
1561
|
+
* ```
|
|
1562
|
+
*/
|
|
1563
|
+
async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1357
1564
|
try {
|
|
1358
|
-
const chainId = this.context.
|
|
1565
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1359
1566
|
if (!chainId) {
|
|
1360
1567
|
throw new Error("Chain ID not available");
|
|
1361
1568
|
}
|
|
1569
|
+
this.assertWallet();
|
|
1362
1570
|
const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
|
|
1363
1571
|
const dataRegistryAbi = getAbi("DataRegistry");
|
|
1364
|
-
const
|
|
1572
|
+
const account = this.context.walletClient.account ?? ownerAddress;
|
|
1573
|
+
const from = typeof account === "string" ? account : account.address;
|
|
1574
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1365
1575
|
address: dataRegistryAddress,
|
|
1366
1576
|
abi: dataRegistryAbi,
|
|
1367
1577
|
functionName: "addFileWithPermissionsAndSchema",
|
|
1368
1578
|
args: [url, ownerAddress, permissions, BigInt(schemaId)],
|
|
1369
|
-
account
|
|
1370
|
-
chain: this.context.walletClient.chain
|
|
1579
|
+
account,
|
|
1580
|
+
chain: this.context.walletClient.chain ?? null
|
|
1581
|
+
});
|
|
1582
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
1583
|
+
return tx({
|
|
1584
|
+
hash,
|
|
1585
|
+
from,
|
|
1586
|
+
contract: "DataRegistry",
|
|
1587
|
+
fn: "addFileWithPermissionsAndSchema"
|
|
1371
1588
|
});
|
|
1372
|
-
const receipt = await this.context.publicClient.waitForTransactionReceipt(
|
|
1373
|
-
{
|
|
1374
|
-
hash: txHash,
|
|
1375
|
-
confirmations: 1
|
|
1376
|
-
}
|
|
1377
|
-
);
|
|
1378
|
-
const { parseFileAddedEvent } = await import("../utils/eventParsing");
|
|
1379
|
-
const eventData = parseFileAddedEvent(receipt);
|
|
1380
|
-
return {
|
|
1381
|
-
fileId: Number(eventData.fileId),
|
|
1382
|
-
transactionHash: txHash
|
|
1383
|
-
};
|
|
1384
1589
|
} catch (error) {
|
|
1385
1590
|
console.error("Failed to add file with permissions and schema:", error);
|
|
1386
1591
|
throw new Error(
|
|
@@ -1417,8 +1622,9 @@ class DataController {
|
|
|
1417
1622
|
* ```
|
|
1418
1623
|
*/
|
|
1419
1624
|
async addRefiner(params) {
|
|
1625
|
+
this.assertWallet();
|
|
1420
1626
|
try {
|
|
1421
|
-
const chainId = this.context.
|
|
1627
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1422
1628
|
if (!chainId) {
|
|
1423
1629
|
throw new Error("Chain ID not available");
|
|
1424
1630
|
}
|
|
@@ -1427,7 +1633,10 @@ class DataController {
|
|
|
1427
1633
|
"DataRefinerRegistry"
|
|
1428
1634
|
);
|
|
1429
1635
|
const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
|
|
1430
|
-
|
|
1636
|
+
this.assertWallet();
|
|
1637
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1638
|
+
const from = typeof account === "string" ? account : account.address;
|
|
1639
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1431
1640
|
address: dataRefinerRegistryAddress,
|
|
1432
1641
|
abi: dataRefinerRegistryAbi,
|
|
1433
1642
|
functionName: "addRefinerWithSchemaId",
|
|
@@ -1437,20 +1646,27 @@ class DataController {
|
|
|
1437
1646
|
BigInt(params.schemaId),
|
|
1438
1647
|
params.refinementInstructionUrl
|
|
1439
1648
|
],
|
|
1440
|
-
account
|
|
1441
|
-
chain: this.context.walletClient.chain
|
|
1649
|
+
account,
|
|
1650
|
+
chain: this.context.walletClient.chain ?? null
|
|
1442
1651
|
});
|
|
1443
|
-
const
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1652
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
1653
|
+
const txResult = tx({
|
|
1654
|
+
hash,
|
|
1655
|
+
from,
|
|
1656
|
+
contract: "DataRefinerRegistry",
|
|
1657
|
+
fn: "addRefinerWithSchemaId"
|
|
1658
|
+
});
|
|
1659
|
+
if (!this.context.waitForTransactionEvents) {
|
|
1660
|
+
throw new Error("waitForTransactionEvents not configured");
|
|
1661
|
+
}
|
|
1662
|
+
const result = await this.context.waitForTransactionEvents(txResult);
|
|
1663
|
+
const event = result.expectedEvents.RefinerAdded;
|
|
1664
|
+
if (!event) {
|
|
1665
|
+
throw new Error("RefinerAdded event not found in transaction");
|
|
1666
|
+
}
|
|
1451
1667
|
return {
|
|
1452
|
-
refinerId: Number(
|
|
1453
|
-
transactionHash:
|
|
1668
|
+
refinerId: Number(event.refinerId),
|
|
1669
|
+
transactionHash: hash
|
|
1454
1670
|
};
|
|
1455
1671
|
} catch (error) {
|
|
1456
1672
|
console.error("Failed to add refiner:", error);
|
|
@@ -1484,7 +1700,7 @@ class DataController {
|
|
|
1484
1700
|
*/
|
|
1485
1701
|
async getRefiner(refinerId) {
|
|
1486
1702
|
try {
|
|
1487
|
-
const chainId = this.context.
|
|
1703
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1488
1704
|
if (!chainId) {
|
|
1489
1705
|
throw new Error("Chain ID not available");
|
|
1490
1706
|
}
|
|
@@ -1496,7 +1712,7 @@ class DataController {
|
|
|
1496
1712
|
const dataRefinerRegistry = getContract({
|
|
1497
1713
|
address: dataRefinerRegistryAddress,
|
|
1498
1714
|
abi: dataRefinerRegistryAbi,
|
|
1499
|
-
client: this.context.
|
|
1715
|
+
client: this.context.publicClient
|
|
1500
1716
|
});
|
|
1501
1717
|
const refinerData = await dataRefinerRegistry.read.refiners([
|
|
1502
1718
|
BigInt(refinerId)
|
|
@@ -1540,7 +1756,7 @@ class DataController {
|
|
|
1540
1756
|
*/
|
|
1541
1757
|
async isValidSchemaId(schemaId) {
|
|
1542
1758
|
try {
|
|
1543
|
-
const chainId = this.context.
|
|
1759
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1544
1760
|
if (!chainId) {
|
|
1545
1761
|
throw new Error("Chain ID not available");
|
|
1546
1762
|
}
|
|
@@ -1552,7 +1768,7 @@ class DataController {
|
|
|
1552
1768
|
const dataRefinerRegistry = getContract({
|
|
1553
1769
|
address: dataRefinerRegistryAddress,
|
|
1554
1770
|
abi: dataRefinerRegistryAbi,
|
|
1555
|
-
client: this.context.
|
|
1771
|
+
client: this.context.publicClient
|
|
1556
1772
|
});
|
|
1557
1773
|
const isValid = await dataRefinerRegistry.read.isValidSchemaId([
|
|
1558
1774
|
BigInt(schemaId)
|
|
@@ -1579,7 +1795,7 @@ class DataController {
|
|
|
1579
1795
|
*/
|
|
1580
1796
|
async getRefinersCount() {
|
|
1581
1797
|
try {
|
|
1582
|
-
const chainId = this.context.
|
|
1798
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1583
1799
|
if (!chainId) {
|
|
1584
1800
|
throw new Error("Chain ID not available");
|
|
1585
1801
|
}
|
|
@@ -1591,7 +1807,7 @@ class DataController {
|
|
|
1591
1807
|
const dataRefinerRegistry = getContract({
|
|
1592
1808
|
address: dataRefinerRegistryAddress,
|
|
1593
1809
|
abi: dataRefinerRegistryAbi,
|
|
1594
|
-
client: this.context.
|
|
1810
|
+
client: this.context.publicClient
|
|
1595
1811
|
});
|
|
1596
1812
|
const count = await dataRefinerRegistry.read.refinersCount();
|
|
1597
1813
|
return Number(count);
|
|
@@ -1623,8 +1839,9 @@ class DataController {
|
|
|
1623
1839
|
* ```
|
|
1624
1840
|
*/
|
|
1625
1841
|
async updateSchemaId(params) {
|
|
1842
|
+
this.assertWallet();
|
|
1626
1843
|
try {
|
|
1627
|
-
const chainId = this.context.
|
|
1844
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1628
1845
|
if (!chainId) {
|
|
1629
1846
|
throw new Error("Chain ID not available");
|
|
1630
1847
|
}
|
|
@@ -1633,20 +1850,19 @@ class DataController {
|
|
|
1633
1850
|
"DataRefinerRegistry"
|
|
1634
1851
|
);
|
|
1635
1852
|
const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
|
|
1636
|
-
|
|
1853
|
+
this.assertWallet();
|
|
1854
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1855
|
+
const hash = await this.context.walletClient.writeContract({
|
|
1637
1856
|
address: dataRefinerRegistryAddress,
|
|
1638
1857
|
abi: dataRefinerRegistryAbi,
|
|
1639
1858
|
functionName: "updateSchemaId",
|
|
1640
1859
|
args: [BigInt(params.refinerId), BigInt(params.newSchemaId)],
|
|
1641
|
-
account
|
|
1642
|
-
chain: this.context.walletClient.chain
|
|
1643
|
-
});
|
|
1644
|
-
await this.context.publicClient.waitForTransactionReceipt({
|
|
1645
|
-
hash: txHash,
|
|
1646
|
-
timeout: 3e4
|
|
1860
|
+
account,
|
|
1861
|
+
chain: this.context.walletClient.chain ?? null
|
|
1647
1862
|
});
|
|
1863
|
+
await this.context.publicClient.waitForTransactionReceipt({ hash });
|
|
1648
1864
|
return {
|
|
1649
|
-
transactionHash:
|
|
1865
|
+
transactionHash: hash
|
|
1650
1866
|
};
|
|
1651
1867
|
} catch (error) {
|
|
1652
1868
|
console.error("Failed to update schema ID:", error);
|
|
@@ -1664,13 +1880,12 @@ class DataController {
|
|
|
1664
1880
|
* 3. Encrypts the user's encryption key with the provided public key
|
|
1665
1881
|
* 4. Registers the file with permissions
|
|
1666
1882
|
*
|
|
1667
|
-
* @param
|
|
1668
|
-
* @param permissions - Array of permissions to grant, each with account address and public key
|
|
1669
|
-
* @param filename - Optional filename for the upload
|
|
1670
|
-
* @param providerName - Optional storage provider to use
|
|
1883
|
+
* @param params - Upload parameters including data, permissions, and options
|
|
1671
1884
|
* @returns Promise resolving to upload result with file ID and storage URL
|
|
1672
1885
|
*/
|
|
1673
|
-
async uploadFileWithPermissions(
|
|
1886
|
+
async uploadFileWithPermissions(params) {
|
|
1887
|
+
this.assertWallet();
|
|
1888
|
+
const { data, permissions, filename, providerName } = params;
|
|
1674
1889
|
try {
|
|
1675
1890
|
const uploadResult = await this.uploadToStorage(
|
|
1676
1891
|
data,
|
|
@@ -1679,7 +1894,7 @@ class DataController {
|
|
|
1679
1894
|
// Always encrypt for uploadFileWithPermissions
|
|
1680
1895
|
providerName
|
|
1681
1896
|
);
|
|
1682
|
-
const userAddress =
|
|
1897
|
+
const userAddress = this.context.userAddress;
|
|
1683
1898
|
const userEncryptionKey = await generateEncryptionKey(
|
|
1684
1899
|
this.context.walletClient,
|
|
1685
1900
|
this.context.platform,
|
|
@@ -1698,26 +1913,41 @@ class DataController {
|
|
|
1698
1913
|
};
|
|
1699
1914
|
})
|
|
1700
1915
|
);
|
|
1701
|
-
let result;
|
|
1702
1916
|
if (this.context.relayerCallbacks?.submitFileAdditionWithPermissions) {
|
|
1703
|
-
result = await this.context.relayerCallbacks.submitFileAdditionWithPermissions(
|
|
1917
|
+
const result = await this.context.relayerCallbacks.submitFileAdditionWithPermissions(
|
|
1704
1918
|
uploadResult.url,
|
|
1705
1919
|
userAddress,
|
|
1706
1920
|
encryptedPermissions
|
|
1707
1921
|
);
|
|
1922
|
+
return {
|
|
1923
|
+
fileId: result.fileId,
|
|
1924
|
+
url: uploadResult.url,
|
|
1925
|
+
size: uploadResult.size,
|
|
1926
|
+
transactionHash: result.transactionHash
|
|
1927
|
+
};
|
|
1708
1928
|
} else {
|
|
1709
|
-
|
|
1929
|
+
const txResult = await this.addFileWithPermissions(
|
|
1710
1930
|
uploadResult.url,
|
|
1711
1931
|
userAddress,
|
|
1712
1932
|
encryptedPermissions
|
|
1713
1933
|
);
|
|
1934
|
+
if (!this.context.waitForTransactionEvents) {
|
|
1935
|
+
throw new Error(
|
|
1936
|
+
"Cannot upload without relay: waitForTransactionEvents not configured"
|
|
1937
|
+
);
|
|
1938
|
+
}
|
|
1939
|
+
const eventResult = await this.context.waitForTransactionEvents(txResult);
|
|
1940
|
+
const fileAddedEvent = eventResult.expectedEvents.FileAdded;
|
|
1941
|
+
if (!fileAddedEvent) {
|
|
1942
|
+
throw new Error("FileAdded event not found in transaction");
|
|
1943
|
+
}
|
|
1944
|
+
return {
|
|
1945
|
+
fileId: Number(fileAddedEvent.fileId),
|
|
1946
|
+
url: uploadResult.url,
|
|
1947
|
+
size: uploadResult.size,
|
|
1948
|
+
transactionHash: txResult.hash
|
|
1949
|
+
};
|
|
1714
1950
|
}
|
|
1715
|
-
return {
|
|
1716
|
-
fileId: result.fileId,
|
|
1717
|
-
url: uploadResult.url,
|
|
1718
|
-
size: uploadResult.size,
|
|
1719
|
-
transactionHash: result.transactionHash
|
|
1720
|
-
};
|
|
1721
1951
|
} catch (error) {
|
|
1722
1952
|
console.error("Failed to upload file with permissions:", error);
|
|
1723
1953
|
throw new Error(
|
|
@@ -1755,6 +1985,7 @@ class DataController {
|
|
|
1755
1985
|
}
|
|
1756
1986
|
let finalBlob = blob;
|
|
1757
1987
|
if (encrypt) {
|
|
1988
|
+
this.assertWallet();
|
|
1758
1989
|
const encryptionKey = await generateEncryptionKey(
|
|
1759
1990
|
this.context.walletClient,
|
|
1760
1991
|
this.context.platform,
|
|
@@ -1776,7 +2007,7 @@ class DataController {
|
|
|
1776
2007
|
);
|
|
1777
2008
|
}
|
|
1778
2009
|
}
|
|
1779
|
-
const finalFilename = filename
|
|
2010
|
+
const finalFilename = filename ?? `upload-${Date.now()}.dat`;
|
|
1780
2011
|
const uploadResult = await this.context.storageManager.upload(
|
|
1781
2012
|
finalBlob,
|
|
1782
2013
|
finalFilename,
|
|
@@ -1801,21 +2032,29 @@ class DataController {
|
|
|
1801
2032
|
* For advanced users who need more control over transaction timing,
|
|
1802
2033
|
* use `submitFilePermission()` instead.
|
|
1803
2034
|
*
|
|
1804
|
-
* @param
|
|
1805
|
-
* @param
|
|
1806
|
-
* @param
|
|
2035
|
+
* @param params - Parameters for adding file permission
|
|
2036
|
+
* @param params.fileId - The ID of the file to grant permission for
|
|
2037
|
+
* @param params.account - The recipient's wallet address that will access the file
|
|
2038
|
+
* @param params.publicKey - The recipient's public key for encryption.
|
|
2039
|
+
* Obtain via `vana.server.getIdentity(account).publicKey`
|
|
1807
2040
|
* @returns Promise resolving to permission data from PermissionGranted event
|
|
1808
2041
|
* @throws {Error} "No addresses available in wallet client" - When wallet is not connected
|
|
1809
2042
|
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1810
2043
|
* @throws {Error} "Failed to add permission to file: {error}" - When transaction fails or user doesn't own file
|
|
1811
2044
|
* @example
|
|
1812
2045
|
* ```typescript
|
|
1813
|
-
* const result = await vana.data.addPermissionToFile(
|
|
2046
|
+
* const result = await vana.data.addPermissionToFile({
|
|
2047
|
+
* fileId: 123,
|
|
2048
|
+
* account: "0xRecipientAddress...",
|
|
2049
|
+
* publicKey: "0xRecipientPublicKey..."
|
|
2050
|
+
* });
|
|
1814
2051
|
* console.log(`Permission granted to ${result.account} for file ${result.fileId}`);
|
|
1815
2052
|
* console.log(`Transaction: ${result.transactionHash}`);
|
|
1816
2053
|
* ```
|
|
1817
2054
|
*/
|
|
1818
|
-
async addPermissionToFile(
|
|
2055
|
+
async addPermissionToFile(params) {
|
|
2056
|
+
this.assertWallet();
|
|
2057
|
+
const { fileId, account, publicKey } = params;
|
|
1819
2058
|
return await this.submitFilePermission(fileId, account, publicKey);
|
|
1820
2059
|
}
|
|
1821
2060
|
/**
|
|
@@ -1829,7 +2068,7 @@ class DataController {
|
|
|
1829
2068
|
* @param fileId - The ID of the file to grant permission for
|
|
1830
2069
|
* @param account - The recipient's wallet address that will access the file
|
|
1831
2070
|
* @param publicKey - The recipient's public key for encryption.
|
|
1832
|
-
* Obtain via `vana.server.getIdentity(account).
|
|
2071
|
+
* Obtain via `vana.server.getIdentity(account).publicKey`
|
|
1833
2072
|
* @returns Promise resolving to TransactionResult for tracking the transaction
|
|
1834
2073
|
* @throws {Error} When chain ID is not available
|
|
1835
2074
|
* @throws {Error} When encryption key generation fails
|
|
@@ -1847,6 +2086,7 @@ class DataController {
|
|
|
1847
2086
|
* ```
|
|
1848
2087
|
*/
|
|
1849
2088
|
async submitFilePermission(fileId, account, publicKey) {
|
|
2089
|
+
this.assertWallet();
|
|
1850
2090
|
try {
|
|
1851
2091
|
const userEncryptionKey = await generateEncryptionKey(
|
|
1852
2092
|
this.context.walletClient,
|
|
@@ -1858,24 +2098,29 @@ class DataController {
|
|
|
1858
2098
|
publicKey,
|
|
1859
2099
|
this.context.platform
|
|
1860
2100
|
);
|
|
1861
|
-
const chainId = this.context.
|
|
2101
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1862
2102
|
if (!chainId) {
|
|
1863
2103
|
throw new Error("Chain ID not available");
|
|
1864
2104
|
}
|
|
1865
2105
|
const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
|
|
1866
2106
|
const dataRegistryAbi = getAbi("DataRegistry");
|
|
2107
|
+
this.assertWallet();
|
|
2108
|
+
const walletAccount = this.context.walletClient.account ?? this.context.userAddress;
|
|
1867
2109
|
const txHash = await this.context.walletClient.writeContract({
|
|
1868
2110
|
address: dataRegistryAddress,
|
|
1869
2111
|
abi: dataRegistryAbi,
|
|
1870
2112
|
functionName: "addFilePermission",
|
|
1871
2113
|
args: [BigInt(fileId), account, encryptedKey],
|
|
1872
|
-
account:
|
|
1873
|
-
chain: this.context.walletClient.chain
|
|
2114
|
+
account: walletAccount,
|
|
2115
|
+
chain: this.context.walletClient.chain ?? null
|
|
1874
2116
|
});
|
|
1875
|
-
|
|
2117
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
2118
|
+
return tx({
|
|
1876
2119
|
hash: txHash,
|
|
1877
|
-
from:
|
|
1878
|
-
|
|
2120
|
+
from: typeof walletAccount === "string" ? walletAccount : walletAccount.address,
|
|
2121
|
+
contract: "DataRegistry",
|
|
2122
|
+
fn: "addFilePermission"
|
|
2123
|
+
});
|
|
1879
2124
|
} catch (error) {
|
|
1880
2125
|
console.error("Failed to add permission to file:", error);
|
|
1881
2126
|
throw new Error(
|
|
@@ -1892,7 +2137,7 @@ class DataController {
|
|
|
1892
2137
|
*/
|
|
1893
2138
|
async getFilePermission(fileId, account) {
|
|
1894
2139
|
try {
|
|
1895
|
-
const chainId = this.context.
|
|
2140
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1896
2141
|
if (!chainId) {
|
|
1897
2142
|
throw new Error("Chain ID not available");
|
|
1898
2143
|
}
|
|
@@ -1901,7 +2146,7 @@ class DataController {
|
|
|
1901
2146
|
const dataRegistry = getContract({
|
|
1902
2147
|
address: dataRegistryAddress,
|
|
1903
2148
|
abi: dataRegistryAbi,
|
|
1904
|
-
client: this.context.
|
|
2149
|
+
client: this.context.publicClient
|
|
1905
2150
|
});
|
|
1906
2151
|
const encryptedKey = await dataRegistry.read.filePermissions([
|
|
1907
2152
|
BigInt(fileId),
|
|
@@ -1925,12 +2170,13 @@ class DataController {
|
|
|
1925
2170
|
*
|
|
1926
2171
|
* @param file - The file to decrypt
|
|
1927
2172
|
* @param privateKey - The private key to decrypt the user's encryption key
|
|
1928
|
-
* @param
|
|
2173
|
+
* @param options - Optional decryption configuration
|
|
2174
|
+
* @param options.account - The account address that has permission (defaults to current wallet account)
|
|
1929
2175
|
* @returns Promise resolving to the decrypted file data
|
|
1930
2176
|
*/
|
|
1931
|
-
async decryptFileWithPermission(file, privateKey,
|
|
2177
|
+
async decryptFileWithPermission(file, privateKey, options) {
|
|
1932
2178
|
try {
|
|
1933
|
-
const permissionAccount = account
|
|
2179
|
+
const permissionAccount = options?.account ?? this.context.userAddress;
|
|
1934
2180
|
const encryptedKey = await this.getFilePermission(
|
|
1935
2181
|
file.id,
|
|
1936
2182
|
permissionAccount
|
|
@@ -1994,11 +2240,8 @@ class DataController {
|
|
|
1994
2240
|
*/
|
|
1995
2241
|
async fetch(url) {
|
|
1996
2242
|
try {
|
|
1997
|
-
const {
|
|
1998
|
-
const response = await
|
|
1999
|
-
url,
|
|
2000
|
-
this.context.downloadRelayer
|
|
2001
|
-
);
|
|
2243
|
+
const { universalFetch } = await import("../utils/download");
|
|
2244
|
+
const response = await universalFetch(url, this.context.downloadRelayer);
|
|
2002
2245
|
if (!response.ok) {
|
|
2003
2246
|
throw new Error(
|
|
2004
2247
|
`HTTP error! status: ${response.status} ${response.statusText}`
|
|
@@ -2063,7 +2306,7 @@ class DataController {
|
|
|
2063
2306
|
"https://dweb.link/ipfs/",
|
|
2064
2307
|
"https://ipfs.io/ipfs/"
|
|
2065
2308
|
];
|
|
2066
|
-
const gateways = options?.gateways
|
|
2309
|
+
const gateways = options?.gateways ?? this.context.ipfsGateways ?? defaultGateways;
|
|
2067
2310
|
const { extractIpfsHash } = await import("../utils/ipfs");
|
|
2068
2311
|
const cid = extractIpfsHash(url);
|
|
2069
2312
|
if (!cid) {
|
|
@@ -2192,7 +2435,7 @@ class DataController {
|
|
|
2192
2435
|
* ```
|
|
2193
2436
|
*/
|
|
2194
2437
|
validateDataAgainstSchema(data, schema) {
|
|
2195
|
-
|
|
2438
|
+
validateDataAgainstSchema(data, schema);
|
|
2196
2439
|
}
|
|
2197
2440
|
/**
|
|
2198
2441
|
* Fetches and validates a data schema from a URL, then returns the parsed data schema.
|