import type { EncryptedPayload } from './keyManagementEncryption' import { storageService } from './storage/indexedDB' export const KEY_STORAGE_KEY = 'nostr_encrypted_key' /** * Store account identifier in IndexedDB * This is just a flag to indicate that an account exists */ export async function storeAccountFlag(): Promise { await storageService.set('nostr_account_exists', true, 'nostr_key_storage') } /** * Check if account flag exists */ export async function hasAccountFlag(): Promise { try { const exists = await storageService.get('nostr_account_exists', 'nostr_key_storage') return exists === true } catch { return false } } /** * Remove account flag from IndexedDB */ export async function removeAccountFlag(): Promise { await storageService.delete('nostr_account_exists') } export async function getEncryptedKey(): Promise { return await storageService.get(KEY_STORAGE_KEY, 'nostr_key_storage') } export async function setEncryptedKey(encryptedNsec: EncryptedPayload): Promise { await storageService.set(KEY_STORAGE_KEY, encryptedNsec, 'nostr_key_storage') } export async function getPublicKeys(): Promise<{ publicKey: string; npub: string } | null> { try { const stored = await storageService.get<{ publicKey: string; npub: string }>('nostr_public_key', 'nostr_key_storage') return stored } catch { return null } } export async function setPublicKeys(publicKey: string, npub: string): Promise { await storageService.set('nostr_public_key', { publicKey, npub }, 'nostr_key_storage') } export async function deleteStoredKeys(): Promise { await storageService.delete(KEY_STORAGE_KEY) await storageService.delete('nostr_public_key') }