@velion-la/onboarding-sdk-react-native 1.2.0-beta.9 → 1.2.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.
Files changed (33) hide show
  1. package/lib/commonjs/camera/LivenessCamera.js +151 -39
  2. package/lib/commonjs/camera/LivenessCamera.js.map +1 -1
  3. package/lib/commonjs/i18n/strings/en.js +1 -0
  4. package/lib/commonjs/i18n/strings/en.js.map +1 -1
  5. package/lib/commonjs/i18n/strings/es.js +1 -0
  6. package/lib/commonjs/i18n/strings/es.js.map +1 -1
  7. package/lib/commonjs/steps/LivenessMatchStep.js +314 -53
  8. package/lib/commonjs/steps/LivenessMatchStep.js.map +1 -1
  9. package/lib/commonjs/transport/irisWebSocket.js +15 -2
  10. package/lib/commonjs/transport/irisWebSocket.js.map +1 -1
  11. package/lib/module/camera/LivenessCamera.js +152 -40
  12. package/lib/module/camera/LivenessCamera.js.map +1 -1
  13. package/lib/module/i18n/strings/en.js +1 -0
  14. package/lib/module/i18n/strings/en.js.map +1 -1
  15. package/lib/module/i18n/strings/es.js +1 -0
  16. package/lib/module/i18n/strings/es.js.map +1 -1
  17. package/lib/module/steps/LivenessMatchStep.js +317 -56
  18. package/lib/module/steps/LivenessMatchStep.js.map +1 -1
  19. package/lib/module/transport/irisWebSocket.js +15 -2
  20. package/lib/module/transport/irisWebSocket.js.map +1 -1
  21. package/lib/typescript/camera/LivenessCamera.d.ts +78 -10
  22. package/lib/typescript/camera/LivenessCamera.d.ts.map +1 -1
  23. package/lib/typescript/i18n/strings/en.d.ts.map +1 -1
  24. package/lib/typescript/i18n/strings/es.d.ts +1 -0
  25. package/lib/typescript/i18n/strings/es.d.ts.map +1 -1
  26. package/lib/typescript/steps/LivenessMatchStep.d.ts.map +1 -1
  27. package/lib/typescript/transport/irisWebSocket.d.ts.map +1 -1
  28. package/package.json +1 -1
  29. package/src/camera/LivenessCamera.tsx +172 -38
  30. package/src/i18n/strings/en.ts +2 -0
  31. package/src/i18n/strings/es.ts +2 -0
  32. package/src/steps/LivenessMatchStep.tsx +362 -75
  33. package/src/transport/irisWebSocket.ts +13 -1
@@ -2,15 +2,18 @@
2
2
  * @fileoverview Liveness camera surface — front-facing vision-camera with an
3
3
  * oval mask, status pill, and capture loop driven by the parent step.
4
4
  *
5
- * Capture strategy: frame processors run on a worklet thread and don't expose
6
- * the JPEG bytes back to JS without a custom native plugin. We avoid that
7
- * complication by capturing stills to a file on a JS-level interval (matches
8
- * the `setInterval` pattern in `web/LivenessModule.ts`). Real-world FPS lands
9
- * around 3–8 fps which is sufficient for Iris's challenge cadence.
5
+ * Capture strategy: the web SDK grabs JPEG frames from the live video
6
+ * element. We do the Android equivalent: `takeSnapshot()` of the preview
7
+ * (the same pixels the user framed in the oval). Still-photo capture on
8
+ * the same session as the evidence recorder produced blurry JPEGs that
9
+ * Iris rejected as `LOW_SHARPNESS` and MiniFAS scored as a screen replay.
10
10
  *
11
- * The camera streams photo and video at once, so the frames sent to Iris and
12
- * the mp4 kept as evidence come off the same session without either
13
- * interrupting the other.
11
+ * `takeSnapshot()` is Android-only. iOS falls back to a photo output with
12
+ * `qualityPrioritization: 'quality'` (not `'speed'` — that is ZSL and
13
+ * starves when video is running).
14
+ *
15
+ * Preview snapshots are selfie-mirrored. We un-mirror before encoding so
16
+ * Iris sees real-world yaw (OSDKR-23). The on-screen preview stays mirrored.
14
17
  *
