@trustchex/react-native-sdk 1.355.1 → 1.357.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.
Files changed (254) hide show
  1. package/README.md +2 -9
  2. package/TrustchexSDK.podspec +5 -4
  3. package/android/build.gradle +6 -4
  4. package/android/src/main/AndroidManifest.xml +1 -1
  5. package/android/src/main/java/com/trustchex/reactnativesdk/TrustchexSDKPackage.kt +45 -25
  6. package/android/src/main/java/com/trustchex/reactnativesdk/camera/TrustchexCameraManager.kt +168 -0
  7. package/android/src/main/java/com/trustchex/reactnativesdk/camera/TrustchexCameraView.kt +871 -0
  8. package/android/src/main/java/com/trustchex/reactnativesdk/mlkit/MLKitModule.kt +245 -0
  9. package/android/src/main/java/com/trustchex/reactnativesdk/mrz/MRZValidationModule.kt +785 -0
  10. package/android/src/main/java/com/trustchex/reactnativesdk/mrz/MRZValidator.kt +419 -0
  11. package/android/src/main/java/com/trustchex/reactnativesdk/opencv/OpenCVModule.kt +818 -0
  12. package/ios/Camera/TrustchexCameraManager.m +37 -0
  13. package/ios/Camera/TrustchexCameraManager.swift +125 -0
  14. package/ios/Camera/TrustchexCameraView.swift +1176 -0
  15. package/ios/MLKit/MLKitModule.m +23 -0
  16. package/ios/MLKit/MLKitModule.swift +250 -0
  17. package/ios/MRZValidation.m +39 -0
  18. package/ios/MRZValidation.swift +802 -0
  19. package/ios/MRZValidator.swift +466 -0
  20. package/ios/OpenCV/OpenCVModule.h +4 -0
  21. package/ios/OpenCV/OpenCVModule.mm +810 -0
  22. package/lib/module/Screens/Dynamic/IdentityDocumentEIDScanningScreen.js +2 -3
  23. package/lib/module/Screens/Dynamic/IdentityDocumentScanningScreen.js +1 -2
  24. package/lib/module/Screens/Dynamic/LivenessDetectionScreen.js +418 -193
  25. package/lib/module/Screens/Static/OTPVerificationScreen.js +11 -11
  26. package/lib/module/Screens/Static/QrCodeScanningScreen.js +5 -1
  27. package/lib/module/Screens/Static/ResultScreen.js +25 -2
  28. package/lib/module/Screens/Static/VerificationSessionCheckScreen.js +25 -7
  29. package/lib/module/Shared/Components/DebugNavigationPanel.js +234 -24
  30. package/lib/module/Shared/Components/EIDScanner.js +99 -9
  31. package/lib/module/Shared/Components/FaceCamera.js +170 -179
  32. package/lib/module/Shared/Components/IdentityDocumentCamera.js +2151 -771
  33. package/lib/module/Shared/Components/QrCodeScannerCamera.js +109 -107
  34. package/lib/module/Shared/Components/TrustchexCamera.js +122 -0
  35. package/lib/module/Shared/EIDReader/tlv/tlv.helpers.js +91 -0
  36. package/lib/module/Shared/EIDReader/tlv/tlv.utils.js +2 -124
  37. package/lib/module/Shared/EIDReader/tlv/tlvInputStream.js +4 -4
  38. package/lib/module/Shared/EIDReader/tlv/tlvOutputState.js +4 -4
  39. package/lib/module/Shared/EIDReader/tlv/tlvOutputStream.js +4 -4
  40. package/lib/module/Shared/Libs/analytics.utils.js +2 -2
  41. package/lib/module/Shared/Libs/debug.utils.js +132 -0
  42. package/lib/module/Shared/Libs/deeplink.utils.js +6 -5
  43. package/lib/module/Shared/Libs/demo.utils.js +13 -3
  44. package/lib/module/Shared/Libs/mrz.utils.js +1 -175
  45. package/lib/module/Shared/Libs/native-device-info.utils.js +12 -6
  46. package/lib/module/Shared/Libs/tts.utils.js +40 -6
  47. package/lib/module/Shared/Services/AnalyticsService.js +9 -8
  48. package/lib/module/Shared/Types/mrzFields.js +1 -0
  49. package/lib/module/Translation/Resources/en.js +87 -88
  50. package/lib/module/Translation/Resources/tr.js +84 -85
  51. package/lib/module/Trustchex.js +9 -2
  52. package/lib/module/index.js +1 -0
  53. package/lib/module/version.js +1 -1
  54. package/lib/typescript/src/Screens/Dynamic/IdentityDocumentEIDScanningScreen.d.ts.map +1 -1
  55. package/lib/typescript/src/Screens/Dynamic/IdentityDocumentScanningScreen.d.ts.map +1 -1
  56. package/lib/typescript/src/Screens/Dynamic/LivenessDetectionScreen.d.ts.map +1 -1
  57. package/lib/typescript/src/Screens/Static/OTPVerificationScreen.d.ts.map +1 -1
  58. package/lib/typescript/src/Screens/Static/QrCodeScanningScreen.d.ts.map +1 -1
  59. package/lib/typescript/src/Screens/Static/ResultScreen.d.ts.map +1 -1
  60. package/lib/typescript/src/Screens/Static/VerificationSessionCheckScreen.d.ts.map +1 -1
  61. package/lib/typescript/src/Shared/Components/DebugNavigationPanel.d.ts.map +1 -1
  62. package/lib/typescript/src/Shared/Components/EIDScanner.d.ts +2 -2
  63. package/lib/typescript/src/Shared/Components/EIDScanner.d.ts.map +1 -1
  64. package/lib/typescript/src/Shared/Components/FaceCamera.d.ts +18 -4
  65. package/lib/typescript/src/Shared/Components/FaceCamera.d.ts.map +1 -1
  66. package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.d.ts +3 -4
  67. package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.d.ts.map +1 -1
  68. package/lib/typescript/src/Shared/Components/QrCodeScannerCamera.d.ts +2 -1
  69. package/lib/typescript/src/Shared/Components/QrCodeScannerCamera.d.ts.map +1 -1
  70. package/lib/typescript/src/Shared/Components/TrustchexCamera.d.ts +124 -0
  71. package/lib/typescript/src/Shared/Components/TrustchexCamera.d.ts.map +1 -0
  72. package/lib/typescript/src/Shared/EIDReader/tlv/tlv.helpers.d.ts +11 -0
  73. package/lib/typescript/src/Shared/EIDReader/tlv/tlv.helpers.d.ts.map +1 -0
  74. package/lib/typescript/src/Shared/EIDReader/tlv/tlv.utils.d.ts +2 -39
  75. package/lib/typescript/src/Shared/EIDReader/tlv/tlv.utils.d.ts.map +1 -1
  76. package/lib/typescript/src/Shared/Libs/analytics.utils.d.ts.map +1 -1
  77. package/lib/typescript/src/Shared/Libs/debug.utils.d.ts +42 -0
  78. package/lib/typescript/src/Shared/Libs/debug.utils.d.ts.map +1 -0
  79. package/lib/typescript/src/Shared/Libs/deeplink.utils.d.ts.map +1 -1
  80. package/lib/typescript/src/Shared/Libs/demo.utils.d.ts.map +1 -1
  81. package/lib/typescript/src/Shared/Libs/http-client.d.ts.map +1 -1
  82. package/lib/typescript/src/Shared/Libs/mrz.utils.d.ts +0 -4
  83. package/lib/typescript/src/Shared/Libs/mrz.utils.d.ts.map +1 -1
  84. package/lib/typescript/src/Shared/Libs/native-device-info.utils.d.ts.map +1 -1
  85. package/lib/typescript/src/Shared/Libs/tts.utils.d.ts +4 -3
  86. package/lib/typescript/src/Shared/Libs/tts.utils.d.ts.map +1 -1
  87. package/lib/typescript/src/Shared/Services/AnalyticsService.d.ts.map +1 -1
  88. package/lib/typescript/src/Shared/Types/identificationInfo.d.ts +2 -2
  89. package/lib/typescript/src/Shared/Types/identificationInfo.d.ts.map +1 -1
  90. package/lib/typescript/src/Shared/Types/mrzFields.d.ts +11 -0
  91. package/lib/typescript/src/Shared/Types/mrzFields.d.ts.map +1 -0
  92. package/lib/typescript/src/Translation/Resources/en.d.ts +4 -5
  93. package/lib/typescript/src/Translation/Resources/en.d.ts.map +1 -1
  94. package/lib/typescript/src/Translation/Resources/tr.d.ts +4 -5
  95. package/lib/typescript/src/Translation/Resources/tr.d.ts.map +1 -1
  96. package/lib/typescript/src/Trustchex.d.ts +2 -0
  97. package/lib/typescript/src/Trustchex.d.ts.map +1 -1
  98. package/lib/typescript/src/index.d.ts +1 -0
  99. package/lib/typescript/src/index.d.ts.map +1 -1
  100. package/lib/typescript/src/version.d.ts +1 -1
  101. package/package.json +4 -35
  102. package/src/Screens/Dynamic/ContractAcceptanceScreen.tsx +1 -1
  103. package/src/Screens/Dynamic/IdentityDocumentEIDScanningScreen.tsx +7 -5
  104. package/src/Screens/Dynamic/IdentityDocumentScanningScreen.tsx +2 -3
  105. package/src/Screens/Dynamic/LivenessDetectionScreen.tsx +498 -216
  106. package/src/Screens/Static/OTPVerificationScreen.tsx +37 -31
  107. package/src/Screens/Static/QrCodeScanningScreen.tsx +8 -1
  108. package/src/Screens/Static/ResultScreen.tsx +136 -88
  109. package/src/Screens/Static/VerificationSessionCheckScreen.tsx +46 -13
  110. package/src/Shared/Components/DebugNavigationPanel.tsx +290 -34
  111. package/src/Shared/Components/EIDScanner.tsx +94 -16
  112. package/src/Shared/Components/FaceCamera.tsx +236 -203
  113. package/src/Shared/Components/IdentityDocumentCamera.tsx +3073 -1030
  114. package/src/Shared/Components/QrCodeScannerCamera.tsx +133 -127
  115. package/src/Shared/Components/TrustchexCamera.tsx +289 -0
  116. package/src/Shared/Config/camera-enhancement.config.ts +2 -2
  117. package/src/Shared/EIDReader/tlv/tlv.helpers.ts +96 -0
  118. package/src/Shared/EIDReader/tlv/tlv.utils.ts +2 -125
  119. package/src/Shared/EIDReader/tlv/tlvInputStream.ts +4 -4
  120. package/src/Shared/EIDReader/tlv/tlvOutputState.ts +4 -4
  121. package/src/Shared/EIDReader/tlv/tlvOutputStream.ts +4 -4
  122. package/src/Shared/Libs/analytics.utils.ts +48 -20
  123. package/src/Shared/Libs/debug.utils.ts +149 -0
  124. package/src/Shared/Libs/deeplink.utils.ts +7 -5
  125. package/src/Shared/Libs/demo.utils.ts +4 -0
  126. package/src/Shared/Libs/http-client.ts +12 -8
  127. package/src/Shared/Libs/mrz.utils.ts +1 -163
  128. package/src/Shared/Libs/native-device-info.utils.ts +12 -6
  129. package/src/Shared/Libs/tts.utils.ts +48 -6
  130. package/src/Shared/Services/AnalyticsService.ts +69 -24
  131. package/src/Shared/Types/identificationInfo.ts +2 -2
  132. package/src/Shared/Types/mrzFields.ts +29 -0
  133. package/src/Translation/Resources/en.ts +90 -100
  134. package/src/Translation/Resources/tr.ts +89 -97
  135. package/src/Translation/index.ts +1 -1
  136. package/src/Trustchex.tsx +21 -4
  137. package/src/index.tsx +14 -0
  138. package/src/version.ts +1 -1
  139. package/android/src/main/java/com/trustchex/reactnativesdk/visioncameraplugins/barcodescanner/BarcodeScannerFrameProcessorPlugin.kt +0 -301
  140. package/android/src/main/java/com/trustchex/reactnativesdk/visioncameraplugins/cropper/BitmapUtils.kt +0 -205
  141. package/android/src/main/java/com/trustchex/reactnativesdk/visioncameraplugins/cropper/CropperPlugin.kt +0 -72
  142. package/android/src/main/java/com/trustchex/reactnativesdk/visioncameraplugins/cropper/FrameMetadata.kt +0 -4
  143. package/android/src/main/java/com/trustchex/reactnativesdk/visioncameraplugins/facedetector/FaceDetectorFrameProcessorPlugin.kt +0 -303
  144. package/android/src/main/java/com/trustchex/reactnativesdk/visioncameraplugins/textrecognition/TextRecognitionFrameProcessorPlugin.kt +0 -115
  145. package/ios/VisionCameraPlugins/BarcodeScanner/BarcodeScannerFrameProcessorPlugin-Bridging-Header.h +0 -9
  146. package/ios/VisionCameraPlugins/BarcodeScanner/BarcodeScannerFrameProcessorPlugin.mm +0 -22
  147. package/ios/VisionCameraPlugins/BarcodeScanner/BarcodeScannerFrameProcessorPlugin.swift +0 -188
  148. package/ios/VisionCameraPlugins/Cropper/Cropper-Bridging-Header.h +0 -13
  149. package/ios/VisionCameraPlugins/Cropper/Cropper.h +0 -20
  150. package/ios/VisionCameraPlugins/Cropper/Cropper.mm +0 -22
  151. package/ios/VisionCameraPlugins/Cropper/Cropper.swift +0 -145
  152. package/ios/VisionCameraPlugins/Cropper/CropperUtils.swift +0 -49
  153. package/ios/VisionCameraPlugins/FaceDetector/FaceDetectorFrameProcessorPlugin-Bridging-Header.h +0 -4
  154. package/ios/VisionCameraPlugins/FaceDetector/FaceDetectorFrameProcessorPlugin.mm +0 -22
  155. package/ios/VisionCameraPlugins/FaceDetector/FaceDetectorFrameProcessorPlugin.swift +0 -320
  156. package/ios/VisionCameraPlugins/TextRecognition/TextRecognitionFrameProcessorPlugin-Bridging-Header.h +0 -4
  157. package/ios/VisionCameraPlugins/TextRecognition/TextRecognitionFrameProcessorPlugin.mm +0 -27
  158. package/ios/VisionCameraPlugins/TextRecognition/TextRecognitionFrameProcessorPlugin.swift +0 -144
  159. package/lib/module/Shared/Libs/camera.utils.js +0 -308
  160. package/lib/module/Shared/Libs/frame-enhancement.utils.js +0 -133
  161. package/lib/module/Shared/Libs/opencv.utils.js +0 -21
  162. package/lib/module/Shared/Libs/worklet.utils.js +0 -68
  163. package/lib/module/Shared/VisionCameraPlugins/BarcodeScanner/hooks/useBarcodeScanner.js +0 -46
  164. package/lib/module/Shared/VisionCameraPlugins/BarcodeScanner/hooks/useCameraPermissions.js +0 -35
  165. package/lib/module/Shared/VisionCameraPlugins/BarcodeScanner/index.js +0 -19
  166. package/lib/module/Shared/VisionCameraPlugins/BarcodeScanner/scanCodes.js +0 -26
  167. package/lib/module/Shared/VisionCameraPlugins/BarcodeScanner/types.js +0 -3
  168. package/lib/module/Shared/VisionCameraPlugins/BarcodeScanner/utils/convert.js +0 -197
  169. package/lib/module/Shared/VisionCameraPlugins/BarcodeScanner/utils/geometry.js +0 -101
  170. package/lib/module/Shared/VisionCameraPlugins/BarcodeScanner/utils/highlights.js +0 -60
  171. package/lib/module/Shared/VisionCameraPlugins/Cropper/index.js +0 -47
  172. package/lib/module/Shared/VisionCameraPlugins/FaceDetector/Camera.js +0 -42
  173. package/lib/module/Shared/VisionCameraPlugins/FaceDetector/detectFaces.js +0 -35
  174. package/lib/module/Shared/VisionCameraPlugins/FaceDetector/index.js +0 -4
  175. package/lib/module/Shared/VisionCameraPlugins/FaceDetector/types.js +0 -3
  176. package/lib/module/Shared/VisionCameraPlugins/TextRecognition/Camera.js +0 -56
  177. package/lib/module/Shared/VisionCameraPlugins/TextRecognition/PhotoRecognizer.js +0 -20
  178. package/lib/module/Shared/VisionCameraPlugins/TextRecognition/RemoveLanguageModel.js +0 -9
  179. package/lib/module/Shared/VisionCameraPlugins/TextRecognition/index.js +0 -6
  180. package/lib/module/Shared/VisionCameraPlugins/TextRecognition/scanText.js +0 -20
  181. package/lib/module/Shared/VisionCameraPlugins/TextRecognition/translateText.js +0 -19
  182. package/lib/module/Shared/VisionCameraPlugins/TextRecognition/types.js +0 -3
  183. package/lib/typescript/src/Shared/Libs/camera.utils.d.ts +0 -87
  184. package/lib/typescript/src/Shared/Libs/camera.utils.d.ts.map +0 -1
  185. package/lib/typescript/src/Shared/Libs/frame-enhancement.utils.d.ts +0 -25
  186. package/lib/typescript/src/Shared/Libs/frame-enhancement.utils.d.ts.map +0 -1
  187. package/lib/typescript/src/Shared/Libs/opencv.utils.d.ts +0 -3
  188. package/lib/typescript/src/Shared/Libs/opencv.utils.d.ts.map +0 -1
  189. package/lib/typescript/src/Shared/Libs/worklet.utils.d.ts +0 -9
  190. package/lib/typescript/src/Shared/Libs/worklet.utils.d.ts.map +0 -1
  191. package/lib/typescript/src/Shared/VisionCameraPlugins/BarcodeScanner/hooks/useBarcodeScanner.d.ts +0 -13
  192. package/lib/typescript/src/Shared/VisionCameraPlugins/BarcodeScanner/hooks/useBarcodeScanner.d.ts.map +0 -1
  193. package/lib/typescript/src/Shared/VisionCameraPlugins/BarcodeScanner/hooks/useCameraPermissions.d.ts +0 -6
  194. package/lib/typescript/src/Shared/VisionCameraPlugins/BarcodeScanner/hooks/useCameraPermissions.d.ts.map +0 -1
  195. package/lib/typescript/src/Shared/VisionCameraPlugins/BarcodeScanner/index.d.ts +0 -12
  196. package/lib/typescript/src/Shared/VisionCameraPlugins/BarcodeScanner/index.d.ts.map +0 -1
  197. package/lib/typescript/src/Shared/VisionCameraPlugins/BarcodeScanner/scanCodes.d.ts +0 -3
  198. package/lib/typescript/src/Shared/VisionCameraPlugins/BarcodeScanner/scanCodes.d.ts.map +0 -1
  199. package/lib/typescript/src/Shared/VisionCameraPlugins/BarcodeScanner/types.d.ts +0 -52
  200. package/lib/typescript/src/Shared/VisionCameraPlugins/BarcodeScanner/types.d.ts.map +0 -1
  201. package/lib/typescript/src/Shared/VisionCameraPlugins/BarcodeScanner/utils/convert.d.ts +0 -62
  202. package/lib/typescript/src/Shared/VisionCameraPlugins/BarcodeScanner/utils/convert.d.ts.map +0 -1
  203. package/lib/typescript/src/Shared/VisionCameraPlugins/BarcodeScanner/utils/geometry.d.ts +0 -34
  204. package/lib/typescript/src/Shared/VisionCameraPlugins/BarcodeScanner/utils/geometry.d.ts.map +0 -1
  205. package/lib/typescript/src/Shared/VisionCameraPlugins/BarcodeScanner/utils/highlights.d.ts +0 -32
  206. package/lib/typescript/src/Shared/VisionCameraPlugins/BarcodeScanner/utils/highlights.d.ts.map +0 -1
  207. package/lib/typescript/src/Shared/VisionCameraPlugins/Cropper/index.d.ts +0 -23
  208. package/lib/typescript/src/Shared/VisionCameraPlugins/Cropper/index.d.ts.map +0 -1
  209. package/lib/typescript/src/Shared/VisionCameraPlugins/FaceDetector/Camera.d.ts +0 -9
  210. package/lib/typescript/src/Shared/VisionCameraPlugins/FaceDetector/Camera.d.ts.map +0 -1
  211. package/lib/typescript/src/Shared/VisionCameraPlugins/FaceDetector/detectFaces.d.ts +0 -3
  212. package/lib/typescript/src/Shared/VisionCameraPlugins/FaceDetector/detectFaces.d.ts.map +0 -1
  213. package/lib/typescript/src/Shared/VisionCameraPlugins/FaceDetector/index.d.ts +0 -3
  214. package/lib/typescript/src/Shared/VisionCameraPlugins/FaceDetector/index.d.ts.map +0 -1
  215. package/lib/typescript/src/Shared/VisionCameraPlugins/FaceDetector/types.d.ts +0 -79
  216. package/lib/typescript/src/Shared/VisionCameraPlugins/FaceDetector/types.d.ts.map +0 -1
  217. package/lib/typescript/src/Shared/VisionCameraPlugins/TextRecognition/Camera.d.ts +0 -6
  218. package/lib/typescript/src/Shared/VisionCameraPlugins/TextRecognition/Camera.d.ts.map +0 -1
  219. package/lib/typescript/src/Shared/VisionCameraPlugins/TextRecognition/PhotoRecognizer.d.ts +0 -3
  220. package/lib/typescript/src/Shared/VisionCameraPlugins/TextRecognition/PhotoRecognizer.d.ts.map +0 -1
  221. package/lib/typescript/src/Shared/VisionCameraPlugins/TextRecognition/RemoveLanguageModel.d.ts +0 -3
  222. package/lib/typescript/src/Shared/VisionCameraPlugins/TextRecognition/RemoveLanguageModel.d.ts.map +0 -1
  223. package/lib/typescript/src/Shared/VisionCameraPlugins/TextRecognition/index.d.ts +0 -5
  224. package/lib/typescript/src/Shared/VisionCameraPlugins/TextRecognition/index.d.ts.map +0 -1
  225. package/lib/typescript/src/Shared/VisionCameraPlugins/TextRecognition/scanText.d.ts +0 -3
  226. package/lib/typescript/src/Shared/VisionCameraPlugins/TextRecognition/scanText.d.ts.map +0 -1
  227. package/lib/typescript/src/Shared/VisionCameraPlugins/TextRecognition/translateText.d.ts +0 -3
  228. package/lib/typescript/src/Shared/VisionCameraPlugins/TextRecognition/translateText.d.ts.map +0 -1
  229. package/lib/typescript/src/Shared/VisionCameraPlugins/TextRecognition/types.d.ts +0 -67
  230. package/lib/typescript/src/Shared/VisionCameraPlugins/TextRecognition/types.d.ts.map +0 -1
  231. package/src/Shared/Libs/camera.utils.ts +0 -345
  232. package/src/Shared/Libs/frame-enhancement.utils.ts +0 -217
  233. package/src/Shared/Libs/opencv.utils.ts +0 -40
  234. package/src/Shared/Libs/worklet.utils.ts +0 -72
  235. package/src/Shared/VisionCameraPlugins/BarcodeScanner/hooks/useBarcodeScanner.ts +0 -79
  236. package/src/Shared/VisionCameraPlugins/BarcodeScanner/hooks/useCameraPermissions.ts +0 -46
  237. package/src/Shared/VisionCameraPlugins/BarcodeScanner/index.ts +0 -60
  238. package/src/Shared/VisionCameraPlugins/BarcodeScanner/scanCodes.ts +0 -32
  239. package/src/Shared/VisionCameraPlugins/BarcodeScanner/types.ts +0 -82
  240. package/src/Shared/VisionCameraPlugins/BarcodeScanner/utils/convert.ts +0 -195
  241. package/src/Shared/VisionCameraPlugins/BarcodeScanner/utils/geometry.ts +0 -135
  242. package/src/Shared/VisionCameraPlugins/BarcodeScanner/utils/highlights.ts +0 -84
  243. package/src/Shared/VisionCameraPlugins/Cropper/index.ts +0 -78
  244. package/src/Shared/VisionCameraPlugins/FaceDetector/Camera.tsx +0 -63
  245. package/src/Shared/VisionCameraPlugins/FaceDetector/detectFaces.ts +0 -44
  246. package/src/Shared/VisionCameraPlugins/FaceDetector/index.ts +0 -3
  247. package/src/Shared/VisionCameraPlugins/FaceDetector/types.ts +0 -99
  248. package/src/Shared/VisionCameraPlugins/TextRecognition/Camera.tsx +0 -76
  249. package/src/Shared/VisionCameraPlugins/TextRecognition/PhotoRecognizer.ts +0 -18
  250. package/src/Shared/VisionCameraPlugins/TextRecognition/RemoveLanguageModel.ts +0 -7
  251. package/src/Shared/VisionCameraPlugins/TextRecognition/index.ts +0 -7
  252. package/src/Shared/VisionCameraPlugins/TextRecognition/scanText.ts +0 -27
  253. package/src/Shared/VisionCameraPlugins/TextRecognition/translateText.ts +0 -21
  254. package/src/Shared/VisionCameraPlugins/TextRecognition/types.ts +0 -141
