16#include "core/bytes.h"
28 static constexpr size_t kSize = 32;
40 static std::optional<PeerId>
from_hex(std::string_view hex);
45 const std::array<uint8_t, kSize>&
bytes() const noexcept {
return bytes_; }
48 bool operator==(const
PeerId& o) const noexcept {
return bytes_ == o.bytes_; }
58 std::array<uint8_t, kSize> bytes_{};
bool operator!=(const PeerId &o) const noexcept
const std::array< uint8_t, kSize > & bytes() const noexcept
static std::optional< PeerId > from_hex(std::string_view hex)
Parse a 64-char lowercase/uppercase hex string. nullopt if malformed.
std::string to_hex() const
static constexpr size_t kSize
SHA-256 digest length.
static std::optional< PeerId > from_bytes(ByteView raw)
Wrap raw 32 id-bytes verbatim (NOT hashed). nullopt unless exactly kSize.
static PeerId from_public_key(const uint8_t *key, size_t len)
Derive the PeerId from a raw static public key (SHA-256 of the key).
bool is_zero() const noexcept
static PeerId from_public_key(ByteView key)
std::string short_hex() const
first 8 hex chars, for logs
bool operator<(const PeerId &o) const noexcept
Hash functor for use as an unordered_map/set key.
size_t operator()(const PeerId &id) const noexcept