encodeKey method
Encodes the public key into a Ripple (XRP) X-Address.
This method encodes the given public key into a Ripple address using the specified network prefix and, optionally, a tag.
pubKey
The public key to be encoded.
kwargs
An optional map of keyword arguments, such as "prefix" for the address prefix and "tag" for an optional tag.
returns The encoded Ripple address as a string.
Implementation
@override
String encodeKey(List<int> pubKey, [Map<String, dynamic> kwargs = const {}]) {
/// Validate network version, Base58 alphabet, and public key mode arguments.
final prefix =
AddrKeyValidator.validateAddressArgs<List<int>>(kwargs, "prefix");
int? tag;
if (kwargs.containsKey("tag")) {
tag = AddrKeyValidator.validateAddressArgs<int>(kwargs, "tag");
}
List<int> pubKeyBytes;
try {
/// Validate and process the public key as a Secp256k1 key.
pubKeyBytes =
AddrKeyValidator.validateAndGetSecp256k1Key(pubKey).compressed;
} catch (e) {
AddrKeyValidator.validateAndGetEd25519Key(pubKey);
pubKeyBytes = pubKey;
}
/// Calculate the hash160 of the public key.
final hash160 = QuickCrypto.hash160(pubKeyBytes);
return XRPAddressUtils.hashToXAddress(hash160, prefix, tag);
}