encodeKey method
Encodes a public key into a blockchain address.
This method takes a public key in the form of a List
pubKey
: The public key to be encoded as a blockchain address.kwargs
: Optional keyword arguments for encoder-specific options.
Returns the blockchain address string representing the encoded public key.
Implementation
@override
String encodeKey(List<int> pubKey, [Map<String, dynamic> kwargs = const {}]) {
AddrKeyValidator.validateAddressArgs<int>(kwargs, "ss58_format");
try {
if (AddrKeyValidator.hasValidPubkeyBytes(
pubKey, EllipticCurveTypes.secp256k1)) {
return SubstrateSecp256k1AddrEncoder().encodeKey(pubKey, kwargs);
} else if (!AddrKeyValidator.hasValidPubkeyBytes(
pubKey, EllipticCurveTypes.sr25519)) {
return SubstrateEd25519AddrEncoder().encodeKey(pubKey, kwargs);
}
return SubstrateSr25519AddrEncoder().encodeKey(pubKey, kwargs);
} catch (e) {
throw const AddressConverterException(
"Invalid ed25519, secp256k1 or sr25519 public key bytes");
}
}