pub struct EthereumSigner { /* private fields */ }Expand description
Ethereum ECDSA signer.
Wraps a secp256k1 SigningKey and applies Keccak-256 hashing,
EIP-2 Low-S normalization, and recovery ID calculation.
Implementations§
Source§impl EthereumSigner
impl EthereumSigner
Sourcepub fn address(&self) -> [u8; 20]
pub fn address(&self) -> [u8; 20]
Derive the Ethereum address from this signer’s public key. Returns the 20-byte address (last 20 bytes of keccak256(uncompressed_pubkey[1..])).
Sourcepub fn sign_typed_data(
&self,
domain_separator: &[u8; 32],
struct_hash: &[u8; 32],
) -> Result<EthereumSignature, SignerError>
pub fn sign_typed_data( &self, domain_separator: &[u8; 32], struct_hash: &[u8; 32], ) -> Result<EthereumSignature, SignerError>
EIP-712: Sign typed structured data.
Computes keccak256("\x19\x01" || domain_separator || struct_hash) and signs it.
domain_separator: 32-byte keccak256 hash of the EIP-712 domain (seeEip712Domain::separator).struct_hash: 32-byte keccak256 hash of the typed struct (computed by the caller).
Sourcepub fn personal_sign(
&self,
message: &[u8],
) -> Result<EthereumSignature, SignerError>
pub fn personal_sign( &self, message: &[u8], ) -> Result<EthereumSignature, SignerError>
EIP-191: Sign a personal message (as used by MetaMask personal_sign).
Computes keccak256("\x19Ethereum Signed Message:\n{len}{message}") and signs it.
This is the standard for off-chain message signing in Ethereum wallets.
Sourcepub fn sign_with_chain_id(
&self,
message: &[u8],
chain_id: u64,
) -> Result<EthereumSignature, SignerError>
pub fn sign_with_chain_id( &self, message: &[u8], chain_id: u64, ) -> Result<EthereumSignature, SignerError>
EIP-155: Sign a message with chain-specific replay protection.
Produces v = {0,1} + chain_id * 2 + 35 instead of v = 27/28.
This is required for mainnet Ethereum transactions since the Spurious Dragon fork.
Common chain IDs: 1 (mainnet), 5 (Goerli), 11155111 (Sepolia), 137 (Polygon).
Sourcepub fn sign_digest_with_chain_id(
&self,
digest: &[u8; 32],
chain_id: u64,
) -> Result<EthereumSignature, SignerError>
pub fn sign_digest_with_chain_id( &self, digest: &[u8; 32], chain_id: u64, ) -> Result<EthereumSignature, SignerError>
EIP-155: Sign a pre-hashed digest with chain-specific replay protection.
Sourcepub fn personal_sign_with_chain_id(
&self,
message: &[u8],
chain_id: u64,
) -> Result<EthereumSignature, SignerError>
pub fn personal_sign_with_chain_id( &self, message: &[u8], chain_id: u64, ) -> Result<EthereumSignature, SignerError>
EIP-191: Sign a personal message with chain-specific v value.
Sourcepub fn address_checksum(&self) -> String
pub fn address_checksum(&self) -> String
Return the EIP-55 checksummed hex address string (e.g., 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B).
Sourcepub fn from_mnemonic(
phrase: &str,
passphrase: &str,
index: u32,
) -> Result<Self, SignerError>
pub fn from_mnemonic( phrase: &str, passphrase: &str, index: u32, ) -> Result<Self, SignerError>
Create an EthereumSigner from a BIP-39 mnemonic phrase.
Uses the standard Ethereum HD derivation path m/44'/60'/0'/0/{index}.
§Arguments
phrase— BIP-39 mnemonic words (12 or 24 words)passphrase— Optional BIP-39 passphrase (empty string for none)index— Account index (0 for the first account)
§Example
use chains_sdk::ethereum::EthereumSigner;
let signer = EthereumSigner::from_mnemonic(
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about",
"",
0,
).unwrap();
println!("Address: {}", signer.address_checksum());Trait Implementations§
Source§impl Drop for EthereumSigner
impl Drop for EthereumSigner
Source§impl KeyPair for EthereumSigner
impl KeyPair for EthereumSigner
Source§fn generate() -> Result<Self, SignerError>
fn generate() -> Result<Self, SignerError>
Source§fn from_bytes(private_key: &[u8]) -> Result<Self, SignerError>
fn from_bytes(private_key: &[u8]) -> Result<Self, SignerError>
Source§fn private_key_bytes(&self) -> Zeroizing<Vec<u8>>
fn private_key_bytes(&self) -> Zeroizing<Vec<u8>>
Zeroizing<Vec<u8>> will scrub the memory on drop.Source§impl Signer for EthereumSigner
impl Signer for EthereumSigner
Source§type Signature = EthereumSignature
type Signature = EthereumSignature
Source§type Error = SignerError
type Error = SignerError
Source§fn sign(&self, message: &[u8]) -> Result<EthereumSignature, SignerError>
fn sign(&self, message: &[u8]) -> Result<EthereumSignature, SignerError>
Source§fn sign_prehashed(
&self,
digest: &[u8],
) -> Result<EthereumSignature, SignerError>
fn sign_prehashed( &self, digest: &[u8], ) -> Result<EthereumSignature, SignerError>
InvalidHashLength if the digest
length doesn’t match the expected hash output size.