XRPL Keypairs Codec¶
Low-level functions for creating and using cryptographic keys with the XRP Ledger.
-
exception
xrpl.core.keypairs.
XRPLKeypairsException
¶ Bases:
xrpl.constants.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) → 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.
- 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: Optional[str] = None, algorithm: xrpl.constants.CryptoAlgorithm = <CryptoAlgorithm.ED25519: 'ed25519'>) → str¶ Generate a seed value that cryptographic keys can be derived from.
- Parameters
entropy – Must be at least addresscodec.SEED_LENGTH bytes long and will be truncated to that length
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.
-
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: 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.