decodeAddr method
Overrides the base class method to decode a P2TR (Pay-to-Taproot) address.
This method decodes a P2TR address from the given input string using Bech32 encoding. It expects an optional map of keyword arguments, with the 'hrp' key specifying the Human-Readable Part (HRP) of the address. It validates the arguments, decodes the address, checks the witness version, and returns the decoded address as a List
Parameters:
- addr: The Bech32-encoded P2TR address to be decoded.
- kwargs: Optional keyword arguments, with 'hrp' for the Human-Readable Part.
Returns: A List
Throws:
- ArgumentException if the provided address has an incorrect witness version, or if the Bech32 checksum is invalid.
Implementation
@override
List<int> decodeAddr(String addr, [Map<String, dynamic> kwargs = const {}]) {
/// Validate address arguments and retrieve the Human-Readable Part (HRP).
AddrKeyValidator.validateAddressArgs<String>(kwargs, "hrp");
final String hrp = kwargs["hrp"];
/// Decode the Bech32-encoded P2TR address and validate its length.
final decode = SegwitBech32Decoder.decode(hrp, addr);
final witVerGot = decode.item1;
final addrDecBytes = decode.item2;
/// Validate the byte length of the decoded address.
AddrDecUtils.validateBytesLength(
addrDecBytes, EcdsaKeysConst.pubKeyCompressedByteLen - 1);
/// Check the witness version.
if (witVerGot != P2TRConst.witnessVer) {
throw AddressConverterException(
'Invalid witness version (expected ${P2TRConst.witnessVer}, got $witVerGot)');
}
/// Return the decoded P2TR address as a List<int>.
return addrDecBytes;
}