@trustchex/react-native-sdk 1.488.0 → 1.490.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 (50) hide show
  1. package/ios/ImageDecoder/ImageDecoderModule.m +12 -0
  2. package/ios/ImageDecoder/ImageDecoderModule.swift +43 -0
  3. package/lib/module/Screens/Static/ResultScreen.js +1 -0
  4. package/lib/module/Shared/Components/DiagnosticReportButton.js +16 -14
  5. package/lib/module/Shared/Components/EIDScanner.js +5 -1
  6. package/lib/module/Shared/Components/IdentityDocumentCamera.flows.js +22 -2
  7. package/lib/module/Shared/Components/IdentityDocumentCamera.js +1 -1
  8. package/lib/module/Shared/Components/IdentityDocumentCamera.utils.js +7 -7
  9. package/lib/module/Shared/EIDReader/eidReader.js +15 -3
  10. package/lib/module/Shared/Libs/diagnosticAuth.js +36 -0
  11. package/lib/module/Shared/Libs/jp2Decode.js +43 -0
  12. package/lib/module/Shared/Libs/sendDiagnosticReport.js +83 -103
  13. package/lib/module/Translation/Resources/en.js +6 -7
  14. package/lib/module/Translation/Resources/tr.js +6 -7
  15. package/lib/module/version.js +1 -1
  16. package/lib/typescript/src/Screens/Static/ResultScreen.d.ts.map +1 -1
  17. package/lib/typescript/src/Shared/Components/DiagnosticReportButton.d.ts +9 -6
  18. package/lib/typescript/src/Shared/Components/DiagnosticReportButton.d.ts.map +1 -1
  19. package/lib/typescript/src/Shared/Components/EIDScanner.d.ts.map +1 -1
  20. package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.d.ts.map +1 -1
  21. package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.flows.d.ts +11 -0
  22. package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.flows.d.ts.map +1 -1
  23. package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.utils.d.ts +1 -1
  24. package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.utils.d.ts.map +1 -1
  25. package/lib/typescript/src/Shared/EIDReader/eidReader.d.ts.map +1 -1
  26. package/lib/typescript/src/Shared/Libs/diagnosticAuth.d.ts +8 -0
  27. package/lib/typescript/src/Shared/Libs/diagnosticAuth.d.ts.map +1 -0
  28. package/lib/typescript/src/Shared/Libs/jp2Decode.d.ts +13 -0
  29. package/lib/typescript/src/Shared/Libs/jp2Decode.d.ts.map +1 -0
  30. package/lib/typescript/src/Shared/Libs/sendDiagnosticReport.d.ts +26 -10
  31. package/lib/typescript/src/Shared/Libs/sendDiagnosticReport.d.ts.map +1 -1
  32. package/lib/typescript/src/Translation/Resources/en.d.ts +4 -5
  33. package/lib/typescript/src/Translation/Resources/en.d.ts.map +1 -1
  34. package/lib/typescript/src/Translation/Resources/tr.d.ts +4 -5
  35. package/lib/typescript/src/Translation/Resources/tr.d.ts.map +1 -1
  36. package/lib/typescript/src/version.d.ts +1 -1
  37. package/package.json +1 -5
  38. package/src/Screens/Static/ResultScreen.tsx +1 -0
  39. package/src/Shared/Components/DiagnosticReportButton.tsx +23 -14
  40. package/src/Shared/Components/EIDScanner.tsx +5 -1
  41. package/src/Shared/Components/IdentityDocumentCamera.flows.ts +22 -2
  42. package/src/Shared/Components/IdentityDocumentCamera.tsx +1 -2
  43. package/src/Shared/Components/IdentityDocumentCamera.utils.ts +6 -8
  44. package/src/Shared/EIDReader/eidReader.ts +19 -4
  45. package/src/Shared/Libs/diagnosticAuth.ts +47 -0
  46. package/src/Shared/Libs/jp2Decode.ts +48 -0
  47. package/src/Shared/Libs/sendDiagnosticReport.ts +91 -118
  48. package/src/Translation/Resources/en.ts +6 -9
  49. package/src/Translation/Resources/tr.ts +6 -9
  50. package/src/version.ts +1 -1
