dpp/identity/
signer.rs

1use crate::address_funds::AddressWitness;
2use crate::ProtocolError;
3use platform_value::BinaryData;
4use std::fmt::Debug;
5use std::sync::Arc;
6
7pub trait Signer<K>: Sync + Debug {
8    /// the public key bytes are only used to look up the private key
9    fn sign(&self, key: &K, data: &[u8]) -> Result<BinaryData, ProtocolError>;
10
11    /// the public key bytes are only used to look up the private key
12    fn sign_create_witness(&self, key: &K, data: &[u8]) -> Result<AddressWitness, ProtocolError>;
13
14    /// do we have this identity public key in the signer?
15    fn can_sign_with(&self, key: &K) -> bool;
16}
17
18impl<K, S> Signer<K> for Arc<S>
19where
20    S: Signer<K> + ?Sized + Send,
21{
22    fn sign(&self, key: &K, data: &[u8]) -> Result<BinaryData, ProtocolError> {
23        (**self).sign(key, data)
24    }
25
26    fn sign_create_witness(&self, key: &K, data: &[u8]) -> Result<AddressWitness, ProtocolError> {
27        (**self).sign_create_witness(key, data)
28    }
29
30    fn can_sign_with(&self, key: &K) -> bool {
31        (**self).can_sign_with(key)
32    }
33}