Skip to content

peer-id: support CIDv1 peer IDs in all recognized multibase encodings #250

Description

@adust09

Spec

specs/peer-ids/peer-ids.md, String Representation / Decoding.

Implementations MUST parse both legacy raw base58btc multihashes and multibase-encoded CIDv1 peer IDs. CID peer IDs must use the libp2p-key codec (0x72).

Current state

parsePeerId recognizes only the lowercase base32 multibase prefix b as a CID. Every other input is passed to the legacy raw-base58 decoder. Valid CIDv1 representations using another multibase encoding, such as base58btc (z) or base32upper (B), are therefore rejected.

Issue #117 added base32lower CID support but did not implement the spec's general multibase decoding requirement.

Scope

  • Dispatch legacy raw peer IDs only for their defined 1... and Qm... forms.
  • Decode CIDv1 using its multibase prefix rather than assuming base32lower.
  • Require CID version 1 and multicodec libp2p-key (0x72).
  • Validate the extracted multihash with the existing peer-ID constraints.
  • Keep toCIDv1 base32lower as the default output format.
  • Reject unknown prefixes, CIDv0-as-CID, wrong codecs, trailing bytes, and non-canonical varints.

Acceptance tests

  • The same PeerId parses from base32lower (b), base32upper (B), and base58btc CIDv1 (z).
  • Legacy 1... and Qm... forms still parse.
  • An arbitrary base58 string is not silently treated as a legacy peer ID unless it has a valid legacy form.
  • Wrong CID version/codec and malformed multibase inputs fail cleanly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions