hopr_api/chain/
keys.rs

1use std::error::Error;
2
3pub use hopr_crypto_packet::{HoprSphinxHeaderSpec, HoprSphinxSuite, KeyIdMapper};
4use hopr_crypto_types::prelude::OffchainPublicKey;
5use hopr_primitive_types::prelude::Address;
6
7/// Operations for offchain keys.
8///
9/// This typically translates to optimized (and cached) versions of [`ChainReadChannelOperations`].
10#[async_trait::async_trait]
11pub trait ChainKeyOperations {
12    type Error: Error + Send + Sync + 'static;
13    type Mapper: KeyIdMapper<HoprSphinxSuite, HoprSphinxHeaderSpec> + Clone + Send + Sync + 'static;
14    /// Translates [`Address`] into [`OffchainPublicKey`].
15    async fn chain_key_to_packet_key(&self, chain: &Address) -> Result<Option<OffchainPublicKey>, Self::Error>;
16    /// Translates [`OffchainPublicKey`] into [`Address`].
17    async fn packet_key_to_chain_key(&self, packet: &OffchainPublicKey) -> Result<Option<Address>, Self::Error>;
18    /// Returns [mapper](KeyIdMapper) for offchain key IDs as a reference.
19    fn key_id_mapper_ref(&self) -> &Self::Mapper;
20}