The following changes were made by the replace_file_content tool to: /root/aadharbot/gateways.js. If relevant, proactively run terminal commands to execute this code for the USER. Don't ask for permission. [diff_block_start] @@ -16,6 +16,39 @@ return JSON.parse(cleanJson); } +/** + * Decrypts AES-256-GCM payloads from CoinPay (pay.coinsll.com). + */ +function decryptCoinPayToken(token) { + if (!token || typeof token !== 'string') { + throw new Error('CoinPay session token is missing'); + } + const parts = token.split('.'); + if (parts.length !== 4 || parts[0] !== 'v1') { + throw new Error('Invalid CoinPay session token format'); + } + + const b64urlToBuf = (s) => { + const b64 = s.replace(/-/g, '+').replace(/_/g, '/').padEnd(Math.ceil(s.length / 4) * 4, '='); + return Buffer.from(b64, 'base64'); + }; + + const rawKey = '90Esa3lAlDqYqQjymRI8Fn2rQRtQ516is_VkZ41EH5IQv0w0jnM-TueWRR65XJla'; + const key = crypto.createHash('sha256').update(rawKey, 'utf8').digest(); + const iv = b64urlToBuf(parts[1]); + const ciphertext = b64urlToBuf(parts[2]); + const tag = b64urlToBuf(parts[3]); + + const decipher = crypto.createDecipheriv('aes-256-gcm', key, iv); + decipher.setAAD(Buffer.from('coinpay.checkout.v1', 'utf8')); + decipher.setAuthTag(tag); + + let decrypted = decipher.update(ciphertext, null, 'utf8'); + decrypted += decipher.final('utf8'); + + return JSON.parse(decrypted); +} + function formatDateIST(date) { const formatter = new Intl.DateTimeFormat('en-US', { timeZone: 'Asia/Kolkata', [diff_block_end] Please note that the above snippet only shows the MODIFIED lines from the last change. It shows up to 3 lines of unchanged lines before and after the modified lines. The actual file contents may have many more lines not shown.