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 + 1,
      minLength: QuickCrypto.blake2b224DigestSize + 4);

  /// validate pointer data
  Pointer.fromBytes(
      addrDecBytes.sublist(QuickCrypto.blake2b224DigestSize + 1));

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