@@ -0,0 +1,419 @@
1
+ package com.trustchex.reactnativesdk.mrz
2
+
3
+ /**
4
+ * Pure MRZ validation logic with no React Native dependencies.
5
+ * Used by both MRZValidationModule and TrustchexCameraView.
6
+ */
7
+ object MRZValidator {
8
+
9
+ data class MRZResult(
10
+ val valid: Boolean,
11
+ val format: String,
12
+ val error: String? = null,
13
+ val documentCode: String? = null,
14
+ val issuingState: String? = null,
15
+ val documentNumber: String? = null,
16
+ val lastName: String? = null,
17
+ val firstName: String? = null,
18
+ val birthDate: String? = null,
19
+ val sex: String? = null,
20
+ val expirationDate: String? = null,
21
+ val nationality: String? = null,
22
+ val optional1: String? = null,
23
+ val optional2: String? = null,
24
+ val rawLines: String? = null
25
+ )
26
+
27
+ fun validateWithCorrections(ocrText: String): MRZResult {
28
+ val fixedText = fixMRZ(ocrText)
29
+ val lines = fixedText.trim().split("\n").map { it.trim() }
30
+
31
+ if (lines.isEmpty() || fixedText.length < 60) {
32
+ return MRZResult(valid = false, format = "UNKNOWN", error = "MRZ text too short")
33
+ }
34
+
35
+ val format = detectMRZFormat(lines)
36
+ if (format == "UNKNOWN") {
37
+ return MRZResult(valid = false, format = "UNKNOWN", error = "Unknown MRZ format")
38
+ }
39
+
40
+ // Phase 1: position-aware corrections
41
+ var result = parseMRZ(fixedText)
42
+ if (result.valid) return result
43
+
44
+ // Phase 2: composite checksum brute-force
45
+ val compositePos = when (format) {
46
+ "TD1" -> Pair(1, 29)
47
+ "TD2" -> Pair(1, 35)
48
+ "TD3" -> Pair(1, 43)
49
+ else -> null
50
+ }
51
+ if (compositePos != null) {
52
+ val mutableLines = lines.toMutableList()
53
+ val targetLine = mutableLines[compositePos.first]
54
+ for (digit in 0..9) {
55
+ val testLine = targetLine.substring(0, compositePos.second) +
56
+ digit +
57
+ targetLine.substring(compositePos.second + 1)
58
+ mutableLines[compositePos.first] = testLine
59
+ val testResult = parseMRZ(mutableLines.joinToString("\n"))
60
+ if (testResult.valid) return testResult
61
+ }
62
+ }
63
+
64
+ // Phase 3: O/0 permutations
65
+ for (permutation in generateO0Permutations(fixedText)) {
66
+ val testResult = parseMRZ(permutation)
67
+ if (testResult.valid) return testResult
68
+ }
69
+
70
+ // Phase 4: I/1 permutations
71
+ for (permutation in generateI1Permutations(fixedText)) {
72
+ val testResult = parseMRZ(permutation)
73
+ if (testResult.valid) return testResult
74
+ }
75
+
76
+ // Phase 5: S/5 permutations
77
+ for (permutation in generatePairPermutations(fixedText, 'S', '5', 30)) {
78
+ val testResult = parseMRZ(permutation)
79
+ if (testResult.valid) return testResult
80
+ }
81
+
82
+ // Phase 6: B/8 permutations
83
+ for (permutation in generatePairPermutations(fixedText, 'B', '8', 30)) {
84
+ val testResult = parseMRZ(permutation)
85
+ if (testResult.valid) return testResult
86
+ }
87
+
88
+ // Phase 7: Z/2 permutations
89
+ for (permutation in generatePairPermutations(fixedText, 'Z', '2', 30)) {
90
+ val testResult = parseMRZ(permutation)
91
+ if (testResult.valid) return testResult
92
+ }
93
+
94
+ // Phase 8: G/6 permutations
95
+ for (permutation in generatePairPermutations(fixedText, 'G', '6', 30)) {
96
+ val testResult = parseMRZ(permutation)
97
+ if (testResult.valid) return testResult
98
+ }
99
+
100
+ return result
101
+ }
102
+
103
+ private fun parseMRZ(rawText: String): MRZResult {
104
+ val lines = rawText.trim().split("\n").map { it.trim() }
105
+ val format = detectMRZFormat(lines)
106
+
107
+ if (format == "UNKNOWN") {
108
+ return MRZResult(valid = false, format = "UNKNOWN", error = "Unknown MRZ format")
109
+ }
110
+
111
+ val fields = when (format) {
112
+ "TD1" -> parseTD1(lines)
113
+ "TD2" -> parseTD2(lines)
114
+ "TD3" -> parseTD3(lines)
115
+ else -> return MRZResult(valid = false, format = "UNKNOWN", error = "Unsupported format")
116
+ }
117
+
118
+ val allValid = validateChecksums(format, lines)
119
+ return fields.copy(valid = allValid, format = format, rawLines = if (allValid) rawText.trim() else null)
120
+ }
121
+
122
+ private fun detectMRZFormat(lines: List<String>): String = when {
123
+ lines.size == 3 && lines.all { it.length == 30 } -> "TD1"
124
+ lines.size == 2 && lines.all { it.length == 36 } -> "TD2"
125
+ lines.size == 2 && lines.all { it.length == 44 } -> "TD3"
126
+ else -> "UNKNOWN"
127
+ }
128
+
129
+ private fun parseTD1(lines: List<String>): MRZResult {
130
+ val names = lines[2].split("<<")
131
+ return MRZResult(
132
+ valid = false,
133
+ format = "TD1",
134
+ documentCode = lines[0].substring(0, 2).replace('<', ' ').trim(),
135
+ issuingState = lines[0].substring(2, 5).replace('<', ' ').trim(),
136
+ documentNumber = lines[0].substring(5, 14).replace('<', ' ').trim(),
137
+ optional1 = lines[0].substring(15, 30).replace('<', ' ').trim(),
138
+ birthDate = lines[1].substring(0, 6),
139
+ sex = lines[1].substring(7, 8),
140
+ expirationDate = lines[1].substring(8, 14),
141
+ nationality = lines[1].substring(15, 18).replace('<', ' ').trim(),
142
+ optional2 = lines[1].substring(18, 29).replace('<', ' ').trim(),
143
+ lastName = names[0].replace('<', ' ').trim(),
144
+ firstName = if (names.size > 1) names[1].replace('<', ' ').trim() else ""
145
+ )
146
+ }
147
+
148
+ private fun parseTD2(lines: List<String>): MRZResult {
149
+ val names = lines[0].substring(5, 36).split("<<")
150
+ return MRZResult(
151
+ valid = false,
152
+ format = "TD2",
153
+ documentCode = lines[0].substring(0, 2).replace('<', ' ').trim(),
154
+ issuingState = lines[0].substring(2, 5).replace('<', ' ').trim(),
155
+ lastName = names[0].replace('<', ' ').trim(),
156
+ firstName = if (names.size > 1) names[1].replace('<', ' ').trim() else "",
157
+ documentNumber = lines[1].substring(0, 9).replace('<', ' ').trim(),
158
+ nationality = lines[1].substring(10, 13).replace('<', ' ').trim(),
159
+ birthDate = lines[1].substring(13, 19),
160
+ sex = lines[1].substring(20, 21),
161
+ expirationDate = lines[1].substring(21, 27),
162
+ optional1 = lines[1].substring(28, 35).replace('<', ' ').trim()
163
+ )
164
+ }
165
+
166
+ private fun parseTD3(lines: List<String>): MRZResult {
167
+ val names = lines[0].substring(5, 44).split("<<")
168
+ return MRZResult(
169
+ valid = false,
170
+ format = "TD3",
171
+ documentCode = lines[0].substring(0, 2).replace('<', ' ').trim(),
172
+ issuingState = lines[0].substring(2, 5).replace('<', ' ').trim(),
173
+ lastName = names[0].replace('<', ' ').trim(),
174
+ firstName = if (names.size > 1) names[1].replace('<', ' ').trim() else "",
175
+ documentNumber = lines[1].substring(0, 9).replace('<', ' ').trim(),
176
+ nationality = lines[1].substring(10, 13).replace('<', ' ').trim(),
177
+ birthDate = lines[1].substring(13, 19),
178
+ sex = lines[1].substring(20, 21),
179
+ expirationDate = lines[1].substring(21, 27),
180
+ optional1 = lines[1].substring(28, 42).replace('<', ' ').trim()
181
+ )
182
+ }
183
+
184
+ private fun validateChecksums(format: String, lines: List<String>): Boolean {
185
+ return try {
186
+ when (format) {
187
+ "TD1" -> {
188
+ val docNumValid = calculateMRZChecksum(lines[0].substring(5, 14)) == lines[0][14]
189
+ val birthValid = calculateMRZChecksum(lines[1].substring(0, 6)) == lines[1][6]
190
+ val expiryValid = calculateMRZChecksum(lines[1].substring(8, 14)) == lines[1][14]
191
+ val composite = lines[0].substring(5, 30) + lines[1].substring(0, 7) +
192
+ lines[1].substring(8, 15) + lines[1].substring(18, 29)
193
+ val compositeValid = calculateMRZChecksum(composite) == lines[1][29]
194
+ docNumValid && birthValid && expiryValid && compositeValid
195
+ }
196
+ "TD2" -> {
197
+ val line = lines[1]
198
+ val docNumValid = calculateMRZChecksum(line.substring(0, 9)) == line[9]
199
+ val birthValid = calculateMRZChecksum(line.substring(13, 19)) == line[19]
200
+ val expiryValid = calculateMRZChecksum(line.substring(21, 27)) == line[27]
201
+ val composite = line.substring(0, 10) + line.substring(13, 20) + line.substring(21, 35)
202
+ val compositeValid = calculateMRZChecksum(composite) == line[35]
203
+ docNumValid && birthValid && expiryValid && compositeValid
204
+ }
205
+ "TD3" -> {
206
+ val line = lines[1]
207
+ val docNumValid = calculateMRZChecksum(line.substring(0, 9)) == line[9]
208
+ val birthValid = calculateMRZChecksum(line.substring(13, 19)) == line[19]
209
+ val expiryValid = calculateMRZChecksum(line.substring(21, 27)) == line[27]
210
+ val personalValid = calculateMRZChecksum(line.substring(28, 42)) == line[42]
211
+ val composite = line.substring(0, 10) + line.substring(13, 20) + line.substring(21, 43)
212
+ val compositeValid = calculateMRZChecksum(composite) == line[43]
213
+ docNumValid && birthValid && expiryValid && personalValid && compositeValid
214
+ }
215
+ else -> false
216
+ }
217
+ } catch (e: Exception) {
218
+ false
219
+ }
220
+ }
221
+
222
+ private fun calculateMRZChecksum(data: String): Char {
223
+ val weights = intArrayOf(7, 3, 1)
224
+ var sum = 0
225
+ for (i in data.indices) {
226
+ val value = when (val c = data[i]) {
227
+ in '0'..'9' -> c - '0'
228
+ in 'A'..'Z' -> c - 'A' + 10
229
+ else -> 0
230
+ }
231
+ sum += value * weights[i % 3]
232
+ }
233
+ return ('0' + (sum % 10))
234
+ }
235
+
236
+ fun fixMRZ(rawText: String): String {
237
+ var fixed = rawText
238
+ .replace(" ", "")
239
+ .replace("«", "")
240
+ .replace(Regex("<K+|r+K+|<r+K+"), "")
241
+
242
+ fixed = fixed.replace(Regex("""\bI<TUR([A-Z0-9]{3})0([A-Z0-9]{6})\b"""), "I<TUR$1O$2")
243
+
244
+ val lines = fixed.split("\n").map { it.trim() }
245
+
246
+ // Extract only lines that look like MRZ (uppercase alphanumeric + filler only, exact MRZ lengths)
247
+ val mrzLines = lines.filter { line ->
248
+ (line.length == 30 || line.length == 36 || line.length == 44) &&
249
+ line.matches(Regex("[A-Z0-9<]+"))
250
+ }
251
+
252
+ // If no exact-length MRZ lines found, fall back to lines containing '<' that could be padded
253
+ val candidateLines = if (mrzLines.isNotEmpty()) mrzLines else lines.filter { it.contains('<') }
254
+
255
+ val targetLength = when {
256
+ candidateLines.all { it.length <= 30 } -> 30
257
+ candidateLines.all { it.length <= 36 } -> 36
258
+ candidateLines.all { it.length <= 44 } -> 44
259
+ else -> return rawText
260
+ }
261
+
262
+ // Keep only lines that fit the target length (filter out non-MRZ lines)
263
+ val filteredLines = candidateLines.filter { it.length <= targetLength && it.matches(Regex("[A-Z0-9<]+")) }
264
+ if (filteredLines.isEmpty()) return rawText
265
+
266
+ val paddedLines = filteredLines.map { line ->
267
+ if (line.length < targetLength) line.padEnd(targetLength, '<') else line
268
+ }
269
+
270
+ return applyOCRCorrections(paddedLines.joinToString("\n"))
271
+ }
272
+
273
+ private fun applyOCRCorrections(mrzText: String): String {
274
+ val lines = mrzText.split("\n").toMutableList()
275
+ if (lines.isEmpty()) return mrzText
276
+
277
+ val format = detectMRZFormat(lines)
278
+ if (format == "UNKNOWN") return mrzText
279
+
280
+ when (format) {
281
+ "TD1" -> {
282
+ lines[0] = correctLetterPositions(lines[0], listOf(0..1, 2..4))
283
+ lines[0] = correctCheckDigitPositions(lines[0], listOf(14))
284
+ lines[1] = correctDigitPositions(lines[1], listOf(0..5, 8..13))
285
+ lines[1] = correctCheckDigitPositions(lines[1], listOf(6, 14, 29))
286
+ lines[1] = correctLetterPositions(lines[1], listOf(7..7, 15..17))
287
+ lines[2] = correctLetterPositions(lines[2], listOf(0..29))
288
+ }
289
+ "TD2" -> {
290
+ lines[0] = correctLetterPositions(lines[0], listOf(0..1, 2..4, 5..35))
291
+ lines[1] = correctDigitPositions(lines[1], listOf(13..18, 21..26))
292
+ lines[1] = correctCheckDigitPositions(lines[1], listOf(9, 19, 27, 35))
293
+ lines[1] = correctLetterPositions(lines[1], listOf(10..12, 20..20))
294
+ }
295
+ "TD3" -> {
296
+ lines[0] = correctLetterPositions(lines[0], listOf(0..1, 2..4, 5..43))
297
+ lines[1] = correctDigitPositions(lines[1], listOf(13..18, 21..26))
298
+ lines[1] = correctCheckDigitPositions(lines[1], listOf(9, 19, 27, 42))
299
+ lines[1] = correctLetterPositions(lines[1], listOf(10..12, 20..20))
300
+ }
301
+ }
302
+
303
+ return lines.joinToString("\n")
304
+ }
305
+
306
+ private fun correctDigitPositions(line: String, ranges: List<IntRange>): String {
307
+ var corrected = line
308
+ ranges.forEach { range ->
309
+ range.forEach { pos ->
310
+ if (pos < corrected.length) {
311
+ val replacement = when (corrected[pos]) {
312
+ 'O', 'o' -> '0'; 'I', 'l' -> '1'; 'Z' -> '2'
313
+ 'S' -> '5'; 'G' -> '6'; 'B' -> '8'; 'D', 'Q' -> '0'
314
+ else -> corrected[pos]
315
+ }
316
+ if (replacement != corrected[pos])
317
+ corrected = corrected.substring(0, pos) + replacement + corrected.substring(pos + 1)
318
+ }
319
+ }
320
+ }
321
+ return corrected
322
+ }
323
+
324
+ private fun correctLetterPositions(line: String, ranges: List<IntRange>): String {
325
+ var corrected = line
326
+ ranges.forEach { range ->
327
+ range.forEach { pos ->
328
+ if (pos < corrected.length) {
329
+ val replacement = when (corrected[pos]) {
330
+ '0' -> 'O'; '1' -> 'I'; '5' -> 'S'; '8' -> 'B'; '2' -> 'Z'; '6' -> 'G'
331
+ else -> corrected[pos]
332
+ }
333
+ if (replacement != corrected[pos])
334
+ corrected = corrected.substring(0, pos) + replacement + corrected.substring(pos + 1)
335
+ }
336
+ }
337
+ }
338
+ return corrected
339
+ }
340
+
341
+ private fun correctCheckDigitPositions(line: String, positions: List<Int>): String {
342
+ var corrected = line
343
+ positions.forEach { pos ->
344
+ if (pos < corrected.length) {
345
+ val replacement = when (corrected[pos]) {
346
+ 'O', 'o' -> '0'; 'I', 'l' -> '1'; 'Z' -> '2'
347
+ 'S' -> '5'; 'G' -> '6'; 'B' -> '8'
348
+ else -> corrected[pos]
349
+ }
350
+ if (replacement != corrected[pos])
351
+ corrected = corrected.substring(0, pos) + replacement + corrected.substring(pos + 1)
352
+ }
353
+ }
354
+ return corrected
355
+ }
356
+
357
+ private fun generateO0Permutations(mrzText: String, maxPermutations: Int = 100): List<String> {
358
+ val permutations = mutableSetOf(mrzText)
359
+ val positions = mrzText.indices
360
+ .filter { val c = mrzText[it]; c == 'O' || c == 'o' || c == '0' }
361
+ .take(7)
362
+ val limit = minOf(1 shl positions.size, maxPermutations)
363
+ for (i in 0 until limit) {
364
+ var variant = mrzText
365
+ positions.forEachIndexed { j, pos ->
366
+ val useZero = (i and (1 shl j)) != 0
367
+ val replacement = if (useZero && variant[pos] != '0') '0'
368
+ else if (!useZero && variant[pos] != 'O') 'O'
369
+ else variant[pos]
370
+ if (replacement != variant[pos])
371
+ variant = variant.substring(0, pos) + replacement + variant.substring(pos + 1)
372
+ }
373
+ permutations.add(variant)
374
+ }
375
+ return permutations.toList()
376
+ }
377
+
378
+ private fun generatePairPermutations(mrzText: String, letter: Char, digit: Char, maxPermutations: Int = 30): List<String> {
379
+ val permutations = mutableSetOf(mrzText)
380
+ val positions = mrzText.indices
381
+ .filter { val c = mrzText[it]; c == letter || c == letter.lowercaseChar() || c == digit }
382
+ .take(5)
383
+ val limit = minOf(1 shl positions.size, maxPermutations)
384
+ for (i in 0 until limit) {
385
+ var variant = mrzText
386
+ positions.forEachIndexed { j, pos ->
387
+ val useDigit = (i and (1 shl j)) != 0
388
+ val replacement = if (useDigit && variant[pos] != digit) digit
389
+ else if (!useDigit && variant[pos] != letter) letter
390
+ else variant[pos]
391
+ if (replacement != variant[pos])
392
+ variant = variant.substring(0, pos) + replacement + variant.substring(pos + 1)
393
+ }
394
+ permutations.add(variant)
395
+ }
396
+ return permutations.toList()
397
+ }
398
+
399
+ private fun generateI1Permutations(mrzText: String, maxPermutations: Int = 50): List<String> {
400
+ val permutations = mutableSetOf(mrzText)
401
+ val positions = mrzText.indices
402
+ .filter { val c = mrzText[it]; c == 'I' || c == 'i' || c == 'l' || c == '1' }
403
+ .take(6)
404
+ val limit = minOf(1 shl positions.size, maxPermutations)
405
+ for (i in 0 until limit) {
406
+ var variant = mrzText
407
+ positions.forEachIndexed { j, pos ->
408
+ val useOne = (i and (1 shl j)) != 0
409
+ val replacement = if (useOne && variant[pos] != '1') '1'
410
+ else if (!useOne && (variant[pos] == '1' || variant[pos] == 'l' || variant[pos] == 'i')) 'I'
411
+ else variant[pos]
412
+ if (replacement != variant[pos])
413
+ variant = variant.substring(0, pos) + replacement + variant.substring(pos + 1)
414
+ }
415
+ permutations.add(variant)
416
+ }
417
+ return permutations.toList()
418
+ }
419
+ }