mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-08 15:28:44 +00:00
Merge pull request #475 from PR0M3TH3AN/codex/check-data-and-setup-for-new-profiles
Handle fresh managed accounts with empty vault
This commit is contained in:
@@ -61,6 +61,7 @@ from utils.terminal_utils import (
|
|||||||
)
|
)
|
||||||
from utils.fingerprint import generate_fingerprint
|
from utils.fingerprint import generate_fingerprint
|
||||||
from constants import MIN_HEALTHY_RELAYS
|
from constants import MIN_HEALTHY_RELAYS
|
||||||
|
from password_manager.migrations import LATEST_VERSION
|
||||||
|
|
||||||
from constants import (
|
from constants import (
|
||||||
APP_DIR,
|
APP_DIR,
|
||||||
@@ -1037,10 +1038,15 @@ class PasswordManager:
|
|||||||
self._relay_thread.start()
|
self._relay_thread.start()
|
||||||
|
|
||||||
def sync_index_from_nostr_if_missing(self) -> None:
|
def sync_index_from_nostr_if_missing(self) -> None:
|
||||||
"""Retrieve the password database from Nostr if it doesn't exist locally."""
|
"""Retrieve the password database from Nostr if it doesn't exist locally.
|
||||||
|
|
||||||
|
If no valid data is found or decryption fails, initialize a fresh local
|
||||||
|
database and publish it to Nostr.
|
||||||
|
"""
|
||||||
index_file = self.fingerprint_dir / "seedpass_entries_db.json.enc"
|
index_file = self.fingerprint_dir / "seedpass_entries_db.json.enc"
|
||||||
if index_file.exists():
|
if index_file.exists():
|
||||||
return
|
return
|
||||||
|
have_data = False
|
||||||
try:
|
try:
|
||||||
result = asyncio.run(self.nostr_client.fetch_latest_snapshot())
|
result = asyncio.run(self.nostr_client.fetch_latest_snapshot())
|
||||||
if result:
|
if result:
|
||||||
@@ -1056,11 +1062,24 @@ class PasswordManager:
|
|||||||
encrypted = deltas[-1]
|
encrypted = deltas[-1]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
self.vault.decrypt_and_save_index_from_nostr(encrypted)
|
try:
|
||||||
logger.info("Initialized local database from Nostr.")
|
self.vault.decrypt_and_save_index_from_nostr(encrypted)
|
||||||
|
logger.info("Initialized local database from Nostr.")
|
||||||
|
have_data = True
|
||||||
|
except Exception as err:
|
||||||
|
logger.warning(
|
||||||
|
f"Failed to decrypt Nostr data: {err}; treating as new account."
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Unable to sync index from Nostr: {e}")
|
logger.warning(f"Unable to sync index from Nostr: {e}")
|
||||||
|
|
||||||
|
if not have_data:
|
||||||
|
self.vault.save_index({"schema_version": LATEST_VERSION, "entries": {}})
|
||||||
|
try:
|
||||||
|
self.sync_vault()
|
||||||
|
except Exception as exc: # pragma: no cover - best effort
|
||||||
|
logger.warning(f"Unable to publish fresh database: {exc}")
|
||||||
|
|
||||||
def handle_add_password(self) -> None:
|
def handle_add_password(self) -> None:
|
||||||
try:
|
try:
|
||||||
fp, parent_fp, child_fp = self.header_fingerprint_args
|
fp, parent_fp, child_fp = self.header_fingerprint_args
|
||||||
|
Reference in New Issue
Block a user