1import { UnavailabilityError } from 'expo-modules-core'; 2import invariant from 'invariant'; 3import ExpoLocalAuthentication from './ExpoLocalAuthentication'; 4import { AuthenticationType, SecurityLevel, } from './LocalAuthentication.types'; 5export { AuthenticationType, SecurityLevel }; 6// @needsAudit 7/** 8 * Determine whether a face or fingerprint scanner is available on the device. 9 * @return Returns a promise which fulfils with a `boolean` value indicating whether a face or 10 * fingerprint scanner is available on this device. 11 */ 12export async function hasHardwareAsync() { 13 if (!ExpoLocalAuthentication.hasHardwareAsync) { 14 throw new UnavailabilityError('expo-local-authentication', 'hasHardwareAsync'); 15 } 16 return await ExpoLocalAuthentication.hasHardwareAsync(); 17} 18// @needsAudit 19/** 20 * Determine what kinds of authentications are available on the device. 21 * @return Returns a promise which fulfils to an array containing [`AuthenticationType`s](#authenticationtype). 22 * 23 * Devices can support multiple authentication methods- i.e. `[1,2]` means the device supports both 24 * fingerprint and facial recognition. If none are supported, this method returns an empty array. 25 */ 26export async function supportedAuthenticationTypesAsync() { 27 if (!ExpoLocalAuthentication.supportedAuthenticationTypesAsync) { 28 throw new UnavailabilityError('expo-local-authentication', 'supportedAuthenticationTypesAsync'); 29 } 30 return await ExpoLocalAuthentication.supportedAuthenticationTypesAsync(); 31} 32// @needsAudit 33/** 34 * Determine whether the device has saved fingerprints or facial data to use for authentication. 35 * @return Returns a promise which fulfils to `boolean` value indicating whether the device has 36 * saved fingerprints or facial data for authentication. 37 */ 38export async function isEnrolledAsync() { 39 if (!ExpoLocalAuthentication.isEnrolledAsync) { 40 throw new UnavailabilityError('expo-local-authentication', 'isEnrolledAsync'); 41 } 42 return await ExpoLocalAuthentication.isEnrolledAsync(); 43} 44// @needsAudit 45/** 46 * Determine what kind of authentication is enrolled on the device. 47 * @return Returns a promise which fulfils with [`SecurityLevel`](#securitylevel). 48 * > **Note:** On Android devices prior to M, `SECRET` can be returned if only the SIM lock has been 49 * enrolled, which is not the method that [`authenticateAsync`](#localauthenticationauthenticateasyncoptions) 50 * prompts. 51 */ 52export async function getEnrolledLevelAsync() { 53 if (!ExpoLocalAuthentication.getEnrolledLevelAsync) { 54 throw new UnavailabilityError('expo-local-authentication', 'getEnrolledLevelAsync'); 55 } 56 return await ExpoLocalAuthentication.getEnrolledLevelAsync(); 57} 58// @needsAudit 59/** 60 * Attempts to authenticate via Fingerprint/TouchID (or FaceID if available on the device). 61 * > **Note:** Apple requires apps which use FaceID to provide a description of why they use this API. 62 * If you try to use FaceID on an iPhone with FaceID without providing `infoPlist.NSFaceIDUsageDescription` 63 * in `app.json`, the module will authenticate using device passcode. For more information about 64 * usage descriptions on iOS, see [permissions guide](/guides/permissions/#ios). 65 * @param options 66 * @return Returns a promise which fulfils with [`LocalAuthenticationResult`](#localauthenticationresult). 67 */ 68export async function authenticateAsync(options = {}) { 69 if (!ExpoLocalAuthentication.authenticateAsync) { 70 throw new UnavailabilityError('expo-local-authentication', 'authenticateAsync'); 71 } 72 if (options.hasOwnProperty('promptMessage')) { 73 invariant(typeof options.promptMessage === 'string' && options.promptMessage.length, 'LocalAuthentication.authenticateAsync : `options.promptMessage` must be a non-empty string.'); 74 } 75 const promptMessage = options.promptMessage || 'Authenticate'; 76 const result = await ExpoLocalAuthentication.authenticateAsync({ ...options, promptMessage }); 77 return result; 78} 79// @needsAudit 80/** 81 * Cancels authentication flow. 82 * @platform android 83 */ 84export async function cancelAuthenticate() { 85 if (!ExpoLocalAuthentication.cancelAuthenticate) { 86 throw new UnavailabilityError('expo-local-authentication', 'cancelAuthenticate'); 87 } 88 await ExpoLocalAuthentication.cancelAuthenticate(); 89} 90//# sourceMappingURL=LocalAuthentication.js.map