react-native-vision-camera-spoof-detector 1.0.18 → 1.0.19

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.
package/index.d.ts CHANGED
@@ -1,84 +1,472 @@
1
1
  /**
2
2
  * React Native Vision Camera Face Anti-Spoofing Detector
3
+ * High-performance face anti-spoofing and liveness detection module
3
4
  * TypeScript type definitions
4
5
  */
5
6
 
6
- import type { Frame } from 'react-native-vision-camera';
7
+ import type { Frame, FrameProcessor } from 'react-native-vision-camera';
8
+ import type { SharedValue } from 'react-native-reanimated';
9
+
10
+ // ============================================================================
11
+ // Core Detection Results
12
+ // ============================================================================
7
13
 
8
14
  /**
9
- * Result from face anti-spoofing detection
15
+ * Face anti-spoofing detection result
16
+ * Contains comprehensive information about face liveness detection
10
17
  */
11
18
  export interface FaceAntiSpoofingResult {
12
- /** Whether the face is live (not a spoof/fake) */
19
+ /**
20
+ * Whether the face is live (real) or a spoof attempt
21
+ * @true - Face is real/live
22
+ * @false - Face is likely a spoof/fake
23
+ */
13
24
  isLive: boolean;
14
-
15
- /** Human-readable label: "Live Face" or "Spoof Face" */
25
+
26
+ /**
27
+ * Human-readable label
28
+ * @values "Live Face" | "Spoof Face"
29
+ */
16
30
  label: string;
17
-
18
- /** Neural network confidence score (0.0-1.0), lower is more likely to be live */
31
+
32
+ /**
33
+ * Neural network confidence score
34
+ * Range: 0.0 to 1.0
35
+ * Lower values indicate more likely to be live
36
+ */
19
37
  neuralNetworkScore: number;
20
-
21
- /** Laplacian-based image quality score, higher is better */
38
+
39
+ /**
40
+ * Laplacian variance-based image quality score
41
+ * Range: 0.0 to 5000+
42
+ * Higher values = better image quality
43
+ * Used to distinguish blur from spoofing
44
+ */
22
45
  laplacianScore: number;
23
-
24
- /** Combined score (weighted average, 0.0-1.0) */
46
+
47
+ /**
48
+ * Combined weighted score from multiple models
49
+ * Range: 0.0 to 1.0
50
+ * Provides robust detection by ensemble voting
51
+ */
25
52
  combinedScore: number;
26
-
27
- /** Error message if detection failed */
53
+
54
+ /**
55
+ * Error message if detection failed
56
+ * @optional Only present if an error occurred
57
+ */
28
58
  error?: string;
29
59
  }
30
60
 
31
61
  /**
32
- * Accelerator type for TensorFlow Lite inference
62
+ * Face rectangle/bounds information
33
63
  */
