encodeKey method
Overrides the base class method to encode a public key as a Neo (NEO) address using Base58 encoding.
This method encodes a public key as a Neo address using Base58 encoding. It expects a version byte as a keyword argument. The method validates the version argument, constructs the Neo address payload, and encodes it as a Base58 address. The result is returned as a String representing the Neo address.
Parameters:
- pubKey: The public key to be encoded as a Neo address in the form of a List
- kwargs: Optional keyword arguments with 'ver' for the version bytes.
Returns: A String representing the Base58-encoded Neo address derived from the provided public key.
Implementation
@override
String encodeKey(List<int> pubKey, [Map<String, dynamic> kwargs = const {}]) {
/// Validate the version argument.
AddrKeyValidator.validateAddressArgs<List<int>>(kwargs, "ver");
List<int> verBytes = kwargs["ver"];
/// Validate and get the Nist256p1 public key.
final pubKeyObj = AddrKeyValidator.validateAndGetNist256p1Key(pubKey);
/// Construct the Neo address payload.
List<int> payloadBytes = List<int>.from([
...NeoAddrConst.prefixByte,
...pubKeyObj.compressed,
...NeoAddrConst.suffixByte,
]);
/// Encode the payload as a Base58 address.
return Base58Encoder.checkEncode(
List<int>.from([...verBytes, ...QuickCrypto.hash160(payloadBytes)]));
}