encodeKey method
Overrides the base class method to encode a public key as a P2WPKH address.
Implementation
@override
String encodeKey(List<int> pubKey, {String? hrp}) {
hrp = AddrKeyValidator.getAddrArg<String>(hrp, "hrp");
/// Validate and process the public key as a Secp256k1 key.
final pubKeyObj = AddrKeyValidator.validateAndGetSecp256k1Key(pubKey);
/// Set the witness version and obtain the public key bytes.
const witnessVer = P2WPKHAddrConst.witnessVer;
final pubKeyBytes = pubKeyObj.compressed;
/// Encode the processed public key as a P2WPKH address using Bech32.
return SegwitBech32Encoder.encode(
hrp,
witnessVer,
QuickCrypto.hash160(pubKeyBytes),
);
}