decodeAddr method

  1. @override
List<int> decodeAddr(
  1. String addr, [
  2. Map<String, dynamic> kwargs = const {}
])
override

Blockchain address decoder for Ada Shelley addresses. This decoder is used to decode payment addresses based on the network tag and address format.

Implementation

@override
List<int> decodeAddr(String addr, [Map<String, dynamic> kwargs = const {}]) {
  /// Determine the network tag, defaulting to mainnet if not specified.
  final netTag = kwargs["net_tag"] ?? ADANetwork.mainnet;

  /// Check if the provided network tag is a valid enum value.
  if (netTag is! ADANetwork) {
    throw const AddressConverterException(
        'Address type is not an enumerative of ADANetwork');
  }

  // Decode the provided Bech32 address.
  final addrDecBytes = Bech32Decoder.decode(
      AdaShelleyAddrConst.networkTagToAddrHrp[netTag]!, addr);

  /// Validate the byte length of the decoded address.
  AddrDecUtils.validateBytesLength(
      addrDecBytes, (QuickCrypto.blake2b224DigestSize * 2) + 1);

  /// Encode the address prefix based on the payment header type and network tag.
  final prefixByte = AdaShelleyAddrUtils.encodePrefix(ADAAddressType.base,
      netTag.value, AdaShelleyAddrUtils.decodeCred(addrDecBytes[0], 4),
      stakeType: AdaShelleyAddrUtils.decodeCred(addrDecBytes[0], 5));
  return AddrDecUtils.validateAndRemovePrefixBytes(addrDecBytes, prefixByte);
}