@richard.fadiora/liveness-detection 2.1.0 → 3.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 CHANGED
@@ -2,9 +2,11 @@
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 latest version introduces **headless mode**, **render-prop customization**, and robust **challenge sequencing**, allowing developers to fully control the UI while keeping the verification logic encapsulated.
6
+
5
7
  ---
6
8
 
7
- ## 📌 Overview
9
+ ## Overview
8
10
 
9
11
  This component strengthens identity verification by combining:
10
12
 
@@ -12,6 +14,7 @@ This component strengthens identity verification by combining:
12
14
  - Strict timeout enforcement
13
15
  - Backend spoof detection
14
16
  - Callback-based integration for easy usage
17
+ - Headless / fully customizable UI via render props
15
18
 
16
19
  It protects against:
17
20
 
@@ -21,45 +24,26 @@ It protects against:
21
24
 
22
25
  ---
23
26
 
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 timer starts immediately. If you do not pass the **duration** property, it will default to 60 seconds.
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
- ---
27
+ ## How It Works
46
28
 
47
- ### 2️⃣ Challenge Execution
29
+ ### Challenge Initialization
48
30
 
49
- - Challenges are validated in real-time using webcam input.
31
+ - When the user starts verification, the system randomly selects **3 challenges** from a pool of 4 (`Smile`, `Blink`, `Turn_Head`, `Thumbs_Up`).
32
+ - A timer starts immediately (default **60 seconds**, configurable via `duration`).
33
+ - Each challenge is verified sequentially, with a brief pause between steps for user feedback.
50
34
  - The next challenge only begins after the current one is successfully completed.
51
- - All 3 challenges must be completed within the 60-second window.
35
+ - If the timer expires, the session terminates and no frames are sent to the backend.
52
36
 
53
- If successful, the component proceeds to backend verification.
37
+ ### Challenge Execution
54
38
 
55
- ---
56
-
57
- ### 3️⃣ Backend Liveness Verification
39
+ - Challenges are validated in real-time using webcam input and MediaPipe models.
40
+ - Sequential verification ensures no steps are skipped.
41
+ - Developers can use **headless mode** to render a fully custom UI while leveraging the verification logic.
58
42
 
59
- After all challenges are completed:
43
+ ### Backend Liveness Verification
60
44
 
61
- - The component captures **5 frames** from the webcam.
62
- - These frames are sent to the backend API defined by the `apiUrl` prop.
45
+ - After all challenges are completed, the component captures **5 frames** from the webcam.
46
+ - Frames are sent to the backend API defined by the `apiUrl` prop.
63
47
  - The backend performs:
64
48
  - Spoof detection
65
49
  - Glare detection
@@ -67,39 +51,79 @@ After all challenges are completed:
67
51
 
68
52
  ---
69
53
 
70
- ## Success & Failure Behavior
54
+ ## Success & Failure Behavior
71
55
 
72
- ### If verification succeeds:
73
- - The UI displays: **"Verification Passed"**
74
- - The component triggers:
56
+ ### If verification succeeds
57
+
58
+ - The UI (or custom render-prop component) can display success feedback.
59
+ - The `onComplete` callback is triggered:
75
60
 
76
61
  ```js
77
- onComplete(true)
62
+ onComplete({ success: true, image: frame, skinConfidence });
78
63
  ```
79
64
 
80
- ### If verification fails:
81
- - The UI displays a failure message
82
- - The component triggers:
65
+ ### If verification fails
66
+
67
+ - The UI displays a failure message.
68
+ - The `onError` callback is triggered:
83
69
 
84
70
  ```js
85
- onError(false)
71
+ onError({ success: false, reason, skinConfidence: null });
86
72
  ```
87
- This is because the parameters being passed for both completion and Error are the same: success, result, and skinConfidence.
73
+
74
+ - The component resets, requiring the user to start a new session.
88
75
 
89
76
  ---
90
77
 
91
- ## 📦 Props
78
+ ## Props
92
79
 
93
80
  | Prop Name | Type | Required | Description |
94
81
  |------------|----------------------------|----------|-------------|
95
- | `apiUrl` | `string` | Yes | Backend endpoint used for liveness verification |
96
- | `onComplete` | `(result: boolean) => void` | Yes | Callback fired after verification completes |
97
- | `onError` | `(result: boolean) => void` | Yes | Callback fired after verification flags error |
98
- | `duration` | `int` | No | Used for setting maximum time for the challenges to be completed |
82
+ | `apiUrl` | `string` | Yes | Backend endpoint for verification |
83
+ | `onComplete` | `(result: boolean) => void` | Yes | Callback on success |
84
+ | `onError` | `(result: boolean) => void` | Yes | Callback on failure |
85
+ | `duration` | `int` | No | Max time for challenges (default 60s) |
86
+ | render` | `(result: boolean) => void` | No | Optional custom UI render prop |
87
+ | `classNames` | `object` | No | Optional CSS classes for default UI |
99
88
 
100
89
  ---
101
90
 
102
- ## 🧩 Usage Example
91
+ ## Styling with `classNames`
92
+
93
+ The `classNames` object allows partial styling of the default UI without fully overriding it. Supported keys:
94
+
95
+ | Key | Element |
96
+ |------------|-----------------------------|
97
+ | `container` | The root wrapper div |
98
+ | `webcam` | The webcam video element |
99
+ | `button` | Start / Retry button |
100
+ | `timer` | Timer display |
101
+ | `error` | Error message display |
102
+ | `success` | Success message display |
103
+
104
+ ### Example Usage
105
+
106
+ ```jsx
107
+ <LivenessSDK
108
+ apiUrl="https://your-backend-api.com/liveness-check"
109
+ onComplete={handleComplete}
110
+ onError={handleError}
111
+ classNames={{
112
+ container: "my-liveness-container",
113
+ webcam: "my-webcam",
114
+ button: "my-button",
115
+ timer: "my-timer",
116
+ error: "my-error",
117
+ success: "my-success"
118
+ }}
119
+ />
120
+ ```
121
+
122
+ ---
123
+
124
+ ## Usage Examples
125
+
126
+ ### Default UI
103
127
 
104
128
  ```jsx
