encodeKey method

  1. @override
String encodeKey(
  1. List<int> pubKey, {
  2. List<int>? addrPrefix,
  3. int? tag,
})
override

Encodes the public key into a Ripple (XRP) X-Address.

Implementation

@override
String encodeKey(List<int> pubKey, {List<int>? addrPrefix, int? tag}) {
  addrPrefix = AddrKeyValidator.getAddrArg<List<int>>(
    addrPrefix,
    "addrPrefix",
  );

  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, addrPrefix, tag);
}