This commit is contained in:
thePR0M3TH3AN
2024-10-26 22:56:57 -04:00
parent 6090c38b92
commit 7d4eef2110
22 changed files with 1759 additions and 1152 deletions

47
src/utils/fingerprint.py Normal file
View File

@@ -0,0 +1,47 @@
# utils/fingerprint.py
"""
Fingerprint Module
This module provides functionality to generate a unique, one-way hashed fingerprint
from a given seed phrase. The fingerprint serves as an identifier for each seed,
facilitating organized and secure storage.
"""
import hashlib
import logging
import traceback
from typing import Optional
# Instantiate the logger
logger = logging.getLogger(__name__)
def generate_fingerprint(seed_phrase: str, length: int = 16) -> Optional[str]:
"""
Generates a unique fingerprint from the provided seed phrase using SHA-256.
Parameters:
seed_phrase (str): The BIP-39 seed phrase.
length (int): The desired length of the fingerprint.
Returns:
Optional[str]: The generated fingerprint or None if an error occurs.
"""
try:
# Normalize the seed phrase
normalized_seed = seed_phrase.strip().lower()
logger.debug(f"Normalized seed: {normalized_seed}")
# Compute SHA-256 hash
sha256_hash = hashlib.sha256(normalized_seed.encode('utf-8')).hexdigest()
logger.debug(f"SHA-256 Hash: {sha256_hash}")
# Truncate to desired length
fingerprint = sha256_hash[:length].upper()
logger.debug(f"Generated Fingerprint: {fingerprint}")
return fingerprint
except Exception as e:
logger.error(f"Failed to generate fingerprint: {e}")
logger.error(traceback.format_exc())
return None