Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / apple / IPC_CONTRACT.md
| 1 | # Apple envelope IPC contract (Phase 3a) |
| 2 | |
| 3 | How the Passwords / Notes / Hub processes share vault envelopes on-device. |
| 4 | Mirrors the Android relay-provider ops and the KMP `SyncSink` interface |
| 5 | (`querySince` / `upsertRaw` / `deleteByVault`) with **identical columns**. |
| 6 | The hub is the only process that talks to the relay; shells read and write |
| 7 | envelopes here; the Credential Provider extension reads over XPC. |
| 8 | |
| 9 | ## Transport |
| 10 | |
| 11 | - **Location:** App-Group shared container |
| 12 | `group.<team>.everysync.shared`, one SQLite file per vault at |
| 13 | `vault/<vaultId>/envelopes.sqlite`, plus a `blobs/` sidecar dir for note |
| 14 | image bytes keyed by `fileName`. |
| 15 | - **Coordination:** `NSFileCoordinator` for file-level coordination between |
| 16 | the apps and their extensions. |
| 17 | - **XPC for the Credential Provider:** the autofill extension cannot assume |
| 18 | direct store access, so the containing Passwords app exposes an XPC service |
| 19 | (`com.vayunmathur.everysync.envelope-ipc`) with exactly the three ops below. |
| 20 | The extension never touches the relay. |
| 21 | |
| 22 | ## Ops (map 1:1 to KMP `SyncSink`) |
| 23 | |
| 24 | | IPC op | KMP `SyncSink` | Semantics | |
| 25 | |---|---|---| |
| 26 | | `querySince(vaultId, table, since)` | `listLocal` + `localChanges` | Rows with `updatedAt > since`, tombstones included; drives both baseline reads and delta detection. An unhealthy read aborts the merge (never fold failure as empty). | |
| 27 | | `upsertRaw(vaultId, table, rows)` | `upsert` | Idempotent upsert keyed on `syncId`; preserves pulled timestamps. | |
| 28 | | `deleteByVault(vaultId, table, syncId)` | `delete` | Passwords table: **hard-delete** the row. Notes/todos tables: set `deleted=1` tombstone. Merge-driven deletes ALWAYS arrive here as tombstone envelopes, never raw deletes. | |
| 29 | |
| 30 | ## Columns (identical everywhere) |
| 31 | |
| 32 | | Column | Type | Semantics | KMP source | |
| 33 | |---|---|---|---| |
| 34 | | `syncId` | TEXT PRIMARY KEY | Relay sync identity (opaque 32-char id) | `EntityKind.syncId` → `RemoteX.uid` | |
| 35 | | `updatedAt` | INTEGER | Last modification, epoch ms; drives relay LWW | `RemoteX.updatedAt` | |
| 36 | | `deleted` | INTEGER 0/1 | Tombstone flag | `RemoteX.deleted` | |
| 37 | | `payloadJson` | TEXT | Full `RemoteX` JSON envelope, plaintext at rest (protected by sandbox + Data Protection; encryption happens at the relay layer, not here) | `PasswordKind` / `NoteKind` / `TodoKind.toJson` | |
| 38 | | `contentHash` | TEXT | `relayContentHash(canonical + "\0deleted=…")`; canonical strips identity/ordering/timestamps | `EntityKind.contentHash` | |
| 39 | |
| 40 | ## Tables ↔ relay channels |
| 41 | |
| 42 | | Table | Relay channel | Envelope | Delete | |
| 43 | |---|---|---|---| |
| 44 | | `passwords` | `passwords:<vaultId>` | `RemotePassword` (`isPasskey` selects the password vs passkey half) | **HARD** — rows vanish; only the app-side snapshot remembers them (`localDeletesAreAuthoritative == false`, so a healthy-read absence IS a genuine local delete) | |
| 45 | | `notes` | `notes:<vaultId>` | `RemoteNote` (title + content + `blocksJson`; image bytes in `blobs/` + `notes-blobs:<vaultId>`) | **SOFT** — `deleted=1` tombstones persist and propagate | |
| 46 | | `todos` | `todos:<vaultId>` | `RemoteTodo` | **SOFT** — tombstones persist and propagate | |
| 47 | | `contacts` / `calendars` | per `recordChannel` | `RemoteContact` / `RemoteEvent` | Hub-managed; same columns; delete semantics per the XCFramework entity kind (Swift holds no opinion) | |
| 48 | |
| 49 | Contacts/calendar rows are hub-internal (system stores are the UI); shells |
| 50 | for those types do not exist in Phase 3a. |
| 51 | |
| 52 | ## Appendix — Phase 3 conformance (no drift) |
| 53 | |
| 54 | Reviewed against the Phase 3 Swift (`Shared/EnvelopeIPC.swift`, |
| 55 | `Shared/BlobStore.swift`, `Passwords/PasswordsXPCService.swift`, |
| 56 | `Hub/IPCRelayStore.swift`, `Hub/SyncIdMap.swift`) — contract holds verbatim: |
| 57 | |
| 58 | - 3 ops (`querySince` / `upsertRaw` / `deleteByVault`) with identical |
| 59 | columns (`syncId / updatedAt / deleted / payloadJson / contentHash`). |
| 60 | - 5 tables (`passwords` HARD / `notes`, `todos` SOFT / hub-internal |
| 61 | `contacts`, `calendars` with kind-driven delete semantics). |
| 62 | - App-Group container + `NSFileCoordinator` + XPC (exactly the 3 ops; |
| 63 | extension never touches the relay); `blobs/` sidecar keyed by `fileName`. |
| 64 | - Cursor keys in Keychain `SecureStore`, never in these tables; vault keys |
| 65 | never appear here or in share links. |
| 66 | - WAL + `busy_timeout=5000` so the Kotlin `RelayStore` shims (specified in |
| 67 | `Hub/IPCRelayStore.swift`, owned by `XCFramework/IOS_ACTUALS_NOTES.md`) |
| 68 | share the same files; schema v1. |
| 69 | |
| 70 | Build-note drift (NOT contract drift): `XCFramework/BUILD_NOTES.md` uses the |
| 71 | `aarch64-apple-ios-sim` Rust target for Apple-Silicon simulators where |
| 72 | `library/everysync-core/IOS_PQC_NOTES.md` says `x86_64-apple-ios` |
| 73 | (Intel-only). Relay/channel/table semantics are unaffected. |
| 74 | |
| 75 | ## Concurrency rules |
| 76 | |
| 77 | 1. Single writer to the relay: the hub. Shells only touch the IPC store. |
| 78 | 2. All IPC access goes through `NSFileCoordinator` (or the XPC service, |
| 79 | which does it internally). |
| 80 | 3. Cursor keys (`relay_cursor:<type>:<vault>:<channel>`) live in the Keychain |
| 81 | `SecureStore` via `RelayCursorStore`, not in these tables. |
| 82 | 4. Vault AES keys never appear here or in share links — keys move exclusively |
| 83 | via PQC-sealed inbox invites (`inbox:<deviceId>`). |