Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / apple / Passwords / PasswordsApp.swift
PasswordsApp.swift126 lines · 6.0 KiBRaw
| 1 | // EverySync Passwords — Phase 3 SwiftUI shell. |
| 2 | // |
| 3 | // ZERO sync logic in Swift. All merge (`mergeCredentials` / `passkeysFor` / |
| 4 | // `PasskeyLink`), TOTP (`Totp.generate`), matching (`DomainMatch`), envelope |
| 5 | // codec (`PasswordKind.toJson/fromJson`), roles (`RelayRoles`), links |
| 6 | // (`RelayLinks`), transport (`IosRelayTransport`), and cursors |
| 7 | // (`RelayCursorStore`) live in the shared XCFramework. This target: |
| 8 | // - renders vault list / detail / TOTP codes from XCFramework snapshots, |
| 9 | // - hosts the Credential Provider extension (see `CredentialProvider.swift`), |
| 10 | // - exposes the XPC envelope service (see `PasswordsXPCService.swift`), |
| 11 | // - schedules background sync (see `../Shared/BackgroundSync.swift`). |
| 12 | // |
| 13 | // Delete semantics — HARD delete (verbatim): passwords rows vanish locally; |
| 14 | // only the app-side snapshot remembers them. |
| 15 | // `PasswordKind.localDeletesAreAuthoritative == false`, so a healthy-read |
| 16 | // absence IS a genuine local delete. `SyncSink.delete` removes the row; |
| 17 | // merge-driven deletes always arrive as tombstone envelopes, never raw. |
| 18 | // See `../IPC_CONTRACT.md`. |
| 19 | |
| 20 | import SwiftUI |
| 21 | import BackgroundTasks |
| 22 | import EverysyncCore |
| 23 | |
| 24 | // MARK: - KMP entry points (Phase 3 wiring — call, never re-implement) |
| 25 | // |
| 26 | // data: core.data.RemotePassword (uid / isPasskey / name / username / |
| 27 | // email / password / note / totpSecret / websites[] / rp* half / |
| 28 | // creationTime / lastUsedTime / signCount / linkedPasswordSyncId / |
| 29 | // deleted / updatedAt) |
| 30 | // merge: core.passwords.mergeCredentials([CredentialDto], [PasskeyDto]) |
| 31 | // -> MergeResult(passkeysByPasswordSyncId, standalone) |
| 32 | // core.passwords.passkeysFor(password, passwords, passkeys) |
| 33 | // core.passwords.PasskeyLink (Auto / Detached / To(syncId)) |
| 34 | // totp: core.passwords.Totp.generate(secret, epochSecond) — Swift only |
| 35 | // passes `Int64(Date().timeIntervalSince1970)`; CryptoKit HMAC is |
| 36 | // behind the XCFramework's `HmacIos` actual. |
| 37 | // match: core.passwords.DomainMatch.normalizeSite / isSameSiteOrSubdomain |
| 38 | // kind: core.sync.adapters.PasswordKind (syncId=uid, LWW updatedAt, |
| 39 | // contentKey password `name␀username` / passkey `rpId␀credentialId`, |
| 40 | // `isTombstoneEnvelope` = `deleted`) |
| 41 | // driver: core.provider.SyncDriver.drive(kind, store, remote, append, now) |
| 42 | // cursors: core.platform.RelayCursorStore (`relay_cursor:<type>:<vault>:<channel>`) |
| 43 | // securestore: core.platform.SecureStore (Keychain actual — see |
| 44 | // ../Shared/KeychainSecureStore.swift; vault AES keys NEVER |
| 45 | // surface in Swift) |
| 46 | // transport: core.network.IosRelayTransport (`recordChannel("passwords", |
| 47 | // vaultId)` -> `passwords:<vaultId>`; envelopes |
| 48 | // `Base64(AES_GCM)` per item; invites PQC-sealed to `inbox:<device>`) |
| 49 | // roles: RelayRoles — passwords offer EDITOR only, NEVER VIEWER |
| 50 | // (read-only passwords still disclose every secret) |
| 51 | // links: RelayLinks.parseJoinLink / .shareLinkFor |
| 52 | // (`everysync://join/<vault>?owner=…&type=…`) |
| 53 | // pqc: exactly 10 fns per IOS_PQC_NOTES.md via `e2eePqc` cinterop. |
| 54 | // Swift never calls Rust directly — only via the XCFramework. |
| 55 | |
| 56 | /// Vault list entry, projected from `RemotePassword` envelopes by the |
| 57 | /// XCFramework. Swift holds display strings only — no secrets leave the |
| 58 | /// envelope except into the visible detail view / autofill response. |
| 59 | struct PasswordRow: Identifiable { |
| 60 | /// Relay sync identity (`RemotePassword.uid`). |
| 61 | let id: String |
| 62 | let name: String |
| 63 | let username: String |
| 64 | /// True for the passkey half (`RemotePassword.isPasskey`). |
| 65 | let isPasskey: Bool |
| 66 | let rpId: String |
| 67 | /// Attached passkeys, from `passkeysFor` in the XCFramework. |
| 68 | let passkeyCount: Int |
| 69 | } |
| 70 | |
| 71 | @main |
| 72 | struct PasswordsApp: App { |
| 73 | init() { |
| 74 | // Register the periodic pull; the cycle itself runs in the XCFramework. |
| 75 | // MAC-CHECK: identifier must match Info.plist |
| 76 | // `BGTaskSchedulerPermittedIdentifiers`. |
| 77 | BackgroundSync.register(handlers: [ |
| 78 | "com.vayunmathur.everysync.passwords.refresh": { task in |
| 79 | // TODO(Mac): call XCFramework SyncDriver cycle for each vault, |
| 80 | // then re-schedule + `task.setTaskCompleted(success:)`. |
| 81 | // (Kotlin `SyncScheduler` actual owns the schedule; this |
| 82 | // handler is the wakeup entry.) |
| 83 | task.setTaskCompleted(success: true) |
| 84 | }, |
| 85 | ]) |
| 86 | } |
| 87 | |
| 88 | var body: some Scene { |
| 89 | WindowGroup { |
| 90 | PasswordsRootView() |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | struct PasswordsRootView: View { |
| 96 | // TODO(Mac): vault list driven by SyncDriver snapshots via |
| 97 | // RelayCursorStore; rows projected from RemotePassword envelopes by |
| 98 | // `mergeCredentials` in the XCFramework. TOTP via `Totp.generate`. |
| 99 | // Search filters on name/username only (never on secret material). |
| 100 | @State private var query = "" |
| 101 | |
| 102 | var body: some View { |
| 103 | NavigationStack { |
| 104 | VStack { |
| 105 | // TODO(Mac): replace with the XCFramework-driven list. |
| 106 | // Placeholder keeps the target compiling on Windows/Linux CI |
| 107 | // where EverysyncCore / SwiftUI previews are unavailable. |
| 108 | Text("EverySync Passwords") |
| 109 | .navigationTitle("Passwords") |
| 110 | } |
| 111 | .searchable(text: $query) |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // MARK: - Detail view contract (Mac implements against XCFramework types) |
| 117 | // |
| 118 | // - Detail shows password fields + `Totp.generate(secret, now)` code. |
| 119 | // - Passkey rows show `rpId / credentialId / userName` + link state |
| 120 | // (`PasskeyLink.fromColumn(linkedPasswordSyncId)`); link/detach writes go |
| 121 | // through the envelope IPC as `linkedPasswordSyncId` field updates — Swift |
| 122 | // never computes merge pairing. |
| 123 | // - Delete = HARD delete via `deleteByVault` (row vanishes); the app-side |
| 124 | // snapshot (XCFramework) remembers it for propagation. |
| 125 | // - Share sheet offers EDITOR only (`RelayRoles.offerable("passwords")`). |
| 126 | // Vault keys never user-visible: links carry ids only. |