@oobit/react-native-sdk 1.1.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/WidgetSDK.d.ts.map +1 -1
- package/dist/WidgetSDK.js +12 -56
- package/dist/WidgetSDK.js.map +1 -1
- package/dist/config.d.ts +6 -7
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +21 -7
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +1 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -18
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -36
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/WidgetSDK.tsx +12 -68
- package/src/config.ts +21 -10
- package/src/index.ts +1 -42
- package/src/types.ts +3 -38
- package/dist/biometricUtils.d.ts +0 -66
- package/dist/biometricUtils.d.ts.map +0 -1
- package/dist/biometricUtils.js +0 -183
- package/dist/biometricUtils.js.map +0 -1
- package/dist/cryptoUtils.d.ts +0 -64
- package/dist/cryptoUtils.d.ts.map +0 -1
- package/dist/cryptoUtils.js +0 -123
- package/dist/cryptoUtils.js.map +0 -1
- package/src/cryptoUtils.ts +0 -131
package/dist/cryptoUtils.d.ts
DELETED
|
@@ -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"}
|
package/dist/cryptoUtils.js
DELETED
|
@@ -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
|
package/dist/cryptoUtils.js.map
DELETED
|
@@ -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"}
|
package/src/cryptoUtils.ts
DELETED
|
@@ -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
|
-
}
|