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