Skip to main content

Module bridge::crypto

use sui::ecdsa_k1;
use sui::hash;

Function ecdsa_pub_key_to_eth_address

public(package) fun ecdsa_pub_key_to_eth_address(compressed_pub_key: &vector<u8>): vector<u8>
Click to open
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
}