@oobit/react-native-sdk 1.0.7 → 2.0.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.
@@ -1,64 +0,0 @@
1
- /**
2
- * Crypto Utilities for Card Details Session Generation
3
- *
4
- * CRITICAL: This implementation MUST match Android's PublicKeyCryptoHelper.kt exactly:
5
- * - RSA Algorithm: RSA/ECB/OAEPWithSHA-1AndMGF1Padding
6
- * - Secret Key: UUID without dashes (32 hex chars = 16 bytes = 128-bit)
7
- * - Input to RSA: secretKey as Base64 string
8
- * - Output: encrypted sessionId as Base64 string
9
- *
10
- * Uses node-forge for pure JavaScript RSA-OAEP encryption.
11
- * This works in Expo Go without native modules.
12
- */
13
- /**
14
- * Generates a random hex key matching Android's generateRandomHexKey()
15
- *
16
- * Creates a UUID v4 without dashes = 32 hex characters = 16 bytes = 128-bit key
17
- * This matches the format used in Android's PublicKeyCryptoHelper
18
- *
19
- * @returns 32-character hexadecimal string
20
- */
21
- export declare function generateRandomHexKey(): string;
22
- /**
23
- * Converts a hex string to Base64 encoding
24
- * Matches Android's hexToBase64() method
25
- *
26
- * @param hexString - Hexadecimal string (must have even length)
27
- * @returns Base64 encoded string
28
- */
29
- export declare function hexToBase64(hexString: string): string;
30
- /**
31
- * Encrypts data using RSA with OAEP-SHA1 padding
32
- *
33
- * MUST match Android's RSA/ECB/OAEPWithSHA-1AndMGF1Padding algorithm
34
- *
35
- * @param data - Plain text data to encrypt (Base64 string of the secret key)
36
- * @param publicKeyPem - RSA public key in PEM format
37
- * @returns Encrypted data as Base64 string
38
- * @throws Error if encryption fails
39
- */
40
- export declare function encryptWithRSA(data: string, publicKeyPem: string): string;
41
- /**
42
- * Generates session credentials for card details API request
43
- *
44
- * This is the main function that creates the cryptographically linked
45
- * sessionId + secretKey pair, matching Android's PublicKeyCryptoHelper.generateSessionId()
46
- *
47
- * Flow:
48
- * 1. Generate random secretKeyHex (UUID without dashes)
49
- * 2. Convert secretKeyHex to Base64
50
- * 3. Encrypt Base64 key with RSA public key → sessionId
51
- * 4. Return both secretKeyHex (for client-side decryption) and sessionId (for API header)
52
- *
53
- * @param publicKeyPem - RSA public key in PEM format (from widget)
54
- * @returns Object containing:
55
- * - secretKeyHex: Keep on device for AES-GCM decryption (32 hex chars)
56
- * - sessionId: Send to API as SessionId header (RSA-encrypted, Base64)
57
- * @throws Error if key generation or encryption fails
58
- */
59
- export declare function generateSessionCredentials(publicKeyPem: string): SessionCredentials;
60
- export interface SessionCredentials {
61
- secretKeyHex: string;
62
- sessionId: string;
63
- }
64
- //# sourceMappingURL=cryptoUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cryptoUtils.d.ts","sourceRoot":"","sources":["../src/cryptoUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAU7C;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAUrD;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAmBzE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,0BAA0B,CAAC,YAAY,EAAE,MAAM,GAAG,kBAAkB,CAqBnF;AAGD,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB"}
@@ -1,123 +0,0 @@
1
- "use strict";
2
- /**
3
- * Crypto Utilities for Card Details Session Generation
4
- *
5
- * CRITICAL: This implementation MUST match Android's PublicKeyCryptoHelper.kt exactly:
6
- * - RSA Algorithm: RSA/ECB/OAEPWithSHA-1AndMGF1Padding
7
- * - Secret Key: UUID without dashes (32 hex chars = 16 bytes = 128-bit)
8
- * - Input to RSA: secretKey as Base64 string
9
- * - Output: encrypted sessionId as Base64 string
10
- *
11
- * Uses node-forge for pure JavaScript RSA-OAEP encryption.
12
- * This works in Expo Go without native modules.
13
- */
14
- var __importDefault = (this && this.__importDefault) || function (mod) {
15
- return (mod && mod.__esModule) ? mod : { "default": mod };
16
- };
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.generateRandomHexKey = generateRandomHexKey;
19
- exports.hexToBase64 = hexToBase64;
20
- exports.encryptWithRSA = encryptWithRSA;
21
- exports.generateSessionCredentials = generateSessionCredentials;
22
- const node_forge_1 = __importDefault(require("node-forge"));
23
- /**
24
- * Generates a random hex key matching Android's generateRandomHexKey()
25
- *
26
- * Creates a UUID v4 without dashes = 32 hex characters = 16 bytes = 128-bit key
27
- * This matches the format used in Android's PublicKeyCryptoHelper
28
- *
29
- * @returns 32-character hexadecimal string
30
- */
31
- function generateRandomHexKey() {
32
- // Generate UUID v4 pattern and remove dashes
33
- // This matches Android's java.util.UUID.randomUUID().toString().replace("-", "")
34
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
35
- .replace(/[xy]/g, (c) => {
36
- const r = (Math.random() * 16) | 0;
37
- const v = c === 'x' ? r : (r & 0x3) | 0x8;
38
- return v.toString(16);
39
- })
40
- .replace(/-/g, '');
41
- }
42
- /**
43
- * Converts a hex string to Base64 encoding
44
- * Matches Android's hexToBase64() method
45
- *
46
- * @param hexString - Hexadecimal string (must have even length)
47
- * @returns Base64 encoded string
48
- */
49
- function hexToBase64(hexString) {
50
- // Convert hex string to binary string
51
- let binaryString = '';
52
- for (let i = 0; i < hexString.length; i += 2) {
53
- const byte = parseInt(hexString.substring(i, i + 2), 16);
54
- binaryString += String.fromCharCode(byte);
55
- }
56
- // Use forge's utility for Base64 encoding
57
- return node_forge_1.default.util.encode64(binaryString);
58
- }
59
- /**
60
- * Encrypts data using RSA with OAEP-SHA1 padding
61
- *
62
- * MUST match Android's RSA/ECB/OAEPWithSHA-1AndMGF1Padding algorithm
63
- *
64
- * @param data - Plain text data to encrypt (Base64 string of the secret key)
65
- * @param publicKeyPem - RSA public key in PEM format
66
- * @returns Encrypted data as Base64 string
67
- * @throws Error if encryption fails
68
- */
69
- function encryptWithRSA(data, publicKeyPem) {
70
- try {
71
- // Parse the PEM-formatted public key
72
- const publicKey = node_forge_1.default.pki.publicKeyFromPem(publicKeyPem);
73
- // Encrypt using RSA-OAEP with SHA-1 (matches Android's OAEPWithSHA-1AndMGF1Padding)
74
- const encrypted = publicKey.encrypt(data, 'RSA-OAEP', {
75
- md: node_forge_1.default.md.sha1.create(),
76
- mgf1: {
77
- md: node_forge_1.default.md.sha1.create(),
78
- },
79
- });
80
- // Encode to Base64
81
- return node_forge_1.default.util.encode64(encrypted);
82
- }
83
- catch (error) {
84
- console.error('[CryptoUtils] RSA encryption failed:', error);
85
- throw new Error('Failed to encrypt session data');
86
- }
87
- }
88
- /**
89
- * Generates session credentials for card details API request
90
- *
91
- * This is the main function that creates the cryptographically linked
92
- * sessionId + secretKey pair, matching Android's PublicKeyCryptoHelper.generateSessionId()
93
- *
94
- * Flow:
95
- * 1. Generate random secretKeyHex (UUID without dashes)
96
- * 2. Convert secretKeyHex to Base64
97
- * 3. Encrypt Base64 key with RSA public key → sessionId
98
- * 4. Return both secretKeyHex (for client-side decryption) and sessionId (for API header)
99
- *
100
- * @param publicKeyPem - RSA public key in PEM format (from widget)
101
- * @returns Object containing:
102
- * - secretKeyHex: Keep on device for AES-GCM decryption (32 hex chars)
103
- * - sessionId: Send to API as SessionId header (RSA-encrypted, Base64)
104
- * @throws Error if key generation or encryption fails
105
- */
106
- function generateSessionCredentials(publicKeyPem) {
107
- // Validate public key
108
- if (!publicKeyPem || !publicKeyPem.includes('BEGIN PUBLIC KEY')) {
109
- throw new Error('Invalid RSA public key format');
110
- }
111
- // Step 1: Generate random secret key (matches Android's generateRandomHexKey)
112
- const secretKeyHex = generateRandomHexKey();
113
- // Step 2: Convert to Base64 (matches Android's hexToBase64)
114
- const secretKeyBase64 = hexToBase64(secretKeyHex);
115
- // Step 3: Encrypt with RSA public key (matches Android's encryptWithPublicKey)
116
- const sessionId = encryptWithRSA(secretKeyBase64, publicKeyPem);
117
- console.log('[CryptoUtils] Session credentials generated successfully');
118
- return {
119
- secretKeyHex,
120
- sessionId,
121
- };
122
- }
123
- //# sourceMappingURL=cryptoUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cryptoUtils.js","sourceRoot":"","sources":["../src/cryptoUtils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;;;AAYH,oDAUC;AASD,kCAUC;AAYD,wCAmBC;AAoBD,gEAqBC;AA/GD,4DAA+B;AAE/B;;;;;;;GAOG;AACH,SAAgB,oBAAoB;IAClC,6CAA6C;IAC7C,iFAAiF;IACjF,OAAO,sCAAsC;SAC1C,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;QACtB,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;QACnC,MAAM,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;QAC1C,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC,CAAC;SACD,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AACvB,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,WAAW,CAAC,SAAiB;IAC3C,sCAAsC;IACtC,IAAI,YAAY,GAAG,EAAE,CAAC;IACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,GAAG,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACzD,YAAY,IAAI,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;IAED,0CAA0C;IAC1C,OAAO,oBAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,cAAc,CAAC,IAAY,EAAE,YAAoB;IAC/D,IAAI,CAAC;QACH,qCAAqC;QACrC,MAAM,SAAS,GAAG,oBAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;QAE3D,oFAAoF;QACpF,MAAM,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,EAAE;YACpD,EAAE,EAAE,oBAAK,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE;YAC1B,IAAI,EAAE;gBACJ,EAAE,EAAE,oBAAK,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE;aAC3B;SACF,CAAC,CAAC;QAEH,mBAAmB;QACnB,OAAO,oBAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;QAC7D,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,0BAA0B,CAAC,YAAoB;IAC7D,sBAAsB;IACtB,IAAI,CAAC,YAAY,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAChE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnD,CAAC;IAED,8EAA8E;IAC9E,MAAM,YAAY,GAAG,oBAAoB,EAAE,CAAC;IAE5C,4DAA4D;IAC5D,MAAM,eAAe,GAAG,WAAW,CAAC,YAAY,CAAC,CAAC;IAElD,+EAA+E;IAC/E,MAAM,SAAS,GAAG,cAAc,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;IAEhE,OAAO,CAAC,GAAG,CAAC,0DAA0D,CAAC,CAAC;IAExE,OAAO;QACL,YAAY;QACZ,SAAS;KACV,CAAC;AACJ,CAAC"}
@@ -1,183 +0,0 @@
1
- /**
2
- * Biometric Authentication Utilities
3
- *
4
- * Provides cross-platform biometric authentication for card details access.
5
- * Uses expo-local-authentication which works in Expo Go without native modules.
6
- *
7
- * @requires expo-local-authentication - included in Expo SDK
8
- */
9
-
10
- import * as LocalAuthentication from 'expo-local-authentication';
11
-
12
- /**
13
- * Result of a biometric authentication attempt
14
- */
15
- export interface BiometricResult {
16
- /** Whether authentication was successful */
17
- success: boolean;
18
- /** Error details if authentication failed */
19
- error?: {
20
- reason: 'cancelled' | 'failed' | 'not_available' | 'not_enrolled';
21
- message?: string;
22
- };
23
- }
24
-
25
- /**
26
- * Information about biometric capabilities on the device
27
- */
28
- export interface BiometricAvailability {
29
- /** Whether any biometric authentication is available */
30
- available: boolean;
31
- /** The types of biometry available */
32
- biometryTypes: LocalAuthentication.AuthenticationType[];
33
- }
34
-
35
- /**
36
- * Checks if biometric authentication is available on the device
37
- *
38
- * @returns Object containing availability status and biometry types
39
- */
40
- export async function isBiometricAvailable(): Promise<BiometricAvailability> {
41
- try {
42
- const hasHardware = await LocalAuthentication.hasHardwareAsync();
43
- const isEnrolled = await LocalAuthentication.isEnrolledAsync();
44
- const supportedTypes = await LocalAuthentication.supportedAuthenticationTypesAsync();
45
-
46
- return {
47
- available: hasHardware && isEnrolled,
48
- biometryTypes: supportedTypes,
49
- };
50
- } catch (error) {
51
- console.error('[BiometricUtils] Error checking biometric availability:', error);
52
- return {
53
- available: false,
54
- biometryTypes: [],
55
- };
56
- }
57
- }
58
-
59
- /**
60
- * Prompts the user for biometric authentication
61
- *
62
- * This function should be called before generating session credentials
63
- * for viewing card details. It ensures proper user verification before
64
- * accessing sensitive payment card information.
65
- *
66
- * @param promptMessage - Message to display in the biometric prompt
67
- * @returns Result indicating success or failure with reason
68
- *
69
- * @example
70
- * ```typescript
71
- * const result = await authenticateWithBiometrics('Authenticate to view card details');
72
- * if (result.success) {
73
- * // Proceed with generating session credentials
74
- * } else {
75
- * // Handle failure based on result.error.reason
76
- * }
77
- * ```
78
- */
79
- export async function authenticateWithBiometrics(
80
- promptMessage: string = 'Authenticate to view card details'
81
- ): Promise<BiometricResult> {
82
- try {
83
- // First check if biometrics are available
84
- const hasHardware = await LocalAuthentication.hasHardwareAsync();
85
-
86
- if (!hasHardware) {
87
- console.log('[BiometricUtils] Biometrics not available on device');
88
- return {
89
- success: false,
90
- error: {
91
- reason: 'not_available',
92
- message: 'Biometric authentication is not available on this device',
93
- },
94
- };
95
- }
96
-
97
- // Check if biometrics are enrolled
98
- const isEnrolled = await LocalAuthentication.isEnrolledAsync();
99
-
100
- if (!isEnrolled) {
101
- console.log('[BiometricUtils] No biometrics enrolled');
102
- return {
103
- success: false,
104
- error: {
105
- reason: 'not_enrolled',
106
- message: 'No biometric authentication is set up on this device',
107
- },
108
- };
109
- }
110
-
111
- console.log('[BiometricUtils] Attempting biometric authentication...');
112
-
113
- // Perform the biometric authentication
114
- const result = await LocalAuthentication.authenticateAsync({
115
- promptMessage,
116
- cancelLabel: 'Cancel',
117
- disableDeviceFallback: false, // Allow PIN/password fallback
118
- fallbackLabel: 'Use Passcode',
119
- });
120
-
121
- if (result.success) {
122
- console.log('[BiometricUtils] Biometric authentication successful');
123
- return { success: true };
124
- }
125
-
126
- // Handle various failure reasons
127
- console.log('[BiometricUtils] Biometric authentication failed:', result.error);
128
-
129
- let reason: 'cancelled' | 'failed' | 'not_available' | 'not_enrolled' = 'failed';
130
-
131
- if (result.error === 'user_cancel' || result.error === 'system_cancel') {
132
- reason = 'cancelled';
133
- } else if (result.error === 'not_enrolled') {
134
- reason = 'not_enrolled';
135
- } else if (result.error === 'not_available') {
136
- reason = 'not_available';
137
- }
138
-
139
- return {
140
- success: false,
141
- error: {
142
- reason,
143
- message: result.warning || 'Authentication failed',
144
- },
145
- };
146
- } catch (error) {
147
- console.error('[BiometricUtils] Biometric authentication error:', error);
148
-
149
- const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
150
-
151
- return {
152
- success: false,
153
- error: {
154
- reason: 'failed',
155
- message: errorMessage,
156
- },
157
- };
158
- }
159
- }
160
-
161
- /**
162
- * Gets a user-friendly description of the biometric type
163
- *
164
- * @param biometryType - The biometry type from the device
165
- * @returns Human-readable string for the biometry type
166
- */
167
- export function getBiometryTypeLabel(
168
- biometryType: LocalAuthentication.AuthenticationType
169
- ): string {
170
- switch (biometryType) {
171
- case LocalAuthentication.AuthenticationType.FACIAL_RECOGNITION:
172
- return 'Face ID';
173
- case LocalAuthentication.AuthenticationType.FINGERPRINT:
174
- return 'Touch ID';
175
- case LocalAuthentication.AuthenticationType.IRIS:
176
- return 'Iris';
177
- default:
178
- return 'Biometric Authentication';
179
- }
180
- }
181
-
182
- // Re-export AuthenticationType for convenience
183
- export { AuthenticationType } from 'expo-local-authentication';
@@ -1,131 +0,0 @@
1
- /**
2
- * Crypto Utilities for Card Details Session Generation
3
- *
4
- * CRITICAL: This implementation MUST match Android's PublicKeyCryptoHelper.kt exactly:
5
- * - RSA Algorithm: RSA/ECB/OAEPWithSHA-1AndMGF1Padding
6
- * - Secret Key: UUID without dashes (32 hex chars = 16 bytes = 128-bit)
7
- * - Input to RSA: secretKey as Base64 string
8
- * - Output: encrypted sessionId as Base64 string
9
- *
10
- * Uses node-forge for pure JavaScript RSA-OAEP encryption.
11
- * This works in Expo Go without native modules.
12
- */
13
-
14
- import forge from 'node-forge';
15
-
16
- /**
17
- * Generates a random hex key matching Android's generateRandomHexKey()
18
- *
19
- * Creates a UUID v4 without dashes = 32 hex characters = 16 bytes = 128-bit key
20
- * This matches the format used in Android's PublicKeyCryptoHelper
21
- *
22
- * @returns 32-character hexadecimal string
23
- */
24
- export function generateRandomHexKey(): string {
25
- // Generate UUID v4 pattern and remove dashes
26
- // This matches Android's java.util.UUID.randomUUID().toString().replace("-", "")
27
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
28
- .replace(/[xy]/g, (c) => {
29
- const r = (Math.random() * 16) | 0;
30
- const v = c === 'x' ? r : (r & 0x3) | 0x8;
31
- return v.toString(16);
32
- })
33
- .replace(/-/g, '');
34
- }
35
-
36
- /**
37
- * Converts a hex string to Base64 encoding
38
- * Matches Android's hexToBase64() method
39
- *
40
- * @param hexString - Hexadecimal string (must have even length)
41
- * @returns Base64 encoded string
42
- */
43
- export function hexToBase64(hexString: string): string {
44
- // Convert hex string to binary string
45
- let binaryString = '';
46
- for (let i = 0; i < hexString.length; i += 2) {
47
- const byte = parseInt(hexString.substring(i, i + 2), 16);
48
- binaryString += String.fromCharCode(byte);
49
- }
50
-
51
- // Use forge's utility for Base64 encoding
52
- return forge.util.encode64(binaryString);
53
- }
54
-
55
- /**
56
- * Encrypts data using RSA with OAEP-SHA1 padding
57
- *
58
- * MUST match Android's RSA/ECB/OAEPWithSHA-1AndMGF1Padding algorithm
59
- *
60
- * @param data - Plain text data to encrypt (Base64 string of the secret key)
61
- * @param publicKeyPem - RSA public key in PEM format
62
- * @returns Encrypted data as Base64 string
63
- * @throws Error if encryption fails
64
- */
65
- export function encryptWithRSA(data: string, publicKeyPem: string): string {
66
- try {
67
- // Parse the PEM-formatted public key
68
- const publicKey = forge.pki.publicKeyFromPem(publicKeyPem);
69
-
70
- // Encrypt using RSA-OAEP with SHA-1 (matches Android's OAEPWithSHA-1AndMGF1Padding)
71
- const encrypted = publicKey.encrypt(data, 'RSA-OAEP', {
72
- md: forge.md.sha1.create(),
73
- mgf1: {
74
- md: forge.md.sha1.create(),
75
- },
76
- });
77
-
78
- // Encode to Base64
79
- return forge.util.encode64(encrypted);
80
- } catch (error) {
81
- console.error('[CryptoUtils] RSA encryption failed:', error);
82
- throw new Error('Failed to encrypt session data');
83
- }
84
- }
85
-
86
- /**
87
- * Generates session credentials for card details API request
88
- *
89
- * This is the main function that creates the cryptographically linked
90
- * sessionId + secretKey pair, matching Android's PublicKeyCryptoHelper.generateSessionId()
91
- *
92
- * Flow:
93
- * 1. Generate random secretKeyHex (UUID without dashes)
94
- * 2. Convert secretKeyHex to Base64
95
- * 3. Encrypt Base64 key with RSA public key → sessionId
96
- * 4. Return both secretKeyHex (for client-side decryption) and sessionId (for API header)
97
- *
98
- * @param publicKeyPem - RSA public key in PEM format (from widget)
99
- * @returns Object containing:
100
- * - secretKeyHex: Keep on device for AES-GCM decryption (32 hex chars)
101
- * - sessionId: Send to API as SessionId header (RSA-encrypted, Base64)
102
- * @throws Error if key generation or encryption fails
103
- */
104
- export function generateSessionCredentials(publicKeyPem: string): SessionCredentials {
105
- // Validate public key
106
- if (!publicKeyPem || !publicKeyPem.includes('BEGIN PUBLIC KEY')) {
107
- throw new Error('Invalid RSA public key format');
108
- }
109
-
110
- // Step 1: Generate random secret key (matches Android's generateRandomHexKey)
111
- const secretKeyHex = generateRandomHexKey();
112
-
113
- // Step 2: Convert to Base64 (matches Android's hexToBase64)
114
- const secretKeyBase64 = hexToBase64(secretKeyHex);
115
-
116
- // Step 3: Encrypt with RSA public key (matches Android's encryptWithPublicKey)
117
- const sessionId = encryptWithRSA(secretKeyBase64, publicKeyPem);
118
-
119
- console.log('[CryptoUtils] Session credentials generated successfully');
120
-
121
- return {
122
- secretKeyHex,
123
- sessionId,
124
- };
125
- }
126
-
127
- // Export types for type safety
128
- export interface SessionCredentials {
129
- secretKeyHex: string;
130
- sessionId: string;
131
- }