Function clarity::utils::get_ethereum_msg_hash
source · pub fn get_ethereum_msg_hash(data: &[u8]) -> Vec<u8>
Expand description
Takes a signature payload of arbitrary size and creates a proper payload for an ethereum_msg signature.
Internally this means Keccak256
hashing the data, appending the Ethereum signed
msg constant, then hashing it again.
This is how you would verify the data from sign_ethereum_msg
§Example
use clarity::PrivateKey;
use clarity::utils::get_ethereum_msg_hash;
let private_key : PrivateKey = "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f1e".parse().unwrap();
let signature = private_key.sign_ethereum_msg("Hello, world!".as_bytes());
// on the other side verifying the signature
let hash = get_ethereum_msg_hash("Hello, world!".as_bytes());
assert_eq!(signature.recover(&hash).unwrap(), private_key.to_address());