-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from bitcoinppl/130-allow-pin-to-wipe-all-dat…
…a-on-device Allow PIN to wipe all data on device
- Loading branch information
Showing
22 changed files
with
1,767 additions
and
374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import SwiftUI | ||
|
||
@Observable class AuthManager: AuthManagerReconciler { | ||
private let logger = Log(id: "AuthManager") | ||
var rust: RustAuthManager | ||
var type = Database().globalConfig().authType() | ||
var lockState: LockState = .locked | ||
var isWipeDataPinEnabled: Bool | ||
|
||
@MainActor | ||
var isUsingBiometrics: Bool = false | ||
|
||
public init() { | ||
let rust = RustAuthManager() | ||
self.rust = rust | ||
isWipeDataPinEnabled = rust.isWipeDataPinEnabled() | ||
|
||
rust.listenForUpdates(reconciler: self) | ||
} | ||
|
||
public func lock() { | ||
guard isAuthEnabled else { return } | ||
lockState = .locked | ||
} | ||
|
||
public var isAuthEnabled: Bool { | ||
type != AuthType.none | ||
} | ||
|
||
public func checkPin(_ pin: String) -> Bool { | ||
if AuthPin().check(pin: pin) { | ||
return true | ||
} | ||
|
||
if checkWipeDataPin(pin) { | ||
AppManager().rust.dangerousWipeAllData() | ||
|
||
// reset auth maanger | ||
rust = RustAuthManager() | ||
lockState = .unlocked | ||
type = .none | ||
|
||
// reset app manager | ||
AppManager().reset() | ||
|
||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
public func checkWipeDataPin(_ pin: String) -> Bool { | ||
rust.checkWipeDataPin(pin: pin) | ||
} | ||
|
||
func reconcile(message: AuthManagerReconcileMessage) { | ||
logger.debug("reconcile: \(message)") | ||
|
||
Task { | ||
await MainActor.run { | ||
switch message { | ||
case let .authTypeChanged(authType): | ||
self.type = authType | ||
|
||
case .wipeDataPinChanged: | ||
self.isWipeDataPinEnabled = self.rust.isWipeDataPinEnabled() | ||
} | ||
} | ||
} | ||
} | ||
|
||
public func dispatch(action: AuthManagerAction) { | ||
logger.debug("dispatch: \(action)") | ||
rust.dispatch(action: action) | ||
} | ||
} |
Oops, something went wrong.