diff --git a/examples/react/src/App.css b/examples/react/src/App.css deleted file mode 100644 index 74b5e05..0000000 --- a/examples/react/src/App.css +++ /dev/null @@ -1,38 +0,0 @@ -.App { - text-align: center; -} - -.App-logo { - height: 40vmin; - pointer-events: none; -} - -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-spin infinite 20s linear; - } -} - -.App-header { - background-color: #282c34; - min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - font-size: calc(10px + 2vmin); - color: white; -} - -.App-link { - color: #61dafb; -} - -@keyframes App-logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } -} diff --git a/examples/react/src/App.js b/examples/react/src/App.js index 7e9e533..dc8e28e 100644 --- a/examples/react/src/App.js +++ b/examples/react/src/App.js @@ -1,21 +1,118 @@ -import React from 'react'; -import './App.css'; -import CryptoPro from './components/CryptoPro'; +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 ( - {({certificate, setCertificate, signature, setSignature, error, setError}) => - <> - - - Создать подпись - - -