decodeAddr method

  1. @override
List<int> decodeAddr(
  1. String addr, {
  2. ADANetwork network = ADANetwork.mainnet,
})
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, {ADANetwork network = ADANetwork.mainnet}) {
  /// Decode the provided address using the staking network tag's address prefix.
  final addrDecBytes = Bech32Decoder.decode(
    AdaShelleyAddrUtils.getRewardAddressHrp(network),
    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,
    network.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);
}