// THE PHONE'S OWN LOCK IN FRONT OF THE VAULT KEY (e2e rulings R7, R8; 16 Nov// 2026). The vault key's Keychain item carries no access control any more// (`VaultKey.swift`), so the prompt a person meets before a reveal, an Approve// or an Allow is this one: `LAContext`'s `.deviceOwnerAuthentication`, Face ID// or Touch ID with the passcode behind it, asked by `VaultKeyring.privateKey()`.//// Three rules:// * **Never a wall.** A phone with no passcode (and a simulator out of the// box) cannot be asked; the act runs, as Android's does on a phone with no// lock (R7: nothing ever blocks).// * **A cancel is a decision.** It is `VaultKeyError.cancelled`, drawn as// nothing, and never retried.// * **Never in a test process**, whose simulator may have a face enrolled// and nobody to look at it. The Mac asks at the screen (`VaultAccess`).//// It blocks the calling thread while the sheet stands, as the guarded// Keychain read did: every caller already reads off the main thread.importCottonValuesimportFoundation#if os(iOS)importLocalAuthentication#endifpublicenumVaultPresence {/// The sentence above the sheet, the kit's line. Said in no app's words:/// every app asks it before Approve or a recovery code, and "Unlock your/// passwords" in Words, Days or Story read as another app's (launch-ios,/// 22 Nov 2026). The passwords app's own reveal says its own line.publicstaticvar reason: String { ShellLines.line("passwords", "vault.confirm_its_you") }/// Ask the phone's own lock; throws ``VaultKeyError/cancelled`` when the/// person said no.publicstaticfunc ask() throws { #if os(iOS)ifKeychainGate.isTestProcess { return }let context = LAContext()var problem: NSError?// No passcode set: nothing to ask, and nothing blocks.guard context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &problem) else { return }let answered = DispatchSemaphore(value: 0)let outcome = Outcome() context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason) { allowed, error in outcome.set(allowed: allowed, error as? LAError) answered.signal() } answered.wait()iflet refused = outcome.refused {switch refused.code {case .passcodeNotSet, .biometryNotEnrolled, .biometryNotAvailable: returndefault: throwVaultKeyError.cancelled } }if outcome.failed { throwVaultKeyError.cancelled } #endif } #if os(iOS)privatefinalclassOutcome: @unchecked Sendable {privatelet lock = NSLock()privatevar error: LAError?privatevar done = falseprivatevar allowed = falsefunc set(allowed: Bool, _ refused: LAError?) { lock.withLock { error = allowed ? nil : refusedself.allowed = allowed done = true } }var refused: LAError? { lock.withLock { error } }/// Refused with no error to read.var failed: Bool { lock.withLock { done && !allowed && error == nil } } } #endif}