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 and GHkrishna committed Mar 20, 2024
1 parent 668eea0 commit 82023ff
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 172 deletions.
18 changes: 12 additions & 6 deletions src/api/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ 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();
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);
Expand All @@ -248,8 +248,14 @@ export const decryptData = (value: any): string => {
const CRYPTO_PRIVATE_KEY: string = `${envConfig.PUBLIC_CRYPTO_PRIVATE_KEY}`

try {
let bytes = CryptoJS.AES.decrypt(value, CRYPTO_PRIVATE_KEY);
return bytes.toString(CryptoJS.enc.Utf8);

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);
Expand Down
16 changes: 10 additions & 6 deletions src/app/LayoutCommon.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,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';
import { envConfig } from '../config/envConfig';
Expand All @@ -15,6 +17,7 @@ envKeys.forEach((item) => {
const sessionToken = getFromCookies(Astro.cookies, 'session');
const refreshToken = getFromCookies(Astro.cookies, 'refresh');
---

<!DOCTYPE html>
Expand Down Expand Up @@ -64,18 +67,19 @@ const refreshToken = getFromCookies(Astro.cookies, 'refresh');
]}
>
<slot />
<script is:inline src="https://cdnjs.cloudflare.com/ajax/libs/flowbite/1.8.0/flowbite.min.js"></script>

<script
id="global"
define:vars={{ initData, envKeys, sessionToken, refreshToken }}
>
<script>
import 'flowbite';
import 'flowbite/dist/datepicker.js';
</script>
<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
18 changes: 9 additions & 9 deletions src/components/organization/OrganizationDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { dateConversion } from '../../utils/DateConversion';
import DateTooltip from '../Tooltip';
import CopyDid from '../../commonComponents/CopyDid';
import { setToLocalStorage } from '../../api/Auth';
import { Tooltip } from 'flowbite-react';
import Tooltip from '../Tooltip';

const OrganizationDetails = ({ orgData }: { orgData: Organisation | null }) => {
const { org_agents } = orgData as Organisation;
Expand Down Expand Up @@ -180,7 +180,8 @@ const OrganizationDetails = ({ orgData }: { orgData: Organisation | null }) => {
<div className="flex justify-between w-full">
<div className="relative flex w-full">
<div
className="mb-4 sm:mb-0 px-0 sm:px-4 py-4 w-full"
className="mb-4 sm:mb-0 px-0 sm:px-4 py-4"
style={{ width: '100%' }}
>
<h3 className="mb-1 mt-1 text-2xl font-bold text-gray-900 dark:text-white">
DID Document
Expand Down Expand Up @@ -209,17 +210,16 @@ const OrganizationDetails = ({ orgData }: { orgData: Organisation | null }) => {
</pre>
</div>
<div className="flex items-start mt-4 mr-4">
<CopyDid
className="block text-sm truncate"
value={JSON.stringify(agentData?.didDocument)}
hideValue={true}
/>
<Tooltip
content={'Copy DID Document'}
placement="bottom"
className="items-center text-center dark:text-white"
>
<CopyDid
className="block text-sm truncate"
value={JSON.stringify(agentData?.didDocument)}
hideValue={true}
/>
</Tooltip>
></Tooltip>
</div>
</div>
</div>
Expand Down
40 changes: 13 additions & 27 deletions src/components/organization/WalletSpinup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import { AlertComponent } from '../AlertComponent';
import CopyDid from '../../commonComponents/CopyDid';
import { DidMethod } from '../../common/enums';
import GenerateBtnPolygon from './walletCommonComponents/GenerateBtnPolygon';
import SetPrivateKeyValue from './walletCommonComponents/SetPrivateKeyValue';
import SetDomainValueInput from './walletCommonComponents/SetDomainValueInput';
import TokenWarningMessage from './walletCommonComponents/TokenWarningMessage';
import LedgerLessMethodsComponents from './walletCommonComponents/LegderLessMethods'
import SetPrivateKeyValueInput from './walletCommonComponents/SetPrivateKeyValue';


interface Values {
Expand Down Expand Up @@ -74,7 +74,7 @@ interface ISharedAgentForm {
loading: boolean;
submitSharedWallet: (
values: ValuesShared,
privatekey: string,
privateKey: string,
domain: string,
endPoint: string,
) => void;
Expand Down Expand Up @@ -244,8 +244,6 @@ const SharedAgentForm = ({
method: yup.string().required('Method is required'),
...(DidMethod.INDY === selectedLedger || DidMethod.POLYGON === selectedLedger) && { network: yup.string().required('Network is required') },
...(DidMethod.INDY === selectedLedger) && { ledger: yup.string().required('Ledger is required') },
...(DidMethod.WEB === selectedLedger) && { domain: yup.string().required('Domain is required for web method') },
...(DidMethod.POLYGON === selectedLedger) && { privatekey: yup.string().required('Private key is required').trim().length(64, 'Private key must be exactly 64 characters long') },
}

return (
Expand Down Expand Up @@ -280,8 +278,6 @@ const SharedAgentForm = ({
network: '',
did: '',
ledger: '',
domain: '',
privatekey: '',
label: orgName || '',
}}
validationSchema={yup.object().shape(validations)}
Expand Down Expand Up @@ -317,8 +313,8 @@ const SharedAgentForm = ({
id="method" name="method" className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500 h-11"
>
<option value="">Select Method</option>
{mappedData && Object.keys(mappedData)?.map((method) => (
<option key={method} value={method}>{method.charAt(0).toUpperCase() + method.slice(1)}</option>
{mappedData && Object.keys(mappedData)?.map((ledger) => (
<option key={ledger} value={ledger}>{ledger}</option>
))}
</select>
{formikHandlers?.errors?.method && formikHandlers?.touched?.method && (
Expand All @@ -340,22 +336,11 @@ const SharedAgentForm = ({
<div className="flex ">
<CopyDid
className="align-center block text-sm text-gray-900 dark:text-white truncate"
value={generatedKeys?.privateKey.slice(2)}
value={generatedKeys?.privateKey}
/>
</div>
</p>

<p className="text-sm truncate">
<span className="font-semibold text-gray-900 dark:text-white">
Public Key Base58:
</span>
<div className="flex ">
<CopyDid
className="align-center block text-sm text-gray-900 dark:text-white truncate"
value={generatedKeys?.publicKeyBase58}
/>
</div>
</p>
<p className="text-sm truncate">
<span className="font-semibold text-gray-900 dark:text-white">
Address:
Expand All @@ -372,9 +357,9 @@ const SharedAgentForm = ({

{generatedKeys && formikHandlers.values.method === DidMethod.POLYGON && (<TokenWarningMessage />)}

{formikHandlers.values.method === DidMethod.POLYGON && (<SetPrivateKeyValueInput setPrivateKeyValue={(val:string)=>setPrivateKeyValue(val)} privateKeyValue={privateKeyValue} formikHandlers={formikHandlers}/>)}
{formikHandlers.values.method === DidMethod.POLYGON && (<SetPrivateKeyValue setPrivateKeyValue={(val:string)=>setPrivateKeyValue(val)} privateKeyValue={privateKeyValue}/>)}

{formikHandlers.values.method === DidMethod.WEB && (<SetDomainValueInput setDomainValue={(val:string)=>setDomainValue(val)} domainValue={domainValue} formikHandlers={formikHandlers}/>)}
{formikHandlers.values.method === DidMethod.WEB && (<SetDomainValueInput setDomainValue={(val:string)=>setDomainValue(val)} domainValue={domainValue}/>)}

{formikHandlers.values.method !== DidMethod.POLYGON && formikHandlers.values.method !== DidMethod.KEY && formikHandlers.values.method !== DidMethod.WEB && (
<div className="my-3 relative">
Expand All @@ -398,7 +383,7 @@ const SharedAgentForm = ({
{mappedData && selectedLedger && mappedData[selectedLedger] &&
Object.keys(mappedData[selectedLedger])?.map(
(ledger) => (
<option key={ledger} value={ledger}>{ledger.charAt(0).toUpperCase() + ledger.slice(1)}</option>
<option key={ledger} value={ledger}>{ledger}</option>
),
)}
</select>
Expand Down Expand Up @@ -599,12 +584,12 @@ const SharedAgentForm = ({

{formikHandlers.values.method === DidMethod.POLYGON && (

<SetPrivateKeyValueInput setPrivateKeyValue={(val:string)=>setPrivateKeyValue(val)} privateKeyValue={privateKeyValue} formikHandlers={formikHandlers}/>
<SetPrivateKeyValue setPrivateKeyValue={(val:string)=>setPrivateKeyValue(val)} privateKeyValue={privateKeyValue}/>
)}

{formikHandlers.values.method === DidMethod.WEB && (

<SetDomainValueInput setDomainValue={(val:string)=>setDomainValue(val)} domainValue={domainValue} formikHandlers={formikHandlers}/>
<SetDomainValueInput setDomainValue={(val:string)=>setDomainValue(val)} domainValue={domainValue}/>

)}

Expand Down Expand Up @@ -927,17 +912,18 @@ const WalletSpinup = (props: {

const submitSharedWallet = async (
values: ValuesShared,
privatekey: string,
privateKey: string,
domain: string,
endPoint: string,
) => {
const polygonPrivateKey = privateKey.slice(2);
setLoading(true);
const payload = {
keyType: values.keyType || 'ed25519',
method: values.method || '',
ledger: values.method === DidMethod.INDY ? values.ledger : '',
label: values.label,
privatekey: values.method === DidMethod.POLYGON ? privatekey : '',
privatekey: values.method === DidMethod.POLYGON ? polygonPrivateKey : '',
seed: values.method === DidMethod.POLYGON ? '' : values.seed || seeds,
network:
values.method === DidMethod.POLYGON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,56 @@ interface IProps {
const LedgerLessMethodsComponent = ({ formikHandlers, setSelectedDid, selectedDid, mappedData, selectedLedger, selectedNetwork }: IProps) => {

return (
<div className="my-3 relative">
<label
htmlFor="network"
className="text-sm font-medium text-gray-900 dark:text-gray-300"
>
Network
<span className="text-red-500 text-xs">*</span>
</label>
<div className="my-3 relative">
<label
htmlFor="network"
className="text-sm font-medium text-gray-900 dark:text-gray-300"
>
Network
<span className="text-red-500 text-xs">*</span>
</label>

<select
onChange={(e) => {
formikHandlers.handleChange(e);
setSelectedDid(e.target.value);
}}
value={selectedDid}
id="network"
name="network"
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500 h-11"
>
<option value="">Select Network</option>
{formikHandlers.values.method === DidMethod.POLYGON &&
mappedData &&
Object.keys(mappedData[selectedLedger])?.map((network) => (
<option key={network} value={network}>
{network.charAt(0).toUpperCase() + network.slice(1)}{' '}
</option>
))}
{formikHandlers.values.method !== DidMethod.POLYGON &&
mappedData &&
selectedLedger &&
selectedNetwork &&
Object.keys(mappedData[selectedLedger][selectedNetwork])?.map(
(network) => (
<option key={network} value={network}>
{network.charAt(0).toUpperCase() + network.slice(1)}{' '}
</option>
),
)}
</select>
<select
onChange={(e) => {
formikHandlers.handleChange(e);
setSelectedDid(e.target.value);
}}
value={selectedDid}
id="network"
name="network"
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500 h-11"
>
<option value="">Select Network</option>
{formikHandlers.values.method === DidMethod.POLYGON &&
mappedData &&
Object.keys(mappedData[selectedLedger])?.map(
(network) => (
<option key={network} value={network}>
{network}
</option>
),
)}
{formikHandlers.values.method !== DidMethod.POLYGON &&
mappedData &&
selectedLedger &&
selectedNetwork &&
Object.keys(
mappedData[selectedLedger][selectedNetwork],
)?.map((network) => (
<option key={network} value={network}>
{network}
</option>
))}
</select>

{formikHandlers?.errors?.network &&
formikHandlers?.touched?.network && (
<span className="absolute botton-0 text-red-500 text-xs">
{formikHandlers?.errors?.network}
</span>
)}
</div>
);
{formikHandlers?.errors?.network &&
formikHandlers?.touched?.network && (
<span className="absolute botton-0 text-red-500 text-xs">
{formikHandlers?.errors?.network}
</span>
)}
</div>
)

}
export default LedgerLessMethodsComponent;
Loading

0 comments on commit 82023ff

Please sign in to comment.