feat: expose to_eip_155 (#111)
This commit is contained in:
parent
43dd8edb92
commit
75aa7f930b
|
@ -60,6 +60,18 @@ use async_trait::async_trait;
|
|||
use ethers_core::types::{Address, Signature, TransactionRequest};
|
||||
use std::error::Error;
|
||||
|
||||
/// Applies [EIP155](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md)
|
||||
pub fn to_eip155_v<T: Into<u8>>(recovery_id: T, chain_id: Option<u64>) -> u64 {
|
||||
let standard_v: u8 = recovery_id.into();
|
||||
if let Some(chain_id) = chain_id {
|
||||
// When signing with a chain ID, add chain replay protection.
|
||||
(standard_v as u64) + 35 + chain_id * 2
|
||||
} else {
|
||||
// Otherwise, convert to 'Electrum' notation.
|
||||
(standard_v as u64) + 27
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait for signing transactions and messages
|
||||
///
|
||||
/// Implement this trait to support different signing modes, e.g. Ledger, hosted etc.
|
||||
|
|
|
@ -4,13 +4,10 @@ mod private_key;
|
|||
#[cfg(feature = "yubihsm")]
|
||||
mod yubi;
|
||||
|
||||
use crate::Signer;
|
||||
use crate::{to_eip155_v, Signer};
|
||||
use ethers_core::{
|
||||
k256::{
|
||||
ecdsa::{
|
||||
recoverable::{Id as RecoveryId, Signature as RecoverableSignature},
|
||||
signature::DigestSigner,
|
||||
},
|
||||
ecdsa::{recoverable::Signature as RecoverableSignature, signature::DigestSigner},
|
||||
elliptic_curve::FieldBytes,
|
||||
Secp256k1,
|
||||
},
|
||||
|
@ -123,18 +120,6 @@ impl<D: DigestSigner<Sha256Proxy, RecoverableSignature>> Wallet<D> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Applies [EIP155](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md)
|
||||
fn to_eip155_v(recovery_id: RecoveryId, chain_id: Option<u64>) -> u64 {
|
||||
let standard_v: u8 = recovery_id.into();
|
||||
if let Some(chain_id) = chain_id {
|
||||
// When signing with a chain ID, add chain replay protection.
|
||||
(standard_v as u64) + 35 + chain_id * 2
|
||||
} else {
|
||||
// Otherwise, convert to 'Electrum' notation.
|
||||
(standard_v as u64) + 27
|
||||
}
|
||||
}
|
||||
|
||||
// do not log the signer
|
||||
impl<D: DigestSigner<Sha256Proxy, RecoverableSignature>> fmt::Debug for Wallet<D> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
|
|
Loading…
Reference in New Issue