encodeKey method
Overrides the base class method to encode a public key as an ICON (ICX) address.
This method encodes a public key as an ICON address. It expects the public key as a List
- Validating and transforming the public key into a 32-byte hash.
- Truncating the hash to the required ICON address length.
- Adding the ICON address prefix to the hash.
Parameters:
- pubKey: The public key to be encoded as an ICON address in the form of a List
- kwargs: Optional keyword arguments (not used in this implementation).
Returns: A string representing the ICON (ICX) address corresponding to the provided public key.
Implementation
@override
String encodeKey(List<int> pubKey, [Map<String, dynamic> kwargs = const {}]) {
/// Validate and transform the public key into a 32-byte hash.
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 CoinsConf.icon.params.addrPrefix! +
BytesUtils.toHexString(pubKeyHashBytes);
}