34
- export type AcceleratorType = 'CPU' | 'GPU' | 'NNAPI';
64
+ export interface FaceRect {
65
+ /** X coordinate in pixels */
66
+ x: number;
67
+ /** Y coordinate in pixels */
68
+ y: number;
69
+ /** Face width in pixels */
70
+ width: number;
71
+ /** Face height in pixels */
72
+ height: number;
73
+ }
74
+
75
+ // ============================================================================
76
+ // Anti-spoofing State & Configuration
77
+ // ============================================================================
78
+
79
+ /**
80
+ * Anti-spoofing detection state
81
+ */
82
+ export interface AntiSpoofState {
83
+ /** Whether face is detected as live */
84
+ isLive: boolean;
85
+ /** Confidence score (0.0-1.0) */
86
+ confidence: number;
87
+ /** Consecutive frames detected as live */
88
+ consecutiveLiveFrames: number;
89
+ /** Last detection result */
90
+ lastResult: FaceAntiSpoofingResult | null;
91
+ /** Whether face is single and detected */
92
+ hasSingleFace: boolean;
93
+ /** Whether face is centered in frame */
94
+ isFaceCentered: boolean;
95
+ }
96
+
97
+ /**
98
+ * Face tracking state
99
+ */
100
+ export interface FaceTrackingState {
101
+ lastX: number;
102
+ lastY: number;
103
+ lastW: number;
104
+ lastH: number;
105
+ stableCount: number;
106
+ }
107
+
108
+ /**
109
+ * Liveness detection state
110
+ */
111
+ export interface LivenessState {
112
+ level: number;
113
+ step: number;
114
+ blinkCount: number;
115
+ }
116
+
117
+ /**
118
+ * Complete shared state for frame processing
119
+ */
120
+ export interface SharedFrameProcessorState {
121
+ lastProcessedTime: number;
122
+ faceTracking: FaceTrackingState;
123
+ flags: {
124
+ captured: boolean;
125
+ showCodeScanner: boolean;
126
+ isActive: boolean;
127
+ hasSingleFace: boolean;
128
+ isFaceCentered: boolean;
129
+ eyeClosed: boolean;
130
+ };
131
+ liveness: LivenessState;
132
+ antiSpoof: AntiSpoofState;
133
+ centering: {
134
+ centeredFrames: number;
135
+ frameWidth: number;
136
+ frameHeight: number;
137
+ };
138
+ performance: {
139
+ batchCounter: number;
140
+ lastBatchUpdate: number;
141
+ };
142
+ }
143
+
144
+ /**
145
+ * Face detection update callback data
146
+ */
147
+ export interface FacesUpdateData {
148
+ count: number;
149
+ progress: number;
150
+ step: number;
151
+ isCentered: boolean;
152
+ antiSpoofState: AntiSpoofState;
153
+ }
154
+
155
+ /**
156
+ * Anti-spoof update callback data
157
+ */
158
+ export interface OnAntiSpoofUpdateData {
159
+ isLive: boolean;
160
+ confidence: number;
161
+ rawResult?: FaceAntiSpoofingResult;
162
+ consecutiveLiveFrames: number;
163
+ isFaceCentered: boolean;
164
+ }
165
+
166
+ // ============================================================================
167
+ // Hook Configuration
168
+ // ============================================================================
169
+
170
+ /**
171
+ * Configuration options for useFaceDetectionFrameProcessor hook
172
+ */
173
+ export interface UseFaceDetectionFrameProcessorOptions {
174
+ /**
175
+ * Callback when a stable, live face is detected
176
+ * @param faceRect - Face position and size
177
+ * @param antiSpoofResult - Anti-spoofing detection result
178
+ */
179
+ onStableFaceDetected?: (
180
+ faceRect: FaceRect,
181
+ antiSpoofResult?: FaceAntiSpoofingResult
182
+ ) => void;
183
+
184
+ /**
185
+ * Callback for face updates during detection
186
+ * Called periodically with detection progress
187
+ */
188
+ onFacesUpdate?: (data: FacesUpdateData) => void;
189
+
190
+ /**
191
+ * Callback for liveness verification updates
192
+ * @param step - Liveness step (0-2)
193
+ * @param extra - Additional data like blink count
194
+ */
195
+ onLivenessUpdate?: (step: number, extra?: Record<string, any>) => void;
196
+
197
+ /**
198
+ * Callback for anti-spoof detection updates
199
+ * Called when anti-spoofing detection result changes
200
+ */
201
+ onAntiSpoofUpdate?: (result: OnAntiSpoofUpdateData) => void;
202
+
203
+ /**
204
+ * Show code scanner overlay
205
+ * @default false
206
+ */
207
+ showCodeScanner?: boolean;
208
+
209
+ /**
210
+ * Loading state - pauses frame processing
211
+ * @default false
212
+ */
213
+ isLoading?: boolean;
214
+
215
+ /**
216
+ * Enable/disable frame processing
217
+ * @default true
218
+ */
219
+ isActive?: boolean;
220
+
221
+ /**
222
+ * Liveness verification level
223
+ * @values 0 - Anti-spoofing only (fast)
224
+ * @values 1 - Anti-spoofing + blink detection (more thorough)
225
+ * @default 0
226
+ */
227
+ livenessLevel?: number;
228
+
229
+ /**
230
+ * Anti-spoofing confidence threshold
231
+ * Range: 0.0 - 1.0
232
+ * Lower values = more lenient, higher values = stricter
233
+ * @default 0.35
234
+ */
235
+ antispooflevel?: number;
236
+ }
237
+
238
+ /**
239
+ * Return value from useFaceDetectionFrameProcessor hook
240
+ */
241
+ export interface UseFaceDetectionFrameProcessorReturn {
242
+ /**
243
+ * Frame processor function for Vision Camera
244
+ */
245
+ frameProcessor: FrameProcessor;
246
+
247
+ /**
248
+ * Reset capture state to initial values
249
+ */
250
+ resetCaptureState: () => void;
251
+
252
+ /**
253
+ * Force reset all states including shared values
254
+ */
255
+ forceResetCaptureState: () => void;
256
+
257
+ /**
258
+ * Update code scanner visibility
259
+ */
260
+ updateShowCodeScanner: (value: boolean) => void;
261
+
262
+ /**
263
+ * Update processing active state
264
+ */
265
+ updateIsActive: (active: boolean) => void;
266
+
267
+ /**
268
+ * Initialize anti-spoofing module
269
+ */
270
+ initializeAntiSpoof: () => Promise<boolean>;
271
+
272
+ /**
273
+ * Shared value for capture state
274
+ * Use .value to access: capturedSV.value.value
275
+ */
276
+ capturedSV: SharedValue<boolean>;
277
+
278
+ /**
279
+ * Current anti-spoofing detection state
280
+ */
281
+ antiSpoofState: AntiSpoofState;
282
+ }
283
+
284
+ // ============================================================================
285
+ // Module Functions
286
+ // ============================================================================
35
287
 
