import React, { useState } from 'react'; import { createAttachedSignature, createDetachedSignature, createHash } from 'crypto-pro'; import Message from './components/Message'; import Certificate from './components/Certificate'; import SignatureType from './components/SignatureType'; import Hash from './components/Hash'; import Signature from './components/Signature'; import SystemInfo from './components/SystemInfo'; function App() { const [message, setMessage] = useState(''); const [certificate, setCertificate] = useState(null); const [detachedSignature, setSignatureType] = useState(null); const [hash, setHash] = useState(''); const [hashStatus, setHashStatus] = useState('Не вычислен'); const [hashError, setHashError] = useState(null); const [signature, setSignature] = useState(''); const [signatureStatus, setSignatureStatus] = useState('Не создана'); const [signatureError, setSignatureError] = useState(null); async function createSignature(event) { let hash; event.preventDefault(); setSignature(''); setSignatureError(null); setHash(''); setHashError(null); setHashStatus('Вычисляется...'); try { hash = await createHash(message); setHash(hash); } catch (error) { setHashError(error.message); return; } setHashStatus('Не вычислен'); setSignatureStatus('Создается...'); if (detachedSignature) { try { setSignature(await createDetachedSignature(certificate.thumbprint, hash)); } catch (error) { setSignatureError(error.message); } setSignatureStatus('Не создана'); return; } try { setSignature(await createAttachedSignature(certificate.thumbprint, message)); } catch (error) { setSignatureError(error.message); } setSignatureStatus('Не создана'); } return ( <>
> ); } export default App;