encodeKey method
Overrides the base class method to encode a public key as an ICON (ICX) address.
Implementation
@override
String encodeKey(List<int> pubKey) {
/// Validate and transform the public key into a 32-byte hash.
final IPublicKey pubKeyObj = AddrKeyValidator.validateAndGetSecp256k1Key(
pubKey,
);
List<int> pubKeyHashBytes = QuickCrypto.sha3256Hash(
pubKeyObj.uncompressed.sublist(1),
);
/// Truncate the hash to the required ICON address length.
pubKeyHashBytes = pubKeyHashBytes.sublist(
pubKeyHashBytes.length - IcxAddrConst.keyHashByteLen,
);
/// Add the ICON address prefix to the hash.
return AddrKeyValidator.getConfigArg(
CoinsConf.icon.params.addrPrefix,
"addrPrefix",
) +
BytesUtils.toHexString(pubKeyHashBytes);
}