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

Commit 93202d6

Browse files
authored
Shift ENR to 0.1.0 (#2)
* Version bump to 0.1.0 * Handle decoding panic (#12) * Remove libp2p dependency * Clean up tests * Update github workflow
1 parent fa181dd commit 93202d6

File tree

4 files changed

+37
-30
lines changed

4 files changed

+37
-30
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: build
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
48

59
jobs:
610
cargo-fmt:

Cargo.toml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "enr"
33
authors = ["Age Manning <[email protected]>"]
44
edition = "2018"
5-
version = "0.1.0-alpha.7"
5+
version = "0.1.0"
66
description = "Rust implementation of Ethereum Node Record (ENR) EIP778"
77
readme = "./README.md"
88
keywords = ["ethereum", "enr", "record", "EIP778", "node"]
@@ -15,22 +15,21 @@ exclude = [
1515
]
1616

1717
[dependencies]
18-
base64 = "0.12.0"
19-
bs58 = "0.3.0"
18+
base64 = "0.12.1"
19+
bs58 = "0.3.1"
2020
hex = "0.4.2"
2121
log = "0.4.8"
2222
rand = "0.7.3"
23-
rlp = "0.4.4"
24-
tiny-keccak = { version = "2", features = ["keccak"] }
23+
rlp = "0.4.5"
24+
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
2525
zeroize = "1.1.0"
26-
libsecp256k1 = { version = "^0", optional = true }
27-
serde = { version = "1.0.104", optional = true }
28-
libp2p-core = { version = "^0", optional = true }
26+
libsecp256k1 = { version = "0.3.5", optional = true }
27+
serde = { version = "1.0.110", optional = true }
2928
ed25519-dalek = { version = "1.0.0-pre.3", optional = true }
30-
c-secp256k1 = { package = "secp256k1", version = "0.17", optional = true }
29+
c-secp256k1 = { package = "secp256k1", version = "0.17.2", optional = true }
3130

3231
[dev-dependencies]
33-
c-secp256k1 = { package = "secp256k1", features = ["rand-std"], version = "0.17" }
32+
c-secp256k1 = { package = "secp256k1", features = ["rand-std"], version = "0.17.2" }
3433

3534
[features]
3635
default = ["serde", "libsecp256k1" ]

src/keys/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
//! [`EnrPublicKey`]: crate::EnrPublicKey
99
//! [`Enr`]: crate::enr::Enr
1010
11-
#[cfg(any(feature = "ed25519", doc))]
11+
#[cfg(feature = "ed25519")]
1212
mod combined;
13-
#[cfg(any(feature = "ed25519", doc))]
13+
#[cfg(feature = "ed25519")]
1414
mod ed25519;
1515
#[cfg(any(feature = "libsecp256k1", doc))]
1616
mod libsecp256k1;
@@ -19,9 +19,9 @@ mod rust_secp256k1;
1919

2020
#[cfg(feature = "rust-secp256k1")]
2121
pub use c_secp256k1;
22-
#[cfg(any(feature = "ed25519", doc))]
22+
#[cfg(feature = "ed25519")]
2323
pub use combined::{CombinedKey, CombinedPublicKey};
24-
#[cfg(any(feature = "ed25519", doc))]
24+
#[cfg(feature = "ed25519")]
2525
pub use ed25519_dalek;
2626
#[cfg(any(feature = "libsecp256k1", doc))]
2727
pub use secp256k1;

src/lib.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
//!
6868
//! Note the `ed25519` feature flag must be set. This makes use of the
6969
//! [`EnrBuilder`] struct.
70-
//!
7170
//! ```rust
71+
//! # #[cfg(feature = "ed25519")] {
7272
//! use enr::{EnrBuilder, CombinedKey};
7373
//! use std::net::Ipv4Addr;
7474
//!
@@ -83,6 +83,7 @@
8383
//!
8484
//! assert_eq!(enr.ip(), Some("192.168.0.1".parse().unwrap()));
8585
//! assert_eq!(enr.id(), Some("v4".into()));
86+
//! # }
8687
//! ```
8788
//!
8889
//! ### Modifying an [`Enr`]
@@ -124,6 +125,7 @@
124125
//! ### Encoding/Decoding ENR's of various key types
125126
//!
126127
//! ```rust
128+
//! # #[cfg(feature = "ed25519")] {
127129
//! use enr::{EnrBuilder, secp256k1::SecretKey, Enr, ed25519_dalek::Keypair, CombinedKey};
128130
//! use std::net::Ipv4Addr;
129131
//! use rand::thread_rng;
@@ -154,6 +156,7 @@
154156
//! // use the combined key to be able to decode either
155157
//! let decoded_enr: Enr<CombinedKey> = base64_string_secp256k1.parse().unwrap();
156158
//! let decoded_enr: Enr<CombinedKey> = base64_string_ed25519.parse().unwrap();
159+
//! # }
157160
//! ```
158161
//!
159162
//!
@@ -745,8 +748,10 @@ impl<K: EnrKey> FromStr for Enr<K> {
745748
}
746749
// support both enr prefix and not
747750
let mut decode_string = base64_string;
748-
if &base64_string[..4] == "enr:" {
749-
decode_string = &decode_string[4..];
751+
if base64_string.starts_with("enr:") {
752+
decode_string = decode_string
753+
.get(4..)
754+
.ok_or_else(|| "Invalid ENR string".to_string())?;
750755
}
751756
let bytes = base64::decode_config(decode_string, base64::URL_SAFE_NO_PAD)
752757
.map_err(|e| format!("Invalid base64 encoding: {:?}", e))?;
@@ -888,7 +893,7 @@ mod tests {
888893

889894
#[cfg(feature = "libsecp256k1")]
890895
#[test]
891-
fn check_test_vector() {
896+
fn test_vector() {
892897
let valid_record = hex::decode("f884b8407098ad865b00a582051940cb9cf36836572411a47278783077011599ed5cd16b76f2635f4e234738f30813a89eb9137e3e3df5266e3a1f11df72ecf1145ccb9c01826964827634826970847f00000189736563703235366b31a103ca634cae0d49acb401d8a4c6b6fe8c55b70d115bf400769cc1400f3258cd31388375647082765f").unwrap();
893898
let signature = hex::decode("7098ad865b00a582051940cb9cf36836572411a47278783077011599ed5cd16b76f2635f4e234738f30813a89eb9137e3e3df5266e3a1f11df72ecf1145ccb9c").unwrap();
894899
let expected_pubkey =
@@ -910,7 +915,7 @@ mod tests {
910915

911916
#[cfg(feature = "libsecp256k1")]
912917
#[test]
913-
fn check_test_vector_2() {
918+
fn test_vector_2() {
914919
let text = "enr:-IS4QHCYrYZbAKWCBRlAy5zzaDZXJBGkcnh4MHcBFZntXNFrdvJjX04jRzjzCBOonrkTfj499SZuOh8R33Ls8RRcy5wBgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQPKY0yuDUmstAHYpMa2_oxVtw0RW_QAdpzBQA8yWM0xOIN1ZHCCdl8";
915920
let signature = hex::decode("7098ad865b00a582051940cb9cf36836572411a47278783077011599ed5cd16b76f2635f4e234738f30813a89eb9137e3e3df5266e3a1f11df72ecf1145ccb9c").unwrap();
916921
let expected_pubkey =
@@ -923,32 +928,31 @@ mod tests {
923928
let enr = text.parse::<DefaultEnr>().unwrap();
924929
let pubkey = enr.public_key().encode();
925930
assert_eq!(enr.ip(), Some(Ipv4Addr::new(127, 0, 0, 1)));
926-
dbg!("here");
927931
assert_eq!(enr.ip6(), None);
928-
dbg!("here");
929932
assert_eq!(enr.id(), Some(String::from("v4")));
930933
assert_eq!(enr.udp(), Some(30303));
931934
assert_eq!(enr.udp6(), None);
932935
assert_eq!(enr.tcp(), None);
933936
assert_eq!(enr.tcp6(), None);
934-
dbg!("here1");
935937
assert_eq!(enr.signature(), &signature[..]);
936-
dbg!("here2");
937938
assert_eq!(pubkey, expected_pubkey);
938-
dbg!("here3");
939939
assert_eq!(enr.node_id().raw().to_vec(), expected_node_id);
940940

941941
assert!(enr.verify());
942942
}
943943

944944
#[cfg(feature = "libsecp256k1")]
945945
#[test]
946-
fn test_read_enr() {
946+
fn test_read_enr_no_prefix() {
947947
let text = "-Iu4QM-YJF2RRpMcZkFiWzMf2kRd1A5F1GIekPa4Sfi_v0DCLTDBfOMTMMWJhhawr1YLUPb5008CpnBKrgjY3sstjfgCgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQP8u1uyQFyJYuQUTyA1raXKhSw1HhhxNUQ2VE52LNHWMIN0Y3CCIyiDdWRwgiMo";
948-
let enr = text.parse::<DefaultEnr>().unwrap();
949-
dbg!(enr.ip());
950-
dbg!(enr.udp());
951-
dbg!(enr.tcp());
948+
text.parse::<DefaultEnr>().unwrap();
949+
}
950+
951+
#[cfg(feature = "libsecp256k1")]
952+
#[test]
953+
fn test_read_enr_prefix() {
954+
let text = "enr:-Iu4QM-YJF2RRpMcZkFiWzMf2kRd1A5F1GIekPa4Sfi_v0DCLTDBfOMTMMWJhhawr1YLUPb5008CpnBKrgjY3sstjfgCgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQP8u1uyQFyJYuQUTyA1raXKhSw1HhhxNUQ2VE52LNHWMIN0Y3CCIyiDdWRwgiMo";
955+
text.parse::<DefaultEnr>().unwrap();
952956
}
953957

954958
#[cfg(feature = "libsecp256k1")]

0 commit comments

Comments
 (0)