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

feat: develop to qa changes #629

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
66e1a37
feat: support multiple did methods
bhavanakarwade Mar 11, 2024
c2c5f35
Merge branch 'develop' of https://github.com/credebl/studio into feat…
pranalidhanavade Mar 12, 2024
50fa053
fix: sonarcloud issues
pranalidhanavade Mar 12, 2024
a914032
fix: sonarlint issues
pranalidhanavade Mar 12, 2024
5e7eede
fix: resolved sonarlint issues
pranalidhanavade Mar 12, 2024
773ba1a
feat: support multiple did methods (#620)
bhavanakarwade Mar 12, 2024
9b0cdda
fix: resolved sonarcloud issues
pranalidhanavade Mar 12, 2024
47ed268
Merge branch 'develop' of https://github.com/credebl/studio into feat…
pranalidhanavade Mar 12, 2024
3f59ecc
Worked on the refresh token implementation
nishad-ayanworks Mar 13, 2024
860394d
Merge branch 'develop' of https://github.com/credebl/studio into auth…
nishad-ayanworks Mar 13, 2024
b73045d
removed unnecessary encryption while storing token in cookies
nishad-ayanworks Mar 14, 2024
deac1cc
cosmetic changes
nishad-ayanworks Mar 14, 2024
90b79fb
Merge pull request #624 from credebl/auth-refresh-token
nishad-ayanworks Mar 15, 2024
eb414b7
feat: did web functionality
bhavanakarwade Mar 18, 2024
ac6e30f
Handled the error validations in encrypt and decrypt of data
nishad-ayanworks Mar 18, 2024
03b517a
refactored auth.ts for encrypt and decrypt data
nishad-ayanworks Mar 18, 2024
665bfc4
Merge pull request #626 from credebl/fix-utf8-data-issue
nishad-ayanworks Mar 18, 2024
a8ebd1b
Merge pull request #623 from credebl/feat/multiple-did-methods
bhavanakarwade Mar 19, 2024
366ca13
Merge branch 'develop' of https://github.com/credebl/studio into deve…
bhavanakarwade Mar 19, 2024
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
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
Loading