Function avalanche_types::hash::keccak256
source · Examples found in repository?
More examples
src/key/secp256k1/address.rs (line 10)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
pub fn eth_checksum(addr: &str) -> String {
let addr_lower_case = addr
.trim_start_matches(super::private_key::HEX_ENCODE_PREFIX)
.to_lowercase();
let digest_h256 = hash::keccak256(&addr_lower_case.as_bytes());
// this also works...
//
// addr_lower_case
// .chars()
// .enumerate()
// .map(|(i, c)| {
// if matches!(c, 'a' | 'b' | 'c' | 'd' | 'e' | 'f')
// && (digest_h256[i >> 1] & if i % 2 == 0 { 128 } else { 8 } != 0)
// {
// c.to_ascii_uppercase()
// } else {
// c
// }
// })
// .collect::<String>()
checksum_eip55(&addr_lower_case, &hex::encode(digest_h256))
}