Enforce 12-word managed account seeds

This commit is contained in:
thePR0M3TH3AN
2025-07-07 22:28:09 -04:00
parent 988a50e066
commit 34784eefe0
6 changed files with 15 additions and 14 deletions

View File

@@ -481,11 +481,13 @@ class EntryManager:
parent_seed: str,
*,
index: int | None = None,
word_count: int = 24,
notes: str = "",
archived: bool = False,
) -> int:
"""Add a new managed account seed entry."""
"""Add a new managed account seed entry.
Managed accounts always use a 12-word seed phrase.
"""
if index is None:
index = self.get_next_index()
@@ -497,6 +499,8 @@ class EntryManager:
seed_bytes = Bip39SeedGenerator(parent_seed).Generate()
bip85 = BIP85(seed_bytes)
word_count = 12
seed_phrase = derive_seed_phrase(bip85, index, word_count)
fingerprint = generate_fingerprint(seed_phrase)
@@ -540,7 +544,7 @@ class EntryManager:
seed_bytes = Bip39SeedGenerator(parent_seed).Generate()
bip85 = BIP85(seed_bytes)
words = int(entry.get("word_count", 24))
words = int(entry.get("word_count", 12))
seed_index = int(entry.get("index", index))
return derive_seed_phrase(bip85, seed_index, words)

View File

@@ -1464,14 +1464,9 @@ class PasswordManager:
if not label:
print(colored("Error: Label cannot be empty.", "red"))
return
words_input = input("Word count (12 or 24, default 24): ").strip()
notes = input("Notes (optional): ").strip()
if words_input and words_input not in {"12", "24"}:
print(colored("Invalid word count. Choose 12 or 24.", "red"))
return
words = int(words_input) if words_input else 24
index = self.entry_manager.add_managed_account(
label, self.parent_seed, word_count=words, notes=notes
label, self.parent_seed, notes=notes
)
seed = self.entry_manager.get_managed_account_seed(index, self.parent_seed)
self.is_dirty = True

View File

@@ -26,7 +26,7 @@ def test_add_managed_account_fields_and_dir():
tmp_path = Path(tmpdir)
mgr = setup_entry_manager(tmp_path)
idx = mgr.add_managed_account("acct", TEST_SEED, word_count=12)
idx = mgr.add_managed_account("acct", TEST_SEED)
entry = mgr.retrieve_entry(idx)
assert entry["type"] == "managed_account"

View File

@@ -29,7 +29,7 @@ def test_add_and_get_managed_account_seed():
tmp_path = Path(tmpdir)
mgr = setup_mgr(tmp_path)
idx = mgr.add_managed_account("acct", TEST_SEED, word_count=12)
idx = mgr.add_managed_account("acct", TEST_SEED)
entry = mgr.retrieve_entry(idx)
assert entry["type"] == "managed_account"
assert entry["kind"] == "managed_account"