105
129
  import { LivenessSDK } from "@richard.fadiora/liveness-detection";
@@ -108,13 +132,9 @@ function App() {
108
132
  return (
109
133
  <LivenessSDK
110
134
  apiUrl="https://your-backend-api.com/liveness-check"
111
- onComplete={(result) => {
112
- if (result) {
113
- console.log("User verified successfully");
114
- } else {
115
- console.log("Liveness verification failed");
116
- }
117
- }}
135
+ onComplete={(result) => console.log("Verification success:", result)}
136
+ onError={(error) => console.log("Verification failed:", error.reason)}
137
+ duration={60}
118
138
  />
119
139
  );
120
140
  }
@@ -122,56 +142,62 @@ function App() {
122
142
  export default App;
123
143
  ```
124
144
 
145
+ ### Headless / Custom UI
146
+
147
+ ```jsx
148
+ <LivenessSDK
149
+ apiUrl="https://your-backend-api.com/liveness-check"
150
+ onComplete={handleComplete}
151
+ onError={handleError}
152
+ render={(sdk) => (
153
+ <div>
154
+ <video ref={sdk.webcamRef} autoPlay playsInline muted />
155
+ <div>Step {sdk.currentStep + 1}: {sdk.sequence[sdk.currentStep]}</div>
156
+ <div>Time left: {sdk.timeLeft}s</div>
157
+ <button onClick={sdk.start}>Start</button>
158
+ </div>
159
+ )}
160
+ />
161
+ ```
162
+
125
163
  ---
126
164
 
127
- ## Timeout Rules
165
+ ## Timeout Rules
128
166
 
129
- - Maximum session duration: Set in the **duration** property, else **60 seconds**
167
+ - Maximum session duration: set via the `duration` property (default 60 seconds)
130
168
  - If time expires:
131
169
  - The challenge stops immediately
132
- - The verification state resets
133
- - User must click **Start Challenge** again
134
- - Backend verification will NOT be triggered
170
+ - Verification state resets
171
+ - User must click Start Challenge again
172
+ - Backend verification is NOT triggered
135
173
 
136
174
  ---
137
175
 
138
- ## 🔐 Security Architecture
139
-
140
- This component uses a layered approach:
176
+ ## Security Architecture
141
177
 
142
- 1. **Client-side active verification**
143
- - Randomized challenge selection
144
- - Real-time gesture detection
178
+ - **Client-side active verification**: randomized challenges, real-time gesture detection
179
+ - **Server-side passive verification**: frame-based spoof analysis, glare detection, video injection detection
180
+ - **Strict session control**: timeout enforcement, restart requirement on failure
145
181
 
146
- 2. **Server-side passive verification**
147
- - Frame-based spoof analysis
148
- - Glare detection
149
- - Video injection detection
150
-
151
- 3. **Strict session control**
152
- - Timeout enforcement
153
- - Restart requirement on failure
154
-
155
- This multi-layer strategy reduces false positives and prevents replay-based attacks.
182
+ This layered approach reduces false positives and prevents replay-based attacks.
156
183
 
157
184
  ---
158
185
 
159
- ## 📊 Verification Criteria
186
+ ## Verification Criteria
160
187
 
161
- A verification is considered successful only if:
188
+ Verification is considered successful only if:
162
189
 
163
- - 3 randomly selected challenges are completed
164
- - All 5 frames are successfully sent to the backend
190
+ - All 3 randomly selected challenges are completed
191
+ - All 5 frames are sent to the backend
165
192
  - Backend confirms:
166
193
  - No spoofing detected
167
194
  - No glare detected
168
- - Skin Texture is human
195
+ - Skin texture is human
169
196
  - No video injection detected
170
197
 
171
-
172
198
  ---
173
199
 
174
- ## 🏗️ Integration Notes
200
+ ## Integration Notes
175
201
 
176
202
  - The component assumes webcam permissions are granted.
177
203
  - The backend must accept 5 frames in the expected format.
@@ -180,7 +206,7 @@ A verification is considered successful only if:
180
206
 
181
207
  ---
182
208
 
183
- ## 🚀 Ideal Use Cases
209
+ ## Ideal Use Cases
184
210
 
185
211
  - KYC verification flows
186
212
  - Identity onboarding systems
@@ -190,6 +216,7 @@ A verification is considered successful only if:
190
216
 
191
217
  ---
192
218
 
193
- ## 👨‍💻 Maintainer
219
+ ## Maintainer
220
+
221
+ Fadiora Richard
194
222
 
195
- Maintained by Princeps Credit Systems Limited.