liveBook · Manning

PeerId

As explained in Rust Servers, Services, and Apps

A peer ID is a unique cryptographic identifier assigned to a node in a peer-to-peer network.

A PeerId uniquely identifies a node on a peer-to-peer network. In libp2p, it is derived from the node’s public key; the associated private key must remain secret. section 11.2.1

use libp2p::{identity, PeerId};                             #1
 
#[tokio::main]                                              #2
async fn main() {                                           #3
    let new_key = identity::Keypair::generate_ed25519();    #4
    let new_peer_id = PeerId::from(new_key.public());       #5
    println!("New peer id: {:?}", new_peer_id);
}

Generate an ED25519 key pair, then create a PeerId from its public key. section 11.2.1

PeerId in a multiaddress

A multiaddress combines a transport address with a peer’s ID, for example `/ip4/192.158.1.23/tcp/1234/p2p/12D3KooWBu3fmjZgSMLkQ2p1DG35UmEayYBrhsk6WEe1xco1JFbV`. section 11.2.2

How Rust Servers, Services, and Apps covers it

How deep it goes
Defines PeerId generation from a public key and demonstrates it in Rust, while deferring other cryptographic uses.
Examples
Shows ED25519-based PeerId generation in Rust and a complete multiaddress containing a PeerId.
What it assumes
Builds from basic public- and private-key roles, explaining their use in peer identity.
What you can do after
Apply libp2p to generate a PeerId from a key pair’s public key and recognize it in a multiaddress.
How it connects
Connects peer identity to public-key cryptography, key pairs, libp2p, and multiaddresses.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust Servers, Services, and Apps. The section links point to the parts of the book it draws on.