15
18
  * NOTE: the preview is deliberately NOT in `<Camera outputs={...}>`.
16
19
  * `<Camera>` creates its own and prepends it (`outputs: [previewOutput,
@@ -34,6 +37,7 @@ import {
34
37
  ActivityIndicator,
35
38
  Animated,
36
39
  Easing,
40
+ Platform,
37
41
  StyleSheet,
38
42
  Text,
39
43
  useWindowDimensions,
@@ -48,13 +52,114 @@ import {
48
52
  usePhotoOutput,
49
53
  useVideoOutput,
50
54
  type CameraRef,
51
- type PhotoFile,
55
+ type Photo,
52
56
  type Recorder,
53
57
  } from 'react-native-vision-camera';
54
58
  import { Button } from '../ui/primitives/Button';
55
59
  import { useTheme, withAlpha } from '../ui/theme';
60
+ import { log } from '../utils/log';
56
61
  import { useSafeAreaInsets } from '../utils/useSafeAreaInsets';
57
62
 
63
+ /**
64
+ * DIAGNOSTIC (OSDKR-24): which stream combination the liveness session binds.
65
+ *
66
+ * On a Motorola Edge 30 Neo and a Moto G51 every frame stays under Iris's
67
+ * sharpness floor, while a Moto G75 and a Galaxy A04 pass with the same code.
68
+ * v5 no longer lets us pick a photo size from the device's list: CameraX
69
+ * negotiates preview + photo + video (+ the fps cap) as one `SessionConfig`
70
+ * and may silently shrink the JPEG to make the combination fit. These
71
+ * variants isolate which part of the combination costs us the resolution:
72
+ *
73
+ * - `'full'` — preview + photo + video, 30 fps cap. Production behaviour.
74
+ * - `'no-video'` — preview + photo, 30 fps cap. The evidence video is skipped
75
+ * (best-effort path: `liveness-verify` goes without a body).
76
+ * - `'no-fps'` — preview + photo + video, no fps constraint.
77
+ * - `'v4-equivalent'` — the photo capture vision-camera 4.7.3 did before the
78
+ * migration: `'balanced'` (MINIMIZE_LATENCY, what v4 called
79
+ * `'speed'`) at UHD_4_3 (the sensor's largest 4:3 size), with
80
+ * video and no fps constraint — v4 never applied fps to the
81
+ * photo stream, while v5 applies it to the whole session.
82
+ * - `'v4-equivalent-30fps'` — the same photo capture plus the 30 fps cap v4
83
+ * put on preview and video. v5 cannot cap only those two: the
84
+ * constraint covers the whole session, photo included, so
85
+ * check the diagnostic log for the capture size it lands on.
86
+ *
87
+ * Android only: iOS always binds `'full'`, the configuration it passes Iris
88
+ * with (see ACTIVE_LIVENESS_CAMERA_VARIANT).
89
+ *
90
+ * Defaults to `'v4-equivalent'`: on the Edge 30 Neo it doubled the measured
91
+ * sharpness against `'full'` at the same face size. `'v4-equivalent-30fps'`
92
+ * was ruled out on the same device: to hold 30 fps CameraX moved the photo to
93
+ * a 16:9 3264x1836 stream, sharpness fell back to `'full'` levels, and the
94
+ * narrower field of view enlarged the face enough to trip `TOO_CLOSE`.
95
+ * Flip it by hand for a test build.
96
+ */
97
+ export type LivenessCameraVariant =
98
+ | 'full'
99
+ | 'no-video'
100
+ | 'no-fps'
101
+ | 'v4-equivalent'
102
+ | 'v4-equivalent-30fps';
103
+
104
+ export const LIVENESS_CAMERA_VARIANT =
105
+ 'v4-equivalent' as LivenessCameraVariant;
106
+
107
+ /** The variant this platform actually binds. */
108
+ export const ACTIVE_LIVENESS_CAMERA_VARIANT: LivenessCameraVariant =
109
+ Platform.OS === 'android' ? LIVENESS_CAMERA_VARIANT : 'full';
110
+
111
+ const IS_V4_EQUIVALENT =
112
+ ACTIVE_LIVENESS_CAMERA_VARIANT === 'v4-equivalent' ||
113
+ ACTIVE_LIVENESS_CAMERA_VARIANT === 'v4-equivalent-30fps';
114
+
115
+ /**
116
+ * Android keeps each liveness frame in memory instead of round-tripping it
117
+ * through files (OSDKR-24). With the 8 MP v4-equivalent capture on an Edge 30
118
+ * Neo, the file path cost ~380 ms per frame on top of the camera's ~330 ms —
119
+ * write the JPEG, load it back through the image loader, write the resized
120
+ * copy, read that back — and held the loop at ~1.4 fps. Scaling and encoding
121
+ * are the same on both paths (bilinear scale, `Bitmap.compress`).
122
+ * `Photo.toImage()` applies the photo's rotation but also mirrors
123
+ * front-camera photos, which the file path does not; `encodeFrame` in the
124
+ * liveness step undoes that mirror, or TURN_LEFT / TURN_RIGHT invert.
125
+ *
126
+ * iOS stays on the file path it passes Iris with. Set to `false` to put
127
+ * Android back on it for an A/B run.
128
+ */
129
+ export const ANDROID_IN_MEMORY_FRAMES = true;
130
+ const IN_MEMORY_FRAMES = Platform.OS === 'android' && ANDROID_IN_MEMORY_FRAMES;
131
+
132
+ /**
133
+ * A liveness frame as the camera handed it over, before it is scaled and
134
+ * encoded for Iris. A `'memory'` frame holds a camera buffer until its photo
135
+ * is disposed, so whoever ends up with it must release it.
136
+ */
137
+ export type CapturedFrame =
138
+ | { kind: 'file'; filePath: string }
139
+ | { kind: 'memory'; photo: Photo };
140
+
141
+ // Module-level so `<Camera>` gets stable references across re-renders.
142
+ const FPS_CONSTRAINTS = [{ fps: 30 }];
143
+ const NO_CONSTRAINTS: never[] = [];
144
+ const SESSION_CONSTRAINTS =
145
+ ACTIVE_LIVENESS_CAMERA_VARIANT === 'no-fps' ||
146
+ ACTIVE_LIVENESS_CAMERA_VARIANT === 'v4-equivalent'
147
+ ? NO_CONSTRAINTS
148
+ : FPS_CONSTRAINTS;
149
+
150
+ const PHOTO_OUTPUT_OPTIONS =
151
+ IS_V4_EQUIVALENT
152
+ ? {
153
+ qualityPrioritization: 'balanced' as const,
154
+ targetResolution: CommonResolutions.UHD_4_3,
155
+ quality: 0.9,
156
+ }
157
+ : {
158
+ qualityPrioritization: 'quality' as const,
159
+ targetResolution: CommonResolutions.FHD_4_3,
160
+ quality: 0.9,
161
+ };
162
+
58
163
  /**
59
164
  * The recorded liveness video, as this component reports it upwards.
60
165
  *
@@ -72,7 +177,7 @@ export interface LivenessVideoFile {
72
177
  }
73
178
 
74
179
  export interface LivenessCameraHandle {
75
- takeFrame: () => Promise<PhotoFile | null>;
180
+ takeFrame: () => Promise<CapturedFrame | null>;
76
181
  /**
77
182
  * Start an mp4/h264 video recording on the same `<Camera>` that feeds the
78
183
  * frame loop. Audio is disabled. Errors during recording are delivered
@@ -126,10 +231,30 @@ export const LivenessCamera = forwardRef<LivenessCameraHandle, LivenessCameraPro
126
231
  const insets = useSafeAreaInsets();
127
232
  const cameraRef = useRef<CameraRef>(null);
128
233
  const device = useCameraDevice('front');
129
- // Frames for Iris: `speed` over quality on purpose. These are downscaled
130
- // and re-compressed by `ImageManipulator` before they ever reach the wire,
131
- // so a slow high-fidelity capture would only cost us frame cadence.
132
- const photoOutput = usePhotoOutput({ qualityPrioritization: 'speed' });
234
+ // Stills at MAXIMIZE_QUALITY, used on iOS and on Android unless the switch
235
+ // above selects the preview snapshot.
236
+ // Capture WELL ABOVE the wire size on purpose (OSDKR-23).
237
+ //
238
+ // Iris scores sharpness as the Laplacian variance of the face region in
239
+ // the frame we send, and that number depends on how much we downscaled to
240
+ // get there. Downsampling concentrates detail and averages out sensor
241
+ // noise, so a 720 px frame derived from a large capture is measurably
242
+ // sharper than one captured at ~720 px natively.
243
+ //
244
+ // The spike had this at HD_4_3 (768x1024), reasoning that the frame gets
245
+ // resized to 720 anyway. It does — but that is a 0.94x scale, which keeps
246
+ // all of the lens softness and noise reduction of the native capture. On a
247
+ // Motorola Edge 30 Neo it measured `sharpness_quality` 0.16 average and
248
+ // 0.216 peak against a 0.35 threshold, with good lighting and a 312x470 px
249
+ // face: not a framing problem, a resolution one.
250
+ //
251
+ // FHD_4_3 gives a 2x linear downscale to the 720 px wire size at a
252
+ // fraction of the cost of the 12 MP default. Escalate to
253
+ // `CommonResolutions.UHD_4_3` — what iOS used when it passed the gate — if
254
+ // the measured sharpness is still short.
255
+ // Options live in PHOTO_OUTPUT_OPTIONS so the active variant can swap
256
+ // them; iOS stays on `'quality'` at FHD_4_3.
257
+ const photoOutput = usePhotoOutput(PHOTO_OUTPUT_OPTIONS);
133
258
  // Pin the recording to 720p so the mp4 stays a few MB instead of the
134
259
  // device-default 1080p–4K bitrate (a 30 s session can otherwise produce a
135
260
  // 50–80 MB file that times out on mobile uplinks). Face visibility for
@@ -153,6 +278,14 @@ export const LivenessCamera = forwardRef<LivenessCameraHandle, LivenessCameraPro
153
278
  // infinite spinner after 4s without a device.
154
279
  const [deviceTimeout, setDeviceTimeout] = useState(false);
155
280
 
281
+ useEffect(() => {
282
+ log.warn('[Liveness][diag] camera variant', {
283
+ variant: ACTIVE_LIVENESS_CAMERA_VARIANT,
284
+ configured: LIVENESS_CAMERA_VARIANT,
285
+ platform: Platform.OS,
286
+ });
287
+ }, []);
288
+
156
289
  useEffect(() => {
157
290
  if (!hasPermission && !requestedRef.current) {
158
291
  requestedRef.current = true;
@@ -169,23 +302,17 @@ export const LivenessCamera = forwardRef<LivenessCameraHandle, LivenessCameraPro
169
302
  return () => clearTimeout(t);
170
303
  }, [device, hasPermission]);
171
304
 
172
- // NOTE: `capturePhotoToFile`, not `capturePhoto`. The in-memory variant
173
- // would hand us a native `Photo` that must be `dispose()`d by hand — in a
174
- // loop running at up to ~7 fps for a whole session, a single missed
175
- // dispose on an error path leaks native buffers. It would only pay off if
176
- // we could sign the bytes directly, and we cannot: the frame still has to
177
- // go through `ImageManipulator` for the downscale and the horizontal flip,
178
- // and that API takes a URI, not a buffer. So the file is needed either
179
- // way, and capturing straight to one keeps the hot loop free of manual
180
- // memory management.
181
- const takeFrame = useCallback(async (): Promise<PhotoFile | null> => {
305
+ const takeFrame = useCallback(async (): Promise<CapturedFrame | null> => {
182
306
  if (inFlightRef.current) return null;
183
307
  inFlightRef.current = true;
184
308
  try {
185
- return await photoOutput.capturePhotoToFile(
186
- { flashMode: 'off', enableShutterSound: false },
187
- {},
188
- );
309
+ const settings = { flashMode: 'off', enableShutterSound: false } as const;
310
+ if (IN_MEMORY_FRAMES) {
311
+ const photo = await photoOutput.capturePhoto(settings, {});
312
+ return { kind: 'memory', photo };
313
+ }
314
+ const file = await photoOutput.capturePhotoToFile(settings, {});
315
+ return { kind: 'file', filePath: file.filePath };
189
316
  } catch {
190
317
  // Frame failures are non-fatal — the parent loop just retries on the
191
318
  // next tick. Keep the camera mounted.
@@ -212,6 +339,12 @@ export const LivenessCamera = forwardRef<LivenessCameraHandle, LivenessCameraPro
212
339
  onRecordingError: (err: unknown) => void;
213
340
  }): Promise<void> => {
214
341
  if (recorderRef.current) return;
342
+ if (ACTIVE_LIVENESS_CAMERA_VARIANT === 'no-video') {
343
+ // The video output is not bound in this variant, so a Recorder on
344
+ // it would never start. Throwing sends the step down the same
345
+ // best-effort path as any other recording startup failure.
346
+ throw new Error('video recording disabled by diagnostic variant');
347
+ }
215
348
  const recorder = await videoOutput.createRecorder({});
216
349
  recorderRef.current = recorder;
217
350
  recordedDurationRef.current = undefined;
@@ -331,14 +464,17 @@ export const LivenessCamera = forwardRef<LivenessCameraHandle, LivenessCameraPro
331
464
  ref={cameraRef}
332
465
  style={StyleSheet.absoluteFill}
333
466
  device={device}
334
- // Preview, frames for Iris, and the mp4 recording all stream off the
335
- // same session. This is the capability the whole liveness step rests
336
- // on: the JPEG frames and the evidence video are produced at once,
337
- // from one camera, without interrupting either.
338
- outputs={[photoOutput, videoOutput]}
467
+ // Photo stills feed Iris, video is the evidence recording; `<Camera>`
468
+ // prepends its own preview. See LIVENESS_CAMERA_VARIANT for the
469
+ // diagnostic combinations.
470
+ outputs={
471
+ ACTIVE_LIVENESS_CAMERA_VARIANT === 'no-video'
472
+ ? [photoOutput]
473
+ : [photoOutput, videoOutput]
474
+ }
339
475
  // Cap the sensor at 30 fps. Resolution and bit-rate are set on the
340
476
  // video output itself (see `useVideoOutput` above).
341
- constraints={[{ fps: 30 }]}
477
+ constraints={SESSION_CONSTRAINTS}
342
478
  // Lock the recorded video orientation to the interface's so it is
343
479
  // never upside-down or sideways on the back-office player. (v5's
344
480
  // spelling of what v4 called `outputOrientation="preview"`.)
@@ -346,10 +482,8 @@ export const LivenessCamera = forwardRef<LivenessCameraHandle, LivenessCameraPro
346
482
  // We keep the front camera's default mirroring rather than forcing
347
483
  // `isMirrored=false`: in v4 that override triggered an iOS bug where
348
484
  // the tkhd matrix was written rotated −90° instead of +90°, leaving
349
- // the mp4 upside-down. The frames we send to Iris are un-mirrored
350
- // separately in `captureAndSend` via a horizontal flip with
351
- // expo-image-manipulator, so TURN_LEFT/RIGHT still maps to the
352
- // real-world yaw.
485
+ // the mp4 upside-down. Preview snapshots are un-mirrored in
486
+ // `takeFrame` before they go to Iris (OSDKR-23).
353
487
  isActive
354
488
  />
355
489
  <OvalOverlay
@@ -253,6 +253,8 @@ export const EN: StringsTable = {
253
253
  positioningReady: 'Looking good — starting the challenges',
254
254
  getReady: 'Heads up — starting now',
255
255
  repositioning: "Let's pause a second — center your face and improve lighting. We'll retry the same step",
256
+ repositioningAfterMoveFarther:
257
+ "Go back to your previous distance — bring the phone a little closer and center your face. We'll retry the same step",
256
258
  finalizing: 'Processing your video…',
257
259
  challenge: {
258
260
  FACE_FORWARD: 'Hold your face forward',
@@ -247,6 +247,8 @@ export const ES = {
247
247
  positioningReady: 'Listo, ya estás bien posicionado — empezamos',
248
248
  getReady: 'Atento — empezamos',
249
249
  repositioning: 'Pausemos un segundo — centrá tu rostro y mejorá la luz. Reintentamos el mismo paso',
250
+ repositioningAfterMoveFarther:
251
+ 'Volvé a la distancia de antes — acercá un poco el teléfono y centrá tu rostro. Reintentamos el mismo paso',
250
252
  finalizing: 'Procesando tu video…',
251
253
  analyzingHeadline: 'Analizando tu video',
252
254
  analyzingCaption: 'Estamos verificando la prueba de vida. Tardará solo unos segundos.',