From 27f6cfcba815e1fb40490fed04d9bc3636d71a08 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Sun, 29 Jun 2025 14:07:25 -0400 Subject: [PATCH] load db from nostr if missing --- src/password_manager/manager.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/password_manager/manager.py b/src/password_manager/manager.py index cf297a0..b18a335 100644 --- a/src/password_manager/manager.py +++ b/src/password_manager/manager.py @@ -200,6 +200,7 @@ class PasswordManager: # Initialize BIP85 and other managers self.initialize_bip85() self.initialize_managers() + self.sync_index_from_nostr_if_missing() print( colored( f"Fingerprint {fingerprint} selected and managers initialized.", @@ -311,6 +312,7 @@ class PasswordManager: # Initialize BIP85 and other managers self.initialize_bip85() self.initialize_managers() + self.sync_index_from_nostr_if_missing() print(colored(f"Switched to fingerprint {selected_fingerprint}.", "green")) # Re-initialize NostrClient with the new fingerprint @@ -483,6 +485,7 @@ class PasswordManager: self.initialize_bip85() self.initialize_managers() + self.sync_index_from_nostr_if_missing() return fingerprint # Return the generated or added fingerprint else: logging.error("Invalid BIP-85 seed phrase. Exiting.") @@ -613,6 +616,7 @@ class PasswordManager: self.initialize_bip85() self.initialize_managers() + self.sync_index_from_nostr_if_missing() except Exception as e: logging.error(f"Failed to encrypt and save parent seed: {e}") logging.error(traceback.format_exc()) @@ -679,6 +683,19 @@ class PasswordManager: print(colored(f"Error: Failed to initialize managers: {e}", "red")) sys.exit(1) + def sync_index_from_nostr_if_missing(self) -> None: + """Retrieve the password database from Nostr if it doesn't exist locally.""" + index_file = self.fingerprint_dir / "seedpass_passwords_db.json.enc" + if index_file.exists(): + return + try: + encrypted = self.nostr_client.retrieve_json_from_nostr_sync() + if encrypted: + self.encryption_manager.decrypt_and_save_index_from_nostr(encrypted) + logger.info("Initialized local database from Nostr.") + except Exception as e: + logger.warning(f"Unable to sync index from Nostr: {e}") + def handle_generate_password(self) -> None: try: website_name = input("Enter the website name: ").strip()