react-native-biometric-verifier 0.0.64 → 0.0.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +212 -75
  2. package/package.json +2 -1
  3. package/src/index.d.ts +303 -0
package/README.md CHANGED
@@ -1,116 +1,253 @@
1
1
  # React Native Biometric Verifier
2
-
3
- A powerful and easy-to-use React Native module for biometric verification, featuring face recognition and QR code scanning capabilities with location validation.
4
-
5
-
6
- ## Features
7
-
8
- - **Face Recognition**: Capture and verify user identity via face scan.
9
- - **QR Code Scanning**: specialized mode for location verification using QR codes.
10
- - **Location Validation**: Verify user presence within a specific geofence.
11
- - **Liveness Detection**: Configurable liveness and anti-spoofing checks.
12
- - **Customizable UI**: Animations, countdown timers, and feedback notifications.
13
-
14
- ## Installation
15
-
2
+
3
+ A beginner-friendly React Native package for biometric verification with camera-based face recognition, optional QR-based location validation, and liveness checks.
4
+
5
+ This component is built so any React Native app can securely verify a user by combining:
6
+ - Face scan
7
+ - GPS location check
8
+ - QR metadata validation
9
+ - Liveness / anti-spoof detection
10
+
11
+ ---
12
+
13
+ ## ✅ What this package does
14
+
15
+ - Opens a verification modal with camera preview.
16
+ - Detects and captures a single face using the front camera.
17
+ - Optionally scans a QR code first to validate location.
18
+ - Uses GPS to confirm the user is within a valid radius.
19
+ - Sends face image data to a backend API for recognition.
20
+ - Displays status messages, countdown timer, and success/error feedback.
21
+
22
+ ---
23
+
24
+ ## 🔧 Features
25
+
26
+ - Face recognition workflow
27
+ - QR-based location verification
28
+ - Distance check using GPS coordinates
29
+ - Liveness and anti-spoof checks
30
+ - Countdown timer for verification sessions
31
+ - Animated notifications and progress state
32
+
33
+ ---
34
+
35
+ ## 🚀 Installation
36
+
16
37
  ```bash
17
38
  npm install react-native-biometric-verifier
18
39
  ```
19
-
20
- ### Peer Dependencies
21
-
22
- This library relies on several peer dependencies that you must install in your project:
23
-
40
+
41
+ ### Required peer dependencies
42
+
24
43
  ```bash
25
44
  npm install react-native-vector-icons react-native-geolocation-service react-native-image-resizer react-native-fs prop-types
26
45
  ```
27
-
28
- ### Platform Configuration
29
-
30
- #### iOS
31
- Add the following keys to your `Info.plist` file to request camera and location permissions:
32
-
46
+
47
+ > The package also depends on native camera and vision packages internally. Make sure your app is configured for camera access.
48
+
49
+ ---
50
+
51
+ ## 📱 Platform setup
52
+
53
+ ### iOS
54
+ Add these keys to `Info.plist`:
55
+
33
56
  ```xml
34
57
  <key>NSCameraUsageDescription</key>
35
- <string>We need access to your camera for biometric verification</string>
58
+ <string>We need access to your camera for biometric verification.</string>
36
59
  <key>NSLocationWhenInUseUsageDescription</key>
37
- <string>We need your location to verify your presence at the designated area</string>
60
+ <string>We need your location to verify your presence at the designated area.</string>
38
61
  ```
39
-
40
- #### Android
41
- Add the following permissions to your `AndroidManifest.xml`:
42
-
62
+
63
+ ### Android
64
+ Add these permissions to `AndroidManifest.xml`:
65
+
43
66
  ```xml
44
67
  <uses-permission android:name="android.permission.CAMERA" />
45
68
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
46
69
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
47
70
  ```
