From 26458d7babc4332876f4f4fb0047ec4c5cdf3613 Mon Sep 17 00:00:00 2001 From: Nishad Shirsat <103021375+nishad-ayanworks@users.noreply.github.com> Date: Wed, 20 Mar 2024 16:28:34 +0530 Subject: [PATCH] develop to qa (#632) * feat: support multiple did methods Signed-off-by: bhavanakarwade * fix: sonarcloud issues Signed-off-by: pranalidhanavade * fix: sonarlint issues Signed-off-by: pranalidhanavade * fix: resolved sonarlint issues Signed-off-by: pranalidhanavade * feat: support multiple did methods (#620) * feat: support multiple did methods Signed-off-by: bhavanakarwade * fix: sonarcloud issues Signed-off-by: pranalidhanavade * fix: sonarlint issues Signed-off-by: pranalidhanavade * fix: resolved sonarlint issues Signed-off-by: pranalidhanavade --------- Signed-off-by: bhavanakarwade Signed-off-by: pranalidhanavade Co-authored-by: pranalidhanavade * fix: resolved sonarcloud issues Signed-off-by: pranalidhanavade * Worked on the refresh token implementation Signed-off-by: Nishad * removed unnecessary encryption while storing token in cookies Signed-off-by: Nishad * cosmetic changes Signed-off-by: Nishad * feat: did web functionality Signed-off-by: bhavanakarwade * Handled the error validations in encrypt and decrypt of data Signed-off-by: Nishad * refactored auth.ts for encrypt and decrypt data Signed-off-by: Nishad * refactoring in wallet spinup Signed-off-by: Nishad * cosmetic changes in wallet spinup Signed-off-by: Nishad * cosmetic changesin Field Signed-off-by: Nishad --------- Signed-off-by: bhavanakarwade Signed-off-by: pranalidhanavade Signed-off-by: Nishad Co-authored-by: bhavanakarwade Co-authored-by: pranalidhanavade Co-authored-by: bhavanakarwade <137506897+bhavanakarwade@users.noreply.github.com> --- src/api/Agent.ts | 46 +- src/api/Auth.ts | 41 +- src/app/LayoutCommon.astro | 12 +- src/common/enums.ts | 7 + src/commonComponents/CopyDid.tsx | 6 +- .../Authentication/SignInUserPasskey.tsx | 1 + .../Authentication/SignInUserPassword.tsx | 1 + src/components/organization/Dashboard.tsx | 2 +- .../organization/OrganizationDetails.tsx | 390 ++++---- src/components/organization/WalletSpinup.tsx | 931 +++++++++++++----- .../organization/interfaces/index.ts | 1 + .../GenerateBtnPolygon.tsx | 26 + .../LegderLessMethods.tsx | 70 ++ .../SetDomainValueInput.tsx | 29 + .../SetPrivateKeyValue.tsx | 29 + .../TokenWarningMessage.tsx | 22 + src/config/CommonConstant.ts | 1 + src/config/apiRoutes.ts | 5 +- src/pages/api/auth/signin.ts | 5 +- src/pages/api/auth/signout.ts | 3 + src/services/axiosIntercepter.ts | 23 +- src/utils/check-session.ts | 39 +- 22 files changed, 1243 insertions(+), 447 deletions(-) create mode 100644 src/components/organization/walletCommonComponents/GenerateBtnPolygon.tsx create mode 100644 src/components/organization/walletCommonComponents/LegderLessMethods.tsx create mode 100644 src/components/organization/walletCommonComponents/SetDomainValueInput.tsx create mode 100644 src/components/organization/walletCommonComponents/SetPrivateKeyValue.tsx create mode 100644 src/components/organization/walletCommonComponents/TokenWarningMessage.tsx 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'; -