Skip to content

Latest commit

 

History

History
71 lines (48 loc) · 2.84 KB

File metadata and controls

71 lines (48 loc) · 2.84 KB

GRAT

Peer-to-peer encrypted chat. Messages are end-to-end encrypted using the Signal Double Ratchet protocol with X25519 key exchange. No servers, no accounts — just keys.

Quick start

nix run .#gratcli -- tui

This builds and launches the interactive TUI. If no identity exists yet, one is generated automatically on first launch.

Nix setup

The project is a Nix flake. You can build or run everything directly without installing Go:

nix build                # Build both binaries to ./result/bin/
nix run .#gratserver     # Run the server daemon
nix run .#gratcli        # Run the CLI
nix develop              # Dev shell with Go, sqlc, golangci-lint

If you don't use Nix, make works too (requires Go 1.25+):

make          # Binaries go to bin/
make test     # Run all tests

Demo

Docker Compose gives you a two-node chat environment — no conflicts with local sockets or databases:

docker compose up --build -d

This creates two isolated nodes (node1, node2) on a shared network, each with its own identity and database.

Open the TUI on a node:

docker compose exec node1 gratcli tui

Press a in the contacts pane and type the other node's hostname (e.g. node2) to discover it. The discovery protocol connects to the peer, exchanges identities, and stores them automatically. Do the same from the other node and you're ready to chat.

To tear down: docker compose down -v

Codebase

Two binaries, a handful of packages.

Binaries (cmd/):

  • gratserver — long-running daemon. Listens on TCP (:1337) for peer connections and on a Unix socket for local IPC from gratcli.
  • gratcli — CLI tool that talks to gratserver over the Unix socket. Sends messages, fetches messages, manages identity, launches the TUI.

Public packages (pkg/):

  • identity — cryptographic identity: Ed25519 signing key + X25519 DH key, 20-byte base32 address, key bundles, signed network updates.
  • doubleratchet — Signal Double Ratchet (X25519 + AES-GCM). kdfchain/ has the root and message KDF chain primitives.
  • netprotocol — binary wire protocol for peer TCP connections. Packet types: Heartbeat, Message, KeyExchange, Discovery. All fixed-size encoding.
  • ipcprotocol — binary wire protocol for local Unix socket IPC between CLI and server.
  • session — ties a DoubleRatchet to a KeyBundle and ephemeral exchange key. SessionManager maps peer addresses to sessions.

Internal packages (internal/):

  • nethandle — TCP connection loop, dispatches packets to typed handlers.
  • ipchandle — Unix socket server for local CLI commands.
  • database — SQLite via modernc.org/sqlite, migrations via golang-migrate, queries generated by sqlc.

SQL queries live in internal/database/queries/. After editing them, regenerate with sqlc generate (available in the Nix dev shell).