48
-
49
- ## Usage
50
-
51
- Import the `BiometricModal` component and standard React hooks.
52
-
71
+
72
+ ---
73
+
74
+ ## 📘 Basic Usage
75
+
53
76
  ```javascript
54
77
  import React, { useState } from 'react';
55
78
  import { View, Button } from 'react-native';
56
79
  import BiometricModal from 'react-native-biometric-verifier';
57
-
58
- const App = () => {
80
+
81
+ const App = ({ navigation }) => {
59
82
  const [isVerifierOpen, setIsVerifierOpen] = useState(false);
60
-
61
- const handleVerificationComplete = (data) => {
62
- console.log('Verification Success:', data);
63
- // Handle success (e.g., navigate to next screen, show success message)
83
+
84
+ const handleVerificationComplete = (result) => {
85
+ console.log('Verification successful:', result);
64
86
  setIsVerifierOpen(false);
65
87
  };
66
-
88
+
67
89
  return (
68
90
  <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
69
91
  <Button title="Start Verification" onPress={() => setIsVerifierOpen(true)} />
70
-
92
+
71
93
  {isVerifierOpen && (
72
94
  <BiometricModal
73
- data="USER_UNIQUE_ID" // e.g., Employee ID or Face ID
74
- depKey="DEPARTMENT_KEY" // Optional: for QR location validation
95
+ data="USER_UNIQUE_ID"
75
96
  apiurl="https://your-api-endpoint.com/"
76
- onclose={(val) => setIsVerifierOpen(val)}
97
+ navigation={navigation}
98
+ onclose={(open) => setIsVerifierOpen(open)}
77
99
  callback={handleVerificationComplete}
78
- // Optional Props
79
- qrscan={false} // Set to true to enable QR scan mode first
80
- duration={100} // Countdown duration in seconds
81
- MaxDistanceMeters={30} // Allowed radius for location verification
100
+ qrscan={false}
101
+ duration={100}
102
+ MaxDistanceMeters={30}
82
103
  frameProcessorFps={5}
83
- livenessLevel="high"
84
- antispooflevel="high"
104
+ livenessLevel={1}
105
+ antispooflevel={0.35}
85
106
  />
86
107
  )}
87
108
  </View>
88
109
  );
89
110
  };
90
-
111
+
91
112
  export default App;
92
113
  ```
93
-
94
- ## Props
95
-
114
+
115
+ > `navigation` is required because the component may call `navigation.goBack()` when the verification timer expires.
116
+
117
+ ---
118
+
119
+ ## 🧠 How the verification flow works
120
+
121
+ The component supports two main flows:
122
+
123
+ 1. **Face verification only** (`qrscan={false}`)
124
+ - Open the front camera.
125
+ - Detect a single centered face.
126
+ - Optionally perform liveness checks.
127
+ - Capture the face image.
128
+ - Send the image to the backend API.
129
+
130
+ 2. **QR + face verification** (`qrscan={true}`)
131
+ - Open the back camera.
132
+ - Scan a QR code containing `latitude,longitude,depKey`.
133
+ - Request current device GPS location.
134
+ - Verify the device is within `MaxDistanceMeters`.
135
+ - Verify the QR `depKey` matches the `depKey` prop.
136
+ - Continue to face verification after location validation.
137
+
138
+ ---
139
+
140
+ ## 🌐 Workflow diagram
141
+
142
+ ```mermaid
143
+ flowchart TD
144
+ A[Start Verification] --> B{qrscan === true?}
145
+ B -- Yes --> C[Scan QR Code]
146
+ B -- No --> F[Start Face Scan]
147
+ C --> D[Request Device Location]
148
+ D --> E[Compare distance and depKey]
149
+ E -- Valid --> F
150
+ E -- Invalid --> G[Show location error]
151
+ F --> H[Detect stable face & liveness]
152
+ H --> I[Capture photo]
153
+ I --> J[Upload to API]
154
+ J --> K{API response}
155
+ K -- Success --> L[Show success and callback]
156
+ K -- Fail --> M[Show failure message]
157
+ ```
158
+
159
+ ---
160
+
161
+ ## 📌 Props reference
162
+
96
163
  | Prop | Type | Required | Description | Default |
97
164
  |------|------|----------|-------------|---------|
