Cleanup - unused files / unused exports / duplicate exports
[ProtonMail-WebClient.git] / packages / shared / lib / authentication / offlineKey.ts
blobc20e5cd089c5547e3a8eea2389b2a1cb0fc58f4a
1 import { ARGON2_PARAMS, CryptoProxy } from '@proton/crypto';
2 import { uint8ArrayToBase64String } from '@proton/shared/lib/helpers/encoding';
4 import { captureMessage } from '../helpers/sentry';
6 export interface OfflineKey {
7     password: string;
8     salt: string;
11 export const getOfflineKey = (password: string, salt: Uint8Array) => {
12     return CryptoProxy.computeArgon2({
13         params: ARGON2_PARAMS.RECOMMENDED,
14         password,
15         salt,
16     });
19 export const generateOfflineKey = async (clearKeyPassword: string): Promise<OfflineKey | undefined> => {
20     try {
21         const salt = crypto.getRandomValues(new Uint8Array(32));
22         const key = await getOfflineKey(clearKeyPassword, salt);
23         return {
24             password: uint8ArrayToBase64String(key),
25             salt: uint8ArrayToBase64String(salt),
26         };
27     } catch (e: any) {
28         captureMessage('Argon2 error', { level: 'info', extra: { message: e.message } });
29         return;
30     }