@richard.fadiora/liveness-detection 2.1.0 → 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 +88 -128
- package/dist/index.es.js +2280 -2279
- package/dist/index.umd.js +23 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,195 +1,155 @@
|
|
|
1
|
-
# Liveness Detection
|
|
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
|
-
##
|
|
9
|
+
## Overview
|
|
8
10
|
|
|
9
|
-
|
|
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
|
|
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
|
|
25
|
+
- Video replay or injection attacks
|
|
21
26
|
|
|
22
27
|
---
|
|
23
28
|
|
|
24
|
-
##
|
|
29
|
+
## How It Works
|
|
25
30
|
|
|
26
|
-
###
|
|
31
|
+
### Challenge Initialization
|
|
27
32
|
|
|
28
|
-
|
|
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
|
-
|
|
31
|
-
- The challenges are chosen from a fixed pool of 4:
|
|
38
|
+
### Challenge Execution
|
|
32
39
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
44
|
+
### Backend Liveness Verification
|
|
39
45
|
|
|
40
|
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
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
|
-
|
|
52
|
+
## Success & Failure Behavior
|
|
48
53
|
|
|
49
|
-
|
|
50
|
-
-
|
|
51
|
-
-
|
|
54
|
+
**Success:**
|
|
55
|
+
- UI displays success message
|
|
56
|
+
- onComplete callback triggered with frame and skin confidence
|
|
52
57
|
|
|
53
|
-
|
|
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
|
-
|
|
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
|
-
onError(false)
|
|
86
|
-
```
|
|
87
|
-
This is because the parameters being passed for both completion and Error are the same: success, result, and skinConfidence.
|
|
88
|
-
|
|
89
|
-
---
|
|
90
|
-
|
|
91
|
-
## 📦 Props
|
|
65
|
+
## Props
|
|
92
66
|
|
|
93
67
|
| Prop Name | Type | Required | Description |
|
|
94
68
|
|------------|----------------------------|----------|-------------|
|
|
95
|
-
| `apiUrl`
|
|
96
|
-
| `onComplete` | `(result: boolean) => void` | Yes
|
|
97
|
-
| `onError` | `(result: boolean) => void` | Yes
|
|
98
|
-
| `duration` | `int` | No
|
|
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 |
|
|
99
75
|
|
|
100
76
|
---
|
|
101
77
|
|
|
102
|
-
##
|
|
78
|
+
## Usage Example
|
|
103
79
|
|
|
80
|
+
**Default UI:**
|
|
104
81
|
```jsx
|
|
105
|
-
import { LivenessSDK } from
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
console.log("User verified successfully");
|
|
114
|
-
} else {
|
|
115
|
-
console.log("Liveness verification failed");
|
|
116
|
-
}
|
|
117
|
-
}}
|
|
118
|
-
/>
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
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
|
+
/>
|
|
123
90
|
```
|
|
124
91
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
+
```
|
|
135
108
|
|
|
136
109
|
---
|
|
137
110
|
|
|
138
|
-
##
|
|
139
|
-
|
|
140
|
-
This component uses a layered approach:
|
|
111
|
+
## Timeout Rules
|
|
141
112
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
- Real-time gesture detection
|
|
113
|
+
- Max session duration: `duration` prop (default 60s)
|
|
114
|
+
- Expiry stops challenge, resets state, requires restart, no backend call
|
|
145
115
|
|
|
146
|
-
|
|
147
|
-
- Frame-based spoof analysis
|
|
148
|
-
- Glare detection
|
|
149
|
-
- Video injection detection
|
|
116
|
+
---
|
|
150
117
|
|
|
151
|
-
|
|
152
|
-
- Timeout enforcement
|
|
153
|
-
- Restart requirement on failure
|
|
118
|
+
## Security Architecture
|
|
154
119
|
|
|
155
|
-
|
|
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
|
|
156
123
|
|
|
157
124
|
---
|
|
158
125
|
|
|
159
|
-
##
|
|
160
|
-
|
|
161
|
-
A verification is considered successful only if:
|
|
162
|
-
|
|
163
|
-
- 3 randomly selected challenges are completed
|
|
164
|
-
- All 5 frames are successfully sent to the backend
|
|
165
|
-
- Backend confirms:
|
|
166
|
-
- No spoofing detected
|
|
167
|
-
- No glare detected
|
|
168
|
-
- Skin Texture is human
|
|
169
|
-
- No video injection detected
|
|
126
|
+
## Verification Criteria
|
|
170
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
|
|
171
131
|
|
|
172
132
|
---
|
|
173
133
|
|
|
174
|
-
##
|
|
134
|
+
## Integration Notes
|
|
175
135
|
|
|
176
|
-
-
|
|
177
|
-
-
|
|
178
|
-
-
|
|
179
|
-
- 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
|
|
180
139
|
|
|
181
140
|
---
|
|
182
141
|
|
|
183
|
-
##
|
|
142
|
+
## Ideal Use Cases
|
|
184
143
|
|
|
185
144
|
- KYC verification flows
|
|
186
|
-
- Identity onboarding
|
|
187
|
-
- Account recovery
|
|
145
|
+
- Identity onboarding
|
|
146
|
+
- Account recovery
|
|
188
147
|
- Secure login systems
|
|
189
|
-
- Financial
|
|
148
|
+
- Financial/compliance applications
|
|
190
149
|
|
|
191
150
|
---
|
|
192
151
|
|
|
193
|
-
##
|
|
152
|
+
## Maintainer
|
|
153
|
+
|
|
154
|
+
Fadiora Richard.
|
|
194
155
|
|
|
195
|
-
Maintained by Princeps Credit Systems Limited.
|