1 import { LockMode } from '@proton/pass/lib/auth/lock/types';
2 import type { Maybe } from '@proton/pass/types';
4 import type { OfflineConfig } from './crypto';
6 type PasswordUnlockOptions = {
9 offlineConfig: Maybe<OfflineConfig>;
10 offlineEnabled: boolean;
11 offlineVerifier: Maybe<string>;
12 encryptedOfflineKD: Maybe<string>;
14 /** We consider that the user can unlock with his proton
15 * password if we have an encrypted cache key & state and
16 * an offline configuration. If the user is offline, allow
17 * unlocking without checking the LockMode. */
18 export const canLocalUnlock = (options: PasswordUnlockOptions): boolean => {
19 if (!(options.offlineConfig && options.offlineVerifier)) return false;
20 if (options.offline) return OFFLINE_SUPPORTED && options.offlineEnabled;
21 if (options.lockMode === LockMode.BIOMETRICS) return Boolean(options.encryptedOfflineKD);
22 if (options.lockMode === LockMode.PASSWORD) return true;