1 import { instance } from '@proton/cross-storage/account-impl/guestInstance';
2 import type { APP_NAMES } from '@proton/shared/lib/constants';
3 import { APPS } from '@proton/shared/lib/constants';
4 import type { KTLocalStorageAPI } from '@proton/shared/lib/interfaces';
5 import { getDefaultKTLS } from '@proton/shared/lib/keyTransparency';
8 * Return the set of functions to use account's local storage
10 export const getKTLocalStorage = async (APP_NAME: APP_NAMES): Promise<KTLocalStorageAPI> => {
11 if (APP_NAME === APPS.PROTONACCOUNT || APP_NAME === APPS.PROTONVPN_SETTINGS || !instance) {
12 // If we are in account, or if the guest cross storage hasn't been setup, we use the app's local storage directly
13 return getDefaultKTLS();
15 // Check if cross storage is available
16 const crossStorageAvailable = await instance.supported();
17 if (!crossStorageAvailable) {
18 return getDefaultKTLS();
20 // Otherwise we access it via cross-storage
22 getItem: async (key: string) => instance.getLocalStorage(key),
23 setItem: async (key: string, value: string) => instance.setLocalStorage(key, value),
24 removeItem: async (key: string) => instance.removeLocalStorage(key),
25 getBlobs: () => instance.getLocalStorageKeys().then((keys) => keys || []),