/* * Wire * Copyright (C) 2022 Wire Swiss GmbH * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. * */ import React, {useState} from 'react'; import {Button, CheckRoundIcon, ContainerSM, H1, Muted, Text} from '@wireapp/react-ui-kit'; import {handleEnterDown} from 'Util/KeyboardUtil'; import {t} from 'Util/LocalizerUtil'; import {EntropyData} from '../../util/Entropy'; import {EntropyCanvas} from '../component/EntropyCanvas'; import {ProgressBar} from '../component/ProgressBar'; interface Props extends React.HTMLProps { onSetEntropy: (entropyData: Uint8Array) => void; containerSize?: number; } const EntropyContainer = ({onSetEntropy, containerSize = 400}: Props) => { const [entropy, setEntropy] = useState(new EntropyData()); const [pause, setPause] = useState(); const [percent, setPercent] = useState(0); const onProgress = (entropyData: EntropyData, percentage: number, pause: boolean) => { setEntropy(entropyData); setPause(pause); setPercent(percentage); }; const forwardEntropy = async (entropy: Uint8Array) => { // we want to hash the entire entropy array to get a 256 bit (32 bytes) array const hashedValue = await window.crypto.subtle.digest('SHA-256', entropy); onSetEntropy(new Uint8Array(hashedValue)); }; return (

{t('setEntropy.headline')}

{percent >= 100 ? ( <> {t('setEntropy.success')} ) : ( <> {t('setEntropy.subheadline')} {percent}% )}
); }; export {EntropyContainer};