@richard.fadiora/liveness-detection 2.0.3 → 3.0.0

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 CHANGED
@@ -1,193 +1,155 @@
1
- # Liveness Detection Component
1
+ # Liveness Detection SDK
2
2
 
3
3
  A React-based liveness detection component that performs randomized user challenges and verifies real-user presence via a backend anti-spoofing API.
4
4
 
5
+ This version introduces headless mode, render-prop customization, robust sequential challenge handling, and timeout enforcement, giving developers full control over the UI while keeping the core verification logic encapsulated.
6
+
5
7
  ---
6
8
 
7
- ## 📌 Overview
9
+ ## Overview
8
10
 
9
- This component strengthens identity verification by combining:
11
+ The component strengthens identity verification using:
10
12
 
11
13
  - Randomized challenge-response validation
14
+ - Real-time gesture detection via MediaPipe
15
+ - Sequential verification to ensure no challenges are skipped
12
16
  - Strict timeout enforcement
13
17
  - Backend spoof detection
14
- - Callback-based integration for easy usage
18
+ - Callback-based integration for success/failure handling
19
+ - Optional headless mode for fully custom UI
15
20
 
16
21
  It protects against:
17
22
 
18
23
  - Presentation (photo) attacks
19
24
  - Screen glare attacks
20
- - Video replay/injection attacks
25
+ - Video replay or injection attacks
21
26
 
22
27
  ---
23
28
 
24
- ## ⚙️ How It Works
29
+ ## How It Works
25
30
 
26
- ### 1️⃣ Challenge Initialization
31
+ ### Challenge Initialization
27
32
 
28
- When the user clicks the **"Start Challenge"** button:
33
+ - Randomly selects 3 challenges from 4: Smile, Blink, Turn_Head, Thumbs_Up
34
+ - Timer starts immediately (default 60s, configurable)
35
+ - Challenges verified sequentially with brief pause between steps
36
+ - Timer expiry terminates session and stops backend verification
29
37
 
30
- - The system randomly selects **3 challenges**
31
- - The challenges are chosen from a fixed pool of 4:
38
+ ### Challenge Execution
32
39
 
33
- - `Smile`
34
- - `Blink`
35
- - `Turn_Head`
36
- - `Thumbs_Up`
40
+ - Validates challenges in real-time using MediaPipe
41
+ - Sequential logic ensures no challenge is skipped
42
+ - Optional render prop allows fully custom UI
37
43
 
38
- - A timer starts immediately. If you do not pass the **duration** property, it will default to 60 seconds.
44
+ ### Backend Liveness Verification
39
45
 
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
46
+ - Captures 5 frames from webcam after all challenges
47
+ - Sends frames to backend API for verification
48
+ - Backend performs spoof, glare, and video injection detection
44
49
 
45
50
  ---
46
51
 
47
- ### 2️⃣ Challenge Execution
52
+ ## Success & Failure Behavior
48
53
 
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.
54
+ **Success:**
55
+ - UI displays success message
56
+ - onComplete callback triggered with frame and skin confidence
52
57
 
53
- If successful, the component proceeds to backend verification.
58
+ **Failure:**
59
+ - UI displays error message
60
+ - onError callback triggered with reason
61
+ - Component resets for new session
54
62
 
55
63
  ---
56
64
 
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
65
+ ## Props
91
66
 
92
67
  | Prop Name | Type | Required | Description |
93
68
  |------------|----------------------------|----------|-------------|
94
- | `apiUrl` | `string` | Yes | Backend endpoint used for liveness verification |
95
- | `onComplete` | `(result: boolean) => void` | Yes | Callback fired after verification completes |
96
- | `duration` | `int` | No | Used for setting maximum time for the challenges to be completed |
69
+ | `apiUrl` | `string` | Yes | Backend endpoint for verification |
70
+ | `onComplete` | `(result: boolean) => void` | Yes | Callback on success |
71
+ | `onError` | `(result: boolean) => void` | Yes | Callback on failure |
72
+ | `duration` | `int` | No | Max time for challenges (default 60s) |
73
+ | render` | `(result: boolean) => void` | No | Optional custom UI render prop |
74
+ | `classNames` | `object` | No | Optional CSS classes for default UI |
97
75
 
98
76
  ---
99
77
 
100
- ## 🧩 Usage Example
78
+ ## Usage Example
101
79
 
80
+ **Default UI:**
102
81
  ```jsx
