feat: add webtransport certhashes field to NoiseExtensions and implement serialization test

Signed-off-by: varun-r-mallya <varunrmallya@gmail.com>
This commit is contained in:
2025-08-26 12:48:57 +05:30
parent 05fde3ad40
commit cacb3c8aca
5 changed files with 23 additions and 8 deletions

View File

@ -24,10 +24,7 @@ async def main():
noise_transport = NoiseTransport(
# local_key_pair: The key pair used for libp2p identity and authentication
libp2p_keypair=key_pair,
# noise_privkey: The private key used for Noise protocol encryption
noise_privkey=key_pair.private_key,
# early_data: Optional data to send during the handshake
# (None means no early data)
# TODO: add early data
)

View File

@ -2,6 +2,7 @@ syntax = "proto2";
package pb;
message NoiseExtensions {
repeated bytes webtransport_certhashes = 1;
repeated string stream_muxers = 2;
}

View File

@ -13,7 +13,7 @@ _sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n$libp2p/security/noise/pb/noise.proto\x12\x02pb\"(\n\x0fNoiseExtensions\x12\x15\n\rstream_muxers\x18\x02 \x03(\t\"Q\n\x15NoiseHandshakePayload\x12\x14\n\x0cidentity_key\x18\x01 \x01(\x0c\x12\x14\n\x0cidentity_sig\x18\x02 \x01(\x0c\x12\x0c\n\x04\x64\x61ta\x18\x03 \x01(\x0c')
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n$libp2p/security/noise/pb/noise.proto\x12\x02pb\"I\n\x0fNoiseExtensions\x12\x1f\n\x17webtransport_certhashes\x18\x01 \x03(\x0c\x12\x15\n\rstream_muxers\x18\x02 \x03(\t\"Q\n\x15NoiseHandshakePayload\x12\x14\n\x0cidentity_key\x18\x01 \x01(\x0c\x12\x14\n\x0cidentity_sig\x18\x02 \x01(\x0c\x12\x0c\n\x04\x64\x61ta\x18\x03 \x01(\x0c')
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'libp2p.security.noise.pb.noise_pb2', globals())
@ -21,7 +21,7 @@ if _descriptor._USE_C_DESCRIPTORS == False:
DESCRIPTOR._options = None
_NOISEEXTENSIONS._serialized_start=44
_NOISEEXTENSIONS._serialized_end=84
_NOISEHANDSHAKEPAYLOAD._serialized_start=86
_NOISEHANDSHAKEPAYLOAD._serialized_end=167
_NOISEEXTENSIONS._serialized_end=117
_NOISEHANDSHAKEPAYLOAD._serialized_start=119
_NOISEHANDSHAKEPAYLOAD._serialized_end=200
# @@protoc_insertion_point(module_scope)

View File

@ -16,15 +16,19 @@ DESCRIPTOR: google.protobuf.descriptor.FileDescriptor
class NoiseExtensions(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor
WEBTRANSPORT_CERTHASHES_FIELD_NUMBER: builtins.int
STREAM_MUXERS_FIELD_NUMBER: builtins.int
@property
def webtransport_certhashes(self) -> google.protobuf.internal.containers.RepeatedScalarFieldContainer[builtins.bytes]: ...
@property
def stream_muxers(self) -> google.protobuf.internal.containers.RepeatedScalarFieldContainer[builtins.str]: ...
def __init__(
self,
*,
webtransport_certhashes: collections.abc.Iterable[builtins.bytes] | None = ...,
stream_muxers: collections.abc.Iterable[builtins.str] | None = ...,
) -> None: ...
def ClearField(self, field_name: typing.Literal["stream_muxers", b"stream_muxers"]) -> None: ...
def ClearField(self, field_name: typing.Literal["stream_muxers", b"stream_muxers", "webtransport_certhashes", b"webtransport_certhashes"]) -> None: ...
global___NoiseExtensions = NoiseExtensions

View File

@ -0,0 +1,13 @@
from libp2p.security.noise.pb import noise_pb2 as noise_pb
def test_noise_extensions_serialization():
# Test NoiseExtensions
ext = noise_pb.NoiseExtensions()
ext.stream_muxers.append("/mplex/6.7.0")
ext.stream_muxers.append("/yamux/1.0.0")
# Serialize and deserialize
data = ext.SerializeToString()
ext2 = noise_pb.NoiseExtensions.FromString(data)
assert list(ext2.stream_muxers) == ["/mplex/6.7.0", "/yamux/1.0.0"]