A simple, no-frills ECDSA verifier for Ethereum signatures in Rust.
This crate allows you to verify Ethereum ECDSA signatures against known Ethereum addresses using the standard signing prefix and recovery method. It's ideal for validating signatures produced by wallets like MetaMask.
- Verifies Ethereum-style ECDSA signatures (
0x...
format). - Recovers Ethereum addresses from message + signature.
- Implements Ethereum's signed message prefix and Keccak256 hashing.
- Fully tested with
libsecp256k1
.
Add this crate to your Cargo.toml
:
[dependencies]
eth-ecdsa-verifier = "0.1.0"
Note: You will also need
libsecp256k1
andeasy-hasher
dependencies (these are re-exported).
use eth_ecdsa_verifier::validate_ecdsa_signature;
fn main() {
let message = "4RvWUp3E9YerY78Kn5UyyEQPTiFs0tIr/mhAeCbwIpY=".to_string();
let address = "0xd1798d6b74ef965d6a60f45e0036f44aed3dfa1b".to_string();
let signature = "0x88bd1f104e132178aea55731be455a5c91b3e15b46f2599e9472d926270d458f4116eea0273fb5dc36238992154afc652aa7c1d91569b596db00146b4e5443fa1b".to_string();
let is_valid = validate_ecdsa_signature(&signature, &message, &address)
.expect("Validation failed");
println!("Is signature valid? {}", is_valid);
}
- Hashes the message using Ethereum’s prefix:
"\x19Ethereum Signed Message:\n" + message.length + message
- Computes Keccak256 of the prefixed message.
- Recovers the public key from the signature using
libsecp256k1
. - Hashes the uncompressed public key (excluding 0x04 prefix) and extracts the last 20 bytes to get the address.
- Compares the recovered address with the given one.
Run:
cargo test
This project is licensed under the MIT License - see the LICENSE file for details.