Update wallet scripts: rename hdwallet_t.py to pyhdwallet.py and modify recovery script
This commit is contained in:
@@ -537,53 +537,31 @@ def cmd_recover(args):
|
|||||||
|
|
||||||
|
|
||||||
def cmd_test(args):
|
def cmd_test(args):
|
||||||
require_for_derive(False, ["ethereum"]) # minimal
|
with NetworkGuard("test"):
|
||||||
from bip_utils import Bip39SeedGenerator, Bip39MnemonicValidator
|
require_for_offline(["ethereum", "solana"])
|
||||||
|
|
||||||
print("🧪 Running Trezor BIP39/BIP32 test vectors...")
|
from bip_utils import Bip39SeedGenerator
|
||||||
|
|
||||||
|
print("🧪 Running tests...")
|
||||||
|
|
||||||
|
# --- Existing vector (yours) ---
|
||||||
mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
|
mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
|
||||||
passphrase = "crypto"
|
passphrase = "" # empty
|
||||||
expected_seed_hex = "92c58d3f4fe52f0111d314f3fa8f10ba498751c37e7c36475c2a5b60145b29708576e11bf6c5c46efac1add0cc26e07c69eb65476742082f9c6460f132181cfe"
|
seed_bytes = Bip39SeedGenerator(mnemonic).Generate(passphrase)
|
||||||
expected_fp = "AECCC350"
|
|
||||||
|
|
||||||
tests = [{
|
# --- NEW: Solana path->address test ---
|
||||||
"mnemonic": mnemonic,
|
expected_addr = "HAgk14JpMQLgt6rVgv7cBQFJWFto5Dqxi472uT3DKpqk"
|
||||||
"passphrase": passphrase,
|
path = "m/44'/501'/0'/0'"
|
||||||
"expected_seed_hex": expected_seed_hex,
|
|
||||||
"expected_fp": expected_fp,
|
|
||||||
}]
|
|
||||||
|
|
||||||
all_passed = True
|
seed32 = slip10_ed25519_seed32_from_path(seed_bytes, path) # or slip10_ed25519_seed32_by_path(...)
|
||||||
for i, test in enumerate(tests, 1):
|
got_addr = sol_pubkey_b58_from_seed32(seed32)
|
||||||
print(f"\nTest {i}: With passphrase '{test['passphrase']}'")
|
|
||||||
|
|
||||||
if not Bip39MnemonicValidator().IsValid(test["mnemonic"]):
|
if got_addr != expected_addr:
|
||||||
print("❌ Invalid mnemonic")
|
raise RuntimeError(f"Solana address mismatch for {path}: got {got_addr}, expected {expected_addr}")
|
||||||
all_passed = False
|
|
||||||
continue
|
|
||||||
|
|
||||||
seed_bytes = Bip39SeedGenerator(test["mnemonic"]).Generate(test["passphrase"])
|
print(f"✅ Solana OK: {path} => {got_addr}")
|
||||||
seed_hex = seed_bytes.hex()
|
print("✅ All tests passed")
|
||||||
|
|
||||||
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")
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -491,21 +491,30 @@ def cmd_recover(args):
|
|||||||
|
|
||||||
def cmd_test(args):
|
def cmd_test(args):
|
||||||
with NetworkGuard("test"):
|
with NetworkGuard("test"):
|
||||||
require_for_offline(["ethereum"])
|
require_for_offline(["ethereum", "solana"])
|
||||||
from bip_utils import Bip39SeedGenerator, Bip39MnemonicValidator
|
|
||||||
|
|
||||||
|
from bip_utils import Bip39SeedGenerator
|
||||||
|
|
||||||
|
print("🧪 Running tests...")
|
||||||
|
|
||||||
|
# --- Existing vector (yours) ---
|
||||||
mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
|
mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
|
||||||
passphrase = "crypto"
|
passphrase = "" # empty
|
||||||
expected_seed_hex = "92c58d3f4fe52f0111d314f3fa8f10ba498751c37e7c36475c2a5b60145b29708576e11bf6c5c46efac1add0cc26e07c69eb65476742082f9c6460f132181cfe"
|
|
||||||
|
|
||||||
if not Bip39MnemonicValidator().IsValid(mnemonic):
|
|
||||||
raise RuntimeError("Test mnemonic failed validation")
|
|
||||||
|
|
||||||
seed_bytes = Bip39SeedGenerator(mnemonic).Generate(passphrase)
|
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")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
Reference in New Issue
Block a user