2019-09-25 05:42:21 +02:00
|
|
|
import Biometrics from 'react-native-biometrics';
|
|
|
|
const BlueApp = require('../BlueApp');
|
|
|
|
|
|
|
|
export default class Biometric {
|
|
|
|
static STORAGEKEY = 'Biometrics';
|
2019-10-06 00:36:16 +02:00
|
|
|
static FaceID = Biometrics.FaceID;
|
|
|
|
static TouchID = Biometrics.TouchID;
|
2019-11-27 18:47:21 +01:00
|
|
|
static Biometrics = Biometrics.Biometrics;
|
2019-09-25 05:42:21 +02:00
|
|
|
|
|
|
|
static async isDeviceBiometricCapable() {
|
2019-11-27 18:47:21 +01:00
|
|
|
const isDeviceBiometricCapable = await Biometrics.isSensorAvailable();
|
|
|
|
if (isDeviceBiometricCapable.available) {
|
|
|
|
return true;
|
2019-09-25 05:42:21 +02:00
|
|
|
}
|
|
|
|
Biometric.setBiometricUseEnabled(false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static async biometricType() {
|
2019-10-29 23:13:19 +01:00
|
|
|
try {
|
|
|
|
const isSensorAvailable = await Biometrics.isSensorAvailable();
|
2019-11-27 18:47:21 +01:00
|
|
|
return isSensorAvailable.biometryType;
|
2019-10-29 23:13:19 +01:00
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
return false;
|
2019-09-25 05:42:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static async isBiometricUseEnabled() {
|
|
|
|
try {
|
|
|
|
const enabledBiometrics = await BlueApp.getItem(Biometric.STORAGEKEY);
|
|
|
|
return !!enabledBiometrics;
|
|
|
|
} catch (_e) {
|
|
|
|
await BlueApp.setItem(Biometric.STORAGEKEY, '');
|
2019-10-06 00:36:16 +02:00
|
|
|
return false;
|
2019-09-25 05:42:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static async isBiometricUseCapableAndEnabled() {
|
|
|
|
const isBiometricUseEnabled = await Biometric.isBiometricUseEnabled();
|
|
|
|
const isDeviceBiometricCapable = await Biometric.isDeviceBiometricCapable();
|
2019-10-06 00:36:16 +02:00
|
|
|
return isBiometricUseEnabled && isDeviceBiometricCapable;
|
2019-09-25 05:42:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static async setBiometricUseEnabled(value) {
|
|
|
|
await BlueApp.setItem(Biometric.STORAGEKEY, value === true ? '1' : '');
|
|
|
|
}
|
|
|
|
|
|
|
|
static async unlockWithBiometrics() {
|
|
|
|
const isDeviceBiometricCapable = await Biometric.isDeviceBiometricCapable();
|
|
|
|
if (isDeviceBiometricCapable) {
|
|
|
|
try {
|
2019-11-27 18:47:21 +01:00
|
|
|
const isConfirmed = await Biometrics.simplePrompt({ promptMessage: 'Please confirm your identity.' });
|
|
|
|
return isConfirmed.success;
|
2019-09-25 05:42:21 +02:00
|
|
|
} catch (_e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|