import React, { useEffect, useMemo, useState } from 'react'; import { Link, Navigate, useParams } from 'react-router-dom'; import { generateSvgAvatar } from '../images/GenerateOnboardingSvg/GenerateSvg'; import User06 from '../images/user-28-06.jpg'; import User08 from '../images/user-28-08.jpg'; import User09 from '../images/user-28-09.jpg'; import SharedDataRoadMap from '../partials/sharedData/SharedDataRoadmap'; import { store } from '../store/store'; import { fetchWrapper } from '../shared/fetchWrapper'; import { cryptography } from '@liskhq/lisk-client'; import { generateTransaction } from '../utils/Utils'; function SharedData() { const [encryptedData, setEncryptedData] = useState([]); const [hasError, setHasError] = useState(false); const { id } = useParams(); const [address, pubKey] = id.split(':'); const passPhrase = sessionStorage.getItem('passPhrase'); useEffect(() => { fetchWrapper .get(`data/shared/${id}`) .then((res) => setEncryptedData(res.data ?? [])) .catch((err) => console.log(err)); }, [id]); const decryptedData = useMemo(() => { return encryptedData.map((item) => { let seed, value, hash; try { [seed, value] = cryptography .decryptMessageWithPassphrase( item.value, item.value_nonce, passPhrase, Buffer.from(pubKey, 'hex') ) .split(':'); hash = cryptography .hash( Buffer.concat([ Buffer.from(seed, 'utf8'), cryptography.hash(value, 'utf8'), ]) ) .toString('hex'); } catch (err) { setHasError(true); console.log(err); } finally { return { seed, value, hash, label: item.label, }; } }); }, [encryptedData]); const validateAccountData = () => { const builder = generateTransaction( BigInt(store.accountInfo?.sequence?.nonce || 0), store.pubKey, store.nodeInfo.networkIdentifier, store.passPhrase, store.nodeInfo?.genesisConfig?.minFeePerByte, store.nodeInfo?.genesisConfig?.baseFees ); const signedTx = builder.validate( decryptedData.map((e) => ({ label: e.label, value: Buffer.from(e.hash, 'hex'), })), address ); if (signedTx) { fetchWrapper .post('transactions', {}, signedTx) .catch((err) => console.log(err)); } }; if (!passPhrase) return ; return (
{/* Content */}

Shared data ✨

    {!hasError && decryptedData.map((item) => (
  • ))} {hasError && encryptedData.map((item) => (
  • ))}
{!hasError && ( )}
{/* Image */}
); } export default SharedData;