103
- import { LivenessSDK } from "@richard.fadiora/liveness-detection";
104
-
105
- function App() {
106
- return (
107
- <LivenessSDK
108
- apiUrl="https://your-backend-api.com/liveness-check"
109
- onComplete={(result) => {
110
- if (result) {
111
- console.log("User verified successfully");
112
- } else {
113
- console.log("Liveness verification failed");
114
- }
115
- }}
116
- />
117
- );
118
- }
119
-
120
- export default App;
82
+ import { LivenessSDK } from '@richard.fadiora/liveness-detection';
83
+
84
+ <LivenessSDK
85
+ apiUrl="https://your-backend-api.com/liveness-check"
86
+ onComplete={(result) => console.log(result)}
87
+ onError={(error) => console.log(error.reason)}
88
+ duration={60}
89
+ />
121
90
  ```
122
91
 
123
- ---
124
-
125
- ## ⏳ Timeout Rules
126
-
127
- - Maximum session duration: Set in the **duration** property, else **60 seconds**
128
- - If time expires:
129
- - The challenge stops immediately
130
- - The verification state resets
131
- - User must click **Start Challenge** again
132
- - Backend verification will NOT be triggered
92
+ **Headless / Custom UI:**
93
+ ```jsx
94
+ <LivenessSDK
95
+ apiUrl="https://your-backend-api.com/liveness-check"
96
+ onComplete={handleComplete}
97
+ onError={handleError}
98
+ render={(sdk) => (
99
+ <div>
100
+ <video ref={sdk.webcamRef} autoPlay playsInline muted />
101
+ <div>Step {sdk.currentStep + 1} of {sdk.sequence.length}: {sdk.sequence[sdk.currentStep]}</div>
102
+ <div>Time left: {sdk.timeLeft}s</div>
103
+ <button onClick={sdk.start}>Start</button>
104
+ </div>
105
+ )}
106
+ />
107
+ ```
133
108
 
134
109
  ---
135
110
 
136
- ## 🔐 Security Architecture
137
-
138
- This component uses a layered approach:
111
+ ## Timeout Rules
139
112
 
140
- 1. **Client-side active verification**
141
- - Randomized challenge selection
142
- - Real-time gesture detection
113
+ - Max session duration: `duration` prop (default 60s)
114
+ - Expiry stops challenge, resets state, requires restart, no backend call
143
115
 
144
- 2. **Server-side passive verification**
145
- - Frame-based spoof analysis
146
- - Glare detection
147
- - Video injection detection
116
+ ---
148
117
 
149
- 3. **Strict session control**
150
- - Timeout enforcement
151
- - Restart requirement on failure
118
+ ## Security Architecture
152
119
 
153
- This multi-layer strategy reduces false positives and prevents replay-based attacks.
120
+ 1. Client-side: randomized challenges, real-time gesture detection
121
+ 2. Server-side: frame-based spoof, glare, and injection detection
122
+ 3. Strict session control: timeout enforcement, restart requirement
154
123
 
155
124
  ---
156
125
 
157
- ## 📊 Verification Criteria
158
-
159
- A verification is considered successful only if:
160
-
161
- - 3 randomly selected challenges are completed
162
- - All 5 frames are successfully sent to the backend
163
- - Backend confirms:
164
- - No spoofing detected
165
- - No glare detected
166
- - Skin Texture is human
167
- - No video injection detected
126
+ ## Verification Criteria
168
127
 
128
+ - All 3 challenges completed
129
+ - All 5 frames sent to backend
130
+ - Backend confirms no spoofing, no glare, human skin, no video injection
169
131
 
170
132
  ---
171
133
 
172
- ## 🏗️ Integration Notes
134
+ ## Integration Notes
173
135
 
174
- - The component assumes webcam permissions are granted.
175
- - The backend must accept 5 frames in the expected format.
176
- - The `apiUrl` must be reachable from the client environment.
177
- - Ensure CORS is properly configured on the backend.
136
+ - Webcam permissions required
137
+ - Backend must accept 5 frames
138
+ - apiUrl must be reachable and CORS-enabled
178
139
 
179
140
  ---
180
141
 
181
- ## 🚀 Ideal Use Cases
142
+ ## Ideal Use Cases
182
143
 
183
144
  - KYC verification flows
184
- - Identity onboarding systems
185
- - Account recovery flows
145
+ - Identity onboarding
146
+ - Account recovery
186
147
  - Secure login systems
187
- - Financial or compliance-based applications
148
+ - Financial/compliance applications
188
149
 
189
150
  ---
190
151
 
191
- ## 👨‍💻 Maintainer
152
+ ## Maintainer
153
+
154
+ Fadiora Richard.
192
155
 
193
- Maintained by Princeps Credit Systems Limited.