biometry-react-components 1.4.0 → 2.0.1

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 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, userFullName, { sessionId });
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, 'John Doe');
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 10 random numbers (0-9) for the user to read aloud. Automatically extracts audio from the recorded video. This component could be used for [Process Video](https://developer.biometrysolutions.com/api/process-video/) and [Voice Enrollment](https://developer.biometrysolutions.com/api/voice-enrollment/)
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 FaceRecorder() {
94
- const handleConfirm = (video: File, audio: File, phrase: string) => {
95
- console.log('Confirmed video:', video);
96
- console.log('Confirmed audio:', audio);
97
- console.log('Phrase:', phrase);
98
- // Send files to your endpoint that will process the biometric data
99
- // const response = await sdk.processVideo(video, phrase, userFullName);
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` | `(video: File, audio: File, phrase: string) => void` | **required** | Triggered when the user confirms they want to use the recorded video. Provides both media files and the spoken phrase. |
113
- | `onRecorded` | `(video: File, audio: File, phrase: string) => void` | *optional* | Triggered automatically right after recording finishes. Useful for pre-uploading or background processing. |
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,30 +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
- The user is prompted with all ten digits (`0-9`) in random order and gets a 10-second recording window. Both are enrollment requirements: the engine builds a text-prompted digit voiceprint, and verification later prompts a random subset, so the enrollment sample has to cover every digit.
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.
125
147
 
126
- > **Note:** the engine builds its voiceprint from **several** recordings. A print built from a single take carries one recording's worth of acoustic variation and scores close enough to the engine's threshold that genuine users can be rejected at login. Call the component more than once and post every take in the same enrollment request (repeated `voice` parts, one `phrase` part each).
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.
127
156
 
128
157
  ```tsx
129
- import { VoiceRecorder } from 'biometry-react-components';
130
-
131
- function VoiceRecorder() {
132
- const handleConfirm = (file: File, phrase: string) => {
133
- console.log('Confirmed audio:', file);
134
- console.log('Phrase:', phrase);
135
- // const response = await sdk.enrollVoice(file, 'John Doe');
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');
136
166
  };
137
167
 
138
168
  return <VoiceRecorder onConfirmRecording={handleConfirm} />;
139
169
  }
140
170
  ```
141
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
+
142
179
  #### Props
143
180
 
144
181
  | Prop | Type | Default | Description |
145
182
  |------|------|---------|-------------|
146
- | `onConfirmRecording` | `(file: File, phrase: string) => void` | **required** | Callback with captured audio file and phrase. Triggered when the user confirms the recorded media |
147
- | `onRecorded` | `(file: File, phrase: string) => void` | *optional* | Callback with captured audio file and phrase. Triggered automatically when recording finishes |
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. |
148
186
  | `rectWidth` | `number` | `360` | Width of component area |
149
187
  | `rectHeight` | `number` | `undefined` | Height of component area (optional) |
150
188
  | `className` | `string` | - | Custom CSS class |
package/dist/index.d.ts CHANGED
@@ -22,28 +22,145 @@ 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
- onConfirmRecording: (file: File, audio: File, phrase: string) => void;
29
- onRecorded?: (video: File, audio: File, phrase: string) => void;
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
- onConfirmRecording: (file: File, phrase: string) => void;
40
- onRecorded?: (file: File, phrase: string) => void;
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
165
  declare const useRecorder: (stream: MediaStream | null, type: "audio" | "video", onStopRecording: OnStopRecordingFunc, lengthMs?: number) => {
49
166
  isRecording: boolean;
@@ -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 };