@@ -7,7 +7,6 @@ import TorConnectionBadge from './components/TorConnection';
77
88import { I18nextProvider } from 'react-i18next';
99import i18n from './i18n/Web';
10- import * as CryptoJS from 'crypto-js';
1110
1211import { systemClient } from './services/System';
1312import ErrorBoundary from './components/ErrorBoundary';
@@ -16,64 +15,7 @@ import { GarageContextProvider } from './contexts/GarageContext';
1615import { FederationContextProvider } from './contexts/FederationContext';
1716import NotificationSwitchBadge from './components/NotificationSwitch';
1817
19- interface SubtleCrypto {
20- digest(algorithm: string, data: ArrayBuffer | Uint8Array | string): Promise<Uint8Array>;
21- }
22-
23- interface Crypto {
24- getRandomValues(arr: Uint8Array): Uint8Array;
25- subtle: SubtleCrypto;
26- }
27-
2818const App = (): React.JSX.Element => {
29- // Necesary for OpenPGP JS
30- const getWebCrypto = (): { subtle: SubtleCrypto } => {
31- return {
32- subtle: {
33- digest: (
34- algorithm: string,
35- data: ArrayBuffer | Uint8Array | string,
36- ): Promise<Uint8Array> => {
37- return new Promise((resolve, reject) => {
38- if (algorithm === 'SHA-256') {
39- let message: string;
40- if (data instanceof Uint8Array) {
41- message = new TextDecoder().decode(data);
42- } else if (data instanceof ArrayBuffer) {
43- message = new TextDecoder().decode(new Uint8Array(data));
44- } else {
45- message = data;
46- }
47-
48- const hash = CryptoJS.SHA256(message).toString();
49- const match = hash.match(/.{1,2}/g);
50- if (!match) {
51- return reject(new Error('Hash computation failed'));
52- }
53- const hashArray = new Uint8Array(match.map((byte) => parseInt(byte, 16)));
54- resolve(hashArray);
55- } else {
56- reject(new Error('Algorithm not supported'));
57- }
58- });
59- },
60- },
61- };
62- };
63-
64- if (typeof window !== 'undefined' && !window?.crypto?.subtle) {
65- // eslint-disable-next-line @typescript-eslint/no-explicit-any
66- (window as any).crypto = {
67- getRandomValues: (arr: Uint8Array): Uint8Array => {
68- for (let i = 0; i < arr.length; i++) {
69- arr[i] = Math.floor(Math.random() * 256);
70- }
71- return arr;
72- },
73- subtle: getWebCrypto().subtle,
74- } as Crypto;
75- }
76-
7719 const [client] = window.RobosatsSettings.split('-');
7820 return (
7921 <StrictMode>
0 commit comments