encodeKey method
Overrides the base class method to encode a public key as a P2PKH (Pay-to-Public-Key-Hash) address using bch Bech32 encoding.
This method encodes a public key as a P2PKH address using Bech32 encoding. It expects an optional map of keyword arguments with 'net_ver' specifying the network version bytes and 'hrp' for the Human-Readable Part (HRP). It validates the arguments, processes the public key as a Secp256k1 key, generates a hash160 of the compressed public key, and encodes it as a P2PKH address using Bech32.
Parameters:
- pubKey: The public key to be encoded as a P2PKH address.
- kwargs: Optional keyword arguments with 'net_ver' for the network version and 'hrp' for HRP.
Returns: A String representing the Bech32-encoded P2PKH address derived from the provided public key.
Implementation
@override
String encodeKey(List<int> pubKey, [Map<String, dynamic> kwargs = const {}]) {
/// Validate network version and HRP arguments.
AddrKeyValidator.validateAddressArgs<List<int>>(kwargs, "net_ver");
AddrKeyValidator.validateAddressArgs<String>(kwargs, "hrp");
String hrp = kwargs['hrp'];
List<int> netVerBytes = kwargs['net_ver'];
/// Validate and process the public key as a Secp256k1 key.
final pubKeyObj = AddrKeyValidator.validateAndGetSecp256k1Key(pubKey);
// Generate the hash160 of the compressed public key.
final pubkeyHash = QuickCrypto.hash160(pubKeyObj.compressed);
/// Encode the P2PKH address using Bech32 encoding.
return BchBech32Encoder.encode(
hrp,
netVerBytes,
pubkeyHash,
);
}