@opendatalabs/vana-sdk 0.1.0-alpha.eebb656 → 0.1.0-alpha.ef15099
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/README.md +67 -351
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.ts +33 -1
- package/dist/browser.js.map +1 -1
- package/dist/chains/definitions.cjs +9 -6
- package/dist/chains/definitions.cjs.map +1 -1
- package/dist/chains/definitions.d.ts +2 -0
- package/dist/chains/definitions.js +9 -6
- package/dist/chains/definitions.js.map +1 -1
- package/dist/chains/index.cjs.map +1 -1
- package/dist/chains/index.d.ts +30 -1
- package/dist/chains/index.js.map +1 -1
- package/dist/client/enhancedResponse.cjs +164 -0
- package/dist/client/enhancedResponse.cjs.map +1 -0
- package/dist/client/enhancedResponse.d.ts +120 -0
- package/dist/client/enhancedResponse.js +138 -0
- package/dist/client/enhancedResponse.js.map +1 -0
- package/dist/config/chains.cjs.map +1 -1
- package/dist/config/chains.d.ts +99 -0
- package/dist/config/chains.js.map +1 -1
- package/dist/config/contracts.config.cjs +400 -0
- package/dist/config/contracts.config.cjs.map +1 -0
- package/dist/config/contracts.config.d.ts +84 -0
- package/dist/config/contracts.config.js +375 -0
- package/dist/config/contracts.config.js.map +1 -0
- 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/contracts/contractController.cjs +1 -1
- package/dist/contracts/contractController.cjs.map +1 -1
- package/dist/contracts/contractController.d.ts +66 -10
- package/dist/contracts/contractController.js +1 -1
- package/dist/contracts/contractController.js.map +1 -1
- package/dist/controllers/__tests__/data-consistency-integration.test.d.ts +7 -0
- package/dist/controllers/__tests__/operations.processQueue.test.d.ts +1 -0
- package/dist/controllers/accessSettlement.cjs +289 -0
- package/dist/controllers/accessSettlement.cjs.map +1 -0
- package/dist/controllers/accessSettlement.d.ts +157 -0
- package/dist/controllers/accessSettlement.js +265 -0
- package/dist/controllers/accessSettlement.js.map +1 -0
- package/dist/controllers/accessSettlement.test.d.ts +1 -0
- package/dist/controllers/base.cjs +116 -0
- package/dist/controllers/base.cjs.map +1 -0
- package/dist/controllers/base.d.ts +94 -0
- package/dist/controllers/base.js +92 -0
- package/dist/controllers/base.js.map +1 -0
- package/dist/controllers/data.cjs +634 -352
- package/dist/controllers/data.cjs.map +1 -1
- package/dist/controllers/data.d.ts +348 -213
- package/dist/controllers/data.js +647 -355
- package/dist/controllers/data.js.map +1 -1
- package/dist/controllers/operations.cjs +430 -0
- package/dist/controllers/operations.cjs.map +1 -0
- package/dist/controllers/operations.d.ts +229 -0
- package/dist/controllers/operations.js +406 -0
- package/dist/controllers/operations.js.map +1 -0
- package/dist/controllers/permissions.cjs +943 -443
- package/dist/controllers/permissions.cjs.map +1 -1
- package/dist/controllers/permissions.d.ts +201 -120
- package/dist/controllers/permissions.js +943 -443
- package/dist/controllers/permissions.js.map +1 -1
- package/dist/controllers/protocol.cjs +14 -10
- package/dist/controllers/protocol.cjs.map +1 -1
- package/dist/controllers/protocol.d.ts +30 -31
- package/dist/controllers/protocol.js +14 -10
- package/dist/controllers/protocol.js.map +1 -1
- package/dist/controllers/runtimePermissions.cjs +272 -0
- package/dist/controllers/runtimePermissions.cjs.map +1 -0
- package/dist/controllers/runtimePermissions.d.ts +152 -0
- package/dist/controllers/runtimePermissions.js +251 -0
- package/dist/controllers/runtimePermissions.js.map +1 -0
- package/dist/controllers/runtimePermissions.test.d.ts +1 -0
- package/dist/controllers/schemas.cjs +113 -43
- package/dist/controllers/schemas.cjs.map +1 -1
- package/dist/controllers/schemas.d.ts +90 -43
- package/dist/controllers/schemas.js +113 -43
- package/dist/controllers/schemas.js.map +1 -1
- package/dist/controllers/server.cjs +276 -60
- package/dist/controllers/server.cjs.map +1 -1
- package/dist/controllers/server.d.ts +159 -54
- package/dist/controllers/server.js +276 -60
- package/dist/controllers/server.js.map +1 -1
- package/dist/core/__tests__/health.test.d.ts +1 -0
- package/dist/core/__tests__/inMemoryNonceManager.test.d.ts +1 -0
- package/dist/core/__tests__/nonceManager.test.d.ts +1 -0
- package/dist/core/__tests__/pollingManager.test.d.ts +4 -0
- package/dist/core/apiClient.cjs +53 -3
- package/dist/core/apiClient.cjs.map +1 -1
- package/dist/core/apiClient.d.ts +132 -7
- package/dist/core/apiClient.js +53 -3
- package/dist/core/apiClient.js.map +1 -1
- package/dist/core/generics.cjs +30 -3
- package/dist/core/generics.cjs.map +1 -1
- package/dist/core/generics.d.ts +95 -6
- package/dist/core/generics.js +30 -3
- package/dist/core/generics.js.map +1 -1
- package/dist/core/health.cjs +289 -0
- package/dist/core/health.cjs.map +1 -0
- package/dist/core/health.d.ts +143 -0
- package/dist/core/health.js +265 -0
- package/dist/core/health.js.map +1 -0
- package/dist/core/inMemoryNonceManager.cjs +138 -0
- package/dist/core/inMemoryNonceManager.cjs.map +1 -0
- package/dist/core/inMemoryNonceManager.d.ts +69 -0
- package/dist/core/inMemoryNonceManager.js +114 -0
- package/dist/core/inMemoryNonceManager.js.map +1 -0
- package/dist/core/nonceManager.cjs +304 -0
- package/dist/core/nonceManager.cjs.map +1 -0
- package/dist/core/nonceManager.d.ts +116 -0
- package/dist/core/nonceManager.js +280 -0
- package/dist/core/nonceManager.js.map +1 -0
- package/dist/core/pollingManager.cjs +292 -0
- package/dist/core/pollingManager.cjs.map +1 -0
- package/dist/core/pollingManager.d.ts +120 -0
- package/dist/core/pollingManager.js +268 -0
- package/dist/core/pollingManager.js.map +1 -0
- package/dist/core.cjs +164 -36
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +69 -10
- package/dist/core.js +167 -37
- package/dist/core.js.map +1 -1
- package/dist/crypto/ecies/__tests__/constants.test.d.ts +1 -1
- package/dist/crypto/ecies/__tests__/interface.test.d.ts +1 -0
- package/dist/crypto/ecies/__tests__/serialization.test.d.ts +8 -0
- package/dist/crypto/ecies/__tests__/utils.test.d.ts +1 -0
- package/dist/crypto/ecies/base.cjs +59 -23
- package/dist/crypto/ecies/base.cjs.map +1 -1
- package/dist/crypto/ecies/base.js +59 -23
- package/dist/crypto/ecies/base.js.map +1 -1
- package/dist/crypto/ecies/constants.cjs +2 -10
- package/dist/crypto/ecies/constants.cjs.map +1 -1
- package/dist/crypto/ecies/constants.d.ts +0 -9
- package/dist/crypto/ecies/constants.js +1 -8
- package/dist/crypto/ecies/constants.js.map +1 -1
- package/dist/crypto/ecies/interface.cjs +19 -2
- package/dist/crypto/ecies/interface.cjs.map +1 -1
- package/dist/crypto/ecies/interface.js +19 -2
- package/dist/crypto/ecies/interface.js.map +1 -1
- package/dist/errors.cjs +45 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +104 -0
- package/dist/errors.js +43 -0
- package/dist/errors.js.map +1 -1
- package/dist/generated/abi/AccessSettlementImplementation.cjs +635 -0
- package/dist/generated/abi/AccessSettlementImplementation.cjs.map +1 -0
- package/dist/generated/abi/AccessSettlementImplementation.d.ts +468 -0
- package/dist/generated/abi/AccessSettlementImplementation.js +611 -0
- package/dist/generated/abi/AccessSettlementImplementation.js.map +1 -0
- package/dist/generated/abi/AttestationPolicyImplementation.cjs +614 -0
- package/dist/generated/abi/AttestationPolicyImplementation.cjs.map +1 -0
- package/dist/generated/abi/AttestationPolicyImplementation.d.ts +449 -0
- package/dist/generated/abi/AttestationPolicyImplementation.js +590 -0
- package/dist/generated/abi/AttestationPolicyImplementation.js.map +1 -0
- package/dist/generated/abi/ComputeEngineImplementation.cjs.map +1 -1
- package/dist/generated/abi/ComputeEngineImplementation.js.map +1 -1
- package/dist/generated/abi/{DLPTreasuryImplementation.cjs → ComputeEngineTreasuryImplementation.cjs} +16 -92
- package/dist/generated/abi/ComputeEngineTreasuryImplementation.cjs.map +1 -0
- package/dist/generated/abi/{DLPTreasuryImplementation.d.ts → ComputeEngineTreasuryImplementation.d.ts} +9 -67
- package/dist/generated/abi/{DLPTreasuryImplementation.js → ComputeEngineTreasuryImplementation.js} +12 -88
- package/dist/generated/abi/ComputeEngineTreasuryImplementation.js.map +1 -0
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.cjs.map +1 -1
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.js.map +1 -1
- package/dist/generated/abi/DATFactoryImplementation.cjs.map +1 -1
- package/dist/generated/abi/DATFactoryImplementation.js.map +1 -1
- package/dist/generated/abi/DATImplementation.cjs.map +1 -1
- package/dist/generated/abi/DATImplementation.js.map +1 -1
- package/dist/generated/abi/DATPausableImplementation.cjs.map +1 -1
- package/dist/generated/abi/DATPausableImplementation.js.map +1 -1
- package/dist/generated/abi/DATVotesImplementation.cjs.map +1 -1
- package/dist/generated/abi/DATVotesImplementation.js.map +1 -1
- package/dist/generated/abi/DLPPerformanceImplementation.cjs +42 -0
- package/dist/generated/abi/DLPPerformanceImplementation.cjs.map +1 -1
- package/dist/generated/abi/DLPPerformanceImplementation.d.ts +32 -0
- package/dist/generated/abi/DLPPerformanceImplementation.js +42 -0
- package/dist/generated/abi/DLPPerformanceImplementation.js.map +1 -1
- package/dist/generated/abi/DLPRegistryImplementation.cjs +5 -5
- package/dist/generated/abi/DLPRegistryImplementation.cjs.map +1 -1
- package/dist/generated/abi/DLPRegistryImplementation.d.ts +4 -4
- package/dist/generated/abi/DLPRegistryImplementation.js +5 -5
- package/dist/generated/abi/DLPRegistryImplementation.js.map +1 -1
- package/dist/generated/abi/DLPRegistryTreasuryImplementation.cjs.map +1 -1
- package/dist/generated/abi/DLPRegistryTreasuryImplementation.js.map +1 -1
- package/dist/generated/abi/DLPRewardDeployerImplementation.cjs +166 -2
- package/dist/generated/abi/DLPRewardDeployerImplementation.cjs.map +1 -1
- package/dist/generated/abi/DLPRewardDeployerImplementation.d.ts +129 -2
- package/dist/generated/abi/DLPRewardDeployerImplementation.js +166 -2
- package/dist/generated/abi/DLPRewardDeployerImplementation.js.map +1 -1
- package/dist/generated/abi/DLPRewardSwapImplementation.cjs.map +1 -1
- package/dist/generated/abi/DLPRewardSwapImplementation.js.map +1 -1
- package/dist/generated/abi/DataLiquidityPoolImplementation.cjs +282 -100
- package/dist/generated/abi/DataLiquidityPoolImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataLiquidityPoolImplementation.d.ts +218 -79
- package/dist/generated/abi/DataLiquidityPoolImplementation.js +281 -99
- package/dist/generated/abi/DataLiquidityPoolImplementation.js.map +1 -1
- package/dist/generated/abi/DataPortabilityGranteesImplementation.cjs +167 -19
- package/dist/generated/abi/DataPortabilityGranteesImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataPortabilityGranteesImplementation.d.ts +127 -14
- package/dist/generated/abi/DataPortabilityGranteesImplementation.js +167 -19
- package/dist/generated/abi/DataPortabilityGranteesImplementation.js.map +1 -1
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs +0 -19
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.ts +0 -14
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.js +0 -19
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.js.map +1 -1
- package/dist/generated/abi/DataPortabilityServersImplementation.cjs +0 -19
- package/dist/generated/abi/DataPortabilityServersImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataPortabilityServersImplementation.d.ts +0 -14
- package/dist/generated/abi/DataPortabilityServersImplementation.js +0 -19
- package/dist/generated/abi/DataPortabilityServersImplementation.js.map +1 -1
- package/dist/generated/abi/DataRefinerRegistryImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataRefinerRegistryImplementation.js.map +1 -1
- package/dist/generated/abi/DataRegistryImplementation.cjs +0 -13
- package/dist/generated/abi/DataRegistryImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataRegistryImplementation.d.ts +0 -10
- package/dist/generated/abi/DataRegistryImplementation.js +0 -13
- package/dist/generated/abi/DataRegistryImplementation.js.map +1 -1
- package/dist/generated/abi/DatasetRegistryImplementation.cjs +751 -0
- package/dist/generated/abi/DatasetRegistryImplementation.cjs.map +1 -0
- package/dist/generated/abi/DatasetRegistryImplementation.d.ts +557 -0
- package/dist/generated/abi/DatasetRegistryImplementation.js +727 -0
- package/dist/generated/abi/DatasetRegistryImplementation.js.map +1 -0
- package/dist/generated/abi/ProtocolConfigImplementation.cjs +578 -0
- package/dist/generated/abi/ProtocolConfigImplementation.cjs.map +1 -0
- package/dist/generated/abi/ProtocolConfigImplementation.d.ts +423 -0
- package/dist/generated/abi/ProtocolConfigImplementation.js +554 -0
- package/dist/generated/abi/ProtocolConfigImplementation.js.map +1 -0
- package/dist/generated/abi/QueryEngineImplementation.cjs.map +1 -1
- package/dist/generated/abi/QueryEngineImplementation.js.map +1 -1
- package/dist/generated/abi/SwapHelperImplementation.cjs +0 -43
- package/dist/generated/abi/SwapHelperImplementation.cjs.map +1 -1
- package/dist/generated/abi/SwapHelperImplementation.d.ts +0 -35
- package/dist/generated/abi/SwapHelperImplementation.js +0 -43
- package/dist/generated/abi/SwapHelperImplementation.js.map +1 -1
- package/dist/generated/abi/TeePoolDedicatedGpuImplementation.cjs.map +1 -1
- package/dist/generated/abi/TeePoolDedicatedGpuImplementation.js.map +1 -1
- package/dist/generated/abi/TeePoolDedicatedStandardImplementation.cjs.map +1 -1
- package/dist/generated/abi/TeePoolDedicatedStandardImplementation.js.map +1 -1
- package/dist/generated/abi/TeePoolEphemeralStandardImplementation.cjs.map +1 -1
- package/dist/generated/abi/TeePoolEphemeralStandardImplementation.js.map +1 -1
- package/dist/generated/abi/TeePoolPersistentGpuImplementation.cjs.map +1 -1
- package/dist/generated/abi/TeePoolPersistentGpuImplementation.js.map +1 -1
- package/dist/generated/abi/TeePoolPersistentStandardImplementation.cjs.map +1 -1
- package/dist/generated/abi/TeePoolPersistentStandardImplementation.js.map +1 -1
- package/dist/generated/abi/TeePoolPhalaImplementation.cjs.map +1 -1
- package/dist/generated/abi/TeePoolPhalaImplementation.js.map +1 -1
- package/dist/generated/abi/UniswapV3NonfungiblePositionManagerImplementation.cjs +1251 -0
- package/dist/generated/abi/UniswapV3NonfungiblePositionManagerImplementation.cjs.map +1 -0
- package/dist/generated/abi/UniswapV3NonfungiblePositionManagerImplementation.d.ts +948 -0
- package/dist/generated/abi/UniswapV3NonfungiblePositionManagerImplementation.js +1227 -0
- package/dist/generated/abi/UniswapV3NonfungiblePositionManagerImplementation.js.map +1 -0
- package/dist/generated/abi/UniswapV3QuoterV2Implementation.cjs +297 -0
- package/dist/generated/abi/UniswapV3QuoterV2Implementation.cjs.map +1 -0
- package/dist/generated/abi/UniswapV3QuoterV2Implementation.d.ts +206 -0
- package/dist/generated/abi/UniswapV3QuoterV2Implementation.js +273 -0
- package/dist/generated/abi/UniswapV3QuoterV2Implementation.js.map +1 -0
- package/dist/generated/abi/VanaEpochImplementation.cjs +195 -0
- package/dist/generated/abi/VanaEpochImplementation.cjs.map +1 -1
- package/dist/generated/abi/VanaEpochImplementation.d.ts +151 -0
- package/dist/generated/abi/VanaEpochImplementation.js +195 -0
- package/dist/generated/abi/VanaEpochImplementation.js.map +1 -1
- package/dist/generated/abi/VanaPoolEntityImplementation.cjs +22 -65
- package/dist/generated/abi/VanaPoolEntityImplementation.cjs.map +1 -1
- package/dist/generated/abi/VanaPoolEntityImplementation.d.ts +17 -51
- package/dist/generated/abi/VanaPoolEntityImplementation.js +22 -65
- package/dist/generated/abi/VanaPoolEntityImplementation.js.map +1 -1
- package/dist/generated/abi/VanaPoolStakingImplementation.cjs +113 -1
- package/dist/generated/abi/VanaPoolStakingImplementation.cjs.map +1 -1
- package/dist/generated/abi/VanaPoolStakingImplementation.d.ts +85 -1
- package/dist/generated/abi/VanaPoolStakingImplementation.js +113 -1
- package/dist/generated/abi/VanaPoolStakingImplementation.js.map +1 -1
- package/dist/generated/abi/VanaPoolTreasuryImplementation.cjs.map +1 -1
- package/dist/generated/abi/VanaPoolTreasuryImplementation.js.map +1 -1
- package/dist/generated/abi/VanaRuntimePermissionsImplementation.cjs +759 -0
- package/dist/generated/abi/VanaRuntimePermissionsImplementation.cjs.map +1 -0
- package/dist/generated/abi/VanaRuntimePermissionsImplementation.d.ts +563 -0
- package/dist/generated/abi/VanaRuntimePermissionsImplementation.js +735 -0
- package/dist/generated/abi/VanaRuntimePermissionsImplementation.js.map +1 -0
- package/dist/generated/abi/VanaRuntimeServersImplementation.cjs +820 -0
- package/dist/generated/abi/VanaRuntimeServersImplementation.cjs.map +1 -0
- package/dist/generated/abi/VanaRuntimeServersImplementation.d.ts +609 -0
- package/dist/generated/abi/VanaRuntimeServersImplementation.js +796 -0
- package/dist/generated/abi/VanaRuntimeServersImplementation.js.map +1 -0
- package/dist/generated/abi/VanaTreasuryImplementation.cjs +536 -0
- package/dist/generated/abi/VanaTreasuryImplementation.cjs.map +1 -0
- package/dist/generated/abi/VanaTreasuryImplementation.d.ts +393 -0
- package/dist/generated/abi/VanaTreasuryImplementation.js +512 -0
- package/dist/generated/abi/VanaTreasuryImplementation.js.map +1 -0
- package/dist/generated/abi/WVANAImplementation.cjs +339 -0
- package/dist/generated/abi/WVANAImplementation.cjs.map +1 -0
- package/dist/generated/abi/WVANAImplementation.d.ts +244 -0
- package/dist/generated/abi/WVANAImplementation.js +315 -0
- package/dist/generated/abi/WVANAImplementation.js.map +1 -0
- package/dist/generated/abi/index.cjs +79 -47
- package/dist/generated/abi/index.cjs.map +1 -1
- package/dist/generated/abi/index.d.ts +15783 -10449
- package/dist/generated/abi/index.js +65 -43
- package/dist/generated/abi/index.js.map +1 -1
- package/dist/{config → generated}/addresses.cjs +174 -75
- package/dist/generated/addresses.cjs.map +1 -0
- package/dist/{config → generated}/addresses.d.ts +174 -165
- package/dist/{config → generated}/addresses.js +174 -75
- package/dist/generated/addresses.js.map +1 -0
- package/dist/generated/event-types.cjs.map +1 -1
- package/dist/generated/event-types.d.ts +482 -399
- package/dist/generated/eventRegistry.cjs +2601 -724
- package/dist/generated/eventRegistry.cjs.map +1 -1
- package/dist/generated/eventRegistry.d.ts +2 -2
- package/dist/generated/eventRegistry.js +2601 -724
- package/dist/generated/eventRegistry.js.map +1 -1
- package/dist/generated/server/server-exports.cjs +22 -0
- package/dist/generated/server/server-exports.cjs.map +1 -1
- package/dist/generated/server/server-exports.d.ts +31 -11
- package/dist/generated/server/server-exports.js +17 -0
- package/dist/generated/server/server-exports.js.map +1 -1
- package/dist/generated/server/server.cjs.map +1 -1
- package/dist/generated/server/server.d.ts +771 -402
- package/dist/generated/subgraph.cjs +797 -32
- package/dist/generated/subgraph.cjs.map +1 -1
- package/dist/generated/subgraph.d.ts +135 -0
- package/dist/generated/subgraph.js +792 -32
- package/dist/generated/subgraph.js.map +1 -1
- package/dist/index.browser.d.ts +6 -1
- package/dist/index.browser.js +26 -1
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.node.cjs +47 -4
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.ts +60 -14
- package/dist/index.node.js +42 -3
- package/dist/index.node.js.map +1 -1
- package/dist/lib/__tests__/redisAtomicStore.test.d.ts +1 -0
- package/dist/lib/redisAtomicStore.cjs +201 -0
- package/dist/lib/redisAtomicStore.cjs.map +1 -0
- package/dist/lib/redisAtomicStore.d.ts +120 -0
- package/dist/lib/redisAtomicStore.js +177 -0
- package/dist/lib/redisAtomicStore.js.map +1 -0
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.ts +39 -1
- package/dist/node.js.map +1 -1
- package/dist/platform/browser.cjs +160 -2
- package/dist/platform/browser.cjs.map +1 -1
- package/dist/platform/browser.d.ts +232 -12
- package/dist/platform/browser.js +160 -2
- package/dist/platform/browser.js.map +1 -1
- package/dist/platform/interface.cjs.map +1 -1
- package/dist/platform/interface.d.ts +283 -90
- package/dist/platform/node.cjs +163 -2
- package/dist/platform/node.cjs.map +1 -1
- package/dist/platform/node.d.ts +69 -6
- package/dist/platform/node.js +163 -2
- package/dist/platform/node.js.map +1 -1
- package/dist/server/relayerHandler.cjs +452 -0
- package/dist/server/relayerHandler.cjs.map +1 -0
- package/dist/server/relayerHandler.d.ts +69 -0
- package/dist/server/relayerHandler.js +428 -0
- package/dist/server/relayerHandler.js.map +1 -0
- package/dist/storage/index.cjs +3 -0
- package/dist/storage/index.cjs.map +1 -1
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/manager.cjs +108 -25
- package/dist/storage/manager.cjs.map +1 -1
- package/dist/storage/manager.d.ts +119 -25
- package/dist/storage/manager.js +108 -25
- package/dist/storage/manager.js.map +1 -1
- package/dist/storage/providers/callback-storage.cjs +86 -15
- package/dist/storage/providers/callback-storage.cjs.map +1 -1
- package/dist/storage/providers/callback-storage.d.ts +109 -20
- package/dist/storage/providers/callback-storage.js +86 -15
- package/dist/storage/providers/callback-storage.js.map +1 -1
- package/dist/storage/providers/dropbox.cjs +237 -0
- package/dist/storage/providers/dropbox.cjs.map +1 -0
- package/dist/storage/providers/dropbox.d.ts +39 -0
- package/dist/storage/providers/dropbox.js +215 -0
- package/dist/storage/providers/dropbox.js.map +1 -0
- package/dist/storage/providers/dropbox.test.d.ts +1 -0
- package/dist/storage/providers/pinata.cjs.map +1 -1
- package/dist/storage/providers/pinata.d.ts +12 -14
- package/dist/storage/providers/pinata.js.map +1 -1
- package/dist/tests/data-upload-owner-validation.test.d.ts +1 -0
- package/dist/tests/factories/mockFactory.d.ts +6 -6
- package/dist/tests/fakes/FakeWaitForTransactionEvents.d.ts +2 -2
- package/dist/tests/permissions-revoke-relayer.test.d.ts +1 -0
- package/dist/tests/permissions-transaction-options.test.d.ts +1 -0
- package/dist/tests/read-only-mode.test.d.ts +1 -0
- package/dist/tests/relayer-integration.test.d.ts +1 -0
- package/dist/tests/relayer-unified.test.d.ts +1 -0
- package/dist/tests/server-relayer-handler.test.d.ts +1 -0
- package/dist/types/accessSettlement.cjs +17 -0
- package/dist/types/accessSettlement.cjs.map +1 -0
- package/dist/types/accessSettlement.d.ts +66 -0
- package/dist/types/accessSettlement.js +1 -0
- package/dist/types/accessSettlement.js.map +1 -0
- package/dist/types/atomicStore.cjs +31 -0
- package/dist/types/atomicStore.cjs.map +1 -0
- package/dist/types/atomicStore.d.ts +236 -0
- package/dist/types/atomicStore.js +7 -0
- package/dist/types/atomicStore.js.map +1 -0
- package/dist/types/blockchain.cjs.map +1 -1
- package/dist/types/blockchain.d.ts +39 -11
- package/dist/types/chains.cjs.map +1 -1
- package/dist/types/chains.d.ts +74 -7
- package/dist/types/chains.js.map +1 -1
- package/dist/types/config.cjs +10 -0
- package/dist/types/config.cjs.map +1 -1
- package/dist/types/config.d.ts +217 -220
- 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 +71 -7
- package/dist/types/controller-context.cjs.map +1 -1
- package/dist/types/controller-context.d.ts +12 -6
- package/dist/types/data.cjs.map +1 -1
- package/dist/types/data.d.ts +82 -10
- package/dist/types/generics.cjs.map +1 -1
- package/dist/types/generics.d.ts +81 -10
- package/dist/types/index.cjs +4 -0
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.ts +36 -6
- package/dist/types/index.js +9 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/operationStore.cjs +17 -0
- package/dist/types/operationStore.cjs.map +1 -0
- package/dist/types/operationStore.d.ts +171 -0
- package/dist/types/operationStore.js +1 -0
- package/dist/types/operationStore.js.map +1 -0
- package/dist/types/operations.cjs +3 -15
- package/dist/types/operations.cjs.map +1 -1
- package/dist/types/operations.d.ts +131 -39
- package/dist/types/operations.js +2 -13
- package/dist/types/operations.js.map +1 -1
- package/dist/types/options.cjs +17 -0
- package/dist/types/options.cjs.map +1 -0
- package/dist/types/options.d.ts +308 -0
- package/dist/types/options.js +1 -0
- package/dist/types/options.js.map +1 -0
- package/dist/types/permissions.cjs.map +1 -1
- package/dist/types/permissions.d.ts +19 -20
- package/dist/types/personal.cjs.map +1 -1
- package/dist/types/personal.d.ts +150 -14
- package/dist/types/relayer.cjs.map +1 -1
- package/dist/types/relayer.d.ts +307 -35
- package/dist/types/runtimePermissions.cjs +17 -0
- package/dist/types/runtimePermissions.cjs.map +1 -0
- package/dist/types/runtimePermissions.d.ts +122 -0
- package/dist/types/runtimePermissions.js +1 -0
- package/dist/types/runtimePermissions.js.map +1 -0
- package/dist/types/storage.cjs.map +1 -1
- package/dist/types/storage.d.ts +9 -21
- package/dist/types/storage.js.map +1 -1
- package/dist/types/utils.cjs.map +1 -1
- package/dist/types/utils.d.ts +0 -45
- package/dist/utils/__tests__/chainQuery.test.d.ts +1 -0
- package/dist/utils/__tests__/subgraphConsistency.test.d.ts +4 -0
- package/dist/utils/__tests__/subgraphPagination.test.d.ts +4 -0
- package/dist/utils/blockchain/registry.cjs +3 -3
- package/dist/utils/blockchain/registry.cjs.map +1 -1
- package/dist/utils/blockchain/registry.d.ts +1 -1
- package/dist/utils/blockchain/registry.js +3 -3
- package/dist/utils/blockchain/registry.js.map +1 -1
- package/dist/utils/chainQuery.cjs +107 -0
- package/dist/utils/chainQuery.cjs.map +1 -0
- package/dist/utils/chainQuery.d.ts +31 -0
- package/dist/utils/chainQuery.js +82 -0
- package/dist/utils/chainQuery.js.map +1 -0
- package/dist/utils/grantFiles.cjs +4 -1
- package/dist/utils/grantFiles.cjs.map +1 -1
- package/dist/utils/grantFiles.d.ts +10 -20
- package/dist/utils/grantFiles.js +4 -1
- package/dist/utils/grantFiles.js.map +1 -1
- package/dist/utils/grantValidation.cjs.map +1 -1
- package/dist/utils/grantValidation.d.ts +95 -16
- package/dist/utils/grantValidation.js.map +1 -1
- package/dist/utils/grants.cjs.map +1 -1
- package/dist/utils/grants.d.ts +93 -12
- package/dist/utils/grants.js.map +1 -1
- package/dist/utils/ipfs.cjs +2 -4
- package/dist/utils/ipfs.cjs.map +1 -1
- package/dist/utils/ipfs.d.ts +1 -1
- package/dist/utils/ipfs.js +2 -4
- package/dist/utils/ipfs.js.map +1 -1
- package/dist/utils/lazy-import.cjs.map +1 -1
- package/dist/utils/lazy-import.d.ts +32 -7
- package/dist/utils/lazy-import.js.map +1 -1
- package/dist/utils/multicall.cjs +1 -1
- package/dist/utils/multicall.cjs.map +1 -1
- package/dist/utils/multicall.js +1 -1
- package/dist/utils/multicall.js.map +1 -1
- package/dist/utils/runtimeGrantFiles.cjs +84 -0
- package/dist/utils/runtimeGrantFiles.cjs.map +1 -0
- package/dist/utils/runtimeGrantFiles.d.ts +66 -0
- package/dist/utils/runtimeGrantFiles.js +58 -0
- package/dist/utils/runtimeGrantFiles.js.map +1 -0
- package/dist/utils/signatureCache.cjs +8 -2
- package/dist/utils/signatureCache.cjs.map +1 -1
- package/dist/utils/signatureCache.d.ts +49 -8
- package/dist/utils/signatureCache.js +8 -2
- package/dist/utils/signatureCache.js.map +1 -1
- package/dist/utils/subgraphConsistency.cjs +184 -0
- package/dist/utils/subgraphConsistency.cjs.map +1 -0
- package/dist/utils/subgraphConsistency.d.ts +65 -0
- package/dist/utils/subgraphConsistency.js +155 -0
- package/dist/utils/subgraphConsistency.js.map +1 -0
- package/dist/utils/subgraphMetaCache.cjs +101 -0
- package/dist/utils/subgraphMetaCache.cjs.map +1 -0
- package/dist/utils/subgraphMetaCache.d.ts +56 -0
- package/dist/utils/subgraphMetaCache.js +76 -0
- package/dist/utils/subgraphMetaCache.js.map +1 -0
- package/dist/utils/subgraphPagination.cjs +104 -0
- package/dist/utils/subgraphPagination.cjs.map +1 -0
- package/dist/utils/subgraphPagination.d.ts +78 -0
- package/dist/utils/subgraphPagination.js +78 -0
- package/dist/utils/subgraphPagination.js.map +1 -0
- package/dist/utils/transactionHelpers.cjs.map +1 -1
- package/dist/utils/transactionHelpers.d.ts +12 -12
- package/dist/utils/transactionHelpers.js.map +1 -1
- package/dist/utils/typedDataConverter.cjs.map +1 -1
- package/dist/utils/typedDataConverter.d.ts +39 -3
- package/dist/utils/typedDataConverter.js.map +1 -1
- package/dist/utils/urlResolver.cjs +7 -0
- package/dist/utils/urlResolver.cjs.map +1 -1
- package/dist/utils/urlResolver.d.ts +22 -4
- package/dist/utils/urlResolver.js +7 -0
- package/dist/utils/urlResolver.js.map +1 -1
- package/dist/utils/wallet.cjs +63 -0
- package/dist/utils/wallet.cjs.map +1 -0
- package/dist/utils/wallet.d.ts +94 -0
- package/dist/utils/wallet.js +37 -0
- package/dist/utils/wallet.js.map +1 -0
- package/package.json +7 -2
- package/dist/config/addresses.cjs.map +0 -1
- package/dist/config/addresses.js.map +0 -1
- package/dist/generated/abi/DLPTreasuryImplementation.cjs.map +0 -1
- package/dist/generated/abi/DLPTreasuryImplementation.js.map +0 -1
- package/dist/server/handler.cjs +0 -101
- package/dist/server/handler.cjs.map +0 -1
- package/dist/server/handler.d.ts +0 -87
- package/dist/server/handler.js +0 -77
- package/dist/server/handler.js.map +0 -1
- /package/dist/{tests/server-handler.test.d.ts → client/__tests__/enhancedResponse.test.d.ts} +0 -0
package/dist/controllers/data.js
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
import { getContract } from "viem";
|
|
2
|
-
import {
|
|
2
|
+
import { PollingManager } from "../core/pollingManager";
|
|
3
|
+
import { BaseController } from "./base";
|
|
4
|
+
import { getContractAddress } from "../generated/addresses";
|
|
3
5
|
import { getAbi } from "../generated/abi";
|
|
6
|
+
import { InvalidConfigurationError } from "../errors";
|
|
4
7
|
import {
|
|
5
|
-
|
|
8
|
+
GetUserFilesPaginatedDocument,
|
|
6
9
|
GetFileProofsDocument,
|
|
7
10
|
GetDlpDocument,
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
GetUserPermissionsPaginatedDocument,
|
|
12
|
+
GetUserTrustedServersPaginatedDocument
|
|
10
13
|
} from "../generated/subgraph";
|
|
11
14
|
import { print } from "graphql";
|
|
15
|
+
import {
|
|
16
|
+
checkSubgraphConsistency,
|
|
17
|
+
fetchSubgraphMeta
|
|
18
|
+
} from "../utils/subgraphConsistency";
|
|
19
|
+
import {
|
|
20
|
+
executePaginatedQuery,
|
|
21
|
+
mapOrderByToEnum,
|
|
22
|
+
mapOrderDirection
|
|
23
|
+
} from "../utils/subgraphPagination";
|
|
24
|
+
import {
|
|
25
|
+
getUserFilesFromChain,
|
|
26
|
+
determineDataSource
|
|
27
|
+
} from "../utils/chainQuery";
|
|
12
28
|
import {
|
|
13
29
|
generateEncryptionKey,
|
|
14
30
|
decryptBlobWithSignedKey,
|
|
@@ -23,11 +39,12 @@ import {
|
|
|
23
39
|
fetchAndValidateSchema
|
|
24
40
|
} from "../utils/schemaValidation";
|
|
25
41
|
import { gasAwareMulticall } from "../utils/multicall";
|
|
26
|
-
class DataController {
|
|
42
|
+
class DataController extends BaseController {
|
|
27
43
|
constructor(context) {
|
|
28
|
-
|
|
44
|
+
super(context);
|
|
29
45
|
}
|
|
30
46
|
async upload(params) {
|
|
47
|
+
this.assertWallet();
|
|
31
48
|
const {
|
|
32
49
|
content,
|
|
33
50
|
filename,
|
|
@@ -35,12 +52,18 @@ class DataController {
|
|
|
35
52
|
permissions = [],
|
|
36
53
|
encrypt = true,
|
|
37
54
|
providerName,
|
|
38
|
-
owner
|
|
55
|
+
owner,
|
|
56
|
+
schemaValidation = "strict"
|
|
39
57
|
} = params;
|
|
58
|
+
if (encrypt && owner && owner.toLowerCase() !== this.context.userAddress.toLowerCase()) {
|
|
59
|
+
throw new InvalidConfigurationError(
|
|
60
|
+
"The 'owner' parameter cannot be different from the connected wallet's address when encryption is enabled. This would create an un-decryptable file."
|
|
61
|
+
);
|
|
62
|
+
}
|
|
40
63
|
try {
|
|
41
64
|
let isValid = true;
|
|
42
65
|
let validationErrors = [];
|
|
43
|
-
if (schemaId !== void 0) {
|
|
66
|
+
if (schemaId !== void 0 && schemaValidation !== "skip") {
|
|
44
67
|
try {
|
|
45
68
|
const { SchemaController } = await import("./schemas");
|
|
46
69
|
const schemaController = new SchemaController(this.context);
|
|
@@ -64,16 +87,20 @@ class DataController {
|
|
|
64
87
|
}
|
|
65
88
|
validateDataAgainstSchema(parsedContent, schema);
|
|
66
89
|
} catch (error) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
90
|
+
if (schemaValidation === "strict") {
|
|
91
|
+
throw error;
|
|
92
|
+
} else if (schemaValidation === "warn") {
|
|
93
|
+
console.warn(
|
|
94
|
+
'[Vana SDK] Schema validation failed, but continuing due to validation mode "warn"'
|
|
95
|
+
);
|
|
96
|
+
if (error instanceof Error) {
|
|
97
|
+
console.warn(" Validation error:", error.message);
|
|
98
|
+
if (typeof error === "object" && "errors" in error && Array.isArray(error.errors)) {
|
|
99
|
+
console.warn(" Detailed errors:", error.errors);
|
|
100
|
+
}
|
|
74
101
|
}
|
|
75
|
-
|
|
76
|
-
validationErrors = ["Schema validation failed"];
|
|
102
|
+
isValid = false;
|
|
103
|
+
validationErrors = error instanceof Error ? [error.message] : ["Schema validation failed"];
|
|
77
104
|
}
|
|
78
105
|
}
|
|
79
106
|
}
|
|
@@ -83,9 +110,10 @@ class DataController {
|
|
|
83
110
|
encrypt,
|
|
84
111
|
providerName
|
|
85
112
|
);
|
|
86
|
-
const userAddress = owner ??
|
|
113
|
+
const userAddress = owner ?? this.context.userAddress;
|
|
87
114
|
let encryptedPermissions = [];
|
|
88
115
|
if (permissions.length > 0 && encrypt) {
|
|
116
|
+
this.assertWallet();
|
|
89
117
|
const userEncryptionKey = await generateEncryptionKey(
|
|
90
118
|
this.context.walletClient,
|
|
91
119
|
this.context.platform,
|
|
@@ -106,29 +134,35 @@ class DataController {
|
|
|
106
134
|
);
|
|
107
135
|
}
|
|
108
136
|
let result;
|
|
109
|
-
if (this.context.
|
|
110
|
-
|
|
111
|
-
|
|
137
|
+
if (this.context.relayer) {
|
|
138
|
+
const request = {
|
|
139
|
+
type: "direct",
|
|
140
|
+
operation: "submitFileAdditionComplete",
|
|
141
|
+
params: {
|
|
112
142
|
url: uploadResult.url,
|
|
113
143
|
userAddress,
|
|
114
144
|
permissions: encryptedPermissions,
|
|
115
145
|
schemaId: schemaId ?? 0,
|
|
116
146
|
ownerAddress: owner
|
|
117
147
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
148
|
+
};
|
|
149
|
+
const response = await this.context.relayer(request);
|
|
150
|
+
if (response.type === "error") {
|
|
151
|
+
throw new Error(response.error);
|
|
152
|
+
}
|
|
153
|
+
if (response.type === "pending") {
|
|
154
|
+
result = await this.pollRelayerForConfirmation(
|
|
155
|
+
response.operationId,
|
|
156
|
+
void 0
|
|
157
|
+
// TODO: Add TransactionOptions to upload method signature
|
|
124
158
|
);
|
|
159
|
+
} else if (response.type === "direct" && typeof response.result === "object" && response.result !== null && "fileId" in response.result) {
|
|
160
|
+
result = response.result;
|
|
161
|
+
} else {
|
|
162
|
+
throw new Error("Invalid response from relayer");
|
|
125
163
|
}
|
|
126
|
-
result = await this.context.relayerCallbacks.submitFileAddition(
|
|
127
|
-
uploadResult.url,
|
|
128
|
-
userAddress
|
|
129
|
-
);
|
|
130
164
|
} else {
|
|
131
|
-
const txResult = await this.
|
|
165
|
+
const txResult = await this.addFileWithEncryptedPermissionsAndSchema(
|
|
132
166
|
uploadResult.url,
|
|
133
167
|
userAddress,
|
|
134
168
|
encryptedPermissions,
|
|
@@ -164,35 +198,110 @@ class DataController {
|
|
|
164
198
|
}
|
|
165
199
|
}
|
|
166
200
|
/**
|
|
167
|
-
*
|
|
201
|
+
* Encrypts data using wallet-derived encryption.
|
|
168
202
|
*
|
|
169
203
|
* @remarks
|
|
170
|
-
* This
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
* decryption.
|
|
204
|
+
* This method provides secure, wallet-based encryption for data before uploading
|
|
205
|
+
* to the Vana network. It's the counterpart to decryptFile for preparing data
|
|
206
|
+
* for secure storage.
|
|
174
207
|
*
|
|
175
208
|
* The method automatically:
|
|
176
|
-
* - Generates
|
|
177
|
-
* -
|
|
178
|
-
* -
|
|
179
|
-
* -
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
* @param
|
|
186
|
-
* @
|
|
187
|
-
* @
|
|
188
|
-
* @
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
209
|
+
* - Generates an encryption key from the user's wallet signature
|
|
210
|
+
* - Converts the input data to a Blob if necessary
|
|
211
|
+
* - Encrypts the data using the generated key
|
|
212
|
+
* - Returns both the encrypted data and the encryption key
|
|
213
|
+
*
|
|
214
|
+
* The encryption key returned can be stored and later used for decryption,
|
|
215
|
+
* or shared with others to grant them decryption access.
|
|
216
|
+
*
|
|
217
|
+
* @param data - The data to encrypt (Blob, string, or object)
|
|
218
|
+
* @param options - Optional encryption configuration
|
|
219
|
+
* @returns Promise resolving to encrypted data and the encryption key used
|
|
220
|
+
* @throws {Error} When wallet is not connected or encryption fails
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* // Encrypt a string
|
|
224
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
225
|
+
* "My secret data"
|
|
226
|
+
* );
|
|
227
|
+
*
|
|
228
|
+
* // Encrypt JSON with custom MIME type
|
|
229
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
230
|
+
* { name: "Alice", age: 30 },
|
|
231
|
+
* { mimeType: "application/json" }
|
|
232
|
+
* );
|
|
233
|
+
*
|
|
234
|
+
* // With custom encryption seed
|
|
235
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
236
|
+
* "Secret message",
|
|
237
|
+
* { seed: "My custom encryption seed" }
|
|
238
|
+
* );
|
|
239
|
+
*
|
|
240
|
+
* // Upload the encrypted data
|
|
241
|
+
* const result = await vana.data.uploadToStorage(encryptedData);
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
async encryptFile(data, options) {
|
|
245
|
+
this.assertWallet();
|
|
246
|
+
try {
|
|
247
|
+
const encryptionKey = await generateEncryptionKey(
|
|
248
|
+
this.context.walletClient,
|
|
249
|
+
this.context.platform,
|
|
250
|
+
options?.seed ?? DEFAULT_ENCRYPTION_SEED
|
|
251
|
+
);
|
|
252
|
+
let blob;
|
|
253
|
+
if (data instanceof Blob) {
|
|
254
|
+
blob = data;
|
|
255
|
+
} else if (typeof data === "string") {
|
|
256
|
+
blob = new Blob([data], { type: options?.mimeType ?? "text/plain" });
|
|
257
|
+
} else {
|
|
258
|
+
blob = new Blob([JSON.stringify(data)], {
|
|
259
|
+
type: options?.mimeType ?? "application/json"
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
const encryptedData = await encryptBlobWithSignedKey(
|
|
263
|
+
blob,
|
|
264
|
+
encryptionKey,
|
|
265
|
+
this.context.platform
|
|
266
|
+
);
|
|
267
|
+
return {
|
|
268
|
+
encryptedData,
|
|
269
|
+
encryptionKey
|
|
270
|
+
};
|
|
271
|
+
} catch (error) {
|
|
272
|
+
throw new Error(
|
|
273
|
+
`Failed to encrypt file: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Decrypts a file using wallet-derived decryption key.
|
|
279
|
+
*
|
|
280
|
+
* @remarks
|
|
281
|
+
* Counterpart to `upload()` for decrypting user files. Automatically
|
|
282
|
+
* generates decryption key from wallet, fetches encrypted content,
|
|
283
|
+
* and decrypts. Supports IPFS (with gateway fallback) and HTTP URLs.
|
|
284
|
+
*
|
|
285
|
+
* @param file - UserFile object from `getUserFiles()`
|
|
286
|
+
* @param options - Decryption options
|
|
287
|
+
* @param options.seed - Custom encryption seed.
|
|
288
|
+
* Defaults to standard Vana seed.
|
|
289
|
+
*
|
|
290
|
+
* @returns Decrypted content as Blob
|
|
291
|
+
*
|
|
292
|
+
* @throws {Error} No wallet connected.
|
|
293
|
+
* Connect wallet before decrypting.
|
|
294
|
+
* @throws {Error} Network error accessing file.
|
|
295
|
+
* Check CORS settings or server availability.
|
|
296
|
+
* @throws {Error} File not found (404).
|
|
297
|
+
* File no longer available at stored URL.
|
|
298
|
+
* @throws {Error} Access denied (403).
|
|
299
|
+
* No permission to access file.
|
|
300
|
+
* @throws {Error} Invalid file format.
|
|
301
|
+
* File not encrypted with Vana protocol.
|
|
302
|
+
* @throws {Error} Wrong encryption key.
|
|
303
|
+
* Verify seed matches upload or use default.
|
|
304
|
+
*
|
|
196
305
|
* @example
|
|
197
306
|
* ```typescript
|
|
198
307
|
* // Basic file decryption
|
|
@@ -218,12 +327,14 @@ class DataController {
|
|
|
218
327
|
* fs.writeFileSync('decrypted-file.txt', Buffer.from(buffer));
|
|
219
328
|
* ```
|
|
220
329
|
*/
|
|
221
|
-
async decryptFile(file,
|
|
330
|
+
async decryptFile(file, options) {
|
|
331
|
+
this.assertWallet();
|
|
222
332
|
try {
|
|
333
|
+
this.assertWallet();
|
|
223
334
|
const encryptionKey = await generateEncryptionKey(
|
|
224
335
|
this.context.walletClient,
|
|
225
336
|
this.context.platform,
|
|
226
|
-
|
|
337
|
+
options?.seed ?? DEFAULT_ENCRYPTION_SEED
|
|
227
338
|
);
|
|
228
339
|
let encryptedBlob;
|
|
229
340
|
try {
|
|
@@ -306,99 +417,126 @@ class DataController {
|
|
|
306
417
|
}
|
|
307
418
|
}
|
|
308
419
|
/**
|
|
309
|
-
* Retrieves all
|
|
420
|
+
* Retrieves all files owned by a specific user address.
|
|
310
421
|
*
|
|
311
422
|
* @remarks
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
* @
|
|
323
|
-
*
|
|
324
|
-
* @
|
|
325
|
-
*
|
|
326
|
-
* @throws {Error}
|
|
327
|
-
*
|
|
328
|
-
* @throws {Error}
|
|
423
|
+
* Queries the Vana subgraph for files owned by the specified address.
|
|
424
|
+
* Automatically deduplicates by file ID, keeping the latest version
|
|
425
|
+
* when duplicates exist from re-indexing or chain reorganizations.
|
|
426
|
+
* Enriches results with DLP proof data when available.
|
|
427
|
+
*
|
|
428
|
+
* @param params - Query configuration
|
|
429
|
+
* @param params.owner - Wallet address of the file owner
|
|
430
|
+
* @param params.subgraphUrl - Subgraph endpoint override.
|
|
431
|
+
* Defaults to context configuration.
|
|
432
|
+
*
|
|
433
|
+
* @returns Array of UserFile objects sorted by timestamp (newest first)
|
|
434
|
+
*
|
|
435
|
+
* @throws {Error} Subgraph URL not configured.
|
|
436
|
+
* Provide `subgraphUrl` parameter or configure in Vana constructor.
|
|
437
|
+
* @throws {Error} Subgraph request failed.
|
|
438
|
+
* Check network connectivity and subgraph availability.
|
|
439
|
+
* @throws {Error} Subgraph returned errors.
|
|
440
|
+
* Review query parameters and subgraph logs.
|
|
441
|
+
*
|
|
329
442
|
* @example
|
|
330
443
|
* ```typescript
|
|
331
|
-
* // Query files for a specific user
|
|
332
444
|
* const files = await vana.data.getUserFiles({
|
|
333
|
-
* owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
|
|
445
|
+
* owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
|
|
334
446
|
* });
|
|
335
447
|
*
|
|
336
448
|
* files.forEach(file => {
|
|
337
|
-
* console.log(`File ${file.id}: ${file.url}
|
|
449
|
+
* console.log(`File ${file.id}: ${file.url}`);
|
|
450
|
+
* console.log(` Schema: ${file.schemaId}`);
|
|
451
|
+
* console.log(` DLPs: ${file.dlpIds?.join(", ") || "none"}`);
|
|
338
452
|
* });
|
|
339
453
|
* ```
|
|
340
454
|
*/
|
|
341
|
-
async getUserFiles(params) {
|
|
455
|
+
async getUserFiles(params, options) {
|
|
342
456
|
const { owner, subgraphUrl } = params;
|
|
457
|
+
let dataSource = options?.source === "chain" ? "chain" : "subgraph";
|
|
458
|
+
if (options?.source === "auto" || !options?.source && options?.minBlock) {
|
|
459
|
+
const endpoint2 = subgraphUrl ?? this.context.subgraphUrl;
|
|
460
|
+
const currentBlock = await this.context.publicClient.getBlockNumber();
|
|
461
|
+
let subgraphBlock;
|
|
462
|
+
if (endpoint2) {
|
|
463
|
+
try {
|
|
464
|
+
const meta = await fetchSubgraphMeta(endpoint2);
|
|
465
|
+
subgraphBlock = meta.blockNumber;
|
|
466
|
+
} catch {
|
|
467
|
+
subgraphBlock = void 0;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
dataSource = determineDataSource(
|
|
471
|
+
options?.source,
|
|
472
|
+
options?.minBlock,
|
|
473
|
+
currentBlock,
|
|
474
|
+
subgraphBlock
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
if (dataSource === "chain") {
|
|
478
|
+
const publicClient = this.context.publicClient;
|
|
479
|
+
const chainId = await publicClient.getChainId();
|
|
480
|
+
const contractAddress = getContractAddress(chainId, "DataRegistry");
|
|
481
|
+
const files = await getUserFilesFromChain(
|
|
482
|
+
publicClient,
|
|
483
|
+
contractAddress,
|
|
484
|
+
owner,
|
|
485
|
+
options?.minBlock ? BigInt(options.minBlock) : void 0
|
|
486
|
+
);
|
|
487
|
+
const limit = options?.fetchAll ? files.length : options?.limit ?? 100;
|
|
488
|
+
const offset = options?.offset ?? 0;
|
|
489
|
+
return files.slice(offset, offset + limit);
|
|
490
|
+
}
|
|
343
491
|
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
344
492
|
if (!endpoint) {
|
|
345
493
|
throw new Error(
|
|
346
494
|
"subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor."
|
|
347
495
|
);
|
|
348
496
|
}
|
|
497
|
+
if (options?.minBlock || options?.waitForSync) {
|
|
498
|
+
await checkSubgraphConsistency(endpoint, options);
|
|
499
|
+
}
|
|
349
500
|
try {
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
501
|
+
const orderByMap = {
|
|
502
|
+
id: "id",
|
|
503
|
+
addedAtBlock: "addedAtBlock",
|
|
504
|
+
addedAtTimestamp: "addedAtTimestamp",
|
|
505
|
+
url: "url",
|
|
506
|
+
schemaId: "schemaId"
|
|
507
|
+
};
|
|
508
|
+
const allFiles = await executePaginatedQuery({
|
|
509
|
+
endpoint,
|
|
510
|
+
document: GetUserFilesPaginatedDocument,
|
|
511
|
+
baseVariables: {
|
|
512
|
+
userId: owner.toLowerCase(),
|
|
513
|
+
// Subgraph requires lowercase addresses
|
|
514
|
+
orderBy: mapOrderByToEnum(
|
|
515
|
+
options?.orderBy,
|
|
516
|
+
orderByMap,
|
|
517
|
+
"addedAtBlock"
|
|
518
|
+
),
|
|
519
|
+
orderDirection: mapOrderDirection(
|
|
520
|
+
options?.orderDirection,
|
|
521
|
+
"asc",
|
|
522
|
+
"desc"
|
|
523
|
+
)
|
|
354
524
|
},
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
// Subgraph requires lowercase addresses
|
|
360
|
-
}
|
|
361
|
-
})
|
|
362
|
-
});
|
|
363
|
-
if (!response.ok) {
|
|
364
|
-
throw new Error(
|
|
365
|
-
`Subgraph request failed: ${response.status} ${response.statusText}`
|
|
366
|
-
);
|
|
367
|
-
}
|
|
368
|
-
const result = await response.json();
|
|
369
|
-
if (result.errors) {
|
|
370
|
-
throw new Error(
|
|
371
|
-
`Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
372
|
-
);
|
|
373
|
-
}
|
|
374
|
-
const user = result.data?.user;
|
|
375
|
-
if (!user?.files?.length) {
|
|
376
|
-
console.warn("No files found for user:", owner);
|
|
377
|
-
return [];
|
|
378
|
-
}
|
|
379
|
-
const fileMap = /* @__PURE__ */ new Map();
|
|
380
|
-
user.files.forEach((file) => {
|
|
381
|
-
const fileId = parseInt(file.id);
|
|
382
|
-
const userFile = {
|
|
383
|
-
id: fileId,
|
|
525
|
+
options,
|
|
526
|
+
extractItems: (data) => data?.user?.files,
|
|
527
|
+
transformItem: (file) => ({
|
|
528
|
+
id: parseInt(file.id),
|
|
384
529
|
url: file.url,
|
|
385
530
|
ownerAddress: file.owner.id,
|
|
386
531
|
addedAtBlock: BigInt(file.addedAtBlock),
|
|
387
532
|
schemaId: parseInt(file.schemaId),
|
|
388
533
|
addedAtTimestamp: BigInt(file.addedAtTimestamp),
|
|
389
534
|
transactionHash: file.transactionHash
|
|
390
|
-
}
|
|
391
|
-
const existing = fileMap.get(fileId);
|
|
392
|
-
if (!existing || userFile.addedAtTimestamp && existing.addedAtTimestamp && userFile.addedAtTimestamp > existing.addedAtTimestamp) {
|
|
393
|
-
fileMap.set(fileId, userFile);
|
|
394
|
-
}
|
|
535
|
+
})
|
|
395
536
|
});
|
|
396
|
-
|
|
397
|
-
(a, b) => Number((b.addedAtTimestamp ?? 0n) - (a.addedAtTimestamp ?? 0n))
|
|
398
|
-
);
|
|
399
|
-
if (userFiles.length > 0) {
|
|
537
|
+
if (allFiles.length > 0) {
|
|
400
538
|
try {
|
|
401
|
-
const fileIds =
|
|
539
|
+
const fileIds = allFiles.map((f) => f.id);
|
|
402
540
|
let proofMap;
|
|
403
541
|
try {
|
|
404
542
|
proofMap = await this._fetchProofsFromSubgraph(fileIds, endpoint);
|
|
@@ -409,7 +547,7 @@ class DataController {
|
|
|
409
547
|
);
|
|
410
548
|
proofMap = await this._fetchProofsFromChain(fileIds);
|
|
411
549
|
}
|
|
412
|
-
for (const file of
|
|
550
|
+
for (const file of allFiles) {
|
|
413
551
|
const dlpIds = proofMap.get(file.id);
|
|
414
552
|
if (dlpIds && dlpIds.length > 0) {
|
|
415
553
|
file.dlpIds = dlpIds;
|
|
@@ -419,7 +557,7 @@ class DataController {
|
|
|
419
557
|
console.warn("Failed to fetch proof data for files:", error);
|
|
420
558
|
}
|
|
421
559
|
}
|
|
422
|
-
return
|
|
560
|
+
return allFiles;
|
|
423
561
|
} catch (error) {
|
|
424
562
|
console.error("Failed to fetch user files from subgraph:", error);
|
|
425
563
|
throw new Error(
|
|
@@ -487,7 +625,7 @@ class DataController {
|
|
|
487
625
|
* @returns Map of file IDs to their associated DLP IDs
|
|
488
626
|
*/
|
|
489
627
|
async _fetchProofsFromChain(fileIds) {
|
|
490
|
-
const chainId = this.context.
|
|
628
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
491
629
|
if (!chainId) {
|
|
492
630
|
throw new Error("Chain ID not available");
|
|
493
631
|
}
|
|
@@ -545,6 +683,9 @@ class DataController {
|
|
|
545
683
|
*/
|
|
546
684
|
async getDLP(dlpId, options = {}) {
|
|
547
685
|
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
686
|
+
if (subgraphUrl && (options.minBlock || options.waitForSync)) {
|
|
687
|
+
await checkSubgraphConsistency(subgraphUrl, options);
|
|
688
|
+
}
|
|
548
689
|
if (subgraphUrl) {
|
|
549
690
|
try {
|
|
550
691
|
const response = await fetch(subgraphUrl, {
|
|
@@ -578,15 +719,15 @@ class DataController {
|
|
|
578
719
|
name: result.data.dlp.name ?? "",
|
|
579
720
|
metadata: result.data.dlp.metadata ?? void 0,
|
|
580
721
|
status: result.data.dlp.status ? parseInt(result.data.dlp.status) : void 0,
|
|
581
|
-
address: result.data.dlp.address,
|
|
582
|
-
owner: result.data.dlp.owner
|
|
722
|
+
address: result.data.dlp.address ? result.data.dlp.address : void 0,
|
|
723
|
+
owner: result.data.dlp.owner ? result.data.dlp.owner : void 0
|
|
583
724
|
};
|
|
584
725
|
} catch (error) {
|
|
585
726
|
console.debug("Subgraph query failed, falling back to chain:", error);
|
|
586
727
|
}
|
|
587
728
|
}
|
|
588
729
|
try {
|
|
589
|
-
const chainId = this.context.
|
|
730
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
590
731
|
if (!chainId) {
|
|
591
732
|
throw new Error("Chain ID not available");
|
|
592
733
|
}
|
|
@@ -685,15 +826,15 @@ class DataController {
|
|
|
685
826
|
name: dlp.name ?? "",
|
|
686
827
|
metadata: dlp.metadata,
|
|
687
828
|
status: dlp.status ? parseInt(dlp.status) : void 0,
|
|
688
|
-
address: dlp.address,
|
|
689
|
-
owner: dlp.owner
|
|
829
|
+
address: dlp.address ? dlp.address : void 0,
|
|
830
|
+
owner: dlp.owner ? dlp.owner : void 0
|
|
690
831
|
}));
|
|
691
832
|
} catch (error) {
|
|
692
833
|
console.debug("Subgraph query failed, falling back to chain:", error);
|
|
693
834
|
}
|
|
694
835
|
}
|
|
695
836
|
try {
|
|
696
|
-
const chainId = this.context.
|
|
837
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
697
838
|
if (!chainId) {
|
|
698
839
|
throw new Error("Chain ID not available");
|
|
699
840
|
}
|
|
@@ -763,21 +904,33 @@ class DataController {
|
|
|
763
904
|
* @returns Promise resolving to an array of permission objects
|
|
764
905
|
* @throws Error if both subgraph and RPC queries fail
|
|
765
906
|
*/
|
|
766
|
-
async getUserPermissions(params) {
|
|
907
|
+
async getUserPermissions(params, options) {
|
|
767
908
|
const { user, subgraphUrl } = params;
|
|
768
909
|
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
910
|
+
if (endpoint && (options?.minBlock || options?.waitForSync)) {
|
|
911
|
+
await checkSubgraphConsistency(endpoint, options);
|
|
912
|
+
}
|
|
769
913
|
if (endpoint) {
|
|
770
914
|
try {
|
|
771
|
-
const permissions = await this._getUserPermissionsViaSubgraph(
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
915
|
+
const permissions = await this._getUserPermissionsViaSubgraph(
|
|
916
|
+
{
|
|
917
|
+
user,
|
|
918
|
+
subgraphUrl: endpoint
|
|
919
|
+
},
|
|
920
|
+
options
|
|
921
|
+
);
|
|
775
922
|
return permissions;
|
|
776
923
|
} catch (error) {
|
|
777
924
|
console.warn("Subgraph query failed, falling back to RPC:", error);
|
|
778
925
|
}
|
|
779
926
|
}
|
|
780
|
-
|
|
927
|
+
const allPermissions = await this._getUserPermissionsViaRpc({ user });
|
|
928
|
+
if (options && !options.fetchAll) {
|
|
929
|
+
const limit = options.limit ?? 100;
|
|
930
|
+
const offset = options.offset ?? 0;
|
|
931
|
+
return allPermissions.slice(offset, offset + limit);
|
|
932
|
+
}
|
|
933
|
+
return allPermissions;
|
|
781
934
|
}
|
|
782
935
|
/**
|
|
783
936
|
* Internal method: Query user permissions via subgraph
|
|
@@ -787,46 +940,48 @@ class DataController {
|
|
|
787
940
|
* @param params.subgraphUrl - The subgraph URL endpoint to query
|
|
788
941
|
* @returns Promise resolving to an array of permission objects
|
|
789
942
|
*/
|
|
790
|
-
async _getUserPermissionsViaSubgraph(params) {
|
|
943
|
+
async _getUserPermissionsViaSubgraph(params, options) {
|
|
791
944
|
const { user, subgraphUrl } = params;
|
|
792
945
|
try {
|
|
793
|
-
const
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
946
|
+
const orderByMap = {
|
|
947
|
+
id: "id",
|
|
948
|
+
addedAtBlock: "addedAtBlock",
|
|
949
|
+
addedAtTimestamp: "addedAtTimestamp",
|
|
950
|
+
grant: "grant",
|
|
951
|
+
nonce: "nonce",
|
|
952
|
+
startBlock: "startBlock",
|
|
953
|
+
endBlock: "endBlock"
|
|
954
|
+
};
|
|
955
|
+
const permissions = await executePaginatedQuery({
|
|
956
|
+
endpoint: subgraphUrl,
|
|
957
|
+
document: GetUserPermissionsPaginatedDocument,
|
|
958
|
+
baseVariables: {
|
|
959
|
+
userId: user.toLowerCase(),
|
|
960
|
+
orderBy: mapOrderByToEnum(
|
|
961
|
+
options?.orderBy,
|
|
962
|
+
orderByMap,
|
|
963
|
+
"addedAtTimestamp"
|
|
964
|
+
),
|
|
965
|
+
orderDirection: mapOrderDirection(
|
|
966
|
+
options?.orderDirection,
|
|
967
|
+
"desc",
|
|
968
|
+
"asc"
|
|
969
|
+
)
|
|
797
970
|
},
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
971
|
+
options,
|
|
972
|
+
extractItems: (data) => data?.user?.permissions,
|
|
973
|
+
transformItem: (permission) => ({
|
|
974
|
+
id: permission.id,
|
|
975
|
+
grant: permission.grant,
|
|
976
|
+
nonce: BigInt(permission.nonce),
|
|
977
|
+
signature: permission.signature,
|
|
978
|
+
addedAtBlock: BigInt(permission.addedAtBlock),
|
|
979
|
+
addedAtTimestamp: BigInt(permission.addedAtTimestamp),
|
|
980
|
+
transactionHash: permission.transactionHash,
|
|
981
|
+
user
|
|
803
982
|
})
|
|
804
983
|
});
|
|
805
|
-
|
|
806
|
-
throw new Error(
|
|
807
|
-
`Subgraph request failed: ${response.status} ${response.statusText}`
|
|
808
|
-
);
|
|
809
|
-
}
|
|
810
|
-
const result = await response.json();
|
|
811
|
-
if (result.errors) {
|
|
812
|
-
throw new Error(
|
|
813
|
-
`Subgraph query errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
814
|
-
);
|
|
815
|
-
}
|
|
816
|
-
const userData = result.data?.user;
|
|
817
|
-
if (!userData?.permissions?.length) {
|
|
818
|
-
return [];
|
|
819
|
-
}
|
|
820
|
-
return userData.permissions.map((permission) => ({
|
|
821
|
-
id: permission.id,
|
|
822
|
-
grant: permission.grant,
|
|
823
|
-
nonce: BigInt(permission.nonce),
|
|
824
|
-
signature: permission.signature,
|
|
825
|
-
addedAtBlock: BigInt(permission.addedAtBlock),
|
|
826
|
-
addedAtTimestamp: BigInt(permission.addedAtTimestamp),
|
|
827
|
-
transactionHash: permission.transactionHash,
|
|
828
|
-
user
|
|
829
|
-
})).sort((a, b) => Number(b.addedAtTimestamp - a.addedAtTimestamp));
|
|
984
|
+
return permissions;
|
|
830
985
|
} catch (error) {
|
|
831
986
|
console.error("Failed to query user permissions from subgraph:", error);
|
|
832
987
|
throw error;
|
|
@@ -842,7 +997,7 @@ class DataController {
|
|
|
842
997
|
async _getUserPermissionsViaRpc(params) {
|
|
843
998
|
const { user } = params;
|
|
844
999
|
try {
|
|
845
|
-
const chainId = this.context.
|
|
1000
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
846
1001
|
if (!chainId) {
|
|
847
1002
|
throw new Error("Chain ID not available");
|
|
848
1003
|
}
|
|
@@ -959,20 +1114,28 @@ class DataController {
|
|
|
959
1114
|
* });
|
|
960
1115
|
* ```
|
|
961
1116
|
*/
|
|
962
|
-
async getUserTrustedServers(params) {
|
|
963
|
-
const { user
|
|
1117
|
+
async getUserTrustedServers(params, options) {
|
|
1118
|
+
const { user } = params;
|
|
964
1119
|
const subgraphUrl = params.subgraphUrl ?? this.context.subgraphUrl;
|
|
1120
|
+
if (subgraphUrl && (options?.minBlock || options?.waitForSync)) {
|
|
1121
|
+
await checkSubgraphConsistency(subgraphUrl, options);
|
|
1122
|
+
}
|
|
965
1123
|
if (subgraphUrl) {
|
|
966
1124
|
try {
|
|
967
|
-
const servers = await this._getUserTrustedServersViaSubgraph(
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
1125
|
+
const servers = await this._getUserTrustedServersViaSubgraph(
|
|
1126
|
+
{
|
|
1127
|
+
user,
|
|
1128
|
+
subgraphUrl
|
|
1129
|
+
},
|
|
1130
|
+
options
|
|
1131
|
+
);
|
|
1132
|
+
return servers;
|
|
972
1133
|
} catch (error) {
|
|
973
1134
|
console.warn("Subgraph query failed, falling back to RPC:", error);
|
|
974
1135
|
}
|
|
975
1136
|
}
|
|
1137
|
+
const limit = options?.fetchAll ? Number.MAX_SAFE_INTEGER : options?.limit ?? 100;
|
|
1138
|
+
const offset = options?.offset ?? 0;
|
|
976
1139
|
const rpcResult = await this._getUserTrustedServersViaRpc({
|
|
977
1140
|
user,
|
|
978
1141
|
limit,
|
|
@@ -988,7 +1151,7 @@ class DataController {
|
|
|
988
1151
|
* @param params.subgraphUrl - The subgraph URL endpoint to query
|
|
989
1152
|
* @returns Promise resolving to an array of trusted server objects
|
|
990
1153
|
*/
|
|
991
|
-
async _getUserTrustedServersViaSubgraph(params) {
|
|
1154
|
+
async _getUserTrustedServersViaSubgraph(params, options) {
|
|
992
1155
|
const { user, subgraphUrl } = params;
|
|
993
1156
|
const graphqlEndpoint = subgraphUrl;
|
|
994
1157
|
if (!graphqlEndpoint) {
|
|
@@ -997,42 +1160,46 @@ class DataController {
|
|
|
997
1160
|
);
|
|
998
1161
|
}
|
|
999
1162
|
try {
|
|
1000
|
-
const
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1163
|
+
const orderByMap = {
|
|
1164
|
+
id: "id",
|
|
1165
|
+
trustedAt: "trustedAt",
|
|
1166
|
+
trustedAtBlock: "trustedAtBlock",
|
|
1167
|
+
server: "server",
|
|
1168
|
+
user: "user"
|
|
1169
|
+
};
|
|
1170
|
+
const serverTrusts = await executePaginatedQuery({
|
|
1171
|
+
endpoint: graphqlEndpoint,
|
|
1172
|
+
document: GetUserTrustedServersPaginatedDocument,
|
|
1173
|
+
baseVariables: {
|
|
1174
|
+
userId: user.toLowerCase(),
|
|
1175
|
+
// Subgraph requires lowercase addresses
|
|
1176
|
+
orderBy: mapOrderByToEnum(
|
|
1177
|
+
options?.orderBy,
|
|
1178
|
+
orderByMap,
|
|
1179
|
+
"trustedAtBlock"
|
|
1180
|
+
),
|
|
1181
|
+
orderDirection: mapOrderDirection(
|
|
1182
|
+
options?.orderDirection,
|
|
1183
|
+
"desc",
|
|
1184
|
+
"asc"
|
|
1185
|
+
)
|
|
1004
1186
|
},
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1187
|
+
options,
|
|
1188
|
+
extractItems: (data) => {
|
|
1189
|
+
const trusts = data?.user?.serverTrusts ?? [];
|
|
1190
|
+
return trusts.filter((trust) => !trust.untrustedAtBlock);
|
|
1191
|
+
},
|
|
1192
|
+
transformItem: (trust) => ({
|
|
1193
|
+
id: trust.server.id,
|
|
1194
|
+
serverAddress: trust.server.serverAddress,
|
|
1195
|
+
serverUrl: trust.server.url,
|
|
1196
|
+
trustedAt: BigInt(trust.trustedAt),
|
|
1197
|
+
user,
|
|
1198
|
+
name: ""
|
|
1199
|
+
// Not available in new schema, will be empty
|
|
1011
1200
|
})
|
|
1012
1201
|
});
|
|
1013
|
-
|
|
1014
|
-
throw new Error(
|
|
1015
|
-
`Subgraph request failed: ${response.status} ${response.statusText}`
|
|
1016
|
-
);
|
|
1017
|
-
}
|
|
1018
|
-
const result = await response.json();
|
|
1019
|
-
if (result.errors) {
|
|
1020
|
-
throw new Error(
|
|
1021
|
-
`Subgraph query errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
1022
|
-
);
|
|
1023
|
-
}
|
|
1024
|
-
if (!result.data?.user) {
|
|
1025
|
-
return [];
|
|
1026
|
-
}
|
|
1027
|
-
return (result.data.user.serverTrusts ?? []).filter((trust) => !trust.untrustedAtBlock).map((trust) => ({
|
|
1028
|
-
id: trust.server.id,
|
|
1029
|
-
serverAddress: trust.server.serverAddress,
|
|
1030
|
-
serverUrl: trust.server.url,
|
|
1031
|
-
trustedAt: BigInt(trust.trustedAt),
|
|
1032
|
-
user,
|
|
1033
|
-
name: ""
|
|
1034
|
-
// Not available in new schema, will be empty
|
|
1035
|
-
}));
|
|
1202
|
+
return serverTrusts;
|
|
1036
1203
|
} catch (error) {
|
|
1037
1204
|
console.error("Failed to query trusted servers from subgraph:", error);
|
|
1038
1205
|
throw error;
|
|
@@ -1050,7 +1217,7 @@ class DataController {
|
|
|
1050
1217
|
async _getUserTrustedServersViaRpc(params) {
|
|
1051
1218
|
const { user, limit, offset } = params;
|
|
1052
1219
|
try {
|
|
1053
|
-
const chainId = this.context.
|
|
1220
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1054
1221
|
if (!chainId) {
|
|
1055
1222
|
throw new Error("Chain ID not available");
|
|
1056
1223
|
}
|
|
@@ -1134,23 +1301,31 @@ class DataController {
|
|
|
1134
1301
|
}
|
|
1135
1302
|
}
|
|
1136
1303
|
/**
|
|
1137
|
-
*
|
|
1304
|
+
* Retrieves total file count from Data Registry.
|
|
1305
|
+
*
|
|
1306
|
+
* @remarks
|
|
1307
|
+
* Queries blockchain for complete file count across all users.
|
|
1308
|
+
* Useful for pagination and network statistics.
|
|
1309
|
+
*
|
|
1310
|
+
* @returns Total number of registered files
|
|
1311
|
+
*
|
|
1312
|
+
* @throws {Error} Chain ID not available.
|
|
1313
|
+
* Ensure network connection.
|
|
1314
|
+
* @throws {Error} Contract read failed.
|
|
1315
|
+
* Check RPC availability.
|
|
1138
1316
|
*
|
|
1139
|
-
* @returns Promise resolving to the total file count
|
|
1140
1317
|
* @example
|
|
1141
1318
|
* ```typescript
|
|
1142
|
-
* const
|
|
1143
|
-
* console.log(`Total files
|
|
1319
|
+
* const total = await vana.data.getTotalFilesCount();
|
|
1320
|
+
* console.log(`Total files: ${total}`);
|
|
1144
1321
|
*
|
|
1145
|
-
* //
|
|
1146
|
-
* const
|
|
1147
|
-
* const totalPages = Math.ceil(totalFiles / filesPerPage);
|
|
1148
|
-
* console.log(`Total pages: ${totalPages}`);
|
|
1322
|
+
* // Calculate pagination
|
|
1323
|
+
* const pages = Math.ceil(total / 20);
|
|
1149
1324
|
* ```
|
|
1150
1325
|
*/
|
|
1151
1326
|
async getTotalFilesCount() {
|
|
1152
1327
|
try {
|
|
1153
|
-
const chainId = this.context.
|
|
1328
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1154
1329
|
if (!chainId) {
|
|
1155
1330
|
throw new Error("Chain ID not available");
|
|
1156
1331
|
}
|
|
@@ -1159,7 +1334,7 @@ class DataController {
|
|
|
1159
1334
|
const dataRegistry = getContract({
|
|
1160
1335
|
address: dataRegistryAddress,
|
|
1161
1336
|
abi: dataRegistryAbi,
|
|
1162
|
-
client: this.context.
|
|
1337
|
+
client: this.context.publicClient
|
|
1163
1338
|
});
|
|
1164
1339
|
const count = await dataRegistry.read.filesCount();
|
|
1165
1340
|
return Number(count);
|
|
@@ -1172,36 +1347,36 @@ class DataController {
|
|
|
1172
1347
|
}
|
|
1173
1348
|
}
|
|
1174
1349
|
/**
|
|
1175
|
-
* Retrieves
|
|
1350
|
+
* Retrieves file metadata by ID from the blockchain.
|
|
1351
|
+
*
|
|
1352
|
+
* @remarks
|
|
1353
|
+
* Queries DataRegistry contract directly for file details.
|
|
1354
|
+
* Works for any file ID regardless of ownership, enabling
|
|
1355
|
+
* cross-user file discovery and verification.
|
|
1356
|
+
*
|
|
1357
|
+
* @param fileId - Numeric file ID to retrieve
|
|
1358
|
+
*
|
|
1359
|
+
* @returns UserFile object with metadata
|
|
1360
|
+
*
|
|
1361
|
+
* @throws {Error} Chain ID not available.
|
|
1362
|
+
* Ensure proper network connection.
|
|
1363
|
+
* @throws {Error} File not found.
|
|
1364
|
+
* Verify file ID exists on-chain.
|
|
1365
|
+
* @throws {Error} Contract call failed.
|
|
1366
|
+
* Check network and RPC availability.
|
|
1176
1367
|
*
|
|
1177
|
-
* @param fileId - The file ID to look up
|
|
1178
|
-
* @returns Promise resolving to UserFile object
|
|
1179
|
-
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1180
|
-
* @throws {Error} "File not found" - When file ID doesn't exist or returns empty data
|
|
1181
|
-
* @throws {Error} "Failed to fetch file {fileId}: {error}" - General contract read failures
|
|
1182
1368
|
* @example
|
|
1183
1369
|
* ```typescript
|
|
1184
|
-
*
|
|
1185
|
-
*
|
|
1186
|
-
*
|
|
1187
|
-
*
|
|
1188
|
-
*
|
|
1189
|
-
* owner: file.ownerAddress,
|
|
1190
|
-
* addedAt: file.addedAtBlock
|
|
1191
|
-
* });
|
|
1192
|
-
* } catch (error) {
|
|
1193
|
-
* console.error('File not found or error retrieving file:', error);
|
|
1194
|
-
* }
|
|
1370
|
+
* const file = await vana.data.getFileById(123);
|
|
1371
|
+
* console.log(`File ${file.id}:`);
|
|
1372
|
+
* console.log(` URL: ${file.url}`);
|
|
1373
|
+
* console.log(` Owner: ${file.ownerAddress}`);
|
|
1374
|
+
* console.log(` Block: ${file.addedAtBlock}`);
|
|
1195
1375
|
* ```
|
|
1196
|
-
*
|
|
1197
|
-
* This method queries the DataRegistry contract directly
|
|
1198
|
-
* to get file details for any file ID, regardless of user ownership.
|
|
1199
|
-
* This is useful for file lookup functionality where users can search
|
|
1200
|
-
* for specific files by ID.
|
|
1201
1376
|
*/
|
|
1202
1377
|
async getFileById(fileId) {
|
|
1203
1378
|
try {
|
|
1204
|
-
const chainId = this.context.
|
|
1379
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1205
1380
|
if (!chainId) {
|
|
1206
1381
|
throw new Error("Chain ID not available");
|
|
1207
1382
|
}
|
|
@@ -1210,7 +1385,7 @@ class DataController {
|
|
|
1210
1385
|
const dataRegistry = getContract({
|
|
1211
1386
|
address: dataRegistryAddress,
|
|
1212
1387
|
abi: dataRegistryAbi,
|
|
1213
|
-
client: this.context.
|
|
1388
|
+
client: this.context.publicClient
|
|
1214
1389
|
});
|
|
1215
1390
|
const fileDetails = await dataRegistry.read.files([BigInt(fileId)]);
|
|
1216
1391
|
if (!fileDetails) {
|
|
@@ -1268,15 +1443,17 @@ class DataController {
|
|
|
1268
1443
|
* console.log(`File ${fileId} registered with schema in tx ${transactionHash}`);
|
|
1269
1444
|
* ```
|
|
1270
1445
|
*/
|
|
1271
|
-
async registerFileWithSchema(url, schemaId) {
|
|
1446
|
+
async registerFileWithSchema(url, schemaId, options) {
|
|
1447
|
+
this.assertWallet();
|
|
1272
1448
|
try {
|
|
1273
|
-
const chainId = this.context.
|
|
1449
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1274
1450
|
if (!chainId) {
|
|
1275
1451
|
throw new Error("Chain ID not available");
|
|
1276
1452
|
}
|
|
1453
|
+
this.assertWallet();
|
|
1277
1454
|
const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
|
|
1278
1455
|
const dataRegistryAbi = getAbi("DataRegistry");
|
|
1279
|
-
const account = this.context.walletClient.account ??
|
|
1456
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1280
1457
|
const from = typeof account === "string" ? account : account.address;
|
|
1281
1458
|
const hash = await this.context.walletClient.writeContract({
|
|
1282
1459
|
address: dataRegistryAddress,
|
|
@@ -1284,7 +1461,8 @@ class DataController {
|
|
|
1284
1461
|
functionName: "addFileWithSchema",
|
|
1285
1462
|
args: [url, BigInt(schemaId)],
|
|
1286
1463
|
account,
|
|
1287
|
-
chain: this.context.walletClient.chain ?? null
|
|
1464
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1465
|
+
...this.spreadTransactionOptions(options)
|
|
1288
1466
|
});
|
|
1289
1467
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1290
1468
|
return tx({
|
|
@@ -1306,13 +1484,6 @@ class DataController {
|
|
|
1306
1484
|
* @returns Promise resolving to the user's wallet address
|
|
1307
1485
|
* @throws {Error} When no addresses are available in wallet client
|
|
1308
1486
|
*/
|
|
1309
|
-
async getUserAddress() {
|
|
1310
|
-
const addresses = await this.context.walletClient.getAddresses();
|
|
1311
|
-
if (addresses.length === 0) {
|
|
1312
|
-
throw new Error("No addresses available in wallet client");
|
|
1313
|
-
}
|
|
1314
|
-
return addresses[0];
|
|
1315
|
-
}
|
|
1316
1487
|
/**
|
|
1317
1488
|
* Adds a file with permissions to the DataRegistry contract.
|
|
1318
1489
|
*
|
|
@@ -1329,12 +1500,14 @@ class DataController {
|
|
|
1329
1500
|
* with specific permissions on the DataRegistry contract. It can be used
|
|
1330
1501
|
* by both direct transactions and relayer services.
|
|
1331
1502
|
*/
|
|
1332
|
-
async addFileWithPermissions(url, ownerAddress, permissions = []) {
|
|
1503
|
+
async addFileWithPermissions(url, ownerAddress, permissions = [], options) {
|
|
1504
|
+
this.assertWallet();
|
|
1333
1505
|
try {
|
|
1334
|
-
const chainId = this.context.
|
|
1506
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1335
1507
|
if (!chainId) {
|
|
1336
1508
|
throw new Error("Chain ID not available");
|
|
1337
1509
|
}
|
|
1510
|
+
this.assertWallet();
|
|
1338
1511
|
const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
|
|
1339
1512
|
const dataRegistryAbi = getAbi("DataRegistry");
|
|
1340
1513
|
const account = this.context.walletClient.account ?? ownerAddress;
|
|
@@ -1345,7 +1518,8 @@ class DataController {
|
|
|
1345
1518
|
functionName: "addFileWithPermissions",
|
|
1346
1519
|
args: [url, ownerAddress, permissions],
|
|
1347
1520
|
account,
|
|
1348
|
-
chain: this.context.walletClient.chain ?? null
|
|
1521
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1522
|
+
...this.spreadTransactionOptions(options)
|
|
1349
1523
|
});
|
|
1350
1524
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1351
1525
|
return tx({
|
|
@@ -1400,10 +1574,12 @@ class DataController {
|
|
|
1400
1574
|
* console.log(`File ${result.fileId} registered in tx ${result.hash}`);
|
|
1401
1575
|
* ```
|
|
1402
1576
|
*/
|
|
1403
|
-
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1577
|
+
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
|
|
1578
|
+
this.assertWallet();
|
|
1404
1579
|
try {
|
|
1405
1580
|
let encryptedPermissions = [];
|
|
1406
1581
|
if (permissions.length > 0) {
|
|
1582
|
+
this.assertWallet();
|
|
1407
1583
|
const userEncryptionKey = await generateEncryptionKey(
|
|
1408
1584
|
this.context.walletClient,
|
|
1409
1585
|
this.context.platform,
|
|
@@ -1428,11 +1604,12 @@ class DataController {
|
|
|
1428
1604
|
})
|
|
1429
1605
|
);
|
|
1430
1606
|
}
|
|
1431
|
-
return await this.
|
|
1607
|
+
return await this.addFileWithEncryptedPermissionsAndSchema(
|
|
1432
1608
|
url,
|
|
1433
1609
|
ownerAddress,
|
|
1434
1610
|
encryptedPermissions,
|
|
1435
|
-
schemaId
|
|
1611
|
+
schemaId,
|
|
1612
|
+
options
|
|
1436
1613
|
);
|
|
1437
1614
|
} catch (error) {
|
|
1438
1615
|
console.error("Failed to add file with permissions and schema:", error);
|
|
@@ -1442,15 +1619,50 @@ class DataController {
|
|
|
1442
1619
|
}
|
|
1443
1620
|
}
|
|
1444
1621
|
/**
|
|
1445
|
-
*
|
|
1446
|
-
*
|
|
1622
|
+
* Adds a file with pre-encrypted permissions and schema to the DataRegistry.
|
|
1623
|
+
*
|
|
1624
|
+
* @remarks
|
|
1625
|
+
* This method is designed for relay services and advanced use cases where permissions
|
|
1626
|
+
* have already been encrypted client-side. Unlike `addFileWithPermissionsAndSchema()`,
|
|
1627
|
+
* this method expects permissions in the encrypted format with a 'key' field instead
|
|
1628
|
+
* of 'publicKey'.
|
|
1629
|
+
*
|
|
1630
|
+
* This is typically used by relay endpoints that receive pre-encrypted data from
|
|
1631
|
+
* the client SDK's `upload()` method, avoiding double encryption.
|
|
1632
|
+
*
|
|
1633
|
+
* @param url - The storage URL of the file (e.g., IPFS URL)
|
|
1634
|
+
* @param ownerAddress - The address that will own this file
|
|
1635
|
+
* @param permissions - Array of pre-encrypted permissions with 'account' and 'key' fields
|
|
1636
|
+
* @param schemaId - Optional schema ID for data validation (defaults to 0)
|
|
1637
|
+
* @returns Promise resolving to transaction result with hash and contract details
|
|
1638
|
+
* @throws {Error} When chain ID is not available
|
|
1639
|
+
* @throws {Error} When wallet is not connected
|
|
1640
|
+
* @throws {Error} When transaction fails
|
|
1641
|
+
* @example
|
|
1642
|
+
* ```typescript
|
|
1643
|
+
* // In a relay endpoint that receives pre-encrypted permissions
|
|
1644
|
+
* const result = await vana.data.addFileWithEncryptedPermissionsAndSchema(
|
|
1645
|
+
* "ipfs://QmXxx...",
|
|
1646
|
+
* ownerAddress,
|
|
1647
|
+
* [
|
|
1648
|
+
* {
|
|
1649
|
+
* account: "0xServerAddress...",
|
|
1650
|
+
* key: "encrypted_key_string" // Already encrypted by client
|
|
1651
|
+
* }
|
|
1652
|
+
* ],
|
|
1653
|
+
* schemaId
|
|
1654
|
+
* );
|
|
1655
|
+
*
|
|
1656
|
+
* console.log(`File registered in tx ${result.hash}`);
|
|
1657
|
+
* ```
|
|
1447
1658
|
*/
|
|
1448
|
-
async
|
|
1659
|
+
async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
|
|
1449
1660
|
try {
|
|
1450
|
-
const chainId = this.context.
|
|
1661
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1451
1662
|
if (!chainId) {
|
|
1452
1663
|
throw new Error("Chain ID not available");
|
|
1453
1664
|
}
|
|
1665
|
+
this.assertWallet();
|
|
1454
1666
|
const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
|
|
1455
1667
|
const dataRegistryAbi = getAbi("DataRegistry");
|
|
1456
1668
|
const account = this.context.walletClient.account ?? ownerAddress;
|
|
@@ -1461,7 +1673,8 @@ class DataController {
|
|
|
1461
1673
|
functionName: "addFileWithPermissionsAndSchema",
|
|
1462
1674
|
args: [url, ownerAddress, permissions, BigInt(schemaId)],
|
|
1463
1675
|
account,
|
|
1464
|
-
chain: this.context.walletClient.chain ?? null
|
|
1676
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1677
|
+
...this.spreadTransactionOptions(options)
|
|
1465
1678
|
});
|
|
1466
1679
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1467
1680
|
return tx({
|
|
@@ -1478,36 +1691,41 @@ class DataController {
|
|
|
1478
1691
|
}
|
|
1479
1692
|
}
|
|
1480
1693
|
/**
|
|
1481
|
-
*
|
|
1694
|
+
* Registers a data refiner for processing templates.
|
|
1482
1695
|
*
|
|
1483
1696
|
* @remarks
|
|
1484
|
-
* Refiners
|
|
1485
|
-
*
|
|
1486
|
-
*
|
|
1487
|
-
*
|
|
1488
|
-
*
|
|
1489
|
-
* @param params - Refiner
|
|
1490
|
-
* @param params.
|
|
1491
|
-
*
|
|
1492
|
-
* @param params.
|
|
1493
|
-
*
|
|
1494
|
-
* @returns
|
|
1495
|
-
*
|
|
1496
|
-
* @throws {Error}
|
|
1697
|
+
* Refiners define data transformation rules for DLPs.
|
|
1698
|
+
* Associates schema, instructions, and processing logic.
|
|
1699
|
+
*
|
|
1700
|
+
* @param params - Refiner configuration
|
|
1701
|
+
* @param params.dlpId - Data Liquidity Pool ID
|
|
1702
|
+
* @param params.name - Refiner display name
|
|
1703
|
+
* @param params.schemaId - Output schema ID.
|
|
1704
|
+
* Obtain via `vana.schemas.list()`.
|
|
1705
|
+
* @param params.refinementInstructionUrl - Processing instructions URL
|
|
1706
|
+
*
|
|
1707
|
+
* @returns Refiner ID and transaction hash
|
|
1708
|
+
*
|
|
1709
|
+
* @throws {Error} Chain ID not available.
|
|
1710
|
+
* Ensure network connection.
|
|
1711
|
+
* @throws {Error} Transaction failed.
|
|
1712
|
+
* Check wallet balance and network status.
|
|
1713
|
+
*
|
|
1497
1714
|
* @example
|
|
1498
1715
|
* ```typescript
|
|
1499
1716
|
* const result = await vana.data.addRefiner({
|
|
1500
1717
|
* dlpId: 1,
|
|
1501
|
-
* name: "
|
|
1718
|
+
* name: "Sentiment Analyzer",
|
|
1502
1719
|
* schemaId: 42,
|
|
1503
1720
|
* refinementInstructionUrl: "ipfs://QmXxx..."
|
|
1504
1721
|
* });
|
|
1505
|
-
* console.log(`
|
|
1722
|
+
* console.log(`Refiner ${result.refinerId} created`);
|
|
1506
1723
|
* ```
|
|
1507
1724
|
*/
|
|
1508
|
-
async addRefiner(params) {
|
|
1725
|
+
async addRefiner(params, options) {
|
|
1726
|
+
this.assertWallet();
|
|
1509
1727
|
try {
|
|
1510
|
-
const chainId = this.context.
|
|
1728
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1511
1729
|
if (!chainId) {
|
|
1512
1730
|
throw new Error("Chain ID not available");
|
|
1513
1731
|
}
|
|
@@ -1516,7 +1734,8 @@ class DataController {
|
|
|
1516
1734
|
"DataRefinerRegistry"
|
|
1517
1735
|
);
|
|
1518
1736
|
const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
|
|
1519
|
-
|
|
1737
|
+
this.assertWallet();
|
|
1738
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1520
1739
|
const from = typeof account === "string" ? account : account.address;
|
|
1521
1740
|
const hash = await this.context.walletClient.writeContract({
|
|
1522
1741
|
address: dataRefinerRegistryAddress,
|
|
@@ -1529,7 +1748,8 @@ class DataController {
|
|
|
1529
1748
|
params.refinementInstructionUrl
|
|
1530
1749
|
],
|
|
1531
1750
|
account,
|
|
1532
|
-
chain: this.context.walletClient.chain ?? null
|
|
1751
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1752
|
+
...this.spreadTransactionOptions(options)
|
|
1533
1753
|
});
|
|
1534
1754
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1535
1755
|
const txResult = tx({
|
|
@@ -1558,31 +1778,34 @@ class DataController {
|
|
|
1558
1778
|
}
|
|
1559
1779
|
}
|
|
1560
1780
|
/**
|
|
1561
|
-
* Retrieves
|
|
1781
|
+
* Retrieves refiner configuration by ID.
|
|
1562
1782
|
*
|
|
1563
1783
|
* @remarks
|
|
1564
|
-
* Queries
|
|
1565
|
-
*
|
|
1784
|
+
* Queries DataRefinerRegistry for refiner details.
|
|
1785
|
+
* Returns DLP association, schema, and processing instructions.
|
|
1786
|
+
*
|
|
1787
|
+
* @param refinerId - Numeric refiner ID
|
|
1788
|
+
*
|
|
1789
|
+
* @returns Refiner configuration object
|
|
1790
|
+
*
|
|
1791
|
+
* @throws {Error} Chain ID not available.
|
|
1792
|
+
* Ensure network connection.
|
|
1793
|
+
* @throws {Error} Refiner not found.
|
|
1794
|
+
* Verify refiner ID exists.
|
|
1795
|
+
* @throws {Error} Contract read failed.
|
|
1796
|
+
* Check network and RPC status.
|
|
1566
1797
|
*
|
|
1567
|
-
* @param refinerId - The numeric refiner ID to retrieve
|
|
1568
|
-
* @returns Promise resolving to the refiner information object
|
|
1569
|
-
* @throws {Error} When chain ID is not available - "Chain ID not available"
|
|
1570
|
-
* @throws {Error} When refiner doesn't exist - "Refiner with ID {refinerId} does not exist"
|
|
1571
|
-
* @throws {Error} When contract read fails - "Failed to fetch refiner: {error}"
|
|
1572
1798
|
* @example
|
|
1573
1799
|
* ```typescript
|
|
1574
1800
|
* const refiner = await vana.data.getRefiner(1);
|
|
1575
|
-
* console.log({
|
|
1576
|
-
*
|
|
1577
|
-
*
|
|
1578
|
-
* schema: refiner.schemaId,
|
|
1579
|
-
* instructions: refiner.refinementInstructionUrl
|
|
1580
|
-
* });
|
|
1801
|
+
* console.log(`Refiner: ${refiner.name}`);
|
|
1802
|
+
* console.log(`DLP: ${refiner.dlpId}`);
|
|
1803
|
+
* console.log(`Schema: ${refiner.schemaId}`);
|
|
1581
1804
|
* ```
|
|
1582
1805
|
*/
|
|
1583
1806
|
async getRefiner(refinerId) {
|
|
1584
1807
|
try {
|
|
1585
|
-
const chainId = this.context.
|
|
1808
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1586
1809
|
if (!chainId) {
|
|
1587
1810
|
throw new Error("Chain ID not available");
|
|
1588
1811
|
}
|
|
@@ -1594,7 +1817,7 @@ class DataController {
|
|
|
1594
1817
|
const dataRefinerRegistry = getContract({
|
|
1595
1818
|
address: dataRefinerRegistryAddress,
|
|
1596
1819
|
abi: dataRefinerRegistryAbi,
|
|
1597
|
-
client: this.context.
|
|
1820
|
+
client: this.context.publicClient
|
|
1598
1821
|
});
|
|
1599
1822
|
const refinerData = await dataRefinerRegistry.read.refiners([
|
|
1600
1823
|
BigInt(refinerId)
|
|
@@ -1618,27 +1841,33 @@ class DataController {
|
|
|
1618
1841
|
}
|
|
1619
1842
|
}
|
|
1620
1843
|
/**
|
|
1621
|
-
* Validates
|
|
1844
|
+
* Validates schema ID existence.
|
|
1622
1845
|
*
|
|
1623
1846
|
* @remarks
|
|
1624
|
-
*
|
|
1625
|
-
*
|
|
1847
|
+
* Verifies schema registration in DataRegistry.
|
|
1848
|
+
* Check before using schemas for uploads.
|
|
1849
|
+
*
|
|
1850
|
+
* @param schemaId - Numeric schema ID to validate
|
|
1851
|
+
*
|
|
1852
|
+
* @returns True if schema exists, false otherwise
|
|
1853
|
+
*
|
|
1854
|
+
* @throws {Error} Chain ID not available.
|
|
1855
|
+
* Ensure network connection.
|
|
1856
|
+
* @throws {Error} Contract read failed.
|
|
1857
|
+
* Check RPC availability.
|
|
1626
1858
|
*
|
|
1627
|
-
* @param schemaId - The numeric schema ID to validate
|
|
1628
|
-
* @returns Promise resolving to true if schema exists, false otherwise
|
|
1629
1859
|
* @example
|
|
1630
1860
|
* ```typescript
|
|
1631
|
-
* const
|
|
1632
|
-
* if (
|
|
1633
|
-
*
|
|
1634
|
-
*
|
|
1635
|
-
* console.log('Schema 42 does not exist');
|
|
1861
|
+
* const valid = await vana.data.isValidSchemaId(42);
|
|
1862
|
+
* if (valid) {
|
|
1863
|
+
* // Safe to use schema 42
|
|
1864
|
+
* await vana.data.upload({ schemaId: 42, ... });
|
|
1636
1865
|
* }
|
|
1637
1866
|
* ```
|
|
1638
1867
|
*/
|
|
1639
1868
|
async isValidSchemaId(schemaId) {
|
|
1640
1869
|
try {
|
|
1641
|
-
const chainId = this.context.
|
|
1870
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1642
1871
|
if (!chainId) {
|
|
1643
1872
|
throw new Error("Chain ID not available");
|
|
1644
1873
|
}
|
|
@@ -1650,7 +1879,7 @@ class DataController {
|
|
|
1650
1879
|
const dataRefinerRegistry = getContract({
|
|
1651
1880
|
address: dataRefinerRegistryAddress,
|
|
1652
1881
|
abi: dataRefinerRegistryAbi,
|
|
1653
|
-
client: this.context.
|
|
1882
|
+
client: this.context.publicClient
|
|
1654
1883
|
});
|
|
1655
1884
|
const isValid = await dataRefinerRegistry.read.isValidSchemaId([
|
|
1656
1885
|
BigInt(schemaId)
|
|
@@ -1677,7 +1906,7 @@ class DataController {
|
|
|
1677
1906
|
*/
|
|
1678
1907
|
async getRefinersCount() {
|
|
1679
1908
|
try {
|
|
1680
|
-
const chainId = this.context.
|
|
1909
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1681
1910
|
if (!chainId) {
|
|
1682
1911
|
throw new Error("Chain ID not available");
|
|
1683
1912
|
}
|
|
@@ -1689,7 +1918,7 @@ class DataController {
|
|
|
1689
1918
|
const dataRefinerRegistry = getContract({
|
|
1690
1919
|
address: dataRefinerRegistryAddress,
|
|
1691
1920
|
abi: dataRefinerRegistryAbi,
|
|
1692
|
-
client: this.context.
|
|
1921
|
+
client: this.context.publicClient
|
|
1693
1922
|
});
|
|
1694
1923
|
const count = await dataRefinerRegistry.read.refinersCount();
|
|
1695
1924
|
return Number(count);
|
|
@@ -1720,9 +1949,10 @@ class DataController {
|
|
|
1720
1949
|
* console.log(`Schema updated in tx ${result.transactionHash}`);
|
|
1721
1950
|
* ```
|
|
1722
1951
|
*/
|
|
1723
|
-
async updateSchemaId(params) {
|
|
1952
|
+
async updateSchemaId(params, options) {
|
|
1953
|
+
this.assertWallet();
|
|
1724
1954
|
try {
|
|
1725
|
-
const chainId = this.context.
|
|
1955
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1726
1956
|
if (!chainId) {
|
|
1727
1957
|
throw new Error("Chain ID not available");
|
|
1728
1958
|
}
|
|
@@ -1731,14 +1961,16 @@ class DataController {
|
|
|
1731
1961
|
"DataRefinerRegistry"
|
|
1732
1962
|
);
|
|
1733
1963
|
const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
|
|
1734
|
-
|
|
1964
|
+
this.assertWallet();
|
|
1965
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1735
1966
|
const hash = await this.context.walletClient.writeContract({
|
|
1736
1967
|
address: dataRefinerRegistryAddress,
|
|
1737
1968
|
abi: dataRefinerRegistryAbi,
|
|
1738
1969
|
functionName: "updateSchemaId",
|
|
1739
1970
|
args: [BigInt(params.refinerId), BigInt(params.newSchemaId)],
|
|
1740
1971
|
account,
|
|
1741
|
-
chain: this.context.walletClient.chain ?? null
|
|
1972
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1973
|
+
...this.spreadTransactionOptions(options)
|
|
1742
1974
|
});
|
|
1743
1975
|
await this.context.publicClient.waitForTransactionReceipt({ hash });
|
|
1744
1976
|
return {
|
|
@@ -1760,13 +1992,12 @@ class DataController {
|
|
|
1760
1992
|
* 3. Encrypts the user's encryption key with the provided public key
|
|
1761
1993
|
* 4. Registers the file with permissions
|
|
1762
1994
|
*
|
|
1763
|
-
* @param
|
|
1764
|
-
* @param permissions - Array of permissions to grant, each with account address and public key
|
|
1765
|
-
* @param filename - Optional filename for the upload
|
|
1766
|
-
* @param providerName - Optional storage provider to use
|
|
1995
|
+
* @param params - Upload parameters including data, permissions, and options
|
|
1767
1996
|
* @returns Promise resolving to upload result with file ID and storage URL
|
|
1768
1997
|
*/
|
|
1769
|
-
async uploadFileWithPermissions(
|
|
1998
|
+
async uploadFileWithPermissions(params) {
|
|
1999
|
+
this.assertWallet();
|
|
2000
|
+
const { data, permissions, filename, providerName } = params;
|
|
1770
2001
|
try {
|
|
1771
2002
|
const uploadResult = await this.uploadToStorage(
|
|
1772
2003
|
data,
|
|
@@ -1775,7 +2006,7 @@ class DataController {
|
|
|
1775
2006
|
// Always encrypt for uploadFileWithPermissions
|
|
1776
2007
|
providerName
|
|
1777
2008
|
);
|
|
1778
|
-
const userAddress =
|
|
2009
|
+
const userAddress = this.context.userAddress;
|
|
1779
2010
|
const userEncryptionKey = await generateEncryptionKey(
|
|
1780
2011
|
this.context.walletClient,
|
|
1781
2012
|
this.context.platform,
|
|
@@ -1794,12 +2025,32 @@ class DataController {
|
|
|
1794
2025
|
};
|
|
1795
2026
|
})
|
|
1796
2027
|
);
|
|
1797
|
-
if (this.context.
|
|
1798
|
-
const
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
2028
|
+
if (this.context.relayer) {
|
|
2029
|
+
const request = {
|
|
2030
|
+
type: "direct",
|
|
2031
|
+
operation: "submitFileAdditionWithPermissions",
|
|
2032
|
+
params: {
|
|
2033
|
+
url: uploadResult.url,
|
|
2034
|
+
userAddress,
|
|
2035
|
+
permissions: encryptedPermissions
|
|
2036
|
+
}
|
|
2037
|
+
};
|
|
2038
|
+
const response = await this.context.relayer(request);
|
|
2039
|
+
if (response.type === "error") {
|
|
2040
|
+
throw new Error(response.error);
|
|
2041
|
+
}
|
|
2042
|
+
let result;
|
|
2043
|
+
if (response.type === "pending") {
|
|
2044
|
+
result = await this.pollRelayerForConfirmation(
|
|
2045
|
+
response.operationId,
|
|
2046
|
+
void 0
|
|
2047
|
+
// TODO: Add TransactionOptions to upload method signature
|
|
2048
|
+
);
|
|
2049
|
+
} else if (response.type === "direct" && typeof response.result === "object" && response.result !== null && "fileId" in response.result) {
|
|
2050
|
+
result = response.result;
|
|
2051
|
+
} else {
|
|
2052
|
+
throw new Error("Invalid response from relayer");
|
|
2053
|
+
}
|
|
1803
2054
|
return {
|
|
1804
2055
|
fileId: result.fileId,
|
|
1805
2056
|
url: uploadResult.url,
|
|
@@ -1866,6 +2117,7 @@ class DataController {
|
|
|
1866
2117
|
}
|
|
1867
2118
|
let finalBlob = blob;
|
|
1868
2119
|
if (encrypt) {
|
|
2120
|
+
this.assertWallet();
|
|
1869
2121
|
const encryptionKey = await generateEncryptionKey(
|
|
1870
2122
|
this.context.walletClient,
|
|
1871
2123
|
this.context.platform,
|
|
@@ -1887,7 +2139,15 @@ class DataController {
|
|
|
1887
2139
|
);
|
|
1888
2140
|
}
|
|
1889
2141
|
}
|
|
1890
|
-
const finalFilename =
|
|
2142
|
+
const finalFilename = (() => {
|
|
2143
|
+
if (filename) {
|
|
2144
|
+
if (encrypt && !filename.endsWith(".enc")) {
|
|
2145
|
+
return `${filename}.enc`;
|
|
2146
|
+
}
|
|
2147
|
+
return filename;
|
|
2148
|
+
}
|
|
2149
|
+
return encrypt ? `upload-${Date.now()}.enc` : `upload-${Date.now()}.dat`;
|
|
2150
|
+
})();
|
|
1891
2151
|
const uploadResult = await this.context.storageManager.upload(
|
|
1892
2152
|
finalBlob,
|
|
1893
2153
|
finalFilename,
|
|
@@ -1912,22 +2172,30 @@ class DataController {
|
|
|
1912
2172
|
* For advanced users who need more control over transaction timing,
|
|
1913
2173
|
* use `submitFilePermission()` instead.
|
|
1914
2174
|
*
|
|
1915
|
-
* @param
|
|
1916
|
-
* @param
|
|
1917
|
-
* @param
|
|
2175
|
+
* @param params - Parameters for adding file permission
|
|
2176
|
+
* @param params.fileId - The ID of the file to grant permission for
|
|
2177
|
+
* @param params.account - The recipient's wallet address that will access the file
|
|
2178
|
+
* @param params.publicKey - The recipient's public key for encryption.
|
|
2179
|
+
* Obtain via `vana.server.getIdentity(account).publicKey`
|
|
1918
2180
|
* @returns Promise resolving to permission data from PermissionGranted event
|
|
1919
2181
|
* @throws {Error} "No addresses available in wallet client" - When wallet is not connected
|
|
1920
2182
|
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1921
2183
|
* @throws {Error} "Failed to add permission to file: {error}" - When transaction fails or user doesn't own file
|
|
1922
2184
|
* @example
|
|
1923
2185
|
* ```typescript
|
|
1924
|
-
* const result = await vana.data.addPermissionToFile(
|
|
2186
|
+
* const result = await vana.data.addPermissionToFile({
|
|
2187
|
+
* fileId: 123,
|
|
2188
|
+
* account: "0xRecipientAddress...",
|
|
2189
|
+
* publicKey: "0xRecipientPublicKey..."
|
|
2190
|
+
* });
|
|
1925
2191
|
* console.log(`Permission granted to ${result.account} for file ${result.fileId}`);
|
|
1926
2192
|
* console.log(`Transaction: ${result.transactionHash}`);
|
|
1927
2193
|
* ```
|
|
1928
2194
|
*/
|
|
1929
|
-
async addPermissionToFile(
|
|
1930
|
-
|
|
2195
|
+
async addPermissionToFile(params, options) {
|
|
2196
|
+
this.assertWallet();
|
|
2197
|
+
const { fileId, account, publicKey } = params;
|
|
2198
|
+
return await this.submitFilePermission(fileId, account, publicKey, options);
|
|
1931
2199
|
}
|
|
1932
2200
|
/**
|
|
1933
2201
|
* Submits a file permission transaction to the blockchain.
|
|
@@ -1957,7 +2225,8 @@ class DataController {
|
|
|
1957
2225
|
* console.log(`Permission granted with ID: ${result.permissionId}`);
|
|
1958
2226
|
* ```
|
|
1959
2227
|
*/
|
|
1960
|
-
async submitFilePermission(fileId, account, publicKey) {
|
|
2228
|
+
async submitFilePermission(fileId, account, publicKey, options) {
|
|
2229
|
+
this.assertWallet();
|
|
1961
2230
|
try {
|
|
1962
2231
|
const userEncryptionKey = await generateEncryptionKey(
|
|
1963
2232
|
this.context.walletClient,
|
|
@@ -1969,20 +2238,22 @@ class DataController {
|
|
|
1969
2238
|
publicKey,
|
|
1970
2239
|
this.context.platform
|
|
1971
2240
|
);
|
|
1972
|
-
const chainId = this.context.
|
|
2241
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1973
2242
|
if (!chainId) {
|
|
1974
2243
|
throw new Error("Chain ID not available");
|
|
1975
2244
|
}
|
|
1976
2245
|
const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
|
|
1977
2246
|
const dataRegistryAbi = getAbi("DataRegistry");
|
|
1978
|
-
|
|
2247
|
+
this.assertWallet();
|
|
2248
|
+
const walletAccount = this.context.walletClient.account ?? this.context.userAddress;
|
|
1979
2249
|
const txHash = await this.context.walletClient.writeContract({
|
|
1980
2250
|
address: dataRegistryAddress,
|
|
1981
2251
|
abi: dataRegistryAbi,
|
|
1982
2252
|
functionName: "addFilePermission",
|
|
1983
2253
|
args: [BigInt(fileId), account, encryptedKey],
|
|
1984
2254
|
account: walletAccount,
|
|
1985
|
-
chain: this.context.walletClient.chain ?? null
|
|
2255
|
+
chain: this.context.walletClient.chain ?? null,
|
|
2256
|
+
...this.spreadTransactionOptions(options)
|
|
1986
2257
|
});
|
|
1987
2258
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1988
2259
|
return tx({
|
|
@@ -2007,7 +2278,7 @@ class DataController {
|
|
|
2007
2278
|
*/
|
|
2008
2279
|
async getFilePermission(fileId, account) {
|
|
2009
2280
|
try {
|
|
2010
|
-
const chainId = this.context.
|
|
2281
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
2011
2282
|
if (!chainId) {
|
|
2012
2283
|
throw new Error("Chain ID not available");
|
|
2013
2284
|
}
|
|
@@ -2016,7 +2287,7 @@ class DataController {
|
|
|
2016
2287
|
const dataRegistry = getContract({
|
|
2017
2288
|
address: dataRegistryAddress,
|
|
2018
2289
|
abi: dataRegistryAbi,
|
|
2019
|
-
client: this.context.
|
|
2290
|
+
client: this.context.publicClient
|
|
2020
2291
|
});
|
|
2021
2292
|
const encryptedKey = await dataRegistry.read.filePermissions([
|
|
2022
2293
|
BigInt(fileId),
|
|
@@ -2040,12 +2311,13 @@ class DataController {
|
|
|
2040
2311
|
*
|
|
2041
2312
|
* @param file - The file to decrypt
|
|
2042
2313
|
* @param privateKey - The private key to decrypt the user's encryption key
|
|
2043
|
-
* @param
|
|
2314
|
+
* @param options - Optional decryption configuration
|
|
2315
|
+
* @param options.account - The account address that has permission (defaults to current wallet account)
|
|
2044
2316
|
* @returns Promise resolving to the decrypted file data
|
|
2045
2317
|
*/
|
|
2046
|
-
async decryptFileWithPermission(file, privateKey,
|
|
2318
|
+
async decryptFileWithPermission(file, privateKey, options) {
|
|
2047
2319
|
try {
|
|
2048
|
-
const permissionAccount = account ??
|
|
2320
|
+
const permissionAccount = options?.account ?? this.context.userAddress;
|
|
2049
2321
|
const encryptedKey = await this.getFilePermission(
|
|
2050
2322
|
file.id,
|
|
2051
2323
|
permissionAccount
|
|
@@ -2327,6 +2599,26 @@ class DataController {
|
|
|
2327
2599
|
async fetchAndValidateSchema(url) {
|
|
2328
2600
|
return fetchAndValidateSchema(url);
|
|
2329
2601
|
}
|
|
2602
|
+
/**
|
|
2603
|
+
* Polls for confirmation of a relayer operation.
|
|
2604
|
+
* @internal
|
|
2605
|
+
*/
|
|
2606
|
+
async pollRelayerForConfirmation(operationId, options) {
|
|
2607
|
+
if (!this.context.relayer) {
|
|
2608
|
+
throw new Error("Relayer not configured for polling");
|
|
2609
|
+
}
|
|
2610
|
+
const pollingManager = new PollingManager(this.context.relayer);
|
|
2611
|
+
const result = await pollingManager.startPolling(operationId, {
|
|
2612
|
+
signal: options?.signal,
|
|
2613
|
+
onStatusUpdate: options?.onStatusUpdate,
|
|
2614
|
+
...options?.pollingOptions
|
|
2615
|
+
});
|
|
2616
|
+
return {
|
|
2617
|
+
fileId: 0,
|
|
2618
|
+
// This would need to be extracted from transaction events
|
|
2619
|
+
transactionHash: result.hash
|
|
2620
|
+
};
|
|
2621
|
+
}
|
|
2330
2622
|
}
|
|
2331
2623
|
export {
|
|
2332
2624
|
DataController
|