@trustchex/react-native-sdk 1.409.0 → 1.464.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 (156) hide show
  1. package/android/src/main/java/com/trustchex/reactnativesdk/TrustchexSDKModule.kt +2 -8
  2. package/android/src/main/java/com/trustchex/reactnativesdk/camera/TrustchexCameraView.kt +59 -1
  3. package/ios/Camera/TrustchexCameraView.swift +9 -1
  4. package/lib/module/Screens/Debug/NFCScanTestScreen.js +635 -0
  5. package/lib/module/Screens/Dynamic/ContractAcceptanceScreen.js +1 -4
  6. package/lib/module/Screens/Dynamic/IdentityDocumentEIDScanningScreen.js +17 -4
  7. package/lib/module/Screens/Dynamic/LivenessDetectionScreen.js +102 -23
  8. package/lib/module/Screens/Dynamic/VerbalConsentScreen.js +1079 -0
  9. package/lib/module/Screens/Dynamic/VideoCallScreen.js +3 -1
  10. package/lib/module/Screens/Static/ResultScreen.js +128 -22
  11. package/lib/module/Screens/Static/VerificationSessionCheckScreen.js +8 -0
  12. package/lib/module/Shared/Animations/recording.json +1 -0
  13. package/lib/module/Shared/Components/DebugNavigationPanel.js +69 -71
  14. package/lib/module/Shared/Components/EIDScanner.js +212 -108
  15. package/lib/module/Shared/Components/IdentityDocumentCamera.flows.js +5 -3
  16. package/lib/module/Shared/Components/IdentityDocumentCamera.js +53 -36
  17. package/lib/module/Shared/Components/IdentityDocumentCamera.utils.js +13 -4
  18. package/lib/module/Shared/Components/NavigationManager.js +24 -16
  19. package/lib/module/Shared/EIDReader/aesSecureMessagingWrapper.js +51 -0
  20. package/lib/module/Shared/EIDReader/apduLevelPACECapable.js +3 -0
  21. package/lib/module/Shared/EIDReader/bacKey.js +16 -2
  22. package/lib/module/Shared/EIDReader/eidReader.js +354 -13
  23. package/lib/module/Shared/EIDReader/eidService.js +25 -1
  24. package/lib/module/Shared/EIDReader/nfcManagerCardService.js +4 -7
  25. package/lib/module/Shared/EIDReader/paceInfo.js +85 -0
  26. package/lib/module/Shared/EIDReader/paceKeySpec.js +51 -0
  27. package/lib/module/Shared/EIDReader/protocol/paceAPDUSender.js +100 -0
  28. package/lib/module/Shared/EIDReader/protocol/paceProtocol.js +655 -0
  29. package/lib/module/Shared/EIDReader/protocol/paceResult.js +37 -0
  30. package/lib/module/Shared/EIDReader/secureMessagingWrapper.js +27 -4
  31. package/lib/module/Shared/EIDReader/smartcards/commandAPDU.js +2 -1
  32. package/lib/module/Shared/EIDReader/tlv/tlv.helpers.js +1 -1
  33. package/lib/module/Shared/EIDReader/tlv/tlv.utils.js +6 -3
  34. package/lib/module/Shared/EIDReader/utils/aesCrypto.utils.js +189 -0
  35. package/lib/module/Shared/Libs/analytics.utils.js +4 -0
  36. package/lib/module/Shared/Libs/contains.js +1 -40
  37. package/lib/module/Shared/Libs/country-display.utils.js +34 -0
  38. package/lib/module/Shared/Libs/demo.utils.js +8 -0
  39. package/lib/module/Shared/Libs/mrz.utils.js +3 -2
  40. package/lib/module/Shared/Libs/status-bar.utils.js +4 -2
  41. package/lib/module/Shared/Types/analytics.types.js +2 -0
  42. package/lib/module/Translation/Resources/en.js +41 -2
  43. package/lib/module/Translation/Resources/tr.js +41 -2
  44. package/lib/module/Trustchex.js +54 -20
  45. package/lib/module/version.js +1 -1
  46. package/lib/typescript/src/Screens/Debug/NFCScanTestScreen.d.ts +3 -0
  47. package/lib/typescript/src/Screens/Debug/NFCScanTestScreen.d.ts.map +1 -0
  48. package/lib/typescript/src/Screens/Dynamic/ContractAcceptanceScreen.d.ts.map +1 -1
  49. package/lib/typescript/src/Screens/Dynamic/IdentityDocumentEIDScanningScreen.d.ts.map +1 -1
  50. package/lib/typescript/src/Screens/Dynamic/LivenessDetectionScreen.d.ts.map +1 -1
  51. package/lib/typescript/src/Screens/Dynamic/VerbalConsentScreen.d.ts +3 -0
  52. package/lib/typescript/src/Screens/Dynamic/VerbalConsentScreen.d.ts.map +1 -0
  53. package/lib/typescript/src/Screens/Dynamic/VideoCallScreen.d.ts.map +1 -1
  54. package/lib/typescript/src/Screens/Static/ResultScreen.d.ts.map +1 -1
  55. package/lib/typescript/src/Screens/Static/VerificationSessionCheckScreen.d.ts.map +1 -1
  56. package/lib/typescript/src/Shared/Components/DebugNavigationPanel.d.ts.map +1 -1
  57. package/lib/typescript/src/Shared/Components/EIDScanner.d.ts.map +1 -1
  58. package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.d.ts.map +1 -1
  59. package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.flows.d.ts +1 -1
  60. package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.flows.d.ts.map +1 -1
  61. package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.utils.d.ts +5 -0
  62. package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.utils.d.ts.map +1 -1
  63. package/lib/typescript/src/Shared/Components/NavigationManager.d.ts.map +1 -1
  64. package/lib/typescript/src/Shared/EIDReader/aesSecureMessagingWrapper.d.ts +18 -0
  65. package/lib/typescript/src/Shared/EIDReader/aesSecureMessagingWrapper.d.ts.map +1 -0
  66. package/lib/typescript/src/Shared/EIDReader/apduLevelPACECapable.d.ts +23 -0
  67. package/lib/typescript/src/Shared/EIDReader/apduLevelPACECapable.d.ts.map +1 -0
  68. package/lib/typescript/src/Shared/EIDReader/bacKey.d.ts +6 -0
  69. package/lib/typescript/src/Shared/EIDReader/bacKey.d.ts.map +1 -1
  70. package/lib/typescript/src/Shared/EIDReader/eidReader.d.ts.map +1 -1
  71. package/lib/typescript/src/Shared/EIDReader/eidService.d.ts +9 -0
  72. package/lib/typescript/src/Shared/EIDReader/eidService.d.ts.map +1 -1
  73. package/lib/typescript/src/Shared/EIDReader/nfcManagerCardService.d.ts.map +1 -1
  74. package/lib/typescript/src/Shared/EIDReader/paceInfo.d.ts +50 -0
  75. package/lib/typescript/src/Shared/EIDReader/paceInfo.d.ts.map +1 -0
  76. package/lib/typescript/src/Shared/EIDReader/paceKeySpec.d.ts +30 -0
  77. package/lib/typescript/src/Shared/EIDReader/paceKeySpec.d.ts.map +1 -0
  78. package/lib/typescript/src/Shared/EIDReader/protocol/paceAPDUSender.d.ts +17 -0
  79. package/lib/typescript/src/Shared/EIDReader/protocol/paceAPDUSender.d.ts.map +1 -0
  80. package/lib/typescript/src/Shared/EIDReader/protocol/paceProtocol.d.ts +105 -0
  81. package/lib/typescript/src/Shared/EIDReader/protocol/paceProtocol.d.ts.map +1 -0
  82. package/lib/typescript/src/Shared/EIDReader/protocol/paceResult.d.ts +24 -0
  83. package/lib/typescript/src/Shared/EIDReader/protocol/paceResult.d.ts.map +1 -0
  84. package/lib/typescript/src/Shared/EIDReader/secureMessagingWrapper.d.ts +15 -0
  85. package/lib/typescript/src/Shared/EIDReader/secureMessagingWrapper.d.ts.map +1 -1
  86. package/lib/typescript/src/Shared/EIDReader/smartcards/commandAPDU.d.ts.map +1 -1
  87. package/lib/typescript/src/Shared/EIDReader/tlv/tlv.utils.d.ts.map +1 -1
  88. package/lib/typescript/src/Shared/EIDReader/utils/aesCrypto.utils.d.ts +39 -0
  89. package/lib/typescript/src/Shared/EIDReader/utils/aesCrypto.utils.d.ts.map +1 -0
  90. package/lib/typescript/src/Shared/Libs/analytics.utils.d.ts.map +1 -1
  91. package/lib/typescript/src/Shared/Libs/contains.d.ts +0 -7
  92. package/lib/typescript/src/Shared/Libs/contains.d.ts.map +1 -1
  93. package/lib/typescript/src/Shared/Libs/country-display.utils.d.ts +2 -0
  94. package/lib/typescript/src/Shared/Libs/country-display.utils.d.ts.map +1 -0
  95. package/lib/typescript/src/Shared/Libs/demo.utils.d.ts.map +1 -1
  96. package/lib/typescript/src/Shared/Libs/http-client.d.ts +1 -1
  97. package/lib/typescript/src/Shared/Libs/http-client.d.ts.map +1 -1
  98. package/lib/typescript/src/Shared/Libs/mrz.utils.d.ts.map +1 -1
  99. package/lib/typescript/src/Shared/Libs/status-bar.utils.d.ts.map +1 -1
  100. package/lib/typescript/src/Shared/Types/analytics.types.d.ts +2 -0
  101. package/lib/typescript/src/Shared/Types/analytics.types.d.ts.map +1 -1
  102. package/lib/typescript/src/Shared/Types/identificationInfo.d.ts +10 -1
  103. package/lib/typescript/src/Shared/Types/identificationInfo.d.ts.map +1 -1
  104. package/lib/typescript/src/Translation/Resources/en.d.ts +40 -1
  105. package/lib/typescript/src/Translation/Resources/en.d.ts.map +1 -1
  106. package/lib/typescript/src/Translation/Resources/tr.d.ts +40 -1
  107. package/lib/typescript/src/Translation/Resources/tr.d.ts.map +1 -1
  108. package/lib/typescript/src/Trustchex.d.ts.map +1 -1
  109. package/lib/typescript/src/version.d.ts +1 -1
  110. package/package.json +7 -4
  111. package/src/Screens/Debug/NFCScanTestScreen.tsx +692 -0
  112. package/src/Screens/Dynamic/ContractAcceptanceScreen.tsx +1 -4
  113. package/src/Screens/Dynamic/IdentityDocumentEIDScanningScreen.tsx +21 -4
  114. package/src/Screens/Dynamic/LivenessDetectionScreen.tsx +124 -23
  115. package/src/Screens/Dynamic/VerbalConsentScreen.tsx +1401 -0
  116. package/src/Screens/Dynamic/VideoCallScreen.tsx +3 -1
  117. package/src/Screens/Static/ResultScreen.tsx +183 -31
  118. package/src/Screens/Static/VerificationSessionCheckScreen.tsx +9 -0
  119. package/src/Shared/Animations/recording.json +1 -0
  120. package/src/Shared/Components/DebugNavigationPanel.tsx +73 -48
  121. package/src/Shared/Components/EIDScanner.tsx +222 -111
  122. package/src/Shared/Components/IdentityDocumentCamera.flows.ts +7 -4
  123. package/src/Shared/Components/IdentityDocumentCamera.tsx +199 -184
  124. package/src/Shared/Components/IdentityDocumentCamera.utils.ts +13 -4
  125. package/src/Shared/Components/NavigationManager.tsx +27 -18
  126. package/src/Shared/EIDReader/aesSecureMessagingWrapper.ts +69 -0
  127. package/src/Shared/EIDReader/apduLevelPACECapable.ts +34 -0
  128. package/src/Shared/EIDReader/bacKey.ts +24 -8
  129. package/src/Shared/EIDReader/eidReader.ts +398 -12
  130. package/src/Shared/EIDReader/eidService.ts +49 -1
  131. package/src/Shared/EIDReader/nfcManagerCardService.ts +4 -6
  132. package/src/Shared/EIDReader/paceInfo.ts +159 -0
  133. package/src/Shared/EIDReader/paceKeySpec.ts +56 -0
  134. package/src/Shared/EIDReader/protocol/paceAPDUSender.ts +163 -0
  135. package/src/Shared/EIDReader/protocol/paceProtocol.ts +946 -0
  136. package/src/Shared/EIDReader/protocol/paceResult.ts +62 -0
  137. package/src/Shared/EIDReader/secureMessagingWrapper.ts +28 -10
  138. package/src/Shared/EIDReader/smartcards/commandAPDU.ts +2 -1
  139. package/src/Shared/EIDReader/tlv/tlv.helpers.ts +1 -1
  140. package/src/Shared/EIDReader/tlv/tlv.utils.ts +8 -5
  141. package/src/Shared/EIDReader/utils/aesCrypto.utils.ts +217 -0
  142. package/src/Shared/Libs/analytics.utils.ts +4 -0
  143. package/src/Shared/Libs/contains.ts +0 -53
  144. package/src/Shared/Libs/country-display.utils.ts +55 -0
  145. package/src/Shared/Libs/crypto.utils.ts +2 -2
  146. package/src/Shared/Libs/demo.utils.ts +10 -0
  147. package/src/Shared/Libs/http-client.ts +12 -4
  148. package/src/Shared/Libs/mrz.utils.ts +3 -2
  149. package/src/Shared/Libs/status-bar.utils.ts +4 -2
  150. package/src/Shared/Services/VideoSessionService.ts +1 -1
  151. package/src/Shared/Types/analytics.types.ts +2 -0
  152. package/src/Shared/Types/identificationInfo.ts +11 -0
  153. package/src/Translation/Resources/en.ts +63 -3
  154. package/src/Translation/Resources/tr.ts +62 -3
  155. package/src/Trustchex.tsx +53 -17
  156. package/src/version.ts +1 -1
