> loading_
# -----------------------------------------------------------
# Walkthrough: Verify an ML-DSA-44 signature (Python / pqcrypto)
# -----------------------------------------------------------
# ML-DSA-44 (FIPS 204) replaces Ed25519 in EIP-8164.
# Below is a minimal key-gen → sign → verify flow so you can
# start experimenting locally.
#
# Prerequisites:
# pip install pqcrypto # or use the oqs-python wrapper
# Python 3.10+
# -----------------------------------------------------------
# Step 1 – Import the ML-DSA-44 module
# The 'dilithium' family was renamed ML-DSA in the FIPS 204 standard.
from pqcrypto.sign.dilithium2 import generate_keypair, sign, verify
# Step 2 – Generate a keypair
# ML-DSA-44 public keys are 1,312 bytes; secret keys are 2,560 bytes.
public_key, secret_key = generate_keypair()
print(f"Public key length : {len(public_key)} bytes") # 1312
print(f"Secret key length : {len(secret_key)} bytes") # 2560
# Step 3 – Sign an arbitrary message (e.g. an EIP-8164 transaction hash)
message = b"EIP-8164 post-quantum transaction payload"
signature = sign(message, secret_key)
print(f"Signature length : {len(signature)} bytes") # ~2420
# Step 4 – Verify the signature
# This is the on-chain-equivalent path: only public_key + signature + message.
try:
verify(message, signature, public_key)
print("✅ Signature valid under ML-DSA-44 (FIPS 204)")
except Exception as e:
print(f"❌ Verification failed: {e}")
# -----------------------------------------------------------
# EIP-7932 note: public key / signature separation
# -----------------------------------------------------------
# Under the updated EIP-7932 spec, you should treat `public_key`
# and `signature` as independent fields during serialization:
#
# tx_envelope = {
# "payload": message,
# "pub_key": public_key, # separated field (1,312 bytes)
# "signature": signature, # separated field (~2,420 bytes)
# }
#
# Do NOT concatenate them into a single blob as older Ed25519
# implementations sometimes did. Deserialization logic must
# parse each field by its known, fixed length.
# -----------------------------------------------------------