pub struct EthereumSignature {
pub expected_address: String,
pub signed_message: String,
pub signature: String,
}
impl EthereumSignature {
pub fn new(expected_address: String, signed_message: String, signature: String) -> Self {
Self { expected_address, signed_message, signature }
}
pub fn verify(&self) -> Result<bool, String> {
use ethers::core::types::{Address, Signature};
use ethers::utils::hash_message;
use std::str::FromStr;
let signature = Signature::from_str(&self.signature).map_err(|e| e.to_string())?;
let expected_address = Address::from_str(&self.expected_address).map_err(|e| e.to_string())?;
let message_hash = hash_message(&self.signed_message);
let recovered_address = signature.recover(message_hash).map_err(|e| e.to_string())?;
Ok(recovered_address == expected_address)
}
}