decodeAddr method
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:
- Validates and removes the Nano address prefix.
- Decodes the Base32-encoded payload, considering the custom Nano Base32 alphabet and padding.
- Validates the length of the decoded address.
- Splits the decoded address into its public key and checksum parts.
- 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;
}