Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authorization added in headers for gateway-backend api #18

Merged
merged 1 commit into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
@@ -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 ';
24 changes: 24 additions & 0 deletions src/services/axios.service.ts
Original file line number Diff line number Diff line change
@@ -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 '';
}
};