diff --git a/src/api/Auth.ts b/src/api/Auth.ts index 9c3204aa1..bbe182a75 100644 --- a/src/api/Auth.ts +++ b/src/api/Auth.ts @@ -5,7 +5,125 @@ import { envConfig } from '../config/envConfig' import { storageKeys } from '../config/CommonConstant' import type { AddPassword } from '../components/Profile/interfaces' import type { AstroCookies } from 'astro' -const storageOperations = new Map>(); + +// import { TextEncoder, TextDecoder } from 'util'; // For encoding/decoding text to/from Uint8Array + +const ENCODER = new TextEncoder(); +const DECODER = new TextDecoder(); + +// Utility function to convert a base64 string to a Uint8Array +const base64ToUint8Array = (base64: string) => Uint8Array.from(atob(base64), c => c.charCodeAt(0)); + +// Utility function to convert a Uint8Array to a base64 string +const uint8ArrayToBase64 = (buffer: Uint8Array) => btoa(String.fromCharCode(...buffer)); + +// Utility function to generate an AES-GCM key (128 or 256 bits) +const getAesKey = async (key: string) => { + const keyBuffer = ENCODER.encode(key.padEnd(32, '0')).slice(0, 32); // Pad key to 32 bytes for AES-256 + return await crypto.subtle.importKey( + 'raw', + keyBuffer, + { name: 'AES-GCM' }, + false, + ['encrypt', 'decrypt'] + ); +}; + +// **Encrypt Data** using AES-GCM with WebCrypto +export const encryptData = async (value: any): Promise => { + try { + const CRYPTO_PRIVATE_KEY = `${envConfig.PUBLIC_CRYPTO_PRIVATE_KEY}`; + const key = await getAesKey(CRYPTO_PRIVATE_KEY); + + if (typeof value !== 'string') { + value = JSON.stringify(value); + } + + const iv = crypto.getRandomValues(new Uint8Array(12)); // 12-byte random initialization vector + const encodedData = ENCODER.encode(value); + + const encryptedData = await crypto.subtle.encrypt( + { name: 'AES-GCM', iv }, + key, + encodedData + ); + + // Concatenate IV and encrypted data and convert to base64 + const ivBase64 = uint8ArrayToBase64(iv); + const encryptedBase64 = uint8ArrayToBase64(new Uint8Array(encryptedData)); + + return `${ivBase64}:${encryptedBase64}`; + } catch (error) { + console.error('Encryption error:', error); + return ''; + } +}; + +// **Decrypt Data** using AES-GCM with WebCrypto +export const decryptData = async (value: string): Promise => { + try { + const CRYPTO_PRIVATE_KEY = `${envConfig.PUBLIC_CRYPTO_PRIVATE_KEY}`; + const key = await getAesKey(CRYPTO_PRIVATE_KEY); + + const [ivBase64, encryptedBase64] = value.split(':'); + + const iv = base64ToUint8Array(ivBase64); + const encryptedData = base64ToUint8Array(encryptedBase64); + + const decryptedData = await crypto.subtle.decrypt( + { name: 'AES-GCM', iv }, + key, + encryptedData + ); + + return DECODER.decode(new Uint8Array(decryptedData)); + } catch (error) { + console.error('Decryption error:', error); + return ''; // Return an empty string to avoid app crashes + } +}; + +// **Set to Local Storage** (Encrypt and Save) +export const setToLocalStorage = async (key: string, value: any): Promise => { + try { + if (typeof value === 'object' && Boolean(Object.keys(value).length <= 0)) { + return false; + } + + if (typeof value === 'string' && !value.trim()) { + return false; + } + + const encryptedValue = await encryptData(value); + localStorage.setItem(key, encryptedValue); + return true; + } catch (error) { + console.error('Error setting to localStorage:', error); + return false; + } +}; + +// **Get from Local Storage** (Decrypt and Return) +export const getFromLocalStorage = async (key: string): Promise => { + try { + const encryptedValue = localStorage.getItem(key); + if (!encryptedValue) { + console.warn(`No value found in localStorage for key: ${key}`); + return null; + } + + const decryptedValue = await decryptData(encryptedValue); + try { + return JSON.parse(decryptedValue); + } catch { + return decryptedValue; + } + } catch (error) { + console.error(`Decryption error for key [${key}]:`, error); + return null; + } +}; + export interface UserSignUpData { email: string, clientId: string, @@ -226,82 +344,81 @@ export const passwordEncryption = (password: string): string => { return encryptedPassword } -export const encryptData = (value: any): string => { +// export const encryptData = (value: any): string => { - const CRYPTO_PRIVATE_KEY: string = `${envConfig.PUBLIC_CRYPTO_PRIVATE_KEY}` - - try { - if (typeof (value) !== 'string') { - value = JSON.stringify(value) - } - return CryptoJS.AES.encrypt(value, CRYPTO_PRIVATE_KEY).toString(); - } catch (error) { - // Handle encryption error - console.error('Encryption error:', error); - return ''; - } -} - -export const decryptData = (value: string): string => { - const CRYPTO_PRIVATE_KEY: string = `${envConfig.PUBLIC_CRYPTO_PRIVATE_KEY}`; - - try { - // Ensure input is valid and not empty - if (!value || typeof value !== "string") { - throw new Error("Invalid input for decryption"); - } - - const bytes = CryptoJS.AES.decrypt(value, CRYPTO_PRIVATE_KEY); - const decryptedText = bytes.toString(CryptoJS.enc.Utf8); - - // Ensure the output is valid UTF-8 - if (!decryptedText) { - throw new Error("Decryption failed or returned empty result"); - } - - return decryptedText; - } catch (error) { - console.error("Decryption error:", error); - return ''; // Return a fallback value to prevent crashes - } -}; - - -export const setToLocalStorage = async (key: string, value: any) =>{ - - // If passed value is object then checked empty object - if (typeof value === 'object' && Boolean(Object.keys(value).length <= 0)) { - return; - } - - // If passed value is string then checked if value is falsy - if (typeof value === 'string' && !value?.trim()) { - return; - } - - const convertedValue = await encryptData(value) - const setValue = await localStorage.setItem(key, convertedValue as string) - return true -} - -export const getFromLocalStorage = async (key: string) => { - - try { - const encryptedValue = localStorage.getItem(key); - - if (!encryptedValue) { - console.warn(`No value found in localStorage for key: ${key}`); - return null; - } - - const decryptedValue = encryptedValue ? decryptData(encryptedValue) : ''; - - return decryptedValue; - } catch (error) { - console.error(`Decryption error for key [${key}]:`, error); - return null; - } -}; +// const CRYPTO_PRIVATE_KEY: string = `${envConfig.PUBLIC_CRYPTO_PRIVATE_KEY}` + +// try { +// if (typeof (value) !== 'string') { +// value = JSON.stringify(value) +// } +// return CryptoJS.AES.encrypt(value, CRYPTO_PRIVATE_KEY).toString(); +// } catch (error) { +// // Handle encryption error +// console.error('Encryption error:', error); +// return ''; +// } +// } + +// export const decryptData = (value: string): string => { +// const CRYPTO_PRIVATE_KEY: string = `${envConfig.PUBLIC_CRYPTO_PRIVATE_KEY}`; + +// try { +// // Ensure input is valid and not empty +// if (!value || typeof value !== "string") { +// throw new Error("Invalid input for decryption"); +// } + +// const bytes = CryptoJS.AES.decrypt(value, CRYPTO_PRIVATE_KEY); +// const decryptedText = bytes.toString(CryptoJS.enc.Utf8); + +// // Ensure the output is valid UTF-8 +// if (!decryptedText) { +// throw new Error("Decryption failed or returned empty result"); +// } + +// return decryptedText; +// } catch (error) { +// console.error("Decryption error:", error); +// return ''; // Return a fallback value to prevent crashes +// } +// }; + +// export const setToLocalStorage = async (key: string, value: any) =>{ + +// // If passed value is object then checked empty object +// if (typeof value === 'object' && Boolean(Object.keys(value).length <= 0)) { +// return; +// } + +// // If passed value is string then checked if value is falsy +// if (typeof value === 'string' && !value?.trim()) { +// return; +// } + +// const convertedValue = await encryptData(value) +// const setValue = await localStorage.setItem(key, convertedValue as string) +// return true +// } + +// export const getFromLocalStorage = async (key: string) => { + +// try { +// const encryptedValue = localStorage.getItem(key); + +// if (!encryptedValue) { +// console.warn(`No value found in localStorage for key: ${key}`); +// return null; +// } + +// const decryptedValue = encryptedValue ? decryptData(encryptedValue) : ''; + +// return decryptedValue; +// } catch (error) { +// console.error(`Decryption error for key [${key}]:`, error); +// return null; +// } +// }; export const setToCookies = (cookies: AstroCookies, key: string, value: any, option: {[key: string]: any }) =>{ // If passed value is object then checked empty object diff --git a/src/commonComponents/CustomCheckbox.tsx b/src/commonComponents/CustomCheckbox.tsx index 09a94ac03..e2068077f 100644 --- a/src/commonComponents/CustomCheckbox.tsx +++ b/src/commonComponents/CustomCheckbox.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useState } from 'react'; -import { setToLocalStorage } from '../api/Auth'; +import { getFromLocalStorage, setToLocalStorage } from '../api/Auth'; import { storageKeys } from '../config/CommonConstant'; import type { ICustomCheckboxProps, ISchemaData } from './interface'; @@ -25,16 +25,20 @@ const CustomCheckbox: React.FC = ({ showCheckbox, isVerifi try { const selectedSchemas = JSON.parse(localStorage.getItem('selectedSchemas') ?? '[]'); - + // const selectedSchemas = await getFromLocalStorage(storageKeys.SELECTED_SCHEMAS); + console.log("🚀 ~ handleCheckboxChange ~ selectedSchemas:", selectedSchemas) + + const filteredSchemas = selectedSchemas.filter((schema: ISchemaData | null) => schema !== null); + if (newChecked) { - selectedSchemas.push(schemaData); + filteredSchemas.push(schemaData); } else { - const index = selectedSchemas.findIndex((schema: ISchemaData) => schema.schemaId === schemaData?.schemaId); + const index = filteredSchemas.findIndex((schema: ISchemaData) => schema.schemaId === schemaData?.schemaId); if (index > -1) { - selectedSchemas.splice(index, 1); + filteredSchemas.splice(index, 1); } } - await setToLocalStorage(storageKeys.SELECTED_SCHEMAS, JSON.stringify(selectedSchemas)); + await setToLocalStorage(storageKeys.SELECTED_SCHEMAS, JSON.stringify(filteredSchemas)); } catch (error) { console.error('Error updating localStorage:', error); } diff --git a/src/components/ConnectionsList/index.tsx b/src/components/ConnectionsList/index.tsx index eadaaf2c3..22860e7eb 100644 --- a/src/components/ConnectionsList/index.tsx +++ b/src/components/ConnectionsList/index.tsx @@ -40,7 +40,7 @@ const ConnectionList = () => { const getConnections = async (apiParameter: IConnectionListAPIParameter) => { const orgId = await getFromLocalStorage(storageKeys.ORG_ID); const orgData = await getOrgDetails(); - const checkWalletCreated = Boolean(orgData.orgDid); + const checkWalletCreated = Boolean(orgData?.orgDid); if (orgId && checkWalletCreated) { setLoading(true); diff --git a/src/components/Issuance/BulkIssuance.tsx b/src/components/Issuance/BulkIssuance.tsx index 9133b77ab..3070938fe 100644 --- a/src/components/Issuance/BulkIssuance.tsx +++ b/src/components/Issuance/BulkIssuance.tsx @@ -109,7 +109,7 @@ const BulkIssuance = () => { let dropDownOptions; setSchemaType(currentSchemaType); - if ((currentSchemaType === SchemaTypes.schema_INDY && isAllSchema) || (currentSchemaType && orgId && !isAllSchema)) { + if ((currentSchemaType === SchemaTypes.schema_INDY && isAllSchemaSelectedFlag) || (currentSchemaType && orgId && !isAllSchemaSelectedFlag)) { const response = await getSchemaCredDef(currentSchemaType); const { data } = response as AxiosResponse; @@ -144,7 +144,7 @@ const BulkIssuance = () => { } setLoading(false); } - else if (currentSchemaType === SchemaTypes.schema_W3C && orgId && isAllSchema) { + else if (currentSchemaType === SchemaTypes.schema_W3C && orgId && isAllSchemaSelectedFlag) { const response = await getAllSchemas(schemaListAPIParameters,currentSchemaType); diff --git a/src/components/Issuance/CredDefSelection.tsx b/src/components/Issuance/CredDefSelection.tsx index 9b531130c..7468b9bdd 100644 --- a/src/components/Issuance/CredDefSelection.tsx +++ b/src/components/Issuance/CredDefSelection.tsx @@ -56,13 +56,13 @@ const CredDefSelection = () => { const getSchemaDetails = async (schemaId: string) => { setSchemaLoader(true); const schemaDid = await getFromLocalStorage(storageKeys.SCHEMA_ATTR); - const schemaDidObject = JSON.parse(schemaDid); - if (schemaDidObject) { + // const schemaDidObject = JSON.parse(schemaDid); + if (schemaDid) { setSchemaDetailsState({ schemaId: schemaId, - issuerDid: schemaDidObject?.issuerDid, - attributes: schemaDidObject?.attribute, - createdDateTime: schemaDidObject?.createdDate, + issuerDid: schemaDid?.issuerDid, + attributes: schemaDid?.attribute, + createdDateTime: schemaDid?.createdDate, }); } setSchemaLoader(false); diff --git a/src/components/Issuance/EmailIssuance.tsx b/src/components/Issuance/EmailIssuance.tsx index 61747edd6..ed0fdd5ec 100644 --- a/src/components/Issuance/EmailIssuance.tsx +++ b/src/components/Issuance/EmailIssuance.tsx @@ -79,7 +79,7 @@ const EmailIssuance = () => { const orgDid = await getFromLocalStorage(storageKeys.ORG_DID); const allSchemaSelectedFlag = await getFromLocalStorage(storageKeys.ALL_SCHEMAS) - if (allSchemaSelectedFlag === `false` || !allSchemaSelectedFlag) { + if (allSchemaSelectedFlag === false || !allSchemaSelectedFlag) { setIsAllSchemaFlagSelected(false) } else if (allSchemaSelectedFlag === 'true') { @@ -107,7 +107,7 @@ const EmailIssuance = () => { //FIXME: Logic of API call as per schema selection if((currentSchemaType === SchemaTypes.schema_INDY && orgId - ) || (currentSchemaType ===SchemaTypes.schema_W3C && isAllSchemaFlagSelected === false)){ + ) || (currentSchemaType ===SchemaTypes.schema_W3C && allSchemaSelectedFlag === false)){ const response = await getSchemaCredDef(currentSchemaType); const { data } = response as AxiosResponse; if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { diff --git a/src/components/Issuance/Issuance.tsx b/src/components/Issuance/Issuance.tsx index 2b8e283fc..eba0c595c 100644 --- a/src/components/Issuance/Issuance.tsx +++ b/src/components/Issuance/Issuance.tsx @@ -92,7 +92,7 @@ const IssueCred = () => { } } } catch(error){ - console.log('Error in getSchemaAndUsers:', error); + console.error('Error in getSchemaAndUsers:', error); setFailure('Error fetching schema and users'); } @@ -117,15 +117,16 @@ const IssueCred = () => { if (w3cSchema) { const orgId = await getFromLocalStorage(storageKeys.ORG_ID); const getW3cSchemaDetails = await getFromLocalStorage(storageKeys.W3C_SCHEMA_DETAILS); - const parsedW3cSchemaDetails = JSON.parse(getW3cSchemaDetails); + console.log("🚀 ~ getSchemaAndU00000000sers ~ getW3cSchemaDetails:", getW3cSchemaDetails) + // const parsedW3cSchemaDetails = JSON.parse(getW3cSchemaDetails); - const schemaId = parsedW3cSchemaDetails?.schemaId; - createW3cSchemaPayload(schemaId, parsedW3cSchemaDetails); + const schemaId = getW3cSchemaDetails?.schemaId; + createW3cSchemaPayload(schemaId, getW3cSchemaDetails); setUserLoader(true); const selectedUsers = await getSelectedUsers(); - const attributes = parsedW3cSchemaDetails?.attributes; + const attributes = getW3cSchemaDetails?.attributes; if (attributes && attributes?.length) { createW3cIssuanceForm(selectedUsers, attributes, orgId); @@ -247,7 +248,7 @@ const IssueCred = () => { let parsedSchemaAttributes = []; if (schemaAttributes) { try { - parsedSchemaAttributes = JSON.parse(schemaAttributes); + parsedSchemaAttributes = (schemaAttributes); } catch (e) { } } @@ -290,7 +291,7 @@ const getSelectedUsers = async (): Promise => { if (!selectedUsers) { return []; } - return JSON.parse(selectedUsers); + return selectedUsers; } catch (error) { console.error("Error parsing selectedUsers:", error); return []; diff --git a/src/components/Profile/DisplayProfileImg.tsx b/src/components/Profile/DisplayProfileImg.tsx index 36e80fef8..3ce1e73fd 100644 --- a/src/components/Profile/DisplayProfileImg.tsx +++ b/src/components/Profile/DisplayProfileImg.tsx @@ -9,13 +9,17 @@ const DisplayProfileImg = () => { const [userObj, setUserObj] = useState(null) const getUserDetails = async () => { const userProfile = await getFromLocalStorage(storageKeys.USER_PROFILE) + console.log("🚀 ~ getUserDetails ~ userProfile: type of:::::::", typeof userProfile) + console.log("🚀 ~ getUserDetails ~ userProfile22222222222:", userProfile) const orgRoles = await getFromLocalStorage(storageKeys.ORG_ROLES) - const parsedUser = userProfile ? JSON.parse(userProfile) : null; + // const parsedUser = userProfile ? JSON.parse(userProfile) : null; + // console.log("🚀 ~ getUserDetails ~ parsedUser type of:", typeof parsedUser) + // console.log("🚀 ~ getUserDetails ~ parsedUser:", parsedUser) - if (parsedUser) { - parsedUser.roles = orgRoles; - setUserObj(parsedUser); - } + // if (parsedUser) { + userProfile.roles = orgRoles; + setUserObj(userProfile); + // } } useEffect(() => { diff --git a/src/components/Profile/DisplayUser.tsx b/src/components/Profile/DisplayUser.tsx index fbc238f09..a1897f162 100644 --- a/src/components/Profile/DisplayUser.tsx +++ b/src/components/Profile/DisplayUser.tsx @@ -11,13 +11,15 @@ const DisplayUser = () => { let timer:any= null const getUserDetails = async () => { const userProfile = await getFromLocalStorage(storageKeys.USER_PROFILE) + console.log("🚀 ~ getUserDetails ~ userProfile11111111111:", userProfile) const orgRoles = await getFromLocalStorage(storageKeys.ORG_ROLES) - const parsedUser = userProfile ? JSON.parse(userProfile) : null + // const parsedUser = userProfile ? JSON.parse(userProfile) : null + // console.log("🚀 ~ getUserDetails ~ parsedUser:", parsedUser) - if (parsedUser) { - parsedUser.roles = orgRoles; - setUserObj(parsedUser); - } + // if (parsedUser) { + userProfile.roles = orgRoles; + setUserObj(userProfile); + // } } useEffect(() => { const fetchData = async () => { @@ -32,7 +34,6 @@ const DisplayUser = () => { }; }, [userObj]); - return (
{ diff --git a/src/components/Profile/EditUserProfile.tsx b/src/components/Profile/EditUserProfile.tsx index 8287afd8f..2c889c263 100644 --- a/src/components/Profile/EditUserProfile.tsx +++ b/src/components/Profile/EditUserProfile.tsx @@ -171,10 +171,10 @@ const EditUserProfile = ({ toggleEditProfile, userProfileInfo, updateProfile }: const { data } = resUpdateUserDetails as AxiosResponse - const updatedUser = JSON.parse(existingUser) + // const updatedUser = JSON.parse(existingUser) const updatedUserData = { - ...updatedUser, + ...existingUser, ...userData } diff --git a/src/components/Verification/CredDefSelection.tsx b/src/components/Verification/CredDefSelection.tsx index 9fca2c9b3..521b1c2b2 100644 --- a/src/components/Verification/CredDefSelection.tsx +++ b/src/components/Verification/CredDefSelection.tsx @@ -34,6 +34,7 @@ const CredDefSelection = () => { const getSchemaAndCredDef = async () => { const schemaId = await getFromLocalStorage(storageKeys.SCHEMA_ID) + console.log("🚀 ~ getSchemaAndCredDef ~ schemaId:", schemaId) if (schemaId) { getSchemaDetails(schemaId) getCredDefs(schemaId) @@ -49,9 +50,9 @@ const CredDefSelection = () => { const getSchemaDetails = async (schemaId: string) => { setSchemaLoader(true) const schemaDid = await getFromLocalStorage(storageKeys.SCHEMA_ATTR) - const schemaDidObject = JSON.parse(schemaDid) - if (schemaDidObject) { - setSchemaDetailsState({ schemaId: schemaId, issuerDid: schemaDidObject?.issuerDid, attributes: schemaDidObject?.attribute, createdDateTime: schemaDidObject?.createdDate }) + // const schemaDidObject = JSON.parse(schemaDid) + if (schemaDid) { + setSchemaDetailsState({ schemaId: schemaId, issuerDid: schemaDid?.issuerDid, attributes: schemaDid?.attribute, createdDateTime: schemaDid?.createdDate }) } setSchemaLoader(false) } @@ -107,10 +108,6 @@ const CredDefSelection = () => { setLoading(false) } - const schemaSelectionCallback = () => { - - } - const selectConnection = async (credDefId: string, checked: boolean) => { if (credDefId && checked) { await setToLocalStorage(storageKeys.CRED_DEF_ID, credDefId) @@ -139,11 +136,8 @@ const CredDefSelection = () => { :
+ isClickable={false} />
} -
diff --git a/src/components/Verification/EmailAttributesSelection.tsx b/src/components/Verification/EmailAttributesSelection.tsx index 070397062..2ac51f3a3 100644 --- a/src/components/Verification/EmailAttributesSelection.tsx +++ b/src/components/Verification/EmailAttributesSelection.tsx @@ -153,10 +153,10 @@ const EmailAttributesSelection = () => { if (w3cSchema) { const getW3CSchemaDetails = await getFromLocalStorage(storageKeys.SELECTED_SCHEMAS); - const parsedW3CSchemaDetails = JSON.parse(getW3CSchemaDetails || '[]'); + // const parsedW3CSchemaDetails = JSON.parse(getW3CSchemaDetails || '[]'); - if (Array.isArray(parsedW3CSchemaDetails) && parsedW3CSchemaDetails.length > 0) { - const allAttributes = parsedW3CSchemaDetails.flatMap(schema => { + if (Array.isArray(getW3CSchemaDetails) && getW3CSchemaDetails.length > 0) { + const allAttributes = getW3CSchemaDetails.flatMap(schema => { if (schema.attributes && Array.isArray(schema.attributes)) { return schema.attributes.map(attribute => ({ ...attribute, @@ -193,17 +193,17 @@ const EmailAttributesSelection = () => { } else { const getSelectedCredDefData = await getFromLocalStorage(storageKeys.CRED_DEF_DATA); - const selectedCredDefs = JSON.parse(getSelectedCredDefData || '[]'); + // const selectedCredDefs = JSON.parse(getSelectedCredDefData || '[]'); const schemaAttributes = await getFromLocalStorage(storageKeys.SCHEMA_ATTRIBUTES); - const parsedSchemaDetails = JSON.parse(schemaAttributes || '[]'); + // const parsedSchemaDetails = JSON.parse(schemaAttributes || '[]'); - if (Array.isArray(parsedSchemaDetails) && parsedSchemaDetails.length > 0) { - const allAttributes = parsedSchemaDetails.flatMap(schema => { + if (Array.isArray(schemaAttributes) && schemaAttributes.length > 0) { + const allAttributes = schemaAttributes.flatMap(schema => { if (schema.attributes && Array.isArray(schema.attributes)) { return schema.attributes.flatMap(attribute => { - const matchingCredDefs = selectedCredDefs.filter( + const matchingCredDefs = getSelectedCredDefData.filter( credDef => credDef.schemaLedgerId === schema.schemaId ); diff --git a/src/components/Verification/EmailCredDefSelection.tsx b/src/components/Verification/EmailCredDefSelection.tsx index 9652e06fe..221b99fd0 100644 --- a/src/components/Verification/EmailCredDefSelection.tsx +++ b/src/components/Verification/EmailCredDefSelection.tsx @@ -34,10 +34,10 @@ const EmailCredDefSelection = () => { const getSchemaAndCredDef = async () => { try { const schemaIdsJSON = await getFromLocalStorage(storageKeys.SCHEMA_IDS); - const schemaIds = schemaIdsJSON ? JSON.parse(schemaIdsJSON) : []; + // const schemaIds = schemaIdsJSON ? JSON.parse(schemaIdsJSON) : []; - if (schemaIds && schemaIds.length > 0) { - getCredDefs(schemaIds); + if (schemaIdsJSON && schemaIdsJSON.length > 0) { + getCredDefs(schemaIdsJSON); } } catch (error) { console.error('Error fetching schema details:', error); @@ -113,9 +113,9 @@ const EmailCredDefSelection = () => { if (!credDefId) return; const getRawCredDefs = await getFromLocalStorage(storageKeys.SCHEMA_CRED_DEFS); - const parsedRawCredDefs = JSON.parse(getRawCredDefs); + // const parsedRawCredDefs = JSON.parse(getRawCredDefs); - const selectedCredDef = parsedRawCredDefs.find( + const selectedCredDef = getRawCredDefs.find( (credDef: CredDefData) => credDef.credentialDefinitionId === credDefId ); @@ -125,7 +125,7 @@ const EmailCredDefSelection = () => { const isAlreadySelected = prevSelected.some( (credDef) => credDef.credentialDefinitionId === selectedCredDef.credentialDefinitionId ); - + if (!isAlreadySelected) { const newSelected = [...prevSelected, selectedCredDef]; setToLocalStorage(storageKeys.CRED_DEF_DATA, JSON.stringify(newSelected)); @@ -142,10 +142,7 @@ const EmailCredDefSelection = () => { return prevSelected; }); } - }; - - - + }; return (
diff --git a/src/components/Verification/EmailVerification.tsx b/src/components/Verification/EmailVerification.tsx index 76c0924fb..9dc6aeb2a 100644 --- a/src/components/Verification/EmailVerification.tsx +++ b/src/components/Verification/EmailVerification.tsx @@ -69,8 +69,8 @@ const EmailVerification = () => { if (w3cSchema) { const getSelectedW3CSchemaDetails = await getFromLocalStorage(storageKeys.ATTRIBUTE_DATA); - const parsedW3CSchemaDetails = JSON.parse(getSelectedW3CSchemaDetails); - const groupedAttributes = parsedW3CSchemaDetails + // const parsedW3CSchemaDetails = JSON.parse(getSelectedW3CSchemaDetails); + const groupedAttributes = getSelectedW3CSchemaDetails .filter(attribute => attribute.isChecked) .reduce((acc, attribute) => { const schemaUri = attribute.schemaId; @@ -116,10 +116,10 @@ const EmailVerification = () => { } else { const selectedAttributes = await getFromLocalStorage(storageKeys.ATTRIBUTE_DATA); - const parsedSelectedAttributes = JSON.parse(selectedAttributes) || []; + // const parsedSelectedAttributes = JSON.parse(selectedAttributes) || []; - const selectedAttributesDetails = parsedSelectedAttributes.filter((attr: ISelectedAttributes) => attr.isChecked && attr.dataType !== 'number') || []; - const selectedPredicatesDetails = parsedSelectedAttributes.filter(attr => attr.isChecked && attr.dataType === 'number') || []; + const selectedAttributesDetails = selectedAttributes.filter((attr: ISelectedAttributes) => attr.isChecked && attr.dataType !== 'number') || []; + const selectedPredicatesDetails = selectedAttributes.filter(attr => attr.isChecked && attr.dataType === 'number') || []; const requestedAttributes: Record = {}; const requestedPredicates: Record = {}; diff --git a/src/components/Verification/Verification.tsx b/src/components/Verification/Verification.tsx index 0c4c420d7..bd7066fd9 100644 --- a/src/components/Verification/Verification.tsx +++ b/src/components/Verification/Verification.tsx @@ -219,7 +219,7 @@ const VerificationCred = () => { if (!w3cSchema) { verifyCredentialPayload = { - connectionId: JSON.parse(userData)[0]?.connectionId, + connectionId: userData[0]?.connectionId, comment: 'string', orgId: orgId, proofFormats: { @@ -236,7 +236,7 @@ const VerificationCred = () => { (attr) => `$.credentialSubject['${attr.attributeName}']` ); verifyCredentialPayload = { - connectionId: JSON.parse(userData)[0]?.connectionId, + connectionId: userData[0]?.connectionId, comment: 'proof request', presentationDefinition: { id: uuidv4(), @@ -291,8 +291,8 @@ const VerificationCred = () => { if(!w3cSchema){ - const parsedSchemaDetails = JSON.parse(schemaAttributes) || []; - const inputArray: SelectedUsers[] = parsedSchemaDetails.attribute.map( + // const parsedSchemaDetails = JSON.parse(schemaAttributes) || []; + const inputArray: SelectedUsers[] = schemaAttributes.attribute.map( (attribute: IAttribute) => { return { displayName: attribute.displayName, @@ -320,9 +320,9 @@ const VerificationCred = () => { const getW3cAttributes = await getFromLocalStorage(storageKeys.W3C_SCHEMA_DATA); - const parsedSchemaAttributes = JSON.parse(getW3cAttributes) || []; + // const parsedSchemaAttributes = JSON.parse(getW3cAttributes) || []; - const w3cInputArray: SelectedUsers[] = parsedSchemaAttributes.attributes.map( + const w3cInputArray: SelectedUsers[] = getW3cAttributes.attributes.map( (attribute: IAttribute) => { return { displayName: attribute.displayName, @@ -355,6 +355,7 @@ const VerificationCred = () => { const attributes = attributeData && attributeData.map((attribute: ISelectedUser, index: number) => { + console.log("🚀 ~ attributeData.map ~ attribute:", attribute) return { data: [ { @@ -448,6 +449,7 @@ const VerificationCred = () => { ], }; }); + console.log('attributes11111999999999::::', attributes) setAttributeList(attributes); @@ -470,10 +472,11 @@ const VerificationCred = () => { if(isW3c){ const orgId = await getFromLocalStorage(storageKeys.ORG_ID); const getW3cSchemaDetails = await getFromLocalStorage(storageKeys.W3C_SCHEMA_DATA); + console.log("🚀 ~ getSchemaAndUsers ~ getW3cSchemaDetails:", getW3cSchemaDetails) - const parsedW3cSchemaDetails = JSON.parse(getW3cSchemaDetails); - const schemaId = parsedW3cSchemaDetails?.schemaId - createW3cSchemaPayload(schemaId,parsedW3cSchemaDetails) + // const parsedW3cSchemaDetails = JSON.parse(getW3cSchemaDetails); + const schemaId = getW3cSchemaDetails?.schemaId + createW3cSchemaPayload(schemaId,getW3cSchemaDetails) } }; diff --git a/src/components/Verification/VerificationSchemasList.tsx b/src/components/Verification/VerificationSchemasList.tsx index 35a3d25cc..6b5c4a5ca 100644 --- a/src/components/Verification/VerificationSchemasList.tsx +++ b/src/components/Verification/VerificationSchemasList.tsx @@ -207,14 +207,16 @@ const VerificationSchemasList = () => { const handleW3CSchemaDetails = async () => { const w3cSchemaDetails = await getFromLocalStorage(storageKeys.SELECTED_SCHEMAS) + console.log("🚀 ~ handleW3CSchemaDetails ~ w3cSchemaDetails:", w3cSchemaDetails) - const parsedSchemaDetails = JSON.parse(w3cSchemaDetails); + // const parsedSchemaDetails = JSON.parse(w3cSchemaDetails); - const w3cSchemaAttributes = parsedSchemaDetails.map(schema => ({ + const w3cSchemaAttributes = w3cSchemaDetails.map(schema => ({ schemaId: schema.schemaId, attributes: schema.attributes, schemaName: schema.schemaName })) + console.log("🚀 ~ w3cSchemaAttributes ~ w3cSchemaAttributes:", w3cSchemaAttributes) await setToLocalStorage(storageKeys.W3C_SCHEMA_ATTRIBUTES, w3cSchemaAttributes); window.location.href = `${pathRoutes.organizations.verification.w3cAttributes}`; diff --git a/src/components/organization/Dashboard.tsx b/src/components/organization/Dashboard.tsx index b9b8560b1..fcb8cfd75 100644 --- a/src/components/organization/Dashboard.tsx +++ b/src/components/organization/Dashboard.tsx @@ -77,10 +77,10 @@ const Dashboard = () => { setOrgData(data?.data); - const organizationData = orgInfoData ? JSON.parse(orgInfoData) : {}; + // const organizationData = orgInfoData ? JSON.parse(orgInfoData) : {}; const {id, name, description, logoUrl} = data?.data || {}; const orgInfo = { - ...organizationData, + ...orgInfoData, ...id && { id }, ...name && { name }, ...description && { description }, diff --git a/src/components/organization/OrgDropDown.tsx b/src/components/organization/OrgDropDown.tsx index 75042a0cb..3779cd715 100644 --- a/src/components/organization/OrgDropDown.tsx +++ b/src/components/organization/OrgDropDown.tsx @@ -74,7 +74,8 @@ const OrgDropDown = () => { const handleActiveOrg = async (organizations: Organisation[]) => { let activeOrgDetails; const orgInfoDetails = await getFromLocalStorage(storageKeys.ORG_INFO); - activeOrgDetails = orgInfoDetails ? JSON.parse(orgInfoDetails) : null; + // activeOrgDetails = orgInfoDetails ? JSON.parse(orgInfoDetails) : null; + activeOrgDetails = orgInfoDetails; if (activeOrgDetails && Object.keys(activeOrgDetails)?.length > 0) { setActiveOrg(activeOrgDetails); diff --git a/src/config/ecosystem.ts b/src/config/ecosystem.ts index ed2599954..7b4cc37cb 100644 --- a/src/config/ecosystem.ts +++ b/src/config/ecosystem.ts @@ -53,38 +53,64 @@ const getOwnerAdminRole = async (props?: string) => { } }; -const getOrgDetails = async (): Promise => { +const getOrgDetails = async (): Promise => { const orgId = await getOrgId(); - const org = await getOrgData(); - const orgData: IOrgDetails = org && JSON.parse(org); - const isOrgData = Object.keys(orgData).length > 0; - const isOrgDid = orgData?.orgDid; - if (!isOrgData || !isOrgDid) { - try { - if (orgId) { - const { data } = (await getOrganizationById(orgId)) as AxiosResponse; - - if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { - const orgData: IOrgDetails = { - orgName: data?.data?.name, - orgDid: - data?.data && data?.data?.org_agents?.length > 0 - ? data?.data?.org_agents[0]?.orgDid - : '', - }; - await setToLocalStorage( - storageKeys.ORG_DETAILS, - JSON.stringify(orgData), - ); - return orgData; - } - } - } catch (err) { - console.log('ERROR-Get ORG Details', err); - } + if (!orgId) { + console.log('🚀 No orgId found'); + return null; // Explicitly return null if orgId is not found + } + + const { data } = (await getOrganizationById(orgId)) as AxiosResponse; + + if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { + const orgData = { + orgName: data?.data?.name, + orgDid: data?.data && data?.data?.org_agents?.length > 0 ? data?.data?.org_agents[0]?.orgDid : '', + }; + console.log('🚀 ~ getOrgDetails ~ orgData:', orgData); + + await setToLocalStorage(storageKeys.ORG_DETAILS, JSON.stringify(orgData)); + return orgData; } - return orgData; + + // Return null or an empty object if the condition is not met + return null; }; + + +// const getOrgDetails = async (): Promise => { +// const orgId = await getOrgId(); +// const org = await getOrgData(); +// const orgData: IOrgDetails = org && JSON.parse(org); +// const isOrgData = Object.keys(orgData).length > 0; +// const isOrgDid = orgData?.orgDid; +// if (!isOrgData || !isOrgDid) { +// try { +// if (orgId) { +// const { data } = (await getOrganizationById(orgId)) as AxiosResponse; + +// if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { +// const orgData: IOrgDetails = { +// orgName: data?.data?.name, +// orgDid: +// data?.data && data?.data?.org_agents?.length > 0 +// ? data?.data?.org_agents[0]?.orgDid +// : '', +// }; +// await setToLocalStorage( +// storageKeys.ORG_DETAILS, +// JSON.stringify(orgData), +// ); +// return orgData; +// } +// } +// } catch (err) { +// console.log('ERROR-Get ORG Details', err); +// } +// } +// return orgData; +// }; + const checkEcosystem = async (): Promise => { await getEcosystemId(); diff --git a/tsconfig.json b/tsconfig.json index d6c2f4fe1..0df4f0d9d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,6 +4,7 @@ "strictNullChecks": true, "jsx": "react-jsx", "jsxImportSource": "react", - "esModuleInterop": true + "esModuleInterop": true, + "lib": ["ESNext", "DOM"] } } \ No newline at end of file