encodeKey method

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

Overrides the base class method to encode a public key as a Nano address.

This method encodes a public key as a Nano address. It expects the public key as a List

  1. Validating and obtaining the Ed25519 Blake2b public key.
  2. Calculating the Nano address payload by appending padding, public key bytes, and checksum.
  3. Encoding the payload using a custom Nano Base32 alphabet.
  4. Prepending the Nano address prefix.

Parameters:

  • pubKey: The public key to be encoded as a Nano address in the form of a List
  • kwargs: Optional keyword arguments (not used in this implementation).

Returns: A string representing the Nano address corresponding to the provided public key.

Implementation

@override
String encodeKey(List<int> pubKey, [Map<String, dynamic> kwargs = const {}]) {
  /// Validate and obtain the Ed25519 Blake2b public key.
  final pubKeyObj = AddrKeyValidator.validateAndGetEd25519Blake2bKey(pubKey);

  /// Extract public key bytes and calculate the checksum.
  final pubKeyBytes = pubKeyObj.compressed.sublist(1);
  final checksumBytes = _NanoAddrUtils.computeChecksum(pubKeyBytes);

  /// Create the Nano address payload by combining padding, public key, and checksum.
  final payloadBytes = List<int>.from(
    [...NanoAddrConst.payloadPadDec, ...pubKeyBytes, ...checksumBytes],
  );

  /// Encode the payload using a custom Nano Base32 alphabet and prepend the Nano address prefix.
  final b32Enc = Base32Encoder.encodeNoPaddingBytes(
    payloadBytes,
    NanoAddrConst.base32Alphabet,
  );
  return CoinsConf.nano.params.addrPrefix! +
      b32Enc.substring(NanoAddrConst.payloadPadEnc.length);
}