ethers-rs/ethers/examples/sign.rs

18 lines
463 B
Rust
Raw Normal View History

use ethers::prelude::*;
2020-05-24 16:14:27 +00:00
fn main() {
let message = "Some data";
2020-06-02 10:58:48 +00:00
let wallet = Wallet::new(&mut rand::thread_rng());
2020-05-24 16:14:27 +00:00
// sign a message
let signature = wallet.sign_message(message);
println!("Produced signature {}", signature);
// recover the address that signed it
let recovered = signature.recover(message).unwrap();
assert_eq!(recovered, wallet.address);
println!("Verified signature produced by {:?}!", wallet.address);
}