@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 +88 -126
- package/dist/index.es.js +2624 -2616
- package/dist/index.umd.js +23 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,193 +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
|
-
onComplete(false)
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
---
|
|
89
|
-
|
|
90
|
-
## 📦 Props
|
|
65
|
+
## Props
|
|
91
66
|
|
|
92
67
|
| Prop Name | Type | Required | Description |
|
|
93
68
|
|------------|----------------------------|----------|-------------|
|
|
94
|
-
| `apiUrl`
|
|
95
|
-
| `onComplete` | `(result: boolean) => void` | Yes
|
|
96
|
-
| `
|
|
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
|
-
##
|
|
78
|
+
## Usage Example
|
|
101
79
|
|
|
80
|
+
**Default UI:**
|
|
102
81
|
```jsx
|
|
103
|
-
import { LivenessSDK } from
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
##
|
|
137
|
-
|
|
138
|
-
This component uses a layered approach:
|
|
111
|
+
## Timeout Rules
|
|
139
112
|
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
145
|
-
- Frame-based spoof analysis
|
|
146
|
-
- Glare detection
|
|
147
|
-
- Video injection detection
|
|
116
|
+
---
|
|
148
117
|
|
|
149
|
-
|
|
150
|
-
- Timeout enforcement
|
|
151
|
-
- Restart requirement on failure
|
|
118
|
+
## Security Architecture
|
|
152
119
|
|
|
153
|
-
|
|
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
|
-
##
|
|
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
|
-
##
|
|
134
|
+
## Integration Notes
|
|
173
135
|
|
|
174
|
-
-
|
|
175
|
-
-
|
|
176
|
-
-
|
|
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
|
-
##
|
|
142
|
+
## Ideal Use Cases
|
|
182
143
|
|
|
183
144
|
- KYC verification flows
|
|
184
|
-
- Identity onboarding
|
|
185
|
-
- Account recovery
|
|
145
|
+
- Identity onboarding
|
|
146
|
+
- Account recovery
|
|
186
147
|
- Secure login systems
|
|
187
|
-
- Financial
|
|
148
|
+
- Financial/compliance applications
|
|
188
149
|
|
|
189
150
|
---
|
|
190
151
|
|
|
191
|
-
##
|
|
152
|
+
## Maintainer
|
|
153
|
+
|
|
154
|
+
Fadiora Richard.
|
|
192
155
|
|
|
193
|
-
Maintained by Princeps Credit Systems Limited.
|