1 import { hasBit } from '../helpers/bitset';
2 import { generateSharedSecret, getUri } from '../helpers/twofa';
3 import type { UserSettings } from '../interfaces';
4 import { SETTINGS_2FA_ENABLED } from '../interfaces';
6 export const TWO_FA_CONFIG = {
12 export const getHasTOTPEnabled = (Enabled?: number) => {
13 return hasBit(Enabled || 0, SETTINGS_2FA_ENABLED.OTP);
16 export const getHasFIDO2Enabled = (Enabled?: number) => {
17 return hasBit(Enabled || 0, SETTINGS_2FA_ENABLED.FIDO2);
20 export const getHasTOTPSettingEnabled = (userSettings?: Pick<UserSettings, '2FA'>) => {
21 return getHasTOTPEnabled(userSettings?.['2FA']?.Enabled);
24 export const getHasFIDO2SettingEnabled = (userSettings?: Pick<UserSettings, '2FA'>) => {
25 return getHasFIDO2Enabled(userSettings?.['2FA'].Enabled);
28 export const getTOTPData = (identifier: string) => {
29 const sharedSecret = generateSharedSecret();
30 const period = TWO_FA_CONFIG.PERIOD;
31 const digits = TWO_FA_CONFIG.DIGITS;
38 algorithm: TWO_FA_CONFIG.ALGORITHM,