encodeKey method
Encodes a public key into a Substrate address.
This method takes a public key as a List
Parameters:
- pubKey: The public key to be encoded as a Substrate address.
- kwargs: Optional keyword arguments (e.g., 'ss58_format') for customization.
Returns: A String representing the Substrate address encoded from the provided public key.
Throws:
- FormatException if the provided SS58 format is invalid or if the public key is not a valid sr25519 key.
Implementation
@override
String encodeKey(List<int> pubKey, [Map<String, dynamic> kwargs = const {}]) {
AddrKeyValidator.validateAddressArgs<int>(kwargs, "ss58_format");
final int ss58Format = kwargs["ss58_format"];
List<int> pubBytes = pubKey;
try {
AddrKeyValidator.validateAndGetSr25519Key(pubBytes);
} catch (e) {
final pub = AddrKeyValidator.validateAndGetEd25519Key(pubKey);
pubBytes = pub.compressed.sublist(1);
}
return SS58Encoder.encode(pubBytes, ss58Format);
}