1
+ var utils = require ( "utils/utils" ) ;
2
+
1
3
var keychainItemIdentifier = "TouchIDKey" ;
2
4
var keychainItemServiceName = null ;
3
5
@@ -14,6 +16,46 @@ var available = function () {
14
16
} ) ;
15
17
} ;
16
18
19
+ var didFingerprintDatabaseChange = function ( ) {
20
+ return new Promise ( function ( resolve , reject ) {
21
+ try {
22
+ var laContext = LAContext . alloc ( ) . init ( ) ;
23
+
24
+ // we expect the dev to have checked 'isAvailable' already so this should not return an error,
25
+ // we do however need to run canEvaluatePolicy here in order to get a non-nil evaluatedPolicyDomainState
26
+ if ( ! laContext . canEvaluatePolicyError ( LAPolicyDeviceOwnerAuthenticationWithBiometrics , null ) ) {
27
+ reject ( "Not available" ) ;
28
+ return ;
29
+ }
30
+
31
+ // only supported on iOS9+, so check this.. if not supported just report back as false
32
+ if ( utils . ios . MajorVersion < 9 ) {
33
+ resolve ( false ) ;
34
+ return ;
35
+ }
36
+
37
+ var FingerprintDatabaseStateKey = "FingerprintDatabaseStateKey" ;
38
+ var state = laContext . evaluatedPolicyDomainState ;
39
+ if ( state !== null ) {
40
+ var stateStr = state . base64EncodedStringWithOptions ( 0 ) ;
41
+ var storedState = NSUserDefaults . standardUserDefaults ( ) . stringForKey ( FingerprintDatabaseStateKey ) ;
42
+
43
+ // Store enrollment
44
+ NSUserDefaults . standardUserDefaults ( ) . setObjectForKey ( stateStr , FingerprintDatabaseStateKey ) ;
45
+ NSUserDefaults . standardUserDefaults ( ) . synchronize ( ) ;
46
+
47
+ // whenever a finger is added/changed/removed the value of the storedState changes,
48
+ // so compare agains a value we previously stored in the context of this app
49
+ var changed = storedState !== null && stateStr !== storedState ;
50
+ resolve ( changed ) ;
51
+ }
52
+ } catch ( ex ) {
53
+ console . log ( "Error in touchid.didFingerprintDatabaseChange: " + ex ) ;
54
+ resolve ( false ) ;
55
+ }
56
+ } ) ;
57
+ } ;
58
+
17
59
/**
18
60
* this 'default' method uses keychain instead of localauth so the passcode fallback can be used
19
61
*/
@@ -61,25 +103,26 @@ var verifyFingerprintWithCustomFallback = function (arg) {
61
103
return new Promise ( function ( resolve , reject ) {
62
104
try {
63
105
var laContext = LAContext . alloc ( ) . init ( ) ;
64
- if ( laContext . canEvaluatePolicyError ( LAPolicyDeviceOwnerAuthenticationWithBiometrics , null ) ) {
65
- var message = arg !== null && arg . message || "Scan your finger" ;
66
- if ( arg !== null && arg . fallbackMessage ) {
67
- laContext . localizedFallbackTitle = arg . fallbackMessage ;
68
- }
69
- laContext . evaluatePolicyLocalizedReasonReply (
70
- LAPolicyDeviceOwnerAuthenticationWithBiometrics ,
71
- message ,
72
- function ( ok , error ) {
73
- if ( ok ) {
74
- resolve ( ok ) ;
75
- } else {
76
- reject ( error ) ;
77
- }
78
- }
79
- ) ;
80
- } else {
106
+ if ( ! laContext . canEvaluatePolicyError ( LAPolicyDeviceOwnerAuthenticationWithBiometrics , null ) ) {
81
107
reject ( "Not available" ) ;
108
+ return ;
82
109
}
110
+
111
+ var message = arg !== null && arg . message || "Scan your finger" ;
112
+ if ( arg !== null && arg . fallbackMessage ) {
113
+ laContext . localizedFallbackTitle = arg . fallbackMessage ;
114
+ }
115
+ laContext . evaluatePolicyLocalizedReasonReply (
116
+ LAPolicyDeviceOwnerAuthenticationWithBiometrics ,
117
+ message ,
118
+ function ( ok , error ) {
119
+ if ( ok ) {
120
+ resolve ( ok ) ;
121
+ } else {
122
+ reject ( error ) ;
123
+ }
124
+ }
125
+ ) ;
83
126
} catch ( ex ) {
84
127
console . log ( "Error in touchid.verifyFingerprint: " + ex ) ;
85
128
reject ( ex ) ;
@@ -119,5 +162,6 @@ var createKeyChainEntry = function () {
119
162
} ;
120
163
121
164
exports . available = available ;
165
+ exports . didFingerprintDatabaseChange = didFingerprintDatabaseChange ;
122
166
exports . verifyFingerprint = verifyFingerprint ;
123
167
exports . verifyFingerprintWithCustomFallback = verifyFingerprintWithCustomFallback ;
0 commit comments