decodeAddr method
Decodes a Tezos (XTZ) blockchain address from its string representation to its byte data.
This method takes an encoded Tezos address string and optional keyword arguments, including the "prefix" specifying the address prefix to use for decoding. It validates and decodes the given address, removing the specified prefix and returning the decoded byte data.
Throws an exception if the address is not in the expected format or if the prefix is invalid.
Parameters:
addr
: The encoded Tezos address as a string.kwargs
: Optional keyword arguments, including "prefix" to specify the address prefix.
Returns: A List<int> containing the decoded byte data of the Tezos address.
Example usage:
final decoder = XtzAddrDecoder();
final encodedAddress = "tz1abc123...";
final decodedAddress = decoder.decodeAddr(encodedAddress, {"prefix": XtzAddrPrefixes.tz1});
Implementation
@override
List<int> decodeAddr(String addr, [Map<String, dynamic> kwargs = const {}]) {
/// Validate and retrieve the address prefix from the keyword arguments.
AddrKeyValidator.validateAddressArgs<XtzAddrPrefixes>(kwargs, "prefix");
final XtzAddrPrefixes prefix = kwargs["prefix"];
/// Decode the base58 address into bytes.
final addrDecBytes = Base58Decoder.checkDecode(addr);
/// Validate the length of the decoded address and remove the prefix bytes.
AddrDecUtils.validateBytesLength(addrDecBytes, prefix.value.length + 20);
final blakeBytes =
AddrDecUtils.validateAndRemovePrefixBytes(addrDecBytes, prefix.value);
return List<int>.from(blakeBytes);
}