98
- | `apiurl` | string | Yes | Base URL for the verification backend API. | - |
99
- | `data` | string | Yes | Unique identifier for the user (e.g., Face ID, User ID). | - |
100
- | `onclose` | function | Yes | Callback function to close the modal. | - |
101
- | `callback` | function | Yes | Callback function returning successful verification data. | - |
102
- | `qrscan` | boolean | No | If `true`, starts with QR code scanning mode. | `false` |
103
- | `depKey` | string | No | Key used to validate the QR code content. | - |
104
- | `duration` | number | No | Timeout duration for the session in seconds. | `100` |
105
- | `MaxDistanceMeters` | number | No | Maximum allowed distance (meters) for location check. | `30` |
106
- | `frameProcessorFps` | number | No | Frames per second for image processing. | - |
107
- | `livenessLevel` | string | No | Liveness detection strictness. | - |
108
- | `antispooflevel` | string | No | Anti-spoofing strictness. | - |
109
-
110
- ## Contributing
111
-
112
- Contributions are welcome! Please open an issue or submit a pull request for any bugs or improvements.
113
-
114
- ## License
115
-
165
+ | `apiurl` | string | Yes | Base URL for the verification backend request. | - |
166
+ | `data` | string | Yes | Unique user identifier (employee ID, face ID, etc.). | - |
167
+ | `navigation` | object | Yes | React Navigation prop used for timeout navigation. | - |
168
+ | `onclose` | function | Yes | Called when the modal closes. Receives `false`. | - |
169
+ | `callback` | function | Yes | Called after successful verification with result data. | - |
170
+ | `qrscan` | boolean | No | Start with QR scan mode. | `false` |
171
+ | `depKey` | string | No | Expected key inside the scanned QR payload. | - |
172
+ | `duration` | number | No | Countdown length in seconds. | `100` |
173
+ | `MaxDistanceMeters` | number | No | Allowed GPS distance radius in meters. | `30` |
174
+ | `frameProcessorFps` | number | No | Camera frame processor FPS. | `5` |
175
+ | `livenessLevel` | number | No | Liveness check mode: `0` or `1`. | `0` |
176
+ | `antispooflevel` | number | No | Anti-spoof threshold used internally. | `0.35` |
177
+ | `fileurl` | string | No | Optional file URL for displaying employee data. | - |
178
+ | `imageurl` | string | No | Optional image URL for display. | - |
179
+
180
+ ---
181
+
182
+ ## 🧩 Example: face-only verification
183
+
184
+ ```javascript
185
+ <BiometricModal
186
+ data="EMPLOYEE_123"
187
+ apiurl="https://your-api-endpoint.com/"
188
+ navigation={navigation}
189
+ onclose={(open) => setIsVerifierOpen(open)}
190
+ callback={handleVerificationComplete}
191
+ qrscan={false}
192
+ duration={90}
193
+ frameProcessorFps={4}
194
+ livenessLevel={0}
195
+ />
196
+ ```
197
+
198
+ ## 🧭 Example: QR + face verification
199
+
200
+ ```javascript
201
+ <BiometricModal
202
+ data="EMPLOYEE_123"
203
+ depKey="OFFICE_A"
204
+ apiurl="https://your-api-endpoint.com/"
205
+ navigation={navigation}
206
+ onclose={(open) => setIsVerifierOpen(open)}
207
+ callback={handleVerificationComplete}
208
+ qrscan={true}
209
+ duration={120}
210
+ MaxDistanceMeters={50}
211
+ frameProcessorFps={3}
212
+ livenessLevel={1}
213
+ antispooflevel={0.35}
214
+ />
215
+ ```
216
+
217
+ ---
218
+
219
+ ## 🧱 Internal architecture
220
+
221
+ - `src/index.js` – Main `BiometricModal` component and verification flow.
222
+ - `src/components/CaptureImageWithoutEdit.js` – Camera capture, face detection, and QR scanning.
223
+ - `src/hooks/useFaceDetectionFrameProcessor.js` – Face liveness and anti-spoof frame processor.
224
+ - `src/hooks/useGeolocation.js` – Location permission and GPS fetch.
225
+ - `src/hooks/useImageProcessing.js` – Image resize and Base64 conversion.
226
+ - `src/hooks/useCountdown.js` – Countdown timer logic.
227
+ - `src/hooks/useNotifyMessage.js` – Animated notification messages.
228
+ - `src/utils/NetworkServiceCall.js` – API request helper.
229
+ - `src/utils/distanceCalculator.js` – Geolocation distance calculation.
230
+ - `src/utils/Global.js` – Shared constants and theme values.
231
+
232
+ ---
233
+
234
+ ## 💡 Interview talking points
235
+
236
+ - Explain the dual modes: face-only and QR-first.
237
+ - Describe how location validation prevents spoofing of presence.
238
+ - Mention the use of `use*` hooks for clean and reusable code.
239
+ - Highlight the flow from camera capture → Base64 conversion → API request → callback.
240
+ - Note the user-friendly UI with timer, notifications, and step indicator.
241
+
242
+ ---
243
+
244
+ ## 🤝 Contribution
245
+
246
+ Contributions are welcome. Open an issue or submit a pull request for bug fixes and improvements.
247
+
248
+ ---
249
+
250
+ ## 📄 License
251
+
116
252
  JESCON TECHNOLOGIES PVT LTD
253
+
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "react-native-biometric-verifier",
3
- "version": "0.0.64",
3
+ "version": "0.0.66",
4
4
  "description": "A React Native module for biometric verification with face recognition and QR code scanning",
5
5
  "main": "src/index.js",
6
+ "types": "src/index.d.ts",
6
7
  "scripts": {
7
8
  "test": "echo \"Error: no test specified\" && exit 1"
8
9
  },
