/* * settings_sync.h — NIP-78 (kind 30078) settings sync for sovereign_browser * * Syncs user-configurable, device-independent settings across all devices * the user logs in on. Uses a single kind 30078 addressable event with * d-tag "sovereign_browser". The content is NIP-44 encrypted (self-to-self) * JSON containing whitelisted settings + all keyboard shortcut bindings. * * Device-specific settings (agent port, allowed origins, session restore, * security toggles) are NOT synced — they stay local only. * * See plans/keyboard-shortcuts.md for the full design. */ #ifndef SETTINGS_SYNC_H #define SETTINGS_SYNC_H #include /* nostr_signer_t is needed for the init function */ #include "nostr_core/nostr_signer.h" #ifdef __cplusplus extern "C" { #endif /* The d-tag identifier used for our kind 30078 event. */ #define SETTINGS_SYNC_D_TAG "sovereign_browser" /* The Nostr kind for arbitrary custom app data (NIP-78). */ #define SETTINGS_SYNC_KIND 30078 /* * Initialize the settings sync module. Stores the signer + pubkey * references for later publish/merge operations. * * signer — the user's nostr_signer_t (NULL for read-only/no-login) * pubkey_hex — the user's hex pubkey (64 chars, may be NULL) * * Call after login and after shortcuts_load() / settings_load(). */ void settings_sync_init(nostr_signer_t *signer, const char *pubkey_hex); /* * Serialize all syncable settings + shortcuts, NIP-44 encrypt to self, * build and sign a kind 30078 event, publish to bootstrap relays, and * store in SQLite. Debounced internally (500ms) so rapid edits coalesce * into a single publish. * * Safe to call from the main thread. No-op if no signer is available * (read-only / no-login mode). */ void settings_sync_publish(void); /* * Decrypt and merge settings from a fetched kind 30078 event. * Called by the relay fetch thread after login. Compares the event's * created_at to the last-synced timestamp; if the Nostr event is newer, * overwrites local db_kv values and reloads in-memory bindings. * * event — a cJSON object representing a kind 30078 event with * d-tag "sovereign_browser" * * Returns 0 on success, -1 on error / not applicable. */ int settings_sync_merge_from_nostr(const void *event_cjson); /* * Update the signer reference (e.g. after switching identity). */ void settings_sync_set_signer(nostr_signer_t *signer, const char *pubkey_hex); #ifdef __cplusplus } #endif #endif /* SETTINGS_SYNC_H */