2020-09-20 15:17:02 +00:00
|
|
|
pub mod app;
|
|
|
|
pub mod types;
|
|
|
|
|
2020-09-24 21:33:09 +00:00
|
|
|
use crate::Signer;
|
2020-09-20 15:17:02 +00:00
|
|
|
use app::LedgerEthereum;
|
|
|
|
use async_trait::async_trait;
|
2020-09-24 21:33:09 +00:00
|
|
|
use ethers_core::types::{Address, Signature, TransactionRequest};
|
2020-09-20 15:17:02 +00:00
|
|
|
use types::LedgerError;
|
|
|
|
|
2020-10-08 15:56:36 +00:00
|
|
|
#[async_trait]
|
2020-09-20 15:17:02 +00:00
|
|
|
impl Signer for LedgerEthereum {
|
|
|
|
type Error = LedgerError;
|
|
|
|
|
|
|
|
/// Signs the hash of the provided message after prefixing it
|
|
|
|
async fn sign_message<S: Send + Sync + AsRef<[u8]>>(
|
|
|
|
&self,
|
|
|
|
message: S,
|
|
|
|
) -> Result<Signature, Self::Error> {
|
|
|
|
self.sign_message(message).await
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Signs the transaction
|
|
|
|
async fn sign_transaction(
|
|
|
|
&self,
|
2020-09-24 21:33:09 +00:00
|
|
|
message: &TransactionRequest,
|
|
|
|
) -> Result<Signature, Self::Error> {
|
2021-07-29 20:22:25 +00:00
|
|
|
self.sign_tx(message).await
|
2020-09-20 15:17:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the signer's Ethereum Address
|
2020-09-24 21:33:09 +00:00
|
|
|
fn address(&self) -> Address {
|
|
|
|
self.address
|
2020-09-20 15:17:02 +00:00
|
|
|
}
|
2021-07-29 20:22:25 +00:00
|
|
|
|
|
|
|
fn with_chain_id<T: Into<u64>>(mut self, chain_id: T) -> Self {
|
|
|
|
self.chain_id = chain_id.into();
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
fn chain_id(&self) -> u64 {
|
|
|
|
self.chain_id
|
|
|
|
}
|
2020-09-20 15:17:02 +00:00
|
|
|
}
|