decodeAddr method

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

Blockchain address decoder for Ada Shelley staking addresses. This decoder is used to decode staking addresses based on network tag and address data.

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 address using the staking network tag's address prefix.
  final addrDecBytes = Bech32Decoder.decode(
      AdaShelleyAddrConst.networkTagToRewardAddrHrp[netTag]!, addr);

  /// Validate the length of the decoded bytes and remove the prefix.
  AddrDecUtils.validateBytesLength(
      addrDecBytes, QuickCrypto.blake2b224DigestSize + 1);

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

  /// Return the final decoded address by removing the prefix and converting it to bytes.
  return AddrDecUtils.validateAndRemovePrefixBytes(addrDecBytes, prefixByte);
}