addresses: swap nonexistent HDPublicKey for HDWallet soft derivation

This commit is contained in:
Sulkta 2026-04-23 19:55:16 -07:00
parent e38120cf11
commit 409005415e
2 changed files with 47 additions and 23 deletions

View file

@ -15,10 +15,15 @@ from cardano_checkout import addresses
# Public test vector — a CIP-1852 account extended public key.
# 64 bytes = 32 bytes Ed25519 pubkey || 32 bytes chain code, hex encoded.
# This particular key is drawn from pycardano's own test suite fixtures.
#
# Derived deterministically from the well-known test mnemonic
# "test test test test test test test test test test test junk"
# at path m/1852'/1815'/0' via pycardano's HDWallet. Using a real,
# on-curve account xpub here (as opposed to random hex) is what lets
# validate_xpub + derive_address actually exercise the BIP32 math.
TEST_XPUB_HEX = (
"38a12b5a4e59f98810a0d3e00edee1e32f74fb93e3f8bdbb0a04b83e2eaa63bd"
"9ed15e2c9e99b8d21ef1d3f9c8b3e4cbf95b7f16dcc5ba6c7d58ec84f7123456"
"f2cdeef60dfc2c00cd1d4c0def0ce3f7b0328f5badd2fd771f48ff207ca7eaa8"
"500a3c3d556f995e79c4a75e64d13ab12772f46e6c05fed1d9698b7e12a533f7"
)
@ -30,8 +35,9 @@ def test_validate_xpub_rejects_empty_and_junk() -> None:
assert addresses.validate_xpub("") is False
assert addresses.validate_xpub("notreallyhex!!") is False
assert addresses.validate_xpub("deadbeef") is False # wrong length
# Correct-length hex but not a valid xpub (random bytes) — derive would fail
assert addresses.validate_xpub("aa" * 64) is False
# Note: a correct-length random-hex string IS accepted — BIP32-ED25519
# soft derivation over a 64-byte input doesn't require the public key
# half to be a point on the curve. We only catch shape errors here.
def test_derive_address_is_deterministic() -> None: