diff --git a/src/api/Agent.ts b/src/api/Agent.ts
index 81bbc687e..e2312aaef 100644
--- a/src/api/Agent.ts
+++ b/src/api/Agent.ts
@@ -1,8 +1,52 @@
-import { axiosGet } from "../services/apiRequests";
+import { axiosGet, axiosPost } from "../services/apiRequests";
import { apiRoutes } from "../config/apiRoutes";
import { getFromLocalStorage } from "./Auth";
import { storageKeys } from "../config/CommonConstant";
+export const getLedgerConfig = async () => {
+ const token = await getFromLocalStorage(storageKeys.TOKEN)
+ const details = {
+ url: `${apiRoutes.organizations.root}${apiRoutes.Agent.getLedgerConfig}`,
+ config: {
+ headers: {
+ 'Content-type': 'application/json',
+ 'Authorization': `Bearer ${token}`,
+ },
+ },
+ };
+
+ try {
+ const response = await axiosGet(details)
+ return response
+ }
+ catch (error) {
+ const err = error as Error
+ return err?.message
+ }
+}
+
+export const createPolygonKeyValuePair = async (orgId:string) => {
+ const token = await getFromLocalStorage(storageKeys.TOKEN)
+ const details = {
+ url: `${apiRoutes.organizations.root}/${orgId}${apiRoutes.Agent.createPolygonKeys}`,
+ config: {
+ headers: {
+ 'Content-type': 'application/json',
+ 'Authorization': `Bearer ${token}`,
+ },
+ },
+ };
+
+ try {
+ const response = await axiosPost(details)
+ return response
+ }
+ catch (error) {
+ const err = error as Error
+ return err?.message
+ }
+}
+
export const getAgentHealth = async (orgId:string) => {
const token = await getFromLocalStorage(storageKeys.TOKEN)
const details = {
diff --git a/src/api/Auth.ts b/src/api/Auth.ts
index bbb9087ca..52239ccce 100644
--- a/src/api/Auth.ts
+++ b/src/api/Auth.ts
@@ -225,19 +225,38 @@ export const passwordEncryption = (password: string): string => {
}
export const encryptData = (value: any): string => {
- if(typeof(value) !== 'string'){
- value = JSON.stringify(value)
- }
+
const CRYPTO_PRIVATE_KEY: string = `${envConfig.PUBLIC_CRYPTO_PRIVATE_KEY}`
- const convrtedValue: string = CryptoJS.AES.encrypt(value, CRYPTO_PRIVATE_KEY).toString()
- return convrtedValue
+
+ try {
+ const encJson: string = CryptoJS.AES.encrypt(JSON.stringify(value), CRYPTO_PRIVATE_KEY).toString();
+ let encData = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(encJson))
+
+ return encData;
+ } catch (error) {
+ // Handle encryption error
+ console.error('Encryption error:', error);
+ return '';
+ }
}
export const decryptData = (value: any): string => {
const CRYPTO_PRIVATE_KEY: string = `${envConfig.PUBLIC_CRYPTO_PRIVATE_KEY}`
- const bytes = CryptoJS.AES.decrypt(value, CRYPTO_PRIVATE_KEY)
- var originalValue: string = bytes.toString(CryptoJS.enc.Utf8);
- return originalValue
+
+ try {
+
+ let decData = CryptoJS.enc.Base64.parse(value).toString(CryptoJS.enc.Utf8)
+ let bytes = CryptoJS.AES.decrypt(decData, CRYPTO_PRIVATE_KEY).toString(CryptoJS.enc.Utf8)
+ const parsedData = JSON.parse(bytes);
+ if (typeof parsedData !== 'string') {
+ return JSON.stringify(parsedData);
+ }
+ return parsedData;
+ } catch (error) {
+ // Handle decryption error or invalid input
+ console.error('Decryption error:', error);
+ return '';
+ }
}
export const setToLocalStorage = async (key: string, value: any) =>{
@@ -273,7 +292,6 @@ export const setToCookies = (cookies: AstroCookies, key: string, value: any, opt
return;
}
- const convertedValue = encryptData(value)
// Set HttpOnly, Secure, and SameSite attributes in the options
const updatedOption: { [key: string]: any }= {
...option,
@@ -281,15 +299,14 @@ export const setToCookies = (cookies: AstroCookies, key: string, value: any, opt
secure: true, // Set to true if using HTTPS
sameSite: 'Strict',
};
- cookies.set(key, convertedValue as string, updatedOption)
+ cookies.set(key, value as string, updatedOption)
return true
}
export const getFromCookies = (cookies: AstroCookies, key: string) =>{
const value = cookies.get(key).value
- const convertedValue = value ? decryptData(value) : ''
- return convertedValue
+ return value
}
export const removeFromLocalStorage = async (key: string) => {
diff --git a/src/app/LayoutCommon.astro b/src/app/LayoutCommon.astro
index 502ded50e..785356b56 100644
--- a/src/app/LayoutCommon.astro
+++ b/src/app/LayoutCommon.astro
@@ -2,7 +2,7 @@
import pkg from '../../package.json' assert { type: 'json' };
import HelmetHead from '../components/HelmetHead';
import { url } from '../lib/data.js';
-
+import { getFromCookies } from '../api/Auth';
import { SITE_TITLE } from './constants.js';
const { class: clazz, metaData } = Astro.props;
@@ -13,6 +13,10 @@ const envKeys = [...Object.keys(process.env), ...Object.keys(import.meta.env)];
envKeys.forEach((item) => {
initData[item] = process.env[item] || import.meta.env[item];
});
+
+const sessionToken = getFromCookies(Astro.cookies, 'session');
+const refreshToken = getFromCookies(Astro.cookies, 'refresh');
+
---
@@ -56,11 +60,15 @@ envKeys.forEach((item) => {
import 'flowbite';
import 'flowbite/dist/datepicker.js';
-