@velion-la/onboarding-sdk-react-native 1.2.0-beta.7 → 1.2.0-beta.9
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/lib/commonjs/steps/DocumentsOcrStep.js +138 -18
- package/lib/commonjs/steps/DocumentsOcrStep.js.map +1 -1
- package/lib/commonjs/steps/LivenessMatchStep.js +62 -28
- package/lib/commonjs/steps/LivenessMatchStep.js.map +1 -1
- package/lib/commonjs/transport/irisWebSocket.js +24 -2
- package/lib/commonjs/transport/irisWebSocket.js.map +1 -1
- package/lib/commonjs/utils/jpegFromUri.js +54 -14
- package/lib/commonjs/utils/jpegFromUri.js.map +1 -1
- package/lib/module/steps/DocumentsOcrStep.js +138 -18
- package/lib/module/steps/DocumentsOcrStep.js.map +1 -1
- package/lib/module/steps/LivenessMatchStep.js +63 -29
- package/lib/module/steps/LivenessMatchStep.js.map +1 -1
- package/lib/module/transport/irisWebSocket.js +24 -2
- package/lib/module/transport/irisWebSocket.js.map +1 -1
- package/lib/module/utils/jpegFromUri.js +52 -14
- package/lib/module/utils/jpegFromUri.js.map +1 -1
- package/lib/typescript/steps/DocumentsOcrStep.d.ts.map +1 -1
- package/lib/typescript/transport/irisWebSocket.d.ts.map +1 -1
- package/lib/typescript/utils/jpegFromUri.d.ts +31 -10
- package/lib/typescript/utils/jpegFromUri.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/steps/DocumentsOcrStep.tsx +158 -16
- package/src/steps/LivenessMatchStep.tsx +68 -34
- package/src/transport/irisWebSocket.ts +20 -2
- package/src/utils/jpegFromUri.ts +54 -16
|
@@ -5,14 +5,23 @@
|
|
|
5
5
|
* path into either base64 (for the Iris HMAC envelope) or raw bytes (for
|
|
6
6
|
* binary WebSocket frames + direct PUT to signed URLs).
|
|
7
7
|
*
|
|
8
|
-
* Why not `fetch(uri)
|
|
8
|
+
* Why not `fetch(uri)`?
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
10
|
+
* Two independent reasons, and the second one is the load-bearing one now:
|
|
11
|
+
*
|
|
12
|
+
* 1. React Native's Blob polyfill does NOT implement `Blob.arrayBuffer()`
|
|
13
|
+
* (it's web-only) — calling it throws `blob.arrayBuffer is not a
|
|
14
|
+
* function`.
|
|
15
|
+
* 2. **`fetch` cannot read local files at all since Expo SDK 57.** Expo now
|
|
16
|
+
* replaces the global `fetch` (`expo/src/winter/runtime.native.ts`:
|
|
17
|
+
* `install('fetch', ...)`) with a native HTTP client, and that client does
|
|
18
|
+
* not handle the `file://` scheme. It answers with an empty body instead
|
|
19
|
+
* of failing, so anything reading a capture through `fetch` silently
|
|
20
|
+
* uploads 0 bytes (OSDKR-22). SDK 54 did not install it, which is why the
|
|
21
|
+
* old code worked.
|
|
22
|
+
*
|
|
23
|
+
* `File.arrayBuffer()` from `expo-file-system` reads straight from disk and is
|
|
24
|
+
* unaffected by either.
|
|
16
25
|
*/
|
|
17
26
|
export interface JpegFromUri {
|
|
18
27
|
bytes: Uint8Array;
|
|
@@ -20,10 +29,22 @@ export interface JpegFromUri {
|
|
|
20
29
|
byteLength: number;
|
|
21
30
|
}
|
|
22
31
|
/**
|
|
23
|
-
* Reads a
|
|
32
|
+
* Reads a local file into raw bytes.
|
|
24
33
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
34
|
+
* Prefer this over `readJpegFromUri` when the caller only needs the bytes —
|
|
35
|
+
* uploads, for instance. It skips the base64 encoding, which is pure waste for
|
|
36
|
+
* a multi-megabyte video.
|
|
37
|
+
*/
|
|
38
|
+
export declare function readBytesFromUri(uri: string): Promise<Uint8Array>;
|
|
39
|
+
/**
|
|
40
|
+
* Size of a local file in bytes, or `0` when it cannot be read.
|
|
41
|
+
*
|
|
42
|
+
* Reads the filesystem metadata instead of loading the contents, so it stays
|
|
43
|
+
* cheap enough to call before an upload.
|
|
44
|
+
*/
|
|
45
|
+
export declare function byteLengthOfUri(uri: string): number;
|
|
46
|
+
/**
|
|
47
|
+
* Reads a `file://` URI into JPEG bytes + base64 representation.
|
|
27
48
|
*/
|
|
28
49
|
export declare function readJpegFromUri(uri: string): Promise<JpegFromUri>;
|
|
29
50
|
//# sourceMappingURL=jpegFromUri.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jpegFromUri.d.ts","sourceRoot":"","sources":["../../../src/utils/jpegFromUri.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"jpegFromUri.d.ts","sourceRoot":"","sources":["../../../src/utils/jpegFromUri.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAKH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB;AAYD;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAGvE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAOnD;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAIvE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@velion-la/onboarding-sdk-react-native",
|
|
3
|
-
"version": "1.2.0-beta.
|
|
3
|
+
"version": "1.2.0-beta.9",
|
|
4
4
|
"description": "Native React Native SDK for the Velion Onboarding (KYC) flow: ID document OCR, passive + active liveness, device fingerprint, OTP verification, address picker, and personal / legal information forms.",
|
|
5
5
|
"main": "./lib/commonjs/index.js",
|
|
6
6
|
"module": "./lib/module/index.js",
|
|
@@ -49,6 +49,7 @@ import { useTheme, mixHex } from '../ui/theme';
|
|
|
49
49
|
import { getStrings } from '../i18n';
|
|
50
50
|
import { resolveCaptureModeFromStepConfig } from '../utils/stepConfig';
|
|
51
51
|
import { log } from '../utils/log';
|
|
52
|
+
import { byteLengthOfUri, readBytesFromUri } from '../utils/jpegFromUri';
|
|
52
53
|
import { DocumentCapture, type CaptureGuide } from '../camera/DocumentCapture';
|
|
53
54
|
import {
|
|
54
55
|
computeGuideCropRect,
|
|
@@ -170,7 +171,24 @@ function DocumentsOcrView({
|
|
|
170
171
|
const handleCaptured = useCallback(
|
|
171
172
|
async (photo: PhotoFile, side: DocumentSide, guide: CaptureGuide) => {
|
|
172
173
|
try {
|
|
174
|
+
// Size of the raw capture BEFORE any processing. Logged next to the
|
|
175
|
+
// compressed size so a 0-byte upload can be traced to the stage that
|
|
176
|
+
// lost it — the capture itself, the crop/compress, or the upload
|
|
177
|
+
// (OSDKR-22).
|
|
178
|
+
const sourceBytes = byteLengthOfUri(photo.filePath);
|
|
173
179
|
const compressed = await compressJpeg(photo.filePath, guide);
|
|
180
|
+
log.info('[DocumentsOCR] side processed', {
|
|
181
|
+
side,
|
|
182
|
+
sourceBytes,
|
|
183
|
+
compressedBytes: compressed.byteLength,
|
|
184
|
+
width: compressed.width,
|
|
185
|
+
height: compressed.height,
|
|
186
|
+
});
|
|
187
|
+
if (compressed.byteLength === 0) {
|
|
188
|
+
throw new Error(
|
|
189
|
+
`Processed ${side} image is 0 bytes (source was ${sourceBytes} bytes).`,
|
|
190
|
+
);
|
|
191
|
+
}
|
|
174
192
|
if (compressed.byteLength > MAX_BYTES) {
|
|
175
193
|
setBannerError(t.documents_ocr.fileTooLarge);
|
|
176
194
|
// Stay on the capture phase so the user can retake immediately.
|
|
@@ -205,10 +223,18 @@ function DocumentsOcrView({
|
|
|
205
223
|
}
|
|
206
224
|
|
|
207
225
|
setBusyLabel(t.documents_ocr.uploadingFront);
|
|
208
|
-
await uploadJpeg(
|
|
226
|
+
await uploadJpeg(
|
|
227
|
+
front.uri,
|
|
228
|
+
init.front_side_upload_url,
|
|
229
|
+
init.max_file_size_bytes,
|
|
230
|
+
);
|
|
209
231
|
|
|
210
232
|
setBusyLabel(t.documents_ocr.uploadingBack);
|
|
211
|
-
await uploadJpeg(
|
|
233
|
+
await uploadJpeg(
|
|
234
|
+
back.uri,
|
|
235
|
+
init.back_side_upload_url,
|
|
236
|
+
init.max_file_size_bytes,
|
|
237
|
+
);
|
|
212
238
|
|
|
213
239
|
setBusyLabel(t.documents_ocr.verifying);
|
|
214
240
|
await api.post(`/sessions/${sessionId}/documents-verify`, {});
|
|
@@ -502,7 +528,7 @@ async function compressJpeg(
|
|
|
502
528
|
compress: COMPRESS_QUALITY,
|
|
503
529
|
format: SaveFormat.JPEG,
|
|
504
530
|
});
|
|
505
|
-
const byteLength =
|
|
531
|
+
const byteLength = byteLengthOfUri(result.uri);
|
|
506
532
|
return {
|
|
507
533
|
uri: result.uri,
|
|
508
534
|
width: result.width,
|
|
@@ -519,27 +545,143 @@ async function compressJpeg(
|
|
|
519
545
|
}
|
|
520
546
|
}
|
|
521
547
|
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
548
|
+
/**
|
|
549
|
+
* Uploads a captured JPEG to its signed URL.
|
|
550
|
+
*
|
|
551
|
+
* The bytes are read with `expo-file-system`, NOT with `fetch(uri)`. Since
|
|
552
|
+
* Expo SDK 57 the global `fetch` is Expo's native HTTP client, which does not
|
|
553
|
+
* handle the `file://` scheme and answers with an empty body rather than
|
|
554
|
+
* failing — so reading a capture through it uploaded a 0-byte object while
|
|
555
|
+
* every status code said success (OSDKR-22).
|
|
556
|
+
*
|
|
557
|
+
* Expo's `fetch` normalises any `ArrayBuffer.isView` into the request body, so
|
|
558
|
+
* a `Uint8Array` is a valid body here.
|
|
559
|
+
*/
|
|
560
|
+
async function uploadJpeg(
|
|
561
|
+
uri: string,
|
|
562
|
+
signedUrl: string,
|
|
563
|
+
maxFileSizeBytes: number | undefined,
|
|
564
|
+
): Promise<void> {
|
|
565
|
+
const bytes = await readBytesFromUri(uri);
|
|
566
|
+
// Never PUT an empty body: the bucket accepts it, the step reports success,
|
|
567
|
+
// and the failure only surfaces later as an unexplained backend rejection.
|
|
568
|
+
if (bytes.byteLength === 0) {
|
|
569
|
+
throw new Error('Captured photo read back as 0 bytes — refusing to upload it.');
|
|
570
|
+
}
|
|
571
|
+
// The CDN signs the URL with an `x-goog-content-length-range` extension
|
|
572
|
+
// header, and GCS rejects the PUT unless every signed header is present in
|
|
573
|
+
// the request — with `MalformedSecurityHeader`, not with a size error, so it
|
|
574
|
+
// reads like a signature problem (OSDKR-22).
|
|
575
|
+
//
|
|
576
|
+
// The value has to match what was signed byte for byte. The CDN builds it as
|
|
577
|
+
// `"0," + maxUploadBytes` and returns that same number as the
|
|
578
|
+
// `max_file_size_bytes` of `documents-init`, so the number below is the one
|
|
579
|
+
// that went into the signature, not a guess.
|
|
580
|
+
const headers: Record<string, string> = { 'Content-Type': 'image/jpeg' };
|
|
581
|
+
if (typeof maxFileSizeBytes === 'number') {
|
|
582
|
+
headers['x-goog-content-length-range'] = `0,${maxFileSizeBytes}`;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// Reject oversize captures here rather than letting GCS do it: past the
|
|
586
|
+
// signed ceiling the bucket answers with the same opaque 400.
|
|
587
|
+
if (typeof maxFileSizeBytes === 'number' && bytes.byteLength > maxFileSizeBytes) {
|
|
588
|
+
throw new Error(
|
|
589
|
+
`Captured image is ${bytes.byteLength} bytes, over the ${maxFileSizeBytes}-byte limit the upload URL was signed for.`,
|
|
590
|
+
);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// If the signature covers the range header but `documents-init` did not give
|
|
594
|
+
// us the number, the PUT cannot succeed and the reason is a contract gap, not
|
|
595
|
+
// a client bug. Say so before failing, so it is not diagnosed as a signature
|
|
596
|
+
// problem again.
|
|
597
|
+
const required = describeSignedUrl(signedUrl).signedHeaders ?? '';
|
|
598
|
+
if (
|
|
599
|
+
required.includes('x-goog-content-length-range') &&
|
|
600
|
+
typeof maxFileSizeBytes !== 'number'
|
|
601
|
+
) {
|
|
602
|
+
log.warn(
|
|
603
|
+
'[DocumentsOCR] upload URL is signed over x-goog-content-length-range but ' +
|
|
604
|
+
'documents-init returned no max_file_size_bytes — the PUT will be rejected ' +
|
|
605
|
+
'with MalformedSecurityHeader.',
|
|
606
|
+
);
|
|
526
607
|
}
|
|
527
|
-
|
|
608
|
+
|
|
609
|
+
log.info('[DocumentsOCR] uploading side', {
|
|
610
|
+
bytes: bytes.byteLength,
|
|
611
|
+
maxFileSizeBytes: maxFileSizeBytes ?? null,
|
|
612
|
+
sentHeaders: Object.keys(headers),
|
|
613
|
+
});
|
|
614
|
+
const startedAt = Date.now();
|
|
528
615
|
const put = await fetch(signedUrl, {
|
|
529
616
|
method: 'PUT',
|
|
530
|
-
headers
|
|
531
|
-
body:
|
|
617
|
+
headers,
|
|
618
|
+
body: bytes,
|
|
619
|
+
});
|
|
620
|
+
// The bucket echoes back what it stored. `etag` is a checksum of the stored
|
|
621
|
+
// object, so a constant etag across two different captures means nothing
|
|
622
|
+
// reached it — the symptom that took a full manual run to notice before.
|
|
623
|
+
// The signed URL is never logged: it carries the V4 signature.
|
|
624
|
+
log.info('[DocumentsOCR] side uploaded', {
|
|
625
|
+
sentBytes: bytes.byteLength,
|
|
626
|
+
status: put.status,
|
|
627
|
+
etag: put.headers.get('etag'),
|
|
628
|
+
elapsedMs: Date.now() - startedAt,
|
|
532
629
|
});
|
|
533
630
|
if (!put.ok) {
|
|
534
|
-
|
|
631
|
+
// A signed-URL rejection is never self-explanatory from the status alone:
|
|
632
|
+
// 400 covers a stale signature, an expired URL and a Content-Type that
|
|
633
|
+
// does not match what was signed. GCS puts the actual reason in an XML
|
|
634
|
+
// body, so read it before throwing (OSDKR-22).
|
|
635
|
+
let reason = '';
|
|
636
|
+
let body = '';
|
|
637
|
+
try {
|
|
638
|
+
body = (await put.text()).slice(0, 400);
|
|
639
|
+
reason = body.match(/<Code>([^<]+)<\/Code>/)?.[1] ?? '';
|
|
640
|
+
} catch {
|
|
641
|
+
/* body not readable; the status and the signed-URL shape are the signal */
|
|
642
|
+
}
|
|
643
|
+
log.warn('[DocumentsOCR] side upload rejected', {
|
|
644
|
+
status: put.status,
|
|
645
|
+
reason,
|
|
646
|
+
sentBytes: bytes.byteLength,
|
|
647
|
+
sentHeaders: Object.keys(headers),
|
|
648
|
+
// Describes the signed URL without ever exposing its signature. The
|
|
649
|
+
// decisive field is usually `signedHeaders`: it lists the headers the
|
|
650
|
+
// signature covers, so a mismatch with what we actually sent shows up
|
|
651
|
+
// here immediately.
|
|
652
|
+
signedUrl: describeSignedUrl(signedUrl),
|
|
653
|
+
body,
|
|
654
|
+
});
|
|
655
|
+
throw new Error(
|
|
656
|
+
`Signed URL upload failed: HTTP ${put.status}${reason ? ` (${reason})` : ''}`,
|
|
657
|
+
);
|
|
535
658
|
}
|
|
536
659
|
}
|
|
537
660
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
661
|
+
/**
|
|
662
|
+
* Summarises a signed URL for logging — host, path and the signing parameters
|
|
663
|
+
* that explain a rejection — while deliberately omitting `X-Goog-Signature`.
|
|
664
|
+
*
|
|
665
|
+
* `signedHeaders` and `expires` are what actually diagnose a 400: the first
|
|
666
|
+
* says which headers the signature covers, the second whether the URL simply
|
|
667
|
+
* aged out between `documents-init` and the upload.
|
|
668
|
+
*/
|
|
669
|
+
function describeSignedUrl(signedUrl: string): Record<string, string | null> {
|
|
670
|
+
try {
|
|
671
|
+
const url = new URL(signedUrl);
|
|
672
|
+
const q = url.searchParams;
|
|
673
|
+
return {
|
|
674
|
+
host: url.host,
|
|
675
|
+
path: url.pathname,
|
|
676
|
+
algorithm: q.get('X-Goog-Algorithm'),
|
|
677
|
+
date: q.get('X-Goog-Date'),
|
|
678
|
+
expiresIn: q.get('X-Goog-Expires'),
|
|
679
|
+
signedHeaders: q.get('X-Goog-SignedHeaders'),
|
|
680
|
+
hasSignature: q.has('X-Goog-Signature') ? 'yes' : 'no',
|
|
681
|
+
};
|
|
682
|
+
} catch {
|
|
683
|
+
return { parseError: 'could not parse signed URL' };
|
|
684
|
+
}
|
|
543
685
|
}
|
|
544
686
|
|
|
545
687
|
/**
|
|
@@ -41,7 +41,7 @@ import { StepIcon } from '../ui/icons/StepIcon';
|
|
|
41
41
|
import { mixHex, useTheme } from '../ui/theme';
|
|
42
42
|
import { getStrings } from '../i18n';
|
|
43
43
|
import { log } from '../utils/log';
|
|
44
|
-
import { readJpegFromUri } from '../utils/jpegFromUri';
|
|
44
|
+
import { readBytesFromUri, readJpegFromUri } from '../utils/jpegFromUri';
|
|
45
45
|
import {
|
|
46
46
|
buildSignedFrameEnvelope,
|
|
47
47
|
importHmacKey,
|
|
@@ -342,29 +342,43 @@ function LivenessMatchView({
|
|
|
342
342
|
});
|
|
343
343
|
const t0 = Date.now();
|
|
344
344
|
try {
|
|
345
|
-
//
|
|
346
|
-
//
|
|
347
|
-
//
|
|
348
|
-
//
|
|
349
|
-
//
|
|
350
|
-
//
|
|
351
|
-
//
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
345
|
+
// Read the bytes with `expo-file-system`, NOT with `fetch(fileUri)`.
|
|
346
|
+
//
|
|
347
|
+
// This reverses what this code used to do, so it is worth spelling
|
|
348
|
+
// out. Under React Native's `fetch` the native Blob was the reliable
|
|
349
|
+
// body and passing bytes sent an empty one. Since Expo SDK 57 the
|
|
350
|
+
// global `fetch` is Expo's native HTTP client
|
|
351
|
+
// (`expo/src/winter/runtime.native.ts` → `install('fetch', ...)`),
|
|
352
|
+
// which does not handle the `file://` scheme: it answers with an empty
|
|
353
|
+
// body instead of failing, so reading the recording through it
|
|
354
|
+
// uploaded a 0-byte object while every status code reported success
|
|
355
|
+
// (OSDKR-22). Expo's `fetch` does accept any `ArrayBuffer.isView` as a
|
|
356
|
+
// request body, so the bytes go up directly.
|
|
357
|
+
const videoBytes = await readBytesFromUri(video.path);
|
|
356
358
|
log.info('[Liveness] video upload body prepared', {
|
|
357
|
-
|
|
358
|
-
blobType: nativeBlob.type,
|
|
359
|
+
bytes: videoBytes.byteLength,
|
|
359
360
|
});
|
|
361
|
+
if (videoBytes.byteLength === 0) {
|
|
362
|
+
throw new Error('Recorded video read back as 0 bytes.');
|
|
363
|
+
}
|
|
360
364
|
const result = await fetch(target.upload_url, {
|
|
361
365
|
method: 'PUT',
|
|
362
366
|
headers: { 'Content-Type': VIDEO_CONTENT_TYPE },
|
|
363
|
-
body:
|
|
367
|
+
body: videoBytes,
|
|
364
368
|
});
|
|
365
369
|
const elapsedMs = Date.now() - t0;
|
|
366
370
|
if (result.ok) {
|
|
367
|
-
|
|
371
|
+
// `sentBytes` is what we actually put on the wire; `sizeBytes` is
|
|
372
|
+
// the file size stat'd before reading. They must match — a mismatch,
|
|
373
|
+
// or an etag that repeats across sessions, means the body never
|
|
374
|
+
// reached the bucket (OSDKR-22).
|
|
375
|
+
log.info('[Liveness] video upload ok', {
|
|
376
|
+
status: result.status,
|
|
377
|
+
sentBytes: videoBytes.byteLength,
|
|
378
|
+
sizeBytes,
|
|
379
|
+
etag: result.headers.get('etag'),
|
|
380
|
+
elapsedMs,
|
|
381
|
+
});
|
|
368
382
|
videoOutcomeRef.current = 'uploaded';
|
|
369
383
|
videoMetaRef.current = {
|
|
370
384
|
content_type: VIDEO_CONTENT_TYPE,
|
|
@@ -581,20 +595,28 @@ function LivenessMatchView({
|
|
|
581
595
|
try {
|
|
582
596
|
const photo = await cameraRef.current?.takeFrame();
|
|
583
597
|
if (!photo || !ws.isOpen()) return;
|
|
584
|
-
//
|
|
585
|
-
//
|
|
586
|
-
//
|
|
587
|
-
//
|
|
588
|
-
// real-world directions
|
|
589
|
-
//
|
|
598
|
+
// DO NOT add a horizontal flip here (OSDKR-23).
|
|
599
|
+
//
|
|
600
|
+
// There used to be one. Under vision-camera v4 the front camera's photo
|
|
601
|
+
// output came out mirrored, and the flip undid that so the yaw Iris
|
|
602
|
+
// measures matched real-world directions. Under v5 the captured photo is
|
|
603
|
+
// already un-mirrored, so the same flip *introduced* the mirroring and
|
|
604
|
+
// inverted the sign of every turn.
|
|
605
|
+
//
|
|
606
|
+
// The effect was not a near miss: Iris measured the turns perfectly and
|
|
607
|
+
// scored both directions at exactly zero, because it expects a positive
|
|
608
|
+
// yaw delta for TURN_LEFT and a negative one for TURN_RIGHT and received
|
|
609
|
+
// the opposite. SMILE kept working throughout — it is symmetric, so
|
|
610
|
+
// mirroring does not touch it, which is what isolated the cause.
|
|
611
|
+
//
|
|
612
|
+
// The preview stays mirrored (vision-camera's `mirrorMode: 'auto'`), so
|
|
613
|
+
// the user still sees a natural selfie view. Only what we send to Iris
|
|
614
|
+
// has to be in real-world orientation.
|
|
590
615
|
const compressed = await ImageManipulator.manipulateAsync(
|
|
591
616
|
photo.filePath.startsWith('file://')
|
|
592
617
|
? photo.filePath
|
|
593
618
|
: `file://${photo.filePath}`,
|
|
594
|
-
[
|
|
595
|
-
{ resize: { width: FRAME_MAX_LONG_EDGE } },
|
|
596
|
-
{ flip: ImageManipulator.FlipType.Horizontal },
|
|
597
|
-
],
|
|
619
|
+
[{ resize: { width: FRAME_MAX_LONG_EDGE } }],
|
|
598
620
|
{ compress: FRAME_QUALITY, format: ImageManipulator.SaveFormat.JPEG },
|
|
599
621
|
);
|
|
600
622
|
if (!ws.isOpen()) return;
|
|
@@ -1092,14 +1114,25 @@ function LivenessMatchView({
|
|
|
1092
1114
|
// retry-dialog mount.
|
|
1093
1115
|
if (code === 4001) return;
|
|
1094
1116
|
stopCapture();
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1117
|
+
|
|
1118
|
+
// Reaching here means the socket closed and the step never
|
|
1119
|
+
// finalized, so we do not know how the session ended (OSDKR-23).
|
|
1120
|
+
//
|
|
1121
|
+
// A close code cannot tell us: Iris closes with 1000 after a
|
|
1122
|
+
// successful SESSION_COMPLETE, after CHALLENGE_NOT_CONFIRMED, and
|
|
1123
|
+
// after SPOOF_RISK_HIGH alike. It always sends the deciding message
|
|
1124
|
+
// immediately before closing, so a 1000 here means we lost it.
|
|
1125
|
+
//
|
|
1126
|
+
// This used to `stopWatchdog()` and then return on 1000, which left
|
|
1127
|
+
// the step on the "analyzing" overlay forever with every safety net
|
|
1128
|
+
// disarmed. Route the user into the same recovery a terminal warning
|
|
1129
|
+
// uses instead: the session did not complete as far as we can tell,
|
|
1130
|
+
// and offering a retry is both honest and actionable.
|
|
1131
|
+
log.warn('[Liveness] socket closed before the step finalized', {
|
|
1132
|
+
code,
|
|
1133
|
+
reason,
|
|
1102
1134
|
});
|
|
1135
|
+
presentTerminalRetry('CONNECTION_CLOSED', t.liveness.terminalRetryFallback);
|
|
1103
1136
|
},
|
|
1104
1137
|
});
|
|
1105
1138
|
} catch (err) {
|
|
@@ -1120,12 +1153,13 @@ function LivenessMatchView({
|
|
|
1120
1153
|
failWith,
|
|
1121
1154
|
handleWsMessage,
|
|
1122
1155
|
locale,
|
|
1156
|
+
presentTerminalRetry,
|
|
1123
1157
|
retry,
|
|
1124
1158
|
sessionId,
|
|
1125
1159
|
stopCapture,
|
|
1126
|
-
stopWatchdog,
|
|
1127
1160
|
t.liveness.connecting,
|
|
1128
1161
|
t.liveness.preparingCamera,
|
|
1162
|
+
t.liveness.terminalRetryFallback,
|
|
1129
1163
|
]);
|
|
1130
1164
|
|
|
1131
1165
|
// Re-run after a terminal retry — same cleanup as start, but reuses the
|
|
@@ -122,11 +122,29 @@ export function openIrisWebSocket(opts: IrisOpenOptions): IrisConnection {
|
|
|
122
122
|
|
|
123
123
|
ws.onmessage = (event: WebSocketMessageEvent) => {
|
|
124
124
|
if (typeof event.data !== 'string') return;
|
|
125
|
+
|
|
126
|
+
// Parsing and handling are deliberately in SEPARATE try blocks (OSDKR-23).
|
|
127
|
+
// They used to share one, so a `catch` written to ignore non-JSON noise
|
|
128
|
+
// also swallowed every exception thrown by the handler. A message that
|
|
129
|
+
// arrived and blew up looked exactly like a message that never arrived —
|
|
130
|
+
// which is how a hung liveness step went undiagnosed.
|
|
131
|
+
let parsed: IrisServerMessage;
|
|
125
132
|
try {
|
|
126
|
-
|
|
127
|
-
opts.onMessage(parsed);
|
|
133
|
+
parsed = JSON.parse(event.data) as IrisServerMessage;
|
|
128
134
|
} catch {
|
|
129
135
|
// Iris only sends JSON; ignore noise.
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Logged before dispatch so the record exists even if the handler throws.
|
|
140
|
+
// This is the line that answers "did SESSION_COMPLETE / the WARNING
|
|
141
|
+
// actually arrive?", which nothing could answer before.
|
|
142
|
+
log.info('[IrisWS] message', { type: parsed.type });
|
|
143
|
+
|
|
144
|
+
try {
|
|
145
|
+
opts.onMessage(parsed);
|
|
146
|
+
} catch (err) {
|
|
147
|
+
log.error('[IrisWS] message handler threw', { type: parsed.type, err });
|
|
130
148
|
}
|
|
131
149
|
};
|
|
132
150
|
|
package/src/utils/jpegFromUri.ts
CHANGED
|
@@ -5,14 +5,23 @@
|
|
|
5
5
|
* path into either base64 (for the Iris HMAC envelope) or raw bytes (for
|
|
6
6
|
* binary WebSocket frames + direct PUT to signed URLs).
|
|
7
7
|
*
|
|
8
|
-
* Why not `fetch(uri)
|
|
8
|
+
* Why not `fetch(uri)`?
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
10
|
+
* Two independent reasons, and the second one is the load-bearing one now:
|
|
11
|
+
*
|
|
12
|
+
* 1. React Native's Blob polyfill does NOT implement `Blob.arrayBuffer()`
|
|
13
|
+
* (it's web-only) — calling it throws `blob.arrayBuffer is not a
|
|
14
|
+
* function`.
|
|
15
|
+
* 2. **`fetch` cannot read local files at all since Expo SDK 57.** Expo now
|
|
16
|
+
* replaces the global `fetch` (`expo/src/winter/runtime.native.ts`:
|
|
17
|
+
* `install('fetch', ...)`) with a native HTTP client, and that client does
|
|
18
|
+
* not handle the `file://` scheme. It answers with an empty body instead
|
|
19
|
+
* of failing, so anything reading a capture through `fetch` silently
|
|
20
|
+
* uploads 0 bytes (OSDKR-22). SDK 54 did not install it, which is why the
|
|
21
|
+
* old code worked.
|
|
22
|
+
*
|
|
23
|
+
* `File.arrayBuffer()` from `expo-file-system` reads straight from disk and is
|
|
24
|
+
* unaffected by either.
|
|
16
25
|
*/
|
|
17
26
|
|
|
18
27
|
import { File } from 'expo-file-system';
|
|
@@ -25,18 +34,47 @@ export interface JpegFromUri {
|
|
|
25
34
|
}
|
|
26
35
|
|
|
27
36
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* Accepts both forms vision-camera returns (`/var/mobile/...` without a
|
|
31
|
-
* scheme on iOS; `file:///data/...` on Android). Normalises to `file://`.
|
|
37
|
+
* Normalises the path forms vision-camera returns (`/var/mobile/...` without a
|
|
38
|
+
* scheme on iOS; `file:///data/...` on Android) to a `file://` URI.
|
|
32
39
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
function normalise(uri: string): string {
|
|
41
|
+
return uri.startsWith('file://') || uri.startsWith('http')
|
|
35
42
|
? uri
|
|
36
43
|
: `file://${uri}`;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Reads a local file into raw bytes.
|
|
48
|
+
*
|
|
49
|
+
* Prefer this over `readJpegFromUri` when the caller only needs the bytes —
|
|
50
|
+
* uploads, for instance. It skips the base64 encoding, which is pure waste for
|
|
51
|
+
* a multi-megabyte video.
|
|
52
|
+
*/
|
|
53
|
+
export async function readBytesFromUri(uri: string): Promise<Uint8Array> {
|
|
54
|
+
const buf = await new File(normalise(uri)).arrayBuffer();
|
|
55
|
+
return new Uint8Array(buf);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Size of a local file in bytes, or `0` when it cannot be read.
|
|
60
|
+
*
|
|
61
|
+
* Reads the filesystem metadata instead of loading the contents, so it stays
|
|
62
|
+
* cheap enough to call before an upload.
|
|
63
|
+
*/
|
|
64
|
+
export function byteLengthOfUri(uri: string): number {
|
|
65
|
+
try {
|
|
66
|
+
const size = new File(normalise(uri)).size;
|
|
67
|
+
return typeof size === 'number' ? size : 0;
|
|
68
|
+
} catch {
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Reads a `file://` URI into JPEG bytes + base64 representation.
|
|
75
|
+
*/
|
|
76
|
+
export async function readJpegFromUri(uri: string): Promise<JpegFromUri> {
|
|
77
|
+
const bytes = await readBytesFromUri(uri);
|
|
40
78
|
const base64 = bytesToBase64(bytes);
|
|
41
79
|
return { bytes, base64, byteLength: bytes.byteLength };
|
|
42
80
|
}
|