mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-10 08:19:23 +00:00
refactor: rename entropy length parameter
This commit is contained in:
@@ -461,7 +461,7 @@ class EntryManager:
|
||||
|
||||
seed_bytes = Bip39SeedGenerator(parent_seed).Generate()
|
||||
bip85 = BIP85(seed_bytes)
|
||||
entropy = bip85.derive_entropy(index=index, bytes_len=32)
|
||||
entropy = bip85.derive_entropy(index=index, entropy_bytes=32)
|
||||
keys = Keys(priv_k=entropy.hex())
|
||||
npub = Keys.hex_to_bech32(keys.public_key_hex(), "npub")
|
||||
nsec = Keys.hex_to_bech32(keys.private_key_hex(), "nsec")
|
||||
@@ -539,7 +539,7 @@ class EntryManager:
|
||||
bip85 = BIP85(seed_bytes)
|
||||
|
||||
key_idx = int(entry.get("index", index))
|
||||
entropy = bip85.derive_entropy(index=key_idx, bytes_len=32)
|
||||
entropy = bip85.derive_entropy(index=key_idx, entropy_bytes=32)
|
||||
keys = Keys(priv_k=entropy.hex())
|
||||
npub = Keys.hex_to_bech32(keys.public_key_hex(), "npub")
|
||||
nsec = Keys.hex_to_bech32(keys.private_key_hex(), "nsec")
|
||||
|
@@ -280,13 +280,15 @@ class PasswordManager:
|
||||
)
|
||||
|
||||
@requires_unlocked
|
||||
def get_bip85_entropy(self, purpose: int, index: int, bytes_len: int = 32) -> bytes:
|
||||
def get_bip85_entropy(
|
||||
self, purpose: int, index: int, entropy_bytes: int = 32
|
||||
) -> bytes:
|
||||
"""Return deterministic entropy via the cached BIP-85 function."""
|
||||
|
||||
if self.bip85 is None:
|
||||
raise RuntimeError("BIP-85 is not initialized")
|
||||
return self.bip85.derive_entropy(
|
||||
index=index, bytes_len=bytes_len, app_no=purpose
|
||||
index=index, entropy_bytes=entropy_bytes, app_no=purpose
|
||||
)
|
||||
|
||||
@requires_unlocked
|
||||
@@ -1243,11 +1245,13 @@ class PasswordManager:
|
||||
self._bip85_cache = {}
|
||||
orig_derive = self.bip85.derive_entropy
|
||||
|
||||
def cached_derive(index: int, bytes_len: int, app_no: int = 39) -> bytes:
|
||||
def cached_derive(
|
||||
index: int, entropy_bytes: int, app_no: int = 39
|
||||
) -> bytes:
|
||||
key = (app_no, index)
|
||||
if key not in self._bip85_cache:
|
||||
self._bip85_cache[key] = orig_derive(
|
||||
index=index, bytes_len=bytes_len, app_no=app_no
|
||||
index=index, entropy_bytes=entropy_bytes, app_no=app_no
|
||||
)
|
||||
return self._bip85_cache[key]
|
||||
|
||||
@@ -2727,14 +2731,14 @@ class PasswordManager:
|
||||
from bip_utils import Bip39SeedGenerator
|
||||
|
||||
words = int(entry.get("word_count", entry.get("words", 24)))
|
||||
bytes_len = {12: 16, 18: 24, 24: 32}.get(words, 32)
|
||||
entropy_bytes = {12: 16, 18: 24, 24: 32}.get(words, 32)
|
||||
seed_bytes = Bip39SeedGenerator(self.parent_seed).Generate()
|
||||
bip85 = BIP85(seed_bytes)
|
||||
entropy = bip85.derive_entropy(
|
||||
index=int(entry.get("index", index)),
|
||||
bytes_len=bytes_len,
|
||||
entropy_bytes=entropy_bytes,
|
||||
app_no=39,
|
||||
words_len=words,
|
||||
word_count=words,
|
||||
)
|
||||
print(color_text(f"Entropy: {entropy.hex()}", "deterministic"))
|
||||
except Exception as e: # pragma: no cover - best effort
|
||||
|
@@ -126,7 +126,7 @@ class PasswordGenerator:
|
||||
|
||||
def _derive_password_entropy(self, index: int) -> bytes:
|
||||
"""Derive deterministic entropy for password generation."""
|
||||
entropy = self.bip85.derive_entropy(index=index, bytes_len=64, app_no=32)
|
||||
entropy = self.bip85.derive_entropy(index=index, entropy_bytes=64, app_no=32)
|
||||
logger.debug("Entropy derived for password generation.")
|
||||
|
||||
hkdf = HKDF(
|
||||
@@ -433,7 +433,7 @@ class PasswordGenerator:
|
||||
|
||||
def derive_ssh_key(bip85: BIP85, idx: int) -> bytes:
|
||||
"""Derive 32 bytes of entropy suitable for an SSH key."""
|
||||
return bip85.derive_entropy(index=idx, bytes_len=32, app_no=32)
|
||||
return bip85.derive_entropy(index=idx, entropy_bytes=32, app_no=32)
|
||||
|
||||
|
||||
def derive_ssh_key_pair(parent_seed: str, index: int) -> tuple[str, str]:
|
||||
@@ -499,7 +499,7 @@ def derive_pgp_key(
|
||||
import hashlib
|
||||
import datetime
|
||||
|
||||
entropy = bip85.derive_entropy(index=idx, bytes_len=32, app_no=32)
|
||||
entropy = bip85.derive_entropy(index=idx, entropy_bytes=32, app_no=32)
|
||||
created = datetime.datetime(2000, 1, 1, tzinfo=datetime.timezone.utc)
|
||||
|
||||
if key_type.lower() == "rsa":
|
||||
|
Reference in New Issue
Block a user