biometry-sdk 1.2.4 → 1.2.5
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 +215 -66
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,74 +1,211 @@
|
|
|
1
1
|
# biometry-sdk
|
|
2
2
|
|
|
3
3
|
## Overview
|
|
4
|
-
The **Biometry Web SDK** is a software development kit
|
|
4
|
+
The **Biometry Web SDK** is a software development kit designed to simplify the integration of Biometry's API services into your web application. Providing tools, UI components, and utilities enables biometric onboarding (face and voice), liveness checks, and user consent.
|
|
5
|
+
|
|
6
|
+
## Table of Contents:
|
|
7
|
+
- [Installation](#installation)
|
|
8
|
+
- [Basic Usage (Direct SDK Methods)](#basic-usage-direct-sdk-methods)
|
|
9
|
+
- [Consent](#1-give-consent)
|
|
10
|
+
- [Face Onboarding](#2-face-onboarding)
|
|
11
|
+
- [Voice Onboarding](#3-voice-onboarding)
|
|
12
|
+
- [Process Video](#4-process-video)
|
|
13
|
+
- [Advanced Usage & Best Practices](#advanced-usage-best-practices)
|
|
14
|
+
- [A Typical docAuth + FaceMatch Flow](#)
|
|
15
|
+
- [Use Cases with processVideoRequestId and usePrefilledVideo](#)
|
|
16
|
+
- [Error Handling](#)
|
|
17
|
+
- [Security & Privacy Considerations](#)
|
|
18
|
+
- [UI Components](#)
|
|
19
|
+
- [Face Onboarding Component](#)
|
|
20
|
+
- [Process Video Component](#)
|
|
5
21
|
|
|
6
|
-
## Features
|
|
7
|
-
- **Consent management**: Ask a permission to store their biometric data for authentication using Biometry.
|
|
8
|
-
- **Voice onboarding**: Onboard voice for Voice Recognition.
|
|
9
|
-
- **Face onboarding**: Onboard face for face recognition.
|
|
10
|
-
- Includes a customizable **Face Onboarding UI Component** for streamlined user interactions.
|
|
11
|
-
- **Face match**: Compares extracted image from user’s personal document with the frame from the `/process-video.`
|
|
12
|
-
- **Process video**: Process the video through Biometry services to check liveness and authorize user.
|
|
13
|
-
- (UI Component for this feature coming soon)
|
|
14
22
|
|
|
15
23
|
## Installation
|
|
24
|
+
Install the Biometry Web SDK via npm:
|
|
16
25
|
```bash
|
|
17
26
|
npm install biometry-sdk
|
|
18
27
|
```
|
|
19
28
|
|
|
20
|
-
## Usage
|
|
29
|
+
## Basic Usage (Direct SDK Methods)
|
|
30
|
+
After installing, import and instantiate the BiometrySDK:
|
|
21
31
|
```typescript
|
|
22
32
|
import { BiometrySDK } from 'biometry-sdk';
|
|
23
33
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const videoFile = new File([/* file parts */], "video.mp4", {type: "video/mp4"});
|
|
27
|
-
const phrase = "one two three four five six";
|
|
28
|
-
const userFullName = "John Doe";
|
|
29
|
-
|
|
30
|
-
const response = await sdk.processVideo(videoFile, phrase, userFullName);
|
|
31
|
-
console.log(response);
|
|
34
|
+
// Initialize the SDK with your API key
|
|
35
|
+
const sdk = new BiometrySDK('YOUR_API_KEY');
|
|
32
36
|
```
|
|
33
37
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
### Example
|
|
39
|
+
You can find an example in the example/ directory. The example demonstrates how you might integrate the BiometrySDK in a React component with the state.
|
|
40
|
+
|
|
41
|
+
### 1. Give Consent
|
|
42
|
+
You **must** obtain user consent before performing any biometric operations:
|
|
43
|
+
```javascript
|
|
44
|
+
await sdk.giveConsent(true, 'John Doe');
|
|
45
|
+
// or
|
|
46
|
+
sdk.giveConsent(true, 'John Doe').then(() => {
|
|
47
|
+
console.log('Consent given');
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
- The first argument (`true`) indicates that the user has granted consent.
|
|
51
|
+
- The second argument is the user’s full name (used for record-keeping within Biometry).
|
|
52
|
+
|
|
53
|
+
### 2. Face Onboarding
|
|
54
|
+
Onboard a user’s face for future recognition or matching:
|
|
55
|
+
```javascript
|
|
56
|
+
const faceFile = new File([/* face image bytes */], 'face.jpg', { type: 'image/jpeg' });
|
|
57
|
+
|
|
58
|
+
// Onboard face
|
|
59
|
+
const faceResponse = await sdk.onboardFace(faceFile, 'John Doe');
|
|
60
|
+
console.log('Face Onboarding Response:', faceResponse);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 3. Voice Onboarding
|
|
64
|
+
Enroll a user’s voice for future authentication checks:
|
|
65
|
+
```javascript
|
|
66
|
+
const voiceFile = new File([/* voice audio bytes */], 'voice.wav', { type: 'audio/wav' });
|
|
67
|
+
|
|
68
|
+
await sdk.giveConsent(true, 'John Doe');
|
|
69
|
+
const voiceResponse = await sdk.enrollVoice(voiceFile, 'John Doe');
|
|
70
|
+
console.log('Voice Onboarding Response:', voiceResponse);
|
|
71
|
+
```
|
|
72
|
+
### 4. Process Video
|
|
73
|
+
Process a user’s video for liveness checks and identity authorization:
|
|
74
|
+
```javascript
|
|
75
|
+
const videoFile = new File([/* file parts */], 'video.mp4', { type: 'video/mp4' });
|
|
76
|
+
const phrase = "one two three four five six";
|
|
77
|
+
const userFullName = 'John Doe';
|
|
78
|
+
|
|
79
|
+
await sdk.giveConsent(true, userFullName);
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const response = await sdk.processVideo(videoFile, phrase, userFullName);
|
|
83
|
+
console.log('Process Video Response:', response);
|
|
84
|
+
|
|
85
|
+
// The response headers or body may include a processVideoRequestId (for reuse).
|
|
86
|
+
const { requestId: processVideoRequestId } = response;
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error('Error processing video:', error);
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
## Advanced Usage & Best Practices
|
|
92
|
+
### A Typical docAuth + FaceMatch Flow
|
|
93
|
+
One common advanced scenario involves document authentication (docAuth) and face matching:
|
|
94
|
+
1. docAuth: The user uploads a picture of their identity document (front side with the face).
|
|
95
|
+
2. Face Onboarding or Process Video: Capture the user’s live face.
|
|
96
|
+
3. Face Match: Compare the extracted face from the document with the user’s live face to verify identity.
|
|
97
|
+
|
|
98
|
+
Below is a possible flow (method names in your SDK may vary slightly depending on your integration setup):
|
|
99
|
+
```javascript
|
|
100
|
+
// 1. Acquire user consent
|
|
101
|
+
await sdk.giveConsent(true, userFullName);
|
|
102
|
+
|
|
103
|
+
// 2. User uploads or captures their ID document
|
|
104
|
+
const docFile = new File([/* document bytes */], 'document.jpg', { type: 'image/jpeg' });
|
|
105
|
+
const docAuthResponse = await sdk.docAuth(docFile, userFullName);
|
|
106
|
+
|
|
107
|
+
// 3. Onboard or capture the user’s live face
|
|
108
|
+
// (Either using onboardFace or processVideo, depending on your user flow)
|
|
109
|
+
const userFaceFile = new File([/* user selfie bytes */], 'selfie.jpg', { type: 'image/jpeg' });
|
|
110
|
+
const onboardResponse = await sdk.onboardFace(userFaceFile, userFullName);
|
|
111
|
+
|
|
112
|
+
// 4. Face Match (Compare doc face with user’s onboarded face)
|
|
113
|
+
const faceMatchResponse = await sdk.faceMatch(
|
|
114
|
+
docAuthResponse.extractedFace,
|
|
115
|
+
userFaceFile,
|
|
116
|
+
userFullName
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
// 5. Evaluate the faceMatch result
|
|
120
|
+
if (faceMatchResponse.matchResult === 'match') {
|
|
121
|
+
console.log('User doc face matches user’s live face. Identity verified!');
|
|
122
|
+
} else {
|
|
123
|
+
console.log('User doc face does NOT match. Additional verification needed.');
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
**Notes:**
|
|
127
|
+
- The `docAuth` method name may differ depending on your specific implementation. Some integrations do the doc face extraction automatically, while others provide a separate endpoint.
|
|
128
|
+
- `extractedFace` in `docAuthResponse` can be a reference (like an ID) or raw data. Confirm your exact API response structure to properly pass it to `faceMatch`.
|
|
129
|
+
|
|
130
|
+
### Use Cases with processVideoRequestId and usePrefilledVideo
|
|
131
|
+
- `processVideoRequestId`: After calling `sdk.processVideo()`, you typically receive a unique ID (`requestId`). You can pass this `processVideoRequestId` into subsequent calls (e.g., `faceMatch`) to reference the previously uploaded video frames.
|
|
132
|
+
- `usePrefilledVideo`: When set to `true`, indicates that the SDK should reuse the video already on file from a previous `processVideo` call rather than requiring a new upload.
|
|
133
|
+
Example:
|
|
134
|
+
```javascript
|
|
135
|
+
const { requestId } = await sdk.processVideo(videoFile, phrase, userFullName);
|
|
136
|
+
|
|
137
|
+
// Later on, we can reuse that video for face match or advanced checks
|
|
138
|
+
const faceMatchResp = await sdk.faceMatch(null, null, userFullName, {
|
|
139
|
+
processVideoRequestId: requestId,
|
|
140
|
+
usePrefilledVideo: true
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
Here, `faceMatch` might not require new face data if it can extract frames from the previously uploaded video.
|
|
144
|
+
### Error Handling
|
|
145
|
+
All SDK calls can throw errors for various reasons:
|
|
146
|
+
- Network/Connection Issues
|
|
147
|
+
- Invalid File Types
|
|
148
|
+
- No Face Detected (Face Onboarding)
|
|
149
|
+
- No Speech Detected (Voice Onboarding)
|
|
150
|
+
- Multiple Faces Detected (Face Onboarding)
|
|
151
|
+
- Liveness Check Failure (Process Video)
|
|
152
|
+
|
|
153
|
+
Always wrap calls in try/catch and provide user-friendly messages or fallback logic.
|
|
154
|
+
```javascript
|
|
155
|
+
try {
|
|
156
|
+
const response = await sdk.faceMatch(...);
|
|
157
|
+
// handle success
|
|
158
|
+
} catch (error) {
|
|
159
|
+
// handle error
|
|
160
|
+
console.error('Face match error:', error);
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
### Security & Privacy Considerations
|
|
164
|
+
1. **Protect Your API Key:** Avoid storing your API key in client-side code if possible. Use environment variables or server-side proxies.
|
|
165
|
+
2. **Obtain Explicit Consent:** Ensure you have a transparent process for obtaining and storing user consent.
|
|
166
|
+
3. **Data Minimization:** Only store data that is required for your use case.
|
|
167
|
+
4. **Regulatory Compliance:** Check local regulations (GDPR, CCPA, etc.) for storing and processing biometric data.
|
|
37
168
|
|
|
38
169
|
## UI Components
|
|
39
|
-
|
|
170
|
+
In addition to direct SDK methods, the Biometry Web SDK offers reusable Web Components that handle user interactions (camera, video recording, error states) automatically.
|
|
171
|
+
The Biometry Web SDK includes reusable, customizable web components for crucial features. These components are easy to embed into your application and handle the most common biometric operations with minimal setup.
|
|
40
172
|
|
|
41
173
|
### Face Onboarding Component
|
|
42
|
-
|
|
174
|
+
This component provides an intuitive interface for onboarding users with their cameras. It integrates directly with the `BiometrySDK backend`, managing camera capture, consent checks, and error handling.
|
|
43
175
|
|
|
44
176
|
### Integration
|
|
45
177
|
Here's how to integrate the `Face Onboarding` component into your application:
|
|
46
178
|
|
|
47
179
|
**Option 1: Using npm (Recommended for full SDK usage)**
|
|
48
180
|
1. Install the SDK package via **npm**:
|
|
49
|
-
```bash
|
|
50
|
-
npm install biometry-sdk
|
|
51
|
-
```
|
|
181
|
+
```bash
|
|
182
|
+
npm install biometry-sdk
|
|
183
|
+
```
|
|
52
184
|
2. Import the component in your **index.js** or equivalent JavaScript file:
|
|
53
|
-
```javascript
|
|
54
|
-
// index.js
|
|
55
|
-
import './node_modules/biometry-sdk/dist/
|
|
56
|
-
```
|
|
185
|
+
```javascript
|
|
186
|
+
// index.js
|
|
187
|
+
import './node_modules/biometry-sdk/dist/biometry-sdk.esm.js';
|
|
188
|
+
```
|
|
57
189
|
3. Connect the script to your **HTML file** and use the component:
|
|
58
|
-
```html
|
|
59
|
-
<script type="module" src="./index.js"></script>
|
|
60
|
-
```
|
|
190
|
+
```html
|
|
191
|
+
<script type="module" src="./index.js"></script>
|
|
192
|
+
```
|
|
61
193
|
|
|
62
194
|
|
|
63
195
|
**Option 2: Using CDN (Quick Integration)**
|
|
64
196
|
```html
|
|
65
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/biometry-sdk/dist/
|
|
197
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/biometry-sdk/dist/biometry-sdk.esm.js"></script>
|
|
66
198
|
```
|
|
67
199
|
|
|
68
200
|
### Usage
|
|
69
|
-
|
|
201
|
+
**Required attributes:**
|
|
202
|
+
- `api-key`: Your Biometry API key.
|
|
203
|
+
- `user-fullname`: The user’s full name (used in data storage and consent).
|
|
70
204
|
|
|
71
|
-
|
|
205
|
+
**Slots:**
|
|
206
|
+
- `video`: Your custom <video> element.
|
|
207
|
+
- `button`: Custom capture button.
|
|
208
|
+
- `loading`, `success`, `error-no-face`, `error-multiple-faces`, `error-not-centered`, `error-other`: Custom UI messages for different states.
|
|
72
209
|
|
|
73
210
|
**Basic Usage**
|
|
74
211
|
```html
|
|
@@ -98,38 +235,31 @@ Custom slots allow you to style and customize UI elements, loading, success, and
|
|
|
98
235
|
```
|
|
99
236
|
|
|
100
237
|
### Process Video Component
|
|
101
|
-
The Process Video component
|
|
238
|
+
The **Process Video** component enables you to record, upload, and process a video within your application. It integrates with Biometry's services to check liveness and authorize the user.
|
|
102
239
|
|
|
103
240
|
### Integration
|
|
104
241
|
**Option 1: Install via npm**
|
|
105
|
-
|
|
106
242
|
1. To include the component in your project, install the biometry-sdk package:
|
|
107
|
-
```bash
|
|
108
|
-
npm install biometry-sdk
|
|
109
|
-
```
|
|
110
|
-
|
|
243
|
+
```bash
|
|
244
|
+
npm install biometry-sdk
|
|
245
|
+
```
|
|
111
246
|
2. After installation, import the component into your project:
|
|
112
|
-
```javascript
|
|
113
|
-
// index.js
|
|
114
|
-
import './node_modules/biometry-sdk/dist/
|
|
115
|
-
```
|
|
116
|
-
|
|
247
|
+
```javascript
|
|
248
|
+
// index.js
|
|
249
|
+
import './node_modules/biometry-sdk/dist/biometry-sdk.esm.js';
|
|
250
|
+
```
|
|
117
251
|
3. Include the component in your HTML:
|
|
252
|
+
You can skip the npm installation and include the component directly in your HTML:
|
|
253
|
+
```html
|
|
254
|
+
<script type="module" src="./index.js"></script>
|
|
255
|
+
<process-video ...></process-video>
|
|
256
|
+
```
|
|
257
|
+
**Option 2: Using CDN (Quick Integration)**
|
|
118
258
|
```html
|
|
119
|
-
<script type="module" src="
|
|
120
|
-
<process-video ...></process-video>
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
**Option 2: Import directly via CDN**
|
|
124
|
-
|
|
125
|
-
You can skip the npm installation and include the component directly in your HTML:
|
|
126
|
-
```html
|
|
127
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/biometry-sdk/dist/components/process-video.js"></script>
|
|
259
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/biometry-sdk/dist/biometry-sdk.esm.js"></script>
|
|
128
260
|
<process-video ...></process-video>
|
|
129
261
|
```
|
|
130
|
-
|
|
131
262
|
### Usage
|
|
132
|
-
|
|
133
263
|
**Basic Usage**
|
|
134
264
|
```html
|
|
135
265
|
<process-video
|
|
@@ -163,16 +293,35 @@ You can skip the npm installation and include the component directly in your HTM
|
|
|
163
293
|
<div slot="success">Video submitted successfully!</div>
|
|
164
294
|
</process-video>
|
|
165
295
|
```
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
296
|
+
**Note:**
|
|
297
|
+
- All default elements and messages are functional out-of-the-box.
|
|
298
|
+
- Replace slots if you want to customize the UI or functionality.
|
|
299
|
+
- Call giveConsent() before using any biometric methods to ensure compliance with data processing requirements.
|
|
300
|
+
|
|
301
|
+
## Best Practices
|
|
302
|
+
1. **Always Acquire Consent**
|
|
303
|
+
- Before performing Face Onboarding or Process Video, you can call:
|
|
304
|
+
```javascript
|
|
305
|
+
sdk.giveConsent(true, userFullName);
|
|
306
|
+
```
|
|
307
|
+
- Or directly send a request to the `/consent` in the [official documentation](https://developer.biometrysolutions.com/overview/).
|
|
308
|
+
|
|
309
|
+
This ensures legal compliance and user awareness when storing and processing biometric data.
|
|
310
|
+
3. **Handle Errors Gracefully**
|
|
311
|
+
- The SDK methods throw errors if something goes wrong (e.g., network, permission, or detection errors). Use try/catch or .catch() to handle them.
|
|
312
|
+
4. **Security**
|
|
313
|
+
- Protect your API key. Avoid exposing it in public repositories or client-side code if possible.
|
|
314
|
+
|
|
172
315
|
## License
|
|
173
316
|
|
|
174
317
|
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
|
|
175
318
|
|
|
176
319
|
## More Information
|
|
177
|
-
|
|
178
|
-
|
|
320
|
+
For more detailed information on Biometry’s API endpoints, parameters, and responses, visit the official [Biometry API Documentation](https://developer.biometrysolutions.com/overview/). If you have questions or need help, please reach out to our support team or create a GitHub issue.
|
|
321
|
+
|
|
322
|
+
## Quick Reference
|
|
323
|
+
- Install: `npm install biometry-sdk`
|
|
324
|
+
- Consent: `sdk.giveConsent(true, userFullName)` (Required before onboarding/processing)
|
|
325
|
+
- Voice Onboarding: `sdk.enrollVoice(file, userFullName)`
|
|
326
|
+
- Face Onboarding: `sdk.enrollFace(file, userFullName)`
|
|
327
|
+
- Process Video: `sdk.processVideo(file, phrase, userFullName)`
|