-
Notifications
You must be signed in to change notification settings - Fork 54
/
index.js
103 lines (94 loc) · 2.86 KB
/
index.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { NativeModules, Platform } from 'react-native';
const { RNSecureStorage } = NativeModules;
export const ACCESSIBLE = {
WHEN_UNLOCKED: 'AccessibleWhenUnlocked',
AFTER_FIRST_UNLOCK: 'AccessibleAfterFirstUnlock',
ALWAYS: 'AccessibleAlways',
WHEN_PASSCODE_SET_THIS_DEVICE_ONLY: 'AccessibleWhenPasscodeSetThisDeviceOnly',
WHEN_UNLOCKED_THIS_DEVICE_ONLY: 'AccessibleWhenUnlockedThisDeviceOnly',
AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY:
'AccessibleAfterFirstUnlockThisDeviceOnly',
ALWAYS_THIS_DEVICE_ONLY: 'AccessibleAlwaysThisDeviceOnly',
};
export const ACCESS_CONTROL = {
USER_PRESENCE: 'UserPresence',
BIOMETRY_ANY: 'BiometryAny',
BIOMETRY_CURRENT_SET: 'BiometryCurrentSet',
DEVICE_PASSCODE: 'DevicePasscode',
APPLICATION_PASSWORD: 'ApplicationPassword',
BIOMETRY_ANY_OR_DEVICE_PASSCODE: 'BiometryAnyOrDevicePasscode',
BIOMETRY_CURRENT_SET_OR_DEVICE_PASSCODE: 'BiometryCurrentSetOrDevicePasscode',
};
export const AUTHENTICATION_TYPE = {
DEVICE_PASSCODE_OR_BIOMETRICS: 'AuthenticationWithBiometricsDevicePasscode',
BIOMETRICS: 'AuthenticationWithBiometrics',
};
export const BIOMETRY_TYPE = {
TOUCH_ID: 'TouchID',
FACE_ID: 'FaceID',
FINGERPRINT: 'Fingerprint',
};
const isAndroid = Platform.OS === 'android'
const defaultOptions = {
accessControl: null,
accessible: ACCESSIBLE.WHEN_UNLOCKED,
accessGroup: null,
authenticationPrompt: 'Authenticate to retrieve secret data',
service: null,
authenticateType: AUTHENTICATION_TYPE.DEVICE_PASSCODE_OR_BIOMETRICS,
}
export default {
getItem(key, options) {
const finalOptions = {
...defaultOptions,
...options,
}
if (isAndroid) {
return RNSecureStorage.getItem(key, finalOptions.service)
}
return RNSecureStorage.getItem(key, finalOptions)
},
setItem(key, value, options) {
const finalOptions = {
...defaultOptions,
...options,
}
if (isAndroid) {
return RNSecureStorage.setItem(key, value, finalOptions.service)
}
return RNSecureStorage.setItem(key, value, finalOptions)
},
removeItem(key, options) {
const finalOptions = {
...defaultOptions,
...options,
}
if (isAndroid) {
return RNSecureStorage.removeItem(key, finalOptions.service)
}
return RNSecureStorage.removeItem(key, finalOptions)
},
getAllKeys(options) {
const finalOptions = {
...defaultOptions,
...options,
}
if (isAndroid) {
return RNSecureStorage.getAllKeys(finalOptions.service)
}
return RNSecureStorage.getAllKeys(finalOptions)
},
getSupportedBiometryType() {
return RNSecureStorage.getSupportedBiometryType()
},
canCheckAuthentication(options) {
const finalOptions = {
...defaultOptions,
...options,
}
if (isAndroid) {
return RNSecureStorage.getSupportedBiometryType() !== null
}
return RNSecureStorage.canCheckAuthentication(options)
},
}