encodeKey method
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
- Validating and obtaining the Ed25519 Blake2b public key.
- Calculating the Nano address payload by appending padding, public key bytes, and checksum.
- Encoding the payload using a custom Nano Base32 alphabet.
- 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);
}