# Starling

Starling is a peer-to-peer local-network messaging client written in Rust.

## How it works

- People agree on an entry passcode in person.
- Each client hashes that passcode into a room id and uses short encrypted UDP probes on port `47631` to find matching rooms on the LAN.
- Chat messages travel directly between peers over encrypted TCP connections opened by each client.
- Files can be shared in the chat by dragging them into the window or using the plus button.
- Photos are rendered inline in the message thread.
- The first two people in a room can connect automatically.
- Once a room already has two connected people, a new person with the same passcode must wait until an existing participant clicks **Allow**.

No central server is required. All discovery and message traffic stays on the local network.

## Run

```powershell
cargo run
```

If Windows Firewall prompts for network access, allow private-network access so LAN discovery and TCP chat can work.

## Build

```powershell
cargo build --release
```

To build a per-user Windows setup executable:

```powershell
scripts\build-windows-installer.ps1
```

The installer is written to `target\installer\StarlingSetup-<version>.exe`.

To build a Windows MSIX bundle containing both x64 and ARM64 packages:

```powershell
scripts\build-windows-msixbundle.ps1 -SkipSign
```

The bundle is written to `target\msix\Starling-<version>.msixbundle`. MSIX packages
must be signed before Windows can install them; pass `-CertificateThumbprint` or
`-CertificatePath` instead of `-SkipSign` when you have a signing certificate.

To build a universal macOS app bundle on macOS:

```bash
bash scripts/build-macos-app.sh --skip-sign
```

The app bundle and zip are written to `target/macos/`. For release builds, pass
`--sign-identity` with a Developer ID Application certificate; notarization is left
as the next packaging step.

The code uses portable Rust plus `eframe`/`egui` for the desktop UI. It is intended to compile for:

- Windows Intel: `x86_64-pc-windows-msvc`
- Windows ARM: `aarch64-pc-windows-msvc`
- macOS ARM: `aarch64-apple-darwin`
- Linux Intel: `x86_64-unknown-linux-gnu`
- Linux ARM: `aarch64-unknown-linux-gnu`

Install a target with:

```powershell
rustup target add aarch64-pc-windows-msvc
```

Then build with:

```powershell
cargo build --release --target aarch64-pc-windows-msvc
```

Cross-compiling GUI apps may require the target platform's native SDKs, linkers, and system libraries.

## Security note

The passcode is not sent directly; discovery uses a truncated SHA-256 room id. UDP discovery and approval payloads are encrypted with `ChaCha20-Poly1305` using a key derived from the in-person passcode. TCP chat uses ephemeral `X25519` public/private key agreement, mixes the shared secret with the passcode-derived room key via `HKDF-SHA256`, and encrypts chat payloads with `ChaCha20-Poly1305`.

This is still not a formal security audit, but the current implementation avoids plaintext discovery payloads and plaintext chat messages on the LAN.
