This commit is contained in:
Morten Olsen
2021-06-09 00:03:41 +02:00
commit b1b24f9774
14 changed files with 5990 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
import { useContext } from 'react';
import ConnectionContext, { States } from '../contexts/ConnectionContext';
const useConnection = () => {
const context = useContext(ConnectionContext);
return context;
};
export const ConnectionStates = States;
export default useConnection;

22
src/hooks/useCrypto.ts Normal file
View File

@@ -0,0 +1,22 @@
import { useCallback } from 'react';
import { encrypt, decrypt } from '../utils/crypto';
const useCrypto = (secret: string) => {
const doEncrypt = useCallback(async (data: any) => {
const raw = JSON.stringify(data);
const result = await encrypt(raw, secret);
return result;
}, [secret]);
const doDecrypt = useCallback(async (data: string[]) => {
return decrypt(data, secret);
}, [secret]);
return {
encrypt: doEncrypt,
decrypt: doDecrypt,
};
}
export default useCrypto;