Skip to content
This repository was archived by the owner on Nov 20, 2023. It is now read-only.

Commit ac1980d

Browse files
authored
Remove libp2p feature (#11)
* Remove libp2p feature * Version bump & workflow correction * Remove libp2p from readme
1 parent eb10eac commit ac1980d

File tree

9 files changed

+14
-302
lines changed

9 files changed

+14
-302
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,3 @@ jobs:
4747
run: rustup update stable
4848
- name: Run tests in release
4949
run: cargo test --all --release --no-default-features --features "libsecp256k1","ed25519" --tests
50-
release-tests-ubuntu-libsecp256k1-ed25519-libp2p:
51-
runs-on: ubuntu-latest
52-
needs: cargo-fmt
53-
steps:
54-
- uses: actions/checkout@v2
55-
- name: Get latest version of stable rust
56-
run: rustup update stable
57-
- name: Run tests in release
58-
run: cargo test --all --release --no-default-features --features "libsecp256k1","ed25519","libp2p" --tests

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
2+
name = "enr"
23
authors = ["Age Manning <[email protected]>"]
34
edition = "2018"
4-
name = "enr"
5-
version = "0.1.0-alpha.5"
5+
version = "0.1.0-alpha.6"
66
description = "Rust implementation of Ethereum Node Record (ENR) EIP778"
77
readme = "./README.md"
88
keywords = ["ethereum", "enr", "record", "EIP778", "node"]
@@ -34,7 +34,6 @@ c-secp256k1 = { package = "secp256k1", features = ["rand-std"], version = "0.17"
3434

3535
[features]
3636
default = ["serde", "libsecp256k1" ]
37-
libp2p = ["libp2p-core"]
3837
ed25519 = ["ed25519-dalek"]
3938
rust-secp256k1 = ["c-secp256k1"]
4039

README.md

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,18 @@ Furthermore, a `CombinedKey` is provided if the `ed25519` feature flag is set, w
3939
ENR type that can support both `secp256k1` and `ed25519` signed ENR records. Examples of the
4040
use of each of these key types is given below.
4141

42-
Additionally there is support for conversion of `rust-libp2p` `Keypair` to the `CombinedKey` type
43-
via the `libp2p` feature flag.
44-
4542
## Features
4643

4744
This crate supports a number of features.
4845

4946
- `serde`: Allows for serde serialization and deserialization for ENRs.
50-
- `libp2p`: Provides libp2p integration. Libp2p `Keypair`'s can be converted to `CombinedKey`
51-
types which can be used to sign and modify ENRs. This feature also adds the `peer_id()`
52-
and `multiaddr()` functions to an ENR which provides an ENR's associated `PeerId` and list of
53-
`MultiAddr`'s respectively.
5447
- `ed25519`: Provides support for `ed25519_dalek` keypair types.
48+
- `rust-secp256k1`: Uses `c-secp256k1` for secp256k1 keys.
5549

5650
These can be enabled via adding the feature flag in your `Cargo.toml`
5751

5852
```toml
59-
enr = { version = "*", features = ["serde", "libp2p", "ed25519"] }
53+
enr = { version = "*", features = ["serde", "ed25519", "rust-secp256k1"] }
6054
```
6155

6256
## Examples
@@ -136,24 +130,6 @@ assert_eq!(decoded_enr.tcp(), Some(8001));
136130
assert_eq!(decoded_enr.get("custom_key"), Some(&vec![0,0,1]));
137131
```
138132

139-
#### Libp2p key conversion, with the `libp2p` feature flag
140-
141-
```rust
142-
use enr::{EnrBuilder, CombinedKey};
143-
use std::net::Ipv4Addr;
144-
use std::convert::TryInto;
145-
146-
// with the `libp2p` feature flag, one can also use a libp2p key
147-
let libp2p_key = libp2p_core::identity::Keypair::generate_secp256k1();
148-
let key: CombinedKey = libp2p_key.try_into().expect("supports secp256k1");
149-
150-
let ip = Ipv4Addr::new(192,168,0,1);
151-
let enr = EnrBuilder::new("v4").ip(ip.into()).tcp(8000).build(&key).unwrap();
152-
153-
assert_eq!(enr.ip(), Some("192.168.0.1".parse().unwrap()));
154-
assert_eq!(enr.id(), Some("v4".into()));
155-
```
156-
157133
#### Encoding/Decoding ENR's of various key types
158134

159135
```rust

src/keys/combined.rs

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ pub use secp256k1;
1010
use std::collections::BTreeMap;
1111
use zeroize::Zeroize;
1212

13-
#[cfg(feature = "libp2p")]
14-
use libp2p_core::{identity::Keypair as Libp2pKeypair, PeerId};
15-
#[cfg(feature = "libp2p")]
16-
use std::convert::TryFrom;
17-
1813
/// A standard implementation of the `EnrKey` trait used to sign and modify ENR records. The variants here represent the currently
1914
/// supported in-built signing schemes.
2015
pub enum CombinedKey {
@@ -44,27 +39,6 @@ impl From<ed25519::SecretKey> for CombinedKey {
4439
}
4540
}
4641

47-
#[cfg(any(feature = "libp2p", doc))]
48-
impl TryFrom<Libp2pKeypair> for CombinedKey {
49-
type Error = &'static str;
50-
51-
fn try_from(keypair: Libp2pKeypair) -> Result<Self, Self::Error> {
52-
match keypair {
53-
Libp2pKeypair::Secp256k1(key) => {
54-
let secret = secp256k1::SecretKey::parse(&key.secret().to_bytes())
55-
.expect("libp2p key must be valid");
56-
Ok(CombinedKey::Secp256k1(secret))
57-
}
58-
Libp2pKeypair::Ed25519(key) => {
59-
let ed_keypair = ed25519::SecretKey::from_bytes(&key.encode()[..32])
60-
.expect("libp2p key must be valid");
61-
Ok(CombinedKey::from(ed_keypair))
62-
}
63-
_ => Err("Unsupported key type"),
64-
}
65-
}
66-
}
67-
6842
impl EnrKey for CombinedKey {
6943
type PublicKey = CombinedPublicKey;
7044

@@ -178,44 +152,33 @@ impl EnrPublicKey for CombinedPublicKey {
178152
/// Verify a raw message, given a public key for the v4 identity scheme.
179153
fn verify_v4(&self, msg: &[u8], sig: &[u8]) -> bool {
180154
match self {
181-
CombinedPublicKey::Secp256k1(pk) => pk.verify_v4(msg, sig),
182-
CombinedPublicKey::Ed25519(pk) => pk.verify_v4(msg, sig),
155+
Self::Secp256k1(pk) => pk.verify_v4(msg, sig),
156+
Self::Ed25519(pk) => pk.verify_v4(msg, sig),
183157
}
184158
}
185159

186160
/// Encodes the public key into compressed form, if possible.
187161
fn encode(&self) -> Vec<u8> {
188162
match self {
189163
// serialize in compressed form: 33 bytes
190-
CombinedPublicKey::Secp256k1(pk) => pk.encode(),
191-
CombinedPublicKey::Ed25519(pk) => pk.encode(),
164+
Self::Secp256k1(pk) => pk.encode(),
165+
Self::Ed25519(pk) => pk.encode(),
192166
}
193167
}
194168

195169
/// Encodes the public key in uncompressed form.
196170
fn encode_uncompressed(&self) -> Vec<u8> {
197171
match self {
198-
CombinedPublicKey::Secp256k1(pk) => pk.encode_uncompressed(),
199-
CombinedPublicKey::Ed25519(pk) => pk.encode_uncompressed(),
172+
Self::Secp256k1(pk) => pk.encode_uncompressed(),
173+
Self::Ed25519(pk) => pk.encode_uncompressed(),
200174
}
201175
}
202176

203177
/// Generates the ENR public key string associated with the key type.
204178
fn enr_key(&self) -> String {
205179
match self {
206-
CombinedPublicKey::Secp256k1(key) => key.enr_key(),
207-
CombinedPublicKey::Ed25519(key) => key.enr_key(),
208-
}
209-
}
210-
211-
#[cfg(any(feature = "libp2p", doc))]
212-
/// Converts the publickey into a peer id, without consuming the key.
213-
///
214-
/// This is only available with the `libp2p` feature flag.
215-
fn into_peer_id(&self) -> PeerId {
216-
match self {
217-
CombinedPublicKey::Secp256k1(pk) => pk.into_peer_id(),
218-
CombinedPublicKey::Ed25519(pk) => pk.into_peer_id(),
180+
Self::Secp256k1(key) => key.enr_key(),
181+
Self::Ed25519(key) => key.enr_key(),
219182
}
220183
}
221184
}

src/keys/ed25519.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
use super::{ed25519_dalek as ed25519, EnrKey, EnrPublicKey, SigningError};
2-
#[cfg(feature = "libp2p")]
3-
use libp2p_core::{PeerId, PublicKey as Libp2pPublicKey};
42
use rlp::DecoderError;
53
use std::collections::BTreeMap;
64

@@ -57,16 +55,4 @@ impl EnrPublicKey for ed25519::PublicKey {
5755
fn enr_key(&self) -> String {
5856
ENR_KEY.into()
5957
}
60-
61-
#[cfg(any(feature = "libp2p", doc))]
62-
/// Converts the publickey into a peer id, without consuming the key.
63-
///
64-
/// This is only available with the `libp2p` feature flag.
65-
fn into_peer_id(&self) -> PeerId {
66-
let pk_bytes = self.to_bytes();
67-
let libp2p_pk = Libp2pPublicKey::Ed25519(
68-
libp2p_core::identity::ed25519::PublicKey::decode(&pk_bytes).expect("valid public key"),
69-
);
70-
PeerId::from_public_key(libp2p_pk)
71-
}
7258
}

src/keys/libsecp256k1.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
33
use super::{secp256k1, EnrKey, EnrPublicKey, SigningError};
44
use crate::digest;
5-
#[cfg(feature = "libp2p")]
6-
use libp2p_core::{PeerId, PublicKey as Libp2pPublicKey};
75
use rlp::DecoderError;
86
use std::collections::BTreeMap;
97

@@ -75,17 +73,4 @@ impl EnrPublicKey for secp256k1::PublicKey {
7573
fn enr_key(&self) -> String {
7674
ENR_KEY.into()
7775
}
78-
79-
#[cfg(any(feature = "libp2p", doc))]
80-
/// Converts the publickey into a peer id, without consuming the key.
81-
///
82-
/// This is only available with the `libp2p` feature flag.
83-
fn into_peer_id(&self) -> PeerId {
84-
let pk_bytes = self.serialize_compressed();
85-
let libp2p_pk = Libp2pPublicKey::Secp256k1(
86-
libp2p_core::identity::secp256k1::PublicKey::decode(&pk_bytes)
87-
.expect("valid public key"),
88-
);
89-
PeerId::from_public_key(libp2p_pk)
90-
}
9176
}

src/keys/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ pub use c_secp256k1;
2323
pub use combined::{CombinedKey, CombinedPublicKey};
2424
#[cfg(any(feature = "ed25519", doc))]
2525
pub use ed25519_dalek;
26-
#[cfg(feature = "libp2p")]
27-
use libp2p_core::PeerId;
2826
#[cfg(any(feature = "libsecp256k1", doc))]
2927
pub use secp256k1;
3028

@@ -69,12 +67,6 @@ pub trait EnrPublicKey {
6967
/// Returns the ENR key identifier for the public key type. For `secp256k1` keys this
7068
/// is `secp256k1`.
7169
fn enr_key(&self) -> String;
72-
73-
#[cfg(any(feature = "libp2p", doc))]
74-
/// Converts an `EnrPublicKey` into a libp2p `PeerId`
75-
///
76-
/// Only required with the `libp2p` feature flag.
77-
fn into_peer_id(&self) -> PeerId;
7870
}
7971

8072
/// An error during signing of a message.

src/keys/rust_secp256k1.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use super::{EnrKey, EnrPublicKey, SigningError};
22
use crate::digest;
3-
#[cfg(feature = "libp2p")]
4-
use libp2p_core::{PeerId, PublicKey as Libp2pPublicKey};
53
use rlp::DecoderError;
64
use std::collections::BTreeMap;
75

@@ -60,14 +58,4 @@ impl EnrPublicKey for c_secp256k1::PublicKey {
6058
fn enr_key(&self) -> String {
6159
ENR_KEY.into()
6260
}
63-
64-
#[cfg(any(feature = "libp2p", doc))]
65-
fn into_peer_id(&self) -> PeerId {
66-
let pk_bytes = self.serialize();
67-
let libp2p_pk = Libp2pPublicKey::Secp256k1(
68-
libp2p_core::identity::secp256k1::PublicKey::decode(&pk_bytes)
69-
.expect("valid public key"),
70-
);
71-
PeerId::from_public_key(libp2p_pk)
72-
}
7361
}

0 commit comments

Comments
 (0)