Repository Public
1<div align="center">23<img src="docs/brand/logo.svg" alt="SP Message logo" width="560">45<br><br>67<img src="docs/brand/icon.png" alt="SP Message icon" width="112" height="112">89# SP Message — macOS and iOS apps1011**Native SwiftUI clients of the private, end-to-end encrypted SP Message service: same account, same passkeys, same conversations — with the MLS client engine shipped inside the signed app instead of being delivered by the server.**1213**Author: [Simon-Pierre Boucher](https://www.spboucher.ai)**1415[](https://message.spboucher.ai)161718192021222324252627282930313233[](https://git.spboucher.ai/sp-message-apple/commits)34[](https://git.spboucher.ai/sp-message-apple/commits)35[](https://git.spboucher.ai/sp-message-apple/insights)36[](https://git.spboucher.ai/sp-message-apple)37[](https://git.spboucher.ai/sp-message-apple/insights)38[](https://git.spboucher.ai/sp-message-apple)39[](https://git.spboucher.ai/sp-message-apple/branches)40[](https://git.spboucher.ai/sp-message-apple/tags)41[](https://git.spboucher.ai/sp-message-apple)4243444546474849505152535455565758</div>5960---6162## Table of contents6364- [Overview](#-overview)65- [Features](#-features)66- [Not in the apps](#-not-in-the-apps-use-the-web-application)67- [Architecture](#-architecture)68- [Stack](#-stack)69- [Repository layout](#-repository-layout)70- [Build](#-build)71- [Configuration](#-configuration)72- [Screens](#-screens)73- [Engine bridge](#-engine-bridge)74- [Local data](#-local-data)75- [Security and privacy](#-security-and-privacy)76- [Testing](#-testing)77- [Release](#-release)78- [State on 2026-11-18](#-state-on-2026-11-18)79- [Gotchas](#-gotchas)80- [Author](#-author)81- [License](#-license)8283---8485## 🎯 Overview8687Native SwiftUI clients of https://message.spboucher.ai (same account, same passkeys, same conversations).8889- **Interface**: SwiftUI, one code base for macOS 15+ and iOS/iPadOS 18+ (`Sources/Views`).90- **Sign-in**: system passkeys (`AuthenticationServices`), relying party `message.spboucher.ai` through Associated Domains.91- **Encryption engine**: the client engine of the web application (MLS, identity, sync, attachments — TypeScript, `native/core.ts` in the server repository) is bundled into the app as `Resources/core.js` and runs in an isolated script context (`Sources/Core/EngineHost.swift`). That context loads nothing from the network: HTTPS, WebSocket and storage are provided by Swift (`Net.swift`, `KV.swift`). The engine code is therefore part of the signed app, not delivered by the server.92- **Local data**: SQLite in Application Support, excluded from backups; device keys and group states sealed with AES-256-GCM under a key held in the Keychain (this device only).9394**Why it matters.** The main residual risk of any web-delivered end-to-end encrypted application is a server that serves altered JavaScript. Here the engine is inside a signed (and, on macOS, notarized) binary, which removes that risk for these clients.9596### The SP Message family9798| Piece | spbgit repository | Role |99|---|---|---|100| Backend, web application, client engine, `native/core.ts` | [sp-message](https://git.spboucher.ai/sp-message) | `https://message.spboucher.ai` |101| macOS and iOS / iPadOS apps | **[sp-message-apple](https://git.spboucher.ai/sp-message-apple)** (this repository) | native clients |102103## ✨ Features104105| Area | What the apps do |106|---|---|107| Sign-in and onboarding | « Sign in with a passkey »; join with an invitation link (name, handle, « Create my passkey »); first device creates the encryption keys and shows the recovery key once |108| Linking a device | « Approve from another device » with a code compared on both sides, or « Enter your recovery key »; a trusted device shows the approval sheet (« Codes match: approve » / « Refuse ») |109| Conversations | list with search of messages and people, new direct conversation or group (« Create group », group name), leave a group, mute notifications |110| Messages | send, reply (quoted), edit, « Delete for everyone », reactions, pin, copy, typing indicator, states *Sending → Sent → Delivered → Read* and *Not sent*; « Forwarded from » is displayed |111| Offline | « Offline. Messages are kept and sent on reconnection. » |112| Attachments | file or « Photo or video », encrypted on the device before they leave it; optional reduction of large photos; files above 200 MB must be sent from the web application |113| Disappearing messages | per-conversation timer |114| Verification | safety number per contact, « Mark as verified » / « Remove verification », identity key fingerprint; key-change warning with « Accept new key » and « Add them back » |115| Details | MLS epoch and device count of the conversation, members, security section |116| Settings | name shown to contacts, privacy (read receipts, notifications that never show message text), trusted devices (remove), « Generate a new recovery key », « Sign out », « Sign out and erase this device » |117| Notifications | local notifications while the app runs; they never include message text |118| Languages | English and French, chosen from the system language (`L(en, fr)` helper) |119120## 🚫 Not in the apps (use the web application)121122Calls, administration (invitations, accounts), voice messages, scheduled messages, shared tasks and notes, message forwarding, QR verification (the safety number is shown), push notifications when the app is closed.123124## 🏗 Architecture125126```mermaid127flowchart TB128 subgraph APP["SP Message.app — signed bundle"]129 UI["SwiftUI — Sources/Views<br/>RootView · MainView · ChatView · Theme"]130 MODEL["AppModel<br/>state, engine calls"]131 subgraph HOST["EngineHost — isolated WKWebView (1×1, non-persistent store)"]132 JS["Resources/core.js<br/>engine: identity · MLS · sync · attachments"]133 end134 NET["Net.swift<br/>URLSession HTTPS + WebSocket"]135 KV[("KV.swift<br/>SQLite store.sqlite · AES-256-GCM")]136 PK["Passkey.swift<br/>AuthenticationServices"]137 end138 KC[("Keychain<br/>wrapping key, this device only")]139 SRV["https://message.spboucher.ai<br/>delivery service — ciphertext only"]140 UI --> MODEL141 MODEL -->|"host.call(op, args)"| JS142 JS -->|"bridge: http · ws-* · kv-*"| NET143 JS --> KV144 MODEL --> PK145 KV --> KC146 NET -->|HTTPS / WSS| SRV147 PK -->|"/api/login/* · /api/register/*"| SRV148```149150The engine context loads nothing from the network. Every request it makes is a bridge message answered by Swift; every piece of state it keeps goes through `KV`.151152### Sending a message153154```mermaid155sequenceDiagram156 autonumber157 participant V as ChatView158 participant M as AppModel159 participant E as Engine (core.js)160 participant S as Swift bridge (Net / KV)161 participant B as message.spboucher.ai162 V->>M: send(text)163 M->>E: host.call("send", …)164 E->>E: MLS encrypt on this device165 E->>S: kv-set (outbox, group state — sealed)166 E->>S: http POST /api/conversations/:id/messages167 S->>B: HTTPS (ciphertext)168 B-->>S: sequence number169 S-->>E: status + body170 E->>S: changed171 S->>M: onChanged → snapshot172 M-->>V: state « Sent », then « Delivered » / « Read »173```174175### Adding this device to an existing account176177```mermaid178sequenceDiagram179 autonumber180 participant N as New device (this app)181 participant B as Server182 participant T as Trusted device (app or web)183 N->>B: sign in with the passkey184 N->>B: requestLink (device public keys)185 N->>N: show the code186 B-->>T: « A new device wants to join your account »187 T->>T: compare the code — « Codes match: approve »188 T->>B: approve (certificate + sealed identity key)189 N->>B: pollLink190 B-->>N: certificate + sealed identity key191 Note over N: messages sent before this device was added stay on the other devices192```193194## 🧱 Stack195196| Layer | Technology | Version (read in the repository) | Role |197|---|---|---|---|198| Language | Swift | `SWIFT_VERSION: "5.0"` | apps |199| UI | SwiftUI | macOS 15.0 / iOS 18.0 deployment targets | one code base |200| Project | XcodeGen | `project.yml` | project and entitlements generated |201| Passkeys | AuthenticationServices | — | relying party `message.spboucher.ai` |202| Engine host | WebKit (`WKWebView`, `WKScriptMessageHandlerWithReply`) | — | isolated script context |203| Engine | TypeScript bundled by esbuild | `format: iife`, `target: safari17`, minified | MLS (RFC 9420), identity, sync, attachments |204| Networking | URLSession | — | HTTPS and WebSocket |205| Storage | SQLite3 (system), CryptoKit, Security | — | sealed key-value store |206| Tooling | zsh / bash scripts, Python (`provision.py`, `asc.py`) | — | build, provisioning, release |207208## 🗂 Repository layout209210```211project.yml XcodeGen: targets SPMessage (macOS) and SPMessage-iOS, entitlements, Info.plist keys212Sources/ 12 Swift files, 1 555 lines213 App.swift app entry point214 AppModel.swift observable state, engine calls, sign-in / join / recover / sign-out, notifications215 Core/216 Config.swift server origin (fixed in Release), relying-party id, device label217 EngineHost.swift isolated script context + bridge218 Net.swift URLSession HTTP and WebSocket219 KV.swift SQLite key-value store, AES-256-GCM sealing, Keychain key220 Passkey.swift passkey registration and assertion221 Models.swift decoded engine snapshots222 Views/223 RootView.swift sign-in, join, first device, recovery key, link device, pending approval224 MainView.swift conversation list, new conversation, device approval, settings225 ChatView.swift conversation, message rows, attachments, details226 Theme.swift avatar, buttons, logo227Resources/Assets.xcassets AppIcon (macOS sizes + 1024 px iOS)228Resources/core.js engine bundle — generated by Scripts/build-core.sh, not committed229Scripts/230 build-core.sh bundle the engine from the server repository231 provision.py · asc.py bundle ids, Associated Domains, Developer ID profile (App Store Connect API)232 release-mac.sh Release archive signed with the existing Developer ID identity → dist/SP Message.app233 notarize.sh notarytool, staple, DMG234 release-ios.sh archive / export / upload to App Store Connect235 ExportOptions.plist method app-store-connect236 window-shot.swift window screenshot helper237dist/ committed release artifacts of 1.0.0 (2): SP Message.app, SPMessage-1.0.0.dmg (+ .sha256),238 ios-export/ (SP Message.ipa, DistributionSummary, Packaging.log)239docs/brand/ logo and icon used by this README240```241242Ignored by git: `*.xcodeproj`, `build/`, `DerivedData/`, `*.entitlements` (generated from `project.yml`), `Resources/core.js`.243244## 🚀 Build245246```bash247Scripts/build-core.sh # bundle the engine from ~/Desktop/Cluster/projets/sp-message into Resources/core.js248xcodegen generate249Scripts/provision.py # bundle ids + Associated Domains + Developer ID profile (App Store Connect API)250Scripts/release-mac.sh && Scripts/notarize.sh # dist/SP Message.app and dist/SPMessage-<version>.dmg251Scripts/release-ios.sh all && Scripts/release-ios.sh upload # TestFlight (app 6836555570, bundle ai.spboucher.spmessage.ios)252```253254`Scripts/build-core.sh` runs esbuild on `native/core.ts` of the server repository ([sp-message](https://git.spboucher.ai/sp-message)), copies the result to `Resources/core.js` and prints the first 16 hex digits of its SHA-256 with the server commit it came from. Set `SPM_WEB_REPO` to build from another checkout.255256Debug builds accept `-SPMDevCookie`, `-SPMDevRecovery`, `-SPMDevSend`, `-SPMTrace` launch arguments for automated runs with throwaway accounts (`tests/native-peer.ts` in the server repository plays the other participant). Release builds ignore them.257258## ⚙️ Configuration259260No secret lives in this repository. Names only:261262| Name | Where | Role |263|---|---|---|264| `SPM_WEB_REPO` | `Scripts/build-core.sh` | path of the server repository checkout |265| `NOTARY_PROFILE` | `Scripts/notarize.sh` | notarytool keychain profile (default `MacLustr-Notarize`) |266| `ASC_KEY_ID`, `ASC_ISSUER_ID` | `Scripts/release-ios.sh` | App Store Connect API key identifiers (the private key stays in `~/.appstoreconnect/private_keys/`) |267| `-SPMBase` | launch argument, **Debug only** | another server origin (local test server) |268| `-SPMDevCookie`, `-SPMDevRecovery`, `-SPMDevSend`, `-SPMTrace` | launch arguments, **Debug only** | automated runs with throwaway accounts, bridge tracing |269270In Release the server origin is fixed to `https://message.spboucher.ai` (`Sources/Core/Config.swift`).271272## 🖥 Screens273274| Screen | View | File |275|---|---|---|276| Sign in | `SignInView` | `Views/RootView.swift` |277| Join with an invitation | `JoinSheet` | `Views/RootView.swift` |278| First device — key creation | `FirstDeviceView` | `Views/RootView.swift` |279| Recovery key (shown once) | `RecoveryKeyView` | `Views/RootView.swift` |280| Add this device | `LinkDeviceView` | `Views/RootView.swift` |281| Waiting for administrator confirmation | `PendingView` | `Views/RootView.swift` |282| Conversation list | `MainView`, `ConvRow` | `Views/MainView.swift` |283| New conversation / group | `NewChatSheet` | `Views/MainView.swift` |284| Approve a new device | `DeviceApprovalSheet` | `Views/MainView.swift` |285| Settings | `SettingsSheet` | `Views/MainView.swift` |286| Conversation | `ChatView`, `MessageRow`, `AttachmentView`, `Banner` | `Views/ChatView.swift` |287| Conversation details and verification | `DetailsSheet` | `Views/ChatView.swift` |288289Keyboard: ⌘↩ sends the message; ↩ confirms the sign-in button.290291## 🔌 Engine bridge292293**Swift → engine** — `host.call(op, …)`, 34 operations used by the apps:294295`boot`, `snapshot`, `setActive`, `signOut` · `createIdentity`, `recover`, `newRecoveryKey`, `myFingerprint` · `requestLink`, `pollLink`, `cancelLink`, `approve`, `reject`, `devices`, `removeDevice` · `directory`, `search`, `create`, `leave`, `remove`, `reAdd` · `send`, `edit`, `react`, `pin`, `typing`, `setTtl`, `setMuted`, `setPref` · `sendFile`, `fetchFile` · `safety`, `setVerified`, `acceptKey`296297**Engine → Swift** — 13 bridge operations handled by `EngineHost.handle`:298299| Operation | Provided by | Role |300|---|---|---|301| `loaded` | `EngineHost` | the engine is ready (reports whether WebCrypto is available) |302| `http` | `Net` | one HTTPS request to the server origin (JSON or binary body) |303| `ws-open` · `ws-send` · `ws-close` | `Net` | the WebSocket; incoming frames are pushed back with `__spmSocket` |304| `kv-get` · `kv-set` · `kv-del` · `kv-list` · `kv-clear` | `KV` | local storage |305| `log` | system log | engine script errors (never message content) |306| `changed` | `AppModel` | state changed — take a new snapshot |307| `notify` | `AppModel` | local notification (title and conversation id, no text) |308309## 🗄 Local data310311| Item | Detail |312|---|---|313| Database | `Application Support/SPMessage/store.sqlite`, one table `kv (k text primary key, v blob)`, WAL |314| Sealed values | keys containing `/secret/` (device keys, group states, key packages): AES-256-GCM |315| Wrapping key | 256-bit, Keychain generic password (service `ai.spboucher.spmessage.store`), data-protection keychain, this device only, never synchronised |316| Backups | the database file is excluded from backups — secrets are useless without the Keychain key, and history must not leave the device in a backup |317| iOS file protection | `completeUntilFirstUserAuthentication` |318| Engine web view | non-persistent website data store |319320If the encrypted store cannot be opened, the app shows the reason instead of starting.321322## 🔐 Security and privacy323324- **The engine is part of the signed app.** `core.js` is bundled at build time; the script context has no page loaded from the network.325- **The server sees ciphertext only.** Messages and files are encrypted on the device before they leave it (MLS, RFC 9420); the details sheet shows the epoch and the number of devices holding the keys.326- **Passkeys prove who signs in; they never encrypt anything.** A stolen passkey alone cannot read a message: the device still needs approval from a trusted device or the recovery key.327- **Adding a device is never silent**: a code is compared on both sides, and conversations show « A new device was added for … ».328- **Key changes are not trusted silently**: a contact whose identity key changed is not used until « Accept new key ».329- **The recovery key is shown only once** and the server cannot read it.330- **Notifications never show message text.**331- **macOS entitlements**: App Sandbox, outgoing network client, user-selected files read-write, Associated Domains `webcredentials:message.spboucher.ai`, keychain access group; hardened runtime on.332- **« Sign out and erase this device »** wipes the local store.333334The protocol, the threat model and the security review live in the server repository: [sp-message](https://git.spboucher.ai/sp-message) (`docs/ARCHITECTURE.md`, `docs/THREAT-MODEL.md`, `docs/SECURITY-REVIEW.md`). The MLS library (`ts-mls`) has had no independent audit.335336## 🧪 Testing337338**No automated tests exist for the apps themselves.** Verification so far is by scripted and manual runs:339340| What | How |341|---|---|342| Scripted runs with throwaway accounts | Debug launch arguments (`-SPMDevCookie`, `-SPMDevRecovery`, `-SPMDevSend`, `-SPMTrace`); `tests/native-peer.ts` in the server repository plays the other participant |343| Engine | covered by the server repository's suites (20 integration tests, 9 browser tests, load test) — the same engine code runs here |344| Screenshots | `Scripts/window-shot.swift` |345346## 📦 Release347348| | macOS | iOS / iPadOS |349|---|---|---|350| Bundle id | `ai.spboucher.spmessage` | `ai.spboucher.spmessage.ios` |351| Version | 1.0.0 (2) | 1.0.0 (2) |352| Deployment target | macOS 15.0 | iOS 18.0, iPhone + iPad |353| Signing | manual, Developer ID Application, profile « SP Message Developer ID », hardened runtime, App Sandbox | automatic |354| Script | `Scripts/release-mac.sh` then `Scripts/notarize.sh` | `Scripts/release-ios.sh archive\|export\|upload\|all` (`all` = archive + export) |355| Output | `dist/SP Message.app`, `dist/SPMessage-1.0.0.dmg` (+ `.sha256`) | `dist/ios-export/SP Message.ipa` |356| Distribution | notarized, stapled DMG | App Store Connect / TestFlight (app `6836555570`) |357| Category | `public.app-category.social-networking` | — |358359`release-mac.sh` creates no certificate: it fails if no Developer ID Application identity exists, or if the provisioning profile made by `Scripts/provision.py` is missing (the profile carries the restricted Associated Domains entitlement). `notarize.sh` never creates, prints or modifies credentials, and prints "notarized" only when Apple answered *Accepted*.360361## 📌 State on 2026-11-18362363- macOS 1.0.0 (2): Developer ID signed, notarised, stapled; installed in /Applications.364- iOS 1.0.0 (2): uploaded to App Store Connect, build VALID, internal TestFlight group "Interne".365- Verified: Mac app and iOS simulator app against production with throwaway accounts (device enrolment by recovery key, group join, send, quoted reply, reaction, read state). The owner signed in to the Mac app with a real passkey and approved it from another device the same day.366- Not verified: iOS on a real iPhone/iPad (passkey, Face ID, photo picker), attachments from the native apps, iPad layout, VoiceOver. No automated tests exist for the apps themselves.367- Before an App Store submission: review the export-compliance answer (`ITSAppUsesNonExemptEncryption` is set to NO).368369## 🧯 Gotchas370371- **Build the engine first.** `Resources/core.js` is not committed; without `Scripts/build-core.sh` the app has no engine. `release-ios.sh archive` runs it for you.372- **The engine comes from another repository.** `build-core.sh` reads the server repository at `~/Desktop/Cluster/projets/sp-message` unless `SPM_WEB_REPO` says otherwise; it needs that checkout's `node_modules` (esbuild).373- **Rebuild the apps when the engine changes on the server**: the bundled `core.js` is a snapshot, not a live copy.374- **Entitlements files are generated** by XcodeGen from `project.yml` and ignored by git — edit `project.yml`.375- **Script headers still say `Scripts/release.sh`**: the macOS release script is `Scripts/release-mac.sh` (the error message of `notarize.sh` also names `release.sh`).376- **History starts when the device is added**: messages sent before stay on the other devices — a consequence of forward secrecy.377- **Files above 200 MB** must be sent from the web application.378- **Passkeys need the Associated Domains association**: the server lists the app ids in `/.well-known/apple-app-site-association`.379- **Export compliance**: `ITSAppUsesNonExemptEncryption` is set to NO; review it before an App Store submission.380381## 👤 Author382383<div align="center">384<img src="docs/brand/icon.png" width="64" height="64" alt=""><br>385386**Simon-Pierre Boucher** — design, development, operations<br>387[www.spboucher.ai](https://www.spboucher.ai) · [git.spboucher.ai](https://git.spboucher.ai) · contact@spboucher.ai388389</div>390391## 📄 License392393All rights reserved © 2026 Simon-Pierre Boucher (`NSHumanReadableCopyright` in `project.yml`). No license file is published in this repository.394