From 9abe9ca5b1810d824b1f3d650da20eaac9e0eafd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CArslanKibria=E2=80=9D?= <“kibriya.mushtaq@ferrum.network”> Date: Wed, 22 Mar 2023 00:45:13 +0500 Subject: [PATCH] Auth added in headers for gateway-backend api --- package.json | 1 + src/constants/constants.ts | 1 + src/services/axios.service.ts | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/package.json b/package.json index 1b5094f..9ceae17 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "dependencies": { "axios": "^1.2.6", "bullmq": "^3.5.11", + "crypto-js": "^4.1.1", "dotenv": "^16.0.3", "ethereumjs-util": "^7.1.5", "express": "^4.17.2", diff --git a/src/constants/constants.ts b/src/constants/constants.ts index 566ec00..01166c6 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -1,3 +1,4 @@ export const NAME = 'FERRUM_TOKEN_BRIDGE_POOL'; export const VERSION = '000.004'; export const CONTRACT_ADDRESS = "0x9aFe354fb34a6303a9b9C89fF43A509A5320ba2D"; +export const BEARER = 'Bearer '; \ No newline at end of file diff --git a/src/services/axios.service.ts b/src/services/axios.service.ts index 4462c7f..d178179 100644 --- a/src/services/axios.service.ts +++ b/src/services/axios.service.ts @@ -1,11 +1,35 @@ import axios from 'axios'; import dotenv from 'dotenv'; +var CryptoJS = require("crypto-js"); +import { BEARER } from '../constants/constants'; dotenv.config(); export const updateTransactionJobStatus = async (txHash: string, body: any) => { const url = process.env.GATEWAY_BACKEND_URL; + let config = { + headers: { + Authorization: getGatewayBackendToken(), + } + }; return axios.put( `${url}/api/v1/transactions/update/swap/and/withdraw/job/${txHash}`, body, + config ); }; + +const getGatewayBackendToken = () => { + return BEARER + doEncryption(); +}; + +const doEncryption = () => { + try { + const privateKey = process.env.PRIVATE_KEY as string; + const publicKey = process.env.PUBLIC_KEY as string; + var ciphertext = CryptoJS.AES.encrypt(publicKey, privateKey); + return ciphertext; + } catch (e) { + console.log(e); + return ''; + } +};