Update wallet scripts: rename hdwallet_t.py to pyhdwallet.py and modify recovery script

This commit is contained in:
LC
2026-01-04 20:16:10 +00:00
parent 9ce1a834f6
commit 4d1ec957c7
2 changed files with 37 additions and 50 deletions

View File

@@ -537,53 +537,31 @@ def cmd_recover(args):
def cmd_test(args):
require_for_derive(False, ["ethereum"]) # minimal
from bip_utils import Bip39SeedGenerator, Bip39MnemonicValidator
with NetworkGuard("test"):
require_for_offline(["ethereum", "solana"])
print("🧪 Running Trezor BIP39/BIP32 test vectors...")
from bip_utils import Bip39SeedGenerator
mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
passphrase = "crypto"
expected_seed_hex = "92c58d3f4fe52f0111d314f3fa8f10ba498751c37e7c36475c2a5b60145b29708576e11bf6c5c46efac1add0cc26e07c69eb65476742082f9c6460f132181cfe"
expected_fp = "AECCC350"
print("🧪 Running tests...")
tests = [{
"mnemonic": mnemonic,
"passphrase": passphrase,
"expected_seed_hex": expected_seed_hex,
"expected_fp": expected_fp,
}]
# --- Existing vector (yours) ---
mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
passphrase = "" # empty
seed_bytes = Bip39SeedGenerator(mnemonic).Generate(passphrase)
all_passed = True
for i, test in enumerate(tests, 1):
print(f"\nTest {i}: With passphrase '{test['passphrase']}'")
# --- NEW: Solana path->address test ---
expected_addr = "HAgk14JpMQLgt6rVgv7cBQFJWFto5Dqxi472uT3DKpqk"
path = "m/44'/501'/0'/0'"
if not Bip39MnemonicValidator().IsValid(test["mnemonic"]):
print("❌ Invalid mnemonic")
all_passed = False
continue
seed32 = slip10_ed25519_seed32_from_path(seed_bytes, path) # or slip10_ed25519_seed32_by_path(...)
got_addr = sol_pubkey_b58_from_seed32(seed32)
seed_bytes = Bip39SeedGenerator(test["mnemonic"]).Generate(test["passphrase"])
seed_hex = seed_bytes.hex()
if got_addr != expected_addr:
raise RuntimeError(f"Solana address mismatch for {path}: got {got_addr}, expected {expected_addr}")
if seed_hex != test["expected_seed_hex"]:
print(f"❌ Seed mismatch: got {seed_hex}, expected {test['expected_seed_hex']}")
all_passed = False
else:
print("✅ Seed correct")
print(f"✅ Solana OK: {path} => {got_addr}")
print("✅ All tests passed")
fp = get_master_fingerprint(seed_bytes)
if fp != test["expected_fp"]:
print(f"❌ Fingerprint mismatch: got {fp}, expected {test['expected_fp']}")
all_passed = False
else:
print(f"✅ Fingerprint correct: {fp}")
if all_passed:
print("\n🎉 All tests passed!")
else:
print("\n❌ Some tests failed!")
sys.exit(1)
# -----------------------------------------------------------------------------

View File

@@ -491,21 +491,30 @@ def cmd_recover(args):
def cmd_test(args):
with NetworkGuard("test"):
require_for_offline(["ethereum"])
from bip_utils import Bip39SeedGenerator, Bip39MnemonicValidator
require_for_offline(["ethereum", "solana"])
from bip_utils import Bip39SeedGenerator
print("🧪 Running tests...")
# --- Existing vector (yours) ---
mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
passphrase = "crypto"
expected_seed_hex = "92c58d3f4fe52f0111d314f3fa8f10ba498751c37e7c36475c2a5b60145b29708576e11bf6c5c46efac1add0cc26e07c69eb65476742082f9c6460f132181cfe"
if not Bip39MnemonicValidator().IsValid(mnemonic):
raise RuntimeError("Test mnemonic failed validation")
passphrase = "" # empty
seed_bytes = Bip39SeedGenerator(mnemonic).Generate(passphrase)
if seed_bytes.hex() != expected_seed_hex:
raise RuntimeError("Seed mismatch")
print("✅ Test passed")
# --- NEW: Solana path->address test ---
expected_addr = "HAgk14JpMQLgt6rVgv7cBQFJWFto5Dqxi472uT3DKpqk"
path = "m/44'/501'/0'/0'"
seed32 = slip10_ed25519_seed32_from_path(seed_bytes, path) # or slip10_ed25519_seed32_by_path(...)
got_addr = sol_pubkey_b58_from_seed32(seed32)
if got_addr != expected_addr:
raise RuntimeError(f"Solana address mismatch for {path}: got {got_addr}, expected {expected_addr}")
print(f"✅ Solana OK: {path} => {got_addr}")
print("✅ All tests passed")
# -----------------------------------------------------------------------------