Skip to content

Commit

Permalink
develop to qa (#632)
Browse files Browse the repository at this point in the history
* feat: support multiple did methods

Signed-off-by: bhavanakarwade <[email protected]>

* fix: sonarcloud issues

Signed-off-by: pranalidhanavade <[email protected]>

* fix: sonarlint issues

Signed-off-by: pranalidhanavade <[email protected]>

* fix: resolved sonarlint issues

Signed-off-by: pranalidhanavade <[email protected]>

* feat: support multiple did methods (#620)

* feat: support multiple did methods

Signed-off-by: bhavanakarwade <[email protected]>

* fix: sonarcloud issues

Signed-off-by: pranalidhanavade <[email protected]>

* fix: sonarlint issues

Signed-off-by: pranalidhanavade <[email protected]>

* fix: resolved sonarlint issues

Signed-off-by: pranalidhanavade <[email protected]>

---------

Signed-off-by: bhavanakarwade <[email protected]>
Signed-off-by: pranalidhanavade <[email protected]>
Co-authored-by: pranalidhanavade <[email protected]>

* fix: resolved sonarcloud issues

Signed-off-by: pranalidhanavade <[email protected]>

* Worked on the refresh token implementation

Signed-off-by: Nishad <[email protected]>

* removed unnecessary encryption while storing token in cookies

Signed-off-by: Nishad <[email protected]>

* cosmetic changes

Signed-off-by: Nishad <[email protected]>

* feat: did web functionality

Signed-off-by: bhavanakarwade <[email protected]>

* Handled the error validations in encrypt and decrypt of data

Signed-off-by: Nishad <[email protected]>

* refactored auth.ts for encrypt and decrypt data

Signed-off-by: Nishad <[email protected]>

* refactoring in wallet spinup

Signed-off-by: Nishad <[email protected]>

* cosmetic changes in wallet spinup

Signed-off-by: Nishad <[email protected]>

* cosmetic changesin Field

Signed-off-by: Nishad <[email protected]>

---------

Signed-off-by: bhavanakarwade <[email protected]>
Signed-off-by: pranalidhanavade <[email protected]>
Signed-off-by: Nishad <[email protected]>
Co-authored-by: bhavanakarwade <[email protected]>
Co-authored-by: pranalidhanavade <[email protected]>
Co-authored-by: bhavanakarwade <[email protected]>
  • Loading branch information
4 people authored Mar 20, 2024
1 parent d8f82b0 commit 26458d7
Show file tree
Hide file tree
Showing 22 changed files with 1,243 additions and 447 deletions.
46 changes: 45 additions & 1 deletion src/api/Agent.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
41 changes: 29 additions & 12 deletions src/api/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>{
Expand Down Expand Up @@ -273,23 +292,21 @@ 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,
httpOnly: true,
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) => {
Expand Down
12 changes: 10 additions & 2 deletions src/app/LayoutCommon.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
---

<!DOCTYPE html>
Expand Down Expand Up @@ -56,11 +60,15 @@ envKeys.forEach((item) => {
import 'flowbite';
import 'flowbite/dist/datepicker.js';
</script>
<script define:vars={{ initData, envKeys }}>
<script define:vars={{ initData, envKeys, sessionToken, refreshToken }}>

envKeys.forEach((item) => {
globalThis[item] = initData[item];
});

globalThis.access_token = sessionToken;
globalThis.refresh_token = refreshToken;

</script>

<style is:global>
Expand Down
7 changes: 7 additions & 0 deletions src/common/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,10 @@ export enum BulkIssuanceStatus {
successful= 'Successful',
failed= 'Failed'
}

export enum DidMethod {
INDY = 'indy',
KEY = 'key',
WEB = 'web',
POLYGON = 'polygon'
}
6 changes: 5 additions & 1 deletion src/commonComponents/CopyDid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import React, { useState } from 'react'
interface IProps {
value: string
className: string
hideValue?: boolean
}

const CopyDid = ({ value, className }: IProps) => {
const CopyDid = ({ value, className, hideValue }: IProps) => {
const [copied, setCopied] = useState(false)
function copyTextVal(e: React.MouseEvent<HTMLButtonElement>) {
e.preventDefault()
Expand All @@ -24,9 +25,12 @@ const CopyDid = ({ value, className }: IProps) => {
}
return (
<>
{
!hideValue &&
<span title={value} className={className}>
{value}
</span>
}
<button
className="shrink-0"
onClick={e => !copied && copyTextVal(e)}
Expand Down
1 change: 1 addition & 0 deletions src/components/Authentication/SignInUserPasskey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const SignInUserPasskey = (signInUserProps: signInUserProps) => {

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
await setToLocalStorage(storageKeys.TOKEN, data?.data?.access_token);
await setToLocalStorage(storageKeys.REFRESH_TOKEN, data?.data?.refresh_token);
const userRole = await getUserDetails(data?.data?.access_token)

const userPayload = {
Expand Down
1 change: 1 addition & 0 deletions src/components/Authentication/SignInUserPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const SignInUserPassword = (signInUserProps: SignInUser3Props) => {
setLoading(false);
} else {
await setToLocalStorage(storageKeys.TOKEN, data?.data?.access_token);
await setToLocalStorage(storageKeys.REFRESH_TOKEN, data?.data?.refresh_token);
const userRole = await getUserDetails(data?.data?.access_token);

const userPayload = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/organization/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const Dashboard = () => {
</div>

<div className="mt-4 p-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800">
<div className="grid w-full grid-cols-1 gap-4 mt-0 mb-4 xl:grid-cols-3 2xl:grid-cols-3">
<div className="grid w-full grid-cols-1 gap-4 mt-0 xl:grid-cols-3 2xl:grid-cols-3">
<DashboardCard
icon={userCard}
backgroundColor="linear-gradient(279deg, #FFF -18.24%, #2F80ED -0.8%, #1F4EAD 61.45%)"
Expand Down
Loading

0 comments on commit 26458d7

Please sign in to comment.