@trustchex/react-native-sdk 1.381.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.
- package/android/src/main/java/com/trustchex/reactnativesdk/TrustchexSDKModule.kt +2 -8
- package/android/src/main/java/com/trustchex/reactnativesdk/camera/TrustchexCameraView.kt +60 -13
- package/android/src/main/java/com/trustchex/reactnativesdk/mlkit/MLKitModule.kt +1 -1
- package/ios/Camera/TrustchexCameraView.swift +10 -13
- package/ios/MLKit/MLKitModule.swift +1 -1
- package/lib/module/Screens/Debug/BarcodeTestScreen.js +308 -0
- package/lib/module/Screens/Debug/MRZTestScreen.js +105 -13
- package/lib/module/Screens/Debug/NFCScanTestScreen.js +635 -0
- package/lib/module/Screens/Dynamic/ContractAcceptanceScreen.js +49 -32
- package/lib/module/Screens/Dynamic/IdentityDocumentEIDScanningScreen.js +22 -4
- package/lib/module/Screens/Dynamic/IdentityDocumentScanningScreen.js +5 -0
- package/lib/module/Screens/Dynamic/LivenessDetectionScreen.js +126 -27
- package/lib/module/Screens/Dynamic/VerbalConsentScreen.js +1079 -0
- package/lib/module/Screens/Dynamic/VideoCallScreen.js +678 -0
- package/lib/module/Screens/Static/OTPVerificationScreen.js +6 -0
- package/lib/module/Screens/Static/QrCodeScanningScreen.js +7 -1
- package/lib/module/Screens/Static/ResultScreen.js +154 -34
- package/lib/module/Screens/Static/VerificationSessionCheckScreen.js +59 -51
- package/lib/module/Shared/Animations/recording.json +1 -0
- package/lib/module/Shared/Animations/video-call.json +1 -0
- package/lib/module/Shared/Components/DebugNavigationPanel.js +231 -67
- package/lib/module/Shared/Components/EIDScanner.js +213 -112
- package/lib/module/Shared/Components/IdentityDocumentCamera.flows.js +5 -3
- package/lib/module/Shared/Components/IdentityDocumentCamera.js +77 -39
- package/lib/module/Shared/Components/IdentityDocumentCamera.utils.js +13 -4
- package/lib/module/Shared/Components/NavigationManager.js +39 -19
- package/lib/module/Shared/Contexts/AppContext.js +1 -0
- package/lib/module/Shared/EIDReader/aesSecureMessagingWrapper.js +51 -0
- package/lib/module/Shared/EIDReader/apduLevelPACECapable.js +3 -0
- package/lib/module/Shared/EIDReader/bacKey.js +16 -2
- package/lib/module/Shared/EIDReader/eidReader.js +354 -13
- package/lib/module/Shared/EIDReader/eidService.js +25 -1
- package/lib/module/Shared/EIDReader/nfcManagerCardService.js +4 -7
- package/lib/module/Shared/EIDReader/paceInfo.js +85 -0
- package/lib/module/Shared/EIDReader/paceKeySpec.js +51 -0
- package/lib/module/Shared/EIDReader/protocol/paceAPDUSender.js +100 -0
- package/lib/module/Shared/EIDReader/protocol/paceProtocol.js +655 -0
- package/lib/module/Shared/EIDReader/protocol/paceResult.js +37 -0
- package/lib/module/Shared/EIDReader/secureMessagingWrapper.js +27 -4
- package/lib/module/Shared/EIDReader/smartcards/commandAPDU.js +2 -1
- package/lib/module/Shared/EIDReader/tlv/tlv.helpers.js +1 -1
- package/lib/module/Shared/EIDReader/tlv/tlv.utils.js +6 -3
- package/lib/module/Shared/EIDReader/utils/aesCrypto.utils.js +189 -0
- package/lib/module/Shared/Libs/SignalingClient.js +128 -0
- package/lib/module/Shared/Libs/analytics.utils.js +8 -0
- package/lib/module/Shared/Libs/contains.js +1 -40
- package/lib/module/Shared/Libs/country-display.utils.js +34 -0
- package/lib/module/Shared/Libs/deeplink.utils.js +9 -1
- package/lib/module/Shared/Libs/demo.utils.js +8 -0
- package/lib/module/Shared/Libs/http-client.js +9 -0
- package/lib/module/Shared/Libs/mrz.utils.js +3 -2
- package/lib/module/Shared/Libs/promise.utils.js +16 -2
- package/lib/module/Shared/Libs/status-bar.utils.js +23 -0
- package/lib/module/Shared/Services/DataUploadService.js +294 -0
- package/lib/module/Shared/Services/VideoSessionService.js +156 -0
- package/lib/module/Shared/Services/WebRTCService.js +510 -0
- package/lib/module/Shared/Types/analytics.types.js +4 -0
- package/lib/module/Translation/Resources/en.js +61 -2
- package/lib/module/Translation/Resources/tr.js +61 -2
- package/lib/module/Trustchex.js +64 -20
- package/lib/module/version.js +1 -1
- package/lib/typescript/src/Screens/Debug/BarcodeTestScreen.d.ts +3 -0
- package/lib/typescript/src/Screens/Debug/BarcodeTestScreen.d.ts.map +1 -0
- package/lib/typescript/src/Screens/Debug/MRZTestScreen.d.ts.map +1 -1
- package/lib/typescript/src/Screens/Debug/NFCScanTestScreen.d.ts +3 -0
- package/lib/typescript/src/Screens/Debug/NFCScanTestScreen.d.ts.map +1 -0
- package/lib/typescript/src/Screens/Dynamic/ContractAcceptanceScreen.d.ts.map +1 -1
- package/lib/typescript/src/Screens/Dynamic/IdentityDocumentEIDScanningScreen.d.ts.map +1 -1
- package/lib/typescript/src/Screens/Dynamic/IdentityDocumentScanningScreen.d.ts.map +1 -1
- package/lib/typescript/src/Screens/Dynamic/LivenessDetectionScreen.d.ts.map +1 -1
- package/lib/typescript/src/Screens/Dynamic/VerbalConsentScreen.d.ts +3 -0
- package/lib/typescript/src/Screens/Dynamic/VerbalConsentScreen.d.ts.map +1 -0
- package/lib/typescript/src/Screens/Dynamic/VideoCallScreen.d.ts +3 -0
- package/lib/typescript/src/Screens/Dynamic/VideoCallScreen.d.ts.map +1 -0
- package/lib/typescript/src/Screens/Static/OTPVerificationScreen.d.ts.map +1 -1
- package/lib/typescript/src/Screens/Static/QrCodeScanningScreen.d.ts.map +1 -1
- package/lib/typescript/src/Screens/Static/ResultScreen.d.ts.map +1 -1
- package/lib/typescript/src/Screens/Static/VerificationSessionCheckScreen.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Components/DebugNavigationPanel.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Components/EIDScanner.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 +1 -1
- package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.flows.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.utils.d.ts +5 -0
- package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.utils.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Components/NavigationManager.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Contexts/AppContext.d.ts +1 -0
- package/lib/typescript/src/Shared/Contexts/AppContext.d.ts.map +1 -1
- package/lib/typescript/src/Shared/EIDReader/aesSecureMessagingWrapper.d.ts +18 -0
- package/lib/typescript/src/Shared/EIDReader/aesSecureMessagingWrapper.d.ts.map +1 -0
- package/lib/typescript/src/Shared/EIDReader/apduLevelPACECapable.d.ts +23 -0
- package/lib/typescript/src/Shared/EIDReader/apduLevelPACECapable.d.ts.map +1 -0
- package/lib/typescript/src/Shared/EIDReader/bacKey.d.ts +6 -0
- package/lib/typescript/src/Shared/EIDReader/bacKey.d.ts.map +1 -1
- package/lib/typescript/src/Shared/EIDReader/eidReader.d.ts.map +1 -1
- package/lib/typescript/src/Shared/EIDReader/eidService.d.ts +9 -0
- package/lib/typescript/src/Shared/EIDReader/eidService.d.ts.map +1 -1
- package/lib/typescript/src/Shared/EIDReader/nfcManagerCardService.d.ts.map +1 -1
- package/lib/typescript/src/Shared/EIDReader/paceInfo.d.ts +50 -0
- package/lib/typescript/src/Shared/EIDReader/paceInfo.d.ts.map +1 -0
- package/lib/typescript/src/Shared/EIDReader/paceKeySpec.d.ts +30 -0
- package/lib/typescript/src/Shared/EIDReader/paceKeySpec.d.ts.map +1 -0
- package/lib/typescript/src/Shared/EIDReader/protocol/paceAPDUSender.d.ts +17 -0
- package/lib/typescript/src/Shared/EIDReader/protocol/paceAPDUSender.d.ts.map +1 -0
- package/lib/typescript/src/Shared/EIDReader/protocol/paceProtocol.d.ts +105 -0
- package/lib/typescript/src/Shared/EIDReader/protocol/paceProtocol.d.ts.map +1 -0
- package/lib/typescript/src/Shared/EIDReader/protocol/paceResult.d.ts +24 -0
- package/lib/typescript/src/Shared/EIDReader/protocol/paceResult.d.ts.map +1 -0
- package/lib/typescript/src/Shared/EIDReader/secureMessagingWrapper.d.ts +15 -0
- package/lib/typescript/src/Shared/EIDReader/secureMessagingWrapper.d.ts.map +1 -1
- package/lib/typescript/src/Shared/EIDReader/smartcards/commandAPDU.d.ts.map +1 -1
- package/lib/typescript/src/Shared/EIDReader/tlv/tlv.utils.d.ts.map +1 -1
- package/lib/typescript/src/Shared/EIDReader/utils/aesCrypto.utils.d.ts +39 -0
- package/lib/typescript/src/Shared/EIDReader/utils/aesCrypto.utils.d.ts.map +1 -0
- package/lib/typescript/src/Shared/Libs/SignalingClient.d.ts +24 -0
- package/lib/typescript/src/Shared/Libs/SignalingClient.d.ts.map +1 -0
- package/lib/typescript/src/Shared/Libs/analytics.utils.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Libs/contains.d.ts +0 -7
- package/lib/typescript/src/Shared/Libs/contains.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Libs/country-display.utils.d.ts +2 -0
- package/lib/typescript/src/Shared/Libs/country-display.utils.d.ts.map +1 -0
- package/lib/typescript/src/Shared/Libs/deeplink.utils.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Libs/demo.utils.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Libs/http-client.d.ts +1 -1
- package/lib/typescript/src/Shared/Libs/http-client.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Libs/mrz.utils.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Libs/promise.utils.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Libs/status-bar.utils.d.ts +9 -0
- package/lib/typescript/src/Shared/Libs/status-bar.utils.d.ts.map +1 -0
- package/lib/typescript/src/Shared/Services/DataUploadService.d.ts +25 -0
- package/lib/typescript/src/Shared/Services/DataUploadService.d.ts.map +1 -0
- package/lib/typescript/src/Shared/Services/VideoSessionService.d.ts +33 -0
- package/lib/typescript/src/Shared/Services/VideoSessionService.d.ts.map +1 -0
- package/lib/typescript/src/Shared/Services/WebRTCService.d.ts +58 -0
- package/lib/typescript/src/Shared/Services/WebRTCService.d.ts.map +1 -0
- package/lib/typescript/src/Shared/Types/analytics.types.d.ts +4 -0
- package/lib/typescript/src/Shared/Types/analytics.types.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Types/identificationInfo.d.ts +13 -1
- package/lib/typescript/src/Shared/Types/identificationInfo.d.ts.map +1 -1
- package/lib/typescript/src/Translation/Resources/en.d.ts +60 -1
- package/lib/typescript/src/Translation/Resources/en.d.ts.map +1 -1
- package/lib/typescript/src/Translation/Resources/tr.d.ts +60 -1
- package/lib/typescript/src/Translation/Resources/tr.d.ts.map +1 -1
- package/lib/typescript/src/Trustchex.d.ts.map +1 -1
- package/lib/typescript/src/version.d.ts +1 -1
- package/package.json +35 -5
- package/src/Screens/Debug/BarcodeTestScreen.tsx +317 -0
- package/src/Screens/Debug/MRZTestScreen.tsx +107 -13
- package/src/Screens/Debug/NFCScanTestScreen.tsx +692 -0
- package/src/Screens/Dynamic/ContractAcceptanceScreen.tsx +58 -35
- package/src/Screens/Dynamic/IdentityDocumentEIDScanningScreen.tsx +27 -4
- package/src/Screens/Dynamic/IdentityDocumentScanningScreen.tsx +6 -0
- package/src/Screens/Dynamic/LivenessDetectionScreen.tsx +156 -27
- package/src/Screens/Dynamic/VerbalConsentScreen.tsx +1401 -0
- package/src/Screens/Dynamic/VideoCallScreen.tsx +766 -0
- package/src/Screens/Static/OTPVerificationScreen.tsx +6 -0
- package/src/Screens/Static/QrCodeScanningScreen.tsx +7 -1
- package/src/Screens/Static/ResultScreen.tsx +235 -48
- package/src/Screens/Static/VerificationSessionCheckScreen.tsx +67 -72
- package/src/Shared/Animations/recording.json +1 -0
- package/src/Shared/Animations/video-call.json +1 -0
- package/src/Shared/Components/DebugNavigationPanel.tsx +252 -51
- package/src/Shared/Components/EIDScanner.tsx +223 -116
- package/src/Shared/Components/IdentityDocumentCamera.flows.ts +7 -4
- package/src/Shared/Components/IdentityDocumentCamera.tsx +224 -188
- package/src/Shared/Components/IdentityDocumentCamera.utils.ts +13 -4
- package/src/Shared/Components/NavigationManager.tsx +41 -19
- package/src/Shared/Contexts/AppContext.ts +2 -0
- package/src/Shared/EIDReader/aesSecureMessagingWrapper.ts +69 -0
- package/src/Shared/EIDReader/apduLevelPACECapable.ts +34 -0
- package/src/Shared/EIDReader/bacKey.ts +24 -8
- package/src/Shared/EIDReader/eidReader.ts +398 -12
- package/src/Shared/EIDReader/eidService.ts +49 -1
- package/src/Shared/EIDReader/nfcManagerCardService.ts +4 -6
- package/src/Shared/EIDReader/paceInfo.ts +159 -0
- package/src/Shared/EIDReader/paceKeySpec.ts +56 -0
- package/src/Shared/EIDReader/protocol/paceAPDUSender.ts +163 -0
- package/src/Shared/EIDReader/protocol/paceProtocol.ts +946 -0
- package/src/Shared/EIDReader/protocol/paceResult.ts +62 -0
- package/src/Shared/EIDReader/secureMessagingWrapper.ts +28 -10
- package/src/Shared/EIDReader/smartcards/commandAPDU.ts +2 -1
- package/src/Shared/EIDReader/tlv/tlv.helpers.ts +1 -1
- package/src/Shared/EIDReader/tlv/tlv.utils.ts +8 -5
- package/src/Shared/EIDReader/utils/aesCrypto.utils.ts +217 -0
- package/src/Shared/Libs/SignalingClient.ts +189 -0
- package/src/Shared/Libs/analytics.utils.ts +8 -0
- package/src/Shared/Libs/contains.ts +0 -53
- package/src/Shared/Libs/country-display.utils.ts +55 -0
- package/src/Shared/Libs/crypto.utils.ts +2 -2
- package/src/Shared/Libs/deeplink.utils.ts +12 -1
- package/src/Shared/Libs/demo.utils.ts +10 -0
- package/src/Shared/Libs/http-client.ts +19 -1
- package/src/Shared/Libs/mrz.utils.ts +3 -2
- package/src/Shared/Libs/promise.utils.ts +16 -2
- package/src/Shared/Libs/status-bar.utils.ts +21 -0
- package/src/Shared/Services/DataUploadService.ts +395 -0
- package/src/Shared/Services/VideoSessionService.ts +190 -0
- package/src/Shared/Services/WebRTCService.ts +636 -0
- package/src/Shared/Types/analytics.types.ts +4 -0
- package/src/Shared/Types/identificationInfo.ts +16 -1
- package/src/Translation/Resources/en.ts +88 -3
- package/src/Translation/Resources/tr.ts +89 -3
- package/src/Trustchex.tsx +65 -19
- package/src/version.ts +1 -1
|
@@ -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
|
+
}
|