encodeKey method
Encodes a Ripple (XRP) public key as a blockchain address.
This method takes a public key represented as a List<int> and optional keyword arguments, including "net_ver" specifying the network version byte and "base58_alph" specifying the Base58 alphabet to use for encoding. It delegates the encoding process to the P2PKHAddrEncoder class, providing the necessary parameters. The resulting Ripple address is returned as a string.
Parameters:
pubKey
: The public key to encode as a Ripple address.kwargs
: Optional keyword arguments, including "net_ver" and "base58_alph" settings.
Returns: A Ripple address string representing the encoded public key.
Example usage:
final encoder = XrpAddrEncoder();
final publicKey = List<int>.from([/* public key bytes */]);
final rippleAddress = encoder.encodeKey(publicKey);
Implementation
@override
String encodeKey(List<int> pubKey, [Map<String, dynamic> kwargs = const {}]) {
var publicType = kwargs["curve_type"] ?? EllipticCurveTypes.secp256k1;
if (publicType is! EllipticCurveTypes ||
(publicType != EllipticCurveTypes.secp256k1 &&
publicType != EllipticCurveTypes.ed25519)) {
throw const AddressConverterException(
'Missing required parameters: curve_type, curvetype must be EllipticCurveTypes.secp256k1 or EllipticCurveTypes.ed25519');
}
if (publicType == EllipticCurveTypes.secp256k1) {
return P2PKHAddrEncoder().encodeKey(pubKey, {
"net_ver": CoinsConf.ripple.params.p2pkhNetVer!,
"base58_alph": Base58Alphabets.ripple,
});
}
AddrKeyValidator.validateAndGetEd25519Key(pubKey);
return XRPAddressUtils._toAddress(pubKey);
}