@@ -1,58 +1,30 @@
1
1
  /**
2
- * Assembles and shares the support diagnostic report.
2
+ * Assembles and uploads the support diagnostic report to the backend.
3
3
  *
4
- * `react-native-share` is an OPTIONAL dependency: the host app opts into the
5
- * diagnostic feature by installing it. When it's present we open the OS share
6
- * sheet with the full report (the user picks email / WhatsApp / Drive / etc. and
7
- * reviews before sending); when it's absent the feature is silently unavailable
8
- * `isDiagnosticSharingAvailable()` returns false and the result-screen button
9
- * renders nothing, so apps that don't want it incur no dependency.
4
+ * This runs from the SDK's DEMO flow only, which is simulated client-side and
5
+ * has no real verification session or account — so there's no session key to
6
+ * encrypt with and nothing to authenticate against. The report is POSTed
7
+ * unauthenticated to the global demo-diagnostics endpoint over HTTPS (encrypted
8
+ * in transit); the backend encrypts the PII fields at rest. Internal developers
9
+ * view and download the reports from a hidden dashboard page.
10
10
  *
11
- * Attached files (staged to a temp dir via react-native-fs, already an SDK dep):
12
- * - `diagnostics.json` technical signals (device, camera, MRZ, NFC steps),
13
- * - `scan-data.json` — the scanned identity data (PII; user reviews it),
14
- * - the captured document/face images.
15
- *
16
- * The readable summary rides as the share `message` so it's visible in the
17
- * draft regardless of the chosen app.
11
+ * Uploaded payload (one JSON body):
12
+ * - non-PII technical metadata (platform, sdkVersion, documentType,
13
+ * nfcErrorCode, paceFallbackReason, succeeded) for the list/filter,
14
+ * - `diagnosticsJson` technical signals (device, camera, MRZ, NFC steps),
15
+ * - `scanDataJson` — the scanned identity data (PII),
16
+ * - `images` — the captured document/face images (base64, PII).
18
17
  */
19
- import RNFS from 'react-native-fs';
18
+ import 'react-native-get-random-values';
20
19
  import { diagnostics } from './diagnostics';
21
20
  import { gatherDeviceDetails } from './native-device-info.utils';
22
21
  import {
23
22
  buildDiagnosticReport,
24
23
  type ScanDataForReport,
25
24
  } from './diagnosticReport';
25
+ import { signDiagnosticBody } from './diagnosticAuth';
26
26
  import { logError } from './debug.utils';
27
27
 
