hopr_api/chain/
keys.rs

1use std::error::Error;
2
3pub use hopr_crypto_packet::{HoprKeyIdent, 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]
11#[auto_impl::auto_impl(&, Box, Arc)]
12pub trait ChainKeyOperations {
13    type Error: Error + Send + Sync + 'static;
14    type Mapper: KeyIdMapper<HoprSphinxSuite, HoprSphinxHeaderSpec> + Clone + Send + Sync + 'static;
15    /// Translates [`Address`] into [`OffchainPublicKey`].
16    async fn chain_key_to_packet_key(&self, chain: &Address) -> Result<Option<OffchainPublicKey>, Self::Error>;
17    /// Translates [`OffchainPublicKey`] into [`Address`].
18    async fn packet_key_to_chain_key(&self, packet: &OffchainPublicKey) -> Result<Option<Address>, Self::Error>;
19    /// Returns [mapper](KeyIdMapper) for offchain key IDs as a reference.
20    fn key_id_mapper_ref(&self) -> &Self::Mapper;
21}