@trustchex/react-native-sdk 1.472.0 → 1.475.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.
Files changed (30) hide show
  1. package/android/build.gradle +3 -3
  2. package/android/src/main/java/com/trustchex/reactnativesdk/camera/TrustchexCameraView.kt +147 -9
  3. package/ios/Camera/TrustchexCameraView.swift +92 -19
  4. package/lib/module/Screens/Debug/MRZTestScreen.js +121 -147
  5. package/lib/module/Screens/Static/ResultScreen.js +5 -0
  6. package/lib/module/Shared/Components/IdentityDocumentCamera.js +38 -4
  7. package/lib/module/Shared/Libs/MRZ_KNOWN_ISSUES.md +112 -0
  8. package/lib/module/Shared/Libs/mrz.utils.js +639 -16
  9. package/lib/module/Shared/Libs/mrzFrameAggregator.js +301 -0
  10. package/lib/module/Shared/Libs/mrzOcrIntegration.js +109 -0
  11. package/lib/module/version.js +1 -1
  12. package/lib/typescript/src/Screens/Debug/MRZTestScreen.d.ts.map +1 -1
  13. package/lib/typescript/src/Screens/Static/ResultScreen.d.ts.map +1 -1
  14. package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.d.ts.map +1 -1
  15. package/lib/typescript/src/Shared/Libs/mrz.utils.d.ts +8 -0
  16. package/lib/typescript/src/Shared/Libs/mrz.utils.d.ts.map +1 -1
  17. package/lib/typescript/src/Shared/Libs/mrzFrameAggregator.d.ts +76 -0
  18. package/lib/typescript/src/Shared/Libs/mrzFrameAggregator.d.ts.map +1 -0
  19. package/lib/typescript/src/Shared/Libs/mrzOcrIntegration.d.ts +73 -0
  20. package/lib/typescript/src/Shared/Libs/mrzOcrIntegration.d.ts.map +1 -0
  21. package/lib/typescript/src/version.d.ts +1 -1
  22. package/package.json +15 -10
  23. package/src/Screens/Debug/MRZTestScreen.tsx +137 -166
  24. package/src/Screens/Static/ResultScreen.tsx +5 -0
  25. package/src/Shared/Components/IdentityDocumentCamera.tsx +46 -6
  26. package/src/Shared/Libs/MRZ_KNOWN_ISSUES.md +112 -0
  27. package/src/Shared/Libs/mrz.utils.ts +704 -11
  28. package/src/Shared/Libs/mrzFrameAggregator.ts +370 -0
  29. package/src/Shared/Libs/mrzOcrIntegration.ts +175 -0
  30. package/src/version.ts +1 -1