28
- // `react-native-share` is OPTIONAL. Load it softly so the SDK bundles and runs
29
- // without it; only host apps that installed it get the diagnostic feature. A
30
- // static `import` would make Metro fail to resolve the module when it's absent,
31
- // so we use a guarded require and keep the reference typed loosely.
32
- type ShareModule = {
33
- open: (options: Record<string, unknown>) => Promise<unknown>;
34
- };
35
-
36
- let shareModule: ShareModule | null | undefined;
37
-
38
- const loadShare = (): ShareModule | null => {
39
- if (shareModule !== undefined) return shareModule;
40
- try {
41
- // eslint-disable-next-line @typescript-eslint/no-var-requires
42
- const mod = require('react-native-share');
43
- shareModule = (mod?.default ?? mod) as ShareModule;
44
- } catch {
45
- shareModule = null; // not installed — feature unavailable
46
- }
47
- return shareModule;
48
- };
49
-
50
- /**
51
- * Whether diagnostic sharing is available (i.e. `react-native-share` is
52
- * installed in the host app). The result-screen button hides itself when false.
53
- */
54
- export const isDiagnosticSharingAvailable = (): boolean => loadShare() != null;
55
-
56
28
  export interface DiagnosticImage {
57
29
  /** Stable file name without extension, e.g. "mrz-side". */
58
30
  name: string;
@@ -61,105 +33,106 @@ export interface DiagnosticImage {
61
33
  }
62
34
 
63
35
  export interface SendDiagnosticParams {
36
+ /** Backend base URL (same value the SDK was initialised with). */
37
+ baseUrl: string;
38
+ /** Demo session id (informational; the endpoint is unauthenticated). */
39
+ sessionId?: string;
64
40
  scan: ScanDataForReport;
65
41
  sdkVersion: string;
66
- sessionId?: string;
67
42
  /** base64 images to attach (MRZ side / front / face / NFC chip face). */
68
43
  images?: DiagnosticImage[];
69
44
  }
70
45
 
71
-
72
- const writeTemp = async (
73
- dir: string,
74
- name: string,
75
- data: string,
76
- encoding: 'utf8' | 'base64'
77
- ): Promise<string> => {
78
- const path = `${dir}/${name}`;
79
- await RNFS.writeFile(path, data, encoding);
80
- return path.startsWith('file://') ? path : `file://${path}`;
81
- };
82
-
83
46
  export interface SendResult {
84
- shared: boolean;
85
- /** True when the user dismissed the share sheet (not an error). */
86
- dismissed?: boolean;
47
+ /** True when the report was uploaded and stored. */
48
+ uploaded: boolean;
87
49
  }
88
50
 
51
+ const mimeToType = (mime: 'jpg' | 'png'): string =>
52
+ mime === 'png' ? 'image/png' : 'image/jpeg';
53
+
89
54
  /**
90
- * Build the report, stage attachments, and present the share sheet. Returns
91
- * { shared } — false on error, with `dismissed` set when the user cancelled.
55
+ * Build the report and upload it (over HTTPS) to the demo-diagnostics endpoint.
56
+ * Returns { uploaded } — false on any error (best-effort; a failed report must
57
+ * never disrupt the user's flow).
92
58
  */
93
59
  export const sendDiagnosticReport = async (
94
60
  params: SendDiagnosticParams
95
61
  ): Promise<SendResult> => {
96
- const share = loadShare();
97
- if (!share) {
98
- // Optional dependency not installed — nothing to do.
99
- return { shared: false };
62
+ const { baseUrl, sessionId, scan, sdkVersion, images = [] } = params;
63
+ if (!baseUrl) {
64
+ return { uploaded: false };
100
65
  }
101
- const { scan, sdkVersion, sessionId, images = [] } = params;
66
+
102
67
  const now = Date.now();
103
68
  const iso = new Date(now).toISOString();
104
69
 
105
- const device = await gatherDeviceDetails();
106
- const report = buildDiagnosticReport({
107
- diag: diagnostics.snapshot(now, iso),
108
- device,
109
- scan,
110
- sdkVersion,
111
- sessionId,
112
- });
113
-
114
- const dir = `${RNFS.TemporaryDirectoryPath}/trustchex-diagnostics-${now}`;
115
70
  try {
116
- await RNFS.mkdir(dir);
117
- const urls: string[] = [];
118
- urls.push(
119
- await writeTemp(dir, 'diagnostics.json', report.diagnosticsJson, 'utf8')
120
- );
121
- urls.push(
122
- await writeTemp(dir, 'scan-data.json', report.scanDataJson, 'utf8')
123
- );
124
- for (const img of images) {
125
- if (!img.base64) continue;
126
- urls.push(
127
- await writeTemp(dir, `${img.name}.${img.mime}`, img.base64, 'base64')
128
- );
129
- }
71
+ const device = await gatherDeviceDetails();
72
+ const snapshot = diagnostics.snapshot(now, iso);
73
+ const report = buildDiagnosticReport({
74
+ diag: snapshot,
75
+ device,
76
+ scan,
77
+ sdkVersion,
78
+ sessionId,
79
+ });
80
+
81
+ // Queryable, non-PII technical metadata for the dashboard list/filter.
82
+ const nfc = snapshot.nfc;
83
+ const failingSw = nfc.failureStep
84
+ ? nfc.steps.find((s) => s.step === nfc.failureStep && !s.ok)?.sw
85
+ : undefined;
86
+ const nfcErrorCode =
87
+ nfc.attempted && !nfc.succeeded
88
+ ? `NFC-${(nfc.errorCategory ?? 'reading_error').toUpperCase()}${failingSw ? `-${failingSw}` : ''}`
89
+ : null;
90
+
91
+ const payload = {
92
+ // metadata (stored in plaintext, no PII)
93
+ platform: device.platform,
94
+ osVersion: device.systemVersion,
95
+ sdkVersion,
96
+ documentType: scan.documentType ?? snapshot.documentType ?? null,
97
+ dataSource: scan.dataSource ?? snapshot.dataSource ?? null,
98
+ nfcErrorCode,
99
+ paceFallbackReason: nfc.paceFallbackReason ?? null,
100
+ succeeded: nfc.attempted ? nfc.succeeded : null,
101
+ // full report (PII, encrypted at rest by the backend)
102
+ diagnosticsJson: report.diagnosticsJson,
103
+ scanDataJson: report.scanDataJson,
104
+ images: images
105
+ .filter((img) => img.base64)
106
+ .map((img) => ({
107
+ name: img.name,
108
+ base64: img.base64,
109
+ mimeType: mimeToType(img.mime),
110
+ })),
111
+ };
112
+
113
+ // Sign the EXACT body bytes so the backend can verify authenticity. Use
114
+ // fetch directly (httpClient doesn't expose custom headers / raw body).
115
+ const rawBody = JSON.stringify(payload);
116
+ const { timestamp, nonce, signature } = signDiagnosticBody(rawBody);
117
+
118
+ const response = await fetch(`${baseUrl}/api/app/mobile/diagnostics`, {
119
+ method: 'POST',
120
+ headers: {
121
+ 'Content-Type': 'application/json',
122
+ 'X-Trustchex-Timestamp': timestamp,
123
+ 'X-Trustchex-Nonce': nonce,
124
+ 'X-Trustchex-Signature': signature,
125
+ },
126
+ body: rawBody,
127
+ });
130
128
 
131
- try {
132
- await share.open({
133
- title: report.subject,
134
- subject: report.subject, // used by email targets
135
- message: report.body,
136
- urls,
137
- // Per-file MIME types so targets render attachments correctly.
138
- filenames: urls.map((u) => u.split('/').pop() ?? 'attachment'),
139
- failOnCancel: false,
140
- });
141
- return { shared: true };
142
- } catch (shareErr) {
143
- // react-native-share throws on user cancel unless failOnCancel:false; treat
144
- // a cancel as a non-error dismissal.
145
- const msg =
146
- shareErr instanceof Error ? shareErr.message : String(shareErr);
147
- if (/cancel|dismiss|user did not share/i.test(msg)) {
148
- return { shared: false, dismissed: true };
149
- }
150
- throw shareErr;
151
- }
129
+ return { uploaded: response.ok };
152
130
  } catch (e) {
153
131
  logError(
154
132
  'Diagnostics',
155
- 'Failed to share diagnostic report',
133
+ 'Failed to upload diagnostic report',
156
134
  e instanceof Error ? e.message : String(e)
157
135
  );
158
- return { shared: false };
159
- } finally {
160
- // Best-effort cleanup — temp files are short-lived.
161
- setTimeout(() => {
162
- RNFS.unlink(dir).catch(() => {});
163
- }, 60_000);
136
+ return { uploaded: false };
164
137
  }
165
138
  };
@@ -54,18 +54,15 @@ export default {
54
54
  'resultScreen.demoVerbalConsentText': 'Text',
55
55
  'resultScreen.demoStartOver': 'Start Over',
56
56
  'diagnosticReport.button': 'Report a scanning issue',
57
- 'diagnosticReport.noticeTitle': 'Share diagnostic report',
57
+ 'diagnosticReport.noticeTitle': 'Report a scanning issue',
58
58
  'diagnosticReport.noticeBody':
59
- 'This opens a draft with your scan data, document images and technical details so support can help resolve a scanning issue. Review it before sending.',
59
+ 'This sends your scan data, document images and technical details to support so they can help resolve a scanning issue.',
60
60
  'diagnosticReport.continue': 'Continue',
61
61
  'diagnosticReport.cancel': 'Cancel',
62
- 'diagnosticReport.shareFailedTitle': "Couldn't open the share sheet",
63
- 'diagnosticReport.shareFailedBody':
64
- "We couldn't attach the report to share. Send it securely to support instead?",
65
- 'diagnosticReport.uploadAction': 'Send to support',
66
- 'diagnosticReport.uploadSuccess': 'Diagnostic report sent to support.',
67
- 'diagnosticReport.uploadFailed':
68
- "Couldn't send the report. Please try again later.",
62
+ 'diagnosticReport.sentTitle': 'Report sent',
63
+ 'diagnosticReport.sentBody': 'Your diagnostic report was sent to support. Thank you.',
64
+ 'diagnosticReport.failedTitle': "Couldn't send the report",
65
+ 'diagnosticReport.failedBody': 'Please try again later.',
69
66
  'livenessDetectionScreen.guideHeader': 'Face Verification',
70
67
  'livenessDetectionScreen.guideText':
71
68
  'Please ensure the following for best results:',
@@ -54,18 +54,15 @@ export default {
54
54
  'resultScreen.demoVerbalConsentText': 'Metin',
55
55
  'resultScreen.demoStartOver': 'Baştan Başla',
56
56
  'diagnosticReport.button': 'Tarama sorununu bildir',
57
- 'diagnosticReport.noticeTitle': 'Tanılama raporu paylaş',
57
+ 'diagnosticReport.noticeTitle': 'Tarama sorununu bildir',
58
58
  'diagnosticReport.noticeBody':
59
- 'Bu işlem; tarama verilerinizi, belge görüntülerinizi ve teknik ayrıntıları içeren bir taslak açar; böylece destek ekibi tarama sorununu çözebilir. Göndermeden önce gözden geçirin.',
59
+ 'Bu işlem; tarama verilerinizi, belge görüntülerinizi ve teknik ayrıntıları destek ekibine gönderir; böylece tarama sorununu çözebilirler.',
60
60
  'diagnosticReport.continue': 'Devam et',
61
61
  'diagnosticReport.cancel': 'İptal',
62
- 'diagnosticReport.shareFailedTitle': 'Paylaşım ekranı açılamadı',
63
- 'diagnosticReport.shareFailedBody':
64
- 'Raporu paylaşmak için ekleyemedik. Bunun yerine destek ekibine güvenli şekilde gönderelim mi?',
65
- 'diagnosticReport.uploadAction': 'Desteğe gönder',
66
- 'diagnosticReport.uploadSuccess': 'Tanılama raporu destek ekibine gönderildi.',
67
- 'diagnosticReport.uploadFailed':
68
- 'Rapor gönderilemedi. Lütfen daha sonra tekrar deneyin.',
62
+ 'diagnosticReport.sentTitle': 'Rapor gönderildi',
63
+ 'diagnosticReport.sentBody': 'Tanılama raporunuz destek ekibine gönderildi. Teşekkürler.',
64
+ 'diagnosticReport.failedTitle': 'Rapor gönderilemedi',
65
+ 'diagnosticReport.failedBody': 'Lütfen daha sonra tekrar deneyin.',
69
66
  'livenessDetectionScreen.guideHeader': 'Yüz Doğrulaması',
70
67
  'livenessDetectionScreen.guideText':
71
68
  'En iyi sonuç için lütfen şunları sağlayın:',
package/src/version.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  // This file is auto-generated. Do not edit manually.
2
2
  // Version is synced from package.json during build.
3
- export const SDK_VERSION = '1.488.0';
3
+ export const SDK_VERSION = '1.490.1';