@richard.fadiora/liveness-detection 3.0.3 → 3.1.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,7 +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 version introduces **headless mode**, **render-prop customization**, and robust **challenge sequencing**, allowing you to fully control the UI while keeping the verification logic encapsulated.
5
+ This version introduces **headless mode**, **render-prop customization**, and robust **challenge sequencing**, **configurable thresholds** for `Smile`, `Blink`, and `Turn_Head` challenges
6
+
7
+ Pause between steps for user feedback
8
+
9
+ Sequential challenge execution with strict timeout handling allowing you to fully control the UI while keeping the verification logic encapsulated.
6
10
 
7
11
  ---
8
12
 
@@ -14,7 +18,8 @@ This component strengthens identity verification by combining:
14
18
  - Strict timeout enforcement
15
19
  - Backend spoof detection
16
20
  - Callback-based integration for easy usage
17
- - Headless / fully customizable UI via render props
21
+ - Headless / fully customizable UI via render props
22
+ - Configurable challenge thresholds to adapt difficulty
18
23
 
19
24
  It protects against:
20
25
 
@@ -38,6 +43,14 @@ It protects against:
38
43
  - Real-time validation using webcam input and MediaPipe models.
39
44
  - Sequential verification ensures **no steps are skipped**.
40
45
  - Developers can render custom UI via the **render prop** while using the same underlying logic.
46
+ - Challenge thresholds are configurable through props:
47
+
48
+ | Prop Name | Default | Description |
49
+ |-----------------------|---------|------------------------------------------|
50
+ | `smileThreshold` | 0.20 | Minimum smile width to count as valid |
51
+ | `blinkThreshold` | 0.01 | Maximum eye aspect ratio to count as blink |
52
+ | `minturnHeadThreshold`| 0.15 | Minimum yaw for right head turn detection |
53
+ | `maxturnHeadThreshold`| 0.85 | Maximum yaw for left head turn detection |
41
54
 
42
55
  ### 3️⃣ Backend Liveness Verification
43
56
 
@@ -76,6 +89,11 @@ onError({ success: false, reason, skinConfidence: null });
76
89
  | `duration` | `number` | No | Maximum time for all challenges (default: 60s) |
77
90
  | `render` | `(sdk: object) => JSX.Element` | No | Optional render prop for full UI customization |
78
91
  | `classNames` | `object` | No | Optional CSS class names to customize default UI |
92
+ | `smileThreshold` | `number` | No | Minimum smile width for Smile challenge |
93
+ | `blinkThreshold` | `number` | No | Maximum eye aspect ratio for Blink challenge |
94
+ | `minturnHeadThreshold` | `number` | No | Minimum yaw for Turn_Head challenge |
95
+ | `maxturnHeadThreshold` | `number` | No | Maximum yaw for Turn_Head challenge |
96
+
79
97
 
80
98
  ---
81
99
 
@@ -115,6 +133,25 @@ export default App;
115
133
  )}
116
134
  />
117
135
  ```
136
+ ## 📤 Hook Return Values
137
+
138
+ The `useLiveness` hook exposes the following values and control functions for managing the liveness detection session.
139
+
140
+ | Name | Type | Description |
141
+ |-----|------|-------------|
142
+ | `webcamRef` | `ref` | React ref attached to the webcam component. Provides access to the live video stream used for face and hand detection as well as frame capture for verification. |
143
+ | `status` | `string` | Represents the current state of the liveness session. Possible values include `loading`, `ready`, `capturing`, `verifying`, `success`, `error`, and `expired`. |
144
+ | `errorMsg` | `string` | Contains the error message displayed when the liveness verification fails or when the system encounters an issue. |
145
+ | `sequence` | `string[]` | The randomized sequence of liveness challenges selected for the current session. Three challenges are chosen from the challenge pool. |
146
+ | `currentStep` | `number` | The index of the current challenge being performed within the challenge sequence. |
147
+ | `timeLeft` | `number` | Remaining time (in seconds) before the session expires. The timer runs while the system is in the `capturing` state. |
148
+ | `isStepTransitioning` | `boolean` | Indicates whether the system is currently transitioning between challenges. Used to briefly pause detection and provide UI feedback after a challenge is completed. |
149
+ | `start` | `function` | Starts the liveness challenge session and begins the detection loop. |
150
+ | `reset` | `function` | Resets the entire session, including the timer, challenge sequence, step index, and error state. |
151
+ | `sendFinalProof` | `function` | Sends captured face frames to the backend verification API to perform the final liveness check. Normally triggered automatically after the last challenge is completed. |
152
+
153
+
154
+
118
155
 
119
156
  ---
120
157
 
@@ -126,6 +163,7 @@ classNames={{
126
163
  container: "liveness-container",
127
164
  webcam: "liveness-webcam",
128
165
  button: "liveness-button",
166
+ challenge: "liveness-challenge",
129
167
  timer: "liveness-timer",
130
168
  error: "liveness-error",
131
169
  success: "liveness-success",
@@ -158,6 +196,11 @@ classNames={{
158
196
  cursor: pointer;
159
197
  margin-top: 10px;
160
198
  }
199
+ .liveness-challenge {
200
+ margin: 5px 0;
201
+ font-weight: bold;
202
+ font-size: 40px;
203
+ }
161
204
  .liveness-timer {
162
205
  margin: 10px 0;
163
206
  font-weight: bold;
@@ -203,7 +246,7 @@ classNames={{
203
246
 
204
247
  - Webcam permissions required
205
248
  - Backend must accept 5 frames in expected format
206
- - `apiUrl` must be reachable and have an endpoint `v1/verify`
249
+ - `apiUrl` must be reachable and have an endpoint `/v1/verify`
207
250
  - CORS must be configured properly
208
251
 
209
252
  ---