decodeAddr method
Overrides the base class method to decode a P2PKH (Pay-to-Public-Key-Hash) address using bch Bech32 encoding.
This method decodes a P2PKH address from the provided input string 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, decodes the Bech32 address, checks its network version, length, and checksum, and returns the decoded P2PKH address as a List
Parameters:
- addr: The Bech32-encoded P2PKH address to be decoded.
- kwargs: Optional keyword arguments with 'net_ver' for the network version and 'hrp' for HRP.
Returns: A List
Implementation
@override
List<int> decodeAddr(String addr, [Map<String, dynamic> kwargs = const {}]) {
/// Validate network version and HRP arguments.
AddrKeyValidator.validateAddressArgs<List<int>>(kwargs, "net_ver");
AddrKeyValidator.validateAddressArgs<String>(kwargs, "hrp");
final String hrp = kwargs["hrp"];
final List<int> netVerBytes = kwargs["net_ver"];
/// Decode the Bech32 address and retrieve network version and decoded bytes.
final result = BchBech32Decoder.decode(hrp, addr);
List<int> netVerBytesGot = result.item1;
List<int> addrDecBytes = result.item2;
/// Validate that the decoded network version matches the expected network version.
if (!BytesUtils.bytesEqual(netVerBytes, netVerBytesGot)) {
throw const AddressConverterException("Invalid net version");
}
/// Validate the length of the decoded address.
AddrDecUtils.validateBytesLength(
addrDecBytes, QuickCrypto.hash160DigestSize);
return addrDecBytes;
}