Module 0xb::crypto
use 0x2::ecdsa_k1;
use 0x2::hash;
Function ecdsa_pub_key_to_eth_address
public(friend) fun ecdsa_pub_key_to_eth_address(compressed_pub_key: &vector<u8>): vector<u8>
Implementation
public(package) fun ecdsa_pub_key_to_eth_address(compressed_pub_key: &vector<u8>): vector<u8> {
// Decompress pub key
let decompressed = ecdsa_k1::decompress_pubkey(compressed_pub_key);
// Skip the first byte
let (mut i, mut decompressed_64) = (1, vector[]);
while (i < 65) {
decompressed_64.push_back(decompressed[i]);
i = i + 1;
};
// Hash
let hash = keccak256(&decompressed_64);
// Take last 20 bytes
let mut address = vector[];
let mut i = 12;
while (i < 32) {
address.push_back(hash[i]);
i = i + 1;
};
address
}
Feedback Form