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 handshake

Core Cryptographic Files

1. SecretKey.cpp (404 lines)

Location: src/libxrpl/protocol/SecretKey.cpp

Key functions:

Navigate to:

  • Line ~50: randomSecretKey() implementation

  • Line ~100: generateKeyPair() for secp256k1

  • Line ~150: generateKeyPair() for ed25519

  • Line ~200: derivePublicKey() implementations

  • Line ~300: sign() function

2. PublicKey.cpp (328 lines)

Location: src/libxrpl/protocol/PublicKey.cpp

Key functions:

Navigate to:

  • Line ~50: verify() function

  • Line ~120: verifyDigest() for secp256k1

  • Line ~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_hasher class

  • Line ~50: ripesha_hasher class

  • Line ~80: Utility functions

4. csprng.cpp (110 lines)

Location: src/libxrpl/crypto/csprng.cpp

Key implementation:

Navigate to:

  • Line ~30: csprng_engine class definition

  • Line ~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:

Task: Understanding Ed25519 Signing

  1. Start at src/libxrpl/protocol/SecretKey.cpp:sign()

  2. Find Ed25519 case in switch statement

  3. See call to ed25519_sign()

  4. Note: External library (ed25519-donna)

  5. Implementation in src/ed25519-donna/

Task: Understanding Secp256k1 Verification

  1. Start at src/libxrpl/protocol/PublicKey.cpp:verify()

  2. Find secp256k1 case

  3. Follow to verifyDigest()

  4. See canonicality check: ecdsaCanonicality()

  5. See secp256k1 library calls: secp256k1_ecdsa_verify()

  6. Implementation in src/secp256k1/

Task: Understanding Address Generation

  1. Start at src/libxrpl/protocol/AccountID.cpp:calcAccountID()

  2. See RIPESHA hash: ripesha_hasher

  3. Implementation in src/libxrpl/protocol/digest.cpp

  4. Double hash: SHA-256 then RIPEMD-160

  5. 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

File
Purpose
Key Functions

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

  1. Start with tests: Look in src/test/ for usage examples

  2. Follow the data: Track how data flows through functions

  3. Read comments: rippled has good documentation in code

  4. Use a debugger: Step through code to understand flow

  5. Check git history: See why code was written that way

  6. Ask questions: rippled has active developer community

Last updated