This repository has been archived by the owner on Apr 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.android.js
68 lines (57 loc) · 2.29 KB
/
index.android.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
/* @flow */
'use strict';
import { NativeModules, DeviceEventEmitter} from 'react-native';
const FingerprintAndroidNative = NativeModules.FingerprintAndroid;
const OVERRIDDEN_METHODS = ["authenticate"];
export interface FingerprintError {
code: number;
message: string;
}
const nop = () => console.warn("NOP'd function called! This should never happen!");
class FingerprintAndroid {
//nop functions because I love my autocomplete
static cancelAuthentication(): Promise<null> { nop() };
static isAuthenticationCanceled(): Promise<boolean> { nop() };
static hasPermission(): Promise<boolean> { nop() };
static hasEnrolledFingerprints(): Promise<boolean> { nop() };
static isHardwareDetected(): Promise<boolean> { nop() };
//constants
static FINGERPRINT_ACQUIRED_GOOD:string;
static FINGERPRINT_ACQUIRED_IMAGER_DIRTY:string;
static FINGERPRINT_ACQUIRED_INSUFFICIENT:string;
static FINGERPRINT_ACQUIRED_PARTIAL:string;
static FINGERPRINT_ACQUIRED_TOO_FAST:string;
static FINGERPRINT_ACQUIRED_TOO_SLOW:string;
static FINGERPRINT_ERROR_CANCELED:string;
static FINGERPRINT_ERROR_HW_UNAVAILABLE:string;
static FINGERPRINT_ERROR_LOCKOUT:string;
static FINGERPRINT_ERROR_NO_SPACE:string;
static FINGERPRINT_ERROR_TIMEOUT:string;
static FINGERPRINT_ERROR_UNABLE_TO_PROCESS:string;
static FINGERPRINT_ERROR_AUTH_FAILED:string;
static async authenticate(warningCallback:?(response:FingerprintError) => {}):Promise<null> {
if(typeof warningCallback === "function") {
DeviceEventEmitter.addListener('fingerPrintAuthenticationHelp', warningCallback);
}
let err;
try {
await FingerprintAndroidNative.authenticate();
} catch(ex) {
err = ex
}
finally {
//remove the subscriptions and crash if needed
DeviceEventEmitter.removeAllListeners("fingerPrintAuthenticationHelp");
if(err) {
throw err
}
}
}
}
//add all available functions from the native module (besides authenticate)
Object.keys(FingerprintAndroidNative).forEach(key => {
if (OVERRIDDEN_METHODS.indexOf(key) === -1) {
FingerprintAndroid[key] = FingerprintAndroidNative[key];
}
});
export default FingerprintAndroid;