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
