forked from kryptonite07/Smart-Contract-Development-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
biometrics.js
61 lines (54 loc) · 1.79 KB
/
biometrics.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import Biometrics from 'react-native-biometrics';
const BlueApp = require('../BlueApp');
export default class Biometric {
static STORAGEKEY = 'Biometrics';
static FaceID = Biometrics.FaceID;
static TouchID = Biometrics.TouchID;
static Biometrics = Biometrics.Biometrics;
static async isDeviceBiometricCapable() {
const isDeviceBiometricCapable = await Biometrics.isSensorAvailable();
if (isDeviceBiometricCapable.available) {
return true;
}
Biometric.setBiometricUseEnabled(false);
return false;
}
static async biometricType() {
try {
const isSensorAvailable = await Biometrics.isSensorAvailable();
return isSensorAvailable.biometryType;
} catch (e) {
console.log(e);
}
return false;
}
static async isBiometricUseEnabled() {
try {
const enabledBiometrics = await BlueApp.getItem(Biometric.STORAGEKEY);
return !!enabledBiometrics;
} catch (_e) {
await BlueApp.setItem(Biometric.STORAGEKEY, '');
return false;
}
}
static async isBiometricUseCapableAndEnabled() {
const isBiometricUseEnabled = await Biometric.isBiometricUseEnabled();
const isDeviceBiometricCapable = await Biometric.isDeviceBiometricCapable();
return isBiometricUseEnabled && isDeviceBiometricCapable;
}
static async setBiometricUseEnabled(value) {
await BlueApp.setItem(Biometric.STORAGEKEY, value === true ? '1' : '');
}
static async unlockWithBiometrics() {
const isDeviceBiometricCapable = await Biometric.isDeviceBiometricCapable();
if (isDeviceBiometricCapable) {
try {
const isConfirmed = await Biometrics.simplePrompt({ promptMessage: 'Please confirm your identity.' });
return isConfirmed.success;
} catch (_e) {
return false;
}
}
return false;
}
}