@trustchex/react-native-sdk 1.487.0 → 1.489.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.
- package/ios/ImageDecoder/ImageDecoderModule.m +12 -0
- package/ios/ImageDecoder/ImageDecoderModule.swift +43 -0
- package/lib/module/Shared/Components/EIDScanner.js +100 -37
- package/lib/module/Shared/Components/IdentityDocumentCamera.constants.js +9 -1
- package/lib/module/Shared/Components/IdentityDocumentCamera.flows.js +22 -2
- package/lib/module/Shared/Components/IdentityDocumentCamera.js +1 -1
- package/lib/module/Shared/Components/IdentityDocumentCamera.utils.js +7 -7
- package/lib/module/Shared/EIDReader/cardFileInputStream.js +25 -2
- package/lib/module/Shared/EIDReader/defaultFileSystem.js +56 -6
- package/lib/module/Shared/EIDReader/eidReader.js +138 -16
- package/lib/module/Shared/EIDReader/lds/icao/dg11File.js +23 -6
- package/lib/module/Shared/EIDReader/nfcManagerCardService.js +79 -9
- package/lib/module/Shared/EIDReader/protocol/paceDH.js +101 -0
- package/lib/module/Shared/EIDReader/protocol/paceErrors.js +34 -0
- package/lib/module/Shared/EIDReader/protocol/paceProtocol.js +53 -4
- package/lib/module/Shared/EIDReader/protocol/readBinaryAPDUSender.js +7 -3
- package/lib/module/Shared/Libs/country-display.utils.js +13 -1
- package/lib/module/Shared/Libs/diagnosticReport.js +24 -1
- package/lib/module/Shared/Libs/diagnostics.js +30 -8
- package/lib/module/Shared/Libs/jp2Decode.js +43 -0
- package/lib/module/Shared/Libs/mrz.utils.js +22 -5
- package/lib/module/Shared/Libs/mrzTransliteration.js +14 -1
- package/lib/module/Translation/Resources/en.js +12 -0
- package/lib/module/Translation/Resources/tr.js +12 -0
- package/lib/module/version.js +1 -1
- package/lib/typescript/src/Shared/Components/EIDScanner.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.constants.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.flows.d.ts +11 -0
- package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.flows.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.utils.d.ts +1 -1
- package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.utils.d.ts.map +1 -1
- package/lib/typescript/src/Shared/EIDReader/cardFileInputStream.d.ts +3 -0
- package/lib/typescript/src/Shared/EIDReader/cardFileInputStream.d.ts.map +1 -1
- package/lib/typescript/src/Shared/EIDReader/defaultFileSystem.d.ts +4 -0
- package/lib/typescript/src/Shared/EIDReader/defaultFileSystem.d.ts.map +1 -1
- package/lib/typescript/src/Shared/EIDReader/eidReader.d.ts.map +1 -1
- package/lib/typescript/src/Shared/EIDReader/lds/icao/dg11File.d.ts.map +1 -1
- package/lib/typescript/src/Shared/EIDReader/nfcManagerCardService.d.ts +9 -1
- package/lib/typescript/src/Shared/EIDReader/nfcManagerCardService.d.ts.map +1 -1
- package/lib/typescript/src/Shared/EIDReader/protocol/paceDH.d.ts +56 -0
- package/lib/typescript/src/Shared/EIDReader/protocol/paceDH.d.ts.map +1 -0
- package/lib/typescript/src/Shared/EIDReader/protocol/paceErrors.d.ts +26 -0
- package/lib/typescript/src/Shared/EIDReader/protocol/paceErrors.d.ts.map +1 -0
- package/lib/typescript/src/Shared/EIDReader/protocol/paceProtocol.d.ts.map +1 -1
- package/lib/typescript/src/Shared/EIDReader/protocol/readBinaryAPDUSender.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Libs/country-display.utils.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Libs/diagnosticReport.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Libs/diagnostics.d.ts +9 -1
- package/lib/typescript/src/Shared/Libs/diagnostics.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Libs/jp2Decode.d.ts +13 -0
- package/lib/typescript/src/Shared/Libs/jp2Decode.d.ts.map +1 -0
- package/lib/typescript/src/Shared/Libs/mrz.utils.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Libs/mrzTransliteration.d.ts.map +1 -1
- package/lib/typescript/src/Translation/Resources/en.d.ts +12 -0
- package/lib/typescript/src/Translation/Resources/en.d.ts.map +1 -1
- package/lib/typescript/src/Translation/Resources/tr.d.ts +12 -0
- package/lib/typescript/src/Translation/Resources/tr.d.ts.map +1 -1
- package/lib/typescript/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/Shared/Components/EIDScanner.tsx +153 -69
- package/src/Shared/Components/IdentityDocumentCamera.constants.ts +9 -1
- package/src/Shared/Components/IdentityDocumentCamera.flows.ts +22 -2
- package/src/Shared/Components/IdentityDocumentCamera.tsx +1 -2
- package/src/Shared/Components/IdentityDocumentCamera.utils.ts +6 -8
- package/src/Shared/EIDReader/cardFileInputStream.ts +30 -6
- package/src/Shared/EIDReader/defaultFileSystem.ts +75 -17
- package/src/Shared/EIDReader/eidReader.ts +172 -24
- package/src/Shared/EIDReader/lds/icao/dg11File.ts +28 -13
- package/src/Shared/EIDReader/nfcManagerCardService.ts +91 -13
- package/src/Shared/EIDReader/protocol/paceDH.ts +183 -0
- package/src/Shared/EIDReader/protocol/paceErrors.ts +41 -0
- package/src/Shared/EIDReader/protocol/paceProtocol.ts +72 -6
- package/src/Shared/EIDReader/protocol/readBinaryAPDUSender.ts +7 -4
- package/src/Shared/Libs/country-display.utils.ts +12 -1
- package/src/Shared/Libs/diagnosticReport.ts +32 -1
- package/src/Shared/Libs/diagnostics.ts +38 -14
- package/src/Shared/Libs/jp2Decode.ts +48 -0
- package/src/Shared/Libs/mrz.utils.ts +27 -6
- package/src/Shared/Libs/mrzTransliteration.ts +16 -3
- package/src/Translation/Resources/en.ts +19 -0
- package/src/Translation/Resources/tr.ts +19 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DH (modular exponentiation, non-EC) primitives for PACE Generic Mapping.
|
|
3
|
+
*
|
|
4
|
+
* Modern ePassports/eIDs use ECDH almost universally; a minority of documents
|
|
5
|
+
* negotiate classic DH PACE. This module provides the DH math as pure,
|
|
6
|
+
* unit-testable functions so it can be verified against the ICAO 9303 Part 11
|
|
7
|
+
* worked example before it ever touches a chip. It is deliberately separate from
|
|
8
|
+
* the EC path in paceProtocol.ts — the working ECDH handshake is not modified.
|
|
9
|
+
*
|
|
10
|
+
* References: ICAO Doc 9303 Part 11 §4.4.3.2 (Generic Mapping), BSI TR-03110
|
|
11
|
+
* Part 3 §3.3.1, RFC 5114 (standardized MODP groups), TR-03110 Table A.1
|
|
12
|
+
* (standardized domain parameter IDs 0–7).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** A DH group: safe-prime modulus p, generator g, and subgroup order q. */
|
|
16
|
+
export interface DHGroup {
|
|
17
|
+
/** prime modulus */
|
|
18
|
+
p: bigint;
|
|
19
|
+
/** generator */
|
|
20
|
+
g: bigint;
|
|
21
|
+
/** subgroup order (q) — used to size exponents */
|
|
22
|
+
q: bigint;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const hx = (s: string): bigint => BigInt('0x' + s.replace(/\s+/g, ''));
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Standardized DH domain parameters by TR-03110 parameter ID.
|
|
29
|
+
* 0 → RFC 5114 §2.1 1024-bit MODP Group with 160-bit Prime Order Subgroup
|
|
30
|
+
* 1 → RFC 5114 §2.2 2048-bit MODP Group with 224-bit Prime Order Subgroup
|
|
31
|
+
* 2 → RFC 5114 §2.3 2048-bit MODP Group with 256-bit Prime Order Subgroup
|
|
32
|
+
* (IDs 3–7 are reserved/unused in practice; EC params start at 8.)
|
|
33
|
+
*/
|
|
34
|
+
export const DH_GROUPS: Record<number, DHGroup> = {
|
|
35
|
+
// RFC 5114 §2.1 — 1024-bit MODP, 160-bit subgroup (the ICAO worked-example group).
|
|
36
|
+
0: {
|
|
37
|
+
p: hx(
|
|
38
|
+
'B10B8F96 A080E01D DE92DE5E AE5D54EC 52C99FBC FB06A3C6' +
|
|
39
|
+
'9A6A9DCA 52D23B61 6073E286 75A23D18 9838EF1E 2EE652C0' +
|
|
40
|
+
'13ECB4AE A9061123 24975C3C D49B83BF ACCBDD7D 90C4BD70' +
|
|
41
|
+
'98488E9C 219A7372 4EFFD6FA E5644738 FAA31A4F F55BCCC0' +
|
|
42
|
+
'A151AF5F 0DC8B4BD 45BF37DF 365C1A65 E68CFDA7 6D4DA708' +
|
|
43
|
+
'DF1FB2BC 2E4A4371'
|
|
44
|
+
),
|
|
45
|
+
g: hx(
|
|
46
|
+
'A4D1CBD5 C3FD3412 6765A442 EFB99905 F8104DD2 58AC507F' +
|
|
47
|
+
'D6406CFF 14266D31 266FEA1E 5C41564B 777E690F 5504F213' +
|
|
48
|
+
'160217B4 B01B886A 5E91547F 9E2749F4 D7FBD7D3 B9A92EE1' +
|
|
49
|
+
'909D0D22 63F80A76 A6A24C08 7A091F53 1DBF0A01 69B6A28A' +
|
|
50
|
+
'D662A4D1 8E73AFA3 2D779D59 18D08BC8 858F4DCE F97C2A24' +
|
|
51
|
+
'855E6EEB 22B3B2E5'
|
|
52
|
+
),
|
|
53
|
+
q: hx('F518AA87 81A8DF27 8ABA4E7D 64B7CB9D 49462353'),
|
|
54
|
+
},
|
|
55
|
+
// RFC 5114 §2.2 — 2048-bit MODP, 224-bit subgroup.
|
|
56
|
+
1: {
|
|
57
|
+
p: hx(
|
|
58
|
+
'AD107E1E 9123A9D0 D660FAA7 9559C51F A20D64E5 683B9FD1' +
|
|
59
|
+
'B54B1597 B61D0A75 E6FA141D F95A56DB AF9A3C40 7BA1DF15' +
|
|
60
|
+
'EB3D688A 309C180E 1DE6B85A 1274A0A6 6D3F8152 AD6AC212' +
|
|
61
|
+
'9037C9ED EFDA4DF8 D91E8FEF 55B7394B 7AD5B7D0 B6C12207' +
|
|
62
|
+
'C9F98D11 ED34DBF6 C6BA0B2C 8BBC27BE 6A00E0A0 B9C49708' +
|
|
63
|
+
'B3BF8A31 70918836 81286130 BC8985DB 1602E714 415D9330' +
|
|
64
|
+
'278273C7 DE31EFDC 7310F712 1FD5A074 15987D9A DC0A486D' +
|
|
65
|
+
'CDF93ACC 44328387 315D75E1 98C641A4 80CD86A1 B9E587E8' +
|
|
66
|
+
'BE60E69C C928B2B9 C52172E4 13042E9B 23F10B0E 16E79763' +
|
|
67
|
+
'C9B53DCF 4BA80A29 E3FB73C1 6B8E75B9 7EF363E2 FFA31F71' +
|
|
68
|
+
'CF9DE538 4E71B81C 0AC4DFFE 0C10E64F'
|
|
69
|
+
),
|
|
70
|
+
g: hx(
|
|
71
|
+
'AC4032EF 4F2D9AE3 9DF30B5C 8FFDAC50 6CDEBE7B 89998CAF' +
|
|
72
|
+
'74866A08 CFE4FFE3 A6824A4E 10B9A6F0 DD921F01 A70C4AFA' +
|
|
73
|
+
'AB739D77 00C29F52 C57DB17C 620A8652 BE5E9001 A8D66AD7' +
|
|
74
|
+
'C1766910 1999024A F4D02727 5AC1348B B8A762D0 521BC98A' +
|
|
75
|
+
'E2471504 22EA1ED4 09939D54 DA7460CD B5F6C6B2 50717CBE' +
|
|
76
|
+
'F180EB34 118E98D1 19529A45 D6F83456 6E3025E3 16A330EF' +
|
|
77
|
+
'BB77A86F 0C1AB15B 051AE3D4 28C8F8AC B70A8137 150B8EEB' +
|
|
78
|
+
'10E183ED D19963DD D9E263E4 770589EF 6AA21E7F 5F2FF381' +
|
|
79
|
+
'B539CCE3 409D13CD 566AFBB4 8D6C0191 81E1BCFE 94B30269' +
|
|
80
|
+
'EDFE72FE 9B6AA4BD 7B5A0F1C 71CFFF4C 19C418E1 F6EC0179' +
|
|
81
|
+
'81BC087F 2A7065B3 84B890D3 191F2BFA'
|
|
82
|
+
),
|
|
83
|
+
q: hx('801C0D34 C58D93FE 99717710 1F80535A 4738CEBC BF389A99' + 'B36371EB'),
|
|
84
|
+
},
|
|
85
|
+
// RFC 5114 §2.3 — 2048-bit MODP, 256-bit subgroup.
|
|
86
|
+
2: {
|
|
87
|
+
p: hx(
|
|
88
|
+
'87A8E61D B4B6663C FFBBD19C 65195999 8CEEF608 660DD0F2' +
|
|
89
|
+
'5D2CEED4 435E3B00 E00DF8F1 D61957D4 FAF7DF45 61B2AA30' +
|
|
90
|
+
'16C3D911 34096FAA 3BF4296D 830E9A7C 209E0C64 97517ABD' +
|
|
91
|
+
'5A8A9D30 6BCF67ED 91F9E672 5B4758C0 22E0B1EF 4275BF7B' +
|
|
92
|
+
'6C5BFC11 D45F9088 B941F54E B1E59BB8 BC39A0BF 12307F5C' +
|
|
93
|
+
'4FDB70C5 81B23F76 B63ACAE1 CAA6B790 2D525267 35488A0E' +
|
|
94
|
+
'F13C6D9A 51BFA4AB 3AD83477 96524D8E F6A167B5 A41825D9' +
|
|
95
|
+
'67E144E5 14056425 1CCACB83 E6B486F6 B3CA3F79 71506026' +
|
|
96
|
+
'C0B857F6 89962856 DED4010A BD0BE621 C3A3960A 54E710C3' +
|
|
97
|
+
'75F26375 D7014103 A4B54330 C198AF12 6116D227 6E11715F' +
|
|
98
|
+
'693877FA D7EF09CA DB094AE9 1E1A1597'
|
|
99
|
+
),
|
|
100
|
+
g: hx(
|
|
101
|
+
'3FB32C9B 73134D0B 2E775066 60EDBD48 4CA7B18F 21EF2054' +
|
|
102
|
+
'07F4793A 1A0BA125 10DBC150 77BE463F FF4FED4A AC0BB555' +
|
|
103
|
+
'BE3A6C1B 0C6B47B1 BC3773BF 7E8C6F62 901228F8 C28CBB18' +
|
|
104
|
+
'A55AE313 41000A65 0196F931 C77A57F2 DDF463E5 E9EC144B' +
|
|
105
|
+
'777DE62A AAB8A862 8AC376D2 82D6ED38 64E67982 428EBC83' +
|
|
106
|
+
'1D14348F 6F2F9193 B5045AF2 767164E1 DFC967C1 FB3F2E55' +
|
|
107
|
+
'A4BD1BFF E83B9C80 D052B985 D182EA0A DB2A3B73 13D3FE14' +
|
|
108
|
+
'C8484B1E 052588B9 B7D2BBD2 DF016199 ECD06E15 57CD0915' +
|
|
109
|
+
'B3353BBB 64E0EC37 7FD02837 0DF92B52 C7891428 CDC67EB6' +
|
|
110
|
+
'184B523D 1DB246C3 2F630784 90F00EF8 D647D148 D4795451' +
|
|
111
|
+
'5E2327CF EF98C582 664B4C0F 6CC41659'
|
|
112
|
+
),
|
|
113
|
+
q: hx(
|
|
114
|
+
'8CF83642 A709A097 B4479976 40129DA2 99B1A47D 1EB3750B' +
|
|
115
|
+
'A308B0FE 64F5FBD3'
|
|
116
|
+
),
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* PACE DH Generic Mapping (ICAO 9303 Part 11 §4.4.3.2):
|
|
122
|
+
* shared secret h = PK_PICC ^ SK_PCD mod p
|
|
123
|
+
* mapped generator g~ = g^s · h mod p
|
|
124
|
+
* where s is the decrypted PICC nonce (a big-endian integer).
|
|
125
|
+
*
|
|
126
|
+
* Pure function over the group + the three inputs, so it can be checked against
|
|
127
|
+
* the ICAO worked example. `pkPicc` is the PICC mapping public key; `skPcd` the
|
|
128
|
+
* PCD mapping private key; `nonce` the decrypted nonce s.
|
|
129
|
+
*/
|
|
130
|
+
export const dhGenericMapping = (
|
|
131
|
+
group: DHGroup,
|
|
132
|
+
skPcd: bigint,
|
|
133
|
+
pkPicc: bigint,
|
|
134
|
+
nonce: bigint
|
|
135
|
+
): { sharedH: bigint; mappedGenerator: bigint } => {
|
|
136
|
+
const sharedH = modPow(pkPicc, skPcd, group.p);
|
|
137
|
+
const gPowS = modPow(group.g, nonce, group.p);
|
|
138
|
+
const mappedGenerator = (gPowS * sharedH) % group.p;
|
|
139
|
+
return { sharedH, mappedGenerator };
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* DH key agreement with a mapped generator (PACE step 3):
|
|
144
|
+
* PK = g~ ^ SK mod p (public key to send)
|
|
145
|
+
* K = PK_PICC ^ SK mod p (shared secret)
|
|
146
|
+
*/
|
|
147
|
+
export const dhPublicKey = (
|
|
148
|
+
group: DHGroup,
|
|
149
|
+
mappedGenerator: bigint,
|
|
150
|
+
sk: bigint
|
|
151
|
+
): bigint => modPow(mappedGenerator, sk, group.p);
|
|
152
|
+
|
|
153
|
+
export const dhSharedSecret = (
|
|
154
|
+
group: DHGroup,
|
|
155
|
+
pkPicc: bigint,
|
|
156
|
+
sk: bigint
|
|
157
|
+
): bigint => modPow(pkPicc, sk, group.p);
|
|
158
|
+
|
|
159
|
+
/** Square-and-multiply modular exponentiation (constant-shape, bigint). */
|
|
160
|
+
export function modPow(base: bigint, exp: bigint, mod: bigint): bigint {
|
|
161
|
+
if (mod === 1n) return 0n;
|
|
162
|
+
let result = 1n;
|
|
163
|
+
base = ((base % mod) + mod) % mod;
|
|
164
|
+
let e = exp;
|
|
165
|
+
while (e > 0n) {
|
|
166
|
+
if (e & 1n) result = (result * base) % mod;
|
|
167
|
+
e >>= 1n;
|
|
168
|
+
base = (base * base) % mod;
|
|
169
|
+
}
|
|
170
|
+
return result;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Fixed-width big-endian byte encoding of a DH value (left-padded to p's size). */
|
|
174
|
+
export const dhEncode = (value: bigint, group: DHGroup): Buffer => {
|
|
175
|
+
const byteLen = Math.ceil(group.p.toString(16).length / 2);
|
|
176
|
+
let h = value.toString(16);
|
|
177
|
+
if (h.length % 2) h = '0' + h;
|
|
178
|
+
const buf = Buffer.from(h, 'hex');
|
|
179
|
+
if (buf.length === byteLen) return buf;
|
|
180
|
+
const out = Buffer.alloc(byteLen);
|
|
181
|
+
buf.copy(out, byteLen - buf.length);
|
|
182
|
+
return out;
|
|
183
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed PACE errors.
|
|
3
|
+
*
|
|
4
|
+
* The point is to let the caller distinguish a PACE CAPABILITY gap (this build
|
|
5
|
+
* cannot run the variant the chip advertises — e.g. DH agreement, CAM mapping,
|
|
6
|
+
* an unregistered curve) from a RUNTIME failure (wrong key, tag lost, APDU
|
|
7
|
+
* error). Both fall back to BAC, but the diagnostics reason must differ so we
|
|
8
|
+
* can tell "we don't support this document's PACE" from "the read went wrong".
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Why a PACE attempt could not even be run by this implementation. */
|
|
12
|
+
export type PACEUnsupportedReason =
|
|
13
|
+
| 'agreement' // key-agreement algorithm not implemented (e.g. DH when only ECDH built)
|
|
14
|
+
| 'mapping' // mapping type not implemented (e.g. CAM)
|
|
15
|
+
| 'curve' // standardized domain parameter / curve not registered
|
|
16
|
+
| 'cipher'; // cipher not implemented for the chosen mapping
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Thrown when the chip advertises a PACE variant this build cannot perform.
|
|
20
|
+
* Carries a coarse, non-PII reason that maps directly to a diagnostics fallback
|
|
21
|
+
* reason (`pace_unsupported_<reason>`), so support can see exactly which
|
|
22
|
+
* capability was missing for a given document.
|
|
23
|
+
*/
|
|
24
|
+
export class PACEUnsupportedError extends Error {
|
|
25
|
+
readonly paceUnsupported = true;
|
|
26
|
+
readonly reason: PACEUnsupportedReason;
|
|
27
|
+
|
|
28
|
+
constructor(reason: PACEUnsupportedReason, detail: string) {
|
|
29
|
+
super(`PACE variant not supported (${reason}): ${detail}`);
|
|
30
|
+
this.name = 'PACEUnsupportedError';
|
|
31
|
+
this.reason = reason;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Type guard usable across module boundaries (instanceof is unreliable after
|
|
36
|
+
* transpilation/bundling, so we also check the marker flag). */
|
|
37
|
+
export const isPACEUnsupportedError = (e: unknown): e is PACEUnsupportedError =>
|
|
38
|
+
e instanceof PACEUnsupportedError ||
|
|
39
|
+
(typeof e === 'object' &&
|
|
40
|
+
e !== null &&
|
|
41
|
+
(e as { paceUnsupported?: boolean }).paceUnsupported === true);
|
|
@@ -4,6 +4,7 @@ import type { SecureMessagingWrapper } from '../secureMessagingWrapper';
|
|
|
4
4
|
import { AESSecureMessagingWrapper } from '../aesSecureMessagingWrapper';
|
|
5
5
|
import { TripleDesSecureMessagingWrapper } from '../tripleDesSecureMessagingWrapper';
|
|
6
6
|
import { PACEInfo } from '../paceInfo';
|
|
7
|
+
import { PACEUnsupportedError } from './paceErrors';
|
|
7
8
|
import { PACEResult } from './paceResult';
|
|
8
9
|
import { PACEKeySpec } from '../paceKeySpec';
|
|
9
10
|
import { EID_CONSTANTS } from '../constants/eidConstants';
|
|
@@ -26,6 +27,60 @@ import { ec as EC } from 'elliptic';
|
|
|
26
27
|
const _hash = require('hash.js') as any;
|
|
27
28
|
const PresetCurve = _elliptic.curves.PresetCurve;
|
|
28
29
|
|
|
30
|
+
// brainpoolP192r1 (RFC 5639 §3.1) — PACE standardized domain parameter ID 9.
|
|
31
|
+
if (!_elliptic.curves.brainpoolP192r1) {
|
|
32
|
+
_elliptic.curves.brainpoolP192r1 = new PresetCurve({
|
|
33
|
+
type: 'short',
|
|
34
|
+
prime: null,
|
|
35
|
+
p: 'c302f41d932a36cda7a3463093d18db78fce476de1a86297',
|
|
36
|
+
a: '6a91174076b1e0e19c39c031fe8685c1cae040e5c69a28ef',
|
|
37
|
+
b: '469a28ef7c28cca3dc721d044f4496bcca7ef4146fbf25c9',
|
|
38
|
+
n: 'c302f41d932a36cda7a3462f9e9e916b5be8f1029ac4acc1',
|
|
39
|
+
hash: _hash.sha256,
|
|
40
|
+
gRed: false,
|
|
41
|
+
g: [
|
|
42
|
+
'c0a0647eaab6a48753b033c56cb0f0900a2f5c4853375fd6',
|
|
43
|
+
'14b690866abd5bb88b5f4828c1490002e6773fa2fa299b8f',
|
|
44
|
+
],
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// brainpoolP224r1 (RFC 5639 §3.2) — PACE standardized domain parameter ID 11.
|
|
49
|
+
if (!_elliptic.curves.brainpoolP224r1) {
|
|
50
|
+
_elliptic.curves.brainpoolP224r1 = new PresetCurve({
|
|
51
|
+
type: 'short',
|
|
52
|
+
prime: null,
|
|
53
|
+
p: 'd7c134aa264366862a18302575d1d787b09f075797da89f57ec8c0ff',
|
|
54
|
+
a: '68a5e62ca9ce6c1c299803a6c1530b514e182ad8b0042a59cad29f43',
|
|
55
|
+
b: '2580f63ccfe44138870713b1a92369e33e2135d266dbb372386c400b',
|
|
56
|
+
n: 'd7c134aa264366862a18302575d0fb98d116bc4b6ddebca3a5a7939f',
|
|
57
|
+
hash: _hash.sha256,
|
|
58
|
+
gRed: false,
|
|
59
|
+
g: [
|
|
60
|
+
'0d9029ad2c7e5cf4340823b2a87dc68c9e4ce3174c1e6efdee12c07d',
|
|
61
|
+
'58aa56f772c0726f24c6b89e4ecdac24354b9e99caa3f6d3761402cd',
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// brainpoolP320r1 (RFC 5639 §3.4) — PACE standardized domain parameter ID 14.
|
|
67
|
+
if (!_elliptic.curves.brainpoolP320r1) {
|
|
68
|
+
_elliptic.curves.brainpoolP320r1 = new PresetCurve({
|
|
69
|
+
type: 'short',
|
|
70
|
+
prime: null,
|
|
71
|
+
p: 'd35e472036bc4fb7e13c785ed201e065f98fcfa6f6f40def4f92b9ec7893ec28fcd412b1f1b32e27',
|
|
72
|
+
a: '3ee30b568fbab0f883ccebd46d3f3bb8a2a73513f5eb79da66190eb085ffa9f492f375a97d860eb4',
|
|
73
|
+
b: '520883949dfdbc42d3ad198640688a6fe13f41349554b49acc31dccd884539816f5eb4ac8fb1f1a6',
|
|
74
|
+
n: 'd35e472036bc4fb7e13c785ed201e065f98fcfa5b68f12a32d482ec7ee8658e98691555b44c59311',
|
|
75
|
+
hash: _hash.sha384,
|
|
76
|
+
gRed: false,
|
|
77
|
+
g: [
|
|
78
|
+
'43bd7e9afb53d8b85289bcc48ee5bfe6f20137d10a087eb6e7871e2a10a599c710af8d0d39e20611',
|
|
79
|
+
'14fdd05545ec1cc8ab4093247f77275e0743ffed117182eaa9c77877aaac6ac7d35245d1692e8ee1',
|
|
80
|
+
],
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
29
84
|
if (!_elliptic.curves.brainpoolP256r1) {
|
|
30
85
|
_elliptic.curves.brainpoolP256r1 = new PresetCurve({
|
|
31
86
|
type: 'short',
|
|
@@ -130,12 +185,19 @@ export class PACEProtocol {
|
|
|
130
185
|
const keyLength = PACEInfo.toKeyLength(oid);
|
|
131
186
|
|
|
132
187
|
if (agreementAlg !== 'ECDH') {
|
|
133
|
-
|
|
134
|
-
|
|
188
|
+
// DH-based PACE is rare in modern documents; surface it as a typed
|
|
189
|
+
// capability gap so the caller falls back to BAC with a precise reason.
|
|
190
|
+
throw new PACEUnsupportedError(
|
|
191
|
+
'agreement',
|
|
192
|
+
`key agreement ${agreementAlg} (only ECDH implemented)`
|
|
135
193
|
);
|
|
136
194
|
}
|
|
137
195
|
if (mappingType !== 'GM' && mappingType !== 'IM') {
|
|
138
|
-
|
|
196
|
+
// CAM (Chip Authentication Mapping) is not implemented.
|
|
197
|
+
throw new PACEUnsupportedError(
|
|
198
|
+
'mapping',
|
|
199
|
+
`mapping type ${mappingType} (only GM/IM implemented)`
|
|
200
|
+
);
|
|
139
201
|
}
|
|
140
202
|
|
|
141
203
|
// Derive static PACE key K_pi from the access key
|
|
@@ -408,8 +470,9 @@ export class PACEProtocol {
|
|
|
408
470
|
ephemeralParams: { generatorX: string; generatorY: string; curve: string };
|
|
409
471
|
}> {
|
|
410
472
|
if (cipherAlg !== 'AES') {
|
|
411
|
-
throw new
|
|
412
|
-
|
|
473
|
+
throw new PACEUnsupportedError(
|
|
474
|
+
'cipher',
|
|
475
|
+
`IM mapping requires AES, found ${cipherAlg}`
|
|
413
476
|
);
|
|
414
477
|
}
|
|
415
478
|
|
|
@@ -940,7 +1003,10 @@ export class PACEProtocol {
|
|
|
940
1003
|
case 18:
|
|
941
1004
|
return 'p521'; // NIST P-521
|
|
942
1005
|
default:
|
|
943
|
-
throw new
|
|
1006
|
+
throw new PACEUnsupportedError(
|
|
1007
|
+
'curve',
|
|
1008
|
+
`domain parameter ID ${parameterId}`
|
|
1009
|
+
);
|
|
944
1010
|
}
|
|
945
1011
|
}
|
|
946
1012
|
}
|
|
@@ -158,11 +158,14 @@ export class ReadBinaryAPDUSender implements APDULevelReadBinaryCapable {
|
|
|
158
158
|
commandAPDU
|
|
159
159
|
);
|
|
160
160
|
} catch (error) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
161
|
+
// A transient transceive failure (iOS RF drop during a large DG2 read)
|
|
162
|
+
// used to be swallowed here, leaving responseAPDU undefined — which then
|
|
163
|
+
// crashed downstream as a misleading "Could not read file" that the retry
|
|
164
|
+
// layer couldn't recognise. Rethrow so the block-read retry/backoff in
|
|
165
|
+
// CardFileInputStream can re-issue the SAME block (idempotent), and the
|
|
166
|
+
// file system can downgrade the read size if needed.
|
|
165
167
|
console.debug('Exception during READ BINARY', error);
|
|
168
|
+
throw error;
|
|
166
169
|
}
|
|
167
170
|
|
|
168
171
|
const responseData = ReadBinaryAPDUSender.getResponseData(
|
|
@@ -5,6 +5,13 @@ const COUNTRY_NAME_OVERRIDES: Record<string, string> = {
|
|
|
5
5
|
TUR: 'Türkiye',
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
+
// ICAO/MRZ issuing-state codes that are not ISO-3166 alpha-3 and must be mapped
|
|
9
|
+
// before lookup. "D" is Germany's historical 1-letter MRZ code (ICAO 9303
|
|
10
|
+
// Part 3 §C), surfaced filler-padded as "D<<" by the chip getters.
|
|
11
|
+
const MRZ_CODE_ALIASES: Record<string, string> = {
|
|
12
|
+
D: 'DEU',
|
|
13
|
+
};
|
|
14
|
+
|
|
8
15
|
const findCountryByAlpha3 = (alpha3Code: string) => {
|
|
9
16
|
return [...UnicodeCountry.VALUES, ...ISOCountry.VALUES].find(
|
|
10
17
|
(country) => country.toAlpha3Code() === alpha3Code
|
|
@@ -17,7 +24,11 @@ export const getLocalizedCountryName = (
|
|
|
17
24
|
): string => {
|
|
18
25
|
if (!alpha3Code) return '';
|
|
19
26
|
|
|
20
|
-
|
|
27
|
+
// Strip MRZ filler (the chip pads short codes, e.g. German "D" → "D<<") and
|
|
28
|
+
// map non-ISO MRZ codes to their alpha-3 before lookup.
|
|
29
|
+
const stripped = alpha3Code.replace(/</g, '').trim().toUpperCase();
|
|
30
|
+
if (!stripped) return '';
|
|
31
|
+
const normalizedCode = MRZ_CODE_ALIASES[stripped] ?? stripped;
|
|
21
32
|
const overrideName = COUNTRY_NAME_OVERRIDES[normalizedCode];
|
|
22
33
|
|
|
23
34
|
if (overrideName) {
|
|
@@ -31,6 +31,30 @@ const icaoCheckDigit = (str: string): string => {
|
|
|
31
31
|
return String(sum);
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Reportable NFC error code, e.g. `NFC-AUTH-6982`. MUST match the code shown to
|
|
36
|
+
* the user by EIDScanner (built in eidReader.buildNfcErrorCode) so a user who
|
|
37
|
+
* quotes "NFC-AUTH-6982" can be matched verbatim against their diagnostics.json.
|
|
38
|
+
* Local copy of the category→prefix map (eidReader pulls in native NFC deps).
|
|
39
|
+
*/
|
|
40
|
+
const NFC_CATEGORY_CODE: Record<string, string> = {
|
|
41
|
+
user_cancelled: 'CANCEL',
|
|
42
|
+
tag_lost: 'TAGLOST',
|
|
43
|
+
timeout: 'TIMEOUT',
|
|
44
|
+
unsupported: 'UNSUPPORTED',
|
|
45
|
+
not_enabled: 'DISABLED',
|
|
46
|
+
auth_failed: 'AUTH',
|
|
47
|
+
reading_error: 'READ',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const nfcErrorCode = (
|
|
51
|
+
category: string | undefined,
|
|
52
|
+
statusWord: string | undefined
|
|
53
|
+
): string => {
|
|
54
|
+
const part = NFC_CATEGORY_CODE[category ?? ''] ?? 'READ';
|
|
55
|
+
return statusWord ? `NFC-${part}-${statusWord}` : `NFC-${part}`;
|
|
56
|
+
};
|
|
57
|
+
|
|
34
58
|
export interface ScanDataForReport {
|
|
35
59
|
documentType?: string;
|
|
36
60
|
dataSource?: string;
|
|
@@ -166,9 +190,16 @@ export const buildDiagnosticReport = (params: {
|
|
|
166
190
|
|
|
167
191
|
// --- compact email body (always under MAX_BODY_BYTES) ---
|
|
168
192
|
const nfc = diag.nfc;
|
|
193
|
+
// Status word of the failing step (if any), used to build the reportable code.
|
|
194
|
+
const failingSw = nfc.failureStep
|
|
195
|
+
? nfc.steps.find((s) => s.step === nfc.failureStep)?.sw
|
|
196
|
+
: undefined;
|
|
197
|
+
const nfcCode = nfcErrorCode(nfc.errorCategory, failingSw);
|
|
169
198
|
const nfcLine = nfc.attempted
|
|
170
199
|
? `${nfc.authProtocol}${nfc.paceFellBackToBac ? '→BAC' : ''} · ${
|
|
171
|
-
nfc.succeeded
|
|
200
|
+
nfc.succeeded
|
|
201
|
+
? 'success'
|
|
202
|
+
: `failed at ${nfc.failureStep ?? '?'} (${nfc.errorCategory ?? 'error'}) [${nfcCode}]`
|
|
172
203
|
}`
|
|
173
204
|
: 'not attempted';
|
|
174
205
|
const checksLine = checkDigits
|
|
@@ -40,7 +40,9 @@ export interface NfcDiagnostics {
|
|
|
40
40
|
/** PACE object identifier string when PACE was attempted. */
|
|
41
41
|
paceOid?: string;
|
|
42
42
|
/** Why PACE wasn't used / fell back: 'no_card_access' | 'no_pace_info' |
|
|
43
|
-
* 'pace_failed'
|
|
43
|
+
* 'pace_failed' | 'pace_unsupported_<agreement|mapping|curve|cipher>'.
|
|
44
|
+
* The pace_unsupported_* reasons mark a CAPABILITY gap (this build can't run
|
|
45
|
+
* the variant the chip advertises) vs pace_failed (a runtime failure). */
|
|
44
46
|
paceFallbackReason?: string;
|
|
45
47
|
steps: NfcStep[];
|
|
46
48
|
/** Name of the first failing step, if any. */
|
|
@@ -175,10 +177,8 @@ export class DiagnosticsCollector {
|
|
|
175
177
|
setMrz(m: Partial<MrzDiagnostics>): void {
|
|
176
178
|
const reachedStable = this.mrz.reachedStable || m.reachedStable === true;
|
|
177
179
|
const maxMrzBandHeightPx =
|
|
178
|
-
Math.max(
|
|
179
|
-
|
|
180
|
-
m.maxMrzBandHeightPx ?? 0
|
|
181
|
-
) || undefined;
|
|
180
|
+
Math.max(this.mrz.maxMrzBandHeightPx ?? 0, m.maxMrzBandHeightPx ?? 0) ||
|
|
181
|
+
undefined;
|
|
182
182
|
this.mrz = { ...this.mrz, ...m, reachedStable, maxMrzBandHeightPx };
|
|
183
183
|
}
|
|
184
184
|
|
|
@@ -186,7 +186,16 @@ export class DiagnosticsCollector {
|
|
|
186
186
|
|
|
187
187
|
nfcAttemptStarted(): void {
|
|
188
188
|
// A fresh attempt: bump retry count if a previous attempt left steps.
|
|
189
|
-
if (this.nfc.attempted)
|
|
189
|
+
if (this.nfc.attempted) {
|
|
190
|
+
this.nfc.retryCount += 1;
|
|
191
|
+
// A retry supersedes the prior attempt: that attempt's failure is stale,
|
|
192
|
+
// so clear it. The failure markers then reflect only the CURRENT attempt —
|
|
193
|
+
// a within-attempt failure (e.g. PACE failing before a BAC fallback in the
|
|
194
|
+
// same read) is retained, while a failure that a later retry recovered is
|
|
195
|
+
// not reported as the outcome.
|
|
196
|
+
this.nfc.failureStep = undefined;
|
|
197
|
+
this.nfc.errorCategory = undefined;
|
|
198
|
+
}
|
|
190
199
|
this.nfc.attempted = true;
|
|
191
200
|
}
|
|
192
201
|
|
|
@@ -214,15 +223,28 @@ export class DiagnosticsCollector {
|
|
|
214
223
|
}
|
|
215
224
|
}
|
|
216
225
|
|
|
226
|
+
/** The first NFC step that failed in the current attempt (e.g. 'paceAuth',
|
|
227
|
+
* 'readDG2'), or undefined. Lets the caller build a step-specific error code
|
|
228
|
+
* without taking a full snapshot. */
|
|
229
|
+
getFailureStep(): string | undefined {
|
|
230
|
+
return this.nfc.failureStep;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** APDU status word recorded for the failing step, if any (e.g. '6982'). */
|
|
234
|
+
getFailureStatusWord(): string | undefined {
|
|
235
|
+
const fs = this.nfc.failureStep;
|
|
236
|
+
if (!fs) return undefined;
|
|
237
|
+
return this.nfc.steps.find((s) => s.step === fs && !s.ok)?.sw;
|
|
238
|
+
}
|
|
239
|
+
|
|
217
240
|
nfcResult(succeeded: boolean, errorCategory?: string): void {
|
|
218
241
|
this.nfc.succeeded = succeeded;
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
} else if (errorCategory) {
|
|
242
|
+
// Note: a failure recovered by a RETRY is already cleared in
|
|
243
|
+
// nfcAttemptStarted (the retry supersedes it). We deliberately do NOT clear
|
|
244
|
+
// here on success, so a within-attempt failure that a fallback recovered
|
|
245
|
+
// (e.g. PACE failing before BAC succeeds in the same read) stays visible in
|
|
246
|
+
// diagnostics — that is a meaningful signal, not the overall outcome.
|
|
247
|
+
if (!succeeded && errorCategory) {
|
|
226
248
|
this.nfc.errorCategory = errorCategory;
|
|
227
249
|
}
|
|
228
250
|
}
|
|
@@ -238,7 +260,9 @@ export class DiagnosticsCollector {
|
|
|
238
260
|
generatedAt: isoNow,
|
|
239
261
|
documentType: this.documentType,
|
|
240
262
|
dataSource: this.dataSource,
|
|
241
|
-
totalDurationMs: this.startedAtMs
|
|
263
|
+
totalDurationMs: this.startedAtMs
|
|
264
|
+
? Math.max(0, nowMs - this.startedAtMs)
|
|
265
|
+
: 0,
|
|
242
266
|
camera: { ...this.camera },
|
|
243
267
|
mrz: { ...this.mrz },
|
|
244
268
|
nfc: { ...this.nfc, steps: this.nfc.steps.map((s) => ({ ...s })) },
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { NativeModules, Platform } from 'react-native';
|
|
2
|
+
import { Buffer } from 'buffer';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Native JPEG2000 decoder bridge.
|
|
6
|
+
*
|
|
7
|
+
* The passport chip portrait (DG2) is frequently stored as JPEG2000
|
|
8
|
+
* (image/jp2). React Native's <Image> renders a JP2 data URI on Android (its
|
|
9
|
+
* Fresco/Skia pipeline decodes it) but NOT on iOS (UIImage-backed <Image>
|
|
10
|
+
* refuses the data URI), so the chip photo showed as a placeholder on iOS.
|
|
11
|
+
*
|
|
12
|
+
* iOS's ImageIO *can* decode JPEG2000, so the native `ImageDecoderModule`
|
|
13
|
+
* round-trips the JP2 to JPEG. We only need this on iOS; on Android the raw
|
|
14
|
+
* JP2 already renders, so there is no native counterpart and we no-op.
|
|
15
|
+
*/
|
|
16
|
+
interface ImageDecoderNativeModule {
|
|
17
|
+
decodeJp2ToJpeg(base64Jp2: string): Promise<string>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const ImageDecoder = (
|
|
21
|
+
NativeModules as { ImageDecoderModule?: ImageDecoderNativeModule }
|
|
22
|
+
).ImageDecoderModule;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Decode a JPEG2000 buffer to JPEG using the native iOS decoder.
|
|
26
|
+
*
|
|
27
|
+
* Returns the JPEG bytes + mime type on success, or null when native decode is
|
|
28
|
+
* unavailable (Android, or the module isn't linked) or fails — callers should
|
|
29
|
+
* fall back to their existing behaviour (keep raw JP2).
|
|
30
|
+
*/
|
|
31
|
+
export async function decodeJp2ToJpeg(
|
|
32
|
+
jp2Buffer: Buffer
|
|
33
|
+
): Promise<{ base64: string; mimeType: string } | null> {
|
|
34
|
+
if (Platform.OS !== 'ios' || !ImageDecoder?.decodeJp2ToJpeg) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const jpegBase64 = await ImageDecoder.decodeJp2ToJpeg(
|
|
39
|
+
jp2Buffer.toString('base64')
|
|
40
|
+
);
|
|
41
|
+
if (!jpegBase64) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return { base64: jpegBase64, mimeType: 'image/jpeg' };
|
|
45
|
+
} catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -32,6 +32,21 @@ const normalizeDocumentCode = (
|
|
|
32
32
|
return 'I';
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Strip MRZ filler characters from a human-readable text field. In the MRZ a
|
|
37
|
+
* single `<` separates words and `<<` separates components; the `mrz` package
|
|
38
|
+
* usually trims trailing fillers but can leave embedded `<`/`<<` in name and
|
|
39
|
+
* optional-data fields, which then surfaced raw in the UI (e.g.
|
|
40
|
+
* "ANNA<<MARIA"). Convert any filler run to a single space and trim, so the
|
|
41
|
+
* displayed value reads "ANNA MARIA". Returns null for empty/filler-only input.
|
|
42
|
+
* Only for text fields — never call on dates, sex, codes, or check digits.
|
|
43
|
+
*/
|
|
44
|
+
const cleanMRZTextField = (value: string | null | undefined): string | null => {
|
|
45
|
+
if (!value) return null;
|
|
46
|
+
const cleaned = value.replace(/</g, ' ').replace(/\s+/g, ' ').trim();
|
|
47
|
+
return cleaned.length > 0 ? cleaned : null;
|
|
48
|
+
};
|
|
49
|
+
|
|
35
50
|
/**
|
|
36
51
|
* Pads a TD1 line to the fixed 30-char width.
|
|
37
52
|
*
|
|
@@ -821,7 +836,11 @@ const linesFromParseRanges = (
|
|
|
821
836
|
for (const range of detail.ranges ?? []) {
|
|
822
837
|
// `raw` (the actual characters at this span) exists at runtime but isn't in
|
|
823
838
|
// the `mrz` Range type.
|
|
824
|
-
const {
|
|
839
|
+
const {
|
|
840
|
+
line,
|
|
841
|
+
start,
|
|
842
|
+
raw = '',
|
|
843
|
+
} = range as typeof range & { raw?: string };
|
|
825
844
|
const buf = buffers[line];
|
|
826
845
|
if (!buf) continue;
|
|
827
846
|
for (let i = 0; i < raw.length && start + i < width; i++) {
|
|
@@ -1388,14 +1407,16 @@ const validateMRZ = (
|
|
|
1388
1407
|
issuingState: result.fields.issuingState || null,
|
|
1389
1408
|
documentNumber: result.fields.documentNumber || null,
|
|
1390
1409
|
nationality: result.fields.nationality || null,
|
|
1391
|
-
|
|
1392
|
-
|
|
1410
|
+
// Text fields can carry embedded MRZ filler (`<`/`<<`) — strip it so the
|
|
1411
|
+
// UI shows "ANNA MARIA", not "ANNA<<MARIA".
|
|
1412
|
+
lastName: cleanMRZTextField(result.fields.lastName),
|
|
1413
|
+
firstName: cleanMRZTextField(result.fields.firstName),
|
|
1393
1414
|
sex: result.fields.sex || null,
|
|
1394
1415
|
birthDate: result.fields.birthDate || null,
|
|
1395
1416
|
expirationDate: result.fields.expirationDate || null,
|
|
1396
|
-
personalNumber: result.fields.personalNumber
|
|
1397
|
-
optional1: result.fields.optional1
|
|
1398
|
-
optional2: result.fields.optional2
|
|
1417
|
+
personalNumber: cleanMRZTextField(result.fields.personalNumber),
|
|
1418
|
+
optional1: cleanMRZTextField(result.fields.optional1),
|
|
1419
|
+
optional2: cleanMRZTextField(result.fields.optional2),
|
|
1399
1420
|
};
|
|
1400
1421
|
|
|
1401
1422
|
return {
|
|
@@ -94,12 +94,25 @@ export function buildDocumentName(
|
|
|
94
94
|
dg11First?: string | null,
|
|
95
95
|
dg11Last?: string | null
|
|
96
96
|
): DocumentName {
|
|
97
|
-
|
|
97
|
+
// Prefer DG11 (the chip's printed name in UTF-8) ONLY when it carries a proper
|
|
98
|
+
// two-part split — both a surname AND a given name. That is the authoritative
|
|
99
|
+
// correction for chips whose DG1 MRZ name lacks a `<<` separator (e.g. Turkish
|
|
100
|
+
// PACE passports), where the raw MRZ would otherwise put the full name into
|
|
101
|
+
// the surname.
|
|
102
|
+
//
|
|
103
|
+
// A one-sided DG11 result (only surname, or only given name) is NOT reliable —
|
|
104
|
+
// it usually means DG11 had no clear separator, so we don't know which part it
|
|
105
|
+
// is. Back-filling the missing side from the raw MRZ caused the given name to
|
|
106
|
+
// be duplicated into both fields, so we now fall through to the MRZ-based
|
|
107
|
+
// split instead, which is more trustworthy than mixing the two sources.
|
|
108
|
+
const hasFirst = (dg11First ?? '') !== '';
|
|
109
|
+
const hasLast = (dg11Last ?? '') !== '';
|
|
110
|
+
if (hasFirst && hasLast) {
|
|
98
111
|
return {
|
|
99
112
|
rawFirst,
|
|
100
113
|
rawLast,
|
|
101
|
-
displayFirst: dg11First,
|
|
102
|
-
displayLast: dg11Last,
|
|
114
|
+
displayFirst: dg11First as string,
|
|
115
|
+
displayLast: dg11Last as string,
|
|
103
116
|
source: 'dg11',
|
|
104
117
|
};
|
|
105
118
|
}
|