Skip to content

fix: share the key encoding across encrypters and keep RSA peer keys - #3669

Merged
tabcat merged 6 commits into
libp2p:mainfrom
tabcat:refactor/key-encoding-cleanups
Oct 17, 2026
Merged

tabcat merged 6 commits into
libp2p:mainfrom
tabcat:refactor/key-encoding-cleanups

Conversation

@tabcat

@tabcat tabcat commented Oct 17, 2026

Copy link
Copy Markdown
Member

Description

Small cleanups to how connection encrypters encode public keys and derive peer ids, ahead of the crypto API changes.

  • plaintext: the Exchange.pubkey field is now declared as bytes holding a protobuf-encoded PublicKey, instead of an embedded PublicKey message. Both encode to the same bytes, so the wire format is unchanged. New tests pin this for Ed25519 and RSA against a hand-built exchange. The key type is now read from the key instead of being guessed from its length, so a key whose type does not match its data is rejected.
  • tls: the certificate's public key is encoded with publicKeyToProtobuf, which replaces a duplicate copy of the key schema. The remote peer id is derived from the key directly. RSA remote peers previously came back without their public key; they now keep it.
  • peer-store, identify: derive peer ids with peerIdFromPublicKey instead of round-tripping through a CID.
  • noise: the handshake returns the remote peer, so the identity key is parsed once instead of twice.
  • interface-compliance-tests: connection encrypters must return RSA remote peers with their public key, with and without an expected peer.

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

The key type is now read from the key instead of guessed from its length. The wire format is unchanged, pinned by new tests for Ed25519 and RSA.
Encode the certificate key with publicKeyToProtobuf, dropping the duplicated key schema, and derive the remote peer id from the key directly.
…-cleanups

# Conflicts:
#	packages/connection-encrypter-tls/package.json
@tabcat
tabcat marked this pull request as ready for review October 17, 2026 01:15
@tabcat
tabcat requested a review from a team as a code owner October 17, 2026 01:15
@tabcat
tabcat merged commit 95392ef into libp2p:main Oct 17, 2026
34 checks passed
@tabcat tabcat mentioned this pull request Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant