Merge pull request #333 from PR0M3TH3AN/codex/investigate-seedpass-sync-issue

Fix test profile directory mismatch
This commit is contained in:
thePR0M3TH3AN
2025-07-06 18:03:33 -04:00
committed by GitHub
3 changed files with 33 additions and 20 deletions

View File

@@ -360,14 +360,14 @@ pytest -vv -s -n 0 src/tests/test_nostr_index_size.py --desktop --max-entries=10
Use the helper script below to populate a profile with sample entries for testing: Use the helper script below to populate a profile with sample entries for testing:
```bash ```bash
python scripts/generate_test_profile.py --profile my_profile --count 100 python scripts/generate_test_profile.py --profile demo_profile --count 100
``` ```
This command creates `~/.seedpass/my_profile` if needed and adds 100 example entries. The script now determines the fingerprint from the generated seed and stores the
After populating the vault, the script prints the derived **fingerprint** and vault under `~/.seedpass/<fingerprint>`. It also prints the fingerprint after
automatically publishes the encrypted index to Nostr under that fingerprint. creation and publishes the encrypted index to Nostr. Use that same seed phrase
Use the same seed phrase when loading SeedPass so it can retrieve the data from to load SeedPass. The app checks Nostr on startup and pulls any newer snapshot
Nostr. so your vault stays in sync across machines.
### Automatically Updating the Script Checksum ### Automatically Updating the Script Checksum

View File

@@ -37,15 +37,15 @@ import gzip
DEFAULT_PASSWORD = "testpassword" DEFAULT_PASSWORD = "testpassword"
def initialize_profile(profile_name: str) -> tuple[str, EntryManager, Path]: def initialize_profile(profile_name: str) -> tuple[str, EntryManager, Path, str]:
"""Create or load a profile and return the seed phrase and manager.""" """Create or load a profile and return the seed phrase, manager, directory and fingerprint."""
profile_dir = APP_DIR / profile_name temp_dir = APP_DIR / profile_name
profile_dir.mkdir(parents=True, exist_ok=True) temp_dir.mkdir(parents=True, exist_ok=True)
seed_key = derive_key_from_password(DEFAULT_PASSWORD) seed_key = derive_key_from_password(DEFAULT_PASSWORD)
seed_mgr = EncryptionManager(seed_key, profile_dir) seed_mgr = EncryptionManager(seed_key, temp_dir)
seed_file = profile_dir / "parent_seed.enc" seed_file = temp_dir / "parent_seed.enc"
clear_path = profile_dir / "seed_phrase.txt" clear_path = temp_dir / "seed_phrase.txt"
if seed_file.exists(): if seed_file.exists():
seed_phrase = seed_mgr.decrypt_parent_seed() seed_phrase = seed_mgr.decrypt_parent_seed()
@@ -65,13 +65,27 @@ def initialize_profile(profile_name: str) -> tuple[str, EntryManager, Path]:
clear_path.write_text(seed_phrase) clear_path.write_text(seed_phrase)
clear_path.chmod(0o600) clear_path.chmod(0o600)
fingerprint = generate_fingerprint(seed_phrase) or profile_name
profile_dir = APP_DIR / fingerprint
if profile_dir != temp_dir:
profile_dir.mkdir(parents=True, exist_ok=True)
for p in temp_dir.iterdir():
target = profile_dir / p.name
if not target.exists():
p.rename(target)
try:
temp_dir.rmdir()
except OSError:
pass
seed_mgr.fingerprint_dir = profile_dir
index_key = derive_index_key(seed_phrase) index_key = derive_index_key(seed_phrase)
enc_mgr = EncryptionManager(index_key, profile_dir) enc_mgr = EncryptionManager(index_key, profile_dir)
vault = Vault(enc_mgr, profile_dir) vault = Vault(enc_mgr, profile_dir)
cfg_mgr = ConfigManager(vault, profile_dir) cfg_mgr = ConfigManager(vault, profile_dir)
backup_mgr = BackupManager(profile_dir, cfg_mgr) backup_mgr = BackupManager(profile_dir, cfg_mgr)
entry_mgr = EntryManager(vault, backup_mgr) entry_mgr = EntryManager(vault, backup_mgr)
return seed_phrase, entry_mgr, profile_dir return seed_phrase, entry_mgr, profile_dir, fingerprint
def random_secret(length: int = 16) -> str: def random_secret(length: int = 16) -> str:
@@ -132,8 +146,7 @@ def main() -> None:
) )
args = parser.parse_args() args = parser.parse_args()
seed, entry_mgr, dir_path = initialize_profile(args.profile) seed, entry_mgr, dir_path, fingerprint = initialize_profile(args.profile)
fingerprint = generate_fingerprint(seed)
print(f"Using profile directory: {dir_path}") print(f"Using profile directory: {dir_path}")
print(f"Parent seed: {seed}") print(f"Parent seed: {seed}")
if fingerprint: if fingerprint:

View File

@@ -302,7 +302,7 @@ class PasswordManager:
# Initialize BIP85 and other managers # Initialize BIP85 and other managers
self.initialize_bip85() self.initialize_bip85()
self.initialize_managers() self.initialize_managers()
self.sync_index_from_nostr_if_missing() self.sync_index_from_nostr()
print( print(
colored( colored(
f"Seed profile {fingerprint} selected and managers initialized.", f"Seed profile {fingerprint} selected and managers initialized.",
@@ -432,7 +432,7 @@ class PasswordManager:
# Initialize BIP85 and other managers # Initialize BIP85 and other managers
self.initialize_bip85() self.initialize_bip85()
self.initialize_managers() self.initialize_managers()
self.sync_index_from_nostr_if_missing() self.sync_index_from_nostr()
print(colored(f"Switched to seed profile {selected_fingerprint}.", "green")) print(colored(f"Switched to seed profile {selected_fingerprint}.", "green"))
# Re-initialize NostrClient with the new fingerprint # Re-initialize NostrClient with the new fingerprint
@@ -616,7 +616,7 @@ class PasswordManager:
self.initialize_bip85() self.initialize_bip85()
self.initialize_managers() self.initialize_managers()
self.sync_index_from_nostr_if_missing() self.sync_index_from_nostr()
return fingerprint # Return the generated or added fingerprint return fingerprint # Return the generated or added fingerprint
else: else:
logging.error("Invalid BIP-85 seed phrase. Exiting.") logging.error("Invalid BIP-85 seed phrase. Exiting.")
@@ -757,7 +757,7 @@ class PasswordManager:
self.initialize_bip85() self.initialize_bip85()
self.initialize_managers() self.initialize_managers()
self.sync_index_from_nostr_if_missing() self.sync_index_from_nostr()
except Exception as e: except Exception as e:
logging.error(f"Failed to encrypt and save parent seed: {e}", exc_info=True) logging.error(f"Failed to encrypt and save parent seed: {e}", exc_info=True)
print(colored(f"Error: Failed to encrypt and save parent seed: {e}", "red")) print(colored(f"Error: Failed to encrypt and save parent seed: {e}", "red"))