@@ -5,55 +5,35 @@ import LocalAuthentication
55
66public class SwiftLocalAuthSignaturePlugin : NSObject , FlutterPlugin {
77
8- private var signatureBiometricManager : SignatureBiometricManager ? = nil
9-
108 public static func register( with registrar: FlutterPluginRegistrar ) {
119 let channel = FlutterMethodChannel ( name: " local_auth_signature " , binaryMessenger: registrar. messenger ( ) )
1210 let instance = SwiftLocalAuthSignaturePlugin ( )
1311 registrar. addMethodCallDelegate ( instance, channel: channel)
1412 }
1513
16- func isBiometricChanged( name: String ) -> Bool {
17- let context = LAContext ( )
18- var error : NSError ?
14+ public func handle( _ call: FlutterMethodCall , result: @escaping FlutterResult ) {
1915
20- // Check if biometric authentication is available
21- guard context. canEvaluatePolicy ( . deviceOwnerAuthenticationWithBiometrics, error: & error) else {
22- // Biometric authentication is not available
23- return true
16+ if call. method == SwiftLocalAuthSignatureMethod . isBiometricChanged {
17+ let keyConfig = KeyConfig ( name: " " )
18+ let signatureBiometricManager = LocalSignatureBiometricManager . newInstance ( keyConfig: keyConfig)
19+
20+ let isChanged = signatureBiometricManager. biometricsChanged ( )
21+ if isChanged {
22+ result ( " changed " )
23+ } else {
24+ result ( " unchanged " )
25+ }
26+ return
27+ } else if call. method == SwiftLocalAuthSignatureMethod . resetBiometricChanged {
28+ let keyConfig = KeyConfig ( name: " " )
29+ let signatureBiometricManager = LocalSignatureBiometricManager . newInstance ( keyConfig: keyConfig)
30+
31+ signatureBiometricManager. biometricsPolicyStateReset ( )
32+
33+ result ( true )
34+ return
2435 }
2536
26- let tag = name. data ( using: . utf8) !
27- let query : [ String : Any ] = [
28- kSecClass as String : kSecClassKey,
29- kSecAttrKeyType as String : kSecAttrKeyTypeECSECPrimeRandom,
30- kSecAttrApplicationTag as String : tag,
31- kSecReturnRef as String : true ,
32- kSecUseAuthenticationUI as String : kSecUseAuthenticationUIFail
33- ]
34-
35- var item : CFTypeRef ?
36- let status = SecItemCopyMatching ( query as CFDictionary , & item)
37-
38- switch status {
39- case errSecSuccess:
40- // Key exists and is accessible without authentication
41- return false
42- case errSecItemNotFound:
43- // Key doesn't exist anymore, biometrics likely changed
44- return true
45- case errSecUserCanceled, errSecAuthFailed:
46- // Key exists but requires authentication (which we've disabled)
47- // Biometrics are still valid
48- return false
49- default :
50- // Any other error suggests the key is not accessible, biometrics likely changed
51- print ( " Unexpected error checking biometric state: \( status) " )
52- return true
53- }
54- }
55-
56- public func handle( _ call: FlutterMethodCall , result: @escaping FlutterResult ) {
5737 guard let args = call. arguments as? Dictionary < String , String > else {
5838 result (
5939 FlutterError (
@@ -77,16 +57,6 @@ public class SwiftLocalAuthSignaturePlugin: NSObject, FlutterPlugin {
7757 }
7858
7959 switch call. method {
80- case SwiftLocalAuthSignatureMethod . isBiometricChanged:
81-
82- let isChanged = isBiometricChanged ( name: key)
83- if isChanged {
84- result ( " changed " )
85- } else {
86- result ( " unchanged " )
87- }
88-
89- break
9060 case SwiftLocalAuthSignatureMethod . CreateKeyPair:
9161 guard let reason = args [ SwiftLocalAuthSignatureArgs . Reason] else {
9262 result (
0 commit comments