@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
|
@@ -32,18 +32,25 @@ __export(data_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(data_exports);
|
|
34
34
|
var import_viem = require("viem");
|
|
35
|
-
var
|
|
35
|
+
var import_pollingManager = require("../core/pollingManager");
|
|
36
|
+
var import_base = require("./base");
|
|
37
|
+
var import_addresses = require("../generated/addresses");
|
|
36
38
|
var import_abi = require("../generated/abi");
|
|
39
|
+
var import_errors = require("../errors");
|
|
37
40
|
var import_subgraph = require("../generated/subgraph");
|
|
38
41
|
var import_graphql = require("graphql");
|
|
42
|
+
var import_subgraphConsistency = require("../utils/subgraphConsistency");
|
|
43
|
+
var import_subgraphPagination = require("../utils/subgraphPagination");
|
|
44
|
+
var import_chainQuery = require("../utils/chainQuery");
|
|
39
45
|
var import_encryption = require("../utils/encryption");
|
|
40
46
|
var import_schemaValidation = require("../utils/schemaValidation");
|
|
41
47
|
var import_multicall = require("../utils/multicall");
|
|
42
|
-
class DataController {
|
|
48
|
+
class DataController extends import_base.BaseController {
|
|
43
49
|
constructor(context) {
|
|
44
|
-
|
|
50
|
+
super(context);
|
|
45
51
|
}
|
|
46
52
|
async upload(params) {
|
|
53
|
+
this.assertWallet();
|
|
47
54
|
const {
|
|
48
55
|
content,
|
|
49
56
|
filename,
|
|
@@ -51,12 +58,18 @@ class DataController {
|
|
|
51
58
|
permissions = [],
|
|
52
59
|
encrypt = true,
|
|
53
60
|
providerName,
|
|
54
|
-
owner
|
|
61
|
+
owner,
|
|
62
|
+
schemaValidation = "strict"
|
|
55
63
|
} = params;
|
|
64
|
+
if (encrypt && owner && owner.toLowerCase() !== this.context.userAddress.toLowerCase()) {
|
|
65
|
+
throw new import_errors.InvalidConfigurationError(
|
|
66
|
+
"The 'owner' parameter cannot be different from the connected wallet's address when encryption is enabled. This would create an un-decryptable file."
|
|
67
|
+
);
|
|
68
|
+
}
|
|
56
69
|
try {
|
|
57
70
|
let isValid = true;
|
|
58
71
|
let validationErrors = [];
|
|
59
|
-
if (schemaId !== void 0) {
|
|
72
|
+
if (schemaId !== void 0 && schemaValidation !== "skip") {
|
|
60
73
|
try {
|
|
61
74
|
const { SchemaController } = await import("./schemas");
|
|
62
75
|
const schemaController = new SchemaController(this.context);
|
|
@@ -80,16 +93,20 @@ class DataController {
|
|
|
80
93
|
}
|
|
81
94
|
(0, import_schemaValidation.validateDataAgainstSchema)(parsedContent, schema);
|
|
82
95
|
} catch (error) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
96
|
+
if (schemaValidation === "strict") {
|
|
97
|
+
throw error;
|
|
98
|
+
} else if (schemaValidation === "warn") {
|
|
99
|
+
console.warn(
|
|
100
|
+
'[Vana SDK] Schema validation failed, but continuing due to validation mode "warn"'
|
|
101
|
+
);
|
|
102
|
+
if (error instanceof Error) {
|
|
103
|
+
console.warn(" Validation error:", error.message);
|
|
104
|
+
if (typeof error === "object" && "errors" in error && Array.isArray(error.errors)) {
|
|
105
|
+
console.warn(" Detailed errors:", error.errors);
|
|
106
|
+
}
|
|
90
107
|
}
|
|
91
|
-
|
|
92
|
-
validationErrors = ["Schema validation failed"];
|
|
108
|
+
isValid = false;
|
|
109
|
+
validationErrors = error instanceof Error ? [error.message] : ["Schema validation failed"];
|
|
93
110
|
}
|
|
94
111
|
}
|
|
95
112
|
}
|
|
@@ -99,9 +116,10 @@ class DataController {
|
|
|
99
116
|
encrypt,
|
|
100
117
|
providerName
|
|
101
118
|
);
|
|
102
|
-
const userAddress = owner ??
|
|
119
|
+
const userAddress = owner ?? this.context.userAddress;
|
|
103
120
|
let encryptedPermissions = [];
|
|
104
121
|
if (permissions.length > 0 && encrypt) {
|
|
122
|
+
this.assertWallet();
|
|
105
123
|
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
106
124
|
this.context.walletClient,
|
|
107
125
|
this.context.platform,
|
|
@@ -122,29 +140,35 @@ class DataController {
|
|
|
122
140
|
);
|
|
123
141
|
}
|
|
124
142
|
let result;
|
|
125
|
-
if (this.context.
|
|
126
|
-
|
|
127
|
-
|
|
143
|
+
if (this.context.relayer) {
|
|
144
|
+
const request = {
|
|
145
|
+
type: "direct",
|
|
146
|
+
operation: "submitFileAdditionComplete",
|
|
147
|
+
params: {
|
|
128
148
|
url: uploadResult.url,
|
|
129
149
|
userAddress,
|
|
130
150
|
permissions: encryptedPermissions,
|
|
131
151
|
schemaId: schemaId ?? 0,
|
|
132
152
|
ownerAddress: owner
|
|
133
153
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
154
|
+
};
|
|
155
|
+
const response = await this.context.relayer(request);
|
|
156
|
+
if (response.type === "error") {
|
|
157
|
+
throw new Error(response.error);
|
|
158
|
+
}
|
|
159
|
+
if (response.type === "pending") {
|
|
160
|
+
result = await this.pollRelayerForConfirmation(
|
|
161
|
+
response.operationId,
|
|
162
|
+
void 0
|
|
163
|
+
// TODO: Add TransactionOptions to upload method signature
|
|
140
164
|
);
|
|
165
|
+
} else if (response.type === "direct" && typeof response.result === "object" && response.result !== null && "fileId" in response.result) {
|
|
166
|
+
result = response.result;
|
|
167
|
+
} else {
|
|
168
|
+
throw new Error("Invalid response from relayer");
|
|
141
169
|
}
|
|
142
|
-
result = await this.context.relayerCallbacks.submitFileAddition(
|
|
143
|
-
uploadResult.url,
|
|
144
|
-
userAddress
|
|
145
|
-
);
|
|
146
170
|
} else {
|
|
147
|
-
const txResult = await this.
|
|
171
|
+
const txResult = await this.addFileWithEncryptedPermissionsAndSchema(
|
|
148
172
|
uploadResult.url,
|
|
149
173
|
userAddress,
|
|
150
174
|
encryptedPermissions,
|
|
@@ -180,35 +204,110 @@ class DataController {
|
|
|
180
204
|
}
|
|
181
205
|
}
|
|
182
206
|
/**
|
|
183
|
-
*
|
|
207
|
+
* Encrypts data using wallet-derived encryption.
|
|
184
208
|
*
|
|
185
209
|
* @remarks
|
|
186
|
-
* This
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* decryption.
|
|
210
|
+
* This method provides secure, wallet-based encryption for data before uploading
|
|
211
|
+
* to the Vana network. It's the counterpart to decryptFile for preparing data
|
|
212
|
+
* for secure storage.
|
|
190
213
|
*
|
|
191
214
|
* The method automatically:
|
|
192
|
-
* - Generates
|
|
193
|
-
* -
|
|
194
|
-
* -
|
|
195
|
-
* -
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
* @param
|
|
202
|
-
* @
|
|
203
|
-
* @
|
|
204
|
-
* @
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
215
|
+
* - Generates an encryption key from the user's wallet signature
|
|
216
|
+
* - Converts the input data to a Blob if necessary
|
|
217
|
+
* - Encrypts the data using the generated key
|
|
218
|
+
* - Returns both the encrypted data and the encryption key
|
|
219
|
+
*
|
|
220
|
+
* The encryption key returned can be stored and later used for decryption,
|
|
221
|
+
* or shared with others to grant them decryption access.
|
|
222
|
+
*
|
|
223
|
+
* @param data - The data to encrypt (Blob, string, or object)
|
|
224
|
+
* @param options - Optional encryption configuration
|
|
225
|
+
* @returns Promise resolving to encrypted data and the encryption key used
|
|
226
|
+
* @throws {Error} When wallet is not connected or encryption fails
|
|
227
|
+
* @example
|
|
228
|
+
* ```typescript
|
|
229
|
+
* // Encrypt a string
|
|
230
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
231
|
+
* "My secret data"
|
|
232
|
+
* );
|
|
233
|
+
*
|
|
234
|
+
* // Encrypt JSON with custom MIME type
|
|
235
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
236
|
+
* { name: "Alice", age: 30 },
|
|
237
|
+
* { mimeType: "application/json" }
|
|
238
|
+
* );
|
|
239
|
+
*
|
|
240
|
+
* // With custom encryption seed
|
|
241
|
+
* const { encryptedData, encryptionKey } = await vana.data.encryptFile(
|
|
242
|
+
* "Secret message",
|
|
243
|
+
* { seed: "My custom encryption seed" }
|
|
244
|
+
* );
|
|
245
|
+
*
|
|
246
|
+
* // Upload the encrypted data
|
|
247
|
+
* const result = await vana.data.uploadToStorage(encryptedData);
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
async encryptFile(data, options) {
|
|
251
|
+
this.assertWallet();
|
|
252
|
+
try {
|
|
253
|
+
const encryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
254
|
+
this.context.walletClient,
|
|
255
|
+
this.context.platform,
|
|
256
|
+
options?.seed ?? import_encryption.DEFAULT_ENCRYPTION_SEED
|
|
257
|
+
);
|
|
258
|
+
let blob;
|
|
259
|
+
if (data instanceof Blob) {
|
|
260
|
+
blob = data;
|
|
261
|
+
} else if (typeof data === "string") {
|
|
262
|
+
blob = new Blob([data], { type: options?.mimeType ?? "text/plain" });
|
|
263
|
+
} else {
|
|
264
|
+
blob = new Blob([JSON.stringify(data)], {
|
|
265
|
+
type: options?.mimeType ?? "application/json"
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
const encryptedData = await (0, import_encryption.encryptBlobWithSignedKey)(
|
|
269
|
+
blob,
|
|
270
|
+
encryptionKey,
|
|
271
|
+
this.context.platform
|
|
272
|
+
);
|
|
273
|
+
return {
|
|
274
|
+
encryptedData,
|
|
275
|
+
encryptionKey
|
|
276
|
+
};
|
|
277
|
+
} catch (error) {
|
|
278
|
+
throw new Error(
|
|
279
|
+
`Failed to encrypt file: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Decrypts a file using wallet-derived decryption key.
|
|
285
|
+
*
|
|
286
|
+
* @remarks
|
|
287
|
+
* Counterpart to `upload()` for decrypting user files. Automatically
|
|
288
|
+
* generates decryption key from wallet, fetches encrypted content,
|
|
289
|
+
* and decrypts. Supports IPFS (with gateway fallback) and HTTP URLs.
|
|
290
|
+
*
|
|
291
|
+
* @param file - UserFile object from `getUserFiles()`
|
|
292
|
+
* @param options - Decryption options
|
|
293
|
+
* @param options.seed - Custom encryption seed.
|
|
294
|
+
* Defaults to standard Vana seed.
|
|
295
|
+
*
|
|
296
|
+
* @returns Decrypted content as Blob
|
|
297
|
+
*
|
|
298
|
+
* @throws {Error} No wallet connected.
|
|
299
|
+
* Connect wallet before decrypting.
|
|
300
|
+
* @throws {Error} Network error accessing file.
|
|
301
|
+
* Check CORS settings or server availability.
|
|
302
|
+
* @throws {Error} File not found (404).
|
|
303
|
+
* File no longer available at stored URL.
|
|
304
|
+
* @throws {Error} Access denied (403).
|
|
305
|
+
* No permission to access file.
|
|
306
|
+
* @throws {Error} Invalid file format.
|
|
307
|
+
* File not encrypted with Vana protocol.
|
|
308
|
+
* @throws {Error} Wrong encryption key.
|
|
309
|
+
* Verify seed matches upload or use default.
|
|
310
|
+
*
|
|
212
311
|
* @example
|
|
213
312
|
* ```typescript
|
|
214
313
|
* // Basic file decryption
|
|
@@ -234,12 +333,14 @@ class DataController {
|
|
|
234
333
|
* fs.writeFileSync('decrypted-file.txt', Buffer.from(buffer));
|
|
235
334
|
* ```
|
|
236
335
|
*/
|
|
237
|
-
async decryptFile(file,
|
|
336
|
+
async decryptFile(file, options) {
|
|
337
|
+
this.assertWallet();
|
|
238
338
|
try {
|
|
339
|
+
this.assertWallet();
|
|
239
340
|
const encryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
240
341
|
this.context.walletClient,
|
|
241
342
|
this.context.platform,
|
|
242
|
-
|
|
343
|
+
options?.seed ?? import_encryption.DEFAULT_ENCRYPTION_SEED
|
|
243
344
|
);
|
|
244
345
|
let encryptedBlob;
|
|
245
346
|
try {
|
|
@@ -322,99 +423,126 @@ class DataController {
|
|
|
322
423
|
}
|
|
323
424
|
}
|
|
324
425
|
/**
|
|
325
|
-
* Retrieves all
|
|
426
|
+
* Retrieves all files owned by a specific user address.
|
|
326
427
|
*
|
|
327
428
|
* @remarks
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
* @
|
|
339
|
-
*
|
|
340
|
-
* @
|
|
341
|
-
*
|
|
342
|
-
* @throws {Error}
|
|
343
|
-
*
|
|
344
|
-
* @throws {Error}
|
|
429
|
+
* Queries the Vana subgraph for files owned by the specified address.
|
|
430
|
+
* Automatically deduplicates by file ID, keeping the latest version
|
|
431
|
+
* when duplicates exist from re-indexing or chain reorganizations.
|
|
432
|
+
* Enriches results with DLP proof data when available.
|
|
433
|
+
*
|
|
434
|
+
* @param params - Query configuration
|
|
435
|
+
* @param params.owner - Wallet address of the file owner
|
|
436
|
+
* @param params.subgraphUrl - Subgraph endpoint override.
|
|
437
|
+
* Defaults to context configuration.
|
|
438
|
+
*
|
|
439
|
+
* @returns Array of UserFile objects sorted by timestamp (newest first)
|
|
440
|
+
*
|
|
441
|
+
* @throws {Error} Subgraph URL not configured.
|
|
442
|
+
* Provide `subgraphUrl` parameter or configure in Vana constructor.
|
|
443
|
+
* @throws {Error} Subgraph request failed.
|
|
444
|
+
* Check network connectivity and subgraph availability.
|
|
445
|
+
* @throws {Error} Subgraph returned errors.
|
|
446
|
+
* Review query parameters and subgraph logs.
|
|
447
|
+
*
|
|
345
448
|
* @example
|
|
346
449
|
* ```typescript
|
|
347
|
-
* // Query files for a specific user
|
|
348
450
|
* const files = await vana.data.getUserFiles({
|
|
349
|
-
* owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
|
|
451
|
+
* owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
|
|
350
452
|
* });
|
|
351
453
|
*
|
|
352
454
|
* files.forEach(file => {
|
|
353
|
-
* console.log(`File ${file.id}: ${file.url}
|
|
455
|
+
* console.log(`File ${file.id}: ${file.url}`);
|
|
456
|
+
* console.log(` Schema: ${file.schemaId}`);
|
|
457
|
+
* console.log(` DLPs: ${file.dlpIds?.join(", ") || "none"}`);
|
|
354
458
|
* });
|
|
355
459
|
* ```
|
|
356
460
|
*/
|
|
357
|
-
async getUserFiles(params) {
|
|
461
|
+
async getUserFiles(params, options) {
|
|
358
462
|
const { owner, subgraphUrl } = params;
|
|
463
|
+
let dataSource = options?.source === "chain" ? "chain" : "subgraph";
|
|
464
|
+
if (options?.source === "auto" || !options?.source && options?.minBlock) {
|
|
465
|
+
const endpoint2 = subgraphUrl ?? this.context.subgraphUrl;
|
|
466
|
+
const currentBlock = await this.context.publicClient.getBlockNumber();
|
|
467
|
+
let subgraphBlock;
|
|
468
|
+
if (endpoint2) {
|
|
469
|
+
try {
|
|
470
|
+
const meta = await (0, import_subgraphConsistency.fetchSubgraphMeta)(endpoint2);
|
|
471
|
+
subgraphBlock = meta.blockNumber;
|
|
472
|
+
} catch {
|
|
473
|
+
subgraphBlock = void 0;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
dataSource = (0, import_chainQuery.determineDataSource)(
|
|
477
|
+
options?.source,
|
|
478
|
+
options?.minBlock,
|
|
479
|
+
currentBlock,
|
|
480
|
+
subgraphBlock
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
if (dataSource === "chain") {
|
|
484
|
+
const publicClient = this.context.publicClient;
|
|
485
|
+
const chainId = await publicClient.getChainId();
|
|
486
|
+
const contractAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
487
|
+
const files = await (0, import_chainQuery.getUserFilesFromChain)(
|
|
488
|
+
publicClient,
|
|
489
|
+
contractAddress,
|
|
490
|
+
owner,
|
|
491
|
+
options?.minBlock ? BigInt(options.minBlock) : void 0
|
|
492
|
+
);
|
|
493
|
+
const limit = options?.fetchAll ? files.length : options?.limit ?? 100;
|
|
494
|
+
const offset = options?.offset ?? 0;
|
|
495
|
+
return files.slice(offset, offset + limit);
|
|
496
|
+
}
|
|
359
497
|
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
360
498
|
if (!endpoint) {
|
|
361
499
|
throw new Error(
|
|
362
500
|
"subgraphUrl is required. Please provide a valid subgraph endpoint or configure it in Vana constructor."
|
|
363
501
|
);
|
|
364
502
|
}
|
|
503
|
+
if (options?.minBlock || options?.waitForSync) {
|
|
504
|
+
await (0, import_subgraphConsistency.checkSubgraphConsistency)(endpoint, options);
|
|
505
|
+
}
|
|
365
506
|
try {
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
507
|
+
const orderByMap = {
|
|
508
|
+
id: "id",
|
|
509
|
+
addedAtBlock: "addedAtBlock",
|
|
510
|
+
addedAtTimestamp: "addedAtTimestamp",
|
|
511
|
+
url: "url",
|
|
512
|
+
schemaId: "schemaId"
|
|
513
|
+
};
|
|
514
|
+
const allFiles = await (0, import_subgraphPagination.executePaginatedQuery)({
|
|
515
|
+
endpoint,
|
|
516
|
+
document: import_subgraph.GetUserFilesPaginatedDocument,
|
|
517
|
+
baseVariables: {
|
|
518
|
+
userId: owner.toLowerCase(),
|
|
519
|
+
// Subgraph requires lowercase addresses
|
|
520
|
+
orderBy: (0, import_subgraphPagination.mapOrderByToEnum)(
|
|
521
|
+
options?.orderBy,
|
|
522
|
+
orderByMap,
|
|
523
|
+
"addedAtBlock"
|
|
524
|
+
),
|
|
525
|
+
orderDirection: (0, import_subgraphPagination.mapOrderDirection)(
|
|
526
|
+
options?.orderDirection,
|
|
527
|
+
"asc",
|
|
528
|
+
"desc"
|
|
529
|
+
)
|
|
370
530
|
},
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
// Subgraph requires lowercase addresses
|
|
376
|
-
}
|
|
377
|
-
})
|
|
378
|
-
});
|
|
379
|
-
if (!response.ok) {
|
|
380
|
-
throw new Error(
|
|
381
|
-
`Subgraph request failed: ${response.status} ${response.statusText}`
|
|
382
|
-
);
|
|
383
|
-
}
|
|
384
|
-
const result = await response.json();
|
|
385
|
-
if (result.errors) {
|
|
386
|
-
throw new Error(
|
|
387
|
-
`Subgraph errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
388
|
-
);
|
|
389
|
-
}
|
|
390
|
-
const user = result.data?.user;
|
|
391
|
-
if (!user?.files?.length) {
|
|
392
|
-
console.warn("No files found for user:", owner);
|
|
393
|
-
return [];
|
|
394
|
-
}
|
|
395
|
-
const fileMap = /* @__PURE__ */ new Map();
|
|
396
|
-
user.files.forEach((file) => {
|
|
397
|
-
const fileId = parseInt(file.id);
|
|
398
|
-
const userFile = {
|
|
399
|
-
id: fileId,
|
|
531
|
+
options,
|
|
532
|
+
extractItems: (data) => data?.user?.files,
|
|
533
|
+
transformItem: (file) => ({
|
|
534
|
+
id: parseInt(file.id),
|
|
400
535
|
url: file.url,
|
|
401
536
|
ownerAddress: file.owner.id,
|
|
402
537
|
addedAtBlock: BigInt(file.addedAtBlock),
|
|
403
538
|
schemaId: parseInt(file.schemaId),
|
|
404
539
|
addedAtTimestamp: BigInt(file.addedAtTimestamp),
|
|
405
540
|
transactionHash: file.transactionHash
|
|
406
|
-
}
|
|
407
|
-
const existing = fileMap.get(fileId);
|
|
408
|
-
if (!existing || userFile.addedAtTimestamp && existing.addedAtTimestamp && userFile.addedAtTimestamp > existing.addedAtTimestamp) {
|
|
409
|
-
fileMap.set(fileId, userFile);
|
|
410
|
-
}
|
|
541
|
+
})
|
|
411
542
|
});
|
|
412
|
-
|
|
413
|
-
(a, b) => Number((b.addedAtTimestamp ?? 0n) - (a.addedAtTimestamp ?? 0n))
|
|
414
|
-
);
|
|
415
|
-
if (userFiles.length > 0) {
|
|
543
|
+
if (allFiles.length > 0) {
|
|
416
544
|
try {
|
|
417
|
-
const fileIds =
|
|
545
|
+
const fileIds = allFiles.map((f) => f.id);
|
|
418
546
|
let proofMap;
|
|
419
547
|
try {
|
|
420
548
|
proofMap = await this._fetchProofsFromSubgraph(fileIds, endpoint);
|
|
@@ -425,7 +553,7 @@ class DataController {
|
|
|
425
553
|
);
|
|
426
554
|
proofMap = await this._fetchProofsFromChain(fileIds);
|
|
427
555
|
}
|
|
428
|
-
for (const file of
|
|
556
|
+
for (const file of allFiles) {
|
|
429
557
|
const dlpIds = proofMap.get(file.id);
|
|
430
558
|
if (dlpIds && dlpIds.length > 0) {
|
|
431
559
|
file.dlpIds = dlpIds;
|
|
@@ -435,7 +563,7 @@ class DataController {
|
|
|
435
563
|
console.warn("Failed to fetch proof data for files:", error);
|
|
436
564
|
}
|
|
437
565
|
}
|
|
438
|
-
return
|
|
566
|
+
return allFiles;
|
|
439
567
|
} catch (error) {
|
|
440
568
|
console.error("Failed to fetch user files from subgraph:", error);
|
|
441
569
|
throw new Error(
|
|
@@ -503,7 +631,7 @@ class DataController {
|
|
|
503
631
|
* @returns Map of file IDs to their associated DLP IDs
|
|
504
632
|
*/
|
|
505
633
|
async _fetchProofsFromChain(fileIds) {
|
|
506
|
-
const chainId = this.context.
|
|
634
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
507
635
|
if (!chainId) {
|
|
508
636
|
throw new Error("Chain ID not available");
|
|
509
637
|
}
|
|
@@ -561,6 +689,9 @@ class DataController {
|
|
|
561
689
|
*/
|
|
562
690
|
async getDLP(dlpId, options = {}) {
|
|
563
691
|
const subgraphUrl = options.subgraphUrl ?? this.context.subgraphUrl;
|
|
692
|
+
if (subgraphUrl && (options.minBlock || options.waitForSync)) {
|
|
693
|
+
await (0, import_subgraphConsistency.checkSubgraphConsistency)(subgraphUrl, options);
|
|
694
|
+
}
|
|
564
695
|
if (subgraphUrl) {
|
|
565
696
|
try {
|
|
566
697
|
const response = await fetch(subgraphUrl, {
|
|
@@ -594,15 +725,15 @@ class DataController {
|
|
|
594
725
|
name: result.data.dlp.name ?? "",
|
|
595
726
|
metadata: result.data.dlp.metadata ?? void 0,
|
|
596
727
|
status: result.data.dlp.status ? parseInt(result.data.dlp.status) : void 0,
|
|
597
|
-
address: result.data.dlp.address,
|
|
598
|
-
owner: result.data.dlp.owner
|
|
728
|
+
address: result.data.dlp.address ? result.data.dlp.address : void 0,
|
|
729
|
+
owner: result.data.dlp.owner ? result.data.dlp.owner : void 0
|
|
599
730
|
};
|
|
600
731
|
} catch (error) {
|
|
601
732
|
console.debug("Subgraph query failed, falling back to chain:", error);
|
|
602
733
|
}
|
|
603
734
|
}
|
|
604
735
|
try {
|
|
605
|
-
const chainId = this.context.
|
|
736
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
606
737
|
if (!chainId) {
|
|
607
738
|
throw new Error("Chain ID not available");
|
|
608
739
|
}
|
|
@@ -701,15 +832,15 @@ class DataController {
|
|
|
701
832
|
name: dlp.name ?? "",
|
|
702
833
|
metadata: dlp.metadata,
|
|
703
834
|
status: dlp.status ? parseInt(dlp.status) : void 0,
|
|
704
|
-
address: dlp.address,
|
|
705
|
-
owner: dlp.owner
|
|
835
|
+
address: dlp.address ? dlp.address : void 0,
|
|
836
|
+
owner: dlp.owner ? dlp.owner : void 0
|
|
706
837
|
}));
|
|
707
838
|
} catch (error) {
|
|
708
839
|
console.debug("Subgraph query failed, falling back to chain:", error);
|
|
709
840
|
}
|
|
710
841
|
}
|
|
711
842
|
try {
|
|
712
|
-
const chainId = this.context.
|
|
843
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
713
844
|
if (!chainId) {
|
|
714
845
|
throw new Error("Chain ID not available");
|
|
715
846
|
}
|
|
@@ -779,21 +910,33 @@ class DataController {
|
|
|
779
910
|
* @returns Promise resolving to an array of permission objects
|
|
780
911
|
* @throws Error if both subgraph and RPC queries fail
|
|
781
912
|
*/
|
|
782
|
-
async getUserPermissions(params) {
|
|
913
|
+
async getUserPermissions(params, options) {
|
|
783
914
|
const { user, subgraphUrl } = params;
|
|
784
915
|
const endpoint = subgraphUrl ?? this.context.subgraphUrl;
|
|
916
|
+
if (endpoint && (options?.minBlock || options?.waitForSync)) {
|
|
917
|
+
await (0, import_subgraphConsistency.checkSubgraphConsistency)(endpoint, options);
|
|
918
|
+
}
|
|
785
919
|
if (endpoint) {
|
|
786
920
|
try {
|
|
787
|
-
const permissions = await this._getUserPermissionsViaSubgraph(
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
921
|
+
const permissions = await this._getUserPermissionsViaSubgraph(
|
|
922
|
+
{
|
|
923
|
+
user,
|
|
924
|
+
subgraphUrl: endpoint
|
|
925
|
+
},
|
|
926
|
+
options
|
|
927
|
+
);
|
|
791
928
|
return permissions;
|
|
792
929
|
} catch (error) {
|
|
793
930
|
console.warn("Subgraph query failed, falling back to RPC:", error);
|
|
794
931
|
}
|
|
795
932
|
}
|
|
796
|
-
|
|
933
|
+
const allPermissions = await this._getUserPermissionsViaRpc({ user });
|
|
934
|
+
if (options && !options.fetchAll) {
|
|
935
|
+
const limit = options.limit ?? 100;
|
|
936
|
+
const offset = options.offset ?? 0;
|
|
937
|
+
return allPermissions.slice(offset, offset + limit);
|
|
938
|
+
}
|
|
939
|
+
return allPermissions;
|
|
797
940
|
}
|
|
798
941
|
/**
|
|
799
942
|
* Internal method: Query user permissions via subgraph
|
|
@@ -803,46 +946,48 @@ class DataController {
|
|
|
803
946
|
* @param params.subgraphUrl - The subgraph URL endpoint to query
|
|
804
947
|
* @returns Promise resolving to an array of permission objects
|
|
805
948
|
*/
|
|
806
|
-
async _getUserPermissionsViaSubgraph(params) {
|
|
949
|
+
async _getUserPermissionsViaSubgraph(params, options) {
|
|
807
950
|
const { user, subgraphUrl } = params;
|
|
808
951
|
try {
|
|
809
|
-
const
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
952
|
+
const orderByMap = {
|
|
953
|
+
id: "id",
|
|
954
|
+
addedAtBlock: "addedAtBlock",
|
|
955
|
+
addedAtTimestamp: "addedAtTimestamp",
|
|
956
|
+
grant: "grant",
|
|
957
|
+
nonce: "nonce",
|
|
958
|
+
startBlock: "startBlock",
|
|
959
|
+
endBlock: "endBlock"
|
|
960
|
+
};
|
|
961
|
+
const permissions = await (0, import_subgraphPagination.executePaginatedQuery)({
|
|
962
|
+
endpoint: subgraphUrl,
|
|
963
|
+
document: import_subgraph.GetUserPermissionsPaginatedDocument,
|
|
964
|
+
baseVariables: {
|
|
965
|
+
userId: user.toLowerCase(),
|
|
966
|
+
orderBy: (0, import_subgraphPagination.mapOrderByToEnum)(
|
|
967
|
+
options?.orderBy,
|
|
968
|
+
orderByMap,
|
|
969
|
+
"addedAtTimestamp"
|
|
970
|
+
),
|
|
971
|
+
orderDirection: (0, import_subgraphPagination.mapOrderDirection)(
|
|
972
|
+
options?.orderDirection,
|
|
973
|
+
"desc",
|
|
974
|
+
"asc"
|
|
975
|
+
)
|
|
813
976
|
},
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
977
|
+
options,
|
|
978
|
+
extractItems: (data) => data?.user?.permissions,
|
|
979
|
+
transformItem: (permission) => ({
|
|
980
|
+
id: permission.id,
|
|
981
|
+
grant: permission.grant,
|
|
982
|
+
nonce: BigInt(permission.nonce),
|
|
983
|
+
signature: permission.signature,
|
|
984
|
+
addedAtBlock: BigInt(permission.addedAtBlock),
|
|
985
|
+
addedAtTimestamp: BigInt(permission.addedAtTimestamp),
|
|
986
|
+
transactionHash: permission.transactionHash,
|
|
987
|
+
user
|
|
819
988
|
})
|
|
820
989
|
});
|
|
821
|
-
|
|
822
|
-
throw new Error(
|
|
823
|
-
`Subgraph request failed: ${response.status} ${response.statusText}`
|
|
824
|
-
);
|
|
825
|
-
}
|
|
826
|
-
const result = await response.json();
|
|
827
|
-
if (result.errors) {
|
|
828
|
-
throw new Error(
|
|
829
|
-
`Subgraph query errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
830
|
-
);
|
|
831
|
-
}
|
|
832
|
-
const userData = result.data?.user;
|
|
833
|
-
if (!userData?.permissions?.length) {
|
|
834
|
-
return [];
|
|
835
|
-
}
|
|
836
|
-
return userData.permissions.map((permission) => ({
|
|
837
|
-
id: permission.id,
|
|
838
|
-
grant: permission.grant,
|
|
839
|
-
nonce: BigInt(permission.nonce),
|
|
840
|
-
signature: permission.signature,
|
|
841
|
-
addedAtBlock: BigInt(permission.addedAtBlock),
|
|
842
|
-
addedAtTimestamp: BigInt(permission.addedAtTimestamp),
|
|
843
|
-
transactionHash: permission.transactionHash,
|
|
844
|
-
user
|
|
845
|
-
})).sort((a, b) => Number(b.addedAtTimestamp - a.addedAtTimestamp));
|
|
990
|
+
return permissions;
|
|
846
991
|
} catch (error) {
|
|
847
992
|
console.error("Failed to query user permissions from subgraph:", error);
|
|
848
993
|
throw error;
|
|
@@ -858,7 +1003,7 @@ class DataController {
|
|
|
858
1003
|
async _getUserPermissionsViaRpc(params) {
|
|
859
1004
|
const { user } = params;
|
|
860
1005
|
try {
|
|
861
|
-
const chainId = this.context.
|
|
1006
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
862
1007
|
if (!chainId) {
|
|
863
1008
|
throw new Error("Chain ID not available");
|
|
864
1009
|
}
|
|
@@ -975,20 +1120,28 @@ class DataController {
|
|
|
975
1120
|
* });
|
|
976
1121
|
* ```
|
|
977
1122
|
*/
|
|
978
|
-
async getUserTrustedServers(params) {
|
|
979
|
-
const { user
|
|
1123
|
+
async getUserTrustedServers(params, options) {
|
|
1124
|
+
const { user } = params;
|
|
980
1125
|
const subgraphUrl = params.subgraphUrl ?? this.context.subgraphUrl;
|
|
1126
|
+
if (subgraphUrl && (options?.minBlock || options?.waitForSync)) {
|
|
1127
|
+
await (0, import_subgraphConsistency.checkSubgraphConsistency)(subgraphUrl, options);
|
|
1128
|
+
}
|
|
981
1129
|
if (subgraphUrl) {
|
|
982
1130
|
try {
|
|
983
|
-
const servers = await this._getUserTrustedServersViaSubgraph(
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
1131
|
+
const servers = await this._getUserTrustedServersViaSubgraph(
|
|
1132
|
+
{
|
|
1133
|
+
user,
|
|
1134
|
+
subgraphUrl
|
|
1135
|
+
},
|
|
1136
|
+
options
|
|
1137
|
+
);
|
|
1138
|
+
return servers;
|
|
988
1139
|
} catch (error) {
|
|
989
1140
|
console.warn("Subgraph query failed, falling back to RPC:", error);
|
|
990
1141
|
}
|
|
991
1142
|
}
|
|
1143
|
+
const limit = options?.fetchAll ? Number.MAX_SAFE_INTEGER : options?.limit ?? 100;
|
|
1144
|
+
const offset = options?.offset ?? 0;
|
|
992
1145
|
const rpcResult = await this._getUserTrustedServersViaRpc({
|
|
993
1146
|
user,
|
|
994
1147
|
limit,
|
|
@@ -1004,7 +1157,7 @@ class DataController {
|
|
|
1004
1157
|
* @param params.subgraphUrl - The subgraph URL endpoint to query
|
|
1005
1158
|
* @returns Promise resolving to an array of trusted server objects
|
|
1006
1159
|
*/
|
|
1007
|
-
async _getUserTrustedServersViaSubgraph(params) {
|
|
1160
|
+
async _getUserTrustedServersViaSubgraph(params, options) {
|
|
1008
1161
|
const { user, subgraphUrl } = params;
|
|
1009
1162
|
const graphqlEndpoint = subgraphUrl;
|
|
1010
1163
|
if (!graphqlEndpoint) {
|
|
@@ -1013,42 +1166,46 @@ class DataController {
|
|
|
1013
1166
|
);
|
|
1014
1167
|
}
|
|
1015
1168
|
try {
|
|
1016
|
-
const
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1169
|
+
const orderByMap = {
|
|
1170
|
+
id: "id",
|
|
1171
|
+
trustedAt: "trustedAt",
|
|
1172
|
+
trustedAtBlock: "trustedAtBlock",
|
|
1173
|
+
server: "server",
|
|
1174
|
+
user: "user"
|
|
1175
|
+
};
|
|
1176
|
+
const serverTrusts = await (0, import_subgraphPagination.executePaginatedQuery)({
|
|
1177
|
+
endpoint: graphqlEndpoint,
|
|
1178
|
+
document: import_subgraph.GetUserTrustedServersPaginatedDocument,
|
|
1179
|
+
baseVariables: {
|
|
1180
|
+
userId: user.toLowerCase(),
|
|
1181
|
+
// Subgraph requires lowercase addresses
|
|
1182
|
+
orderBy: (0, import_subgraphPagination.mapOrderByToEnum)(
|
|
1183
|
+
options?.orderBy,
|
|
1184
|
+
orderByMap,
|
|
1185
|
+
"trustedAtBlock"
|
|
1186
|
+
),
|
|
1187
|
+
orderDirection: (0, import_subgraphPagination.mapOrderDirection)(
|
|
1188
|
+
options?.orderDirection,
|
|
1189
|
+
"desc",
|
|
1190
|
+
"asc"
|
|
1191
|
+
)
|
|
1020
1192
|
},
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1193
|
+
options,
|
|
1194
|
+
extractItems: (data) => {
|
|
1195
|
+
const trusts = data?.user?.serverTrusts ?? [];
|
|
1196
|
+
return trusts.filter((trust) => !trust.untrustedAtBlock);
|
|
1197
|
+
},
|
|
1198
|
+
transformItem: (trust) => ({
|
|
1199
|
+
id: trust.server.id,
|
|
1200
|
+
serverAddress: trust.server.serverAddress,
|
|
1201
|
+
serverUrl: trust.server.url,
|
|
1202
|
+
trustedAt: BigInt(trust.trustedAt),
|
|
1203
|
+
user,
|
|
1204
|
+
name: ""
|
|
1205
|
+
// Not available in new schema, will be empty
|
|
1027
1206
|
})
|
|
1028
1207
|
});
|
|
1029
|
-
|
|
1030
|
-
throw new Error(
|
|
1031
|
-
`Subgraph request failed: ${response.status} ${response.statusText}`
|
|
1032
|
-
);
|
|
1033
|
-
}
|
|
1034
|
-
const result = await response.json();
|
|
1035
|
-
if (result.errors) {
|
|
1036
|
-
throw new Error(
|
|
1037
|
-
`Subgraph query errors: ${result.errors.map((e) => e.message).join(", ")}`
|
|
1038
|
-
);
|
|
1039
|
-
}
|
|
1040
|
-
if (!result.data?.user) {
|
|
1041
|
-
return [];
|
|
1042
|
-
}
|
|
1043
|
-
return (result.data.user.serverTrusts ?? []).filter((trust) => !trust.untrustedAtBlock).map((trust) => ({
|
|
1044
|
-
id: trust.server.id,
|
|
1045
|
-
serverAddress: trust.server.serverAddress,
|
|
1046
|
-
serverUrl: trust.server.url,
|
|
1047
|
-
trustedAt: BigInt(trust.trustedAt),
|
|
1048
|
-
user,
|
|
1049
|
-
name: ""
|
|
1050
|
-
// Not available in new schema, will be empty
|
|
1051
|
-
}));
|
|
1208
|
+
return serverTrusts;
|
|
1052
1209
|
} catch (error) {
|
|
1053
1210
|
console.error("Failed to query trusted servers from subgraph:", error);
|
|
1054
1211
|
throw error;
|
|
@@ -1066,7 +1223,7 @@ class DataController {
|
|
|
1066
1223
|
async _getUserTrustedServersViaRpc(params) {
|
|
1067
1224
|
const { user, limit, offset } = params;
|
|
1068
1225
|
try {
|
|
1069
|
-
const chainId = this.context.
|
|
1226
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1070
1227
|
if (!chainId) {
|
|
1071
1228
|
throw new Error("Chain ID not available");
|
|
1072
1229
|
}
|
|
@@ -1150,23 +1307,31 @@ class DataController {
|
|
|
1150
1307
|
}
|
|
1151
1308
|
}
|
|
1152
1309
|
/**
|
|
1153
|
-
*
|
|
1310
|
+
* Retrieves total file count from Data Registry.
|
|
1311
|
+
*
|
|
1312
|
+
* @remarks
|
|
1313
|
+
* Queries blockchain for complete file count across all users.
|
|
1314
|
+
* Useful for pagination and network statistics.
|
|
1315
|
+
*
|
|
1316
|
+
* @returns Total number of registered files
|
|
1317
|
+
*
|
|
1318
|
+
* @throws {Error} Chain ID not available.
|
|
1319
|
+
* Ensure network connection.
|
|
1320
|
+
* @throws {Error} Contract read failed.
|
|
1321
|
+
* Check RPC availability.
|
|
1154
1322
|
*
|
|
1155
|
-
* @returns Promise resolving to the total file count
|
|
1156
1323
|
* @example
|
|
1157
1324
|
* ```typescript
|
|
1158
|
-
* const
|
|
1159
|
-
* console.log(`Total files
|
|
1325
|
+
* const total = await vana.data.getTotalFilesCount();
|
|
1326
|
+
* console.log(`Total files: ${total}`);
|
|
1160
1327
|
*
|
|
1161
|
-
* //
|
|
1162
|
-
* const
|
|
1163
|
-
* const totalPages = Math.ceil(totalFiles / filesPerPage);
|
|
1164
|
-
* console.log(`Total pages: ${totalPages}`);
|
|
1328
|
+
* // Calculate pagination
|
|
1329
|
+
* const pages = Math.ceil(total / 20);
|
|
1165
1330
|
* ```
|
|
1166
1331
|
*/
|
|
1167
1332
|
async getTotalFilesCount() {
|
|
1168
1333
|
try {
|
|
1169
|
-
const chainId = this.context.
|
|
1334
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1170
1335
|
if (!chainId) {
|
|
1171
1336
|
throw new Error("Chain ID not available");
|
|
1172
1337
|
}
|
|
@@ -1175,7 +1340,7 @@ class DataController {
|
|
|
1175
1340
|
const dataRegistry = (0, import_viem.getContract)({
|
|
1176
1341
|
address: dataRegistryAddress,
|
|
1177
1342
|
abi: dataRegistryAbi,
|
|
1178
|
-
client: this.context.
|
|
1343
|
+
client: this.context.publicClient
|
|
1179
1344
|
});
|
|
1180
1345
|
const count = await dataRegistry.read.filesCount();
|
|
1181
1346
|
return Number(count);
|
|
@@ -1188,36 +1353,36 @@ class DataController {
|
|
|
1188
1353
|
}
|
|
1189
1354
|
}
|
|
1190
1355
|
/**
|
|
1191
|
-
* Retrieves
|
|
1356
|
+
* Retrieves file metadata by ID from the blockchain.
|
|
1357
|
+
*
|
|
1358
|
+
* @remarks
|
|
1359
|
+
* Queries DataRegistry contract directly for file details.
|
|
1360
|
+
* Works for any file ID regardless of ownership, enabling
|
|
1361
|
+
* cross-user file discovery and verification.
|
|
1362
|
+
*
|
|
1363
|
+
* @param fileId - Numeric file ID to retrieve
|
|
1364
|
+
*
|
|
1365
|
+
* @returns UserFile object with metadata
|
|
1366
|
+
*
|
|
1367
|
+
* @throws {Error} Chain ID not available.
|
|
1368
|
+
* Ensure proper network connection.
|
|
1369
|
+
* @throws {Error} File not found.
|
|
1370
|
+
* Verify file ID exists on-chain.
|
|
1371
|
+
* @throws {Error} Contract call failed.
|
|
1372
|
+
* Check network and RPC availability.
|
|
1192
1373
|
*
|
|
1193
|
-
* @param fileId - The file ID to look up
|
|
1194
|
-
* @returns Promise resolving to UserFile object
|
|
1195
|
-
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1196
|
-
* @throws {Error} "File not found" - When file ID doesn't exist or returns empty data
|
|
1197
|
-
* @throws {Error} "Failed to fetch file {fileId}: {error}" - General contract read failures
|
|
1198
1374
|
* @example
|
|
1199
1375
|
* ```typescript
|
|
1200
|
-
*
|
|
1201
|
-
*
|
|
1202
|
-
*
|
|
1203
|
-
*
|
|
1204
|
-
*
|
|
1205
|
-
* owner: file.ownerAddress,
|
|
1206
|
-
* addedAt: file.addedAtBlock
|
|
1207
|
-
* });
|
|
1208
|
-
* } catch (error) {
|
|
1209
|
-
* console.error('File not found or error retrieving file:', error);
|
|
1210
|
-
* }
|
|
1376
|
+
* const file = await vana.data.getFileById(123);
|
|
1377
|
+
* console.log(`File ${file.id}:`);
|
|
1378
|
+
* console.log(` URL: ${file.url}`);
|
|
1379
|
+
* console.log(` Owner: ${file.ownerAddress}`);
|
|
1380
|
+
* console.log(` Block: ${file.addedAtBlock}`);
|
|
1211
1381
|
* ```
|
|
1212
|
-
*
|
|
1213
|
-
* This method queries the DataRegistry contract directly
|
|
1214
|
-
* to get file details for any file ID, regardless of user ownership.
|
|
1215
|
-
* This is useful for file lookup functionality where users can search
|
|
1216
|
-
* for specific files by ID.
|
|
1217
1382
|
*/
|
|
1218
1383
|
async getFileById(fileId) {
|
|
1219
1384
|
try {
|
|
1220
|
-
const chainId = this.context.
|
|
1385
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1221
1386
|
if (!chainId) {
|
|
1222
1387
|
throw new Error("Chain ID not available");
|
|
1223
1388
|
}
|
|
@@ -1226,7 +1391,7 @@ class DataController {
|
|
|
1226
1391
|
const dataRegistry = (0, import_viem.getContract)({
|
|
1227
1392
|
address: dataRegistryAddress,
|
|
1228
1393
|
abi: dataRegistryAbi,
|
|
1229
|
-
client: this.context.
|
|
1394
|
+
client: this.context.publicClient
|
|
1230
1395
|
});
|
|
1231
1396
|
const fileDetails = await dataRegistry.read.files([BigInt(fileId)]);
|
|
1232
1397
|
if (!fileDetails) {
|
|
@@ -1284,15 +1449,17 @@ class DataController {
|
|
|
1284
1449
|
* console.log(`File ${fileId} registered with schema in tx ${transactionHash}`);
|
|
1285
1450
|
* ```
|
|
1286
1451
|
*/
|
|
1287
|
-
async registerFileWithSchema(url, schemaId) {
|
|
1452
|
+
async registerFileWithSchema(url, schemaId, options) {
|
|
1453
|
+
this.assertWallet();
|
|
1288
1454
|
try {
|
|
1289
|
-
const chainId = this.context.
|
|
1455
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1290
1456
|
if (!chainId) {
|
|
1291
1457
|
throw new Error("Chain ID not available");
|
|
1292
1458
|
}
|
|
1459
|
+
this.assertWallet();
|
|
1293
1460
|
const dataRegistryAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
1294
1461
|
const dataRegistryAbi = (0, import_abi.getAbi)("DataRegistry");
|
|
1295
|
-
const account = this.context.walletClient.account ??
|
|
1462
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1296
1463
|
const from = typeof account === "string" ? account : account.address;
|
|
1297
1464
|
const hash = await this.context.walletClient.writeContract({
|
|
1298
1465
|
address: dataRegistryAddress,
|
|
@@ -1300,7 +1467,8 @@ class DataController {
|
|
|
1300
1467
|
functionName: "addFileWithSchema",
|
|
1301
1468
|
args: [url, BigInt(schemaId)],
|
|
1302
1469
|
account,
|
|
1303
|
-
chain: this.context.walletClient.chain ?? null
|
|
1470
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1471
|
+
...this.spreadTransactionOptions(options)
|
|
1304
1472
|
});
|
|
1305
1473
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1306
1474
|
return tx({
|
|
@@ -1322,13 +1490,6 @@ class DataController {
|
|
|
1322
1490
|
* @returns Promise resolving to the user's wallet address
|
|
1323
1491
|
* @throws {Error} When no addresses are available in wallet client
|
|
1324
1492
|
*/
|
|
1325
|
-
async getUserAddress() {
|
|
1326
|
-
const addresses = await this.context.walletClient.getAddresses();
|
|
1327
|
-
if (addresses.length === 0) {
|
|
1328
|
-
throw new Error("No addresses available in wallet client");
|
|
1329
|
-
}
|
|
1330
|
-
return addresses[0];
|
|
1331
|
-
}
|
|
1332
1493
|
/**
|
|
1333
1494
|
* Adds a file with permissions to the DataRegistry contract.
|
|
1334
1495
|
*
|
|
@@ -1345,12 +1506,14 @@ class DataController {
|
|
|
1345
1506
|
* with specific permissions on the DataRegistry contract. It can be used
|
|
1346
1507
|
* by both direct transactions and relayer services.
|
|
1347
1508
|
*/
|
|
1348
|
-
async addFileWithPermissions(url, ownerAddress, permissions = []) {
|
|
1509
|
+
async addFileWithPermissions(url, ownerAddress, permissions = [], options) {
|
|
1510
|
+
this.assertWallet();
|
|
1349
1511
|
try {
|
|
1350
|
-
const chainId = this.context.
|
|
1512
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1351
1513
|
if (!chainId) {
|
|
1352
1514
|
throw new Error("Chain ID not available");
|
|
1353
1515
|
}
|
|
1516
|
+
this.assertWallet();
|
|
1354
1517
|
const dataRegistryAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
1355
1518
|
const dataRegistryAbi = (0, import_abi.getAbi)("DataRegistry");
|
|
1356
1519
|
const account = this.context.walletClient.account ?? ownerAddress;
|
|
@@ -1361,7 +1524,8 @@ class DataController {
|
|
|
1361
1524
|
functionName: "addFileWithPermissions",
|
|
1362
1525
|
args: [url, ownerAddress, permissions],
|
|
1363
1526
|
account,
|
|
1364
|
-
chain: this.context.walletClient.chain ?? null
|
|
1527
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1528
|
+
...this.spreadTransactionOptions(options)
|
|
1365
1529
|
});
|
|
1366
1530
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1367
1531
|
return tx({
|
|
@@ -1416,10 +1580,12 @@ class DataController {
|
|
|
1416
1580
|
* console.log(`File ${result.fileId} registered in tx ${result.hash}`);
|
|
1417
1581
|
* ```
|
|
1418
1582
|
*/
|
|
1419
|
-
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
|
|
1583
|
+
async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
|
|
1584
|
+
this.assertWallet();
|
|
1420
1585
|
try {
|
|
1421
1586
|
let encryptedPermissions = [];
|
|
1422
1587
|
if (permissions.length > 0) {
|
|
1588
|
+
this.assertWallet();
|
|
1423
1589
|
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
1424
1590
|
this.context.walletClient,
|
|
1425
1591
|
this.context.platform,
|
|
@@ -1444,11 +1610,12 @@ class DataController {
|
|
|
1444
1610
|
})
|
|
1445
1611
|
);
|
|
1446
1612
|
}
|
|
1447
|
-
return await this.
|
|
1613
|
+
return await this.addFileWithEncryptedPermissionsAndSchema(
|
|
1448
1614
|
url,
|
|
1449
1615
|
ownerAddress,
|
|
1450
1616
|
encryptedPermissions,
|
|
1451
|
-
schemaId
|
|
1617
|
+
schemaId,
|
|
1618
|
+
options
|
|
1452
1619
|
);
|
|
1453
1620
|
} catch (error) {
|
|
1454
1621
|
console.error("Failed to add file with permissions and schema:", error);
|
|
@@ -1458,15 +1625,50 @@ class DataController {
|
|
|
1458
1625
|
}
|
|
1459
1626
|
}
|
|
1460
1627
|
/**
|
|
1461
|
-
*
|
|
1462
|
-
*
|
|
1628
|
+
* Adds a file with pre-encrypted permissions and schema to the DataRegistry.
|
|
1629
|
+
*
|
|
1630
|
+
* @remarks
|
|
1631
|
+
* This method is designed for relay services and advanced use cases where permissions
|
|
1632
|
+
* have already been encrypted client-side. Unlike `addFileWithPermissionsAndSchema()`,
|
|
1633
|
+
* this method expects permissions in the encrypted format with a 'key' field instead
|
|
1634
|
+
* of 'publicKey'.
|
|
1635
|
+
*
|
|
1636
|
+
* This is typically used by relay endpoints that receive pre-encrypted data from
|
|
1637
|
+
* the client SDK's `upload()` method, avoiding double encryption.
|
|
1638
|
+
*
|
|
1639
|
+
* @param url - The storage URL of the file (e.g., IPFS URL)
|
|
1640
|
+
* @param ownerAddress - The address that will own this file
|
|
1641
|
+
* @param permissions - Array of pre-encrypted permissions with 'account' and 'key' fields
|
|
1642
|
+
* @param schemaId - Optional schema ID for data validation (defaults to 0)
|
|
1643
|
+
* @returns Promise resolving to transaction result with hash and contract details
|
|
1644
|
+
* @throws {Error} When chain ID is not available
|
|
1645
|
+
* @throws {Error} When wallet is not connected
|
|
1646
|
+
* @throws {Error} When transaction fails
|
|
1647
|
+
* @example
|
|
1648
|
+
* ```typescript
|
|
1649
|
+
* // In a relay endpoint that receives pre-encrypted permissions
|
|
1650
|
+
* const result = await vana.data.addFileWithEncryptedPermissionsAndSchema(
|
|
1651
|
+
* "ipfs://QmXxx...",
|
|
1652
|
+
* ownerAddress,
|
|
1653
|
+
* [
|
|
1654
|
+
* {
|
|
1655
|
+
* account: "0xServerAddress...",
|
|
1656
|
+
* key: "encrypted_key_string" // Already encrypted by client
|
|
1657
|
+
* }
|
|
1658
|
+
* ],
|
|
1659
|
+
* schemaId
|
|
1660
|
+
* );
|
|
1661
|
+
*
|
|
1662
|
+
* console.log(`File registered in tx ${result.hash}`);
|
|
1663
|
+
* ```
|
|
1463
1664
|
*/
|
|
1464
|
-
async
|
|
1665
|
+
async addFileWithEncryptedPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0, options) {
|
|
1465
1666
|
try {
|
|
1466
|
-
const chainId = this.context.
|
|
1667
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1467
1668
|
if (!chainId) {
|
|
1468
1669
|
throw new Error("Chain ID not available");
|
|
1469
1670
|
}
|
|
1671
|
+
this.assertWallet();
|
|
1470
1672
|
const dataRegistryAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
1471
1673
|
const dataRegistryAbi = (0, import_abi.getAbi)("DataRegistry");
|
|
1472
1674
|
const account = this.context.walletClient.account ?? ownerAddress;
|
|
@@ -1477,7 +1679,8 @@ class DataController {
|
|
|
1477
1679
|
functionName: "addFileWithPermissionsAndSchema",
|
|
1478
1680
|
args: [url, ownerAddress, permissions, BigInt(schemaId)],
|
|
1479
1681
|
account,
|
|
1480
|
-
chain: this.context.walletClient.chain ?? null
|
|
1682
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1683
|
+
...this.spreadTransactionOptions(options)
|
|
1481
1684
|
});
|
|
1482
1685
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1483
1686
|
return tx({
|
|
@@ -1494,36 +1697,41 @@ class DataController {
|
|
|
1494
1697
|
}
|
|
1495
1698
|
}
|
|
1496
1699
|
/**
|
|
1497
|
-
*
|
|
1700
|
+
* Registers a data refiner for processing templates.
|
|
1498
1701
|
*
|
|
1499
1702
|
* @remarks
|
|
1500
|
-
* Refiners
|
|
1501
|
-
*
|
|
1502
|
-
*
|
|
1503
|
-
*
|
|
1504
|
-
*
|
|
1505
|
-
* @param params - Refiner
|
|
1506
|
-
* @param params.
|
|
1507
|
-
*
|
|
1508
|
-
* @param params.
|
|
1509
|
-
*
|
|
1510
|
-
* @returns
|
|
1511
|
-
*
|
|
1512
|
-
* @throws {Error}
|
|
1703
|
+
* Refiners define data transformation rules for DLPs.
|
|
1704
|
+
* Associates schema, instructions, and processing logic.
|
|
1705
|
+
*
|
|
1706
|
+
* @param params - Refiner configuration
|
|
1707
|
+
* @param params.dlpId - Data Liquidity Pool ID
|
|
1708
|
+
* @param params.name - Refiner display name
|
|
1709
|
+
* @param params.schemaId - Output schema ID.
|
|
1710
|
+
* Obtain via `vana.schemas.list()`.
|
|
1711
|
+
* @param params.refinementInstructionUrl - Processing instructions URL
|
|
1712
|
+
*
|
|
1713
|
+
* @returns Refiner ID and transaction hash
|
|
1714
|
+
*
|
|
1715
|
+
* @throws {Error} Chain ID not available.
|
|
1716
|
+
* Ensure network connection.
|
|
1717
|
+
* @throws {Error} Transaction failed.
|
|
1718
|
+
* Check wallet balance and network status.
|
|
1719
|
+
*
|
|
1513
1720
|
* @example
|
|
1514
1721
|
* ```typescript
|
|
1515
1722
|
* const result = await vana.data.addRefiner({
|
|
1516
1723
|
* dlpId: 1,
|
|
1517
|
-
* name: "
|
|
1724
|
+
* name: "Sentiment Analyzer",
|
|
1518
1725
|
* schemaId: 42,
|
|
1519
1726
|
* refinementInstructionUrl: "ipfs://QmXxx..."
|
|
1520
1727
|
* });
|
|
1521
|
-
* console.log(`
|
|
1728
|
+
* console.log(`Refiner ${result.refinerId} created`);
|
|
1522
1729
|
* ```
|
|
1523
1730
|
*/
|
|
1524
|
-
async addRefiner(params) {
|
|
1731
|
+
async addRefiner(params, options) {
|
|
1732
|
+
this.assertWallet();
|
|
1525
1733
|
try {
|
|
1526
|
-
const chainId = this.context.
|
|
1734
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1527
1735
|
if (!chainId) {
|
|
1528
1736
|
throw new Error("Chain ID not available");
|
|
1529
1737
|
}
|
|
@@ -1532,7 +1740,8 @@ class DataController {
|
|
|
1532
1740
|
"DataRefinerRegistry"
|
|
1533
1741
|
);
|
|
1534
1742
|
const dataRefinerRegistryAbi = (0, import_abi.getAbi)("DataRefinerRegistry");
|
|
1535
|
-
|
|
1743
|
+
this.assertWallet();
|
|
1744
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1536
1745
|
const from = typeof account === "string" ? account : account.address;
|
|
1537
1746
|
const hash = await this.context.walletClient.writeContract({
|
|
1538
1747
|
address: dataRefinerRegistryAddress,
|
|
@@ -1545,7 +1754,8 @@ class DataController {
|
|
|
1545
1754
|
params.refinementInstructionUrl
|
|
1546
1755
|
],
|
|
1547
1756
|
account,
|
|
1548
|
-
chain: this.context.walletClient.chain ?? null
|
|
1757
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1758
|
+
...this.spreadTransactionOptions(options)
|
|
1549
1759
|
});
|
|
1550
1760
|
const { tx } = await import("../utils/transactionHelpers");
|
|
1551
1761
|
const txResult = tx({
|
|
@@ -1574,31 +1784,34 @@ class DataController {
|
|
|
1574
1784
|
}
|
|
1575
1785
|
}
|
|
1576
1786
|
/**
|
|
1577
|
-
* Retrieves
|
|
1787
|
+
* Retrieves refiner configuration by ID.
|
|
1578
1788
|
*
|
|
1579
1789
|
* @remarks
|
|
1580
|
-
* Queries
|
|
1581
|
-
*
|
|
1790
|
+
* Queries DataRefinerRegistry for refiner details.
|
|
1791
|
+
* Returns DLP association, schema, and processing instructions.
|
|
1792
|
+
*
|
|
1793
|
+
* @param refinerId - Numeric refiner ID
|
|
1794
|
+
*
|
|
1795
|
+
* @returns Refiner configuration object
|
|
1796
|
+
*
|
|
1797
|
+
* @throws {Error} Chain ID not available.
|
|
1798
|
+
* Ensure network connection.
|
|
1799
|
+
* @throws {Error} Refiner not found.
|
|
1800
|
+
* Verify refiner ID exists.
|
|
1801
|
+
* @throws {Error} Contract read failed.
|
|
1802
|
+
* Check network and RPC status.
|
|
1582
1803
|
*
|
|
1583
|
-
* @param refinerId - The numeric refiner ID to retrieve
|
|
1584
|
-
* @returns Promise resolving to the refiner information object
|
|
1585
|
-
* @throws {Error} When chain ID is not available - "Chain ID not available"
|
|
1586
|
-
* @throws {Error} When refiner doesn't exist - "Refiner with ID {refinerId} does not exist"
|
|
1587
|
-
* @throws {Error} When contract read fails - "Failed to fetch refiner: {error}"
|
|
1588
1804
|
* @example
|
|
1589
1805
|
* ```typescript
|
|
1590
1806
|
* const refiner = await vana.data.getRefiner(1);
|
|
1591
|
-
* console.log({
|
|
1592
|
-
*
|
|
1593
|
-
*
|
|
1594
|
-
* schema: refiner.schemaId,
|
|
1595
|
-
* instructions: refiner.refinementInstructionUrl
|
|
1596
|
-
* });
|
|
1807
|
+
* console.log(`Refiner: ${refiner.name}`);
|
|
1808
|
+
* console.log(`DLP: ${refiner.dlpId}`);
|
|
1809
|
+
* console.log(`Schema: ${refiner.schemaId}`);
|
|
1597
1810
|
* ```
|
|
1598
1811
|
*/
|
|
1599
1812
|
async getRefiner(refinerId) {
|
|
1600
1813
|
try {
|
|
1601
|
-
const chainId = this.context.
|
|
1814
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1602
1815
|
if (!chainId) {
|
|
1603
1816
|
throw new Error("Chain ID not available");
|
|
1604
1817
|
}
|
|
@@ -1610,7 +1823,7 @@ class DataController {
|
|
|
1610
1823
|
const dataRefinerRegistry = (0, import_viem.getContract)({
|
|
1611
1824
|
address: dataRefinerRegistryAddress,
|
|
1612
1825
|
abi: dataRefinerRegistryAbi,
|
|
1613
|
-
client: this.context.
|
|
1826
|
+
client: this.context.publicClient
|
|
1614
1827
|
});
|
|
1615
1828
|
const refinerData = await dataRefinerRegistry.read.refiners([
|
|
1616
1829
|
BigInt(refinerId)
|
|
@@ -1634,27 +1847,33 @@ class DataController {
|
|
|
1634
1847
|
}
|
|
1635
1848
|
}
|
|
1636
1849
|
/**
|
|
1637
|
-
* Validates
|
|
1850
|
+
* Validates schema ID existence.
|
|
1638
1851
|
*
|
|
1639
1852
|
* @remarks
|
|
1640
|
-
*
|
|
1641
|
-
*
|
|
1853
|
+
* Verifies schema registration in DataRegistry.
|
|
1854
|
+
* Check before using schemas for uploads.
|
|
1855
|
+
*
|
|
1856
|
+
* @param schemaId - Numeric schema ID to validate
|
|
1857
|
+
*
|
|
1858
|
+
* @returns True if schema exists, false otherwise
|
|
1859
|
+
*
|
|
1860
|
+
* @throws {Error} Chain ID not available.
|
|
1861
|
+
* Ensure network connection.
|
|
1862
|
+
* @throws {Error} Contract read failed.
|
|
1863
|
+
* Check RPC availability.
|
|
1642
1864
|
*
|
|
1643
|
-
* @param schemaId - The numeric schema ID to validate
|
|
1644
|
-
* @returns Promise resolving to true if schema exists, false otherwise
|
|
1645
1865
|
* @example
|
|
1646
1866
|
* ```typescript
|
|
1647
|
-
* const
|
|
1648
|
-
* if (
|
|
1649
|
-
*
|
|
1650
|
-
*
|
|
1651
|
-
* console.log('Schema 42 does not exist');
|
|
1867
|
+
* const valid = await vana.data.isValidSchemaId(42);
|
|
1868
|
+
* if (valid) {
|
|
1869
|
+
* // Safe to use schema 42
|
|
1870
|
+
* await vana.data.upload({ schemaId: 42, ... });
|
|
1652
1871
|
* }
|
|
1653
1872
|
* ```
|
|
1654
1873
|
*/
|
|
1655
1874
|
async isValidSchemaId(schemaId) {
|
|
1656
1875
|
try {
|
|
1657
|
-
const chainId = this.context.
|
|
1876
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1658
1877
|
if (!chainId) {
|
|
1659
1878
|
throw new Error("Chain ID not available");
|
|
1660
1879
|
}
|
|
@@ -1666,7 +1885,7 @@ class DataController {
|
|
|
1666
1885
|
const dataRefinerRegistry = (0, import_viem.getContract)({
|
|
1667
1886
|
address: dataRefinerRegistryAddress,
|
|
1668
1887
|
abi: dataRefinerRegistryAbi,
|
|
1669
|
-
client: this.context.
|
|
1888
|
+
client: this.context.publicClient
|
|
1670
1889
|
});
|
|
1671
1890
|
const isValid = await dataRefinerRegistry.read.isValidSchemaId([
|
|
1672
1891
|
BigInt(schemaId)
|
|
@@ -1693,7 +1912,7 @@ class DataController {
|
|
|
1693
1912
|
*/
|
|
1694
1913
|
async getRefinersCount() {
|
|
1695
1914
|
try {
|
|
1696
|
-
const chainId = this.context.
|
|
1915
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1697
1916
|
if (!chainId) {
|
|
1698
1917
|
throw new Error("Chain ID not available");
|
|
1699
1918
|
}
|
|
@@ -1705,7 +1924,7 @@ class DataController {
|
|
|
1705
1924
|
const dataRefinerRegistry = (0, import_viem.getContract)({
|
|
1706
1925
|
address: dataRefinerRegistryAddress,
|
|
1707
1926
|
abi: dataRefinerRegistryAbi,
|
|
1708
|
-
client: this.context.
|
|
1927
|
+
client: this.context.publicClient
|
|
1709
1928
|
});
|
|
1710
1929
|
const count = await dataRefinerRegistry.read.refinersCount();
|
|
1711
1930
|
return Number(count);
|
|
@@ -1736,9 +1955,10 @@ class DataController {
|
|
|
1736
1955
|
* console.log(`Schema updated in tx ${result.transactionHash}`);
|
|
1737
1956
|
* ```
|
|
1738
1957
|
*/
|
|
1739
|
-
async updateSchemaId(params) {
|
|
1958
|
+
async updateSchemaId(params, options) {
|
|
1959
|
+
this.assertWallet();
|
|
1740
1960
|
try {
|
|
1741
|
-
const chainId = this.context.
|
|
1961
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1742
1962
|
if (!chainId) {
|
|
1743
1963
|
throw new Error("Chain ID not available");
|
|
1744
1964
|
}
|
|
@@ -1747,14 +1967,16 @@ class DataController {
|
|
|
1747
1967
|
"DataRefinerRegistry"
|
|
1748
1968
|
);
|
|
1749
1969
|
const dataRefinerRegistryAbi = (0, import_abi.getAbi)("DataRefinerRegistry");
|
|
1750
|
-
|
|
1970
|
+
this.assertWallet();
|
|
1971
|
+
const account = this.context.walletClient.account ?? this.context.userAddress;
|
|
1751
1972
|
const hash = await this.context.walletClient.writeContract({
|
|
1752
1973
|
address: dataRefinerRegistryAddress,
|
|
1753
1974
|
abi: dataRefinerRegistryAbi,
|
|
1754
1975
|
functionName: "updateSchemaId",
|
|
1755
1976
|
args: [BigInt(params.refinerId), BigInt(params.newSchemaId)],
|
|
1756
1977
|
account,
|
|
1757
|
-
chain: this.context.walletClient.chain ?? null
|
|
1978
|
+
chain: this.context.walletClient.chain ?? null,
|
|
1979
|
+
...this.spreadTransactionOptions(options)
|
|
1758
1980
|
});
|
|
1759
1981
|
await this.context.publicClient.waitForTransactionReceipt({ hash });
|
|
1760
1982
|
return {
|
|
@@ -1776,13 +1998,12 @@ class DataController {
|
|
|
1776
1998
|
* 3. Encrypts the user's encryption key with the provided public key
|
|
1777
1999
|
* 4. Registers the file with permissions
|
|
1778
2000
|
*
|
|
1779
|
-
* @param
|
|
1780
|
-
* @param permissions - Array of permissions to grant, each with account address and public key
|
|
1781
|
-
* @param filename - Optional filename for the upload
|
|
1782
|
-
* @param providerName - Optional storage provider to use
|
|
2001
|
+
* @param params - Upload parameters including data, permissions, and options
|
|
1783
2002
|
* @returns Promise resolving to upload result with file ID and storage URL
|
|
1784
2003
|
*/
|
|
1785
|
-
async uploadFileWithPermissions(
|
|
2004
|
+
async uploadFileWithPermissions(params) {
|
|
2005
|
+
this.assertWallet();
|
|
2006
|
+
const { data, permissions, filename, providerName } = params;
|
|
1786
2007
|
try {
|
|
1787
2008
|
const uploadResult = await this.uploadToStorage(
|
|
1788
2009
|
data,
|
|
@@ -1791,7 +2012,7 @@ class DataController {
|
|
|
1791
2012
|
// Always encrypt for uploadFileWithPermissions
|
|
1792
2013
|
providerName
|
|
1793
2014
|
);
|
|
1794
|
-
const userAddress =
|
|
2015
|
+
const userAddress = this.context.userAddress;
|
|
1795
2016
|
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
1796
2017
|
this.context.walletClient,
|
|
1797
2018
|
this.context.platform,
|
|
@@ -1810,12 +2031,32 @@ class DataController {
|
|
|
1810
2031
|
};
|
|
1811
2032
|
})
|
|
1812
2033
|
);
|
|
1813
|
-
if (this.context.
|
|
1814
|
-
const
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
2034
|
+
if (this.context.relayer) {
|
|
2035
|
+
const request = {
|
|
2036
|
+
type: "direct",
|
|
2037
|
+
operation: "submitFileAdditionWithPermissions",
|
|
2038
|
+
params: {
|
|
2039
|
+
url: uploadResult.url,
|
|
2040
|
+
userAddress,
|
|
2041
|
+
permissions: encryptedPermissions
|
|
2042
|
+
}
|
|
2043
|
+
};
|
|
2044
|
+
const response = await this.context.relayer(request);
|
|
2045
|
+
if (response.type === "error") {
|
|
2046
|
+
throw new Error(response.error);
|
|
2047
|
+
}
|
|
2048
|
+
let result;
|
|
2049
|
+
if (response.type === "pending") {
|
|
2050
|
+
result = await this.pollRelayerForConfirmation(
|
|
2051
|
+
response.operationId,
|
|
2052
|
+
void 0
|
|
2053
|
+
// TODO: Add TransactionOptions to upload method signature
|
|
2054
|
+
);
|
|
2055
|
+
} else if (response.type === "direct" && typeof response.result === "object" && response.result !== null && "fileId" in response.result) {
|
|
2056
|
+
result = response.result;
|
|
2057
|
+
} else {
|
|
2058
|
+
throw new Error("Invalid response from relayer");
|
|
2059
|
+
}
|
|
1819
2060
|
return {
|
|
1820
2061
|
fileId: result.fileId,
|
|
1821
2062
|
url: uploadResult.url,
|
|
@@ -1882,6 +2123,7 @@ class DataController {
|
|
|
1882
2123
|
}
|
|
1883
2124
|
let finalBlob = blob;
|
|
1884
2125
|
if (encrypt) {
|
|
2126
|
+
this.assertWallet();
|
|
1885
2127
|
const encryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
1886
2128
|
this.context.walletClient,
|
|
1887
2129
|
this.context.platform,
|
|
@@ -1903,7 +2145,15 @@ class DataController {
|
|
|
1903
2145
|
);
|
|
1904
2146
|
}
|
|
1905
2147
|
}
|
|
1906
|
-
const finalFilename =
|
|
2148
|
+
const finalFilename = (() => {
|
|
2149
|
+
if (filename) {
|
|
2150
|
+
if (encrypt && !filename.endsWith(".enc")) {
|
|
2151
|
+
return `${filename}.enc`;
|
|
2152
|
+
}
|
|
2153
|
+
return filename;
|
|
2154
|
+
}
|
|
2155
|
+
return encrypt ? `upload-${Date.now()}.enc` : `upload-${Date.now()}.dat`;
|
|
2156
|
+
})();
|
|
1907
2157
|
const uploadResult = await this.context.storageManager.upload(
|
|
1908
2158
|
finalBlob,
|
|
1909
2159
|
finalFilename,
|
|
@@ -1928,22 +2178,30 @@ class DataController {
|
|
|
1928
2178
|
* For advanced users who need more control over transaction timing,
|
|
1929
2179
|
* use `submitFilePermission()` instead.
|
|
1930
2180
|
*
|
|
1931
|
-
* @param
|
|
1932
|
-
* @param
|
|
1933
|
-
* @param
|
|
2181
|
+
* @param params - Parameters for adding file permission
|
|
2182
|
+
* @param params.fileId - The ID of the file to grant permission for
|
|
2183
|
+
* @param params.account - The recipient's wallet address that will access the file
|
|
2184
|
+
* @param params.publicKey - The recipient's public key for encryption.
|
|
2185
|
+
* Obtain via `vana.server.getIdentity(account).publicKey`
|
|
1934
2186
|
* @returns Promise resolving to permission data from PermissionGranted event
|
|
1935
2187
|
* @throws {Error} "No addresses available in wallet client" - When wallet is not connected
|
|
1936
2188
|
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1937
2189
|
* @throws {Error} "Failed to add permission to file: {error}" - When transaction fails or user doesn't own file
|
|
1938
2190
|
* @example
|
|
1939
2191
|
* ```typescript
|
|
1940
|
-
* const result = await vana.data.addPermissionToFile(
|
|
2192
|
+
* const result = await vana.data.addPermissionToFile({
|
|
2193
|
+
* fileId: 123,
|
|
2194
|
+
* account: "0xRecipientAddress...",
|
|
2195
|
+
* publicKey: "0xRecipientPublicKey..."
|
|
2196
|
+
* });
|
|
1941
2197
|
* console.log(`Permission granted to ${result.account} for file ${result.fileId}`);
|
|
1942
2198
|
* console.log(`Transaction: ${result.transactionHash}`);
|
|
1943
2199
|
* ```
|
|
1944
2200
|
*/
|
|
1945
|
-
async addPermissionToFile(
|
|
1946
|
-
|
|
2201
|
+
async addPermissionToFile(params, options) {
|
|
2202
|
+
this.assertWallet();
|
|
2203
|
+
const { fileId, account, publicKey } = params;
|
|
2204
|
+
return await this.submitFilePermission(fileId, account, publicKey, options);
|
|
1947
2205
|
}
|
|
1948
2206
|
/**
|
|
1949
2207
|
* Submits a file permission transaction to the blockchain.
|
|
@@ -1973,7 +2231,8 @@ class DataController {
|
|
|
1973
2231
|
* console.log(`Permission granted with ID: ${result.permissionId}`);
|
|
1974
2232
|
* ```
|
|
1975
2233
|
*/
|
|
1976
|
-
async submitFilePermission(fileId, account, publicKey) {
|
|
2234
|
+
async submitFilePermission(fileId, account, publicKey, options) {
|
|
2235
|
+
this.assertWallet();
|
|
1977
2236
|
try {
|
|
1978
2237
|
const userEncryptionKey = await (0, import_encryption.generateEncryptionKey)(
|
|
1979
2238
|
this.context.walletClient,
|
|
@@ -1985,20 +2244,22 @@ class DataController {
|
|
|
1985
2244
|
publicKey,
|
|
1986
2245
|
this.context.platform
|
|
1987
2246
|
);
|
|
1988
|
-
const chainId = this.context.
|
|
2247
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
1989
2248
|
if (!chainId) {
|
|
1990
2249
|
throw new Error("Chain ID not available");
|
|
1991
2250
|
}
|
|
1992
2251
|
const dataRegistryAddress = (0, import_addresses.getContractAddress)(chainId, "DataRegistry");
|
|
1993
2252
|
const dataRegistryAbi = (0, import_abi.getAbi)("DataRegistry");
|
|
1994
|
-
|
|
2253
|
+
this.assertWallet();
|
|
2254
|
+
const walletAccount = this.context.walletClient.account ?? this.context.userAddress;
|
|
1995
2255
|
const txHash = await this.context.walletClient.writeContract({
|
|
1996
2256
|
address: dataRegistryAddress,
|
|
1997
2257
|
abi: dataRegistryAbi,
|
|
1998
2258
|
functionName: "addFilePermission",
|
|
1999
2259
|
args: [BigInt(fileId), account, encryptedKey],
|
|
2000
2260
|
account: walletAccount,
|
|
2001
|
-
chain: this.context.walletClient.chain ?? null
|
|
2261
|
+
chain: this.context.walletClient.chain ?? null,
|
|
2262
|
+
...this.spreadTransactionOptions(options)
|
|
2002
2263
|
});
|
|
2003
2264
|
const { tx } = await import("../utils/transactionHelpers");
|
|
2004
2265
|
return tx({
|
|
@@ -2023,7 +2284,7 @@ class DataController {
|
|
|
2023
2284
|
*/
|
|
2024
2285
|
async getFilePermission(fileId, account) {
|
|
2025
2286
|
try {
|
|
2026
|
-
const chainId = this.context.
|
|
2287
|
+
const chainId = this.context.publicClient.chain?.id;
|
|
2027
2288
|
if (!chainId) {
|
|
2028
2289
|
throw new Error("Chain ID not available");
|
|
2029
2290
|
}
|
|
@@ -2032,7 +2293,7 @@ class DataController {
|
|
|
2032
2293
|
const dataRegistry = (0, import_viem.getContract)({
|
|
2033
2294
|
address: dataRegistryAddress,
|
|
2034
2295
|
abi: dataRegistryAbi,
|
|
2035
|
-
client: this.context.
|
|
2296
|
+
client: this.context.publicClient
|
|
2036
2297
|
});
|
|
2037
2298
|
const encryptedKey = await dataRegistry.read.filePermissions([
|
|
2038
2299
|
BigInt(fileId),
|
|
@@ -2056,12 +2317,13 @@ class DataController {
|
|
|
2056
2317
|
*
|
|
2057
2318
|
* @param file - The file to decrypt
|
|
2058
2319
|
* @param privateKey - The private key to decrypt the user's encryption key
|
|
2059
|
-
* @param
|
|
2320
|
+
* @param options - Optional decryption configuration
|
|
2321
|
+
* @param options.account - The account address that has permission (defaults to current wallet account)
|
|
2060
2322
|
* @returns Promise resolving to the decrypted file data
|
|
2061
2323
|
*/
|
|
2062
|
-
async decryptFileWithPermission(file, privateKey,
|
|
2324
|
+
async decryptFileWithPermission(file, privateKey, options) {
|
|
2063
2325
|
try {
|
|
2064
|
-
const permissionAccount = account ??
|
|
2326
|
+
const permissionAccount = options?.account ?? this.context.userAddress;
|
|
2065
2327
|
const encryptedKey = await this.getFilePermission(
|
|
2066
2328
|
file.id,
|
|
2067
2329
|
permissionAccount
|
|
@@ -2343,6 +2605,26 @@ class DataController {
|
|
|
2343
2605
|
async fetchAndValidateSchema(url) {
|
|
2344
2606
|
return (0, import_schemaValidation.fetchAndValidateSchema)(url);
|
|
2345
2607
|
}
|
|
2608
|
+
/**
|
|
2609
|
+
* Polls for confirmation of a relayer operation.
|
|
2610
|
+
* @internal
|
|
2611
|
+
*/
|
|
2612
|
+
async pollRelayerForConfirmation(operationId, options) {
|
|
2613
|
+
if (!this.context.relayer) {
|
|
2614
|
+
throw new Error("Relayer not configured for polling");
|
|
2615
|
+
}
|
|
2616
|
+
const pollingManager = new import_pollingManager.PollingManager(this.context.relayer);
|
|
2617
|
+
const result = await pollingManager.startPolling(operationId, {
|
|
2618
|
+
signal: options?.signal,
|
|
2619
|
+
onStatusUpdate: options?.onStatusUpdate,
|
|
2620
|
+
...options?.pollingOptions
|
|
2621
|
+
});
|
|
2622
|
+
return {
|
|
2623
|
+
fileId: 0,
|
|
2624
|
+
// This would need to be extracted from transaction events
|
|
2625
|
+
transactionHash: result.hash
|
|
2626
|
+
};
|
|
2627
|
+
}
|
|
2346
2628
|
}
|
|
2347
2629
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2348
2630
|
0 && (module.exports = {
|