36
288
  /**
37
289
  * Frame processor function for real-time face anti-spoofing detection
290
+ * Call within a Vision Camera frame processor
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * const frameProcessor = useFrameProcessor((frame) => {
295
+ * 'worklet';
296
+ * const result = faceAntiSpoofFrameProcessor(frame);
297
+ * if (result?.isLive) {
298
+ * // Face is live
299
+ * }
300
+ * }, []);
301
+ * ```
302
+ *
303
+ * @param frame - Vision Camera frame object
304
+ * @returns Detection result or null if no face detected
38
305
  */
39
306
  export function faceAntiSpoofFrameProcessor(
40
307
  frame: Frame
41
308
  ): FaceAntiSpoofingResult | null;
42
309
 
43
310
  /**
44
- * Check if face anti-spoofing module is available
311
+ * Check if face anti-spoofing module is available on device
312
+ * Call before attempting to use the module
313
+ *
314
+ * @returns true if module is available, false otherwise
45
315
  */
46
316
  export function isFaceAntiSpoofAvailable(): boolean;
47
317
 
48
318
  /**
49
319
  * Initialize the face anti-spoofing module
50
320
  * Must be called before using the frame processor
321
+ *
322
+ * @returns Promise<boolean> - true if initialization successful
323
+ *
324
+ * @example
325
+ * ```typescript
326
+ * useEffect(() => {
327
+ * initializeFaceAntiSpoof()
328
+ * .then(success => {
329
+ * if (success) {
330
+ * console.log('Anti-spoof ready');
331
+ * }
332
+ * });
333
+ * }, []);
334
+ * ```
51
335
  */
52
336
  export function initializeFaceAntiSpoof(): Promise<boolean>;
53
337
 
