1use crate::address_funds::AddressWitness;
2use crate::ProtocolError;
3use async_trait::async_trait;
4use platform_value::BinaryData;
5use std::fmt::Debug;
6use std::sync::Arc;
7
8#[async_trait]
11pub trait Signer<K>: Send + Sync + Debug {
12 async fn sign(&self, key: &K, data: &[u8]) -> Result<BinaryData, ProtocolError>;
14
15 async fn sign_create_witness(
17 &self,
18 key: &K,
19 data: &[u8],
20 ) -> Result<AddressWitness, ProtocolError>;
21
22 fn can_sign_with(&self, key: &K) -> bool;
24}
25
26#[async_trait]
27impl<K, S> Signer<K> for Arc<S>
28where
29 K: Send + Sync,
30 S: Signer<K> + ?Sized + Send + Sync,
31{
32 async fn sign(&self, key: &K, data: &[u8]) -> Result<BinaryData, ProtocolError> {
33 (**self).sign(key, data).await
34 }
35
36 async fn sign_create_witness(
37 &self,
38 key: &K,
39 data: &[u8],
40 ) -> Result<AddressWitness, ProtocolError> {
41 (**self).sign_create_witness(key, data).await
42 }
43
44 fn can_sign_with(&self, key: &K) -> bool {
45 (**self).can_sign_with(key)
46 }
47}