XRPL Keypairs Codec

Low-level functions for creating and using cryptographic keys with the XRP Ledger.

exception xrpl.core.keypairs.XRPLKeypairsException

Bases: XRPLException

General XRPL Keypair Codec Exception.

xrpl.core.keypairs.derive_classic_address(public_key: str) str

Derive the XRP Ledger classic address for a given public key. See Address Derivation for more information.

Parameters:

public_key – The public key to derive the address from, as hexadecimal.

Returns:

The classic address corresponding to the given public key.

xrpl.core.keypairs.derive_keypair(seed: str, validator: bool = False, algorithm: CryptoAlgorithm | None = None) Tuple[str, str]

Derive the public and private keys from a given seed value.

Parameters:
  • seed – Seed to derive the key pair from. Use generate_seed() to generate an appropriate value.

  • validator – Whether the keypair is a validator keypair.

  • algorithm – The algorithm used to encode the keys. Inferred from the seed if not included.

Returns:

A (public key, private key) pair derived from the given seed.

Raises:

XRPLKeypairsException – If the derived keypair did not generate a verifiable signature.

xrpl.core.keypairs.generate_seed(entropy: str | None = None, algorithm: CryptoAlgorithm = CryptoAlgorithm.ED25519) str

Generate a seed value that cryptographic keys can be derived from.

Parameters:
  • entropy – Hexadecimal string that is addresscodec.SEED_LENGTH bytes long

  • algorithm – CryptoAlgorithm to use for seed generation. The default is CryptoAlgorithm.ED25519.

Returns:

A seed value that can be used to derive a key pair with the given cryptographic algorithm.

Raises:

XRPLAddressCodecException – If entropy is not of length addresscodec.SEED_LENGTH, this exception will be thrown in addresscodec.encode_seed.

xrpl.core.keypairs.is_valid_message(message: bytes, signature: bytes, public_key: str) bool

Verifies the signature on a given message.

Parameters:
  • message – The message to validate.

  • signature – The signature of the message.

  • public_key – The public key to use to verify the message and signature.

Returns:

Whether the message is valid for the given signature and public key.

xrpl.core.keypairs.sign(message: str | bytes, private_key: str) str

Sign a message using a given private key.

Parameters:
  • message – The message to sign, as bytes.

  • private_key – The private key to use to sign the message.

Returns:

Signed message, as hexadecimal.