biometry-sdk 1.3.2 → 1.3.4
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 +53 -85
- package/dist/biometry-sdk.esm.js +5 -9
- package/dist/sdk.d.ts +1 -1
- package/dist/types/biometry/doc-auth.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,8 +41,25 @@ const sdk = new BiometrySDK('YOUR_API_KEY');
|
|
|
41
41
|
### Example
|
|
42
42
|
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.
|
|
43
43
|
|
|
44
|
-
### 1.
|
|
45
|
-
|
|
44
|
+
### 1. Sessions
|
|
45
|
+
Session is a way to group transactions together. It is useful when you want to group transactions that are related to each other. For example, you can start a session and then use the session ID to link transactions within a unified group.
|
|
46
|
+
```javascript
|
|
47
|
+
const response = await sdk.startSession();
|
|
48
|
+
const sessionId = response.data;
|
|
49
|
+
|
|
50
|
+
const voiceFile = new File([/* voice audio bytes */], 'voice.wav', { type: 'audio/wav' });
|
|
51
|
+
const faceFile = new File([/* face image bytes */], 'face.jpg', { type: 'image/jpeg' });
|
|
52
|
+
|
|
53
|
+
// Use the session ID to link transactions within a unified group
|
|
54
|
+
await sdk.giveStorageConsent(true, 'John Doe', { sessionId });
|
|
55
|
+
await sdk.enrollFace(faceFile, 'John Doe', { sessionId });
|
|
56
|
+
await sdk.enrollVoice(voiceFile, 'John Doe', { sessionId });
|
|
57
|
+
|
|
58
|
+
// Go to the Results page in your dashboard and see the transactions grouped by the session ID
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 2. Consents
|
|
62
|
+
#### 2.1 Give Authorization Consent
|
|
46
63
|
You **must** obtain user authorization consent before performing any biometric operations (Face Recognition, Voice Recognition, etc.):
|
|
47
64
|
```javascript
|
|
48
65
|
await sdk.giveAuthorizationConsent(true, 'John Doe');
|
|
@@ -54,7 +71,7 @@ You **must** obtain user authorization consent before performing any biometric o
|
|
|
54
71
|
- The first argument (`true`) indicates that the user has granted consent.
|
|
55
72
|
- The second argument is the user’s full name (used for record-keeping within Biometry).
|
|
56
73
|
|
|
57
|
-
####
|
|
74
|
+
#### 2.2 Give Storage Consent
|
|
58
75
|
You **must** obtain user consent before storing biometric data (Face Enrollment, Voice Enrollment):
|
|
59
76
|
```javascript
|
|
60
77
|
await sdk.giveStorageConsent(true, 'John Doe');
|
|
@@ -66,7 +83,7 @@ You **must** obtain user consent before storing biometric data (Face Enrollment,
|
|
|
66
83
|
- The first argument (`true`) indicates that the user has granted consent.
|
|
67
84
|
- The second argument is the user’s full name (used for record-keeping within Biometry).
|
|
68
85
|
|
|
69
|
-
###
|
|
86
|
+
### 3. Face Enrollment
|
|
70
87
|
Enroll a user’s face for future recognition or matching:
|
|
71
88
|
```javascript
|
|
72
89
|
const faceFile = new File([/* face image bytes */], 'face.jpg', { type: 'image/jpeg' });
|
|
@@ -76,7 +93,7 @@ Enroll a user’s face for future recognition or matching:
|
|
|
76
93
|
console.log('Face Enrollment Response:', faceResponse);
|
|
77
94
|
```
|
|
78
95
|
|
|
79
|
-
###
|
|
96
|
+
### 4. Voice Enrollment
|
|
80
97
|
Enroll a user’s voice for future authentication checks:
|
|
81
98
|
```javascript
|
|
82
99
|
const voiceFile = new File([/* voice audio bytes */], 'voice.wav', { type: 'audio/wav' });
|
|
@@ -85,7 +102,7 @@ Enroll a user’s voice for future authentication checks:
|
|
|
85
102
|
const voiceResponse = await sdk.enrollVoice(voiceFile, 'John Doe');
|
|
86
103
|
console.log('Voice Enrollment Response:', voiceResponse);
|
|
87
104
|
```
|
|
88
|
-
###
|
|
105
|
+
### 5. Process Video
|
|
89
106
|
Process a user’s video for liveness checks and identity authorization:
|
|
90
107
|
```javascript
|
|
91
108
|
const videoFile = new File([/* file parts */], 'video.mp4', { type: 'video/mp4' });
|
|
@@ -97,28 +114,14 @@ Process a user’s video for liveness checks and identity authorization:
|
|
|
97
114
|
try {
|
|
98
115
|
const response = await sdk.processVideo(videoFile, phrase, userFullName);
|
|
99
116
|
console.log('Process Video Response:', response);
|
|
100
|
-
|
|
101
|
-
// Retrieve the processVideoRequestId from the *response headers* called x-request-id.
|
|
102
117
|
} catch (error) {
|
|
103
118
|
console.error('Error processing video:', error);
|
|
104
119
|
}
|
|
105
120
|
```
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
- `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.
|
|
109
|
-
### 5. Face match
|
|
121
|
+
|
|
122
|
+
### 6. Face match
|
|
110
123
|
Use matchFaces to compare a reference image (e.g., a document or a captured selfie) with a face from a video:
|
|
111
124
|
```javascript
|
|
112
|
-
/**
|
|
113
|
-
* matchFaces(
|
|
114
|
-
* image: File,
|
|
115
|
-
* video?: File,
|
|
116
|
-
* userFullName?: string,
|
|
117
|
-
* processVideoRequestId?: string,
|
|
118
|
-
* usePrefilledVideo?: boolean,
|
|
119
|
-
* requestUserProvidedId?: string
|
|
120
|
-
* ): Promise<FaceMatchResponse>
|
|
121
|
-
*/
|
|
122
125
|
const faceFile = new File([/* face image bytes */], 'face.jpg', { type: 'image/jpeg' });
|
|
123
126
|
const videoFile = new File([/* file parts */], 'video.mp4', { type: 'video/mp4' });
|
|
124
127
|
const userFullName = 'John Doe';
|
|
@@ -128,34 +131,40 @@ Use matchFaces to compare a reference image (e.g., a document or a captured self
|
|
|
128
131
|
videoFile,
|
|
129
132
|
userFullName
|
|
130
133
|
);
|
|
131
|
-
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
You can also reuse a video that was previously processed with the `processVideo` method by passing the same sessionId:
|
|
137
|
+
```javascript
|
|
138
|
+
const sessionId = await sdk.startSession();
|
|
139
|
+
|
|
140
|
+
// First, process a video with a sessionId
|
|
141
|
+
const processVideoResponse = await sdk.processVideo(videoFile, phrase, userFullName, { sessionId });
|
|
142
|
+
|
|
143
|
+
// Later, reuse the same video for face matching by providing the sessionId
|
|
132
144
|
const faceMatchResponse = await sdk.faceMatch(
|
|
133
|
-
faceFile,
|
|
134
|
-
null,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
145
|
+
faceFile,
|
|
146
|
+
null, // No need to pass the video file again
|
|
147
|
+
userFullName,
|
|
148
|
+
true, // usePrefilledVideo
|
|
149
|
+
{ sessionId }
|
|
138
150
|
);
|
|
139
151
|
```
|
|
140
152
|
|
|
141
|
-
###
|
|
142
|
-
|
|
153
|
+
### 7. DocAuth
|
|
154
|
+
DocAuth is a way to authenticate a user's document. It is useful when you want to authenticate a user's document.
|
|
143
155
|
```javascript
|
|
144
156
|
const sessionId = await sdk.startSession();
|
|
145
157
|
|
|
146
|
-
const
|
|
147
|
-
const phrase = "one two three four five six";
|
|
158
|
+
const documentFile = new File([/* file parts */], 'document.jpg', { type: 'image/jpeg' });
|
|
148
159
|
const userFullName = 'John Doe';
|
|
149
160
|
|
|
150
161
|
await sdk.giveAuthorizationConsent(true, userFullName, { sessionId });
|
|
151
162
|
|
|
152
163
|
try {
|
|
153
|
-
const response = await sdk.
|
|
154
|
-
console.log('
|
|
155
|
-
|
|
156
|
-
// Retrieve the processVideoRequestId from the *response headers* called x-request-id.
|
|
164
|
+
const response = await sdk.checkDocAuth(documentFile, userFullName, { sessionId });
|
|
165
|
+
console.log('DocAuth Response:', response);
|
|
157
166
|
} catch (error) {
|
|
158
|
-
console.error('Error
|
|
167
|
+
console.error('Error checking document:', error);
|
|
159
168
|
}
|
|
160
169
|
```
|
|
161
170
|
|
|
@@ -168,8 +177,8 @@ One common advanced scenario involves document authentication in enrollment face
|
|
|
168
177
|
|
|
169
178
|
Below is a possible flow (method names in your SDK may vary slightly depending on your integration setup):
|
|
170
179
|
```javascript
|
|
171
|
-
// 1. Acquire user consent
|
|
172
|
-
await sdk.
|
|
180
|
+
// 1. Acquire user storage consent
|
|
181
|
+
await sdk.giveStorageConsent(true, userFullName);
|
|
173
182
|
|
|
174
183
|
// 2. Enroll or capture the user’s face
|
|
175
184
|
// (Either using enrollFace or processVideo, depending on your user flow)
|
|
@@ -177,14 +186,17 @@ Below is a possible flow (method names in your SDK may vary slightly depending o
|
|
|
177
186
|
const userVideoFile = new File([/* user selfie bytes */], 'video.mp4', { type: 'video/*' });
|
|
178
187
|
const enrollResponse = await sdk.enrollFace(userFaceFile, userFullName);
|
|
179
188
|
|
|
180
|
-
// 3.
|
|
189
|
+
// 3. Acquire user authorization consent. It's required to use enrolled face for using biometric data.
|
|
190
|
+
await sdk.giveAuthorizationConsent(true, userFullName);
|
|
191
|
+
|
|
192
|
+
// 4. Face Match (Compare video face with user’s enrolled face)
|
|
181
193
|
const faceMatchResponse = await sdk.faceMatch(
|
|
182
194
|
userFaceFile,
|
|
183
195
|
userVideoFile,
|
|
184
196
|
userFullName
|
|
185
197
|
);
|
|
186
198
|
|
|
187
|
-
//
|
|
199
|
+
// 5. Evaluate the faceMatch result
|
|
188
200
|
if (faceMatchResponse.matchResult === 'match') {
|
|
189
201
|
console.log('User video face matches user’s live face. Identity verified!');
|
|
190
202
|
} else {
|
|
@@ -326,50 +338,6 @@ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file
|
|
|
326
338
|
## More Information
|
|
327
339
|
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.
|
|
328
340
|
|
|
329
|
-
## Quick Reference
|
|
330
|
-
- **Install**:
|
|
331
|
-
```bash
|
|
332
|
-
npm install biometry-sdk
|
|
333
|
-
```
|
|
334
|
-
- **Consent**: (Required before enrollment/processing)
|
|
335
|
-
```javascript
|
|
336
|
-
sdk.giveConsent(true, userFullName)
|
|
337
|
-
```
|
|
338
|
-
- **Voice Enrollment**:
|
|
339
|
-
```javascript
|
|
340
|
-
sdk.enrollVoice(file, userFullName)
|
|
341
|
-
```
|
|
342
|
-
- **Face Enrollment**:
|
|
343
|
-
```javascript
|
|
344
|
-
sdk.enrollFace(file, userFullName)
|
|
345
|
-
```
|
|
346
|
-
- **Face match (basic):**
|
|
347
|
-
```javascript
|
|
348
|
-
sdk.faceMatch(image, video, userFullName);
|
|
349
|
-
```
|
|
350
|
-
- **Face match (advanced w/ reusing video or linking IDs):**
|
|
351
|
-
```javascript
|
|
352
|
-
sdk.faceMatch(
|
|
353
|
-
image, // Reference image file that contains user's face.
|
|
354
|
-
video, // Video file that contains user's face.
|
|
355
|
-
userFullName,
|
|
356
|
-
processVideoRequestId, // ID from the response header of /process-video endpoint.
|
|
357
|
-
usePrefilledVideo // Pass true to use the video from the process-video endpoint.
|
|
358
|
-
);
|
|
359
|
-
```
|
|
360
|
-
- **Process Video (basic):**
|
|
361
|
-
```javascript
|
|
362
|
-
sdk.processVideo(file, phrase, userFullName);
|
|
363
|
-
```
|
|
364
|
-
- **Process Video (advanced w/ reusing video or linking IDs):**
|
|
365
|
-
```javascript
|
|
366
|
-
sdk.processVideo(
|
|
367
|
-
video, // Video file that you want to process
|
|
368
|
-
phrase,
|
|
369
|
-
userFullName,
|
|
370
|
-
requestUserProvidedId // An optional user-provided ID to link transactions within a unified group
|
|
371
|
-
);
|
|
372
|
-
```
|
|
373
341
|
- **UI Components:**
|
|
374
342
|
- `<biometry-enrollment ...>` (face enrollment)
|
|
375
343
|
- `<process-video ...>` (video enrollment)
|
package/dist/biometry-sdk.esm.js
CHANGED
|
@@ -221,11 +221,13 @@ class BiometrySDK {
|
|
|
221
221
|
* @returns {Promise<FaceMatchResponse>} - A promise resolving to the voice enrolling response.
|
|
222
222
|
* @throws {Error} - If required parameters are missing or the request fails.
|
|
223
223
|
*/
|
|
224
|
-
async matchFaces(image, video, userFullName,
|
|
224
|
+
async matchFaces(image, video, userFullName, usePrefilledVideo, props) {
|
|
225
225
|
if (!image)
|
|
226
226
|
throw new Error('Face image is required.');
|
|
227
|
-
if ((!
|
|
227
|
+
if ((!usePrefilledVideo) && !video)
|
|
228
228
|
throw new Error('Video is required.');
|
|
229
|
+
if (usePrefilledVideo && !(props === null || props === undefined ? undefined : props.sessionId))
|
|
230
|
+
throw new Error('Session ID is required to use a video from the process-video endpoint.');
|
|
229
231
|
const formData = new FormData();
|
|
230
232
|
if (video) {
|
|
231
233
|
formData.append('video', video);
|
|
@@ -235,10 +237,7 @@ class BiometrySDK {
|
|
|
235
237
|
if (userFullName) {
|
|
236
238
|
headers['X-User-Fullname'] = userFullName;
|
|
237
239
|
}
|
|
238
|
-
if (
|
|
239
|
-
headers['X-Request-Id'] = processVideoRequestId;
|
|
240
|
-
}
|
|
241
|
-
if (processVideoRequestId && usePrefilledVideo) {
|
|
240
|
+
if (usePrefilledVideo) {
|
|
242
241
|
headers['X-Use-Prefilled-Video'] = 'true';
|
|
243
242
|
}
|
|
244
243
|
if (props === null || props === undefined ? undefined : props.sessionId) {
|
|
@@ -247,9 +246,6 @@ class BiometrySDK {
|
|
|
247
246
|
if (props === null || props === undefined ? undefined : props.deviceInfo) {
|
|
248
247
|
headers['X-Device-Info'] = JSON.stringify(props.deviceInfo);
|
|
249
248
|
}
|
|
250
|
-
if (props === null || props === undefined ? undefined : props.deviceInfo) {
|
|
251
|
-
headers['X-Device-Info'] = JSON.stringify(props.deviceInfo);
|
|
252
|
-
}
|
|
253
249
|
return await this.request('/api-gateway/match-faces', 'POST', formData, headers);
|
|
254
250
|
}
|
|
255
251
|
/**
|
package/dist/sdk.d.ts
CHANGED
|
@@ -116,7 +116,7 @@ export declare class BiometrySDK {
|
|
|
116
116
|
* @returns {Promise<FaceMatchResponse>} - A promise resolving to the voice enrolling response.
|
|
117
117
|
* @throws {Error} - If required parameters are missing or the request fails.
|
|
118
118
|
*/
|
|
119
|
-
matchFaces(image: File, video?: File, userFullName?: string,
|
|
119
|
+
matchFaces(image: File, video?: File, userFullName?: string, usePrefilledVideo?: boolean, props?: {
|
|
120
120
|
sessionId?: string;
|
|
121
121
|
deviceInfo?: object;
|
|
122
122
|
}): Promise<ApiResponse<FaceMatchResponse>>;
|