54
338
  /**
55
- * Native module interface
339
+ * Custom React Native hook for comprehensive face detection with anti-spoofing
340
+ * Provides advanced features like blink detection and face centering
341
+ *
342
+ * @param options - Configuration options
343
+ * @returns Hook return value with frame processor and callbacks
344
+ *
345
+ * @example
346
+ * ```typescript
347
+ * const { frameProcessor, resetCaptureState, antiSpoofState } =
348
+ * useFaceDetectionFrameProcessor({
349
+ * livenessLevel: 1,
350
+ * antispooflevel: 0.35,
351
+ * onStableFaceDetected: (rect, result) => {
352
+ * console.log('Capture complete!', rect);
353
+ * },
354
+ * });
355
+ * ```
356
+ */
357
+ export function useFaceDetectionFrameProcessor(
358
+ options: UseFaceDetectionFrameProcessorOptions
359
+ ): UseFaceDetectionFrameProcessorReturn;
360
+
361
+ // ============================================================================
362
+ // Accelerator Types
363
+ // ============================================================================
364
+
365
+ /**
366
+ * TensorFlow Lite accelerator type
367
+ * Determines which hardware is used for inference
368
+ */
369
+ export type AcceleratorType = 'CPU' | 'GPU' | 'NNAPI';
370
+
371
+ /**
372
+ * Module information
373
+ */
374
+ export interface ModuleInfo {
375
+ /** Module name */
376
+ name: string;
377
+ /** Available API methods */
378
+ methods: string[];
379
+ /** Module version */
380
+ version: string;
381
+ /** Active accelerator (if available) */
382
+ accelerator?: AcceleratorType;
383
+ }
384
+
385
+ /**
386
+ * Model status information
387
+ */
388
+ export interface ModelStatus {
389
+ /** Whether plugin is available on this device */
390
+ pluginAvailable: boolean;
391
+ /** Whether TensorFlow Lite model is loaded */
392
+ modelLoaded: boolean;
393
+ /** Active accelerator type */
394
+ accelerator?: AcceleratorType;
395
+ }
396
+
397
+ // ============================================================================
398
+ // Native Module Interface
399
+ // ============================================================================
400
+
401
+ /**
402
+ * Native module interface for advanced use cases
403
+ * Generally not needed - use the exported functions instead
56
404
  */
57
405
  export interface FaceAntiSpoofModule {
406
+ /**
407
+ * Initialize native module
408
+ */
58
409
  initialize(): Promise<boolean>;
59
-
60
- checkModelStatus(): Promise<{
61
- pluginAvailable: boolean;
62
- modelLoaded: boolean;
63
- accelerator?: AcceleratorType;
64
- }>;
65
-
410
+
411
+ /**
412
+ * Check model loading status
413
+ */
414
+ checkModelStatus(): Promise<ModelStatus>;
415
+
416
+ /**
417
+ * Check module availability
418
+ */
66
419
  isAvailable(): Promise<boolean>;
67
-
420
+
421
+ /**
422
+ * Test connection to native module
423
+ */
68
424
  testMethod(): Promise<string>;
69
-
70
- getModuleInfo(): Promise<{
71
- name: string;
72
- methods: string[];
73
- version: string;
74
- accelerator?: AcceleratorType;
75
- }>;
76
-
425
+
426
+ /**
427
+ * Get module information
428
+ */
429
+ getModuleInfo(): Promise<ModuleInfo>;
430
+
431
+ /**
432
+ * Install/setup native dependencies
433
+ */
77
434
  install(): Promise<boolean>;
78
435
  }
79
436
 
80
437
  /**
81
- * Default export - the native module
438
+ * Native module instance
82
439
  */
83
440
  declare const FaceAntiSpoof: FaceAntiSpoofModule;
441
+
84
442
  export default FaceAntiSpoof;
