A visual tool for understanding Sphinx onion packet construction used in the Lightning Network.
This application demonstrates how Lightning Network onion packets are built layer by layer using the Sphinx protocol. It provides:
- Interactive packet builder - Configure session keys, associated data, and multiple hops
- Step-by-step visualization - See how each layer wraps the previous with encryption
- Flow diagram - React Flow-based graphical representation of packet construction
- Shared secrets display - View ECDH shared secrets and derived keys (rho, mu)
- Final packet output - Copy the complete 1366-byte onion packet
sphinx_packet_visualizer/
├── backend/ # Rust backend server
│ ├── src/
│ │ ├── main.rs # Entry point, web server
│ │ ├── api.rs # REST API endpoints
│ │ ├── crypto.rs # Cryptographic operations
│ │ ├── types.rs # Data structures
│ │ └── utils.rs # Helper functions
│ └── Cargo.toml
├── frontend/ # React frontend
│ ├── src/
│ │ ├── components/ # React components
│ │ │ ├── FlowVisualization.jsx
│ │ │ ├── LayerVisualization.jsx
│ │ │ ├── SharedSecrets.jsx
│ │ │ └── ...
│ │ └── styles/
│ └── package.json
└── test/ # Test inputs
- Rust 1.70+ (edition 2021)
- Cargo
- Node.js 18+
- npm
cd backend
cargo build --releasecd frontend
npm installcd backend
cargo run -- --web --port 3000The API will be available at http://localhost:3000
cd frontend
npm run devThe UI will be available at http://localhost:5173
{
"session_key": "4141414141414141414141414141414141414141414141414141414141414141",
"associated_data": "4242424242424242424242424242424242424242424242424242424242424242",
"hops": [
{
"pubkey": "02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619",
"payload": "1202023a98040205dc06080000000000000001"
}
]
}- ECDH: secp256k1 elliptic curve for shared secret derivation
- Key Derivation: HMAC-SHA256 for generating rho/mu keys
- Stream Cipher: ChaCha20 for mix header encryption
- Authentication: HMAC-SHA256 for packet integrity
| Field | Size | Description |
|---|---|---|
| Version | 1 byte | Packet version (0x00) |
| Ephemeral Public Key | 33 bytes | Session public key |
| Mix Header | 1300 bytes | Encrypted routing information |
| HMAC | 32 bytes | Authentication tag |
GPL-3.0