decodeAddr method

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

Overrides the base class method to decode a Nano (NANO) address.

This method decodes a Nano address from the provided input string. It expects an optional map of keyword arguments for custom Nano address parameters. The method performs the following steps:

  1. Validates and removes the Nano address prefix.
  2. Decodes the Base32-encoded payload, considering the custom Nano Base32 alphabet and padding.
  3. Validates the length of the decoded address.
  4. Splits the decoded address into its public key and checksum parts.
  5. Validates the address checksum.

Parameters:

  • addr: The Nano address to be decoded as a string.
  • kwargs: Optional keyword arguments for custom Nano address parameters.

Returns: A List

Implementation

@override
List<int> decodeAddr(String addr, [Map<String, dynamic> kwargs = const {}]) {
  /// Validate and remove the Nano address prefix.
  final addrNoPrefix = AddrDecUtils.validateAndRemovePrefix(
      addr, CoinsConf.nano.params.addrPrefix!);

  /// Decode the Base32-encoded payload using the custom Nano Base32 alphabet and padding.
  final addrDecBytes = Base32Decoder.decode(
    NanoAddrConst.payloadPadEnc + addrNoPrefix,
    NanoAddrConst.base32Alphabet,
  );

  /// Validate the length of the decoded address.
  AddrDecUtils.validateBytesLength(
    addrDecBytes,
    Ed25519KeysConst.pubKeyByteLen +
        QuickCrypto.blake2b40DigestSize +
        NanoAddrConst.payloadPadDec.length,
  );

  /// Split the decoded address into its public key and checksum parts.
  final decode = AddrDecUtils.splitPartsByChecksum(
    addrDecBytes.sublist(NanoAddrConst.payloadPadDec.length),
    QuickCrypto.blake2b40DigestSize,
  );

  /// Retrieve the public key bytes and checksum bytes.
  final pubKeyBytes = decode.item1;
  final checksumBytes = decode.item2;

  /// Validate the address checksum using the computed checksum function.
  AddrDecUtils.validateChecksum(
    pubKeyBytes,
    checksumBytes,
    _NanoAddrUtils.computeChecksum,
  );

  return pubKeyBytes;
}