enr
This crate contains an implementation of an Ethereum Node Record (ENR) as specified by EIP-778 extended to allow for the use of ed25519 keys.
An ENR is a signed, key-value record which has an associated NodeId
(a 32-byte identifier).
Updating/modifying an ENR requires an EnrKey
in order to re-sign the record with the
associated key-pair.
User's wishing to implement their own singing algorithms simply need to
implement the [EnrKey
] trait and apply it to an [EnrRaw
].
This implementation uses a DefaultKey
which implements signing for secp256k1
and
ed25519
keys. With the libp2p
feature enabled, this provides conversions from libp2p
Keypair
for libp2p integration.
ENR's are identified by their sequence number. When updating an ENR, the sequence number is increased.
Different identity schemes can be used to define the node id and signatures. Currently only the "v4" identity is supported and is set by default.
Features
This crate supports two features.
serde
: Allows for serde serialization and deserialization for ENRslibp2p
: Provides libp2p integration. Libp2p keypairs can be converted toDefaultKey
structs which can be used to sign and modify ENR's. This feature also adds apeer_id()
function to an ENR which provides an ENR's associated peer_id.
These can be enabled via adding the feature flag in your Cargo.toml
= { = "0.1.0-alpha", = ["serde", "libp2p"]
Usage
Add this to your Cargo.toml
:
[]
= "0.1.0-alpha"
To build an ENR, an EnrBuilder
is provided.
Example (Building an ENR):
use ;
use Ipv4Addr;
let key = generate_secp256k1;
let ip = new;
let enr = new.ip.tcp.build.unwrap;
assert_eq!;
assert_eq!;
Pre-existing keys can also be used to sign/modify an ENR.
use ;
use Ipv4Addr;
use SecretKey;
use thread_rng;
use TryInto;
let mut rng = thread_rng;
let key: DefaultKey = random.into;
// with the `libp2p` feature flag, can also use a libp2p key
// let libp2p_key = libp2p_core::identity::Keypair::generate_secp256k1();
// let key: DefaultKey = libp2p_key.try_into().expect("supports secp256k1");
let ip = new;
let enr = new.ip.tcp.build.unwrap;
// a multiaddr and peer_id exist with libp2p feature flag
// assert_eq!(enr.multiaddr()[0], "/ip4/192.168.0.1/tcp/8000".parse().unwrap());
assert_eq!;
assert_eq!;