1 |
|
2 |
|
3 | import { Platform, NativeModules } from 'react-native';
|
4 | import invariant from 'invariant';
|
5 |
|
6 | const { ExponentFingerprint } = NativeModules;
|
7 |
|
8 | type FingerprintAuthenticationResult = {
|
9 | success: boolean,
|
10 | error: any,
|
11 | };
|
12 |
|
13 | export function hasHardwareAsync(): Promise<boolean> {
|
14 | return ExponentFingerprint.hasHardwareAsync();
|
15 | }
|
16 |
|
17 | export function isEnrolledAsync(): Promise<boolean> {
|
18 | return ExponentFingerprint.isEnrolledAsync();
|
19 | }
|
20 |
|
21 | export function authenticateAsync(
|
22 | promptMessageIOS?: string = 'Authenticate'
|
23 | ): Promise<FingerprintAuthenticationResult> {
|
24 | if (Platform.OS === 'ios') {
|
25 | invariant(
|
26 | typeof promptMessageIOS === 'string' && promptMessageIOS.length,
|
27 | 'Fingerprint.authenticateAsync must be called with a non-empty string on iOS'
|
28 | );
|
29 | return ExponentFingerprint.authenticateAsync(promptMessageIOS);
|
30 | } else {
|
31 | return ExponentFingerprint.authenticateAsync();
|
32 | }
|
33 | }
|
34 |
|
35 | export function cancelAuthenticate(): void {
|
36 | ExponentFingerprint.cancelAuthenticate();
|
37 | }
|