export interface TokenStorage { getItem(key: string): Promise; setItem(key: string, value: string): Promise; deleteItem(key: string): Promise; } export const STORAGE_KEYS = { MWA_AUTH_TOKEN: 'dubs_mwa_auth_token', MWA_WALLET_ADDRESS: 'dubs_mwa_wallet_address', JWT_TOKEN: 'dubs_jwt_token', PHANTOM_SESSION: 'dubs_phantom_session', PHANTOM_CONNECT_IN_FLIGHT: 'dubs_phantom_connect_in_flight', } as const; /** * Creates a TokenStorage backed by expo-secure-store. * Lazy-imports the module so it's only required at runtime when actually used. * Throws a clear error if expo-secure-store is not installed. */ export function createSecureStoreStorage(): TokenStorage { // Use `any` to avoid requiring expo-secure-store types at build time. // The module is lazy-imported at runtime only when this storage is actually used. let SecureStore: any = null; function getStore(): { getItemAsync: (key: string) => Promise; setItemAsync: (key: string, value: string) => Promise; deleteItemAsync: (key: string) => Promise; } { if (!SecureStore) { try { // Use require() to keep the import opaque to TypeScript's DTS generation. // eslint-disable-next-line @typescript-eslint/no-var-requires SecureStore = require('expo-secure-store'); } catch { throw new Error( '@dubsdotapp/expo: expo-secure-store is required for default token storage. ' + 'Install it with: npx expo install expo-secure-store — ' + 'or pass a custom tokenStorage prop to .', ); } } return SecureStore; } return { async getItem(key: string): Promise { const store = getStore(); return store.getItemAsync(key); }, async setItem(key: string, value: string): Promise { const store = getStore(); await store.setItemAsync(key, value); }, async deleteItem(key: string): Promise { const store = getStore(); await store.deleteItemAsync(key); }, }; }