react-native-unit-components 3.5.0 → 3.5.2
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/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.js +2 -0
- package/lib/commonjs/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.js.map +1 -1
- package/lib/commonjs/scripts/html/bodyScript.js +22 -1
- package/lib/commonjs/scripts/html/bodyScript.js.map +1 -1
- package/lib/commonjs/services/veryfiService.js +68 -12
- package/lib/commonjs/services/veryfiService.js.map +1 -1
- package/lib/commonjs/services/veryfiService.utils.js +87 -0
- package/lib/commonjs/services/veryfiService.utils.js.map +1 -0
- package/lib/commonjs/unitComponentsSdkManager/UnitComponentsSdkManager.js +1 -1
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.js +3 -1
- package/lib/module/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.js.map +1 -1
- package/lib/module/scripts/html/bodyScript.js +21 -0
- package/lib/module/scripts/html/bodyScript.js.map +1 -1
- package/lib/module/services/veryfiService.js +68 -12
- package/lib/module/services/veryfiService.js.map +1 -1
- package/lib/module/services/veryfiService.utils.js +79 -0
- package/lib/module/services/veryfiService.utils.js.map +1 -0
- package/lib/module/unitComponentsSdkManager/UnitComponentsSdkManager.js +1 -1
- package/lib/typescript/src/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.d.ts.map +1 -1
- package/lib/typescript/src/scripts/html/bodyScript.d.ts +1 -0
- package/lib/typescript/src/scripts/html/bodyScript.d.ts.map +1 -1
- package/lib/typescript/src/services/veryfiService.d.ts +2 -4
- package/lib/typescript/src/services/veryfiService.d.ts.map +1 -1
- package/lib/typescript/src/services/veryfiService.utils.d.ts +10 -0
- package/lib/typescript/src/services/veryfiService.utils.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/components/UNBottomSheetComponent/UNBottomSheetComponent.utils.ts +3 -1
- package/src/scripts/html/bodyScript.ts +21 -0
- package/src/services/veryfiService.ts +76 -16
- package/src/services/veryfiService.utils.ts +87 -0
- package/src/unitComponentsSdkManager/UnitComponentsSdkManager.ts +1 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export interface UNVeryfiImage {
|
|
2
|
+
base64Img: string;
|
|
3
|
+
isFront: boolean;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const JPEG_SOF_MARKERS = [0xc0, 0xc1, 0xc2, 0xc3, 0xc5, 0xc6, 0xc7, 0xc9, 0xca, 0xcb, 0xcd, 0xce, 0xcf];
|
|
7
|
+
|
|
8
|
+
export const readJpegDimensions = (base64: string): { width: number; height: number } | null => {
|
|
9
|
+
try {
|
|
10
|
+
// SOF sits near the file start; a 4-aligned prefix keeps atob happy and cheap.
|
|
11
|
+
const prefix = base64.length > 786432 ? base64.slice(0, 786432) : base64;
|
|
12
|
+
const bytes = atob(prefix);
|
|
13
|
+
if (bytes.charCodeAt(0) !== 0xff || bytes.charCodeAt(1) !== 0xd8) return null;
|
|
14
|
+
let i = 2;
|
|
15
|
+
while (i + 9 < bytes.length) {
|
|
16
|
+
if (bytes.charCodeAt(i) !== 0xff) {
|
|
17
|
+
i++;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
const marker = bytes.charCodeAt(i + 1);
|
|
21
|
+
if (marker === 0xff) {
|
|
22
|
+
i++;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (marker === 0x01 || (marker >= 0xd0 && marker <= 0xd9)) {
|
|
26
|
+
i += 2;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (JPEG_SOF_MARKERS.includes(marker)) {
|
|
30
|
+
return {
|
|
31
|
+
height: bytes.charCodeAt(i + 5) * 256 + bytes.charCodeAt(i + 6),
|
|
32
|
+
width: bytes.charCodeAt(i + 7) * 256 + bytes.charCodeAt(i + 8),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
i += 2 + bytes.charCodeAt(i + 2) * 256 + bytes.charCodeAt(i + 3);
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
} catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Veryfi's parsed result is the authority on which image is the front
|
|
44
|
+
// (their meta.pages[].is_front); page order does not correspond to the
|
|
45
|
+
// delivery array's order, so pages are matched to our images by exact
|
|
46
|
+
// pixel dimensions. Returns null whenever the verdict is not unambiguous.
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
+
export const labelSidesFromPages = (images: UNVeryfiImage[], pages: any): UNVeryfiImage[] | null => {
|
|
49
|
+
if (!Array.isArray(pages) || pages.length !== 2 || images.length !== 2) return null;
|
|
50
|
+
|
|
51
|
+
const fronts = pages.filter((p) => p && p.is_front === true);
|
|
52
|
+
const backs = pages.filter((p) => p && p.is_front === false);
|
|
53
|
+
const frontPage = fronts[0];
|
|
54
|
+
const backPage = backs[0];
|
|
55
|
+
if (fronts.length !== 1 || backs.length !== 1 || !frontPage || !backPage) return null;
|
|
56
|
+
if (typeof frontPage.width !== 'number' || typeof frontPage.height !== 'number') return null;
|
|
57
|
+
|
|
58
|
+
const dims: { width: number; height: number }[] = [];
|
|
59
|
+
for (const img of images) {
|
|
60
|
+
const d = readJpegDimensions(img.base64Img);
|
|
61
|
+
if (!d) return null;
|
|
62
|
+
dims.push(d);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Veryfi may auto-rotate pages in the parsed result, so dimensions are
|
|
66
|
+
// compared as an unordered pair.
|
|
67
|
+
const sameDims = (d: { width: number; height: number }, w: number, h: number) =>
|
|
68
|
+
(d.width === w && d.height === h) || (d.width === h && d.height === w);
|
|
69
|
+
|
|
70
|
+
const matchesFront = dims.map((d) => sameDims(d, frontPage.width, frontPage.height));
|
|
71
|
+
if (matchesFront.filter(Boolean).length !== 1) return null;
|
|
72
|
+
|
|
73
|
+
const frontIdx = matchesFront.indexOf(true);
|
|
74
|
+
const backIdx = 1 - frontIdx;
|
|
75
|
+
const frontImage = images[frontIdx];
|
|
76
|
+
const backImage = images[backIdx];
|
|
77
|
+
const backDims = dims[backIdx];
|
|
78
|
+
if (!frontImage || !backImage || !backDims) return null;
|
|
79
|
+
if (typeof backPage.width === 'number' && typeof backPage.height === 'number') {
|
|
80
|
+
if (!sameDims(backDims, backPage.width, backPage.height)) return null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return [
|
|
84
|
+
{ base64Img: frontImage.base64Img, isFront: true },
|
|
85
|
+
{ base64Img: backImage.base64Img, isFront: false },
|
|
86
|
+
];
|
|
87
|
+
};
|
|
@@ -27,7 +27,7 @@ export class UnitComponentsSDK {
|
|
|
27
27
|
protected static fonts?: UNFonts;
|
|
28
28
|
protected static signedNonce?: string;
|
|
29
29
|
protected static pushProvisionModule?: typeof NativeModules;
|
|
30
|
-
protected static sdkVersion = '3.5.
|
|
30
|
+
protected static sdkVersion = '3.5.2';
|
|
31
31
|
static iosFontBase64Map: Record<string, string> = {};
|
|
32
32
|
|
|
33
33
|
public static init = async (
|