SPB Git

Repository Public

DeviceLock.swift 1.5 KB 33 lines swift

1// SP Wallet iOS2// File: Core/Security/DeviceLock.swift3// Description: Optional local lock of the app with Face ID / Touch ID / the device passcode (LocalAuthentication). It protects4//              what is displayed on THIS device. It authorizes nothing on the server: every transaction still needs a passkey5//              assertion bound to its intent.6//7// Author: Simon-Pierre Boucher8// Contact: contact@spboucher.ai9import Foundation10import LocalAuthentication1112enum DeviceLock {13    enum Kind: Sendable { case faceID, touchID, opticID, passcode, none }1415    static func available() -> Kind {16        let c = LAContext()17        var e: NSError?18        if c.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &e) {19            switch c.biometryType { case .faceID: return .faceID; case .touchID: return .touchID; case .opticID: return .opticID; default: break }20        }21        return c.canEvaluatePolicy(.deviceOwnerAuthentication, error: &e) ? .passcode : .none22    }2324    /** True when the person proved presence with biometrics or the device passcode. False on cancel or failure. */25    static func unlock(reason: String) async -> Bool {26        let c = LAContext()27        c.localizedCancelTitle = String(localized: "Annuler")28        var e: NSError?29        guard c.canEvaluatePolicy(.deviceOwnerAuthentication, error: &e) else { return false }30        return (try? await c.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason)) ?? false31    }32}33
Files main
Menu

Theme