@richard.fadiora/liveness-detection 1.0.5 → 2.0.1

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/README.md ADDED
@@ -0,0 +1,192 @@
1
+ # Liveness Detection Component
2
+
3
+ A React-based liveness detection component that performs randomized user challenges and verifies real-user presence via a backend anti-spoofing API.
4
+
5
+ ---
6
+
7
+ ## 📌 Overview
8
+
9
+ This component strengthens identity verification by combining:
10
+
11
+ - Randomized challenge-response validation
12
+ - Strict timeout enforcement
13
+ - Backend spoof detection
14
+ - Callback-based integration for easy usage
15
+
16
+ It protects against:
17
+
18
+ - Presentation (photo) attacks
19
+ - Screen glare attacks
20
+ - Video replay/injection attacks
21
+
22
+ ---
23
+
24
+ ## ⚙️ How It Works
25
+
26
+ ### 1️⃣ Challenge Initialization
27
+
28
+ When the user clicks the **"Start Challenge"** button:
29
+
30
+ - The system randomly selects **3 challenges**
31
+ - The challenges are chosen from a fixed pool of 4:
32
+
33
+ - `Smile`
34
+ - `Blink`
35
+ - `Turn_Head`
36
+ - `Thumbs_Up`
37
+
38
+ - A **60-second timer** starts immediately.
39
+
40
+ If the timer expires before completion:
41
+ - The session is terminated
42
+ - The user must restart the process manually
43
+ - No frames are sent to the backend
44
+
45
+ ---
46
+
47
+ ### 2️⃣ Challenge Execution
48
+
49
+ - Challenges are validated in real-time using webcam input.
50
+ - The next challenge only begins after the current one is successfully completed.
51
+ - All 3 challenges must be completed within the 60-second window.
52
+
53
+ If successful, the component proceeds to backend verification.
54
+
55
+ ---
56
+
57
+ ### 3️⃣ Backend Liveness Verification
58
+
59
+ After all challenges are completed:
60
+
61
+ - The component captures **5 frames** from the webcam.
62
+ - These frames are sent to the backend API defined by the `apiUrl` prop.
63
+ - The backend performs:
64
+ - Spoof detection
65
+ - Glare detection
66
+ - Video injection detection
67
+
68
+ ---
69
+
70
+ ## ✅ Success & Failure Behavior
71
+
72
+ ### If verification succeeds:
73
+ - The UI displays: **"Verification Passed"**
74
+ - The component triggers:
75
+
76
+ ```js
77
+ onComplete(true)
78
+ ```
79
+
80
+ ### If verification fails:
81
+ - The UI displays a failure message
82
+ - The component triggers:
83
+
84
+ ```js
85
+ onComplete(false)
86
+ ```
87
+
88
+ ---
89
+
90
+ ## 📦 Props
91
+
92
+ | Prop Name | Type | Required | Description |
93
+ |------------|----------------------------|----------|-------------|
94
+ | `apiUrl` | `string` | Yes | Backend endpoint used for liveness verification |
95
+ | `onComplete` | `(result: boolean) => void` | Yes | Callback fired after verification completes |
96
+
97
+ ---
98
+
99
+ ## 🧩 Usage Example
100
+
101
+ ```jsx
102
+ import { LivenessSDK } from "./LivenessSDK";
103
+
104
+ function App() {
105
+ return (
106
+ <LivenessSDK
107
+ apiUrl="https://your-backend-api.com/liveness-check"
108
+ onComplete={(result) => {
109
+ if (result) {
110
+ console.log("User verified successfully");
111
+ } else {
112
+ console.log("Liveness verification failed");
113
+ }
114
+ }}
115
+ />
116
+ );
117
+ }
118
+
119
+ export default App;
120
+ ```
121
+
122
+ ---
123
+
124
+ ## ⏳ Timeout Rules
125
+
126
+ - Maximum session duration: **60 seconds**
127
+ - If time expires:
128
+ - The challenge stops immediately
129
+ - The verification state resets
130
+ - User must click **Start Challenge** again
131
+ - Backend verification will NOT be triggered
132
+
133
+ ---
134
+
135
+ ## 🔐 Security Architecture
136
+
137
+ This component uses a layered approach:
138
+
139
+ 1. **Client-side active verification**
140
+ - Randomized challenge selection
141
+ - Real-time gesture detection
142
+
143
+ 2. **Server-side passive verification**
144
+ - Frame-based spoof analysis
145
+ - Glare detection
146
+ - Video injection detection
147
+
148
+ 3. **Strict session control**
149
+ - Timeout enforcement
150
+ - Restart requirement on failure
151
+
152
+ This multi-layer strategy reduces false positives and prevents replay-based attacks.
153
+
154
+ ---
155
+
156
+ ## 📊 Verification Criteria
157
+
158
+ A verification is considered successful only if:
159
+
160
+ - 3 randomly selected challenges are completed
161
+ - All 5 frames are successfully sent to the backend
162
+ - Backend confirms:
163
+ - No spoofing detected
164
+ - No glare detected
165
+ - Skin Texture is human
166
+ - No video injection detected
167
+
168
+
169
+ ---
170
+
171
+ ## 🏗️ Integration Notes
172
+
173
+ - The component assumes webcam permissions are granted.
174
+ - The backend must accept 5 frames in the expected format.
175
+ - The `apiUrl` must be reachable from the client environment.
176
+ - Ensure CORS is properly configured on the backend.
177
+
178
+ ---
179
+
180
+ ## 🚀 Ideal Use Cases
181
+
182
+ - KYC verification flows
183
+ - Identity onboarding systems
184
+ - Account recovery flows
185
+ - Secure login systems
186
+ - Financial or compliance-based applications
187
+
188
+ ---
189
+
190
+ ## 👨‍💻 Maintainer
191
+
192
+ Maintained by Princeps Credit Systems Limited.