|
| 1 | +export type AuthenticateIOS = { |
| 2 | + description: string; |
| 3 | + fallbackEnabled: boolean; |
| 4 | +}; |
| 5 | +export type AuthenticateAndroid = { onAttempt: () => void }; |
| 6 | + |
| 7 | +export type Biometrics = 'Touch ID' | 'Face ID' | 'Fingerprint'; |
| 8 | + |
| 9 | +export type Errors = |
| 10 | + | { name: 'AuthenticationNotMatch'; message: 'No match' } |
| 11 | + | { |
| 12 | + name: 'AuthenticationFailed'; |
| 13 | + message: 'Authentication was not successful because the user failed to provide valid credentials'; |
| 14 | + } |
| 15 | + | { |
| 16 | + name: 'UserCancel'; |
| 17 | + message: 'Authentication was canceled by the user - e.g. the user tapped Cancel in the dialog'; |
| 18 | + } |
| 19 | + | { |
| 20 | + name: 'UserFallback'; |
| 21 | + message: 'Authentication was canceled because the user tapped the fallback button (Enter Password)'; |
| 22 | + } |
| 23 | + | { |
| 24 | + name: 'SystemCancel'; |
| 25 | + message: 'Authentication was canceled by system - e.g. if another application came to foreground while the authentication dialog was up'; |
| 26 | + } |
| 27 | + | { |
| 28 | + name: 'PasscodeNotSet'; |
| 29 | + message: 'Authentication could not start because the passcode is not set on the device'; |
| 30 | + } |
| 31 | + | { |
| 32 | + name: 'FingerprintScannerNotAvailable'; |
| 33 | + message: ' Authentication could not start because Fingerprint Scanner is not available on the device'; |
| 34 | + } |
| 35 | + | { |
| 36 | + name: 'FingerprintScannerNotEnrolled'; |
| 37 | + message: ' Authentication could not start because Fingerprint Scanner has no enrolled fingers'; |
| 38 | + } |
| 39 | + | { |
| 40 | + name: 'FingerprintScannerUnknownError'; |
| 41 | + message: 'Could not authenticate for an unknown reason'; |
| 42 | + } |
| 43 | + | { |
| 44 | + name: 'FingerprintScannerNotSupported'; |
| 45 | + message: 'Device does not support Fingerprint Scanner'; |
| 46 | + } |
| 47 | + | { |
| 48 | + name: 'DeviceLocked'; |
| 49 | + message: 'Authentication was not successful, the device currently in a lockout of 30 seconds'; |
| 50 | + }; |
| 51 | + |
| 52 | +export type FingerprintScannerError = { biometric: Biometrics } & Errors; |
| 53 | + |
| 54 | +export interface FingerPrintProps { |
| 55 | + /** |
| 56 | + ### release(): (Android) |
| 57 | + Stops fingerprint scanner listener, releases cache of internal state in native code. |
| 58 | + - Returns a `void` |
| 59 | +
|
| 60 | + ------------------- |
| 61 | + Exemple |
| 62 | + |
| 63 | + ``` |
| 64 | + componentWillUnmount() { |
| 65 | + FingerprintScanner.release(); |
| 66 | + } |
| 67 | + ``` |
| 68 | + */ |
| 69 | + release: () => void; |
| 70 | + |
| 71 | + /** |
| 72 | + ### isSensorAvailable(): (Android, iOS) |
| 73 | + Checks if Fingerprint Scanner is able to be used by now. |
| 74 | + - Returns a `Promise<string>` |
| 75 | + - `biometryType`: *String* - The type of biometric authentication supported by the device. |
| 76 | + - `error: FingerprintScannerError { name, message, biometric }` - The name and message of failure and the biometric type in use. |
| 77 | + |
| 78 | + ------------- |
| 79 | + Exemple |
| 80 | +
|
| 81 | + ``` |
| 82 | + FingerprintScanner |
| 83 | + .isSensorAvailable() |
| 84 | + .then(biometryType => this.setState({ biometryType })) |
| 85 | + .catch(error => this.setState({ errorMessage: error.message })); |
| 86 | + ``` |
| 87 | +
|
| 88 | + ------------ |
| 89 | + */ |
| 90 | + isSensorAvailable: () => Promise<string>; |
| 91 | + |
| 92 | + /** |
| 93 | + ### authenticate({ description, fallbackEnabled }): (iOS) |
| 94 | +
|
| 95 | + - Returns a `Promise` |
| 96 | + - `description: String` - the string to explain the request for user authentication. |
| 97 | + - `fallbackEnabled: Boolean` - default to ***true***, whether to display fallback button (e.g. Enter Password). |
| 98 | +
|
| 99 | + ---------------- |
| 100 | + - Example: |
| 101 | + ``` |
| 102 | + FingerprintScanner |
| 103 | + .authenticate({ description: 'Scan your fingerprint on the device scanner to continue' }) |
| 104 | + .then(() => { |
| 105 | + this.props.handlePopupDismissed(); |
| 106 | + AlertIOS.alert('Authenticated successfully'); |
| 107 | + }) |
| 108 | + .catch((error) => { |
| 109 | + this.props.handlePopupDismissed(); |
| 110 | + AlertIOS.alert(error.message); |
| 111 | + }); |
| 112 | + ``` |
| 113 | + ----------------- |
| 114 | + |
| 115 | + ### authenticate({ onAttempt }): (Android) |
| 116 | +
|
| 117 | + - Returns a `Promise` |
| 118 | + - `onAttempt: Function` - a callback function when users are trying to scan their fingerprint but failed. |
| 119 | +
|
| 120 | + ----------------- |
| 121 | + - Example: |
| 122 | + ``` |
| 123 | + FingerprintScanner |
| 124 | + .authenticate({ onAttempt: this.handleAuthenticationAttempted }) |
| 125 | + .then(() => { |
| 126 | + this.props.handlePopupDismissed(); |
| 127 | + Alert.alert('Fingerprint Authentication', 'Authenticated successfully'); |
| 128 | + }) |
| 129 | + .catch((error) => { |
| 130 | + this.setState({ errorMessage: error.message }); |
| 131 | + this.description.shake(); |
| 132 | + }); |
| 133 | + ``` |
| 134 | + ----------------- |
| 135 | + */ |
| 136 | + authenticate: ( |
| 137 | + platformProps: AuthenticateIOS | AuthenticateAndroid |
| 138 | + ) => Promise<void>; |
| 139 | +} |
| 140 | + |
| 141 | +declare const FingerprintScanner: FingerPrintProps; |
| 142 | + |
| 143 | +export default FingerprintScanner; |
0 commit comments