@@ -0,0 +1,301 @@
1
+ "use strict";
2
+
3
+ import mrzUtils from "./mrz.utils.js";
4
+ /**
5
+ * Multi-frame MRZ aggregator: per-character voting across video frames.
6
+ *
7
+ * A single OCR frame of a glossy ID card is noisy — different frames misread
8
+ * different characters (B↔8, S↔5, O↔0, <↔K, dropped/inserted digits). Instead of
9
+ * trusting one frame (or requiring N identical frames, which a single misread
10
+ * resets), this accumulates a per-position character vote across frames and reads
11
+ * out the majority consensus. Frames vote in proportion to a quality weight, so a
12
+ * sharper/closer frame counts more than a blurry one.
13
+ *
14
+ * This is a JS-only, ROVER-inspired post-OCR fusion (Recognizer Output Voting
15
+ * Error Reduction): each frame is first normalised into fixed-width MRZ lines via
16
+ * the existing reconstruction, lines are aligned by index and column, votes are
17
+ * tallied per (line, column), and the winning character per cell forms the
18
+ * consensus MRZ — which is then validated with check digits. Research shows
19
+ * post-OCR result integration beats single-frame OCR and image super-resolution
20
+ * for MRZ in a video stream.
21
+ *
22
+ * Why per-character voting over "N identical reads": a frame that misreads ONE
23
+ * character still contributes correct votes for the other 89 positions, so the
24
+ * consensus converges far faster and is robust to sporadic OCR errors.
25
+ */
26
+
27
+ /** Fixed line geometry per ICAO 9303 format. */
28
+ const FORMAT_GEOMETRY = {
29
+ TD1: {
30
+ lines: 3,
31
+ width: 30
32
+ },
33
+ TD2: {
34
+ lines: 2,
35
+ width: 36
36
+ },
37
+ TD3: {
38
+ lines: 2,
39
+ width: 44
40
+ }
41
+ };
42
+ const MRZ_CHAR = /^[A-Z0-9<]$/;
43
+ /**
44
+ * Reconstructs fixed-width MRZ candidate line-sets for a frame's raw OCR text.
45
+ * Reuses the same reconstruction the single-frame validator uses, so the
46
+ * aggregator sees the SAME normalised lines (filler/doc-code fixes applied),
47
+ * just fused across frames. Returns the best (longest, most filled) candidate.
48
+ */
49
+ /** Does this exact line-set already match a known fixed-width MRZ format? */
50
+ const exactFormatLines = lines => {
51
+ for (const g of Object.values(FORMAT_GEOMETRY)) {
52
+ if (lines.length === g.lines && lines.every(l => l.length === g.width)) {
53
+ return lines;
54
+ }
55
+ }
56
+ return null;
57
+ };
58
+ const linesForFrame = text => {
59
+ // Fast path: if the raw OCR already splits into clean fixed-width MRZ lines of
60
+ // a known format, use them directly. Reconstruction is tuned for noisy TD1 and
61
+ // can mis-shape an already-clean TD2/TD3 (e.g. force a 2×44 passport into a
62
+ // 3×30 layout), so prefer the as-is lines when they're exact.
63
+ const rawLines = text.split('\n').map(l => l.trim().replace(/[^A-Z0-9<]/gi, '').toUpperCase()).filter(Boolean);
64
+ const exact = exactFormatLines(rawLines);
65
+ if (exact) return exact;
66
+ const candidates = mrzUtils.reconstructMRZCandidates(text);
67
+ if (!candidates.length) {
68
+ // Fall back to the lightweight fixMRZ split for already-clean text.
69
+ const fixed = mrzUtils.fixMRZ(text).split('\n').map(l => l.trim()).filter(Boolean);
70
+ return fixed.length >= 2 ? fixed : null;
71
+ }
72
+ // Pick the best candidate and coerce it to an exact format geometry so it can
73
+ // be voted. A frame whose reconstruction is ALMOST a format (right line count,
74
+ // lines within a few chars of the width) still carries useful per-character
75
+ // votes — pad/truncate each line to the format width rather than discarding the
76
+ // whole frame. This keeps the vote accumulating every frame during continuous
77
+ // scanning instead of stalling on the occasional perfectly-shaped frame.
78
+ let best = null;
79
+ let bestScore = -1;
80
+ for (const cand of candidates) {
81
+ const geom = Object.values(FORMAT_GEOMETRY).find(g => g.lines === cand.length);
82
+ if (!geom) continue;
83
+ // Reject if any line is wildly off the expected width (likely not the band).
84
+ if (cand.some(l => Math.abs(l.length - geom.width) > 6)) continue;
85
+ const coerced = cand.map(l => l.length >= geom.width ? l.slice(0, geom.width) : l.padEnd(geom.width, '<'));
86
+ const isExactWidth = cand.every(l => l.length === geom.width);
87
+ const filled = coerced.join('').replace(/</g, '').length;
88
+ // Exact-shaped frames score a little higher, but near-shaped still qualify.
89
+ const score = (isExactWidth ? 10000 : 0) + filled;
90
+ if (score > bestScore) {
91
+ bestScore = score;
92
+ best = coerced;
93
+ }
94
+ }
95
+ return best;
96
+ };
97
+
98
+ /**
99
+ * Stateful aggregator. Feed it one frame's OCR text at a time via `addFrame`;
100
+ * after each it returns the current per-character-voted consensus and whether it
101
+ * is valid + stable. Reset between documents with `reset`.
102
+ */
103
+ export class MRZFrameAggregator {
104
+ // format -> per-line, per-column vote tallies
105
+ tallies = {};
106
+ frameCount = 0;
107
+ lastConsensusMrz = null;
108
+ stableStreak = 0;
109
+ // Consecutive frames whose identifying region disagrees with the consensus.
110
+ mismatchStreak = 0;
111
+ constructor(options = {}) {
112
+ this.stabilityTarget = Math.max(1, options.stabilityTarget ?? 2);
113
+ this.maxFrames = Math.max(1, options.maxFrames ?? 60);
114
+ }
115
+ reset() {
116
+ this.tallies = {};
117
+ this.frameCount = 0;
118
+ this.lastConsensusMrz = null;
119
+ this.stableStreak = 0;
120
+ this.mismatchStreak = 0;
121
+ }
122
+
123
+ /**
124
+ * Returns true when the incoming frame's identifying region (the line-1 data
125
+ * span that holds the document number) has disagreed with the current
126
+ * consensus for enough consecutive frames to conclude a NEW document is in
127
+ * view — so the caller should drop the stale votes. A few disagreeing frames
128
+ * are tolerated as OCR noise; a sustained disagreement is a document swap.
129
+ */
130
+ detectDocumentChange(format, lines) {
131
+ const tally = this.tallies[format];
132
+ if (!tally || this.frameCount < 3) {
133
+ this.mismatchStreak = 0;
134
+ return false;
135
+ }
136
+ // Compare the document-number-bearing region of line 1 (positions 5..14 in
137
+ // TD1; positions 0..9 in TD2/TD3) against the current per-cell winners.
138
+ const [start, end] = format === 'TD1' ? [5, 14] : [0, 9];
139
+ const consensusL1 = this.consensusLines(format)[format === 'TD1' ? 0 : 1];
140
+ const frameL1 = lines[format === 'TD1' ? 0 : 1] ?? '';
141
+ let diffs = 0;
142
+ let compared = 0;
143
+ for (let i = start; i < end; i++) {
144
+ const a = consensusL1[i];
145
+ const b = frameL1[i];
146
+ if (a === '<' || b === '<' || b === undefined) continue; // skip fillers/gaps
147
+ compared++;
148
+ if (a !== b) diffs++;
149
+ }
150
+ // Majority of the doc-number characters differ → this frame is a different doc.
151
+ const isMismatch = compared >= 4 && diffs >= Math.ceil(compared / 2);
152
+ this.mismatchStreak = isMismatch ? this.mismatchStreak + 1 : 0;
153
+ return this.mismatchStreak >= 3;
154
+ }
155
+
156
+ /** Frames contributed so far. */
157
+ get frames() {
158
+ return this.frameCount;
159
+ }
160
+ ensureTally(format) {
161
+ if (!this.tallies[format]) {
162
+ const geom = FORMAT_GEOMETRY[format];
163
+ this.tallies[format] = Array.from({
164
+ length: geom.lines
165
+ }, () => Array.from({
166
+ length: geom.width
167
+ }, () => ({})));
168
+ }
169
+ return this.tallies[format];
170
+ }
171
+
172
+ /**
173
+ * Ingest one frame and return the current consensus. The frame's lines are
174
+ * voted into the tally for whichever format they match; the consensus is then
175
+ * read out per format and validated, and the best valid (or best-effort)
176
+ * consensus is returned.
177
+ */
178
+ addFrame(input) {
179
+ const weight = input.weight && input.weight > 0 ? input.weight : 1;
180
+ const lines = linesForFrame(input.text);
181
+ if (lines) {
182
+ // Determine the format this frame's lines fit (by line count + width).
183
+ const format = Object.keys(FORMAT_GEOMETRY).find(f => {
184
+ const g = FORMAT_GEOMETRY[f];
185
+ return lines.length === g.lines && lines.every(l => l.length === g.width);
186
+ });
187
+ if (format) {
188
+ // Auto-reset when a DIFFERENT document is shown: if this frame's
189
+ // identifying region (line 1 data, where the doc number lives) disagrees
190
+ // strongly with the accumulated consensus for several consecutive frames,
191
+ // the votes are stale — clear them so the new document can converge
192
+ // instead of staying "stable" on the previous one.
193
+ if (this.detectDocumentChange(format, lines)) {
194
+ this.reset();
195
+ }
196
+ const tally = this.ensureTally(format);
197
+ for (let li = 0; li < lines.length; li++) {
198
+ const line = lines[li];
199
+ for (let ci = 0; ci < line.length; ci++) {
200
+ const ch = line[ci];
201
+ if (!MRZ_CHAR.test(ch)) continue;
202
+ const cell = tally[li][ci];
203
+ cell[ch] = (cell[ch] ?? 0) + weight;
204
+ }
205
+ }
206
+ this.frameCount++;
207
+ if (this.frameCount > this.maxFrames) this.decay();
208
+ }
209
+ }
210
+ return this.currentConsensus();
211
+ }
212
+
213
+ /** Halve all tallies to bound memory while preserving relative vote ratios. */
214
+ decay() {
215
+ for (const format of Object.keys(this.tallies)) {
216
+ for (const lineCells of this.tallies[format]) {
217
+ for (const cell of lineCells) {
218
+ for (const ch of Object.keys(cell)) {
219
+ cell[ch] /= 2;
220
+ }
221
+ }
222
+ }
223
+ }
224
+ this.frameCount = Math.ceil(this.frameCount / 2);
225
+ }
226
+
227
+ /** Read out the winning character per cell for a format. */
228
+ consensusLines(format) {
229
+ const geom = FORMAT_GEOMETRY[format];
230
+ const tally = this.tallies[format];
231
+ const lines = [];
232
+ for (let li = 0; li < geom.lines; li++) {
233
+ let line = '';
234
+ for (let ci = 0; ci < geom.width; ci++) {
235
+ const cell = tally[li][ci];
236
+ let bestCh = '<';
237
+ let bestW = -1;
238
+ for (const ch of Object.keys(cell)) {
239
+ // Tie-break deterministically: higher weight wins; on a tie a non-filler
240
+ // beats a filler (fillers are the "no information" default), else lexical.
241
+ const w = cell[ch];
242
+ if (w > bestW || w === bestW && bestCh === '<' && ch !== '<' || w === bestW && bestCh !== '<' && ch !== '<' && ch < bestCh) {
243
+ bestW = w;
244
+ bestCh = ch;
245
+ }
246
+ }
247
+ line += bestW < 0 ? '<' : bestCh;
248
+ }
249
+ lines.push(line);
250
+ }
251
+ return lines;
252
+ }
253
+
254
+ /** Best consensus across all formats seen, validated with check digits. */
255
+ currentConsensus() {
256
+ const formats = Object.keys(this.tallies);
257
+ if (!formats.length) {
258
+ return {
259
+ mrz: null,
260
+ validation: null,
261
+ frames: this.frameCount,
262
+ stable: false
263
+ };
264
+ }
265
+ let bestMrz = null;
266
+ let bestValidation = null;
267
+ let bestValid = false;
268
+ for (const format of formats) {
269
+ const lines = this.consensusLines(format);
270
+ const mrz = lines.join('\n');
271
+ const validation = mrzUtils.validateMRZWithCorrections(mrz);
272
+ // Prefer a valid consensus; among valid, prefer the one the validator could
273
+ // fully correct (it sets correctedMrz). Among invalid, keep the first.
274
+ if (validation.valid && !bestValid) {
275
+ bestValid = true;
276
+ bestMrz = validation.correctedMrz ?? mrz;
277
+ bestValidation = validation;
278
+ } else if (!bestValid && bestMrz === null) {
279
+ bestMrz = mrz;
280
+ bestValidation = validation;
281
+ }
282
+ }
283
+
284
+ // Stability: the (valid) consensus must be unchanged across consecutive
285
+ // contributing frames. Track the streak on the corrected/consensus string.
286
+ const stableKey = bestValid ? bestMrz : null;
287
+ if (stableKey && stableKey === this.lastConsensusMrz) {
288
+ this.stableStreak++;
289
+ } else {
290
+ this.stableStreak = stableKey ? 1 : 0;
291
+ }
292
+ this.lastConsensusMrz = stableKey;
293
+ return {
294
+ mrz: bestMrz,
295
+ validation: bestValidation,
296
+ frames: this.frameCount,
297
+ stable: bestValid && this.stableStreak >= this.stabilityTarget
298
+ };
299
+ }
300
+ }
301
+ export default MRZFrameAggregator;
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+
3
+ import { NativeModules } from 'react-native';
4
+ import mrzUtils from "./mrz.utils.js";
5
+
6
+ /**
7
+ * On-device MRZ ↔ OCR integration test harness.
8
+ *
9
+ * Runs the REAL ML Kit v2 text recognizer (via the native `MLKitModule`) on a
10
+ * still test image, assembles the recognized text exactly like the camera path
11
+ * does, feeds it through `validateMRZWithCorrections`, and reports whether the
12
+ * OCR-misread MRZ was corrected to a check-digit-valid result.
13
+ *
14
+ * This must run on a device/emulator (ML Kit is native) — it is not a jest test.
15
+ * Feed it the synthetic MRZ images under
16
+ * `src/Screens/Debug/__fixtures__/mrz-images/` (generated by
17
+ * `scripts/gen-mrz-test-images.py`), e.g. read with react-native-fs and pass the
18
+ * base64 to `runMrzOcrSuite`. The check-digit-driven correction in
19
+ * `mrz.utils.ts` is what these images exercise end-to-end against real OCR.
20
+ *
21
+ * ML Kit Text Recognition v2:
22
+ * https://developers.google.com/ml-kit/vision/text-recognition/v2
23
+ */
24
+
25
+ const MLKit = NativeModules.MLKitModule;
26
+
27
+ /** A single image-based test case. */
28
+
29
+ /** Assemble the OCR blocks into newline-separated text, mirroring the camera path. */
30
+ export const assembleOcrText = blocks => blocks.map(b => (b.text ?? '').trim()).filter(t => t.length > 0).join('\n');
31
+
32
+ /**
33
+ * Runs one image through real ML Kit OCR + MRZ correction and checks expectations.
34
+ */
35
+ export const runMrzOcrCase = async (testCase, now = Date.now) => {
36
+ const start = now();
37
+ if (!MLKit?.recognizeText) {
38
+ return {
39
+ name: testCase.name,
40
+ passed: false,
41
+ rawOcr: '',
42
+ validation: {
43
+ valid: false,
44
+ format: 'UNKNOWN',
45
+ error: 'native module'
46
+ },
47
+ reason: 'MLKitModule.recognizeText is unavailable (native module not linked)',
48
+ durationMs: now() - start
49
+ };
50
+ }
51
+ let blocks = [];
52
+ try {
53
+ blocks = await MLKit.recognizeText(testCase.base64);
54
+ } catch (err) {
55
+ return {
56
+ name: testCase.name,
57
+ passed: false,
58
+ rawOcr: '',
59
+ validation: {
60
+ valid: false,
61
+ format: 'UNKNOWN',
62
+ error: 'ocr error'
63
+ },
64
+ reason: `OCR threw: ${err instanceof Error ? err.message : String(err)}`,
65
+ durationMs: now() - start
66
+ };
67
+ }
68
+ const rawOcr = assembleOcrText(blocks);
69
+ const validation = mrzUtils.validateMRZWithCorrections(rawOcr);
70
+ const exp = testCase.expect ?? {};
71
+ const wantValid = exp.valid ?? true;
72
+ const checks = [];
73
+ if (validation.valid !== wantValid) {
74
+ checks.push(`valid=${validation.valid}, expected ${wantValid}`);
75
+ }
76
+ if (wantValid && validation.valid) {
77
+ if (exp.documentNumber && validation.fields?.documentNumber !== exp.documentNumber) {
78
+ checks.push(`documentNumber=${validation.fields?.documentNumber}, expected ${exp.documentNumber}`);
79
+ }
80
+ if (exp.birthDate && validation.fields?.birthDate !== exp.birthDate) {
81
+ checks.push(`birthDate=${validation.fields?.birthDate}, expected ${exp.birthDate}`);
82
+ }
83
+ if (exp.expirationDate && validation.fields?.expirationDate !== exp.expirationDate) {
84
+ checks.push(`expirationDate=${validation.fields?.expirationDate}, expected ${exp.expirationDate}`);
85
+ }
86
+ }
87
+ return {
88
+ name: testCase.name,
89
+ passed: checks.length === 0,
90
+ rawOcr,
91
+ validation,
92
+ reason: checks.join('; '),
93
+ durationMs: now() - start
94
+ };
95
+ };
96
+ /** Runs every case sequentially and aggregates pass/fail. */
97
+ export const runMrzOcrSuite = async cases => {
98
+ const results = [];
99
+ for (const c of cases) {
100
+ results.push(await runMrzOcrCase(c));
101
+ }
102
+ const passed = results.filter(r => r.passed).length;
103
+ return {
104
+ total: results.length,
105
+ passed,
106
+ failed: results.length - passed,
107
+ results
108
+ };
109
+ };
@@ -2,4 +2,4 @@
2
2
 
