Appendix : Codebase Navigation Guide
Introduction
This appendix provides a comprehensive guide to navigating rippled's cryptographic code. You'll learn where to find specific implementations, how files are organized, and which functions are most important to understand.
Directory Structure
rippled/
├── include/xrpl/ # Public headers
│ ├── protocol/
│ │ ├── SecretKey.h # Secret key class
│ │ ├── PublicKey.h # Public key class
│ │ ├── digest.h # Hash functions
│ │ ├── KeyType.h # Key type enumeration
│ │ └── AccountID.h # Account identifier
│ └── crypto/
│ ├── csprng.h # CSPRNG interface
│ └── secure_erase.h # Secure memory erasure
│
├── src/libxrpl/ # Core library implementation
│ ├── protocol/
│ │ ├── SecretKey.cpp # Key generation, signing (404 lines)
│ │ ├── PublicKey.cpp # Verification, canonicality (328 lines)
│ │ ├── digest.cpp # Hash implementations (109 lines)
│ │ ├── AccountID.cpp # Account ID utilities
│ │ └── tokens.cpp # Base58 encoding/decoding
│ ├── crypto/
│ │ ├── csprng.cpp # CSPRNG implementation (110 lines)
│ │ ├── secure_erase.cpp # Memory wiping (35 lines)
│ │ └── RFC1751.cpp # Mnemonic words
│ └── basics/
│ └── make_SSLContext.cpp # SSL/TLS configuration
│
└── src/xrpld/ # Daemon-specific code
├── app/tx/impl/
│ └── Transactor.cpp # Transaction signature validation
├── app/ledger/
│ └── LedgerMaster.cpp # Ledger management
└── overlay/detail/
└── Handshake.cpp # Peer cryptographic handshakeCore Cryptographic Files
1. SecretKey.cpp (404 lines)
Location: src/libxrpl/protocol/SecretKey.cpp
Key functions:
Navigate to:
Line ~50:
randomSecretKey()implementationLine ~100:
generateKeyPair()for secp256k1Line ~150:
generateKeyPair()for ed25519Line ~200:
derivePublicKey()implementationsLine ~300:
sign()function
2. PublicKey.cpp (328 lines)
Location: src/libxrpl/protocol/PublicKey.cpp
Key functions:
Navigate to:
Line ~50:
verify()functionLine ~120:
verifyDigest()for secp256k1Line ~180: Ed25519 verification
Line ~240:
ecdsaCanonicality()implementation
3. digest.cpp (109 lines)
Location: src/libxrpl/protocol/digest.cpp
Key implementations:
Navigate to:
Line ~20:
sha512_half_hasherclassLine ~50:
ripesha_hasherclassLine ~80: Utility functions
4. csprng.cpp (110 lines)
Location: src/libxrpl/crypto/csprng.cpp
Key implementation:
Navigate to:
Line ~30:
csprng_engineclass definitionLine ~50: Constructor (entropy initialization)
Line ~70:
operator()(random byte generation)Line ~90:
mix_entropy()(additional entropy)
5. tokens.cpp
Location: src/libxrpl/protocol/tokens.cpp
Key functions:
Finding Specific Functionality
"Where is...?"
Key generation:
Signing:
Verification:
Hashing:
Random numbers:
Address encoding:
Transaction signing:
Peer handshake:
Navigation by Task
Task: Understanding Ed25519 Signing
Start at
src/libxrpl/protocol/SecretKey.cpp:sign()Find Ed25519 case in switch statement
See call to
ed25519_sign()Note: External library (ed25519-donna)
Implementation in
src/ed25519-donna/
Task: Understanding Secp256k1 Verification
Start at
src/libxrpl/protocol/PublicKey.cpp:verify()Find secp256k1 case
Follow to
verifyDigest()See canonicality check:
ecdsaCanonicality()See secp256k1 library calls:
secp256k1_ecdsa_verify()Implementation in
src/secp256k1/
Task: Understanding Address Generation
Start at
src/libxrpl/protocol/AccountID.cpp:calcAccountID()See RIPESHA hash:
ripesha_hasherImplementation in
src/libxrpl/protocol/digest.cppDouble hash: SHA-256 then RIPEMD-160
Encoding:
src/libxrpl/protocol/tokens.cpp:encodeBase58Token()
Header vs Implementation
When to read headers:
When to read implementation:
Search Patterns
Using grep to find code:
Using git blame:
Using tags/symbols:
Common Code Patterns
RAII Pattern:
Error Handling Pattern:
Key Type Detection Pattern:
Quick Reference
File → Purpose Mapping
SecretKey.cpp
Key management, signing
randomSecretKey(), sign()
PublicKey.cpp
Verification
verify(), ecdsaCanonicality()
digest.cpp
Hashing
sha512Half(), RIPESHA
csprng.cpp
Random generation
crypto_prng()
tokens.cpp
Base58 encoding
encodeBase58Token()
Handshake.cpp
Peer authentication
makeSharedValue()
STTx.cpp
Transaction signing
STTx::sign(), STTx::checkSign()
Tips for Code Reading
Start with tests: Look in
src/test/for usage examplesFollow the data: Track how data flows through functions
Read comments: rippled has good documentation in code
Use a debugger: Step through code to understand flow
Check git history: See why code was written that way
Ask questions: rippled has active developer community
Last updated

