# https://github.com/q9f/eth.rb/blob/main/lib/eth/util.rb#L29
#
# Generates an Ethereum address from a given compressed or
# uncompressed binary or hexadecimal public key string.
#
# @param str [String] the public key to be converted.
# @return [Eth::Address] an Ethereum address.
def public_key_to_address(str)
str = hex_to_bin str if hex? str
bytes = keccak256(str[1..-1])[-20..-1]
Address.new bin_to_prefixed_hex bytes
end
It seems that it doesn't handle the compressed public key right.
The original code
It seems that it doesn't handle the compressed public key right.
Example:
Maybe we can fix it like this:
ref: https://github.com/etscrivner/rbsecp256k1/blob/master/documentation/public_key.md#from_datapublic_key_data