-
-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathcommon.ts
144 lines (129 loc) · 3.89 KB
/
common.ts
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
export enum ERROR_CODES {
PASSWORD_FALLBACK_SELECTED = -3, // historically this is what iOS uses, so using that as well
SUCCESS = 0,
DEVELOPER_ERROR = 10,
NOT_AVAILABLE = 20,
NOT_CONFIGURED = 30,
NOT_RECOGNIZED = 40,
RECOVERABLE_ERROR = 50,
USER_CANCELLED = 60,
UNEXPECTED_ERROR = 70,
}
export interface VerifyBiometricOptions {
/**
* The required title in the fingerprint page for android.
* Default: whatever the device default is ('Confirm your password' is likely)
*/
title?: string;
/**
* The optional subtitle in the fingerprint page for android.
* Default: Empty
*/
subTitle?: string;
/**
* The optional message in the fingerprint dialog on ios and page description on android.
* Default: 'Scan your finger' on iOS and the device default on Android (which is likely 'Enter your device password to continue').
*/
message?: string; // Used IOS
/**
* The optional confirm button after biometrics have been verified in the fingerprint page for android.
* Default: False
*/
confirm?: boolean;
/**
* The optional button label when scanning the fingerprint fails.
* Default: 'Enter password'.
*
* Android: When pinFallback is true this will be the text displayed on the pin dialog.
* When pinFallback is false this will be the Negative button text on the Biometric Prompt.
*/
fallbackMessage?: string; // Used IOS
/***
* Allow Fallback to Pin - note if true no cryptographic operations will happen and face id is not available on android.
*/
pinFallback?: boolean;
/**
* Name of the key to use for crypto operations.
*
* Will be created if it does not exist.
* Is not used if pinFallback is true.
*/
keyName?: string;
/**
* If set and pinFallback is true, and keyName is set then this string will be encrypted via the Biometric controlled Key (Android ) or stored (IOS).
*/
secret?: string;
android?: AndroidOptions;
ios?: IOSOptions;
}
export interface IOSOptions {
/** Allow a custom fallback from biometrics */
customFallback?: boolean;
/** Attempt to fetch secret from the specified key */
fetchSecret?: boolean;
}
export interface AndroidOptions {
/**
* If set and pinFallback is true, and keyName is set then this string will be decrypted via the Biometric controlled Key.
*/
decryptText?: string;
/**
* Required id decryptText is set.
*
* Retrieved from the result of an encryption.
*/
iv?: string;
/**
* The period in seconds for which operations on the key are valid without triggering a biometric prompt.
*/
validityDuration?: number;
}
export interface BiometricIDAvailableResult {
/**
* Has Bio
*
* Note: will be true if no bio available on android but device is secure ( has pin etc. set).
*/
any: boolean;
/***
* IOS Only
*/
touch?: boolean;
/***
* IOS Only
*/
face?: boolean;
/***
* Android Only indicates one of Face/Fingerprint available.
*/
biometrics?: boolean;
}
//noinspection JSUnusedGlobalSymbols
export interface BiometricApi {
available(): Promise<BiometricIDAvailableResult>;
didBiometricDatabaseChange(): Promise<boolean>;
/**
* This (recommended) method uses keychain instead of localauth so the passcode fallback can be used.
* On Android, when 'useCustomAndroidUI' is set to 'true', and the user opted for manually entering the password,
* this method may return a string (the entered password) for you to compare to the actual password.
*/
verifyBiometric(options: VerifyBiometricOptions): Promise<BiometricResult>;
/**
* Note will not do anything on android if using pin fallback.
*/
close(): void;
/**
*
* When using encryption backed biometrics keys are generated, this allow you to remove the key.
*
* @param keyName Optional keyName to delete, if not supplied will delete the default key.
*/
deleteKey(keyName?: string): void;
}
export interface BiometricResult {
code: ERROR_CODES;
message: string;
encrypted?: string;
decrypted?: string;
iv?: string;
}