package/src/index.d.ts ADDED
@@ -0,0 +1,303 @@
1
+ import React from 'react';
2
+ import { Animated, NavigationProp } from 'react-native';
3
+
4
+ // ============ COMPONENTS ============
5
+
6
+ /**
7
+ * Card component props
8
+ */
9
+ export interface CardProps {
10
+ employeeData: {
11
+ facename: string;
12
+ faceid: string;
13
+ imageurl?: string;
14
+ };
15
+ apiurl: string;
16
+ fileurl?: string;
17
+ }
18
+
19
+ /**
20
+ * Card component - displays employee information
21
+ */
22
+ export const Card: React.FC<CardProps>;
23
+
24
+ /**
25
+ * Loader component props
26
+ */
27
+ export interface LoaderProps {
28
+ state: {
29
+ isLoading: boolean;
30
+ loadingType: string;
31
+ currentStep: string;
32
+ animationState: string;
33
+ };
34
+ gifSource: { uri: string } | null;
35
+ }
36
+
37
+ /**
38
+ * Loader component - displays loading animation
39
+ */
40
+ export const Loader: React.FC<LoaderProps>;
41
+
42
+ /**
43
+ * CountdownTimer component props
44
+ */
45
+ export interface CountdownTimerProps {
46
+ duration: number;
47
+ currentTime: number;
48
+ }
49
+
50
+ /**
51
+ * CountdownTimer component - displays countdown timer
52
+ */
53
+ export const CountdownTimer: React.FC<CountdownTimerProps>;
54
+
55
+ /**
56
+ * Notification component props
57
+ */
58
+ export interface NotificationProps {
59
+ notification: {
60
+ visible: boolean;
61
+ message: string;
62
+ type: 'success' | 'error' | 'info' | 'warning';
63
+ };
64
+ fadeAnim: Animated.Value;
65
+ slideAnim: Animated.Value;
66
+ }
67
+
68
+ /**
69
+ * Notification component - displays notifications
70
+ */
71
+ export const Notification: React.FC<NotificationProps>;
72
+
73
+ /**
74
+ * CaptureImageWithoutEdit component props
75
+ */
76
+ export interface CaptureImageWithoutEditProps {
77
+ cameraType: 'front' | 'back';
78
+ onCapture: (capturedData: any) => void;
79
+ showCodeScanner?: boolean;
80
+ isLoading?: boolean;
81
+ frameProcessorFps?: number;
82
+ livenessLevel?: string;
83
+ antispooflevel?: string;
84
+ }
85
+
86
+ /**
87
+ * CaptureImageWithoutEdit component - captures images from camera
88
+ */
89
+ export const CaptureImageWithoutEdit: React.FC<CaptureImageWithoutEditProps>;
90
+
91
+ /**
92
+ * StepIndicator component props
93
+ */
94
+ export interface StepIndicatorProps {
95
+ currentStep: string;
96
+ qrscan?: boolean;
97
+ }
98
+
99
+ /**
100
+ * StepIndicator component - shows current verification step
101
+ */
102
+ export const StepIndicator: React.FC<StepIndicatorProps>;
103
+
104
+ // ============ HOOKS ============
105
+
106
+ /**
107
+ * useCountdown hook return type
108
+ */
109
+ export interface UseCountdownReturn {
110
+ countdown: number;
111
+ startCountdown: (onExpireCallback?: () => void) => void;
112
+ resetCountdown: () => void;
113
+ pauseCountdown: () => void;
114
+ resumeCountdown: () => void;
115
+ }
116
+
117
+ /**
118
+ * Custom hook for countdown timer with pause/resume functionality
119
+ */
120
+ export function useCountdown(duration: number, onExpire?: () => void): UseCountdownReturn;
121
+
122
+ /**
123
+ * useGeolocation hook return type
124
+ */
125
+ export interface UseGeolocationReturn {
126
+ requestLocationPermission: () => Promise<boolean>;
127
+ getCurrentLocation: () => Promise<{
128
+ latitude: number;
129
+ longitude: number;
130
+ accuracy: number;
131
+ altitude?: number;
132
+ speed?: number;
133
+ heading?: number;
134
+ } | null>;
135
+ }
136
+
137
+ /**
138
+ * Custom hook for geolocation functionality
139
+ */
140
+ export function useGeolocation(): UseGeolocationReturn;
141
+
142
+ /**
143
+ * useImageProcessing hook return type
144
+ */
145
+ export interface UseImageProcessingReturn {
146
+ convertImageToBase64: (imageUri: string) => Promise<string>;
147
+ }
148
+
149
+ /**
150
+ * Custom hook for image processing utilities
151
+ */
152
+ export function useImageProcessing(): UseImageProcessingReturn;
153
+
154
+ /**
155
+ * useNotifyMessage hook return type
156
+ */
157
+ export interface UseNotifyMessageReturn {
158
+ notification: {
159
+ visible: boolean;
160
+ message: string;
161
+ type: 'success' | 'error' | 'info' | 'warning';
162
+ };
163
+ fadeAnim: Animated.Value;
164
+ slideAnim: Animated.Value;
165
+ notifyMessage: (message: string, type?: 'success' | 'error' | 'info' | 'warning') => void;
166
+ clearNotification: () => void;
167
+ }
168
+
169
+ /**
170
+ * Custom hook for notification management
171
+ */
172
+ export function useNotifyMessage(): UseNotifyMessageReturn;
173
+
174
+ /**
175
+ * useSafeCallback hook return type
176
+ */
177
+ export type SafeCallback = (data: any) => void;
178
+
179
+ /**
180
+ * Custom hook for safe callback execution
181
+ */
182
+ export function useSafeCallback(callback: SafeCallback, notifyMessage: (msg: string, type?: string) => void): (data: any) => void;
183
+
184
+ // ============ UTILITIES ============
185
+
186
+ /**
187
+ * Global constants and configuration
188
+ */
189
+ export class Global {
190
+ static AppTheme: {
191
+ primary: string;
192
+ primaryLight: string;
193
+ success: string;
194
+ error: string;
195
+ warning: string;
196
+ info: string;
197
+ dark: string;
198
+ light: string;
199
+ gray: string;
200
+ background: string;
201
+ cardBackground: string;
202
+ textLight: string;
203
+ shadow: string;
204
+ modalBackground: string;
205
+ };
206
+
207
+ static LoadingTypes: {
208
+ none: string;
209
+ imageProcessing: string;
210
+ faceRecognition: string;
211
+ networkRequest: string;
212
+ locationPermission: string;
213
+ gettingLocation: string;
214
+ calculateDistance: string;
215
+ locationVerification: string;
216
+ };
217
+
218
+ static AnimationStates: {
219
+ faceScan: string;
220
+ qrScan: string;
221
+ processing: string;
222
+ success: string;
223
+ error: string;
224
+ };
225
+
226
+ static ImageResize: {
227
+ width: number;
228
+ height: number;
229
+ format: 'JPEG' | 'PNG';
230
+ quality: number;
231
+ };
232
+
233
+ static CountdownDuration: number;
234
+ }
235
+
236
+ /**
237
+ * Calculates distance between two geographical points using Haversine formula
238
+ */
239
+ export function getDistanceInMeters(lat1: number, lng1: number, lat2: number, lng2: number): number | null;
240
+
241
+ /**
242
+ * Network service call options
243
+ */
244
+ export interface NetworkServiceCallResponse {
245
+ httpstatus?: number;
246
+ data?: any;
247
+ message?: string;
248
+ [key: string]: any;
249
+ }
250
+
251
+ /**
252
+ * Makes HTTP requests with method, URL, headers, and body
253
+ */
254
+ export function networkServiceCall(
255
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH',
256
+ url: string,
257
+ extraHeaders?: Record<string, string>,
258
+ body?: Record<string, any>
259
+ ): Promise<NetworkServiceCallResponse>;
260
+
261
+ /**
262
+ * Helper function for GET API calls
263
+ */
264
+ export function getApiCall(url: string, extraHeaders?: Record<string, string>): Promise<NetworkServiceCallResponse>;
265
+
266
+ /**
267
+ * Get appropriate loader GIF based on animation state
268
+ */
269
+ export function getLoaderGif(
270
+ animationState: string,
271
+ currentStep: string,
272
+ apiurl: string,
273
+ imageurl?: string
274
+ ): { uri: string } | null;
275
+
276
+ // ============ MAIN COMPONENT ============
277
+
278
+ /**
279
+ * BiometricModal component props
280
+ */
281
+ export interface BiometricModalProps {
282
+ data: any;
283
+ depKey: string;
284
+ qrscan?: boolean;
285
+ callback: (result: any) => void;
286
+ apiurl: string;
287
+ onclose: () => void;
288
+ frameProcessorFps?: number;
289
+ livenessLevel?: string;
290
+ fileurl?: string;
291
+ imageurl?: string;
292
+ navigation: NavigationProp<any>;
293
+ duration?: number;
294
+ MaxDistanceMeters?: number;
295
+ antispooflevel?: string;
296
+ }
297
+
298
+ /**
299
+ * Main biometric verification modal component
300
+ */
301
+ declare const BiometricModal: React.MemoExoticComponent<React.FC<BiometricModalProps>>;
302
+
303
+ export default BiometricModal;