PeerId class

A libp2p PeerId represented as the raw multihash bytes of a public key.

In the libp2p network stack, a PeerId uniquely identifies a peer. It is conceptually the multihash of the peer's public key. This class stores the raw byte representation and provides encoding/decoding to common string formats used in libp2p: Base58 (default) and Base36.

PeerId values are immutable and can be compared for equality. The hashCode implementation uses an FNV-1a 32-bit hash suitable for collections such as Map and Set.

Example

final peerId = PeerId.fromBytes([0x12, 0x20, 0xab, 0xcd]);
final b58 = peerId.toBase58();
final recovered = PeerId.fromBase58(b58);
assert(peerId == recovered);

See also:

Constructors

PeerId.fromBase58(String base58)
Creates a PeerId from a Base58-encoded string.
factory
PeerId.fromBytes(List<int> bytes)
Creates a PeerId from a raw byte list.
factory

Properties

bytes List<int>
The raw multihash bytes (identity hash of the public key).
final
hashCode int
A 32-bit hash code derived from the raw bytes using an FNV-1a algorithm.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

encodeBase36({bool multibase = false}) String
Encodes this PeerId's raw bytes using standard Base36 (lowercase).
encodeBase58({bool multibase = false}) String
Encodes this PeerId's raw bytes using standard Base58 (Bitcoin alphabet).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toBase36() String
Returns the Base36 encoding of this peer ID.
toBase58() String
Returns the Base58 encoding of this peer ID.
toString() String
Returns a lowercase hex string representation of the raw bytes.
override

Operators

operator ==(Object other) bool
Whether two PeerIds represent the same raw byte sequence.
override

Static Methods

decodeBase36(String input) PeerId
Decodes a Base36-encoded string into a PeerId.
decodeBase58(String input) PeerId
Decodes a Base58-encoded string into a PeerId.
fromPublicKey(List<int> publicKeyBytes) Future<PeerId>
Derives a PeerId from raw public key bytes using SHA-256 multihash.