diff --git a/src/lean_spec/subspecs/networking/transport/quic/tls.py b/src/lean_spec/subspecs/networking/transport/quic/tls.py index b571d563..76783406 100644 --- a/src/lean_spec/subspecs/networking/transport/quic/tls.py +++ b/src/lean_spec/subspecs/networking/transport/quic/tls.py @@ -31,6 +31,7 @@ from cryptography.hazmat.primitives.asymmetric import ec from ..identity import IdentityKeypair +from ..peer_id import KeyType LIBP2P_EXTENSION_OID: Final = x509.ObjectIdentifier("1.3.6.1.4.1.53594.1.1") """libp2p TLS extension OID (Protocol Labs assigned).""" @@ -43,10 +44,6 @@ Without a prefix, the signature could potentially be replayed in other contexts. """ -# Key type identifiers matching libp2p protobuf definitions -KEY_TYPE_SECP256K1: Final = 2 -"""secp256k1 key type in libp2p protobuf.""" - def generate_libp2p_certificate( identity_key: IdentityKeypair, @@ -174,7 +171,7 @@ def _create_extension_payload( # Field 1 (Type): tag=0x08, value=2 (secp256k1) # Field 2 (Data): tag=0x12, length, bytes public_key_proto = ( - bytes([0x08, KEY_TYPE_SECP256K1, 0x12, len(public_key_compressed)]) + public_key_compressed + bytes([0x08, KeyType.SECP256K1, 0x12, len(public_key_compressed)]) + public_key_compressed ) # Encode as ASN.1 DER SEQUENCE. diff --git a/tests/lean_spec/subspecs/networking/transport/quic/test_tls.py b/tests/lean_spec/subspecs/networking/transport/quic/test_tls.py index 7223d7e5..15c6ad03 100644 --- a/tests/lean_spec/subspecs/networking/transport/quic/test_tls.py +++ b/tests/lean_spec/subspecs/networking/transport/quic/test_tls.py @@ -18,8 +18,8 @@ from cryptography.hazmat.primitives.asymmetric import ec from lean_spec.subspecs.networking.transport.identity.keypair import IdentityKeypair +from lean_spec.subspecs.networking.transport.peer_id import KeyType from lean_spec.subspecs.networking.transport.quic.tls import ( - KEY_TYPE_SECP256K1, LIBP2P_EXTENSION_OID, SIGNATURE_PREFIX, _create_extension_payload, @@ -59,7 +59,7 @@ def test_signature_prefix(self) -> None: def test_key_type_secp256k1(self) -> None: """Key type 2 matches the libp2p protobuf KeyType enum for secp256k1.""" - assert KEY_TYPE_SECP256K1 == 2 + assert KeyType.SECP256K1 == 2 # --------------------------------------------------------------------------- @@ -229,7 +229,7 @@ def test_protobuf_encoding(self, identity_key: IdentityKeypair) -> None: # Protobuf field 1 (Type): varint tag=0x08, value=2 (secp256k1) assert public_key_proto[0] == 0x08 - assert public_key_proto[1] == KEY_TYPE_SECP256K1 + assert public_key_proto[1] == KeyType.SECP256K1 # Protobuf field 2 (Data): length-delimited tag=0x12 assert public_key_proto[2] == 0x12 key_len = public_key_proto[3]