encodeKey method
Encodes a public key as an Ethereum address.
This method takes a public key in the form of a List<int>
and converts it
into an Ethereum address as a string. It includes an option to skip
checksum encoding if specified.
Parameters:
- pubKey: The public key in a
List<int>
format to be encoded. - kwargs: Optional keyword arguments (e.g., skip_chksum_enc) for additional configuration.
Returns: A string representing the Ethereum address.
Implementation
@override
String encodeKey(List<int> pubKey, [Map<String, dynamic> kwargs = const {}]) {
final IPublicKey pubKeyObj =
AddrKeyValidator.validateAndGetSecp256k1Key(pubKey);
final skipChecksum = kwargs["skip_chksum_enc"] ?? false;
final String kekkakHex = BytesUtils.toHexString(
QuickCrypto.keccack256Hash(pubKeyObj.uncompressed.sublist(1)));
final String addr = kekkakHex.substring(EthAddrConst.startByte);
if (skipChecksum) {
return addr;
}
return CoinsConf.ethereum.params.addrPrefix! +
EthAddrUtils._checksumEncode(addr);
}