Skip to content

discv5/discv5_enr.hpp

Namespaces

Name
discv5

Classes

Name
class discv5::EnrParser
Parses and validates Ethereum Node Records (EIP-778).

Source code

// Copyright 2025 GeniusVentures
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <cstdint>
#include <string>
#include <vector>

#include <discv5/discv5_error.hpp>
#include <discv5/discv5_types.hpp>

namespace discv5
{

// ---------------------------------------------------------------------------
// EnrParser
// ---------------------------------------------------------------------------

class EnrParser
{
public:
    // -----------------------------------------------------------------------
    // Primary entry point
    // -----------------------------------------------------------------------

    static Result<EnrRecord> parse(const std::string& enr_uri) noexcept;

    // -----------------------------------------------------------------------
    // Step-level helpers (also used by tests)
    // -----------------------------------------------------------------------

    static Result<std::vector<uint8_t>> decode_uri(const std::string& enr_uri) noexcept;

    static Result<std::vector<uint8_t>> base64url_decode(const std::string& body) noexcept;

    static Result<EnrRecord> decode_rlp(const std::vector<uint8_t>& raw) noexcept;

    static VoidResult verify_signature(EnrRecord& record) noexcept;

    static Result<ValidatedPeer> to_validated_peer(const EnrRecord& record) noexcept;

private:
    // -----------------------------------------------------------------------
    // Internal helpers
    // -----------------------------------------------------------------------

    static Result<std::string> decode_ipv4(const std::vector<uint8_t>& bytes) noexcept;

    static Result<std::string> decode_ipv6(const std::vector<uint8_t>& bytes) noexcept;

    static Result<uint16_t> decode_port(const std::vector<uint8_t>& bytes) noexcept;

    static Result<ForkId> decode_eth_entry(const std::vector<uint8_t>& bytes) noexcept;

    static Result<NodeId> decompress_pubkey(
        const std::array<uint8_t, kCompressedKeyBytes>& compressed) noexcept;
};

} // namespace discv5

Updated on 2026-04-13 at 23:22:46 -0700