biometry-sdk 1.2.4 → 1.2.6
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 +245 -73
- package/dist/biometry-sdk.esm.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,74 +1,214 @@
|
|
|
1
1
|
# biometry-sdk
|
|
2
2
|
|
|
3
3
|
## Overview
|
|
4
|
-
The **Biometry Web SDK** is a software development kit
|
|
5
|
-
|
|
6
|
-
##
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
|
|
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 And Best Practices](#advanced-usage-and-best-practices)
|
|
14
|
+
- [Typical FaceMatch Flow](#typical-facematch-flow)
|
|
15
|
+
- [Use Cases with processVideoRequestId and usePrefilledVideo](#use-cases-with-processVideoRequestId-and-usePrefilledVideo)
|
|
16
|
+
- [Error Handling](#error-handling)
|
|
17
|
+
- [Security And Privacy Considerations](#security-and-privacy-considerations)
|
|
18
|
+
- [UI Components](#ui-components)
|
|
19
|
+
- [Face Onboarding Component](#face-onboarding-component)
|
|
20
|
+
- [Process Video Component](#process-video-component)
|
|
21
|
+
- [License](#license)
|
|
22
|
+
- [More Information](#more-information)
|
|
23
|
+
- [Quick Reference](#quick-reference)
|
|
14
24
|
|
|
15
25
|
## Installation
|
|
26
|
+
Install the Biometry Web SDK via npm:
|
|
16
27
|
```bash
|
|
17
28
|
npm install biometry-sdk
|
|
18
29
|
```
|
|
19
30
|
|
|
20
|
-
## Usage
|
|
31
|
+
## Basic Usage (Direct SDK Methods)
|
|
32
|
+
After installing, import and instantiate the BiometrySDK:
|
|
21
33
|
```typescript
|
|
22
34
|
import { BiometrySDK } from 'biometry-sdk';
|
|
23
35
|
|
|
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);
|
|
36
|
+
// Initialize the SDK with your API key
|
|
37
|
+
const sdk = new BiometrySDK('YOUR_API_KEY');
|
|
32
38
|
```
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
### Example
|
|
41
|
+
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.
|
|
42
|
+
|
|
43
|
+
### 1. Give Consent
|
|
44
|
+
You **must** obtain user consent before performing any biometric operations:
|
|
45
|
+
```javascript
|
|
46
|
+
await sdk.giveConsent(true, 'John Doe');
|
|
47
|
+
// or
|
|
48
|
+
sdk.giveConsent(true, 'John Doe').then(() => {
|
|
49
|
+
console.log('Consent given');
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
- The first argument (`true`) indicates that the user has granted consent.
|
|
53
|
+
- The second argument is the user’s full name (used for record-keeping within Biometry).
|
|
54
|
+
|
|
55
|
+
### 2. Face Onboarding
|
|
56
|
+
Onboard a user’s face for future recognition or matching:
|
|
57
|
+
```javascript
|
|
58
|
+
const faceFile = new File([/* face image bytes */], 'face.jpg', { type: 'image/jpeg' });
|
|
59
|
+
|
|
60
|
+
// Onboard face
|
|
61
|
+
const faceResponse = await sdk.onboardFace(faceFile, 'John Doe');
|
|
62
|
+
console.log('Face Onboarding Response:', faceResponse);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 3. Voice Onboarding
|
|
66
|
+
Enroll a user’s voice for future authentication checks:
|
|
67
|
+
```javascript
|
|
68
|
+
const voiceFile = new File([/* voice audio bytes */], 'voice.wav', { type: 'audio/wav' });
|
|
69
|
+
|
|
70
|
+
await sdk.giveConsent(true, 'John Doe');
|
|
71
|
+
const voiceResponse = await sdk.onboardVoice(voiceFile, 'John Doe');
|
|
72
|
+
console.log('Voice Onboarding Response:', voiceResponse);
|
|
73
|
+
```
|
|
74
|
+
### 4. Process Video
|
|
75
|
+
Process a user’s video for liveness checks and identity authorization:
|
|
76
|
+
```javascript
|
|
77
|
+
const videoFile = new File([/* file parts */], 'video.mp4', { type: 'video/mp4' });
|
|
78
|
+
const phrase = "one two three four five six";
|
|
79
|
+
const userFullName = 'John Doe';
|
|
80
|
+
|
|
81
|
+
await sdk.giveConsent(true, userFullName);
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
const response = await sdk.processVideo(videoFile, phrase, userFullName);
|
|
85
|
+
console.log('Process Video Response:', response);
|
|
86
|
+
|
|
87
|
+
// The response headers or body may include a processVideoRequestId (for reuse).
|
|
88
|
+
const { requestId: processVideoRequestId } = response;
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.error('Error processing video:', error);
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
## Advanced Usage And Best Practices
|
|
94
|
+
### Typical FaceMatch Flow
|
|
95
|
+
One common advanced scenario involves document authentication in onboarding face and face matching:
|
|
96
|
+
1. Face Onboarding: Capture the user’s live face or the user uploads a picture of their identity document (front side with the face)
|
|
97
|
+
2. Process Video: Capture the user’s live face
|
|
98
|
+
3. Face Match: Compare the extracted face from the document with the user’s live face to verify identity.
|
|
99
|
+
|
|
100
|
+
Below is a possible flow (method names in your SDK may vary slightly depending on your integration setup):
|
|
101
|
+
```javascript
|
|
102
|
+
// 1. Acquire user consent
|
|
103
|
+
await sdk.giveConsent(true, userFullName);
|
|
104
|
+
|
|
105
|
+
// 2. Onboard or capture the user’s face
|
|
106
|
+
// (Either using onboardFace or processVideo, depending on your user flow)
|
|
107
|
+
const userFaceFile = new File([/* user selfie bytes */], 'image.jpg', { type: 'image/jpeg' });
|
|
108
|
+
const userVideoFile = new File([/* user selfie bytes */], 'video.mp4', { type: 'video/*' });
|
|
109
|
+
const onboardResponse = await sdk.onboardFace(userFaceFile, userFullName);
|
|
110
|
+
|
|
111
|
+
// 3. Face Match (Compare video face with user’s onboarded face)
|
|
112
|
+
const faceMatchResponse = await sdk.faceMatch(
|
|
113
|
+
userFaceFile,
|
|
114
|
+
userVideoFile,
|
|
115
|
+
userFullName
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
// 4. Evaluate the faceMatch result
|
|
119
|
+
if (faceMatchResponse.matchResult === 'match') {
|
|
120
|
+
console.log('User video face matches user’s live face. Identity verified!');
|
|
121
|
+
} else {
|
|
122
|
+
console.log('User video face does NOT match. Additional verification needed.');
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Use Cases with processVideoRequestId and usePrefilledVideo
|
|
127
|
+
- `processVideoRequestId`: After calling `sdk.processVideo()`, you typically receive a unique ID (`x-request-id`). You can pass this `processVideoRequestId` into subsequent calls (e.g., `faceMatch`) to reference the previously uploaded video frames.
|
|
128
|
+
- `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.
|
|
129
|
+
Example:
|
|
130
|
+
```javascript
|
|
131
|
+
const { x-request-id } = await sdk.processVideo(videoFile, phrase, userFullName);
|
|
132
|
+
|
|
133
|
+
// Later on, we can reuse that video for face match or advanced checks
|
|
134
|
+
const faceMatchResp = await sdk.faceMatch(null, null, userFullName, {
|
|
135
|
+
processVideoRequestId: requestId,
|
|
136
|
+
usePrefilledVideo: true
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
Here, `faceMatch` might not require new face data if it can extract frames from the previously uploaded video.
|
|
140
|
+
### Error Handling
|
|
141
|
+
All SDK calls can throw errors for various reasons:
|
|
142
|
+
- Network/Connection Issues
|
|
143
|
+
- Invalid File Types
|
|
144
|
+
- No Face Detected (Face Onboarding)
|
|
145
|
+
- No Speech Detected (Voice Onboarding)
|
|
146
|
+
- Multiple Faces Detected (Face Onboarding)
|
|
147
|
+
- Liveness Check Failure (Process Video)
|
|
148
|
+
|
|
149
|
+
Always wrap calls in try/catch and provide user-friendly messages or fallback logic.
|
|
150
|
+
```javascript
|
|
151
|
+
try {
|
|
152
|
+
const response = await sdk.faceMatch(...);
|
|
153
|
+
// handle success
|
|
154
|
+
} catch (error) {
|
|
155
|
+
// handle error
|
|
156
|
+
console.error('Face match error:', error);
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
### Security And Privacy Considerations
|
|
160
|
+
1. **Protect Your API Key:** Avoid storing your API key in client-side code if possible. Use environment variables or server-side proxies.
|
|
161
|
+
2. **Obtain Explicit Consent:** Ensure you have a transparent process for obtaining and storing user consent.
|
|
162
|
+
3. **Data Minimization:** Only store data that is required for your use case.
|
|
163
|
+
4. **Regulatory Compliance:** Check local regulations (GDPR, CCPA, etc.) for storing and processing biometric data.
|
|
37
164
|
|
|
38
165
|
## UI Components
|
|
39
|
-
|
|
166
|
+
In addition to direct SDK methods, the Biometry Web SDK offers reusable Web Components that handle user interactions (camera, video recording, error states) automatically.
|
|
167
|
+
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
168
|
|
|
41
169
|
### Face Onboarding Component
|
|
42
|
-
|
|
170
|
+
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
171
|
|
|
44
172
|
### Integration
|
|
45
|
-
Here's how to integrate the `Face Onboarding` component into your application:
|
|
46
|
-
|
|
47
173
|
**Option 1: Using npm (Recommended for full SDK usage)**
|
|
48
174
|
1. Install the SDK package via **npm**:
|
|
49
|
-
```bash
|
|
50
|
-
npm install biometry-sdk
|
|
51
|
-
```
|
|
175
|
+
```bash
|
|
176
|
+
npm install biometry-sdk
|
|
177
|
+
```
|
|
52
178
|
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
|
-
```
|
|
179
|
+
```javascript
|
|
180
|
+
// index.js
|
|
181
|
+
import './node_modules/biometry-sdk/dist/biometry-sdk.esm.js';
|
|
182
|
+
```
|
|
57
183
|
3. Connect the script to your **HTML file** and use the component:
|
|
58
|
-
```html
|
|
59
|
-
<script type="module" src="./index.js"></script>
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
184
|
+
```html
|
|
185
|
+
<script type="module" src="./index.js"></script>
|
|
186
|
+
|
|
187
|
+
<biometry-onboarding
|
|
188
|
+
api-key="your-api-key"
|
|
189
|
+
user-fullname="John Doe">
|
|
190
|
+
</biometry-onboarding>
|
|
191
|
+
```
|
|
192
|
+
|
|
63
193
|
**Option 2: Using CDN (Quick Integration)**
|
|
64
194
|
```html
|
|
65
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/biometry-sdk/dist/
|
|
195
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/biometry-sdk/dist/biometry-sdk.esm.js"></script>
|
|
196
|
+
|
|
197
|
+
<biometry-onboarding
|
|
198
|
+
api-key="your-api-key"
|
|
199
|
+
user-fullname="John Doe">
|
|
200
|
+
</biometry-onboarding>
|
|
66
201
|
```
|
|
67
202
|
|
|
68
203
|
### Usage
|
|
69
|
-
|
|
204
|
+
**Required attributes:**
|
|
205
|
+
- `api-key`: Your Biometry API key.
|
|
206
|
+
- `user-fullname`: The user’s full name (used in data storage and consent).
|
|
70
207
|
|
|
71
|
-
|
|
208
|
+
**Slots:**
|
|
209
|
+
- `video`: Your custom `<video>` element.
|
|
210
|
+
- `button`: Custom capture button.
|
|
211
|
+
- `loading`, `success`, `error-no-face`, `error-multiple-faces`, `error-not-centered`, `error-other`: Custom UI messages for different states.
|
|
72
212
|
|
|
73
213
|
**Basic Usage**
|
|
74
214
|
```html
|
|
@@ -82,7 +222,7 @@ Custom slots allow you to style and customize UI elements, loading, success, and
|
|
|
82
222
|
```html
|
|
83
223
|
<biometry-onboarding
|
|
84
224
|
api-key="your-api-key"
|
|
85
|
-
user-fullname="
|
|
225
|
+
user-fullname="John Doe">
|
|
86
226
|
|
|
87
227
|
<video slot="video" autoplay playsinline style="width: 100%; border-radius: 10px;"></video>
|
|
88
228
|
<button slot="button" style="padding: 10px 20px; font-size: 16px;">Capture</button>
|
|
@@ -98,43 +238,38 @@ Custom slots allow you to style and customize UI elements, loading, success, and
|
|
|
98
238
|
```
|
|
99
239
|
|
|
100
240
|
### Process Video Component
|
|
101
|
-
The Process Video component
|
|
241
|
+
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
242
|
|
|
103
243
|
### Integration
|
|
104
244
|
**Option 1: Install via npm**
|
|
105
|
-
|
|
106
245
|
1. To include the component in your project, install the biometry-sdk package:
|
|
107
|
-
```bash
|
|
108
|
-
npm install biometry-sdk
|
|
109
|
-
```
|
|
110
|
-
|
|
246
|
+
```bash
|
|
247
|
+
npm install biometry-sdk
|
|
248
|
+
```
|
|
111
249
|
2. After installation, import the component into your project:
|
|
112
|
-
```javascript
|
|
113
|
-
// index.js
|
|
114
|
-
import './node_modules/biometry-sdk/dist/
|
|
115
|
-
```
|
|
116
|
-
|
|
250
|
+
```javascript
|
|
251
|
+
// index.js
|
|
252
|
+
import './node_modules/biometry-sdk/dist/biometry-sdk.esm.js';
|
|
253
|
+
```
|
|
117
254
|
3. Include the component in your HTML:
|
|
255
|
+
You can skip the npm installation and include the component directly in your HTML:
|
|
256
|
+
```html
|
|
257
|
+
<script type="module" src="./index.js"></script>
|
|
258
|
+
|
|
259
|
+
<process-video ...></process-video>
|
|
260
|
+
```
|
|
261
|
+
**Option 2: Using CDN (Quick Integration)**
|
|
118
262
|
```html
|
|
119
|
-
<script type="module" src="
|
|
120
|
-
<process-video ...></process-video>
|
|
121
|
-
```
|
|
263
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/biometry-sdk/dist/biometry-sdk.esm.js"></script>
|
|
122
264
|
|
|
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>
|
|
128
265
|
<process-video ...></process-video>
|
|
129
266
|
```
|
|
130
|
-
|
|
131
267
|
### Usage
|
|
132
|
-
|
|
133
268
|
**Basic Usage**
|
|
134
269
|
```html
|
|
135
270
|
<process-video
|
|
136
271
|
api-key="your-api-key"
|
|
137
|
-
user-fullname="
|
|
272
|
+
user-fullname="John Doe"
|
|
138
273
|
></process-video>
|
|
139
274
|
```
|
|
140
275
|
|
|
@@ -142,7 +277,7 @@ You can skip the npm installation and include the component directly in your HTM
|
|
|
142
277
|
```html
|
|
143
278
|
<process-video
|
|
144
279
|
api-key="eyJhb...apikey"
|
|
145
|
-
user-fullname="John Doe
|
|
280
|
+
user-fullname="John Doe"
|
|
146
281
|
>
|
|
147
282
|
<!-- Custom video element -->
|
|
148
283
|
<video slot="video" muted playsinline style="border-radius: 1rem;"></video>
|
|
@@ -163,16 +298,53 @@ You can skip the npm installation and include the component directly in your HTM
|
|
|
163
298
|
<div slot="success">Video submitted successfully!</div>
|
|
164
299
|
</process-video>
|
|
165
300
|
```
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
301
|
+
**Note:**
|
|
302
|
+
- All default elements and messages are functional out-of-the-box.
|
|
303
|
+
- Replace slots if you want to customize the UI or functionality.
|
|
304
|
+
- Call giveConsent() before using any biometric methods to ensure compliance with data processing requirements.
|
|
305
|
+
|
|
172
306
|
## License
|
|
173
307
|
|
|
174
308
|
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
|
|
175
309
|
|
|
176
310
|
## More Information
|
|
177
|
-
|
|
178
|
-
|
|
311
|
+
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.
|
|
312
|
+
|
|
313
|
+
## Quick Reference
|
|
314
|
+
- **Install**:
|
|
315
|
+
```bash
|
|
316
|
+
npm install biometry-sdk
|
|
317
|
+
```
|
|
318
|
+
- **Consent**: (Required before onboarding/processing)
|
|
319
|
+
```javascript
|
|
320
|
+
sdk.giveConsent(true, userFullName)
|
|
321
|
+
```
|
|
322
|
+
- **Voice Onboarding**:
|
|
323
|
+
```javascript
|
|
324
|
+
sdk.onbaordVoice(file, userFullName)
|
|
325
|
+
```
|
|
326
|
+
- **Face Onboarding**:
|
|
327
|
+
```javascript
|
|
328
|
+
sdk.onboardFace(file, userFullName)
|
|
329
|
+
```
|
|
330
|
+
- Face match
|
|
331
|
+
```javascript
|
|
332
|
+
sdk.faceMatch(image, video, userFullName, { ...options });
|
|
333
|
+
```
|
|
334
|
+
- Process Video (basic):
|
|
335
|
+
```javascript
|
|
336
|
+
sdk.processVideo(file, phrase, userFullName);
|
|
337
|
+
```
|
|
338
|
+
- Process Video (advanced w/ reusing video or linking IDs):
|
|
339
|
+
```javascript
|
|
340
|
+
sdk.processVideo(null, phrase, userFullName, {
|
|
341
|
+
usePrefilledVideo: true,
|
|
342
|
+
processVideoRequestId: 'YOUR_REQUEST_ID',
|
|
343
|
+
requestUserProvidedId: 'YOUR_CUSTOM_ID'
|
|
344
|
+
});
|
|
345
|
+
```
|
|
346
|
+
- UI Components:
|
|
347
|
+
- `<biometry-onboarding ...>` (face onboarding)
|
|
348
|
+
- `<process-video ...>` (video onboarding)
|
|
349
|
+
With these **direct SDK methods**, **UI components**, and advanced **best practices** (faceOnboard + faceMatch flows, reuse of video, error handling), you can build robust, privacy-conscious biometric solutions on your web application.
|
|
350
|
+
|
package/dist/biometry-sdk.esm.js
CHANGED
|
@@ -1319,6 +1319,10 @@ class ProcessVideoComponent extends HTMLElement {
|
|
|
1319
1319
|
this.videoElement.play();
|
|
1320
1320
|
this.videoElement.muted = false;
|
|
1321
1321
|
this.stopTimer();
|
|
1322
|
+
// Clean up the object URL when the video loads
|
|
1323
|
+
this.videoElement.onloadeddata = () => {
|
|
1324
|
+
URL.revokeObjectURL(videoURL);
|
|
1325
|
+
};
|
|
1322
1326
|
}
|
|
1323
1327
|
handleFileUpload(event) {
|
|
1324
1328
|
var _a, _b;
|