discv5::EnrParser¶
Parses and validates Ethereum Node Records (EIP-778). More...
#include <discv5_enr.hpp>
Public Functions¶
| Name | |
|---|---|
| Result< EnrRecord > | parse(const std::string & enr_uri) Parse and validate an ENR URI of the form "enr: |
| Result< std::vector< uint8_t > > | decode_uri(const std::string & enr_uri) Decode the base64url body of an ENR URI into raw bytes. |
| Result< std::vector< uint8_t > > | base64url_decode(const std::string & body) Base64url-decode a raw body string (without the "enr:" prefix). |
| Result< EnrRecord > | decode_rlp(const std::vector< uint8_t > & raw) RLP-decode raw bytes into an EnrRecord (no signature verification). |
| VoidResult | verify_signature(EnrRecord & record) Verify the secp256k1-v4 signature embedded in record. |
| Result< ValidatedPeer > | to_validated_peer(const EnrRecord & record) Convert a fully-parsed EnrRecord into a ValidatedPeer. |
Detailed Description¶
Parses and validates Ethereum Node Records (EIP-778).
Responsibilities:
- Decode the base64url body of an "enr:…" URI.
- RLP-decode the record into signature + key–value content.
- Verify the secp256k1-v4 ECDSA signature.
- Extract all standard fields into an
EnrRecord. - Reject incomplete records that cannot yield a dialable
ValidatedPeer.
The class is stateless and all public methods are const/noexcept-safe.
Public Functions Documentation¶
function parse¶
Parse and validate an ENR URI of the form "enr:
Parameters:
- enr_uri Null-terminated ENR URI string.
Return: Populated EnrRecord on success, discv5Error on failure.
On success returns a fully populated EnrRecord whose node_id and at least one dialable endpoint (ip/udp_port or ip6/udp6_port) are set.
function decode_uri¶
Decode the base64url body of an ENR URI into raw bytes.
Parameters:
- enr_uri Full URI string including the "enr:" prefix.
Return: Raw RLP bytes on success, error on failure.
Strips the leading "enr:" prefix (case-sensitive) and decodes the remainder as unpadded RFC-4648 §5 base64url.
function base64url_decode¶
Base64url-decode a raw body string (without the "enr:" prefix).
Parameters:
- body Base64url-encoded string.
Return: Decoded bytes on success, error on failure.
Accepts both padded and unpadded base64url input.
function decode_rlp¶
RLP-decode raw bytes into an EnrRecord (no signature verification).
Parameters:
- raw Raw RLP bytes of the full ENR record.
Return: Partially-populated EnrRecord, or error on decode failure.
Populates all key–value fields but leaves node_id and the signature validity flag untouched — the caller should call verify_signature separately.
function verify_signature¶
Verify the secp256k1-v4 signature embedded in record.
Parameters:
- record EnrRecord whose
raw_rlpandcompressed_pubkeyare already populated (as returned by decode_rlp).
Return: outcome::success() on valid signature, error otherwise.
Uses the compressed public key from the "secp256k1" field to verify the signature over keccak256(RLP([seq, k1, v1, …])). On success sets record.node_id to the recovered 64-byte uncompressed key.
function to_validated_peer¶
Convert a fully-parsed EnrRecord into a ValidatedPeer.
Parameters:
- record Populated EnrRecord (signature already verified).
Return: ValidatedPeer on success, kEnrMissingAddress on failure.
Fails if neither an IPv4 nor an IPv6 dialable endpoint is present.
Updated on 2026-04-13 at 23:22:46 -0700