UNPKG

1 kBJavaScriptView Raw
1// @flow
2
3import { Platform, NativeModules } from 'react-native';
4import invariant from 'invariant';
5
6const { ExponentFingerprint } = NativeModules;
7
8type FingerprintAuthenticationResult = {
9 success: boolean,
10 error: any,
11};
12
13export function hasHardwareAsync(): Promise<boolean> {
14 return ExponentFingerprint.hasHardwareAsync();
15}
16
17export function isEnrolledAsync(): Promise<boolean> {
18 return ExponentFingerprint.isEnrolledAsync();
19}
20
21export 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
35export function cancelAuthenticate(): void {
36 ExponentFingerprint.cancelAuthenticate();
37}