Add method parameter to seed setup

This commit is contained in:
thePR0M3TH3AN
2025-07-16 04:04:13 -04:00
parent 8370dec5c3
commit f701124fb1

View File

@@ -15,7 +15,7 @@ import logging
import getpass import getpass
import os import os
import hashlib import hashlib
from typing import Optional from typing import Optional, Literal
import shutil import shutil
import time import time
import builtins import builtins
@@ -750,24 +750,42 @@ class PasswordManager:
).strip() ).strip()
if choice == "1": if choice == "1":
self.setup_existing_seed() self.setup_existing_seed(method="paste")
elif choice == "2": elif choice == "2":
self.setup_existing_seed_word_by_word() self.setup_existing_seed(method="words")
elif choice == "3": elif choice == "3":
self.generate_new_seed() self.generate_new_seed()
else: else:
print(colored("Invalid choice. Exiting.", "red")) print(colored("Invalid choice. Exiting.", "red"))
sys.exit(1) sys.exit(1)
def setup_existing_seed(self) -> Optional[str]: def setup_existing_seed(
""" self, method: Literal["paste", "words"] = "paste"
Prompts the user to enter an existing BIP-85 seed and validates it. ) -> Optional[str]:
"""Prompt for an existing BIP-85 seed and set it up.
Returns: Parameters
Optional[str]: The fingerprint if setup is successful, None otherwise. ----------
method:
``"paste"`` to enter the entire phrase at once or ``"words"`` to
be prompted one word at a time.
Returns
-------
Optional[str]
The fingerprint if setup is successful, ``None`` otherwise.
""" """
try: try:
if method == "words":
parent_seed = prompt_seed_words()
else:
parent_seed = masked_input("Enter your 12-word BIP-85 seed: ").strip() parent_seed = masked_input("Enter your 12-word BIP-85 seed: ").strip()
if not self.validate_bip85_seed(parent_seed):
logging.error("Invalid BIP-85 seed phrase. Exiting.")
print(colored("Error: Invalid BIP-85 seed phrase.", "red"))
sys.exit(1)
return self._finalize_existing_seed(parent_seed) return self._finalize_existing_seed(parent_seed)
except KeyboardInterrupt: except KeyboardInterrupt:
logging.info("Operation cancelled by user.") logging.info("Operation cancelled by user.")
@@ -776,13 +794,7 @@ class PasswordManager:
def setup_existing_seed_word_by_word(self) -> Optional[str]: def setup_existing_seed_word_by_word(self) -> Optional[str]:
"""Prompt for an existing seed one word at a time and set it up.""" """Prompt for an existing seed one word at a time and set it up."""
try: return self.setup_existing_seed(method="words")
parent_seed = prompt_seed_words()
return self._finalize_existing_seed(parent_seed)
except KeyboardInterrupt:
logging.info("Operation cancelled by user.")
self.notify("Operation cancelled by user.", level="WARNING")
sys.exit(0)
def _finalize_existing_seed(self, parent_seed: str) -> Optional[str]: def _finalize_existing_seed(self, parent_seed: str) -> Optional[str]:
"""Common logic for initializing an existing seed.""" """Common logic for initializing an existing seed."""