use std::future::Future;
use std::sync::Arc;
use alloy_primitives::{Address, FixedBytes, Signature};
use alloy_signer_local::PrivateKeySigner;
pub trait SignerLike: Send + Sync {
fn address(&self) -> Address;
fn sign_hash(
&self,
hash: &FixedBytes<32>,
) -> impl Future<Output = Result<Signature, alloy_signer::Error>> + Send;
}
impl SignerLike for PrivateKeySigner {
fn address(&self) -> Address {
Self::address(self)
}
async fn sign_hash(&self, hash: &FixedBytes<32>) -> Result<Signature, alloy_signer::Error> {
alloy_signer::Signer::sign_hash(self, hash).await
}
}
impl<T: SignerLike + Send + Sync> SignerLike for Arc<T> {
fn address(&self) -> Address {
(**self).address()
}
async fn sign_hash(&self, hash: &FixedBytes<32>) -> Result<Signature, alloy_signer::Error> {
(**self).sign_hash(hash).await
}
}