Trait Signer

pub trait Signer<Sig = Signature> {
    // Required methods
    fn sign_hash<'life0, 'life1, 'async_trait>(
        &'life0 self,
        hash: &'life1 FixedBytes<32>,
    ) -> Pin<Box<dyn Future<Output = Result<Sig, Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn address(&self) -> Address;
    fn chain_id(&self) -> Option<u64>;
    fn set_chain_id(&mut self, chain_id: Option<u64>);

    // Provided methods
    fn sign_message<'life0, 'life1, 'async_trait>(
        &'life0 self,
        message: &'life1 [u8],
    ) -> Pin<Box<dyn Future<Output = Result<Sig, Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: Sync + 'async_trait { ... }
    fn with_chain_id(self, chain_id: Option<u64>) -> Self
       where Self: Sized { ... }
}
Expand description

Asynchronous Ethereum signer.

All provided implementations rely on sign_hash. A signer may not always be able to implement this method, in which case it should return UnsupportedOperation, and implement all the signing methods directly.

Synchronous signers should implement both this trait and [SignerSync].

Required Methods§

fn sign_hash<'life0, 'life1, 'async_trait>( &'life0 self, hash: &'life1 FixedBytes<32>, ) -> Pin<Box<dyn Future<Output = Result<Sig, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Signs the given hash.

fn address(&self) -> Address

Returns the signer’s Ethereum Address.

fn chain_id(&self) -> Option<u64>

Returns the signer’s chain ID.

fn set_chain_id(&mut self, chain_id: Option<u64>)

Sets the signer’s chain ID.

Provided Methods§

fn sign_message<'life0, 'life1, 'async_trait>( &'life0 self, message: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<Sig, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: Sync + 'async_trait,

Signs the hash of the provided message after prefixing it, as specified in EIP-191.

fn with_chain_id(self, chain_id: Option<u64>) -> Self
where Self: Sized,

Sets the signer’s chain ID and returns self.

Implementations on Foreign Types§

§

impl<'a, Sig, U> Signer<Sig> for &'a mut U
where U: 'a + Signer<Sig> + Sync + ?Sized,

§

fn sign_hash<'life0, 'life1, 'async_trait>( &'life0 self, hash: &'life1 FixedBytes<32>, ) -> Pin<Box<dyn Future<Output = Result<Sig, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, &'a mut U: 'async_trait,

§

fn sign_message<'life0, 'life1, 'async_trait>( &'life0 self, message: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<Sig, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, &'a mut U: Sync + 'async_trait,

§

fn address(&self) -> Address

§

fn chain_id(&self) -> Option<u64>

§

fn set_chain_id(&mut self, chain_id: Option<u64>)

§

impl<A, B, Sig> Signer<Sig> for Either<A, B>
where A: Signer<Sig> + Send + Sync, B: Signer<Sig> + Send + Sync, Sig: Send,

§

fn sign_hash<'life0, 'life1, 'async_trait>( &'life0 self, hash: &'life1 FixedBytes<32>, ) -> Pin<Box<dyn Future<Output = Result<Sig, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Either<A, B>: 'async_trait,

§

fn address(&self) -> Address

§

fn chain_id(&self) -> Option<u64>

§

fn set_chain_id(&mut self, chain_id: Option<u64>)

§

impl<C> Signer for LocalSigner<C>
where C: PrehashSigner<(Signature<Secp256k1>, RecoveryId)> + Send + Sync,

§

fn sign_hash<'life0, 'life1, 'async_trait>( &'life0 self, hash: &'life1 FixedBytes<32>, ) -> Pin<Box<dyn Future<Output = Result<Signature, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, LocalSigner<C>: 'async_trait,

§

fn address(&self) -> Address

§

fn chain_id(&self) -> Option<u64>

§

fn set_chain_id(&mut self, chain_id: Option<u64>)

§

impl<Sig, U> Signer<Sig> for Box<U>
where U: Signer<Sig> + Sync + ?Sized,

§

fn sign_hash<'life0, 'life1, 'async_trait>( &'life0 self, hash: &'life1 FixedBytes<32>, ) -> Pin<Box<dyn Future<Output = Result<Sig, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<U>: 'async_trait,

§

fn sign_message<'life0, 'life1, 'async_trait>( &'life0 self, message: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<Sig, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<U>: Sync + 'async_trait,

§

fn address(&self) -> Address

§

fn chain_id(&self) -> Option<u64>

§

fn set_chain_id(&mut self, chain_id: Option<u64>)

Implementors§