decodeAddr method
Overrides the base class method to decode a P2PKH (Pay-to-Public-Key-Hash) address using bch Bech32 encoding.
Implementation
@override
List<int> decodeAddr(String addr, {List<int>? netVersion, String? hrp}) {
hrp = AddrKeyValidator.getAddrArg<String>(hrp, "hrp");
netVersion = AddrKeyValidator.getAddrArg<List<int>>(
netVersion,
"netVersion",
);
/// Decode the Bech32 address and retrieve network version and decoded bytes.
final result = BchBech32Decoder.decode(hrp, addr);
final List<int> netVerBytesGot = result.$1;
final List<int> addrDecBytes = result.$2;
/// Validate that the decoded network version matches the expected network version.
if (!BytesUtils.bytesEqual(netVersion, netVerBytesGot)) {
throw AddressConverterException.addressKeyValidationFailed(
reason: "Invalid address checksum.",
);
}
/// Validate the length of the decoded address.
AddrDecUtils.validateBytesLength(
addrDecBytes,
QuickCrypto.hash160DigestSize,
);
return addrDecBytes;
}