mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-08 07:18:47 +00:00
Improve test profile persistence
This commit is contained in:
@@ -39,45 +39,40 @@ DEFAULT_PASSWORD = "testpassword"
|
|||||||
|
|
||||||
def initialize_profile(profile_name: str) -> tuple[str, EntryManager, Path, str]:
|
def initialize_profile(profile_name: str) -> tuple[str, EntryManager, Path, str]:
|
||||||
"""Create or load a profile and return the seed phrase, manager, directory and fingerprint."""
|
"""Create or load a profile and return the seed phrase, manager, directory and fingerprint."""
|
||||||
temp_dir = APP_DIR / profile_name
|
seed_txt = APP_DIR / f"{profile_name}_seed.txt"
|
||||||
temp_dir.mkdir(parents=True, exist_ok=True)
|
if seed_txt.exists():
|
||||||
|
seed_phrase = seed_txt.read_text().strip()
|
||||||
seed_key = derive_key_from_password(DEFAULT_PASSWORD)
|
|
||||||
seed_mgr = EncryptionManager(seed_key, temp_dir)
|
|
||||||
seed_file = temp_dir / "parent_seed.enc"
|
|
||||||
clear_path = temp_dir / "seed_phrase.txt"
|
|
||||||
|
|
||||||
if seed_file.exists():
|
|
||||||
seed_phrase = seed_mgr.decrypt_parent_seed()
|
|
||||||
if not clear_path.exists():
|
|
||||||
clear_path.write_text(seed_phrase)
|
|
||||||
clear_path.chmod(0o600)
|
|
||||||
elif clear_path.exists():
|
|
||||||
seed_phrase = clear_path.read_text().strip()
|
|
||||||
seed_mgr.encrypt_parent_seed(seed_phrase)
|
|
||||||
else:
|
else:
|
||||||
seed_phrase = (
|
seed_phrase = (
|
||||||
Bip39MnemonicGenerator(Bip39Languages.ENGLISH)
|
Bip39MnemonicGenerator(Bip39Languages.ENGLISH)
|
||||||
.FromWordsNumber(Bip39WordsNum.WORDS_NUM_12)
|
.FromWordsNumber(Bip39WordsNum.WORDS_NUM_12)
|
||||||
.ToStr()
|
.ToStr()
|
||||||
)
|
)
|
||||||
seed_mgr.encrypt_parent_seed(seed_phrase)
|
seed_txt.write_text(seed_phrase)
|
||||||
clear_path.write_text(seed_phrase)
|
seed_txt.chmod(0o600)
|
||||||
clear_path.chmod(0o600)
|
|
||||||
|
|
||||||
fingerprint = generate_fingerprint(seed_phrase) or profile_name
|
fingerprint = generate_fingerprint(seed_phrase) or profile_name
|
||||||
profile_dir = APP_DIR / fingerprint
|
profile_dir = APP_DIR / fingerprint
|
||||||
if profile_dir != temp_dir:
|
profile_dir.mkdir(parents=True, exist_ok=True)
|
||||||
profile_dir.mkdir(parents=True, exist_ok=True)
|
|
||||||
for p in temp_dir.iterdir():
|
seed_key = derive_key_from_password(DEFAULT_PASSWORD)
|
||||||
target = profile_dir / p.name
|
seed_mgr = EncryptionManager(seed_key, profile_dir)
|
||||||
if not target.exists():
|
seed_file = profile_dir / "parent_seed.enc"
|
||||||
p.rename(target)
|
clear_path = profile_dir / "seed_phrase.txt"
|
||||||
|
|
||||||
|
if seed_file.exists():
|
||||||
try:
|
try:
|
||||||
temp_dir.rmdir()
|
current = seed_mgr.decrypt_parent_seed()
|
||||||
except OSError:
|
except Exception:
|
||||||
pass
|
current = None
|
||||||
seed_mgr.fingerprint_dir = profile_dir
|
if current != seed_phrase:
|
||||||
|
seed_mgr.encrypt_parent_seed(seed_phrase)
|
||||||
|
else:
|
||||||
|
seed_mgr.encrypt_parent_seed(seed_phrase)
|
||||||
|
|
||||||
|
if not clear_path.exists():
|
||||||
|
clear_path.write_text(seed_phrase)
|
||||||
|
clear_path.chmod(0o600)
|
||||||
|
|
||||||
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)
|
||||||
|
Reference in New Issue
Block a user