mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-02-10 17:03:12 +00:00
2.9 KiB
2.9 KiB
Chat CLI
A terminal chat application built with ratatui using the logos-chat library.
Features
- 💬 End-to-end encrypted messaging using the Double Ratchet algorithm
- 📁 File-based transport for local simulation (no network required)
- 💾 Persistent storage (SQLite)
- 🖥️ Beautiful terminal UI with ratatui
Usage
Run two instances with different usernames in separate terminals:
Terminal 1 (Alice)
cargo run -p chat-cli -- alice
Terminal 2 (Bob)
cargo run -p chat-cli -- bob
Establishing a Connection
- In Alice's terminal, type
/introto generate an introduction bundle - Copy the bundle string (starts with
Bundle:) - In Bob's terminal, type
/connect alice <bundle>(paste Alice's bundle) - Bob can now send messages to Alice
- Alice will see Bob's initial "Hello!" message and can reply
Commands
| Command | Description |
|---|---|
/help |
Show available commands |
/intro |
Generate and display your introduction bundle |
/connect <user> <bundle> |
Connect to a user using their introduction bundle |
/peers |
List available peers |
/status |
Show connection status and your address |
/clear |
Clear message history |
/quit or Esc or Ctrl+C |
Exit the application |
Sending Messages
Simply type your message and press Enter. Messages are automatically encrypted and delivered via file-based transport.
How It Works
File-Based Transport
Messages are passed between users via files in a shared directory:
- Each user has an "inbox" directory at
chat-cli-data/transport/<username>/ - When Alice sends a message to Bob, it's written as a JSON file in Bob's inbox
- Bob's client watches for new files and processes incoming messages
- Files are deleted after processing
Storage
User data (identity keys, chat state) is stored in SQLite databases at:
chat-cli-data/<username>.db
Encryption
All messages are encrypted using:
- X3DH key agreement for initial key exchange
- Double Ratchet algorithm for ongoing message encryption
- ChaCha20-Poly1305 for authenticated encryption
Example Session
# Terminal 1 (Alice)
$ cargo run -p chat-cli -- alice
/intro
# Output: Bundle:abc123...def456
# Terminal 2 (Bob)
$ cargo run -p chat-cli -- bob
/connect alice Bundle:abc123...def456
# Connected! Bob sends "Hello!" automatically
# Now type messages in either terminal to chat!
Architecture
chat-cli/
├── src/
│ ├── main.rs # Entry point
│ ├── app.rs # Application state and logic
│ ├── transport.rs # File-based message transport
│ └── ui.rs # Ratatui terminal UI
The CLI uses logos-chat as a library without modifying it:
ChatManagerhandles all encryption/decryptionIntroductionbundles enable key exchangeAddressedEnvelopecarries encrypted messages