3
3
  // This file is auto-generated. Do not edit manually.
4
4
  // Version is synced from package.json during build.
5
- export const SDK_VERSION = '1.472.0';
5
+ export const SDK_VERSION = '1.475.1';
@@ -1 +1 @@
1
- {"version":3,"file":"MRZTestScreen.d.ts","sourceRoot":"","sources":["../../../../../src/Screens/Debug/MRZTestScreen.tsx"],"names":[],"mappings":"AAyBA,QAAA,MAAM,aAAa,+CA6LlB,CAAC;AAwFF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"MRZTestScreen.d.ts","sourceRoot":"","sources":["../../../../../src/Screens/Debug/MRZTestScreen.tsx"],"names":[],"mappings":"AA0CA,QAAA,MAAM,aAAa,+CAwIlB,CAAC;AA+FF,eAAe,aAAa,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ResultScreen.d.ts","sourceRoot":"","sources":["../../../../../src/Screens/Static/ResultScreen.tsx"],"names":[],"mappings":"AAqDA,QAAA,MAAM,YAAY,+CAgiCjB,CAAC;AAqIF,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"ResultScreen.d.ts","sourceRoot":"","sources":["../../../../../src/Screens/Static/ResultScreen.tsx"],"names":[],"mappings":"AAqDA,QAAA,MAAM,YAAY,+CAqiCjB,CAAC;AAqIF,eAAe,YAAY,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"IdentityDocumentCamera.d.ts","sourceRoot":"","sources":["../../../../../src/Shared/Components/IdentityDocumentCamera.tsx"],"names":[],"mappings":"AAuEA,OAAO,KAAK,EACV,mBAAmB,EACnB,SAAS,EACT,2BAA2B,EAK5B,MAAM,gCAAgC,CAAC;AAGxC,YAAY,EAAE,mBAAmB,EAAE,SAAS,EAAE,2BAA2B,EAAE,CAAC;AAC5E,YAAY,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAMnE,QAAA,MAAM,sBAAsB,GAAI,uDAI7B,2BAA2B,4CAm2E7B,CAAC;AAiIF,eAAe,sBAAsB,CAAC"}
1
+ {"version":3,"file":"IdentityDocumentCamera.d.ts","sourceRoot":"","sources":["../../../../../src/Shared/Components/IdentityDocumentCamera.tsx"],"names":[],"mappings":"AAwEA,OAAO,KAAK,EACV,mBAAmB,EACnB,SAAS,EACT,2BAA2B,EAK5B,MAAM,gCAAgC,CAAC;AAGxC,YAAY,EAAE,mBAAmB,EAAE,SAAS,EAAE,2BAA2B,EAAE,CAAC;AAC5E,YAAY,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAMnE,QAAA,MAAM,sBAAsB,GAAI,uDAI7B,2BAA2B,4CA04E7B,CAAC;AAiIF,eAAe,sBAAsB,CAAC"}
@@ -10,12 +10,20 @@ export interface MRZValidationResult {
10
10
  valid: boolean;
11
11
  format: MRZFormat;
12
12
  fields?: MRZFields;
13
+ /**
14
+ * The corrected MRZ as newline-joined fixed-width lines, when a valid result
15
+ * was produced. This reflects the FULLY recovered MRZ — check-digit-driven
16
+ * field repair, composite recomputation and noisy-frame reconstruction all
17
+ * applied — not the lightweight `fixMRZ` pre-clean. Display this to the user.
18
+ */
19
+ correctedMrz?: string;
13
20
  error?: string;
14
21
  }
15
22
  declare const _default: {
16
23
  fixMRZ: (rawText: string) => string;
17
24
  validateMRZ: (mrzText: string, autocorrect?: boolean) => MRZValidationResult;
18
25
  validateMRZWithCorrections: (mrzText: string) => MRZValidationResult;
26
+ reconstructMRZCandidates: (rawText: string) => string[][];
19
27
  calculateMRZQualityScore: (mrzText: string) => number;
20
28
  assessMRZQuality: (mrzText: string) => {
21
29
  score: number;
@@ -1 +1 @@
1
- {"version":3,"file":"mrz.utils.d.ts","sourceRoot":"","sources":["../../../../../src/Shared/Libs/mrz.utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,SAAS,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,SAAS,CAAC;IAClB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;;sBAOwB,MAAM,KAAG,MAAM;2BAwU7B,MAAM,gBACF,OAAO,KACnB,mBAAmB;0CAuEuB,MAAM,KAAG,mBAAmB;wCAU9B,MAAM,KAAG,MAAM;gCAmDvB,MAAM;;;;;+BAtQP,MAAM,KAAG,OAAO;iCA4Bd,MAAM,KAAG,MAAM;wCAwPR,MAAM,GAAG,IAAI,KAAG,MAAM,GAAG,IAAI;;AAgBxE,wBASE"}
1
+ {"version":3,"file":"mrz.utils.d.ts","sourceRoot":"","sources":["../../../../../src/Shared/Libs/mrz.utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAepD;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,SAAS,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,SAAS,CAAC;IAClB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;;sBAOwB,MAAM,KAAG,MAAM;2BAk5B7B,MAAM,gBACF,OAAO,KACnB,mBAAmB;0CA6JuB,MAAM,KAAG,mBAAmB;wCA52B9B,MAAM,KAAG,MAAM,EAAE,EAAE;wCAs3BnB,MAAM,KAAG,MAAM;gCAmDvB,MAAM;;;;;+BAvtBP,MAAM,KAAG,OAAO;iCA4Bd,MAAM,KAAG,MAAM;wCAysBR,MAAM,GAAG,IAAI,KAAG,MAAM,GAAG,IAAI;;AAgBxE,wBAUE"}
@@ -0,0 +1,76 @@
1
+ import type { MRZValidationResult } from './mrz.utils';
2
+ export interface MRZFrameInput {
3
+ /** Raw OCR text for this frame (assembled MRZ blocks, newline-separated). */
4
+ text: string;
5
+ /**
6
+ * Optional per-frame quality weight (higher = sharper/closer). Defaults to 1.
7
+ * A caller can pass e.g. a sharpness/focus estimate or the MRZ block's pixel
8
+ * height so crisper frames dominate the vote, per the research finding that
9
+ * focus-weighted voting beats unweighted.
10
+ */
11
+ weight?: number;
12
+ }
13
+ export interface MRZConsensus {
14
+ /** Best consensus MRZ (newline-joined fixed-width lines), or null if none yet. */
15
+ mrz: string | null;
16
+ /** Validation of the current consensus (valid only when check digits pass). */
17
+ validation: MRZValidationResult | null;
18
+ /** Number of frames that contributed a usable line-set so far. */
19
+ frames: number;
20
+ /**
21
+ * True when the consensus is valid AND stable — it has not changed across the
22
+ * last `stabilityTarget` contributing frames. Callers should advance only then.
23
+ */
24
+ stable: boolean;
25
+ }
26
+ export interface MRZFrameAggregatorOptions {
27
+ /**
28
+ * How many consecutive contributing frames the valid consensus must remain
29
+ * unchanged before it is considered stable. Default 2.
30
+ */
31
+ stabilityTarget?: number;
32
+ /** Drop the running tallies after this many frames to bound memory. Default 60. */
33
+ maxFrames?: number;
34
+ }
35
+ /**
36
+ * Stateful aggregator. Feed it one frame's OCR text at a time via `addFrame`;
37
+ * after each it returns the current per-character-voted consensus and whether it
38
+ * is valid + stable. Reset between documents with `reset`.
39
+ */
40
+ export declare class MRZFrameAggregator {
41
+ private readonly stabilityTarget;
42
+ private readonly maxFrames;
43
+ private tallies;
44
+ private frameCount;
45
+ private lastConsensusMrz;
46
+ private stableStreak;
47
+ private mismatchStreak;
48
+ constructor(options?: MRZFrameAggregatorOptions);
49
+ reset(): void;
50
+ /**
51
+ * Returns true when the incoming frame's identifying region (the line-1 data
52
+ * span that holds the document number) has disagreed with the current
53
+ * consensus for enough consecutive frames to conclude a NEW document is in
54
+ * view — so the caller should drop the stale votes. A few disagreeing frames
55
+ * are tolerated as OCR noise; a sustained disagreement is a document swap.
56
+ */
57
+ private detectDocumentChange;
58
+ /** Frames contributed so far. */
59
+ get frames(): number;
60
+ private ensureTally;
61
+ /**
62
+ * Ingest one frame and return the current consensus. The frame's lines are
63
+ * voted into the tally for whichever format they match; the consensus is then
64
+ * read out per format and validated, and the best valid (or best-effort)
65
+ * consensus is returned.
66
+ */
67
+ addFrame(input: MRZFrameInput): MRZConsensus;
68
+ /** Halve all tallies to bound memory while preserving relative vote ratios. */
69
+ private decay;
70
+ /** Read out the winning character per cell for a format. */
71
+ private consensusLines;
72
+ /** Best consensus across all formats seen, validated with check digits. */
73
+ currentConsensus(): MRZConsensus;
74
+ }
75
+ export default MRZFrameAggregator;
76
+ //# sourceMappingURL=mrzFrameAggregator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mrzFrameAggregator.d.ts","sourceRoot":"","sources":["../../../../../src/Shared/Libs/mrzFrameAggregator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAkCvD,MAAM,WAAW,aAAa;IAC5B,6EAA6E;IAC7E,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,kFAAkF;IAClF,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,+EAA+E;IAC/E,UAAU,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACvC,kEAAkE;IAClE,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mFAAmF;IACnF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAkFD;;;;GAIG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IAEnC,OAAO,CAAC,OAAO,CAAqC;IACpD,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,gBAAgB,CAAuB;IAC/C,OAAO,CAAC,YAAY,CAAK;IAEzB,OAAO,CAAC,cAAc,CAAK;gBAEf,OAAO,GAAE,yBAA8B;IAKnD,KAAK,IAAI,IAAI;IAQb;;;;;;OAMG;IACH,OAAO,CAAC,oBAAoB;IA0B5B,iCAAiC;IACjC,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,OAAO,CAAC,WAAW;IAUnB;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,YAAY;IAuC5C,+EAA+E;IAC/E,OAAO,CAAC,KAAK;IAab,4DAA4D;IAC5D,OAAO,CAAC,cAAc;IA8BtB,2EAA2E;IAC3E,gBAAgB,IAAI,YAAY;CAgDjC;AAED,eAAe,kBAAkB,CAAC"}
@@ -0,0 +1,73 @@
1
+ import type { MRZValidationResult } from './mrz.utils';
2
+ /**
3
+ * On-device MRZ ↔ OCR integration test harness.
4
+ *
5
+ * Runs the REAL ML Kit v2 text recognizer (via the native `MLKitModule`) on a
6
+ * still test image, assembles the recognized text exactly like the camera path
7
+ * does, feeds it through `validateMRZWithCorrections`, and reports whether the
8
+ * OCR-misread MRZ was corrected to a check-digit-valid result.
9
+ *
10
+ * This must run on a device/emulator (ML Kit is native) — it is not a jest test.
11
+ * Feed it the synthetic MRZ images under
12
+ * `src/Screens/Debug/__fixtures__/mrz-images/` (generated by
13
+ * `scripts/gen-mrz-test-images.py`), e.g. read with react-native-fs and pass the
14
+ * base64 to `runMrzOcrSuite`. The check-digit-driven correction in
15
+ * `mrz.utils.ts` is what these images exercise end-to-end against real OCR.
16
+ *
17
+ * ML Kit Text Recognition v2:
18
+ * https://developers.google.com/ml-kit/vision/text-recognition/v2
19
+ */
20
+ interface NativeTextBlock {
21
+ text?: string;
22
+ boundingBox?: {
23
+ left: number;
24
+ top: number;
25
+ right: number;
26
+ bottom: number;
27
+ };
28
+ }
29
+ /** A single image-based test case. */
30
+ export interface MrzOcrTestCase {
31
+ /** Human label, e.g. "TD1 specimen — straight-on". */
32
+ name: string;
33
+ /** Base64-encoded JPEG/PNG of the (synthetic) MRZ document. */
34
+ base64: string;
35
+ /**
36
+ * Optional expectations. When omitted, the test passes if the MRZ validates.
37
+ * Provide these for stronger assertions against the known synthetic values.
38
+ */
39
+ expect?: {
40
+ valid?: boolean;
41
+ documentNumber?: string;
42
+ birthDate?: string;
43
+ expirationDate?: string;
44
+ };
45
+ }
46
+ export interface MrzOcrTestResult {
47
+ name: string;
48
+ passed: boolean;
49
+ /** Raw text ML Kit produced (joined blocks). Useful for debugging failures. */
50
+ rawOcr: string;
51
+ /** Validation result after correction. */
52
+ validation: MRZValidationResult;
53
+ /** Why it failed (empty when passed). */
54
+ reason?: string;
55
+ /** Time spent in OCR + correction, ms. */
56
+ durationMs: number;
57
+ }
58
+ /** Assemble the OCR blocks into newline-separated text, mirroring the camera path. */
59
+ export declare const assembleOcrText: (blocks: NativeTextBlock[]) => string;
60
+ /**
61
+ * Runs one image through real ML Kit OCR + MRZ correction and checks expectations.
62
+ */
63
+ export declare const runMrzOcrCase: (testCase: MrzOcrTestCase, now?: () => number) => Promise<MrzOcrTestResult>;
64
+ export interface MrzOcrSuiteResult {
65
+ total: number;
66
+ passed: number;
67
+ failed: number;
68
+ results: MrzOcrTestResult[];
69
+ }
70
+ /** Runs every case sequentially and aggregates pass/fail. */
71
+ export declare const runMrzOcrSuite: (cases: MrzOcrTestCase[]) => Promise<MrzOcrSuiteResult>;
72
+ export {};
73
+ //# sourceMappingURL=mrzOcrIntegration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mrzOcrIntegration.d.ts","sourceRoot":"","sources":["../../../../../src/Shared/Libs/mrzOcrIntegration.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD;;;;;;;;;;;;;;;;;GAiBG;AAEH,UAAU,eAAe;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5E;AASD,sCAAsC;AACtC,MAAM,WAAW,cAAc;IAC7B,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,+DAA+D;IAC/D,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,MAAM,CAAC,EAAE;QACP,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,CAAC;CACH;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,+EAA+E;IAC/E,MAAM,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,UAAU,EAAE,mBAAmB,CAAC;IAChC,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,sFAAsF;AACtF,eAAO,MAAM,eAAe,GAAI,QAAQ,eAAe,EAAE,KAAG,MAI7C,CAAC;AAEhB;;GAEG;AACH,eAAO,MAAM,aAAa,GACxB,UAAU,cAAc,EACxB,MAAK,MAAM,MAAiB,KAC3B,OAAO,CAAC,gBAAgB,CAuE1B,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,gBAAgB,EAAE,CAAC;CAC7B;AAED,6DAA6D;AAC7D,eAAO,MAAM,cAAc,GACzB,OAAO,cAAc,EAAE,KACtB,OAAO,CAAC,iBAAiB,CAY3B,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const SDK_VERSION = "1.472.0";
1
+ export declare const SDK_VERSION = "1.475.1";
2
2
  //# sourceMappingURL=version.d.ts.map