@@ -0,0 +1,159 @@
1
+ /**
2
+ * PACE (Password Authenticated Connection Establishment) protocol info.
3
+ * Parses PACE OIDs to extract mapping type, cipher, digest, key agreement algorithm, and key length.
4
+ *
5
+ * Based on ICAO Doc 9303 Part 11 and BSI TR-03110.
6
+ */
7
+
8
+ export enum MappingType {
9
+ GM = 'GM',
10
+ IM = 'IM',
11
+ CAM = 'CAM',
12
+ }
13
+
14
+ // PACE OID constants (BSI TR-03110 / ICAO 9303)
15
+ export const ID_PACE = '0.4.0.127.0.7.2.2.4';
16
+
17
+ export const ID_PACE_DH_GM = '0.4.0.127.0.7.2.2.4.1';
18
+ export const ID_PACE_DH_GM_3DES_CBC_CBC = '0.4.0.127.0.7.2.2.4.1.1';
19
+ export const ID_PACE_DH_GM_AES_CBC_CMAC_128 = '0.4.0.127.0.7.2.2.4.1.2';
20
+ export const ID_PACE_DH_GM_AES_CBC_CMAC_192 = '0.4.0.127.0.7.2.2.4.1.3';
21
+ export const ID_PACE_DH_GM_AES_CBC_CMAC_256 = '0.4.0.127.0.7.2.2.4.1.4';
22
+
23
+ export const ID_PACE_ECDH_GM = '0.4.0.127.0.7.2.2.4.2';
24
+ export const ID_PACE_ECDH_GM_3DES_CBC_CBC = '0.4.0.127.0.7.2.2.4.2.1';
25
+ export const ID_PACE_ECDH_GM_AES_CBC_CMAC_128 = '0.4.0.127.0.7.2.2.4.2.2';
26
+ export const ID_PACE_ECDH_GM_AES_CBC_CMAC_192 = '0.4.0.127.0.7.2.2.4.2.3';
27
+ export const ID_PACE_ECDH_GM_AES_CBC_CMAC_256 = '0.4.0.127.0.7.2.2.4.2.4';
28
+
29
+ export const ID_PACE_DH_IM = '0.4.0.127.0.7.2.2.4.3';
30
+ export const ID_PACE_DH_IM_3DES_CBC_CBC = '0.4.0.127.0.7.2.2.4.3.1';
31
+ export const ID_PACE_DH_IM_AES_CBC_CMAC_128 = '0.4.0.127.0.7.2.2.4.3.2';
32
+ export const ID_PACE_DH_IM_AES_CBC_CMAC_192 = '0.4.0.127.0.7.2.2.4.3.3';
33
+ export const ID_PACE_DH_IM_AES_CBC_CMAC_256 = '0.4.0.127.0.7.2.2.4.3.4';
34
+
35
+ export const ID_PACE_ECDH_IM = '0.4.0.127.0.7.2.2.4.4';
36
+ export const ID_PACE_ECDH_IM_3DES_CBC_CBC = '0.4.0.127.0.7.2.2.4.4.1';
37
+ export const ID_PACE_ECDH_IM_AES_CBC_CMAC_128 = '0.4.0.127.0.7.2.2.4.4.2';
38
+ export const ID_PACE_ECDH_IM_AES_CBC_CMAC_192 = '0.4.0.127.0.7.2.2.4.4.3';
39
+ export const ID_PACE_ECDH_IM_AES_CBC_CMAC_256 = '0.4.0.127.0.7.2.2.4.4.4';
40
+
41
+ export const ID_PACE_ECDH_CAM = '0.4.0.127.0.7.2.2.4.6';
42
+ export const ID_PACE_ECDH_CAM_AES_CBC_CMAC_128 = '0.4.0.127.0.7.2.2.4.6.2';
43
+ export const ID_PACE_ECDH_CAM_AES_CBC_CMAC_192 = '0.4.0.127.0.7.2.2.4.6.3';
44
+ export const ID_PACE_ECDH_CAM_AES_CBC_CMAC_256 = '0.4.0.127.0.7.2.2.4.6.4';
45
+
46
+ // Standard domain parameter identifiers
47
+ export const PARAM_ID_ECP_NIST_P256_R1 = 12;
48
+ export const PARAM_ID_ECP_BRAINPOOL_P256_R1 = 13;
49
+ export const PARAM_ID_ECP_BRAINPOOL_P384_R1 = 16;
50
+ export const PARAM_ID_ECP_BRAINPOOL_P512_R1 = 17;
51
+ export const PARAM_ID_ECP_NIST_P384_R1 = 15;
52
+ export const PARAM_ID_ECP_NIST_P521_R1 = 18;
53
+
54
+ const GM_OIDS = new Set([
55
+ ID_PACE_DH_GM_3DES_CBC_CBC,
56
+ ID_PACE_DH_GM_AES_CBC_CMAC_128,
57
+ ID_PACE_DH_GM_AES_CBC_CMAC_192,
58
+ ID_PACE_DH_GM_AES_CBC_CMAC_256,
59
+ ID_PACE_ECDH_GM_3DES_CBC_CBC,
60
+ ID_PACE_ECDH_GM_AES_CBC_CMAC_128,
61
+ ID_PACE_ECDH_GM_AES_CBC_CMAC_192,
62
+ ID_PACE_ECDH_GM_AES_CBC_CMAC_256,
63
+ ]);
64
+
65
+ const IM_OIDS = new Set([
66
+ ID_PACE_DH_IM_3DES_CBC_CBC,
67
+ ID_PACE_DH_IM_AES_CBC_CMAC_128,
68
+ ID_PACE_DH_IM_AES_CBC_CMAC_192,
69
+ ID_PACE_DH_IM_AES_CBC_CMAC_256,
70
+ ID_PACE_ECDH_IM_3DES_CBC_CBC,
71
+ ID_PACE_ECDH_IM_AES_CBC_CMAC_128,
72
+ ID_PACE_ECDH_IM_AES_CBC_CMAC_192,
73
+ ID_PACE_ECDH_IM_AES_CBC_CMAC_256,
74
+ ]);
75
+
76
+ const CAM_OIDS = new Set([
77
+ ID_PACE_ECDH_CAM_AES_CBC_CMAC_128,
78
+ ID_PACE_ECDH_CAM_AES_CBC_CMAC_192,
79
+ ID_PACE_ECDH_CAM_AES_CBC_CMAC_256,
80
+ ]);
81
+
82
+ const DH_OIDS = new Set([
83
+ ID_PACE_DH_GM_3DES_CBC_CBC,
84
+ ID_PACE_DH_GM_AES_CBC_CMAC_128,
85
+ ID_PACE_DH_GM_AES_CBC_CMAC_192,
86
+ ID_PACE_DH_GM_AES_CBC_CMAC_256,
87
+ ID_PACE_DH_IM_3DES_CBC_CBC,
88
+ ID_PACE_DH_IM_AES_CBC_CMAC_128,
89
+ ID_PACE_DH_IM_AES_CBC_CMAC_192,
90
+ ID_PACE_DH_IM_AES_CBC_CMAC_256,
91
+ ]);
92
+
93
+ const DES_OIDS = new Set([
94
+ ID_PACE_DH_GM_3DES_CBC_CBC,
95
+ ID_PACE_DH_IM_3DES_CBC_CBC,
96
+ ID_PACE_ECDH_GM_3DES_CBC_CBC,
97
+ ID_PACE_ECDH_IM_3DES_CBC_CBC,
98
+ ]);
99
+
100
+ const KEY_128_OIDS = new Set([
101
+ ID_PACE_DH_GM_3DES_CBC_CBC,
102
+ ID_PACE_DH_IM_3DES_CBC_CBC,
103
+ ID_PACE_ECDH_GM_3DES_CBC_CBC,
104
+ ID_PACE_ECDH_IM_3DES_CBC_CBC,
105
+ ID_PACE_DH_GM_AES_CBC_CMAC_128,
106
+ ID_PACE_DH_IM_AES_CBC_CMAC_128,
107
+ ID_PACE_ECDH_GM_AES_CBC_CMAC_128,
108
+ ID_PACE_ECDH_IM_AES_CBC_CMAC_128,
109
+ ID_PACE_ECDH_CAM_AES_CBC_CMAC_128,
110
+ ]);
111
+
112
+ const KEY_192_OIDS = new Set([
113
+ ID_PACE_DH_GM_AES_CBC_CMAC_192,
114
+ ID_PACE_DH_IM_AES_CBC_CMAC_192,
115
+ ID_PACE_ECDH_GM_AES_CBC_CMAC_192,
116
+ ID_PACE_ECDH_IM_AES_CBC_CMAC_192,
117
+ ID_PACE_ECDH_CAM_AES_CBC_CMAC_192,
118
+ ]);
119
+
120
+ const KEY_256_OIDS = new Set([
121
+ ID_PACE_DH_GM_AES_CBC_CMAC_256,
122
+ ID_PACE_DH_IM_AES_CBC_CMAC_256,
123
+ ID_PACE_ECDH_GM_AES_CBC_CMAC_256,
124
+ ID_PACE_ECDH_IM_AES_CBC_CMAC_256,
125
+ ID_PACE_ECDH_CAM_AES_CBC_CMAC_256,
126
+ ]);
127
+
128
+ const SHA256_OIDS = new Set([...KEY_192_OIDS, ...KEY_256_OIDS]);
129
+
130
+ export class PACEInfo {
131
+ public static toMappingType(oid: string): MappingType {
132
+ if (GM_OIDS.has(oid)) return MappingType.GM;
133
+ if (IM_OIDS.has(oid)) return MappingType.IM;
134
+ if (CAM_OIDS.has(oid)) return MappingType.CAM;
135
+ throw new Error(`Unknown PACE OID: ${oid}`);
136
+ }
137
+
138
+ public static toKeyAgreementAlgorithm(oid: string): 'DH' | 'ECDH' {
139
+ if (DH_OIDS.has(oid)) return 'DH';
140
+ return 'ECDH';
141
+ }
142
+
143
+ public static toCipherAlgorithm(oid: string): 'DESede' | 'AES' {
144
+ if (DES_OIDS.has(oid)) return 'DESede';
145
+ return 'AES';
146
+ }
147
+
148
+ public static toDigestAlgorithm(oid: string): 'SHA-1' | 'SHA-256' {
149
+ if (SHA256_OIDS.has(oid)) return 'SHA-256';
150
+ return 'SHA-1';
151
+ }
152
+
153
+ public static toKeyLength(oid: string): 128 | 192 | 256 {
154
+ if (KEY_128_OIDS.has(oid)) return 128;
155
+ if (KEY_192_OIDS.has(oid)) return 192;
156
+ if (KEY_256_OIDS.has(oid)) return 256;
157
+ throw new Error(`Unknown PACE OID: ${oid}`);
158
+ }
159
+ }
@@ -0,0 +1,56 @@
1
+ import type { AccessKeySpec } from './accessKeySpec';
2
+ import { EID_CONSTANTS } from './constants/eidConstants';
3
+
4
+ /**
5
+ * A key specification for PACE authentication.
6
+ * Supports MRZ, CAN, PIN, and PUK key types.
7
+ */
8
+ export class PACEKeySpec implements AccessKeySpec {
9
+ private key: string;
10
+ private keyReference: number;
11
+
12
+ constructor(key: string, keyReference: number) {
13
+ this.key = key;
14
+ this.keyReference = keyReference;
15
+ }
16
+
17
+ public getAlgorithm(): string {
18
+ return 'PACE';
19
+ }
20
+
21
+ public getKey(): string {
22
+ return this.key;
23
+ }
24
+
25
+ public getKeyReference(): number {
26
+ return this.keyReference;
27
+ }
28
+
29
+ /**
30
+ * Creates a PACE key from a Card Access Number (CAN).
31
+ */
32
+ public static createCANKey(can: string): PACEKeySpec {
33
+ return new PACEKeySpec(can, EID_CONSTANTS.CAN_PACE_KEY_REFERENCE);
34
+ }
35
+
36
+ /**
37
+ * Creates a PACE key from a PIN.
38
+ */
39
+ public static createPINKey(pin: string): PACEKeySpec {
40
+ return new PACEKeySpec(pin, EID_CONSTANTS.PIN_PACE_KEY_REFERENCE);
41
+ }
42
+
43
+ /**
44
+ * Creates a PACE key from a PUK.
45
+ */
46
+ public static createPUKKey(puk: string): PACEKeySpec {
47
+ return new PACEKeySpec(puk, EID_CONSTANTS.PUK_PACE_KEY_REFERENCE);
48
+ }
49
+
50
+ /**
51
+ * Creates an MRZ-based PACE key from BAC key seed bytes.
52
+ */
53
+ public static createMRZKey(keySeed: string): PACEKeySpec {
54
+ return new PACEKeySpec(keySeed, EID_CONSTANTS.MRZ_PACE_KEY_REFERENCE);
55
+ }
56
+ }
@@ -0,0 +1,163 @@
1
+ import type { APDULevelPACECapable } from '../apduLevelPACECapable';
2
+ import type { APDUWrapper } from '../smartcards/apduWrapper';
3
+ import { Buffer } from 'buffer';
4
+ import { CardService } from '../cardService';
5
+ import { CommandAPDU } from '../smartcards/commandAPDU';
6
+ import { ISO7816_CLA, ISO7816_INS, ISO7816_SW } from '../smartcards/iso7816';
7
+ import { SecureMessagingAPDUSender } from './secureMessagingAPDUSender';
8
+ import TLVUtil from '../tlv/tlv.utils';
9
+
10
+ const INS_PACE_GENERAL_AUTHENTICATE = 0x86;
11
+
12
+ /**
13
+ * Low-level APDU sender to support the PACE protocol.
14
+ */
15
+ export class PACEAPDUSender implements APDULevelPACECapable {
16
+ private secureMessagingSender: SecureMessagingAPDUSender;
17
+
18
+ constructor(service: CardService) {
19
+ this.secureMessagingSender = new SecureMessagingAPDUSender(service);
20
+ }
21
+
22
+ public async sendMSESetATMutualAuth(
23
+ wrapper: APDUWrapper | null,
24
+ oid: string,
25
+ refPublicKeyOrSecretKey: number,
26
+ refPrivateKeyOrForComputingSessionKey: number[] | null
27
+ ): Promise<void> {
28
+ if (oid == null) {
29
+ throw new Error('OID cannot be null');
30
+ }
31
+
32
+ const oidBytes = PACEAPDUSender.toOIDBytes(oid);
33
+
34
+ // 0x83: Reference of a public key / secret key
35
+ const refBytes = Array.from(
36
+ TLVUtil.wrapDO(0x83, [refPublicKeyOrSecretKey])
37
+ );
38
+
39
+ // Build data
40
+ const data: number[] = [...oidBytes, ...refBytes];
41
+
42
+ // 0x84: Reference of a private key / Reference for computing a session key (optional)
43
+ if (refPrivateKeyOrForComputingSessionKey != null) {
44
+ const refPrivateBytes = Array.from(
45
+ TLVUtil.wrapDO(0x84, refPrivateKeyOrForComputingSessionKey)
46
+ );
47
+ data.push(...refPrivateBytes);
48
+ }
49
+
50
+ const commandAPDU = new CommandAPDU(
51
+ ISO7816_CLA.ISO7816,
52
+ ISO7816_INS.MSE,
53
+ 0xc1,
54
+ 0xa4,
55
+ Uint8Array.from(data),
56
+ 0,
57
+ data.length,
58
+ -1
59
+ );
60
+
61
+ const responseAPDU = await this.secureMessagingSender.transmit(
62
+ wrapper,
63
+ commandAPDU
64
+ );
65
+
66
+ const sw = responseAPDU.getSW();
67
+ if (sw !== ISO7816_SW.NO_ERROR) {
68
+ throw new Error(
69
+ `Sending MSE AT failed, SW = ${sw.toString(16).padStart(4, '0')}`
70
+ );
71
+ }
72
+ }
73
+
74
+ public async sendGeneralAuthenticate(
75
+ wrapper: APDUWrapper | null,
76
+ data: number[],
77
+ le: number,
78
+ isLast: boolean
79
+ ): Promise<number[]> {
80
+ // Wrap data in 0x7C
81
+ const commandData = Array.from(TLVUtil.wrapDO(0x7c, data));
82
+
83
+ const cla = isLast ? ISO7816_CLA.ISO7816 : ISO7816_CLA.COMMAND_CHAINING;
84
+
85
+ const commandAPDU = new CommandAPDU(
86
+ cla,
87
+ INS_PACE_GENERAL_AUTHENTICATE,
88
+ 0x00,
89
+ 0x00,
90
+ Uint8Array.from(commandData),
91
+ 0,
92
+ commandData.length,
93
+ le
94
+ );
95
+
96
+ console.debug(
97
+ `[PACE APDU] >> CLA=${cla.toString(16)} INS=86 Lc=${commandData.length} Le=${le} data(first32)=${Buffer.from(commandData.slice(0, 32)).toString('hex')}`
98
+ );
99
+
100
+ const responseAPDU = await this.secureMessagingSender.transmit(
101
+ wrapper,
102
+ commandAPDU
103
+ );
104
+
105
+ const sw = responseAPDU.getSW();
106
+ console.debug(
107
+ `[PACE APDU] << SW=${sw.toString(16).padStart(4, '0')} dataLen=${responseAPDU.getData()?.length ?? 0}`
108
+ );
109
+ if (sw !== ISO7816_SW.NO_ERROR) {
110
+ throw new Error(
111
+ `Sending general authenticate failed, SW = ${sw.toString(16).padStart(4, '0')}`
112
+ );
113
+ }
114
+
115
+ const responseData = responseAPDU.getData();
116
+ if (responseData == null || responseData.length === 0) {
117
+ return [];
118
+ }
119
+
120
+ // Unwrap 0x7C
121
+ return await TLVUtil.unwrapDO(0x7c, Array.from(responseData));
122
+ }
123
+
124
+ /**
125
+ * Encodes an OID string to its ASN.1 byte representation wrapped in tag 0x80.
126
+ */
127
+ private static toOIDBytes(oid: string): number[] {
128
+ const components = oid.split('.').map(Number);
129
+ if (components.length < 2) {
130
+ throw new Error(`Invalid OID: ${oid}`);
131
+ }
132
+
133
+ // First two components encoded as (first * 40 + second)
134
+ const encodedComponents: number[] = [];
135
+ const firstByte = components[0] * 40 + components[1];
136
+ encodedComponents.push(firstByte);
137
+
138
+ // Remaining components use base-128 encoding
139
+ for (let i = 2; i < components.length; i++) {
140
+ const value = components[i];
141
+ if (value < 128) {
142
+ encodedComponents.push(value);
143
+ } else {
144
+ const bytes: number[] = [];
145
+ let v = value;
146
+ bytes.push(v & 0x7f);
147
+ v >>= 7;
148
+ while (v > 0) {
149
+ bytes.push((v & 0x7f) | 0x80);
150
+ v >>= 7;
151
+ }
152
+ bytes.reverse();
153
+ encodedComponents.push(...bytes);
154
+ }
155
+ }
156
+
157
+ // Wrap with tag 0x80 (TLV)
158
+ const oidContent = Uint8Array.from(encodedComponents);
159
+ const result: number[] = [0x80, oidContent.length, ...oidContent];
160
+
161
+ return result;
162
+ }
163
+ }