443
+
444
+ // ============================================================================
445
+ // Constants
446
+ // ============================================================================
447
+
448
+ /**
449
+ * Default anti-spoofing confidence threshold
450
+ */
451
+ export const DEFAULT_ANTI_SPOOF_LEVEL = 0.35;
452
+
453
+ /**
454
+ * Default face stability threshold (frames)
455
+ */
456
+ export const DEFAULT_FACE_STABILITY_THRESHOLD = 3;
457
+
458
+ /**
459
+ * Default face movement threshold (pixels)
460
+ */
461
+ export const DEFAULT_FACE_MOVEMENT_THRESHOLD = 15;
462
+
463
+ /**
464
+ * Minimum required blinks for liveness verification
465
+ */
466
+ export const DEFAULT_REQUIRED_BLINKS = 3;
467
+
468
+ /**
469
+ * Blink detection threshold (eye closure probability)
470
+ */
471
+ export const DEFAULT_BLINK_THRESHOLD = 0.3;
472
+
package/package.json CHANGED
@@ -1,36 +1,41 @@
1
1
  {
2
2
  "name": "react-native-vision-camera-spoof-detector",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "High-performance face anti-spoofing and liveness detection module for React Native Vision Camera. Uses TensorFlow Lite with GPU acceleration and optimized YUV processing.",
5
5
  "homepage": "https://github.com/jescon-tech/react-native-vision-camera-spoof-detector",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/dpraful/react-native-vision-camera-spoof-detector.git"
8
+ "url": "https://github.com/jescon-tech/react-native-vision-camera-spoof-detector.git"
9
9
  },
10
10
  "bugs": {
11
11
  "url": "https://github.com/jescon-tech/react-native-vision-camera-spoof-detector/issues"
12
12
  },
13
- "license": "JESCON TECHNOLOGIES PVT LTD",
13
+ "license": "JSCON TECHNOLOGIES PVT LTD",
14
14
  "author": {
15
15
  "name": "PRAFULDAS M M",
16
- "company": "JESCON TECHNOLOGIES PVT LTD THRISSUR, KERALA, INDIA",
16
+ "company": "JESCON TECHNOLOGIES PVT LTD",
17
17
  "email": "jescontechnologies@gmail.com"
18
18
  },
19
+ "contributors": [
20
+ {
21
+ "name": "JESCON TECHNOLOGIES PVT LTD",
22
+ "email": "jescontechnologies@gmail.com"
23
+ }
24
+ ],
19
25
  "main": "index.js",
20
26
  "browser": "index.js",
21
27
  "react-native": "index.js",
22
28
  "types": "index.d.ts",
23
29
  "files": [
24
30
  "android/",
31
+ ".npmignore",
32
+ "CHANGELOG.md",
33
+ "CONTRIBUTING.md",
25
34
  "index.js",
26
35
  "index.d.ts",
27
- "README.md"
36
+ "README.md",
37
+ "LICENSE"
28
38
  ],
29
- "scripts": {
30
- "test": "jest",
31
- "lint": "eslint .",
32
- "type-check": "tsc --noEmit"
33
- },
34
39
  "keywords": [
35
40
  "react-native",
36
41
  "vision-camera",
@@ -41,9 +46,15 @@
41
46
  "spoofing-detection",
42
47
  "tensorflow-lite",
43
48
  "gpu-acceleration",
44
- "yuv-processing"
49
+ "yuv-processing",
50
+ "face-recognition",
51
+ "biometric",
52
+ "security",
53
+ "ai",
54
+ "ml"
45
55
  ],
46
56
  "peerDependencies": {
57
+ "react": ">=16.8.0",
47
58
  "react-native": ">=0.60.0",
48
59
  "react-native-vision-camera": "^4.6.4 || ^5.0.0",
49
60
  "react-native-reanimated": "^3.0.0",
@@ -55,14 +66,20 @@
55
66
  }
56
67
  },
57
68
  "devDependencies": {
69
+ "react": "^18.2.0",
58
70
  "react-native": "^0.72.0",
59
71
  "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
60
- "@babel/plugin-proposal-optional-chaining": "^7.21.0"
72
+ "@babel/plugin-proposal-optional-chaining": "^7.21.0",
73
+ "typescript": "^5.0.0"
61
74
  },
62
75
  "engines": {
63
76
  "node": ">=16.0.0",
64
77
  "npm": ">=8.0.0"
65
78
  },
66
79
  "packageManager": "npm@8.0.0",
67
- "documentation": "https://github.com/jescon-tech/react-native-vision-camera-spoof-detector/wiki"
80
+ "documentation": "https://github.com/jescon-tech/react-native-vision-camera-spoof-detector/wiki",
81
+ "publishConfig": {
82
+ "access": "public",
83
+ "registry": "https://registry.npmjs.org/"
84
+ }
68
85
  }