Is PeerID always Multihash of type SHA2_256?

Is PeerID always Multihash of type SHA2_256 (SHA256)?

In general, you shouldn’t assume that PeerId will always be SHA2-256, but it will always be a valid multihash.

There’s some complicated history around this, but generally in practice PeerIds will be SHA2_256 multihashes.

There are some cases where people using compact Ed25519 keys are using the “identity” multihash function to embed the key into the PeerId itself, so that you don’t need to do a separate lookup to get the public key. This behavior might evolve in the future, depending on how the discussion at the link above shakes out.

3 Likes