Key Generation Pipeline
Introduction
The Two Paths to Key Generation
Path 1: Random Generation
crypto_prng() → SecretKey → PublicKey → AccountID
(Used for: New accounts, one-time keys)
Path 2: Deterministic Generation
Seed → SecretKey → PublicKey → AccountID
(Used for: Wallet recovery, multiple accounts from one seed)Random Key Generation
The Simple Case: randomSecretKey()
randomSecretKey()// From src/libxrpl/protocol/SecretKey.cpp
SecretKey randomSecretKey()
{
std::uint8_t buf[32];
beast::rngfill(buf, sizeof(buf), crypto_prng());
SecretKey sk(Slice{buf, sizeof(buf)});
secure_erase(buf, sizeof(buf));
return sk;
}Why 32 Bytes?
Generating a Complete Key Pair
Deterministic Key Generation from Seeds
What is a Seed?
Generating Keys from Seeds: The Interface
Ed25519: Simple Derivation
Secp256k1: Complex Derivation
The Generator Class
Deriving the Root Key
Public Key Derivation
For Secp256k1
For Ed25519
Account ID Generation
RIPESHA: Double Hashing
Address Encoding
Complete Key Generation Examples
Example 1: Random Ed25519 Key
Example 2: Deterministic Secp256k1 Key
Example 3: Multiple Accounts from One Seed
Key Type Detection
Public Key Type Detection
Automatic Algorithm Selection
The secp256k1 Context
Security Considerations
Secret Key Storage
Key Validation
Seed Protection
Performance Characteristics
Key Generation Speed
Caching Considerations
Summary
Last updated

