forked from Vizir/react-native-fingerprint-scanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
173 lines (155 loc) · 5.45 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
export type AuthenticateIOS = {
description?: string;
fallbackEnabled?: boolean;
};
export type AuthenticateAndroid = {
title?: string;
subTitle?: string;
description?: string;
cancelButton?: string;
onAttempt?: (error: FingerprintScannerError) => void;
};
export type Biometrics = 'Touch ID' | 'Face ID' | 'Biometrics';
export type Errors =
| { name: 'AuthenticationNotMatch'; message: 'No match' }
| {
name: 'AuthenticationFailed';
message: 'Authentication was not successful because the user failed to provide valid credentials';
}
| {
name: 'AuthenticationTimeout';
message: 'Authentication was not successful because the operation timed out.';
}
| {
name: 'AuthenticationProcessFailed';
message: 'Sensor was unable to process the image. Please try again.';
}
| {
name: 'UserCancel';
message: 'Authentication was canceled by the user - e.g. the user tapped Cancel in the dialog';
}
| {
name: 'UserFallback';
message: 'Authentication was canceled because the user tapped the fallback button (Enter Password)';
}
| {
name: 'SystemCancel';
message: 'Authentication was canceled by system - e.g. if another application came to foreground while the authentication dialog was up';
}
| {
name: 'PasscodeNotSet';
message: 'Authentication could not start because the passcode is not set on the device';
}
| {
name: 'FingerprintScannerNotAvailable';
message: ' Authentication could not start because Fingerprint Scanner is not available on the device';
}
| {
name: 'FingerprintScannerNotEnrolled';
message: ' Authentication could not start because Fingerprint Scanner has no enrolled fingers';
}
| {
name: 'FingerprintScannerUnknownError';
message: 'Could not authenticate for an unknown reason';
}
| {
name: 'FingerprintScannerNotSupported';
message: 'Device does not support Fingerprint Scanner';
}
| {
name: 'DeviceLocked';
message: 'Authentication was not successful, the device currently in a lockout of 30 seconds';
}
| {
name: 'DeviceLockedPermanent';
message: 'Authentication was not successful, device must be unlocked via password.';
}
| {
name: 'DeviceOutOfMemory';
message: 'Authentication could not proceed because there is not enough free memory on the device.';
}
| {
name: 'HardwareError';
message: 'A hardware error occurred.';
};
export type FingerprintScannerError = { biometric: Biometrics } & Errors;
export interface FingerPrintProps {
/**
### release(): (Android)
Stops fingerprint scanner listener, releases cache of internal state in native code.
- Returns a `void`
-------------------
Example
```
componentWillUnmount() {
FingerprintScanner.release();
}
```
*/
release: () => void;
/**
### isSensorAvailable(): (Android, iOS)
Checks if Fingerprint Scanner is able to be used by now.
- Returns a `Promise<Biometrics>`
- `biometryType`: *String* - The type of biometric authentication supported by the device.
- `error: FingerprintScannerError { name, message, biometric }` - The name and message of failure and the biometric type in use.
-------------
Example
```
FingerprintScanner
.isSensorAvailable()
.then(biometryType => this.setState({ biometryType }))
.catch(error => this.setState({ errorMessage: error.message }));
```
------------
*/
isSensorAvailable: () => Promise<Biometrics>;
/**
### authenticate({ description, fallbackEnabled }): (iOS)
- Returns a `Promise`
- `description: String` - the string to explain the request for user authentication.
- `fallbackEnabled: Boolean` - default to ***true***, whether to display fallback button (e.g. Enter Password).
----------------
- Example:
```
FingerprintScanner
.authenticate({ description: 'Scan your fingerprint on the device scanner to continue' })
.then(() => {
this.props.handlePopupDismissed();
AlertIOS.alert('Authenticated successfully');
})
.catch((error) => {
this.props.handlePopupDismissed();
AlertIOS.alert(error.message);
});
```
-----------------
### authenticate({ description: 'Log in with Biometrics', onAttempt: () => (null) }): (Android)
- Returns a `Promise`
- `description: String` - the title text to appear on the native Android prompt
- `onAttempt: Function` - a callback function when users are trying to scan their fingerprint but failed.
-----------------
- Example:
```
FingerprintScanner
.authenticate({
description: 'Log in with Biometrics',
onAttempt: this.handleAuthenticationAttempted,
})
.then(() => {
this.props.handlePopupDismissed();
Alert.alert('Fingerprint Authentication', 'Authenticated successfully');
})
.catch((error) => {
this.setState({ errorMessage: error.message });
this.description.shake();
});
```
-----------------
*/
authenticate: (
platformProps: AuthenticateIOS | AuthenticateAndroid
) => Promise<void>;
}
declare const FingerprintScanner: FingerPrintProps;
export default FingerprintScanner;