encodeKey method

  1. @override
String encodeKey(
  1. List<int> pubKey, [
  2. Map<String, dynamic> kwargs = const {}
])
override

Encodes a Zilliqa blockchain address from a given public key.

This method takes a public key in the form of a List<int> and generates a Zilliqa blockchain address by following these steps:

  1. Validate and obtain a secp256k1 key object from the input public key.
  2. Calculate the SHA-256 hash of the compressed public key.
  3. Encode the Zilliqa blockchain address using Bech32 encoding.

Parameters:

  • pubKey: The public key to encode as a Zilliqa blockchain address.
  • kwargs: An optional map of keyword arguments, which is not used in this implementation.

Returns the Zilliqa blockchain address as a string.

Throws:

  • ArgumentException if the public key validation fails or if there is an issue with Bech32 encoding.

Implementation

@override
String encodeKey(List<int> pubKey, [Map<String, dynamic> kwargs = const {}]) {
  /// Validate the public key and obtain a secp256k1 key object.
  final pubKeyObj = AddrKeyValidator.validateAndGetSecp256k1Key(pubKey);

  /// Calculate the SHA-256 hash of the compressed public key.
  final keyHash = QuickCrypto.sha256Hash(pubKeyObj.compressed);

  /// Encode the Zilliqa blockchain address using Bech32 encoding.
  return Bech32Encoder.encode(CoinsConf.zilliqa.params.addrHrp!,
      keyHash.sublist(keyHash.length - ZilAddrConst.sha256ByteLen));
}