Apple Clients (macOS & iOS) Architecture
Apple serves as Chirp's reference client implementation via two Xcode targets—Chirp-macOS and Chirp-iOS—supporting macOS 27.0+ (Apple Silicon) and iOS 27.0+ (arm64), written in Swift 6 strict concurrency mode (SWIFT_STRICT_CONCURRENCY = complete).
Design Philosophy & Module Layout
Apple maximizes code sharing (Client/apple/Shared/ holds 90%+ of authentication, sync, identity, group protocol, chat, and cache logic) while keeping platform divergence thin—restricted mainly to windowing (macOS persistent multi-window background calls vs. iOS tabbed shell) and audio routing (macOS explicit output picker vs. iOS speaker/earpiece/CallKit).
| Module / Core File | Responsibility & Implementation Notes |
|---|---|
ApplicationSession.swift · ChirpApp.swift | Top-level @MainActor session root and foreground/background observer orchestrating discovery, directory SSE, and cold-launch-only local unlock prompts. |
ClientLogin.swift · DeviceLogin.swift | System ASWebAuthenticationSession Passkey sign-in (cn.youzifeile.chirp://auth/callback, S256 PKCE) plus macOS QR polling login. |
SavedLogin.swift · LoginSession.swift · LoginLockView.swift | Seals resumption records in kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly Keychain (biometryCurrentSet on iOS, userPresence on macOS, fresh LAContext per cold launch) with atomic backup-excluded index hints, lock screen UI, and retry state machine. |
DeviceIdentityStore.swift | Local KeychainIdentityPersistence using Data Protection Keychain (kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly, kSecAttrSynchronizable = false) so private keys never sync to iCloud. |
DevicePairingSession.swift · DevicePairingImages.swift | Executes chirp-device-pair-v1; image imports decode primary frame via Image I/O and scan QR codes with Apple Vision (Core Image fallback). |
AuthorizationAuthority.swift · SocialIdentity.swift | Validates bundled AuthorizationTrust.json keys, refreshes signed snapshots every 20s (ContinuousClock 60s expiry), and persists checkpoints/friend trust. |
CallController.swift · LiveKitCallMedia.swift | Coordinates preflight, audio presets, VAD gating, and LiveKit rooms; tracks explicit mic intent to suppress unwanted unmutes. |
RoomChat.swift · AttachmentCache.swift | Encrypted data-channel chat (4,096 B / 1,000-message ring) and Caches/ChirpRoomAttachments storage (512 MiB cap) guarded by revocable AttachmentLeases. |
ChirpLogStore.swift | SQLite ATTACH/DETACH + secure_delete=ON writer and 24-hour .chirplog single-file exporter. |
Apple End-to-End Encryption Pipeline
prepare-livekit-swift.py applies 9 source patches to pinned client-sdk-swift 2.19.0 and injects C++/Objective-C++ frame hooks:
- Strip external ICE & block remote unmutes:
livekit-no-external-ice.patchclears third-party STUN/TURN entries on connect/join/reconnect;livekit-local-microphone-intent.patchdrops server-initiated remote unmute commands. - Entry & SAS verification lock:
GroupSession.swiftandRoomIdentity.swiftvalidate peer certificates, 60s snapshot freshness, and pairwise SAS confirmation before group creation starts. - Rust OpenMLS group & exporter:
MLS/Sources/ChirpMLS/MLSClient.swiftinvokesChirpMLSNative.xcframeworkacross the C boundary to verify the exact roster, process OpenMLSAdd/Welcome, and derive 32-byte per-sender keys viaChirp LiveKit sender key v5. - Dual-slot smooth rotation & 20ms expiry sweeps:
livekit-group-key-provider.patchandlivekit-smooth-rotation.patchenforce 2 key slots per sender (zero ratchet window, SIF plaintext bypass disabled);livekit-v5-expiry.patchplus a ~20 msContinuousClockwatchdog invalidates providers immediately when a 3s lease, 60s snapshot, or 120s key cap expires. - Pre-Opus frame authentication & 96-bit IV replay protection (
ChirpVoiceReceiver.mm·ChirpVoiceKeys.swift):livekit-voice-receiver.patchhooksChirpVoiceReceiverahead of the WebRTC Opus decoder;- Each frame verifies and decrypts using a 16-byte AES-GCM key derived via
HKDF<SHA256>(128 zero-byteinfo); - Per-sender, per-key
Set<Nonce>drops duplicate 96-bit IVs across subscriptions while permitting out-of-order delivery, halting after 65,536 distinct IVs until rotation; - Audio callbacks avoid logging, heap allocations, or blocking locks, accumulating timing counters sampled externally every second into
.chirplog.
Audio Processing Presets & RNNoise
Located in Client/apple/Audio/, offering live-switchable presets confirmed via active track state readbacks:
- Apple System Processing + RNNoise (Default): Hardware VoiceProcessingIO AEC/AGC followed by RNNoise denoising.
- Apple System Processing: Native hardware voice unit only.
- WebRTC AEC + RNNoise: Software WebRTC AEC/AGC paired with RNNoise for external interfaces incompatible with Apple system processing.
Building & Testing on Apple
See Native Client Builds · Apple for Xcode scripts, SwiftPM test commands, and physical iPhone signing.
