Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/lean_spec/subspecs/networking/transport/quic/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)."""
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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


# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -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]
Expand Down
Loading