biometry-react-components 1.3.5 → 2.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 +68 -26
- package/dist/index.d.ts +124 -6
- package/dist/index.esm.js +263 -135
- package/dist/index.js +263 -135
- package/package.json +14 -7
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# biometry-react-components
|
|
2
2
|
|
|
3
|
-
React UI component library with tools to work with camera and microphone for easier integration of Biometry services. This library could be used in combination with [Biometry SDK](https://www.npmjs.com/package/biometry-sdk)
|
|
3
|
+
React UI component library with tools to work with camera and microphone for easier integration of Biometry services. This library could be used in combination with the [Biometry SDK](https://www.npmjs.com/package/biometry-sdk) (v3+, targeting the Biometry API v2).
|
|
4
|
+
|
|
5
|
+
> The SDK snippets below use the **API v2** methods. Biometric calls identify the end user with an opaque, customer-provided `userId` (not a full name).
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
@@ -35,7 +37,7 @@ function DocumentCapture() {
|
|
|
35
37
|
console.log('Confirmed captured document:', file);
|
|
36
38
|
// Send file to your endpoint that will process DocAuth (we recommend this way, because you will not expose the API key on client side)
|
|
37
39
|
// or
|
|
38
|
-
// const response = await sdk.checkDocAuth(file,
|
|
40
|
+
// const response = await sdk.checkDocAuth(file, { sessionId });
|
|
39
41
|
};
|
|
40
42
|
|
|
41
43
|
return <DocScan onConfirmCapture={handleConfirmCapture} />;
|
|
@@ -64,7 +66,9 @@ import { FaceCapture } from 'biometry-react-components';
|
|
|
64
66
|
function FaceCapture() {
|
|
65
67
|
const handleConfirmCapture = (file: File) => {
|
|
66
68
|
console.log('Confirmed captured face:', file);
|
|
67
|
-
// const response = await sdk.enrollFace(file, '
|
|
69
|
+
// const response = await sdk.enrollFace(file, 'user-123'); // 'user-123' = your opaque userId
|
|
70
|
+
// or, to match against a reference image:
|
|
71
|
+
// const response = await sdk.matchFaces(referenceImage, 'user-123', { video });
|
|
68
72
|
};
|
|
69
73
|
|
|
70
74
|
return <FaceCapture onConfirmCapture={handleConfirmCapture} />;
|
|
@@ -85,32 +89,48 @@ function FaceCapture() {
|
|
|
85
89
|
|
|
86
90
|
### FaceRecorder
|
|
87
91
|
|
|
88
|
-
Records video with facial guidance overlay and displays
|
|
92
|
+
Records video with facial guidance overlay and displays challenge digits for the user to read aloud. Use it for [Process Video](https://developer.biometrysolutions.com/api/process-video/).
|
|
89
93
|
|
|
90
94
|
```tsx
|
|
91
|
-
import { FaceRecorder } from 'biometry-react-components';
|
|
92
|
-
|
|
93
|
-
function
|
|
94
|
-
const handleConfirm = (
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
//
|
|
99
|
-
// const response = await sdk.
|
|
100
|
-
// or
|
|
101
|
-
// const voiceResponse = await sdk.enrollVoice(audio, userFullName);
|
|
95
|
+
import { FaceRecorder, type FaceRecording } from 'biometry-react-components';
|
|
96
|
+
|
|
97
|
+
function Verify() {
|
|
98
|
+
const handleConfirm = ({ file, phrase }: FaceRecording) => {
|
|
99
|
+
// Upload the video. The voice is extracted server-side from the same file
|
|
100
|
+
// that passed the liveness check, so there is no separate audio to send.
|
|
101
|
+
// const response = await sdk.liveness(file, 'user-123', phrase);
|
|
102
|
+
// or, to verify against an enrolled face:
|
|
103
|
+
// const response = await sdk.faceVerify(file, 'user-123', phrase);
|
|
102
104
|
};
|
|
103
105
|
|
|
104
106
|
return <FaceRecorder onConfirmRecording={handleConfirm} />;
|
|
105
107
|
}
|
|
106
108
|
```
|
|
107
109
|
|
|
110
|
+
> **Breaking change in 2.0.0:** both callbacks now receive a single object,
|
|
111
|
+
> `{ file, audio?, phrase }`, instead of the positional `(video, audio, phrase)`.
|
|
112
|
+
> The old middle `audio` argument could not simply be dropped — doing so would
|
|
113
|
+
> have shifted `phrase` into its slot for every JavaScript consumer with no
|
|
114
|
+
> warning — so the payload became an object in one break.
|
|
115
|
+
>
|
|
116
|
+
> `audio` is no longer produced by default. The blob was byte-identical to the
|
|
117
|
+
> video's own audio track (RecordRTC hands both encoders the same
|
|
118
|
+
> `MediaStreamTrack`) and nothing consumed it. It also must not be consumed for
|
|
119
|
+
> verification: the backend binds the voice check to the video that passed
|
|
120
|
+
> liveness, so a separately supplied audio file would let one person's video be
|
|
121
|
+
> paired with another's audio. Set `emitAudio` only if you need the blob for
|
|
122
|
+
> something else.
|
|
123
|
+
|
|
108
124
|
#### Props
|
|
109
125
|
|
|
110
126
|
| Prop | Type | Default | Description |
|
|
111
127
|
|------|------|---------|-------------|
|
|
112
|
-
| `onConfirmRecording` | `(
|
|
113
|
-
| `onRecorded` | `(
|
|
128
|
+
| `onConfirmRecording` | `(recording: FaceRecording) => void` | **required** | Triggered when the user confirms the recording. Receives `{ file, audio?, phrase }`. |
|
|
129
|
+
| `onRecorded` | `(recording: FaceRecording) => void` | *optional* | Triggered right after recording finishes, before confirmation. |
|
|
130
|
+
| `challengeDigits` | `number[] \| null` | `undefined` | Server-issued challenge digits (each `0–9`) the user must read, so the backend can verify the spoken digits against what it issued. Invalid or empty values fall back to a generated challenge. Applied only while idle. |
|
|
131
|
+
| `recordingSeconds` | `number` | `7` | Recording duration. The window is fixed — capture stops when it expires, and a clipped final digit fails the engine's quality check before any comparison. Widen it when the challenge is longer than the default. |
|
|
132
|
+
| `countdownSeconds` | `number` | `3` | Lead-in before recording starts. |
|
|
133
|
+
| `emitAudio` | `boolean` | `false` | Also record a separate audio track and expose it as `audio`. See the note above. |
|
|
114
134
|
| `rectWidth` | `number` | `360` | Width of camera area |
|
|
115
135
|
| `rectHeight` | `number` | `576` | Height of camera area |
|
|
116
136
|
| `className` | `string` | - | Custom CSS class |
|
|
@@ -121,26 +141,48 @@ function FaceRecorder() {
|
|
|
121
141
|
|
|
122
142
|
Records audio with real-time waveform visualization and adaptive quality settings. Use this for [Voice Enrollment](https://developer.biometrysolutions.com/api/voice-enrollment/)
|
|
123
143
|
|
|
124
|
-
|
|
125
|
-
|
|
144
|
+
The component collects **five takes** in one session and emits them together.
|
|
145
|
+
Each take prompts a different fixed 9-digit sequence from the vendor's published
|
|
146
|
+
set, and a 10-second window.
|
|
126
147
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
148
|
+
> **Why five, and why fixed sequences.** Four is the vendor floor — a
|
|
149
|
+
> random-phrase digit voiceprint should contain at least four different
|
|
150
|
+
> utterances, each with a different digit sequence — and the guide says to use
|
|
151
|
+
> more where possible. A print built from a single take scores well immediately
|
|
152
|
+
> after enrollment and poorly on every later attempt. The sequences are fixed
|
|
153
|
+
> rather than random because they contain no duplicate 2-digit contexts, and
|
|
154
|
+
> presenting every user the same prompts is what keeps cross-user calibration
|
|
155
|
+
> accurate — calibration being what sets the acceptance threshold.
|
|
156
|
+
|
|
157
|
+
```tsx
|
|
158
|
+
import { VoiceRecorder, type VoiceEnrollment } from 'biometry-react-components';
|
|
159
|
+
|
|
160
|
+
function Enroll() {
|
|
161
|
+
// Fires once, after the last take is confirmed.
|
|
162
|
+
const handleConfirm = async ({ files, phrases }: VoiceEnrollment) => {
|
|
163
|
+
// Post every take in one enrollment request: repeated `voice` parts, one
|
|
164
|
+
// `phrase` part each. A partial set is worse than none.
|
|
165
|
+
// await sdk.enrollVoice(files, phrases, 'user-123');
|
|
132
166
|
};
|
|
133
167
|
|
|
134
168
|
return <VoiceRecorder onConfirmRecording={handleConfirm} />;
|
|
135
169
|
}
|
|
136
170
|
```
|
|
137
171
|
|
|
172
|
+
> **Breaking change in 2.0.0:** `onConfirmRecording` previously fired per
|
|
173
|
+
> recording with `(file, phrase)`. It now fires **once**, when every take has
|
|
174
|
+
> been confirmed, with `{ files, phrases }`. A consumer that genuinely wants one
|
|
175
|
+
> recording can pass `takes={1}` and read `files[0]` / `phrases[0]` — but see
|
|
176
|
+
> the note above first. `onRecorded` still fires per take, now with
|
|
177
|
+
> `{ file, phrase }`.
|
|
178
|
+
|
|
138
179
|
#### Props
|
|
139
180
|
|
|
140
181
|
| Prop | Type | Default | Description |
|
|
141
182
|
|------|------|---------|-------------|
|
|
142
|
-
| `onConfirmRecording` | `(
|
|
143
|
-
| `onRecorded` | `(
|
|
183
|
+
| `onConfirmRecording` | `(enrollment: VoiceEnrollment) => void` | **required** | Fires once, when all takes are confirmed. Receives `{ files, phrases }`. |
|
|
184
|
+
| `onRecorded` | `(take: VoiceTake) => void` | *optional* | Fires as each take finishes, before the user confirms it. Receives `{ file, phrase }`. |
|
|
185
|
+
| `takes` | `number` | `5` | Recordings collected per enrollment. |
|
|
144
186
|
| `rectWidth` | `number` | `360` | Width of component area |
|
|
145
187
|
| `rectHeight` | `number` | `undefined` | Height of component area (optional) |
|
|
146
188
|
| `className` | `string` | - | Custom CSS class |
|
package/dist/index.d.ts
CHANGED
|
@@ -22,30 +22,147 @@ interface FaceCaptureProps {
|
|
|
22
22
|
}
|
|
23
23
|
declare const FaceCapture: React.FC<FaceCaptureProps>;
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* What the recorder hands back. `audio` is present only when `emitAudio` is set.
|
|
27
|
+
*
|
|
28
|
+
* An object, not positional arguments: dropping the old middle `audio` argument
|
|
29
|
+
* would have shifted `phrase` into its slot for every JavaScript consumer with
|
|
30
|
+
* no warning at all (BM-461).
|
|
31
|
+
*/
|
|
32
|
+
interface FaceRecording {
|
|
33
|
+
file: File;
|
|
34
|
+
audio?: File;
|
|
35
|
+
phrase: string;
|
|
36
|
+
}
|
|
25
37
|
interface FaceRecorderProps {
|
|
26
38
|
rectWidth?: number;
|
|
27
39
|
rectHeight?: number;
|
|
28
|
-
|
|
29
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Server-issued liveness challenge digits the user must read aloud (each 0–9).
|
|
42
|
+
* When provided these are shown and emitted instead of a generated challenge,
|
|
43
|
+
* so the backend can verify the spoken digits against what it issued. Omitted
|
|
44
|
+
* or invalid values fall back to a generated challenge.
|
|
45
|
+
*/
|
|
46
|
+
challengeDigits?: number[] | null;
|
|
47
|
+
/**
|
|
48
|
+
* Recording duration in seconds.
|
|
49
|
+
*
|
|
50
|
+
* The window is fixed: capture stops when it expires whether or not the
|
|
51
|
+
* person has finished speaking, and a clipped final digit fails the engine's
|
|
52
|
+
* quality check before any comparison happens. Widen it when the challenge is
|
|
53
|
+
* longer than the default.
|
|
54
|
+
*/
|
|
55
|
+
recordingSeconds?: number;
|
|
56
|
+
/** Lead-in countdown before recording starts, in seconds. */
|
|
57
|
+
countdownSeconds?: number;
|
|
58
|
+
/**
|
|
59
|
+
* Also record a separate audio track and expose it as `audio`.
|
|
60
|
+
*
|
|
61
|
+
* Off by default. The blob is byte-identical to the video's own audio track —
|
|
62
|
+
* RecordRTC hands both encoders the same MediaStreamTrack — so it is a second
|
|
63
|
+
* Opus encode of the same samples for a file nothing consumes. It must also
|
|
64
|
+
* stay unconsumed for verification: the backend binds the voice check to the
|
|
65
|
+
* video that passed liveness, so a separately supplied audio file would let
|
|
66
|
+
* person A's video be paired with person B's audio.
|
|
67
|
+
*/
|
|
68
|
+
emitAudio?: boolean;
|
|
69
|
+
onConfirmRecording: (recording: FaceRecording) => void;
|
|
70
|
+
onRecorded?: (recording: FaceRecording) => void;
|
|
30
71
|
className?: string;
|
|
31
72
|
style?: React.CSSProperties;
|
|
32
73
|
noShadow?: boolean;
|
|
33
74
|
}
|
|
34
75
|
declare const FaceRecorder: React.FC<FaceRecorderProps>;
|
|
35
76
|
|
|
77
|
+
/** One confirmed take. */
|
|
78
|
+
interface VoiceTake {
|
|
79
|
+
file: File;
|
|
80
|
+
phrase: string;
|
|
81
|
+
}
|
|
82
|
+
/** The completed enrollment: every take, in the order they were recorded. */
|
|
83
|
+
interface VoiceEnrollment {
|
|
84
|
+
files: File[];
|
|
85
|
+
phrases: string[];
|
|
86
|
+
}
|
|
36
87
|
interface VoiceRecorderProps {
|
|
37
88
|
rectWidth?: number;
|
|
38
89
|
rectHeight?: number | undefined;
|
|
39
|
-
|
|
40
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Recordings collected per enrollment.
|
|
92
|
+
*
|
|
93
|
+
* Five. Four is the vendor floor — a random-phrase digit voiceprint should
|
|
94
|
+
* contain at least four different utterances, each with a different sequence
|
|
95
|
+
* of digits — but the same guide says to use more where possible. A print
|
|
96
|
+
* built from one take scores well immediately after enrollment and poorly on
|
|
97
|
+
* every later attempt (BM-407, BM-430).
|
|
98
|
+
*/
|
|
99
|
+
takes?: number;
|
|
100
|
+
/** Emitted as each take finishes, before the user confirms it. */
|
|
101
|
+
onRecorded?: (take: VoiceTake) => void;
|
|
102
|
+
/** Emitted once, when every take has been confirmed. */
|
|
103
|
+
onConfirmRecording: (enrollment: VoiceEnrollment) => void;
|
|
41
104
|
className?: string;
|
|
42
105
|
style?: React.CSSProperties;
|
|
43
106
|
noShadow?: boolean;
|
|
44
107
|
}
|
|
45
108
|
declare const VoiceRecorder: React.FC<VoiceRecorderProps>;
|
|
46
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Digit challenge and phrase helpers, kept in step with
|
|
112
|
+
* biometry-angular-components `src/lib/utils/numbers.ts`. The two packages must
|
|
113
|
+
* produce the same `phrase` for the same digits: it is compared against what the
|
|
114
|
+
* voice engine recognised, so a divergence here is a verification failure with no
|
|
115
|
+
* obvious cause.
|
|
116
|
+
*/
|
|
117
|
+
/**
|
|
118
|
+
* Digits a generated challenge may contain.
|
|
119
|
+
*
|
|
120
|
+
* `0` is deliberately absent. A server-issued challenge may still contain one
|
|
121
|
+
* while the backend rolls out, and numbersToPhrase tolerates that — but nothing
|
|
122
|
+
* we generate emits it.
|
|
123
|
+
*/
|
|
124
|
+
declare const CHALLENGE_DIGITS: readonly number[];
|
|
125
|
+
/**
|
|
126
|
+
* Enrolment prompts, taken verbatim from the vendor guide's published set.
|
|
127
|
+
*
|
|
128
|
+
* These are fixed, not random, and that is the point: random prompting is only
|
|
129
|
+
* required at verification time. Presenting every user the same sequences is
|
|
130
|
+
* also what makes cross-user calibration accurate — and calibration is what
|
|
131
|
+
* sets our acceptance threshold (BM-449).
|
|
132
|
+
*
|
|
133
|
+
* The guide selects these specifically because they contain no duplicate
|
|
134
|
+
* 2-digit contexts: biometric performance depends on co-articulation between
|
|
135
|
+
* adjacent digits, and "321" and "123" are different contexts for "2". Drawing
|
|
136
|
+
* enrolment prompts at random gives each user an arbitrary, unmeasured slice of
|
|
137
|
+
* that space.
|
|
138
|
+
*
|
|
139
|
+
* Order matters: the first two are count-up and count-down, which the guide
|
|
140
|
+
* uses to open its enrolment flow because they are the easiest to comply with.
|
|
141
|
+
*/
|
|
142
|
+
declare const ENROLMENT_DIGIT_SEQUENCES: readonly (readonly number[])[];
|
|
143
|
+
/**
|
|
144
|
+
* Render digits as the spoken words the engine expects in `phrase`.
|
|
145
|
+
*
|
|
146
|
+
* Lowercase, matching the Angular package and therefore the only casing that
|
|
147
|
+
* has been exercised in production. The gateway forwards `phrase` to the engine
|
|
148
|
+
* untouched, so the client's casing is what gets compared.
|
|
149
|
+
*
|
|
150
|
+
* `zero` is retained even though we no longer generate it: a server-issued
|
|
151
|
+
* challenge may contain a 0, and rendering it as "0" would send a phrase the
|
|
152
|
+
* engine cannot match at all. A digit outside 0–9 is passed through as-is
|
|
153
|
+
* rather than silently becoming a word that was never displayed.
|
|
154
|
+
*/
|
|
155
|
+
declare function numbersToPhrase(digits: number[]): string;
|
|
156
|
+
/**
|
|
157
|
+
* `count` distinct digits drawn from CHALLENGE_DIGITS, in random order.
|
|
158
|
+
*
|
|
159
|
+
* Used for the face recorder's fallback challenge when the server issued none.
|
|
160
|
+
* Enrolment does not call this — see ENROLMENT_DIGIT_SEQUENCES.
|
|
161
|
+
*/
|
|
162
|
+
declare function generateRandomDigits(count: number): number[];
|
|
163
|
+
|
|
47
164
|
type OnStopRecordingFunc = (blob: Blob) => void;
|
|
48
|
-
declare const useRecorder: (stream: MediaStream | null, type: "audio" | "video", onStopRecording: OnStopRecordingFunc) => {
|
|
165
|
+
declare const useRecorder: (stream: MediaStream | null, type: "audio" | "video", onStopRecording: OnStopRecordingFunc, lengthMs?: number) => {
|
|
49
166
|
isRecording: boolean;
|
|
50
167
|
startRecording: () => void;
|
|
51
168
|
stopRecording: () => void;
|
|
@@ -72,4 +189,5 @@ declare const useAudioPermissions: () => {
|
|
|
72
189
|
isLoading: boolean;
|
|
73
190
|
};
|
|
74
191
|
|
|
75
|
-
export { DocScan, FaceCapture, FaceRecorder, VoiceRecorder, useAudioPermissions, usePermissions, useRecorder };
|
|
192
|
+
export { CHALLENGE_DIGITS, DocScan, ENROLMENT_DIGIT_SEQUENCES, FaceCapture, FaceRecorder, VoiceRecorder, generateRandomDigits, numbersToPhrase, useAudioPermissions, usePermissions, useRecorder };
|
|
193
|
+
export type { FaceRecorderProps, FaceRecording, VoiceEnrollment, VoiceRecorderProps, VoiceTake };
|