mirror of
https://github.com/morten-olsen/catpic.delivery.git
synced 2026-02-08 01:46:26 +01:00
init
This commit is contained in:
11
src/hooks/useConnection.ts
Normal file
11
src/hooks/useConnection.ts
Normal 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
22
src/hooks/useCrypto.ts
Normal 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;
|
||||
Reference in New Issue
Block a user