diff --git a/Cargo.lock b/Cargo.lock index ce1fd20a73b..d99211a3961 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1422,6 +1422,12 @@ dependencies = [ "multiaddr", ] +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + [[package]] name = "flate2" version = "1.0.25" @@ -2102,6 +2108,7 @@ dependencies = [ "base64 0.21.0", "clap 4.1.8", "libp2p-core", + "libp2p-identity", "serde", "serde_json", "zeroize", @@ -2156,6 +2163,7 @@ dependencies = [ "libp2p-floodsub", "libp2p-gossipsub", "libp2p-identify", + "libp2p-identity", "libp2p-kad", "libp2p-mdns", "libp2p-metrics", @@ -2194,6 +2202,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-identify", + "libp2p-identity", "libp2p-noise", "libp2p-request-response", "libp2p-swarm", @@ -2209,43 +2218,31 @@ dependencies = [ name = "libp2p-core" version = "0.39.1" dependencies = [ - "asn1_der", "async-std", - "base64 0.21.0", - "bs58", - "criterion", - "ed25519-dalek", "either", "fnv", "futures", "futures-timer", "instant", + "libp2p-identity", "libp2p-mplex", "libp2p-noise", - "libsecp256k1", "log", "multiaddr", "multihash", "multistream-select", "once_cell", - "p256 0.12.0", "parking_lot 0.12.1", "pin-project", "quick-protobuf", "quickcheck-ext", "rand 0.8.5", - "ring", - "rmp-serde", "rw-stream-sink", - "sec1", "serde", - "serde_json", - "sha2 0.10.6", "smallvec", "thiserror", "unsigned-varint", "void", - "zeroize", ] [[package]] @@ -2263,6 +2260,7 @@ dependencies = [ "libp2p-core", "libp2p-dns", "libp2p-identify", + "libp2p-identity", "libp2p-noise", "libp2p-ping", "libp2p-plaintext", @@ -2301,6 +2299,7 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p-core", + "libp2p-identity", "log", "parking_lot 0.12.1", "smallvec", @@ -2317,6 +2316,7 @@ dependencies = [ "fnv", "futures", "libp2p-core", + "libp2p-identity", "libp2p-swarm", "log", "quick-protobuf", @@ -2342,6 +2342,7 @@ dependencies = [ "hex_fmt", "instant", "libp2p-core", + "libp2p-identity", "libp2p-mplex", "libp2p-noise", "libp2p-swarm", @@ -2372,6 +2373,7 @@ dependencies = [ "futures", "futures-timer", "libp2p-core", + "libp2p-identity", "libp2p-mplex", "libp2p-noise", "libp2p-swarm", @@ -2386,6 +2388,36 @@ dependencies = [ "void", ] +[[package]] +name = "libp2p-identity" +version = "0.1.0" +dependencies = [ + "asn1_der", + "base64 0.21.0", + "bs58", + "criterion", + "ed25519-dalek", + "libsecp256k1", + "log", + "multiaddr", + "multihash", + "p256 0.12.0", + "prost", + "prost-build", + "quick-protobuf", + "quickcheck-ext", + "rand 0.8.5", + "ring", + "rmp-serde", + "sec1", + "serde", + "serde_json", + "sha2 0.10.6", + "thiserror", + "void", + "zeroize", +] + [[package]] name = "libp2p-kad" version = "0.43.1" @@ -2400,6 +2432,7 @@ dependencies = [ "futures-timer", "instant", "libp2p-core", + "libp2p-identity", "libp2p-noise", "libp2p-swarm", "libp2p-yamux", @@ -2427,6 +2460,7 @@ dependencies = [ "futures", "if-watch", "libp2p-core", + "libp2p-identity", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2452,6 +2486,7 @@ dependencies = [ "libp2p-dcutr", "libp2p-gossipsub", "libp2p-identify", + "libp2p-identity", "libp2p-kad", "libp2p-noise", "libp2p-ping", @@ -2475,6 +2510,7 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p-core", + "libp2p-identity", "libp2p-muxer-test-harness", "libp2p-plaintext", "libp2p-tcp", @@ -2507,6 +2543,7 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p-core", + "libp2p-identity", "libp2p-tcp", "log", "once_cell", @@ -2532,6 +2569,7 @@ dependencies = [ "futures-timer", "instant", "libp2p-core", + "libp2p-identity", "libp2p-swarm", "libp2p-swarm-test", "log", @@ -2549,6 +2587,7 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p-core", + "libp2p-identity", "log", "quick-protobuf", "quickcheck-ext", @@ -2563,6 +2602,7 @@ version = "0.22.3" dependencies = [ "futures", "libp2p-core", + "libp2p-identity", "libp2p-noise", "libp2p-swarm", "libp2p-tcp", @@ -2588,6 +2628,7 @@ dependencies = [ "futures-timer", "if-watch", "libp2p-core", + "libp2p-identity", "libp2p-muxer-test-harness", "libp2p-noise", "libp2p-tcp", @@ -2617,6 +2658,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-identify", + "libp2p-identity", "libp2p-noise", "libp2p-ping", "libp2p-plaintext", @@ -2646,6 +2688,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-identify", + "libp2p-identity", "libp2p-mplex", "libp2p-noise", "libp2p-ping", @@ -2672,6 +2715,7 @@ dependencies = [ "futures", "instant", "libp2p-core", + "libp2p-identity", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2695,6 +2739,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-identify", + "libp2p-identity", "libp2p-kad", "libp2p-ping", "libp2p-plaintext", @@ -2726,6 +2771,7 @@ dependencies = [ "futures", "futures-timer", "libp2p-core", + "libp2p-identity", "libp2p-plaintext", "libp2p-swarm", "libp2p-tcp", @@ -2746,6 +2792,7 @@ dependencies = [ "if-watch", "libc", "libp2p-core", + "libp2p-identity", "log", "socket2", "tokio", @@ -2760,6 +2807,7 @@ dependencies = [ "hex", "hex-literal", "libp2p-core", + "libp2p-identity", "libp2p-swarm", "libp2p-yamux", "rcgen 0.10.0", @@ -2811,6 +2859,7 @@ dependencies = [ "hex-literal", "if-watch", "libp2p-core", + "libp2p-identity", "libp2p-noise", "libp2p-ping", "libp2p-swarm", @@ -2842,6 +2891,7 @@ dependencies = [ "futures-rustls", "libp2p-core", "libp2p-dns", + "libp2p-identity", "libp2p-tcp", "log", "parking_lot 0.12.1", @@ -3108,6 +3158,12 @@ dependencies = [ "synstructure", ] +[[package]] +name = "multimap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" + [[package]] name = "multistream-select" version = "0.12.1" @@ -3117,6 +3173,7 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p-core", + "libp2p-identity", "libp2p-mplex", "libp2p-plaintext", "libp2p-swarm", @@ -3440,6 +3497,16 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" +[[package]] +name = "petgraph" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dd7d28ee937e54fe3080c91faa1c3a46c06de6252988a7f4592ba2310ef22a4" +dependencies = [ + "fixedbitset", + "indexmap", +] + [[package]] name = "pin-project" version = "1.0.12" @@ -3593,6 +3660,16 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "prettyplease" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e97e3215779627f01ee256d2fad52f3d95e8e1c11e9fc6fd08f7cd455d5d5c78" +dependencies = [ + "proc-macro2", + "syn", +] + [[package]] name = "primeorder" version = "0.12.1" @@ -3668,6 +3745,60 @@ dependencies = [ "syn", ] +[[package]] +name = "prost" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e48e50df39172a3e7eb17e14642445da64996989bc212b583015435d39a58537" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-build" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c828f93f5ca4826f97fedcbd3f9a536c16b12cff3dbbb4a007f932bbad95b12" +dependencies = [ + "bytes", + "heck", + "itertools", + "lazy_static", + "log", + "multimap", + "petgraph", + "prettyplease", + "prost", + "prost-types", + "regex", + "syn", + "tempfile", + "which", +] + +[[package]] +name = "prost-derive" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea9b0f8cbe5e15a8a042d030bd96668db28ecb567ec37d691971ff5731d2b1b" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "prost-types" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "379119666929a1afd7a043aa6cf96fa67a6dce9af60c88095a4686dbce4c9c88" +dependencies = [ + "prost", +] + [[package]] name = "quick-error" version = "1.2.3" @@ -5299,6 +5430,17 @@ dependencies = [ "cc", ] +[[package]] +name = "which" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" +dependencies = [ + "either", + "libc", + "once_cell", +] + [[package]] name = "widestring" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index c32c8c42d1b..5d8a55cf211 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ members = [ "examples/ipfs-private", "examples/ping-example", "examples/rendezvous", + "identity", "misc/metrics", "misc/multistream-select", "misc/rw-stream-sink", diff --git a/core/Cargo.toml b/core/Cargo.toml index 4c998eaf77e..1ef65ee689a 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -11,58 +11,40 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -asn1_der = "0.7.4" -bs58 = "0.4.0" -ed25519-dalek = "1.0.1" either = "1.5" fnv = "1.0" futures = { version = "0.3.26", features = ["executor", "thread-pool"] } futures-timer = "3" instant = "0.1.11" -libsecp256k1 = { version = "0.7.0", optional = true } +libp2p-identity = { version = "0.1", path = "../identity", features = ["peerid", "ed25519"] } log = "0.4" multiaddr = { version = "0.17.0" } multihash = { version = "0.17.0", default-features = false, features = ["std", "multihash-impl", "identity", "sha2"] } multistream-select = { version = "0.12.1", path = "../misc/multistream-select" } -p256 = { version = "0.12.0", default-features = false, features = ["ecdsa", "std"], optional = true } +once_cell = "1.17.1" parking_lot = "0.12.0" pin-project = "1.0.0" quick-protobuf = "0.8" -once_cell = "1.17.1" rand = "0.8" rw-stream-sink = { version = "0.3.0", path = "../misc/rw-stream-sink" } -sec1 = { version = "0.3.0", features = ["std"] } # Activate `std` feature until https://github.com/RustCrypto/traits/pull/1131 is released. serde = { version = "1", optional = true, features = ["derive"] } -sha2 = "0.10.0" smallvec = "1.6.1" thiserror = "1.0" unsigned-varint = "0.7" void = "1" -zeroize = "1" - -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] -ring = { version = "0.16.9", features = ["alloc", "std"], default-features = false, optional = true} [dev-dependencies] async-std = { version = "1.6.2", features = ["attributes"] } -base64 = "0.21.0" -criterion = "0.4" libp2p-mplex = { path = "../muxers/mplex" } libp2p-noise = { path = "../transports/noise" } multihash = { version = "0.17.0", default-features = false, features = ["arb"] } quickcheck = { package = "quickcheck-ext", path = "../misc/quickcheck-ext" } -rmp-serde = "1.0" -serde_json = "1.0" [features] -secp256k1 = [ "libsecp256k1" ] -ecdsa = [ "p256" ] -rsa = [ "dep:ring" ] -serde = ["multihash/serde-codec", "dep:serde"] - -[[bench]] -name = "peer_id" -harness = false +secp256k1 = [ "libp2p-identity/secp256k1" ] +ecdsa = [ "libp2p-identity/ecdsa" ] +rsa = [ "libp2p-identity/rsa" ] +serde = ["multihash/serde-codec", "dep:serde", "libp2p-identity/serde"] # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/core/src/generated/envelope.proto b/core/src/generated/envelope.proto index 9ab3e6fd256..dab3cfe96c9 100644 --- a/core/src/generated/envelope.proto +++ b/core/src/generated/envelope.proto @@ -2,8 +2,6 @@ syntax = "proto3"; package envelope_proto; -import "keys.proto"; - // Envelope encloses a signed payload produced by a peer, along with the public // key of the keypair it was signed with so that it can be statelessly validated // by the receiver. @@ -14,7 +12,7 @@ import "keys.proto"; message Envelope { // public_key is the public key of the keypair the enclosed payload was // signed with. - keys_proto.PublicKey public_key = 1; + bytes public_key = 1; // payload_type encodes the type of payload, so that it can be deserialized // deterministically. diff --git a/core/src/generated/envelope_proto.rs b/core/src/generated/envelope_proto.rs index 268b6a334f3..0f342f05413 100644 --- a/core/src/generated/envelope_proto.rs +++ b/core/src/generated/envelope_proto.rs @@ -16,7 +16,7 @@ use super::*; #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Debug, Default, PartialEq, Clone)] pub struct Envelope { - pub public_key: Option, + pub public_key: Vec, pub payload_type: Vec, pub payload: Vec, pub signature: Vec, @@ -27,7 +27,7 @@ impl<'a> MessageRead<'a> for Envelope { let mut msg = Self::default(); while !r.is_eof() { match r.next_tag(bytes) { - Ok(10) => msg.public_key = Some(r.read_message::(bytes)?), + Ok(10) => msg.public_key = r.read_bytes(bytes)?.to_owned(), Ok(18) => msg.payload_type = r.read_bytes(bytes)?.to_owned(), Ok(26) => msg.payload = r.read_bytes(bytes)?.to_owned(), Ok(42) => msg.signature = r.read_bytes(bytes)?.to_owned(), @@ -42,14 +42,14 @@ impl<'a> MessageRead<'a> for Envelope { impl MessageWrite for Envelope { fn get_size(&self) -> usize { 0 - + self.public_key.as_ref().map_or(0, |m| 1 + sizeof_len((m).get_size())) + + if self.public_key.is_empty() { 0 } else { 1 + sizeof_len((&self.public_key).len()) } + if self.payload_type.is_empty() { 0 } else { 1 + sizeof_len((&self.payload_type).len()) } + if self.payload.is_empty() { 0 } else { 1 + sizeof_len((&self.payload).len()) } + if self.signature.is_empty() { 0 } else { 1 + sizeof_len((&self.signature).len()) } } fn write_message(&self, w: &mut Writer) -> Result<()> { - if let Some(ref s) = self.public_key { w.write_with_tag(10, |w| w.write_message(s))?; } + if !self.public_key.is_empty() { w.write_with_tag(10, |w| w.write_bytes(&**&self.public_key))?; } if !self.payload_type.is_empty() { w.write_with_tag(18, |w| w.write_bytes(&**&self.payload_type))?; } if !self.payload.is_empty() { w.write_with_tag(26, |w| w.write_bytes(&**&self.payload))?; } if !self.signature.is_empty() { w.write_with_tag(42, |w| w.write_bytes(&**&self.signature))?; } diff --git a/core/src/generated/mod.rs b/core/src/generated/mod.rs index 964d125e02f..950f42ed128 100644 --- a/core/src/generated/mod.rs +++ b/core/src/generated/mod.rs @@ -1,4 +1,3 @@ // Automatically generated mod.rs pub mod envelope_proto; -pub mod keys_proto; pub mod peer_record_proto; diff --git a/core/src/lib.rs b/core/src/lib.rs index f3e00b1ff15..84e39fdafb1 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -40,8 +40,7 @@ mod proto { include!("generated/mod.rs"); pub use self::{ - envelope_proto::*, keys_proto::*, peer_record_proto::mod_PeerRecord::*, - peer_record_proto::PeerRecord, + envelope_proto::*, peer_record_proto::mod_PeerRecord::*, peer_record_proto::PeerRecord, }; } @@ -51,25 +50,78 @@ use std::fmt; use std::fmt::Formatter; pub type Negotiated = multistream_select::Negotiated; -mod peer_id; +#[deprecated(since = "0.39.0", note = "Depend on `libp2p-identity` instead.")] +pub mod identity { + pub use libp2p_identity::Keypair; + pub use libp2p_identity::PublicKey; + + pub mod ed25519 { + pub use libp2p_identity::ed25519::Keypair; + pub use libp2p_identity::ed25519::PublicKey; + pub use libp2p_identity::ed25519::SecretKey; + } + + #[cfg(feature = "ecdsa")] + #[deprecated( + since = "0.39.0", + note = "The `ecdsa` feature-flag is deprecated and will be removed in favor of `libp2p-identity`." + )] + pub mod ecdsa { + pub use libp2p_identity::ecdsa::Keypair; + pub use libp2p_identity::ecdsa::PublicKey; + pub use libp2p_identity::ecdsa::SecretKey; + } + + #[cfg(feature = "secp256k1")] + #[deprecated( + since = "0.39.0", + note = "The `secp256k1` feature-flag is deprecated and will be removed in favor of `libp2p-identity`." + )] + pub mod secp256k1 { + pub use libp2p_identity::secp256k1::Keypair; + pub use libp2p_identity::secp256k1::PublicKey; + pub use libp2p_identity::secp256k1::SecretKey; + } + + #[cfg(feature = "rsa")] + #[deprecated( + since = "0.39.0", + note = "The `rsa` feature-flag is deprecated and will be removed in favor of `libp2p-identity`." + )] + pub mod rsa { + pub use libp2p_identity::rsa::Keypair; + pub use libp2p_identity::rsa::PublicKey; + } + + pub mod error { + pub use libp2p_identity::DecodingError; + pub use libp2p_identity::SigningError; + } +} + mod translation; pub mod connection; pub mod either; -pub mod identity; pub mod muxing; pub mod peer_record; pub mod signed_envelope; pub mod transport; pub mod upgrade; +#[deprecated(since = "0.39.0", note = "Depend on `libp2p-identity` instead.")] +pub type PublicKey = libp2p_identity::PublicKey; + +#[deprecated(since = "0.39.0", note = "Depend on `libp2p-identity` instead.")] +pub type PeerId = libp2p_identity::PeerId; + +#[deprecated(since = "0.39.0", note = "Depend on `libp2p-identity` instead.")] +pub type ParseError = libp2p_identity::ParseError; + pub use connection::{ConnectedPoint, Endpoint}; -pub use identity::PublicKey; pub use multiaddr::Multiaddr; pub use multihash; pub use muxing::StreamMuxer; -pub use peer_id::ParseError; -pub use peer_id::PeerId; pub use peer_record::PeerRecord; pub use signed_envelope::SignedEnvelope; pub use translation::address_translation; diff --git a/core/src/peer_record.rs b/core/src/peer_record.rs index 2a01a18fd42..35433dc245f 100644 --- a/core/src/peer_record.rs +++ b/core/src/peer_record.rs @@ -1,9 +1,9 @@ -use crate::identity::error::SigningError; -use crate::identity::Keypair; -use crate::proto; use crate::signed_envelope::SignedEnvelope; -use crate::{signed_envelope, DecodeError, Multiaddr, PeerId}; +use crate::{proto, signed_envelope, DecodeError, Multiaddr}; use instant::SystemTime; +use libp2p_identity::Keypair; +use libp2p_identity::PeerId; +use libp2p_identity::SigningError; use quick_protobuf::{BytesReader, Writer}; use std::convert::TryInto; diff --git a/core/src/signed_envelope.rs b/core/src/signed_envelope.rs index 12c1324efa9..0eafda4c487 100644 --- a/core/src/signed_envelope.rs +++ b/core/src/signed_envelope.rs @@ -1,8 +1,7 @@ -use crate::identity::error::SigningError; -use crate::identity::Keypair; -use crate::{identity, proto, DecodeError, PublicKey}; +use crate::{proto, DecodeError}; +use libp2p_identity::SigningError; +use libp2p_identity::{Keypair, PublicKey}; use quick_protobuf::{BytesReader, Writer}; -use std::convert::TryInto; use std::fmt; use unsigned_varint::encode::usize_buffer; @@ -77,7 +76,7 @@ impl SignedEnvelope { use quick_protobuf::MessageWrite; let envelope = proto::Envelope { - public_key: Some((&self.key).into()), + public_key: self.key.to_protobuf_encoding(), payload_type: self.payload_type, payload: self.payload, signature: self.signature, @@ -102,10 +101,7 @@ impl SignedEnvelope { proto::Envelope::from_reader(&mut reader, bytes).map_err(DecodeError::from)?; Ok(Self { - key: envelope - .public_key - .ok_or(DecodingError::MissingPublicKey)? - .try_into()?, + key: PublicKey::from_protobuf_encoding(&envelope.public_key)?, payload_type: envelope.payload_type.to_vec(), payload: envelope.payload.to_vec(), signature: envelope.signature.to_vec(), @@ -152,7 +148,7 @@ pub enum DecodingError { InvalidEnvelope(#[from] DecodeError), /// The public key in the envelope could not be converted to our internal public key type. #[error("Failed to convert public key")] - InvalidPublicKey(#[from] identity::error::DecodingError), + InvalidPublicKey(#[from] libp2p_identity::DecodingError), /// The public key in the envelope could not be converted to our internal public key type. #[error("Public key is missing from protobuf struct")] MissingPublicKey, diff --git a/core/src/transport/upgrade.rs b/core/src/transport/upgrade.rs index 4f28296065b..9f6998d9968 100644 --- a/core/src/transport/upgrade.rs +++ b/core/src/transport/upgrade.rs @@ -33,9 +33,10 @@ use crate::{ self, apply_inbound, apply_outbound, InboundUpgrade, InboundUpgradeApply, OutboundUpgrade, OutboundUpgradeApply, UpgradeError, }, - Negotiated, PeerId, + Negotiated, }; use futures::{prelude::*, ready}; +use libp2p_identity::PeerId; use multiaddr::Multiaddr; use std::{ error::Error, diff --git a/core/tests/transport_upgrade.rs b/core/tests/transport_upgrade.rs index dac84534369..e2c44f9f0d4 100644 --- a/core/tests/transport_upgrade.rs +++ b/core/tests/transport_upgrade.rs @@ -19,9 +19,9 @@ // DEALINGS IN THE SOFTWARE. use futures::prelude::*; -use libp2p_core::identity; use libp2p_core::transport::{MemoryTransport, Transport}; use libp2p_core::upgrade::{self, InboundUpgrade, OutboundUpgrade, UpgradeInfo}; +use libp2p_identity as identity; use libp2p_mplex::MplexConfig; use libp2p_noise as noise; use multiaddr::{Multiaddr, Protocol}; diff --git a/examples/dcutr/src/main.rs b/examples/dcutr/src/main.rs index aa7b32af4ce..e7dd716723f 100644 --- a/examples/dcutr/src/main.rs +++ b/examples/dcutr/src/main.rs @@ -28,13 +28,13 @@ use libp2p::{ core::{ multiaddr::{Multiaddr, Protocol}, transport::{OrTransport, Transport}, - upgrade, PeerId, + upgrade, }, dcutr, dns::DnsConfig, identify, identity, noise, ping, relay, swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent}, - tcp, yamux, + tcp, yamux, PeerId, }; use log::info; use std::error::Error; @@ -281,7 +281,5 @@ fn generate_ed25519(secret_key_seed: u8) -> identity::Keypair { let mut bytes = [0u8; 32]; bytes[0] = secret_key_seed; - let secret_key = identity::ed25519::SecretKey::from_bytes(&mut bytes) - .expect("this returns `Err` only if the length is wrong; the length is correct; qed"); - identity::Keypair::Ed25519(secret_key.into()) + identity::Keypair::ed25519_from_bytes(bytes).expect("only errors on wrong length") } diff --git a/examples/file-sharing/src/main.rs b/examples/file-sharing/src/main.rs index 27649be9657..fb7e1b75ff0 100644 --- a/examples/file-sharing/src/main.rs +++ b/examples/file-sharing/src/main.rs @@ -81,10 +81,7 @@ use clap::Parser; use futures::prelude::*; use futures::StreamExt; -use libp2p::{ - core::{Multiaddr, PeerId}, - multiaddr::Protocol, -}; +use libp2p::{core::Multiaddr, multiaddr::Protocol, PeerId}; use std::error::Error; use std::io::Write; use std::path::PathBuf; diff --git a/examples/file-sharing/src/network.rs b/examples/file-sharing/src/network.rs index a7dce68991f..8704f5f6dbb 100644 --- a/examples/file-sharing/src/network.rs +++ b/examples/file-sharing/src/network.rs @@ -7,7 +7,7 @@ use futures::prelude::*; use libp2p::{ core::{ upgrade::{read_length_prefixed, write_length_prefixed, ProtocolName}, - Multiaddr, PeerId, + Multiaddr, }, identity, kad::{ @@ -16,6 +16,7 @@ use libp2p::{ multiaddr::Protocol, request_response::{self, ProtocolSupport, RequestId, ResponseChannel}, swarm::{ConnectionHandlerUpgrErr, NetworkBehaviour, Swarm, SwarmEvent}, + PeerId, }; use std::collections::{hash_map, HashMap, HashSet}; @@ -38,10 +39,7 @@ pub async fn new( Some(seed) => { let mut bytes = [0u8; 32]; bytes[0] = seed; - let secret_key = identity::ed25519::SecretKey::from_bytes(&mut bytes).expect( - "this returns `Err` only if the length is wrong; the length is correct; qed", - ); - identity::Keypair::Ed25519(secret_key.into()) + identity::Keypair::ed25519_from_bytes(bytes).unwrap() } None => identity::Keypair::generate_ed25519(), }; diff --git a/examples/identify/src/main.rs b/examples/identify/src/main.rs index cd136d585c8..cd06ee0f7e8 100644 --- a/examples/identify/src/main.rs +++ b/examples/identify/src/main.rs @@ -38,10 +38,10 @@ use futures::prelude::*; use libp2p::{ - core::{multiaddr::Multiaddr, upgrade::Version, PeerId}, + core::{multiaddr::Multiaddr, upgrade::Version}, identify, identity, noise, swarm::{Swarm, SwarmEvent}, - tcp, yamux, Transport, + tcp, yamux, PeerId, Transport, }; use std::error::Error; diff --git a/identity/Cargo.toml b/identity/Cargo.toml new file mode 100644 index 00000000000..46c257a0bb2 --- /dev/null +++ b/identity/Cargo.toml @@ -0,0 +1,55 @@ +[package] +name = "libp2p-identity" +version = "0.1.0" +edition = "2021" +description = "Data structures and algorithms for identifying peers in libp2p." +rust-version = "1.60.0" +license = "MIT" +repository = "https://github.com/libp2p/rust-libp2p" +keywords = ["peer-to-peer", "libp2p", "networking", "cryptography"] +categories = ["cryptography"] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +asn1_der = { version = "0.7.4", optional = true } +bs58 = { version = "0.4.0", optional = true } +ed25519-dalek = { version = "1.0.1", optional = true } +libsecp256k1 = { version = "0.7.0", optional = true } +log = "0.4" +multiaddr = { version = "0.17.0", optional = true } +multihash = { version = "0.17.0", default-features = false, features = ["std", "multihash-impl", "identity", "sha2"], optional = true } +p256 = { version = "0.12", default-features = false, features = ["ecdsa", "std"], optional = true } +prost = { version = "0.11", optional = true } +quick-protobuf = "0.8.1" +rand = { version = "0.8", optional = true } +sec1 = { version = "0.3.0", features = ["std"], optional = true } # Activate `std` feature until https://github.com/RustCrypto/traits/pull/1131 is released. +serde = { version = "1", optional = true, features = ["derive"] } +sha2 = { version = "0.10.0", optional = true } +thiserror = { version = "1.0", optional = true } +void = { version = "1.0", optional = true } +zeroize = { version = "1.0", optional = true } + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +ring = { version = "0.16.9", features = ["alloc", "std"], default-features = false, optional = true} + +[features] +secp256k1 = [ "libsecp256k1", "asn1_der", "prost", "rand", "sha2", "zeroize" ] +ecdsa = [ "p256", "prost", "rand", "void", "zeroize", "sec1" ] +rsa = [ "dep:ring", "asn1_der", "prost", "rand", "zeroize" ] +ed25519 = [ "ed25519-dalek", "prost", "rand", "zeroize" ] +peerid = [ "multihash", "multiaddr", "bs58", "rand", "thiserror" ] + +[dev-dependencies] +quickcheck = { package = "quickcheck-ext", path = "../misc/quickcheck-ext" } +base64 = "0.21.0" +serde_json = "1.0" +rmp-serde = "1.0" +criterion = "0.4" + +[build-dependencies] +prost-build = "0.11" + +[[bench]] +name = "peer_id" +harness = false diff --git a/core/benches/peer_id.rs b/identity/benches/peer_id.rs similarity index 85% rename from core/benches/peer_id.rs rename to identity/benches/peer_id.rs index e9fec2f18d3..358778e221e 100644 --- a/core/benches/peer_id.rs +++ b/identity/benches/peer_id.rs @@ -19,13 +19,10 @@ // DEALINGS IN THE SOFTWARE. use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use libp2p_core::{identity, PeerId}; +use libp2p_identity::{Keypair, PeerId}; fn from_bytes(c: &mut Criterion) { - let peer_id_bytes = identity::Keypair::generate_ed25519() - .public() - .to_peer_id() - .to_bytes(); + let peer_id_bytes = Keypair::generate_ed25519().public().to_peer_id().to_bytes(); c.bench_function("from_bytes", |b| { b.iter(|| { @@ -35,7 +32,7 @@ fn from_bytes(c: &mut Criterion) { } fn clone(c: &mut Criterion) { - let peer_id = identity::Keypair::generate_ed25519().public().to_peer_id(); + let peer_id = Keypair::generate_ed25519().public().to_peer_id(); c.bench_function("clone", |b| { b.iter(|| { @@ -46,7 +43,7 @@ fn clone(c: &mut Criterion) { fn sort_vec(c: &mut Criterion) { let peer_ids: Vec<_> = (0..100) - .map(|_| identity::Keypair::generate_ed25519().public().to_peer_id()) + .map(|_| Keypair::generate_ed25519().public().to_peer_id()) .collect(); c.bench_function("sort_vec", |b| { diff --git a/core/src/identity/ecdsa.rs b/identity/src/ecdsa.rs similarity index 100% rename from core/src/identity/ecdsa.rs rename to identity/src/ecdsa.rs diff --git a/core/src/identity/ed25519.rs b/identity/src/ed25519.rs similarity index 100% rename from core/src/identity/ed25519.rs rename to identity/src/ed25519.rs diff --git a/core/src/identity/error.rs b/identity/src/error.rs similarity index 93% rename from core/src/identity/error.rs rename to identity/src/error.rs index fb5d8eb2006..aa12fa9d7dc 100644 --- a/core/src/identity/error.rs +++ b/identity/src/error.rs @@ -35,6 +35,7 @@ impl DecodingError { feature = "ecdsa", feature = "rsa", feature = "secp256k1", + feature = "ed25519", not(target_arch = "wasm32") )))] pub(crate) fn missing_feature(feature_name: &'static str) -> Self { @@ -44,6 +45,12 @@ impl DecodingError { } } + #[cfg(any( + feature = "ecdsa", + feature = "secp256k1", + feature = "ed25519", + feature = "rsa" + ))] pub(crate) fn failed_to_parse(what: &'static str, source: S) -> Self where E: Error + Send + Sync + 'static, @@ -58,6 +65,12 @@ impl DecodingError { } } + #[cfg(any( + feature = "ecdsa", + feature = "secp256k1", + feature = "ed25519", + feature = "rsa" + ))] pub(crate) fn bad_protobuf( what: &'static str, source: impl Error + Send + Sync + 'static, diff --git a/core/src/generated/keys.proto b/identity/src/generated/keys.proto similarity index 100% rename from core/src/generated/keys.proto rename to identity/src/generated/keys.proto diff --git a/core/src/generated/keys_proto.rs b/identity/src/generated/keys_proto.rs similarity index 100% rename from core/src/generated/keys_proto.rs rename to identity/src/generated/keys_proto.rs diff --git a/identity/src/generated/mod.rs b/identity/src/generated/mod.rs new file mode 100644 index 00000000000..9f9a104ac10 --- /dev/null +++ b/identity/src/generated/mod.rs @@ -0,0 +1,2 @@ +// Automatically generated mod.rs +pub mod keys_proto; diff --git a/core/src/identity.rs b/identity/src/keypair.rs similarity index 69% rename from core/src/identity.rs rename to identity/src/keypair.rs index 5c290c11c5a..2c1f565d4ed 100644 --- a/core/src/identity.rs +++ b/identity/src/keypair.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2023 Protocol Labs. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), @@ -18,34 +18,22 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -//! A node's network identity keys. -//! -//! Such identity keys can be randomly generated on every startup, -//! but using already existing, fixed keys is usually required. -//! Though libp2p uses other crates (e.g. `ed25519_dalek`) internally, -//! such details are not exposed as part of libp2p's public interface -//! to keep them easily upgradable or replaceable (e.g. to `ed25519_zebra`). -//! Consequently, keys of external ed25519 or secp256k1 crates cannot be -//! directly converted into libp2p network identities. -//! Instead, loading fixed keys must use the standard, thus more portable -//! binary representation of the specific key type -//! (e.g. [ed25519 binary format](https://datatracker.ietf.org/doc/html/rfc8032#section-5.1.5)). -//! All key types have functions to enable conversion to/from their binary representations. +use crate::error::{DecodingError, SigningError}; +use crate::proto; +use quick_protobuf::{BytesReader, Writer}; +use std::convert::TryFrom; + +#[cfg(feature = "ed25519")] +use crate::ed25519; -#[cfg(feature = "ecdsa")] -pub mod ecdsa; -pub mod ed25519; #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] -pub mod rsa; -#[cfg(feature = "secp256k1")] -pub mod secp256k1; +use crate::rsa; -pub mod error; +#[cfg(feature = "secp256k1")] +use crate::secp256k1; -use self::error::*; -use crate::{proto, PeerId}; -use quick_protobuf::{BytesReader, Writer}; -use std::convert::{TryFrom, TryInto}; +#[cfg(feature = "ecdsa")] +use crate::ecdsa; /// Identity keypair of a node. /// @@ -68,42 +56,100 @@ use std::convert::{TryFrom, TryInto}; #[allow(clippy::large_enum_variant)] pub enum Keypair { /// An Ed25519 keypair. + #[cfg(feature = "ed25519")] + #[deprecated( + since = "0.1.0", + note = "This enum will be made opaque in the future, use `Keypair::into_ed25519` instead." + )] Ed25519(ed25519::Keypair), /// An RSA keypair. #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] + #[deprecated( + since = "0.1.0", + note = "This enum will be made opaque in the future, use `Keypair::into_rsa` instead." + )] Rsa(rsa::Keypair), /// A Secp256k1 keypair. #[cfg(feature = "secp256k1")] + #[deprecated( + since = "0.1.0", + note = "This enum will be made opaque in the future, use `Keypair::into_secp256k1` instead." + )] Secp256k1(secp256k1::Keypair), /// An ECDSA keypair. #[cfg(feature = "ecdsa")] + #[deprecated( + since = "0.1.0", + note = "This enum will be made opaque in the future, use `Keypair::into_ecdsa` instead." + )] Ecdsa(ecdsa::Keypair), } impl Keypair { /// Generate a new Ed25519 keypair. + #[cfg(feature = "ed25519")] pub fn generate_ed25519() -> Keypair { + #[allow(deprecated)] Keypair::Ed25519(ed25519::Keypair::generate()) } /// Generate a new Secp256k1 keypair. #[cfg(feature = "secp256k1")] pub fn generate_secp256k1() -> Keypair { + #[allow(deprecated)] Keypair::Secp256k1(secp256k1::Keypair::generate()) } /// Generate a new ECDSA keypair. #[cfg(feature = "ecdsa")] pub fn generate_ecdsa() -> Keypair { + #[allow(deprecated)] Keypair::Ecdsa(ecdsa::Keypair::generate()) } + #[cfg(feature = "ed25519")] + pub fn into_ed25519(self) -> Option { + #[allow(deprecated)] + match self { + Keypair::Ed25519(inner) => Some(inner), + _ => None, + } + } + + #[cfg(feature = "secp256k1")] + pub fn into_secp256k1(self) -> Option { + #[allow(deprecated)] + match self { + Keypair::Secp256k1(inner) => Some(inner), + _ => None, + } + } + + #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] + pub fn into_rsa(self) -> Option { + #[allow(deprecated)] + match self { + Keypair::Rsa(inner) => Some(inner), + _ => None, + } + } + + #[cfg(feature = "ecdsa")] + pub fn into_ecdsa(self) -> Option { + #[allow(deprecated)] + match self { + Keypair::Ecdsa(inner) => Some(inner), + _ => None, + } + } + /// Decode an keypair from a DER-encoded secret key in PKCS#8 PrivateKeyInfo /// format (i.e. unencrypted) as defined in [RFC5208]. /// /// [RFC5208]: https://tools.ietf.org/html/rfc5208#section-5 #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] pub fn rsa_from_pkcs8(pkcs8_der: &mut [u8]) -> Result { + #[allow(deprecated)] rsa::Keypair::from_pkcs8(pkcs8_der).map(Keypair::Rsa) } @@ -113,15 +159,26 @@ impl Keypair { /// [RFC5915]: https://tools.ietf.org/html/rfc5915 #[cfg(feature = "secp256k1")] pub fn secp256k1_from_der(der: &mut [u8]) -> Result { + #[allow(deprecated)] secp256k1::SecretKey::from_der(der) .map(|sk| Keypair::Secp256k1(secp256k1::Keypair::from(sk))) } + #[cfg(feature = "ed25519")] + pub fn ed25519_from_bytes(bytes: impl AsMut<[u8]>) -> Result { + #[allow(deprecated)] + Ok(Keypair::Ed25519(ed25519::Keypair::from( + ed25519::SecretKey::from_bytes(bytes)?, + ))) + } + /// Sign a message using the private key of this keypair, producing /// a signature that can be verified using the corresponding public key. pub fn sign(&self, msg: &[u8]) -> Result, SigningError> { use Keypair::*; + #[allow(deprecated)] match self { + #[cfg(feature = "ed25519")] Ed25519(ref pair) => Ok(pair.sign(msg)), #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] Rsa(ref pair) => pair.sign(msg), @@ -135,7 +192,9 @@ impl Keypair { /// Get the public key of this keypair. pub fn public(&self) -> PublicKey { use Keypair::*; + #[allow(deprecated)] match self { + #[cfg(feature = "ed25519")] Ed25519(pair) => PublicKey::Ed25519(pair.public()), #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] Rsa(pair) => PublicKey::Rsa(pair.public()), @@ -147,10 +206,19 @@ impl Keypair { } /// Encode a private key as protobuf structure. + #[cfg_attr( + not(feature = "ed25519"), + allow(unreachable_code, unused_variables, unused_mut) + )] pub fn to_protobuf_encoding(&self) -> Result, DecodingError> { use quick_protobuf::MessageWrite; - let pk = match self { + #[cfg(not(feature = "ed25519"))] + return Err(DecodingError::missing_feature("ed25519")); + + #[allow(deprecated)] + let pk: proto::PrivateKey = match self { + #[cfg(feature = "ed25519")] Self::Ed25519(data) => proto::PrivateKey { Type: proto::KeyType::Ed25519, Data: data.encode().to_vec(), @@ -171,6 +239,7 @@ impl Keypair { } /// Decode a private key from a protobuf structure and parse it as a [`Keypair`]. + #[cfg_attr(not(feature = "ed25519"), allow(unused_mut))] pub fn from_protobuf_encoding(bytes: &[u8]) -> Result { use quick_protobuf::MessageRead; @@ -180,9 +249,14 @@ impl Keypair { .map(zeroize::Zeroizing::new)?; match private_key.Type { - proto::KeyType::Ed25519 => { + #[cfg(feature = "ed25519")] + proto::KeyType::Ed25519 => + { + #[allow(deprecated)] ed25519::Keypair::decode(&mut private_key.Data).map(Keypair::Ed25519) } + #[cfg(not(feature = "ed25519"))] + proto::KeyType::Ed25519 => Err(DecodingError::missing_feature("ed25519")), proto::KeyType::RSA => Err(DecodingError::decoding_unsupported("RSA")), proto::KeyType::Secp256k1 => Err(DecodingError::decoding_unsupported("secp256k1")), proto::KeyType::ECDSA => Err(DecodingError::decoding_unsupported("ECDSA")), @@ -190,27 +264,37 @@ impl Keypair { } } -impl zeroize::Zeroize for proto::PrivateKey { - fn zeroize(&mut self) { - // KeyType cannot be zeroized. - self.Type = proto::KeyType::default(); - self.Data.zeroize(); - } -} - /// The public key of a node's identity keypair. #[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub enum PublicKey { /// A public Ed25519 key. + #[cfg(feature = "ed25519")] + #[deprecated( + since = "0.1.0", + note = "This enum will be made opaque in the future, use `PublicKey::into_ed25519` instead." + )] Ed25519(ed25519::PublicKey), #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] /// A public RSA key. + + #[deprecated( + since = "0.1.0", + note = "This enum will be made opaque in the future, use `PublicKey::into_rsa` instead." + )] Rsa(rsa::PublicKey), #[cfg(feature = "secp256k1")] /// A public Secp256k1 key. + #[deprecated( + since = "0.1.0", + note = "This enum will be made opaque in the future, use `PublicKey::into_secp256k1` instead." + )] Secp256k1(secp256k1::PublicKey), /// A public ECDSA key. #[cfg(feature = "ecdsa")] + #[deprecated( + since = "0.1.0", + note = "This enum will be made opaque in the future, use `PublicKey::into_ecdsa` instead." + )] Ecdsa(ecdsa::PublicKey), } @@ -222,7 +306,9 @@ impl PublicKey { #[must_use] pub fn verify(&self, msg: &[u8], sig: &[u8]) -> bool { use PublicKey::*; + #[allow(deprecated)] match self { + #[cfg(feature = "ed25519")] Ed25519(pk) => pk.verify(msg, sig), #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] Rsa(pk) => pk.verify(msg, sig), @@ -233,6 +319,42 @@ impl PublicKey { } } + #[cfg(feature = "ed25519")] + pub fn into_ed25519(self) -> Option { + #[allow(deprecated)] + match self { + PublicKey::Ed25519(inner) => Some(inner), + _ => None, + } + } + + #[cfg(feature = "secp256k1")] + pub fn into_secp256k1(self) -> Option { + #[allow(deprecated)] + match self { + PublicKey::Secp256k1(inner) => Some(inner), + _ => None, + } + } + + #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] + pub fn into_rsa(self) -> Option { + #[allow(deprecated)] + match self { + PublicKey::Rsa(inner) => Some(inner), + _ => None, + } + } + + #[cfg(feature = "ecdsa")] + pub fn into_ecdsa(self) -> Option { + #[allow(deprecated)] + match self { + PublicKey::Ecdsa(inner) => Some(inner), + _ => None, + } + } + /// Encode the public key into a protobuf structure for storage or /// exchange with other nodes. pub fn to_protobuf_encoding(&self) -> Vec { @@ -263,45 +385,27 @@ impl PublicKey { } /// Convert the `PublicKey` into the corresponding `PeerId`. - pub fn to_peer_id(&self) -> PeerId { + #[cfg(feature = "peerid")] + pub fn to_peer_id(&self) -> crate::PeerId { self.into() } } -impl From<&PublicKey> for proto::PublicKey { - fn from(key: &PublicKey) -> Self { - match key { - PublicKey::Ed25519(key) => proto::PublicKey { - Type: proto::KeyType::Ed25519, - Data: key.encode().to_vec(), - }, - #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] - PublicKey::Rsa(key) => proto::PublicKey { - Type: proto::KeyType::RSA, - Data: key.encode_x509(), - }, - #[cfg(feature = "secp256k1")] - PublicKey::Secp256k1(key) => proto::PublicKey { - Type: proto::KeyType::Secp256k1, - Data: key.encode().to_vec(), - }, - #[cfg(feature = "ecdsa")] - PublicKey::Ecdsa(key) => proto::PublicKey { - Type: proto::KeyType::ECDSA, - Data: key.encode_der(), - }, - } - } -} - impl TryFrom for PublicKey { type Error = DecodingError; fn try_from(pubkey: proto::PublicKey) -> Result { + #[allow(deprecated)] match pubkey.Type { + #[cfg(feature = "ed25519")] proto::KeyType::Ed25519 => { ed25519::PublicKey::decode(&pubkey.Data).map(PublicKey::Ed25519) } + #[cfg(not(feature = "ed25519"))] + proto::KeyType::Ed25519 => { + log::debug!("support for ed25519 was disabled at compile-time"); + Err(DecodingError::missing_feature("ed25519")) + } #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] proto::KeyType::RSA => rsa::PublicKey::decode_x509(&pubkey.Data).map(PublicKey::Rsa), #[cfg(any(not(feature = "rsa"), target_arch = "wasm32"))] @@ -334,10 +438,12 @@ impl TryFrom for PublicKey { #[cfg(test)] mod tests { use super::*; + use crate::PeerId; use base64::prelude::*; use std::str::FromStr; #[test] + #[cfg(feature = "ed25519")] fn keypair_protobuf_roundtrip() { let expected_keypair = Keypair::generate_ed25519(); let expected_peer_id = expected_keypair.public().to_peer_id(); @@ -367,6 +473,7 @@ mod tests { #[test] fn public_key_implements_hash() { + use crate::PublicKey; use std::hash::Hash; fn assert_implements_hash() {} @@ -376,6 +483,7 @@ mod tests { #[test] fn public_key_implements_ord() { + use crate::PublicKey; use std::cmp::Ord; fn assert_implements_ord() {} diff --git a/identity/src/keypair_dummy.rs b/identity/src/keypair_dummy.rs new file mode 100644 index 00000000000..4e1bb61f15c --- /dev/null +++ b/identity/src/keypair_dummy.rs @@ -0,0 +1,69 @@ +// Copyright 2023 Protocol Labs. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +use crate::error::{DecodingError, SigningError}; + +#[derive(Debug, Clone)] +pub enum Keypair {} + +impl Keypair { + pub fn sign(&self, _: &[u8]) -> Result, SigningError> { + unreachable!("Can never construct empty enum") + } + + pub fn public(&self) -> PublicKey { + unreachable!("Can never construct empty enum") + } + + pub fn to_protobuf_encoding(&self) -> Result, DecodingError> { + unreachable!("Can never construct empty enum") + } + + pub fn from_protobuf_encoding(_: &[u8]) -> Result { + Err(DecodingError::missing_feature( + "ecdsa|rsa|ed25519|secp256k1", + )) + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] +pub enum PublicKey {} + +impl PublicKey { + #[must_use] + pub fn verify(&self, _: &[u8], _: &[u8]) -> bool { + unreachable!("Can never construct empty enum") + } + + pub fn to_protobuf_encoding(&self) -> Vec { + unreachable!("Can never construct empty enum") + } + + pub fn from_protobuf_encoding(_: &[u8]) -> Result { + Err(DecodingError::missing_feature( + "ecdsa|rsa|ed25519|secp256k1", + )) + } + + #[cfg(feature = "peerid")] + pub fn to_peer_id(&self) -> crate::PeerId { + unreachable!("Can never construct empty enum") + } +} diff --git a/identity/src/lib.rs b/identity/src/lib.rs new file mode 100644 index 00000000000..1f92b904bfe --- /dev/null +++ b/identity/src/lib.rs @@ -0,0 +1,121 @@ +// Copyright 2019 Parity Technologies (UK) Ltd. +// Copyright 2023 Protocol Labs. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +//! A node's network identity keys. +//! +//! Such identity keys can be randomly generated on every startup, +//! but using already existing, fixed keys is usually required. +//! Though libp2p uses other crates (e.g. `ed25519_dalek`) internally, +//! such details are not exposed as part of libp2p's public interface +//! to keep them easily upgradable or replaceable (e.g. to `ed25519_zebra`). +//! Consequently, keys of external ed25519 or secp256k1 crates cannot be +//! directly converted into libp2p network identities. +//! Instead, loading fixed keys must use the standard, thus more portable +//! binary representation of the specific key type +//! (e.g. [ed25519 binary format](https://datatracker.ietf.org/doc/html/rfc8032#section-5.1.5)). +//! All key types have functions to enable conversion to/from their binary representations. + +mod proto { + include!("generated/mod.rs"); + pub use self::keys_proto::*; +} + +#[cfg(feature = "ecdsa")] +pub mod ecdsa; + +#[cfg(feature = "ed25519")] +pub mod ed25519; + +#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] +pub mod rsa; + +#[cfg(feature = "secp256k1")] +pub mod secp256k1; + +mod error; +#[cfg(any( + feature = "ecdsa", + feature = "secp256k1", + feature = "ed25519", + feature = "rsa" +))] +mod keypair; +#[cfg(all( + not(feature = "ecdsa"), + not(feature = "secp256k1"), + not(feature = "ed25519"), + not(feature = "rsa") +))] +#[path = "./keypair_dummy.rs"] +mod keypair; +#[cfg(feature = "peerid")] +mod peer_id; + +#[cfg(any( + feature = "ecdsa", + feature = "secp256k1", + feature = "ed25519", + feature = "rsa" +))] +impl zeroize::Zeroize for proto::PrivateKey { + fn zeroize(&mut self) { + self.Data.zeroize(); + } +} + +#[cfg(any( + feature = "ecdsa", + feature = "secp256k1", + feature = "ed25519", + feature = "rsa" +))] +impl From<&PublicKey> for proto::PublicKey { + fn from(key: &PublicKey) -> Self { + #[allow(deprecated)] + match key { + #[cfg(feature = "ed25519")] + PublicKey::Ed25519(key) => proto::PublicKey { + Type: proto::KeyType::Ed25519, + Data: key.encode().to_vec(), + }, + #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] + PublicKey::Rsa(key) => proto::PublicKey { + Type: proto::KeyType::RSA, + Data: key.encode_x509(), + }, + #[cfg(feature = "secp256k1")] + PublicKey::Secp256k1(key) => proto::PublicKey { + Type: proto::KeyType::Secp256k1, + Data: key.encode().to_vec(), + }, + #[cfg(feature = "ecdsa")] + PublicKey::Ecdsa(key) => proto::PublicKey { + Type: proto::KeyType::ECDSA, + Data: key.encode_der(), + }, + } + } +} + +pub use error::{DecodingError, SigningError}; +pub use keypair::{Keypair, PublicKey}; +#[cfg(feature = "peerid")] +pub use peer_id::{ParseError, PeerId}; diff --git a/core/src/peer_id.rs b/identity/src/peer_id.rs similarity index 92% rename from core/src/peer_id.rs rename to identity/src/peer_id.rs index 014f1fc240d..ae9ffc80c0a 100644 --- a/core/src/peer_id.rs +++ b/identity/src/peer_id.rs @@ -18,9 +18,8 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use crate::PublicKey; use multiaddr::{Multiaddr, Protocol}; -use multihash::{Code, Error, Multihash, MultihashDigest}; +use multihash::{Code, Error, Multihash}; use rand::Rng; use std::{convert::TryFrom, fmt, str::FromStr}; use thiserror::Error; @@ -55,7 +54,9 @@ impl fmt::Display for PeerId { impl PeerId { /// Builds a `PeerId` from a public key. - pub fn from_public_key(key: &PublicKey) -> PeerId { + pub fn from_public_key(key: &crate::keypair::PublicKey) -> PeerId { + use multihash::MultihashDigest as _; + let key_enc = key.to_protobuf_encoding(); let hash_algorithm = if key_enc.len() <= MAX_INLINE_KEY_LENGTH { @@ -126,7 +127,9 @@ impl PeerId { /// /// Returns `None` if this `PeerId`s hash algorithm is not supported when encoding the /// given public key, otherwise `Some` boolean as the result of an equality check. - pub fn is_public_key(&self, public_key: &PublicKey) -> Option { + pub fn is_public_key(&self, public_key: &crate::PublicKey) -> Option { + use multihash::MultihashDigest as _; + let alg = Code::try_from(self.multihash.code()) .expect("Internal multihash is always a valid `Code`"); let enc = public_key.to_protobuf_encoding(); @@ -134,14 +137,14 @@ impl PeerId { } } -impl From for PeerId { - fn from(key: PublicKey) -> PeerId { +impl From for PeerId { + fn from(key: crate::PublicKey) -> PeerId { PeerId::from_public_key(&key) } } -impl From<&PublicKey> for PeerId { - fn from(key: &PublicKey) -> PeerId { +impl From<&crate::PublicKey> for PeerId { + fn from(key: &crate::PublicKey) -> PeerId { PeerId::from_public_key(key) } } @@ -254,25 +257,26 @@ impl FromStr for PeerId { #[cfg(test)] mod tests { - use crate::{identity, PeerId}; + use super::*; + use crate::keypair::Keypair; #[test] fn peer_id_is_public_key() { - let key = identity::Keypair::generate_ed25519().public(); + let key = Keypair::generate_ed25519().public(); let peer_id = key.to_peer_id(); assert_eq!(peer_id.is_public_key(&key), Some(true)); } #[test] fn peer_id_into_bytes_then_from_bytes() { - let peer_id = identity::Keypair::generate_ed25519().public().to_peer_id(); + let peer_id = Keypair::generate_ed25519().public().to_peer_id(); let second = PeerId::from_bytes(&peer_id.to_bytes()).unwrap(); assert_eq!(peer_id, second); } #[test] fn peer_id_to_base58_then_back() { - let peer_id = identity::Keypair::generate_ed25519().public().to_peer_id(); + let peer_id = Keypair::generate_ed25519().public().to_peer_id(); let second: PeerId = peer_id.to_base58().parse().unwrap(); assert_eq!(peer_id, second); } @@ -292,6 +296,7 @@ mod tests { .parse() .unwrap(); + #[allow(deprecated)] let peer_id = PeerId::try_from_multiaddr(&address).unwrap(); assert_eq!( @@ -306,6 +311,7 @@ mod tests { fn no_panic_on_extract_peer_id_from_multi_address_if_not_present() { let address = "/memory/1234".to_string().parse().unwrap(); + #[allow(deprecated)] let maybe_empty = PeerId::try_from_multiaddr(&address); assert!(maybe_empty.is_none()); diff --git a/core/src/identity/rsa.rs b/identity/src/rsa.rs similarity index 100% rename from core/src/identity/rsa.rs rename to identity/src/rsa.rs diff --git a/core/src/identity/secp256k1.rs b/identity/src/secp256k1.rs similarity index 100% rename from core/src/identity/secp256k1.rs rename to identity/src/secp256k1.rs diff --git a/core/src/identity/test/rsa-2048.pk8 b/identity/src/test/rsa-2048.pk8 similarity index 100% rename from core/src/identity/test/rsa-2048.pk8 rename to identity/src/test/rsa-2048.pk8 diff --git a/core/src/identity/test/rsa-3072.pk8 b/identity/src/test/rsa-3072.pk8 similarity index 100% rename from core/src/identity/test/rsa-3072.pk8 rename to identity/src/test/rsa-3072.pk8 diff --git a/core/src/identity/test/rsa-4096.pk8 b/identity/src/test/rsa-4096.pk8 similarity index 100% rename from core/src/identity/test/rsa-4096.pk8 rename to identity/src/test/rsa-4096.pk8 diff --git a/identity/tests/keypair_api.rs b/identity/tests/keypair_api.rs new file mode 100644 index 00000000000..c1102278a63 --- /dev/null +++ b/identity/tests/keypair_api.rs @@ -0,0 +1,13 @@ +use libp2p_identity::Keypair; + +#[test] +fn calling_keypair_api() { + let _ = Keypair::from_protobuf_encoding(&[]); +} + +#[allow(dead_code)] +fn using_keypair(kp: Keypair) { + let _ = kp.to_protobuf_encoding(); + let _ = kp.sign(&[]); + let _ = kp.public(); +} diff --git a/core/tests/serde.rs b/identity/tests/serde.rs similarity index 98% rename from core/tests/serde.rs rename to identity/tests/serde.rs index 35796902dd1..b0987bb9ced 100644 --- a/core/tests/serde.rs +++ b/identity/tests/serde.rs @@ -2,7 +2,7 @@ use std::str::FromStr; -use libp2p_core::PeerId; +use libp2p_identity::PeerId; #[test] pub fn serialize_peer_id_json() { diff --git a/libp2p/CHANGELOG.md b/libp2p/CHANGELOG.md index 49c4f1f5574..416ecfdb8fd 100644 --- a/libp2p/CHANGELOG.md +++ b/libp2p/CHANGELOG.md @@ -2,6 +2,13 @@ - Depend on `libp2p-tls` `v0.1.0`. +- Introduce `ed25519` feature. + For backwards-compatibility, the `ed25519` identity keys are still available without activating this feature. + However, going forward, you should explicitly activate it to avoid compile errors going forward. + See [PR 3350]. + +[PR 3350]: https://github.com/libp2p/rust-libp2p/pull/3350 + # 0.51.0 - Enable `NetworkBehaviour`s to manage connections. diff --git a/libp2p/Cargo.toml b/libp2p/Cargo.toml index af21df20860..83e97d1dbd2 100644 --- a/libp2p/Cargo.toml +++ b/libp2p/Cargo.toml @@ -18,10 +18,12 @@ full = [ "deflate", "dns", "ecdsa", + "ed25519", "floodsub", "gossipsub", "identify", "kad", + "macros", "mdns", "metrics", "mplex", @@ -30,7 +32,6 @@ full = [ "plaintext", "pnet", "quic", - "macros", "relay", "rendezvous", "request-response", @@ -54,7 +55,8 @@ autonat = ["dep:libp2p-autonat"] dcutr = ["dep:libp2p-dcutr", "libp2p-metrics?/dcutr"] deflate = ["dep:libp2p-deflate"] dns = ["dep:libp2p-dns"] -ecdsa = ["libp2p-core/ecdsa"] +ecdsa = ["libp2p-identity/ecdsa"] +ed25519 = ["libp2p-identity/ed25519"] floodsub = ["dep:libp2p-floodsub"] gossipsub = ["dep:libp2p-gossipsub", "libp2p-metrics?/gossipsub"] identify = ["dep:libp2p-identify", "libp2p-metrics?/identify"] @@ -71,8 +73,8 @@ quic = ["dep:libp2p-quic"] relay = ["dep:libp2p-relay", "libp2p-metrics?/relay"] rendezvous = ["dep:libp2p-rendezvous"] request-response = ["dep:libp2p-request-response"] -rsa = ["libp2p-core/rsa"] -secp256k1 = ["libp2p-core/secp256k1"] +rsa = ["libp2p-identity/rsa"] +secp256k1 = ["libp2p-identity/secp256k1"] serde = ["libp2p-core/serde", "libp2p-kad?/serde", "libp2p-gossipsub?/serde"] tcp = ["dep:libp2p-tcp"] tls = ["dep:libp2p-tls"] @@ -97,6 +99,7 @@ libp2p-core = { version = "0.39.0", path = "../core" } libp2p-dcutr = { version = "0.9.0", path = "../protocols/dcutr", optional = true } libp2p-floodsub = { version = "0.42.0", path = "../protocols/floodsub", optional = true } libp2p-identify = { version = "0.42.0", path = "../protocols/identify", optional = true } +libp2p-identity = { version = "0.1.0", path = "../identity" } libp2p-kad = { version = "0.43.0", path = "../protocols/kad", optional = true } libp2p-metrics = { version = "0.12.0", path = "../misc/metrics", optional = true } libp2p-mplex = { version = "0.39.0", path = "../muxers/mplex", optional = true } diff --git a/libp2p/src/lib.rs b/libp2p/src/lib.rs index 1055a726cea..5a58b149e97 100644 --- a/libp2p/src/lib.rs +++ b/libp2p/src/lib.rs @@ -147,14 +147,15 @@ pub mod bandwidth; pub mod tutorials; pub use self::core::{ - identity, transport::TransportError, upgrade::{InboundUpgrade, InboundUpgradeExt, OutboundUpgrade, OutboundUpgradeExt}, - PeerId, Transport, + Transport, }; pub use self::multiaddr::{multiaddr as build_multiaddr, Multiaddr}; pub use self::swarm::Swarm; pub use self::transport_ext::TransportExt; +pub use libp2p_identity as identity; +pub use libp2p_identity::PeerId; /// Builds a `Transport` based on TCP/IP that supports the most commonly-used features of libp2p: /// diff --git a/libp2p/src/transport_ext.rs b/libp2p/src/transport_ext.rs index 2a4c30f17e3..e66d7395a5c 100644 --- a/libp2p/src/transport_ext.rs +++ b/libp2p/src/transport_ext.rs @@ -23,12 +23,12 @@ use crate::core::{ muxing::{StreamMuxer, StreamMuxerBox}, transport::Boxed, - PeerId, }; use crate::{ bandwidth::{BandwidthLogging, BandwidthSinks}, Transport, }; +use libp2p_identity::PeerId; use std::sync::Arc; /// Trait automatically implemented on all objects that implement `Transport`. Provides some diff --git a/misc/keygen/Cargo.toml b/misc/keygen/Cargo.toml index 6e661d28470..e4e0795a71d 100644 --- a/misc/keygen/Cargo.toml +++ b/misc/keygen/Cargo.toml @@ -16,3 +16,4 @@ serde = { version = "1.0.136", features = ["derive"] } serde_json = "1.0.94" libp2p-core = { version = "0.39.0", path = "../../core" } base64 = "0.21.0" +libp2p-identity = { version = "0.1.0", path = "../../identity" } diff --git a/misc/keygen/src/config.rs b/misc/keygen/src/config.rs index cfbcbd5a98f..30ec8f8324e 100644 --- a/misc/keygen/src/config.rs +++ b/misc/keygen/src/config.rs @@ -3,8 +3,8 @@ use serde::{Deserialize, Serialize}; use std::error::Error; use std::path::Path; -use libp2p_core::identity::Keypair; -use libp2p_core::PeerId; +use libp2p_identity::Keypair; +use libp2p_identity::PeerId; #[derive(Clone, Serialize, Deserialize)] #[serde(rename_all = "PascalCase")] diff --git a/misc/keygen/src/main.rs b/misc/keygen/src/main.rs index e5681922460..64d98005369 100644 --- a/misc/keygen/src/main.rs +++ b/misc/keygen/src/main.rs @@ -8,8 +8,8 @@ use std::thread; mod config; use clap::Parser; -use libp2p_core::identity::{self, ed25519}; -use libp2p_core::PeerId; +use libp2p_identity as identity; +use libp2p_identity::PeerId; use zeroize::Zeroizing; #[derive(Debug, Parser)] @@ -94,19 +94,18 @@ fn main() -> Result<(), Box> { let tx = tx.clone(); thread::spawn(move || loop { - let keypair = ed25519::Keypair::generate(); - let peer_id = identity::PublicKey::Ed25519(keypair.public()).to_peer_id(); + let keypair = identity::Keypair::generate_ed25519(); + let peer_id = keypair.public().to_peer_id(); let base58 = peer_id.to_base58(); if base58[8..].starts_with(&prefix) { - tx.send((peer_id, identity::Keypair::Ed25519(keypair))) - .expect("to send"); + tx.send((peer_id, keypair)).expect("to send"); } }); } rx.recv().expect("to recv") } else { - let keypair = identity::Keypair::Ed25519(ed25519::Keypair::generate()); + let keypair = identity::Keypair::generate_ed25519(); (keypair.public().into(), keypair) } } diff --git a/misc/metrics/Cargo.toml b/misc/metrics/Cargo.toml index e51dd368cf5..bf23d3a4d62 100644 --- a/misc/metrics/Cargo.toml +++ b/misc/metrics/Cargo.toml @@ -26,6 +26,7 @@ libp2p-kad = { version = "0.43.0", path = "../../protocols/kad", optional = true libp2p-ping = { version = "0.42.0", path = "../../protocols/ping", optional = true } libp2p-relay = { version = "0.15.0", path = "../../protocols/relay", optional = true } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } +libp2p-identity = { version = "0.1.0", path = "../../identity" } prometheus-client = "0.19.0" [target.'cfg(not(target_os = "unknown"))'.dependencies] diff --git a/misc/metrics/examples/metrics/main.rs b/misc/metrics/examples/metrics/main.rs index 22c3bd2f0a1..5e974ff0cc7 100644 --- a/misc/metrics/examples/metrics/main.rs +++ b/misc/metrics/examples/metrics/main.rs @@ -51,8 +51,10 @@ use env_logger::Env; use futures::executor::block_on; use futures::stream::StreamExt; -use libp2p_core::{identity, upgrade::Version, Multiaddr, PeerId, Transport}; +use libp2p_core::{upgrade::Version, Multiaddr, Transport}; use libp2p_identify as identify; +use libp2p_identity as identity; +use libp2p_identity::PeerId; use libp2p_metrics::{Metrics, Recorder}; use libp2p_noise as noise; use libp2p_ping as ping; diff --git a/misc/metrics/src/identify.rs b/misc/metrics/src/identify.rs index 4ba0da76b04..e93620b4fef 100644 --- a/misc/metrics/src/identify.rs +++ b/misc/metrics/src/identify.rs @@ -19,7 +19,7 @@ // DEALINGS IN THE SOFTWARE. use crate::protocol_stack; -use libp2p_core::PeerId; +use libp2p_identity::PeerId; use prometheus_client::encoding::{EncodeLabelSet, EncodeMetric, MetricEncoder}; use prometheus_client::metrics::counter::Counter; use prometheus_client::metrics::family::Family; diff --git a/misc/multistream-select/Cargo.toml b/misc/multistream-select/Cargo.toml index ef24c98e77c..c364b33ebea 100644 --- a/misc/multistream-select/Cargo.toml +++ b/misc/multistream-select/Cargo.toml @@ -25,6 +25,7 @@ libp2p-core = { path = "../../core" } libp2p-mplex = { path = "../../muxers/mplex" } libp2p-plaintext = { path = "../../transports/plaintext" } libp2p-swarm = { path = "../../swarm", features = ["async-std"] } +libp2p-identity = { path = "../../identity", features = ["ed25519"] } quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" } rand = "0.8" rw-stream-sink = { version = "0.3.0", path = "../../misc/rw-stream-sink" } diff --git a/misc/multistream-select/tests/transport.rs b/misc/multistream-select/tests/transport.rs index 77fcc1ca4ca..f5eafbf9e3d 100644 --- a/misc/multistream-select/tests/transport.rs +++ b/misc/multistream-select/tests/transport.rs @@ -20,12 +20,13 @@ use futures::{channel::oneshot, prelude::*, ready}; use libp2p_core::{ - identity, multiaddr::Protocol, muxing::StreamMuxerBox, transport::{self, MemoryTransport}, - upgrade, Multiaddr, PeerId, Transport, + upgrade, Multiaddr, Transport, }; +use libp2p_identity as identity; +use libp2p_identity::PeerId; use libp2p_mplex::MplexConfig; use libp2p_plaintext::PlainText2Config; use libp2p_swarm::{dummy, Swarm, SwarmEvent}; diff --git a/muxers/mplex/Cargo.toml b/muxers/mplex/Cargo.toml index 50c7e8239cb..2fac5201e69 100644 --- a/muxers/mplex/Cargo.toml +++ b/muxers/mplex/Cargo.toml @@ -15,6 +15,7 @@ bytes = "1" futures = "0.3.26" asynchronous-codec = "0.6" libp2p-core = { version = "0.39.0", path = "../../core" } +libp2p-identity = { version = "0.1.0", path = "../../identity" } log = "0.4" nohash-hasher = "0.2" parking_lot = "0.12" diff --git a/muxers/mplex/benches/split_send_size.rs b/muxers/mplex/benches/split_send_size.rs index 65cc76eed08..56bd934f302 100644 --- a/muxers/mplex/benches/split_send_size.rs +++ b/muxers/mplex/benches/split_send_size.rs @@ -27,9 +27,9 @@ use futures::future::poll_fn; use futures::prelude::*; use futures::{channel::oneshot, future::join}; use libp2p_core::muxing::StreamMuxerExt; -use libp2p_core::{ - identity, multiaddr::multiaddr, muxing, transport, upgrade, Multiaddr, PeerId, Transport, -}; +use libp2p_core::{multiaddr::multiaddr, muxing, transport, upgrade, Multiaddr, Transport}; +use libp2p_identity as identity; +use libp2p_identity::PeerId; use libp2p_mplex as mplex; use libp2p_plaintext::PlainText2Config; use std::pin::Pin; diff --git a/protocols/autonat/Cargo.toml b/protocols/autonat/Cargo.toml index 4c067634c9a..7ddf5688f01 100644 --- a/protocols/autonat/Cargo.toml +++ b/protocols/autonat/Cargo.toml @@ -18,6 +18,7 @@ instant = "0.1" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } libp2p-request-response = { version = "0.24.0", path = "../request-response" } +libp2p-identity = { version = "0.1.0", path = "../../identity" } log = "0.4" rand = "0.8" quick-protobuf = "0.8" diff --git a/protocols/autonat/examples/autonat_client.rs b/protocols/autonat/examples/autonat_client.rs index d2a7b2dee2f..4608937954a 100644 --- a/protocols/autonat/examples/autonat_client.rs +++ b/protocols/autonat/examples/autonat_client.rs @@ -33,8 +33,10 @@ use clap::Parser; use futures::prelude::*; use libp2p_autonat as autonat; use libp2p_core::multiaddr::Protocol; -use libp2p_core::{identity, upgrade::Version, Multiaddr, PeerId, Transport}; +use libp2p_core::{upgrade::Version, Multiaddr, Transport}; use libp2p_identify as identify; +use libp2p_identity as identity; +use libp2p_identity::PeerId; use libp2p_noise as noise; use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmEvent}; use libp2p_tcp as tcp; diff --git a/protocols/autonat/examples/autonat_server.rs b/protocols/autonat/examples/autonat_server.rs index 8163826c830..d3f7fa5957b 100644 --- a/protocols/autonat/examples/autonat_server.rs +++ b/protocols/autonat/examples/autonat_server.rs @@ -29,8 +29,10 @@ use clap::Parser; use futures::prelude::*; use libp2p_autonat as autonat; -use libp2p_core::{identity, multiaddr::Protocol, upgrade::Version, Multiaddr, PeerId, Transport}; +use libp2p_core::{multiaddr::Protocol, upgrade::Version, Multiaddr, Transport}; use libp2p_identify as identify; +use libp2p_identity as identity; +use libp2p_identity::PeerId; use libp2p_noise as noise; use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmEvent}; use libp2p_tcp as tcp; diff --git a/protocols/autonat/src/behaviour.rs b/protocols/autonat/src/behaviour.rs index 8e97e6395a7..47f15b8def6 100644 --- a/protocols/autonat/src/behaviour.rs +++ b/protocols/autonat/src/behaviour.rs @@ -28,7 +28,8 @@ use as_server::AsServer; pub use as_server::{InboundProbeError, InboundProbeEvent}; use futures_timer::Delay; use instant::Instant; -use libp2p_core::{multiaddr::Protocol, ConnectedPoint, Endpoint, Multiaddr, PeerId}; +use libp2p_core::{multiaddr::Protocol, ConnectedPoint, Endpoint, Multiaddr}; +use libp2p_identity::PeerId; use libp2p_request_response::{ self as request_response, ProtocolSupport, RequestId, ResponseChannel, }; diff --git a/protocols/autonat/src/behaviour/as_client.rs b/protocols/autonat/src/behaviour/as_client.rs index 1018bebd84b..2ab66f8bffc 100644 --- a/protocols/autonat/src/behaviour/as_client.rs +++ b/protocols/autonat/src/behaviour/as_client.rs @@ -27,7 +27,8 @@ use super::{ use futures::FutureExt; use futures_timer::Delay; use instant::Instant; -use libp2p_core::{Multiaddr, PeerId}; +use libp2p_core::Multiaddr; +use libp2p_identity::PeerId; use libp2p_request_response::{self as request_response, OutboundFailure, RequestId}; use libp2p_swarm::{ AddressScore, ConnectionId, ExternalAddresses, ListenAddresses, NetworkBehaviourAction, diff --git a/protocols/autonat/src/behaviour/as_server.rs b/protocols/autonat/src/behaviour/as_server.rs index ec38678e4f5..69f0474e621 100644 --- a/protocols/autonat/src/behaviour/as_server.rs +++ b/protocols/autonat/src/behaviour/as_server.rs @@ -23,7 +23,8 @@ use super::{ ResponseError, }; use instant::Instant; -use libp2p_core::{multiaddr::Protocol, Multiaddr, PeerId}; +use libp2p_core::{multiaddr::Protocol, Multiaddr}; +use libp2p_identity::PeerId; use libp2p_request_response::{ self as request_response, InboundFailure, RequestId, ResponseChannel, }; diff --git a/protocols/autonat/src/protocol.rs b/protocols/autonat/src/protocol.rs index 2bee14200d1..82e448cda24 100644 --- a/protocols/autonat/src/protocol.rs +++ b/protocols/autonat/src/protocol.rs @@ -21,7 +21,8 @@ use crate::proto; use async_trait::async_trait; use futures::io::{AsyncRead, AsyncWrite, AsyncWriteExt}; -use libp2p_core::{upgrade, Multiaddr, PeerId}; +use libp2p_core::{upgrade, Multiaddr}; +use libp2p_identity::PeerId; use libp2p_request_response::{self as request_response, ProtocolName}; use quick_protobuf::{BytesReader, Writer}; use std::{convert::TryFrom, io}; diff --git a/protocols/autonat/tests/test_client.rs b/protocols/autonat/tests/test_client.rs index b8ed029be26..221833c9377 100644 --- a/protocols/autonat/tests/test_client.rs +++ b/protocols/autonat/tests/test_client.rs @@ -22,7 +22,8 @@ use async_std::task::JoinHandle; use libp2p_autonat::{ Behaviour, Config, Event, NatStatus, OutboundProbeError, OutboundProbeEvent, ResponseError, }; -use libp2p_core::{Multiaddr, PeerId}; +use libp2p_core::Multiaddr; +use libp2p_identity::PeerId; use libp2p_swarm::{AddressScore, Swarm, SwarmEvent}; use libp2p_swarm_test::SwarmExt as _; use std::time::Duration; diff --git a/protocols/autonat/tests/test_server.rs b/protocols/autonat/tests/test_server.rs index 72f3465307d..319fd84865d 100644 --- a/protocols/autonat/tests/test_server.rs +++ b/protocols/autonat/tests/test_server.rs @@ -21,7 +21,8 @@ use libp2p_autonat::{ Behaviour, Config, Event, InboundProbeError, InboundProbeEvent, ResponseError, }; -use libp2p_core::{multiaddr::Protocol, ConnectedPoint, Endpoint, Multiaddr, PeerId}; +use libp2p_core::{multiaddr::Protocol, ConnectedPoint, Endpoint, Multiaddr}; +use libp2p_identity::PeerId; use libp2p_swarm::DialError; use libp2p_swarm::{AddressScore, Swarm, SwarmEvent}; use libp2p_swarm_test::SwarmExt as _; diff --git a/protocols/dcutr/Cargo.toml b/protocols/dcutr/Cargo.toml index f3ce00ecea9..723ce56a8b7 100644 --- a/protocols/dcutr/Cargo.toml +++ b/protocols/dcutr/Cargo.toml @@ -18,6 +18,7 @@ futures-timer = "3.0" instant = "0.1.11" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } +libp2p-identity = { version = "0.1.0", path = "../../identity" } log = "0.4" quick-protobuf = "0.8" quick-protobuf-codec = { version = "0.1", path = "../../misc/quick-protobuf-codec" } diff --git a/protocols/dcutr/src/behaviour_impl.rs b/protocols/dcutr/src/behaviour_impl.rs index f8edc5930f3..3b2f287c642 100644 --- a/protocols/dcutr/src/behaviour_impl.rs +++ b/protocols/dcutr/src/behaviour_impl.rs @@ -24,7 +24,8 @@ use crate::handler; use either::Either; use libp2p_core::connection::ConnectedPoint; use libp2p_core::multiaddr::Protocol; -use libp2p_core::{Endpoint, Multiaddr, PeerId}; +use libp2p_core::{Endpoint, Multiaddr}; +use libp2p_identity::PeerId; use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm}; use libp2p_swarm::dial_opts::{self, DialOpts}; use libp2p_swarm::{dummy, ConnectionDenied, ConnectionId, THandler, THandlerOutEvent}; diff --git a/protocols/dcutr/tests/lib.rs b/protocols/dcutr/tests/lib.rs index 2164f59e0da..b48fd2e451c 100644 --- a/protocols/dcutr/tests/lib.rs +++ b/protocols/dcutr/tests/lib.rs @@ -21,8 +21,9 @@ use libp2p_core::multiaddr::{Multiaddr, Protocol}; use libp2p_core::transport::upgrade::Version; use libp2p_core::transport::{MemoryTransport, Transport}; -use libp2p_core::{identity, PeerId}; use libp2p_dcutr as dcutr; +use libp2p_identity as identity; +use libp2p_identity::PeerId; use libp2p_plaintext::PlainText2Config; use libp2p_relay as relay; use libp2p_swarm::{NetworkBehaviour, Swarm, SwarmEvent}; diff --git a/protocols/floodsub/Cargo.toml b/protocols/floodsub/Cargo.toml index e616791646c..1314faa9495 100644 --- a/protocols/floodsub/Cargo.toml +++ b/protocols/floodsub/Cargo.toml @@ -17,6 +17,7 @@ fnv = "1.0" futures = "0.3.26" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } +libp2p-identity = { version = "0.1.0", path = "../../identity" } log = "0.4" quick-protobuf = "0.8" quick-protobuf-codec = { version = "0.1", path = "../../misc/quick-protobuf-codec" } diff --git a/protocols/floodsub/src/layer.rs b/protocols/floodsub/src/layer.rs index 769bf7dfcef..ff29f27b160 100644 --- a/protocols/floodsub/src/layer.rs +++ b/protocols/floodsub/src/layer.rs @@ -26,7 +26,8 @@ use crate::topic::Topic; use crate::FloodsubConfig; use cuckoofilter::{CuckooError, CuckooFilter}; use fnv::FnvHashSet; -use libp2p_core::{Endpoint, Multiaddr, PeerId}; +use libp2p_core::{Endpoint, Multiaddr}; +use libp2p_identity::PeerId; use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, FromSwarm}; use libp2p_swarm::{ dial_opts::DialOpts, ConnectionDenied, ConnectionId, NetworkBehaviour, NetworkBehaviourAction, diff --git a/protocols/floodsub/src/lib.rs b/protocols/floodsub/src/lib.rs index c0d1327f2df..6bd4dfac9bf 100644 --- a/protocols/floodsub/src/lib.rs +++ b/protocols/floodsub/src/lib.rs @@ -22,7 +22,7 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -use libp2p_core::PeerId; +use libp2p_identity::PeerId; pub mod protocol; diff --git a/protocols/floodsub/src/protocol.rs b/protocols/floodsub/src/protocol.rs index 7a70806606d..7ac584bd2de 100644 --- a/protocols/floodsub/src/protocol.rs +++ b/protocols/floodsub/src/protocol.rs @@ -26,7 +26,8 @@ use futures::{ Future, }; use futures::{SinkExt, StreamExt}; -use libp2p_core::{InboundUpgrade, OutboundUpgrade, PeerId, UpgradeInfo}; +use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; +use libp2p_identity::PeerId; use std::{io, iter, pin::Pin}; const MAX_MESSAGE_LEN_BYTES: usize = 2048; diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index 285871ce9f2..c2e2b9a2ab4 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -13,6 +13,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] libp2p-swarm = { version = "0.42.0", path = "../../swarm" } libp2p-core = { version = "0.39.0", path = "../../core" } +libp2p-identity = { version = "0.1.0", path = "../../identity" } bytes = "1.4" byteorder = "1.3.4" fnv = "1.0.7" diff --git a/protocols/gossipsub/src/backoff.rs b/protocols/gossipsub/src/backoff.rs index 3e902bca4b7..b05d338deff 100644 --- a/protocols/gossipsub/src/backoff.rs +++ b/protocols/gossipsub/src/backoff.rs @@ -20,12 +20,12 @@ //! Data structure for efficiently storing known back-off's when pruning peers. use crate::topic::TopicHash; -use libp2p_core::PeerId; -use std::collections::{ - hash_map::{Entry, HashMap}, - HashSet, -}; -use std::time::Duration; +use libp2p_identity::PeerId; +use std::collections::{ + hash_map::{Entry, HashMap}, + HashSet, +}; +use std::time::Duration; use wasm_timer::Instant; #[derive(Copy, Clone)] diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 44cb6224326..be28285f326 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -34,10 +34,9 @@ use log::{debug, error, trace, warn}; use prometheus_client::registry::Registry; use rand::{seq::SliceRandom, thread_rng}; -use libp2p_core::{ - identity::Keypair, multiaddr::Protocol::Ip4, multiaddr::Protocol::Ip6, Endpoint, Multiaddr, - PeerId, -}; +use libp2p_core::{multiaddr::Protocol::Ip4, multiaddr::Protocol::Ip6, Endpoint, Multiaddr}; +use libp2p_identity::Keypair; +use libp2p_identity::PeerId; use libp2p_swarm::{ behaviour::{AddressChange, ConnectionClosed, ConnectionEstablished, FromSwarm}, dial_opts::DialOpts, diff --git a/protocols/gossipsub/src/behaviour/tests.rs b/protocols/gossipsub/src/behaviour/tests.rs index 6502c5986ec..5413f6dbb89 100644 --- a/protocols/gossipsub/src/behaviour/tests.rs +++ b/protocols/gossipsub/src/behaviour/tests.rs @@ -62,7 +62,7 @@ where F: TopicSubscriptionFilter + Clone + Default + Send + 'static, { pub fn create_network(self) -> (Behaviour, Vec, Vec) { - let keypair = libp2p_core::identity::Keypair::generate_ed25519(); + let keypair = libp2p_identity::Keypair::generate_ed25519(); // create a gossipsub struct let mut gs: Behaviour = Behaviour::new_with_subscription_filter_and_transform( MessageAuthenticity::Signed(keypair), diff --git a/protocols/gossipsub/src/config.rs b/protocols/gossipsub/src/config.rs index 37e7764e077..1f0b23848d6 100644 --- a/protocols/gossipsub/src/config.rs +++ b/protocols/gossipsub/src/config.rs @@ -22,7 +22,7 @@ use std::borrow::Cow; use std::sync::Arc; use std::time::Duration; -use libp2p_core::PeerId; +use libp2p_identity::PeerId; use crate::types::{FastMessageId, Message, MessageId, RawMessage}; diff --git a/protocols/gossipsub/src/gossip_promises.rs b/protocols/gossipsub/src/gossip_promises.rs index bcd29603b1f..a5804c82c01 100644 --- a/protocols/gossipsub/src/gossip_promises.rs +++ b/protocols/gossipsub/src/gossip_promises.rs @@ -21,7 +21,7 @@ use crate::peer_score::RejectReason; use crate::MessageId; use crate::ValidationError; -use libp2p_core::PeerId; +use libp2p_identity::PeerId; use log::debug; use std::collections::HashMap; use wasm_timer::Instant; diff --git a/protocols/gossipsub/src/mcache.rs b/protocols/gossipsub/src/mcache.rs index 01aa6b37269..7fa08a6ac6a 100644 --- a/protocols/gossipsub/src/mcache.rs +++ b/protocols/gossipsub/src/mcache.rs @@ -20,7 +20,7 @@ use crate::topic::TopicHash; use crate::types::{MessageId, RawMessage}; -use libp2p_core::PeerId; +use libp2p_identity::PeerId; use log::{debug, trace}; use std::collections::hash_map::Entry; use std::fmt::Debug; @@ -218,7 +218,7 @@ mod tests { use super::*; use crate::types::RawMessage; use crate::{IdentTopic as Topic, TopicHash}; - use libp2p_core::PeerId; + use libp2p_identity::PeerId; fn gen_testm(x: u64, topic: TopicHash) -> (MessageId, RawMessage) { let default_id = |message: &RawMessage| { diff --git a/protocols/gossipsub/src/peer_score.rs b/protocols/gossipsub/src/peer_score.rs index 94df313d6bb..acf37967d13 100644 --- a/protocols/gossipsub/src/peer_score.rs +++ b/protocols/gossipsub/src/peer_score.rs @@ -24,7 +24,7 @@ use crate::metrics::{Metrics, Penalty}; use crate::time_cache::TimeCache; use crate::{MessageId, TopicHash}; -use libp2p_core::PeerId; +use libp2p_identity::PeerId; use log::{debug, trace, warn}; use std::collections::{hash_map, HashMap, HashSet}; use std::net::IpAddr; diff --git a/protocols/gossipsub/src/protocol.rs b/protocols/gossipsub/src/protocol.rs index 54fe2b510c3..cdd50037ce2 100644 --- a/protocols/gossipsub/src/protocol.rs +++ b/protocols/gossipsub/src/protocol.rs @@ -31,9 +31,8 @@ use byteorder::{BigEndian, ByteOrder}; use bytes::BytesMut; use futures::future; use futures::prelude::*; -use libp2p_core::{ - identity::PublicKey, InboundUpgrade, OutboundUpgrade, PeerId, ProtocolName, UpgradeInfo, -}; +use libp2p_core::{InboundUpgrade, OutboundUpgrade, ProtocolName, UpgradeInfo}; +use libp2p_identity::{PeerId, PublicKey}; use log::{debug, warn}; use quick_protobuf::Writer; use std::pin::Pin; diff --git a/protocols/gossipsub/src/rpc_proto.rs b/protocols/gossipsub/src/rpc_proto.rs index 5d198f2f575..470475070b9 100644 --- a/protocols/gossipsub/src/rpc_proto.rs +++ b/protocols/gossipsub/src/rpc_proto.rs @@ -27,7 +27,7 @@ pub mod proto { mod test { use crate::rpc_proto::proto::compat; use crate::IdentTopic as Topic; - use libp2p_core::PeerId; + use libp2p_identity::PeerId; use quick_protobuf::{BytesReader, MessageRead, MessageWrite, Writer}; use rand::Rng; diff --git a/protocols/gossipsub/src/types.rs b/protocols/gossipsub/src/types.rs index 5a3f54752da..ae9b5a09f35 100644 --- a/protocols/gossipsub/src/types.rs +++ b/protocols/gossipsub/src/types.rs @@ -20,7 +20,7 @@ //! A collection of types using the Gossipsub system. use crate::TopicHash; -use libp2p_core::PeerId; +use libp2p_identity::PeerId; use libp2p_swarm::ConnectionId; use prometheus_client::encoding::EncodeLabelValue; use quick_protobuf::MessageWrite; diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index c7b62354520..9c0b904a6d7 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -16,6 +16,7 @@ futures = "0.3.26" futures-timer = "3.0.2" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } +libp2p-identity = { version = "0.1.0", path = "../../identity" } log = "0.4.1" lru = "0.9.0" quick-protobuf-codec = { version = "0.1", path = "../../misc/quick-protobuf-codec" } diff --git a/protocols/identify/src/behaviour.rs b/protocols/identify/src/behaviour.rs index 22e50d1d3f5..1447768ecb2 100644 --- a/protocols/identify/src/behaviour.rs +++ b/protocols/identify/src/behaviour.rs @@ -20,7 +20,9 @@ use crate::handler::{self, Handler, InEvent}; use crate::protocol::{Info, Protocol, UpgradeError}; -use libp2p_core::{multiaddr, ConnectedPoint, Endpoint, Multiaddr, PeerId, PublicKey}; +use libp2p_core::{multiaddr, ConnectedPoint, Endpoint, Multiaddr}; +use libp2p_identity::PeerId; +use libp2p_identity::PublicKey; use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm}; use libp2p_swarm::{ dial_opts::DialOpts, AddressScore, ConnectionDenied, ConnectionHandlerUpgrErr, DialError, @@ -559,7 +561,9 @@ mod tests { use super::*; use futures::pin_mut; use futures::prelude::*; - use libp2p_core::{identity, muxing::StreamMuxerBox, transport, upgrade, PeerId, Transport}; + use libp2p_core::{muxing::StreamMuxerBox, transport, upgrade, Transport}; + use libp2p_identity as identity; + use libp2p_identity::PeerId; use libp2p_mplex::MplexConfig; use libp2p_noise as noise; use libp2p_swarm::{Swarm, SwarmEvent}; diff --git a/protocols/identify/src/handler.rs b/protocols/identify/src/handler.rs index 2aa8cf34f86..c0bd9d928eb 100644 --- a/protocols/identify/src/handler.rs +++ b/protocols/identify/src/handler.rs @@ -27,7 +27,9 @@ use futures::prelude::*; use futures::stream::FuturesUnordered; use futures_timer::Delay; use libp2p_core::upgrade::SelectUpgrade; -use libp2p_core::{Multiaddr, PeerId, PublicKey}; +use libp2p_core::Multiaddr; +use libp2p_identity::PeerId; +use libp2p_identity::PublicKey; use libp2p_swarm::handler::{ ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, }; diff --git a/protocols/identify/src/protocol.rs b/protocols/identify/src/protocol.rs index e2271324e1b..51e530291dc 100644 --- a/protocols/identify/src/protocol.rs +++ b/protocols/identify/src/protocol.rs @@ -22,10 +22,12 @@ use crate::proto; use asynchronous_codec::{FramedRead, FramedWrite}; use futures::{future::BoxFuture, prelude::*}; use libp2p_core::{ - identity, multiaddr, + multiaddr, upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}, - Multiaddr, PublicKey, + Multiaddr, }; +use libp2p_identity as identity; +use libp2p_identity::PublicKey; use libp2p_swarm::ConnectionId; use log::{debug, trace}; use std::convert::TryFrom; @@ -266,7 +268,7 @@ pub enum UpgradeError { #[error("Failed decoding multiaddr")] Multiaddr(#[from] multiaddr::Error), #[error("Failed decoding public key")] - PublicKey(#[from] identity::error::DecodingError), + PublicKey(#[from] identity::DecodingError), } #[cfg(test)] @@ -274,10 +276,10 @@ mod tests { use super::*; use futures::channel::oneshot; use libp2p_core::{ - identity, upgrade::{self, apply_inbound, apply_outbound}, Transport, }; + use libp2p_identity as identity; use libp2p_tcp as tcp; #[test] diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index 117501e638c..0604a520d64 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -21,6 +21,7 @@ log = "0.4" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } quick-protobuf = "0.8" +libp2p-identity = { version = "0.1.0", path = "../../identity" } rand = "0.8" sha2 = "0.10.0" smallvec = "1.6.1" diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index 9d3d9014538..6c13bf46403 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -39,7 +39,8 @@ use crate::record::{ use crate::K_VALUE; use fnv::{FnvHashMap, FnvHashSet}; use instant::Instant; -use libp2p_core::{ConnectedPoint, Endpoint, Multiaddr, PeerId}; +use libp2p_core::{ConnectedPoint, Endpoint, Multiaddr}; +use libp2p_identity::PeerId; use libp2p_swarm::behaviour::{ AddressChange, ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm, }; diff --git a/protocols/kad/src/behaviour/test.rs b/protocols/kad/src/behaviour/test.rs index 2f51eaef52d..fdbf55680ec 100644 --- a/protocols/kad/src/behaviour/test.rs +++ b/protocols/kad/src/behaviour/test.rs @@ -29,12 +29,13 @@ use futures::{executor::block_on, future::poll_fn, prelude::*}; use futures_timer::Delay; use libp2p_core::{ connection::ConnectedPoint, - identity, multiaddr::{multiaddr, Multiaddr, Protocol}, multihash::{Code, Multihash, MultihashDigest}, transport::MemoryTransport, - upgrade, Endpoint, PeerId, Transport, + upgrade, Endpoint, Transport, }; +use libp2p_identity as identity; +use libp2p_identity::PeerId; use libp2p_noise as noise; use libp2p_swarm::{ConnectionId, Swarm, SwarmEvent}; use libp2p_yamux as yamux; diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index 27938c1f477..22c1253dd1e 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -27,7 +27,8 @@ use either::Either; use futures::prelude::*; use futures::stream::SelectAll; use instant::Instant; -use libp2p_core::{upgrade, ConnectedPoint, PeerId}; +use libp2p_core::{upgrade, ConnectedPoint}; +use libp2p_identity::PeerId; use libp2p_swarm::handler::{ ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, }; diff --git a/protocols/kad/src/jobs.rs b/protocols/kad/src/jobs.rs index 3d5e3f98d16..94c4fe43eef 100644 --- a/protocols/kad/src/jobs.rs +++ b/protocols/kad/src/jobs.rs @@ -65,7 +65,7 @@ use crate::record::{self, store::RecordStore, ProviderRecord, Record}; use futures::prelude::*; use futures_timer::Delay; use instant::Instant; -use libp2p_core::PeerId; +use libp2p_identity::PeerId; use std::collections::HashSet; use std::pin::Pin; use std::task::{Context, Poll}; diff --git a/protocols/kad/src/kbucket.rs b/protocols/kad/src/kbucket.rs index cef1e70242b..5288be44786 100644 --- a/protocols/kad/src/kbucket.rs +++ b/protocols/kad/src/kbucket.rs @@ -522,7 +522,7 @@ where #[cfg(test)] mod tests { use super::*; - use libp2p_core::PeerId; + use libp2p_identity::PeerId; use quickcheck::*; type TestTable = KBucketsTable; diff --git a/protocols/kad/src/kbucket/bucket.rs b/protocols/kad/src/kbucket/bucket.rs index c03b011de10..1f560676608 100644 --- a/protocols/kad/src/kbucket/bucket.rs +++ b/protocols/kad/src/kbucket/bucket.rs @@ -435,7 +435,7 @@ where #[cfg(test)] mod tests { use super::*; - use libp2p_core::PeerId; + use libp2p_identity::PeerId; use quickcheck::*; use std::collections::VecDeque; diff --git a/protocols/kad/src/kbucket/key.rs b/protocols/kad/src/kbucket/key.rs index 62401c46095..c2ea38a1406 100644 --- a/protocols/kad/src/kbucket/key.rs +++ b/protocols/kad/src/kbucket/key.rs @@ -19,7 +19,8 @@ // DEALINGS IN THE SOFTWARE. use crate::record; -use libp2p_core::{multihash::Multihash, PeerId}; +use libp2p_core::multihash::Multihash; +use libp2p_identity::PeerId; use sha2::digest::generic_array::{typenum::U32, GenericArray}; use sha2::{Digest, Sha256}; use std::borrow::Borrow; diff --git a/protocols/kad/src/protocol.rs b/protocols/kad/src/protocol.rs index 47d7c33e496..969d189325b 100644 --- a/protocols/kad/src/protocol.rs +++ b/protocols/kad/src/protocol.rs @@ -34,7 +34,8 @@ use codec::UviBytes; use futures::prelude::*; use instant::Instant; use libp2p_core::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; -use libp2p_core::{Multiaddr, PeerId}; +use libp2p_core::Multiaddr; +use libp2p_identity::PeerId; use quick_protobuf::{BytesReader, Writer}; use std::{borrow::Cow, convert::TryFrom, time::Duration}; use std::{io, iter}; diff --git a/protocols/kad/src/query.rs b/protocols/kad/src/query.rs index 708c758464f..e30235c9682 100644 --- a/protocols/kad/src/query.rs +++ b/protocols/kad/src/query.rs @@ -31,7 +31,7 @@ use crate::{ALPHA_VALUE, K_VALUE}; use either::Either; use fnv::FnvHashMap; use instant::Instant; -use libp2p_core::PeerId; +use libp2p_identity::PeerId; use std::{num::NonZeroUsize, time::Duration}; /// A `QueryPool` provides an aggregate state machine for driving `Query`s to completion. diff --git a/protocols/kad/src/query/peers.rs b/protocols/kad/src/query/peers.rs index 7a177a494cf..824fb658e7c 100644 --- a/protocols/kad/src/query/peers.rs +++ b/protocols/kad/src/query/peers.rs @@ -41,7 +41,7 @@ pub mod closest; pub mod fixed; -use libp2p_core::PeerId; +use libp2p_identity::PeerId; use std::borrow::Cow; /// The state of a peer iterator. diff --git a/protocols/kad/src/query/peers/closest.rs b/protocols/kad/src/query/peers/closest.rs index d56f6ce5160..0f84ee5f667 100644 --- a/protocols/kad/src/query/peers/closest.rs +++ b/protocols/kad/src/query/peers/closest.rs @@ -23,7 +23,7 @@ use super::*; use crate::kbucket::{Distance, Key, KeyBytes}; use crate::{ALPHA_VALUE, K_VALUE}; use instant::Instant; -use libp2p_core::PeerId; +use libp2p_identity::PeerId; use std::collections::btree_map::{BTreeMap, Entry}; use std::{iter::FromIterator, num::NonZeroUsize, time::Duration}; @@ -475,10 +475,8 @@ enum PeerState { #[cfg(test)] mod tests { use super::*; - use libp2p_core::{ - multihash::{Code, Multihash}, - PeerId, - }; + use libp2p_core::multihash::{Code, Multihash}; + use libp2p_identity::PeerId; use quickcheck::*; use rand::{rngs::StdRng, Rng, SeedableRng}; use std::{iter, time::Duration}; diff --git a/protocols/kad/src/query/peers/closest/disjoint.rs b/protocols/kad/src/query/peers/closest/disjoint.rs index d8713bb33d2..cbee599f402 100644 --- a/protocols/kad/src/query/peers/closest/disjoint.rs +++ b/protocols/kad/src/query/peers/closest/disjoint.rs @@ -21,7 +21,7 @@ use super::*; use crate::kbucket::{Key, KeyBytes}; use instant::Instant; -use libp2p_core::PeerId; +use libp2p_identity::PeerId; use std::{ collections::HashMap, iter::{Cycle, Map, Peekable}, diff --git a/protocols/kad/src/query/peers/fixed.rs b/protocols/kad/src/query/peers/fixed.rs index 022a3de6f9f..07ec6cf9f4e 100644 --- a/protocols/kad/src/query/peers/fixed.rs +++ b/protocols/kad/src/query/peers/fixed.rs @@ -21,7 +21,7 @@ use super::*; use fnv::FnvHashMap; -use libp2p_core::PeerId; +use libp2p_identity::PeerId; use std::{collections::hash_map::Entry, num::NonZeroUsize, vec}; /// A peer iterator for a fixed set of peers. diff --git a/protocols/kad/src/record.rs b/protocols/kad/src/record.rs index 0da60e704e9..814d7fa194d 100644 --- a/protocols/kad/src/record.rs +++ b/protocols/kad/src/record.rs @@ -24,7 +24,8 @@ pub mod store; use bytes::Bytes; use instant::Instant; -use libp2p_core::{multihash::Multihash, Multiaddr, PeerId}; +use libp2p_core::{multihash::Multihash, Multiaddr}; +use libp2p_identity::PeerId; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; use std::borrow::Borrow; diff --git a/protocols/kad/src/record/store/memory.rs b/protocols/kad/src/record/store/memory.rs index 87951637889..fdc6316033f 100644 --- a/protocols/kad/src/record/store/memory.rs +++ b/protocols/kad/src/record/store/memory.rs @@ -21,7 +21,7 @@ use super::*; use crate::kbucket; -use libp2p_core::PeerId; +use libp2p_identity::PeerId; use smallvec::SmallVec; use std::borrow::Cow; use std::collections::{hash_map, hash_set, HashMap, HashSet}; diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml index 4e09b217f94..b6ff74f22dd 100644 --- a/protocols/mdns/Cargo.toml +++ b/protocols/mdns/Cargo.toml @@ -17,6 +17,7 @@ futures = "0.3.26" if-watch = "3.0.0" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } +libp2p-identity = { version = "0.1.0", path = "../../identity" } log = "0.4.14" rand = "0.8.3" smallvec = "1.6.1" diff --git a/protocols/mdns/src/behaviour.rs b/protocols/mdns/src/behaviour.rs index f110373fd61..b34a1a73629 100644 --- a/protocols/mdns/src/behaviour.rs +++ b/protocols/mdns/src/behaviour.rs @@ -27,7 +27,8 @@ use crate::behaviour::{socket::AsyncSocket, timer::Builder}; use crate::Config; use futures::Stream; use if_watch::IfEvent; -use libp2p_core::{Endpoint, Multiaddr, PeerId}; +use libp2p_core::{Endpoint, Multiaddr}; +use libp2p_identity::PeerId; use libp2p_swarm::behaviour::FromSwarm; use libp2p_swarm::{ dummy, ConnectionDenied, ConnectionId, ListenAddresses, NetworkBehaviour, diff --git a/protocols/mdns/src/behaviour/iface.rs b/protocols/mdns/src/behaviour/iface.rs index f07e6564a4c..4b5580e0869 100644 --- a/protocols/mdns/src/behaviour/iface.rs +++ b/protocols/mdns/src/behaviour/iface.rs @@ -25,7 +25,8 @@ use self::dns::{build_query, build_query_response, build_service_discovery_respo use self::query::MdnsPacket; use crate::behaviour::{socket::AsyncSocket, timer::Builder}; use crate::Config; -use libp2p_core::{Multiaddr, PeerId}; +use libp2p_core::Multiaddr; +use libp2p_identity::PeerId; use libp2p_swarm::ListenAddresses; use socket2::{Domain, Socket, Type}; use std::{ diff --git a/protocols/mdns/src/behaviour/iface/dns.rs b/protocols/mdns/src/behaviour/iface/dns.rs index 8ea4db49f2d..0e277d65cbe 100644 --- a/protocols/mdns/src/behaviour/iface/dns.rs +++ b/protocols/mdns/src/behaviour/iface/dns.rs @@ -21,7 +21,8 @@ //! (M)DNS encoding and decoding on top of the `dns_parser` library. use crate::{META_QUERY_SERVICE, SERVICE_NAME}; -use libp2p_core::{Multiaddr, PeerId}; +use libp2p_core::Multiaddr; +use libp2p_identity::PeerId; use rand::distributions::Alphanumeric; use rand::{thread_rng, Rng}; use std::{borrow::Cow, cmp, error, fmt, str, time::Duration}; @@ -395,7 +396,7 @@ impl error::Error for MdnsResponseError {} #[cfg(test)] mod tests { use super::*; - use libp2p_core::identity; + use libp2p_identity as identity; use std::time::Duration; use trust_dns_proto::op::Message; diff --git a/protocols/mdns/src/behaviour/iface/query.rs b/protocols/mdns/src/behaviour/iface/query.rs index 7cf22223c41..5eb491dbbf6 100644 --- a/protocols/mdns/src/behaviour/iface/query.rs +++ b/protocols/mdns/src/behaviour/iface/query.rs @@ -23,8 +23,8 @@ use crate::{META_QUERY_SERVICE_FQDN, SERVICE_NAME_FQDN}; use libp2p_core::{ address_translation, multiaddr::{Multiaddr, Protocol}, - PeerId, }; +use libp2p_identity::PeerId; use std::time::Instant; use std::{convert::TryFrom, fmt, net::SocketAddr, str, time::Duration}; use trust_dns_proto::{ diff --git a/protocols/ping/Cargo.toml b/protocols/ping/Cargo.toml index 4990b84b469..c5f2e5f0e99 100644 --- a/protocols/ping/Cargo.toml +++ b/protocols/ping/Cargo.toml @@ -17,6 +17,7 @@ futures-timer = "3.0.2" instant = "0.1.11" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } +libp2p-identity = { version = "0.1.0", path = "../../identity" } log = "0.4.1" rand = "0.8" void = "1.0" diff --git a/protocols/ping/src/lib.rs b/protocols/ping/src/lib.rs index b9016f34aa7..04fab82fc50 100644 --- a/protocols/ping/src/lib.rs +++ b/protocols/ping/src/lib.rs @@ -47,7 +47,8 @@ mod protocol; use handler::Handler; pub use handler::{Config, Failure, Success}; -use libp2p_core::{Endpoint, Multiaddr, PeerId}; +use libp2p_core::{Endpoint, Multiaddr}; +use libp2p_identity::PeerId; use libp2p_swarm::{ behaviour::FromSwarm, ConnectionDenied, ConnectionId, NetworkBehaviour, NetworkBehaviourAction, PollParameters, THandler, THandlerInEvent, THandlerOutEvent, diff --git a/protocols/relay/Cargo.toml b/protocols/relay/Cargo.toml index 60b75c39fc1..6c2b5f15c0b 100644 --- a/protocols/relay/Cargo.toml +++ b/protocols/relay/Cargo.toml @@ -19,6 +19,7 @@ futures-timer = "3" instant = "0.1.11" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } +libp2p-identity = { version = "0.1.0", path = "../../identity" } log = "0.4" quick-protobuf = "0.8" quick-protobuf-codec = { version = "0.1", path = "../../misc/quick-protobuf-codec" } diff --git a/protocols/relay/examples/relay.rs b/protocols/relay/examples/relay.rs index 5d88f1739df..ec5e3be7c39 100644 --- a/protocols/relay/examples/relay.rs +++ b/protocols/relay/examples/relay.rs @@ -24,8 +24,10 @@ use futures::executor::block_on; use futures::stream::StreamExt; use libp2p_core::multiaddr::Protocol; use libp2p_core::upgrade; -use libp2p_core::{identity, Multiaddr, PeerId, Transport}; +use libp2p_core::{Multiaddr, Transport}; use libp2p_identify as identify; +use libp2p_identity as identity; +use libp2p_identity::PeerId; use libp2p_noise as noise; use libp2p_ping as ping; use libp2p_relay as relay; @@ -103,9 +105,7 @@ fn generate_ed25519(secret_key_seed: u8) -> identity::Keypair { let mut bytes = [0u8; 32]; bytes[0] = secret_key_seed; - let secret_key = identity::ed25519::SecretKey::from_bytes(&mut bytes) - .expect("this returns `Err` only if the length is wrong; the length is correct; qed"); - identity::Keypair::Ed25519(secret_key.into()) + identity::Keypair::ed25519_from_bytes(bytes).expect("only errors on wrong length") } #[derive(Debug, Parser)] diff --git a/protocols/relay/src/behaviour.rs b/protocols/relay/src/behaviour.rs index 6a59cf3826c..e8000966738 100644 --- a/protocols/relay/src/behaviour.rs +++ b/protocols/relay/src/behaviour.rs @@ -30,7 +30,8 @@ use crate::protocol::{inbound_hop, outbound_stop}; use either::Either; use instant::Instant; use libp2p_core::multiaddr::Protocol; -use libp2p_core::{ConnectedPoint, Endpoint, Multiaddr, PeerId}; +use libp2p_core::{ConnectedPoint, Endpoint, Multiaddr}; +use libp2p_identity::PeerId; use libp2p_swarm::behaviour::{ConnectionClosed, FromSwarm}; use libp2p_swarm::{ dummy, ConnectionDenied, ConnectionHandlerUpgrErr, ConnectionId, ExternalAddresses, diff --git a/protocols/relay/src/behaviour/handler.rs b/protocols/relay/src/behaviour/handler.rs index 923d322fa2b..3acbda0eff5 100644 --- a/protocols/relay/src/behaviour/handler.rs +++ b/protocols/relay/src/behaviour/handler.rs @@ -30,7 +30,8 @@ use futures::io::AsyncWriteExt; use futures::stream::{FuturesUnordered, StreamExt}; use futures_timer::Delay; use instant::Instant; -use libp2p_core::{upgrade, ConnectedPoint, Multiaddr, PeerId}; +use libp2p_core::{upgrade, ConnectedPoint, Multiaddr}; +use libp2p_identity::PeerId; use libp2p_swarm::handler::{ ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, ListenUpgradeError, diff --git a/protocols/relay/src/behaviour/rate_limiter.rs b/protocols/relay/src/behaviour/rate_limiter.rs index 00d70aa3541..542b23e5c43 100644 --- a/protocols/relay/src/behaviour/rate_limiter.rs +++ b/protocols/relay/src/behaviour/rate_limiter.rs @@ -23,7 +23,7 @@ pub use generic::{ }; use instant::Instant; use libp2p_core::multiaddr::{Multiaddr, Protocol}; -use libp2p_core::PeerId; +use libp2p_identity::PeerId; use std::net::IpAddr; /// Allows rate limiting access to some resource based on the [`PeerId`] and diff --git a/protocols/relay/src/priv_client.rs b/protocols/relay/src/priv_client.rs index f9869832ae7..63140936791 100644 --- a/protocols/relay/src/priv_client.rs +++ b/protocols/relay/src/priv_client.rs @@ -34,7 +34,8 @@ use futures::future::{BoxFuture, FutureExt}; use futures::io::{AsyncRead, AsyncWrite}; use futures::ready; use futures::stream::StreamExt; -use libp2p_core::{Endpoint, Multiaddr, PeerId}; +use libp2p_core::{Endpoint, Multiaddr}; +use libp2p_identity::PeerId; use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, FromSwarm}; use libp2p_swarm::dial_opts::DialOpts; use libp2p_swarm::{ diff --git a/protocols/relay/src/priv_client/handler.rs b/protocols/relay/src/priv_client/handler.rs index 69d89ee1389..3d7bc6c4d1e 100644 --- a/protocols/relay/src/priv_client/handler.rs +++ b/protocols/relay/src/priv_client/handler.rs @@ -29,7 +29,8 @@ use futures::stream::{FuturesUnordered, StreamExt}; use futures_timer::Delay; use instant::Instant; use libp2p_core::multiaddr::Protocol; -use libp2p_core::{upgrade, Multiaddr, PeerId}; +use libp2p_core::{upgrade, Multiaddr}; +use libp2p_identity::PeerId; use libp2p_swarm::handler::{ ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, ListenUpgradeError, diff --git a/protocols/relay/src/priv_client/transport.rs b/protocols/relay/src/priv_client/transport.rs index 6dfc46710f8..6dceefd8661 100644 --- a/protocols/relay/src/priv_client/transport.rs +++ b/protocols/relay/src/priv_client/transport.rs @@ -31,7 +31,7 @@ use futures::stream::SelectAll; use futures::stream::{Stream, StreamExt}; use libp2p_core::multiaddr::{Multiaddr, Protocol}; use libp2p_core::transport::{ListenerId, TransportError, TransportEvent}; -use libp2p_core::PeerId; +use libp2p_identity::PeerId; use std::collections::VecDeque; use std::pin::Pin; use std::task::{Context, Poll}; diff --git a/protocols/relay/src/protocol/inbound_hop.rs b/protocols/relay/src/protocol/inbound_hop.rs index 283ceacc886..485c3ef76bd 100644 --- a/protocols/relay/src/protocol/inbound_hop.rs +++ b/protocols/relay/src/protocol/inbound_hop.rs @@ -24,7 +24,8 @@ use asynchronous_codec::{Framed, FramedParts}; use bytes::Bytes; use futures::{future::BoxFuture, prelude::*}; use instant::{Duration, SystemTime}; -use libp2p_core::{upgrade, Multiaddr, PeerId}; +use libp2p_core::{upgrade, Multiaddr}; +use libp2p_identity::PeerId; use libp2p_swarm::NegotiatedSubstream; use std::convert::TryInto; use std::iter; diff --git a/protocols/relay/src/protocol/inbound_stop.rs b/protocols/relay/src/protocol/inbound_stop.rs index 77152f0b237..67e4cdd5323 100644 --- a/protocols/relay/src/protocol/inbound_stop.rs +++ b/protocols/relay/src/protocol/inbound_stop.rs @@ -23,7 +23,8 @@ use crate::protocol::{self, MAX_MESSAGE_SIZE, STOP_PROTOCOL_NAME}; use asynchronous_codec::{Framed, FramedParts}; use bytes::Bytes; use futures::{future::BoxFuture, prelude::*}; -use libp2p_core::{upgrade, PeerId}; +use libp2p_core::upgrade; +use libp2p_identity::PeerId; use libp2p_swarm::NegotiatedSubstream; use std::iter; use thiserror::Error; diff --git a/protocols/relay/src/protocol/outbound_hop.rs b/protocols/relay/src/protocol/outbound_hop.rs index e1ddda99738..323d0be3b9a 100644 --- a/protocols/relay/src/protocol/outbound_hop.rs +++ b/protocols/relay/src/protocol/outbound_hop.rs @@ -25,7 +25,8 @@ use bytes::Bytes; use futures::{future::BoxFuture, prelude::*}; use futures_timer::Delay; use instant::{Duration, SystemTime}; -use libp2p_core::{upgrade, Multiaddr, PeerId}; +use libp2p_core::{upgrade, Multiaddr}; +use libp2p_identity::PeerId; use libp2p_swarm::NegotiatedSubstream; use std::convert::TryFrom; use std::iter; diff --git a/protocols/relay/src/protocol/outbound_stop.rs b/protocols/relay/src/protocol/outbound_stop.rs index 5302fed65a8..4ba9c6909e1 100644 --- a/protocols/relay/src/protocol/outbound_stop.rs +++ b/protocols/relay/src/protocol/outbound_stop.rs @@ -23,7 +23,8 @@ use crate::protocol::{MAX_MESSAGE_SIZE, STOP_PROTOCOL_NAME}; use asynchronous_codec::{Framed, FramedParts}; use bytes::Bytes; use futures::{future::BoxFuture, prelude::*}; -use libp2p_core::{upgrade, PeerId}; +use libp2p_core::upgrade; +use libp2p_identity::PeerId; use libp2p_swarm::NegotiatedSubstream; use std::convert::TryInto; use std::iter; diff --git a/protocols/relay/src/v2.rs b/protocols/relay/src/v2.rs index bf428684bbc..baaf148f2b5 100644 --- a/protocols/relay/src/v2.rs +++ b/protocols/relay/src/v2.rs @@ -107,7 +107,8 @@ pub mod relay { pub mod rate_limiter { use instant::Instant; - use libp2p_core::{Multiaddr, PeerId}; + use libp2p_core::Multiaddr; + use libp2p_identity::PeerId; #[deprecated( since = "0.15.0", diff --git a/protocols/relay/tests/lib.rs b/protocols/relay/tests/lib.rs index a26d09e6e3b..e09fd7d7255 100644 --- a/protocols/relay/tests/lib.rs +++ b/protocols/relay/tests/lib.rs @@ -27,8 +27,10 @@ use libp2p_core::multiaddr::{Multiaddr, Protocol}; use libp2p_core::muxing::StreamMuxerBox; use libp2p_core::transport::choice::OrTransport; use libp2p_core::transport::{Boxed, MemoryTransport, Transport}; -use libp2p_core::PublicKey; -use libp2p_core::{identity, upgrade, PeerId}; +use libp2p_core::upgrade; +use libp2p_identity as identity; +use libp2p_identity::PeerId; +use libp2p_identity::PublicKey; use libp2p_ping as ping; use libp2p_plaintext::PlainText2Config; use libp2p_relay as relay; diff --git a/protocols/rendezvous/Cargo.toml b/protocols/rendezvous/Cargo.toml index 9fbd98c4fc5..1575c5dd21e 100644 --- a/protocols/rendezvous/Cargo.toml +++ b/protocols/rendezvous/Cargo.toml @@ -18,6 +18,7 @@ futures-timer = "3.0.2" instant = "0.1.11" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } +libp2p-identity = { version = "0.1.0", path = "../../identity" } log = "0.4" quick-protobuf = "0.8" quick-protobuf-codec = { version = "0.1", path = "../../misc/quick-protobuf-codec" } diff --git a/protocols/rendezvous/src/client.rs b/protocols/rendezvous/src/client.rs index 8cb91a71f11..718eee1ed43 100644 --- a/protocols/rendezvous/src/client.rs +++ b/protocols/rendezvous/src/client.rs @@ -28,9 +28,8 @@ use futures::future::FutureExt; use futures::stream::FuturesUnordered; use futures::stream::StreamExt; use instant::Duration; -use libp2p_core::identity::error::SigningError; -use libp2p_core::identity::Keypair; -use libp2p_core::{Endpoint, Multiaddr, PeerId, PeerRecord}; +use libp2p_core::{Endpoint, Multiaddr, PeerRecord}; +use libp2p_identity::{Keypair, PeerId, SigningError}; use libp2p_swarm::behaviour::FromSwarm; use libp2p_swarm::{ CloseConnection, ConnectionDenied, ConnectionId, ExternalAddresses, NetworkBehaviour, diff --git a/protocols/rendezvous/src/server.rs b/protocols/rendezvous/src/server.rs index 2d38d201497..609428bf29e 100644 --- a/protocols/rendezvous/src/server.rs +++ b/protocols/rendezvous/src/server.rs @@ -27,7 +27,8 @@ use futures::future::BoxFuture; use futures::ready; use futures::stream::FuturesUnordered; use futures::{FutureExt, StreamExt}; -use libp2p_core::{Endpoint, Multiaddr, PeerId}; +use libp2p_core::{Endpoint, Multiaddr}; +use libp2p_identity::PeerId; use libp2p_swarm::behaviour::FromSwarm; use libp2p_swarm::{ CloseConnection, ConnectionDenied, ConnectionId, NetworkBehaviour, NetworkBehaviourAction, @@ -527,7 +528,8 @@ mod tests { use instant::SystemTime; use std::option::Option::None; - use libp2p_core::{identity, PeerRecord}; + use libp2p_core::PeerRecord; + use libp2p_identity as identity; use super::*; diff --git a/protocols/rendezvous/tests/rendezvous.rs b/protocols/rendezvous/tests/rendezvous.rs index 154ffe4005c..494f56551d8 100644 --- a/protocols/rendezvous/tests/rendezvous.rs +++ b/protocols/rendezvous/tests/rendezvous.rs @@ -20,7 +20,7 @@ use futures::stream::FuturesUnordered; use futures::StreamExt; -use libp2p_core::identity; +use libp2p_identity as identity; use libp2p_rendezvous as rendezvous; use libp2p_swarm::{DialError, Swarm, SwarmEvent}; use libp2p_swarm_test::SwarmExt; diff --git a/protocols/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index fecf2a3fd41..e10df6b49a4 100644 --- a/protocols/request-response/Cargo.toml +++ b/protocols/request-response/Cargo.toml @@ -16,6 +16,7 @@ futures = "0.3.26" instant = "0.1.11" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } +libp2p-identity = { version = "0.1.0", path = "../../identity" } rand = "0.8" smallvec = "1.6.1" diff --git a/protocols/request-response/src/lib.rs b/protocols/request-response/src/lib.rs index 008a6aa38e9..707be901bba 100644 --- a/protocols/request-response/src/lib.rs +++ b/protocols/request-response/src/lib.rs @@ -70,7 +70,8 @@ pub use handler::ProtocolSupport; use futures::channel::oneshot; use handler::{Handler, RequestProtocol}; -use libp2p_core::{ConnectedPoint, Endpoint, Multiaddr, PeerId}; +use libp2p_core::{ConnectedPoint, Endpoint, Multiaddr}; +use libp2p_identity::PeerId; use libp2p_swarm::{ behaviour::{AddressChange, ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm}, dial_opts::DialOpts, diff --git a/protocols/request-response/tests/ping.rs b/protocols/request-response/tests/ping.rs index 3324684e51b..c69f771dbe0 100644 --- a/protocols/request-response/tests/ping.rs +++ b/protocols/request-response/tests/ping.rs @@ -24,8 +24,9 @@ use async_trait::async_trait; use futures::{prelude::*, AsyncWriteExt}; use libp2p_core::{ upgrade::{read_length_prefixed, write_length_prefixed}, - PeerId, ProtocolName, + ProtocolName, }; +use libp2p_identity::PeerId; use libp2p_request_response as request_response; use libp2p_request_response::ProtocolSupport; use libp2p_swarm::{Swarm, SwarmEvent}; diff --git a/swarm-test/Cargo.toml b/swarm-test/Cargo.toml index f395fe1d2d2..c5525ffe077 100644 --- a/swarm-test/Cargo.toml +++ b/swarm-test/Cargo.toml @@ -10,10 +10,11 @@ publish = false [dependencies] async-trait = "0.1.57" libp2p-core = { path = "../core" } -libp2p-swarm = { path = "../swarm" } -libp2p-yamux = { path = "../muxers/yamux" } +libp2p-identity = { path = "../identity" } libp2p-plaintext = { path = "../transports/plaintext" } +libp2p-swarm = { path = "../swarm" } libp2p-tcp = { path = "../transports/tcp", features = ["async-io"] } +libp2p-yamux = { path = "../muxers/yamux" } futures = "0.3.24" log = "0.4.17" rand = "0.8.5" diff --git a/swarm-test/src/lib.rs b/swarm-test/src/lib.rs index 1acec7ba393..50af3a6f71d 100644 --- a/swarm-test/src/lib.rs +++ b/swarm-test/src/lib.rs @@ -23,8 +23,9 @@ use futures::future::Either; use futures::StreamExt; use libp2p_core::{ identity::Keypair, multiaddr::Protocol, transport::MemoryTransport, upgrade::Version, - Multiaddr, PeerId, Transport, + Multiaddr, Transport, }; +use libp2p_identity::PeerId; use libp2p_plaintext::PlainText2Config; use libp2p_swarm::{ dial_opts::DialOpts, AddressScore, NetworkBehaviour, Swarm, SwarmEvent, THandlerErr, diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 8c6d12e539a..b6194277dfd 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -17,6 +17,7 @@ futures = "0.3.26" futures-timer = "3.0.2" instant = "0.1.11" libp2p-core = { version = "0.39.0", path = "../core" } +libp2p-identity = { version = "0.1.0", path = "../identity" } libp2p-swarm-derive = { version = "0.32.0", path = "../swarm-derive", optional = true } log = "0.4" rand = "0.8" @@ -41,6 +42,7 @@ either = "1.6.0" env_logger = "0.10" futures = "0.3.26" libp2p-identify = { path = "../protocols/identify" } +libp2p-identity = { version = "0.1.0", path = "../identity", features = ["ed25519"] } libp2p-kad = { path = "../protocols/kad" } libp2p-ping = { path = "../protocols/ping" } libp2p-plaintext = { path = "../transports/plaintext" } diff --git a/swarm/src/behaviour.rs b/swarm/src/behaviour.rs index cefb6470765..fcb614430f7 100644 --- a/swarm/src/behaviour.rs +++ b/swarm/src/behaviour.rs @@ -34,7 +34,8 @@ use crate::{ AddressRecord, AddressScore, ConnectionDenied, DialError, ListenError, THandler, THandlerInEvent, THandlerOutEvent, }; -use libp2p_core::{transport::ListenerId, ConnectedPoint, Endpoint, Multiaddr, PeerId}; +use libp2p_core::{transport::ListenerId, ConnectedPoint, Endpoint, Multiaddr}; +use libp2p_identity::PeerId; use std::{task::Context, task::Poll}; /// A [`NetworkBehaviour`] defines the behaviour of the local node on the network. diff --git a/swarm/src/behaviour/either.rs b/swarm/src/behaviour/either.rs index e807749ddb8..ef71f8e5e2e 100644 --- a/swarm/src/behaviour/either.rs +++ b/swarm/src/behaviour/either.rs @@ -22,7 +22,8 @@ use crate::behaviour::{self, NetworkBehaviour, NetworkBehaviourAction, PollParam use crate::connection::ConnectionId; use crate::{ConnectionDenied, THandler, THandlerInEvent, THandlerOutEvent}; use either::Either; -use libp2p_core::{Endpoint, Multiaddr, PeerId}; +use libp2p_core::{Endpoint, Multiaddr}; +use libp2p_identity::PeerId; use std::{task::Context, task::Poll}; /// Implementation of [`NetworkBehaviour`] that can be either of two implementations. diff --git a/swarm/src/behaviour/toggle.rs b/swarm/src/behaviour/toggle.rs index a4302cef65b..395e380490f 100644 --- a/swarm/src/behaviour/toggle.rs +++ b/swarm/src/behaviour/toggle.rs @@ -32,7 +32,8 @@ use crate::{ }; use either::Either; use futures::future; -use libp2p_core::{upgrade::DeniedUpgrade, Endpoint, Multiaddr, PeerId}; +use libp2p_core::{upgrade::DeniedUpgrade, Endpoint, Multiaddr}; +use libp2p_identity::PeerId; use std::{task::Context, task::Poll}; /// Implementation of `NetworkBehaviour` that can be either in the disabled or enabled state. diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index baa3896462c..b42bdde9620 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -42,8 +42,9 @@ use libp2p_core::connection::ConnectedPoint; use libp2p_core::multiaddr::Multiaddr; use libp2p_core::muxing::{StreamMuxerBox, StreamMuxerEvent, StreamMuxerExt, SubstreamBox}; use libp2p_core::upgrade::{InboundUpgradeApply, OutboundUpgradeApply}; +use libp2p_core::Endpoint; use libp2p_core::{upgrade, UpgradeError}; -use libp2p_core::{Endpoint, PeerId}; +use libp2p_identity::PeerId; use std::future::Future; use std::sync::atomic::{AtomicUsize, Ordering}; use std::task::Waker; diff --git a/swarm/src/connection/pool/concurrent_dial.rs b/swarm/src/connection/pool/concurrent_dial.rs index 7bd9e7f1f66..024c21a568d 100644 --- a/swarm/src/connection/pool/concurrent_dial.rs +++ b/swarm/src/connection/pool/concurrent_dial.rs @@ -25,7 +25,7 @@ use futures::{ stream::{FuturesUnordered, StreamExt}, }; use libp2p_core::muxing::StreamMuxerBox; -use libp2p_core::PeerId; +use libp2p_identity::PeerId; use std::{ num::NonZeroU8, pin::Pin, diff --git a/swarm/src/dial_opts.rs b/swarm/src/dial_opts.rs index 0d4ce9eb8f0..c43a7a52b8d 100644 --- a/swarm/src/dial_opts.rs +++ b/swarm/src/dial_opts.rs @@ -23,7 +23,8 @@ use crate::ConnectionId; use libp2p_core::connection::Endpoint; use libp2p_core::multiaddr::Protocol; use libp2p_core::multihash::Multihash; -use libp2p_core::{Multiaddr, PeerId}; +use libp2p_core::Multiaddr; +use libp2p_identity::PeerId; use std::num::NonZeroU8; /// Options to configure a dial to a known or unknown peer. @@ -52,7 +53,7 @@ impl DialOpts { /// /// ``` /// # use libp2p_swarm::dial_opts::{DialOpts, PeerCondition}; - /// # use libp2p_core::PeerId; + /// # use libp2p_identity::PeerId; /// DialOpts::peer_id(PeerId::random()) /// .condition(PeerCondition::Disconnected) /// .addresses(vec!["/ip6/::1/tcp/12345".parse().unwrap()]) @@ -327,7 +328,7 @@ impl WithoutPeerIdWithAddress { /// /// ``` /// # use libp2p_swarm::dial_opts::{DialOpts, PeerCondition}; -/// # use libp2p_core::PeerId; +/// # use libp2p_identity::PeerId; /// # /// DialOpts::peer_id(PeerId::random()) /// .condition(PeerCondition::Disconnected) diff --git a/swarm/src/dummy.rs b/swarm/src/dummy.rs index 8d9fa74c7ab..9396344ca30 100644 --- a/swarm/src/dummy.rs +++ b/swarm/src/dummy.rs @@ -8,8 +8,9 @@ use crate::{ SubstreamProtocol, THandler, THandlerInEvent, THandlerOutEvent, }; use libp2p_core::upgrade::DeniedUpgrade; -use libp2p_core::{Endpoint, PeerId}; +use libp2p_core::Endpoint; use libp2p_core::{Multiaddr, UpgradeError}; +use libp2p_identity::PeerId; use std::task::{Context, Poll}; use void::Void; diff --git a/swarm/src/handler.rs b/swarm/src/handler.rs index cf8b9c1f2cb..6c0ccc068b7 100644 --- a/swarm/src/handler.rs +++ b/swarm/src/handler.rs @@ -49,7 +49,8 @@ mod select; pub use crate::upgrade::{InboundUpgradeSend, OutboundUpgradeSend, SendWrapper, UpgradeInfoSend}; use instant::Instant; -use libp2p_core::{upgrade::UpgradeError, ConnectedPoint, Multiaddr, PeerId}; +use libp2p_core::{upgrade::UpgradeError, ConnectedPoint, Multiaddr}; +use libp2p_identity::PeerId; use std::{cmp::Ordering, error, fmt, task::Context, task::Poll, time::Duration}; pub use map_in::MapInEvent; diff --git a/swarm/src/handler/either.rs b/swarm/src/handler/either.rs index a10dbc0313d..92d82371163 100644 --- a/swarm/src/handler/either.rs +++ b/swarm/src/handler/either.rs @@ -28,7 +28,8 @@ use crate::upgrade::SendWrapper; use crate::ConnectionHandlerUpgrErr; use either::Either; use futures::future; -use libp2p_core::{ConnectedPoint, PeerId, UpgradeError}; +use libp2p_core::{ConnectedPoint, UpgradeError}; +use libp2p_identity::PeerId; use std::task::{Context, Poll}; /// Auxiliary type to allow implementing [`IntoConnectionHandler`]. As [`IntoConnectionHandler`] is diff --git a/swarm/src/handler/multi.rs b/swarm/src/handler/multi.rs index 47a095d972f..146a2a96895 100644 --- a/swarm/src/handler/multi.rs +++ b/swarm/src/handler/multi.rs @@ -32,7 +32,8 @@ use crate::upgrade::{InboundUpgradeSend, OutboundUpgradeSend, UpgradeInfoSend}; use crate::NegotiatedSubstream; use futures::{future::BoxFuture, prelude::*}; use libp2p_core::upgrade::{NegotiationError, ProtocolError, ProtocolName, UpgradeError}; -use libp2p_core::{ConnectedPoint, PeerId}; +use libp2p_core::ConnectedPoint; +use libp2p_identity::PeerId; use rand::Rng; use std::{ cmp, diff --git a/swarm/src/handler/select.rs b/swarm/src/handler/select.rs index a1dd844c019..edb9a9154b1 100644 --- a/swarm/src/handler/select.rs +++ b/swarm/src/handler/select.rs @@ -30,8 +30,9 @@ use either::Either; use futures::future; use libp2p_core::{ upgrade::{NegotiationError, ProtocolError, SelectUpgrade, UpgradeError}, - ConnectedPoint, PeerId, + ConnectedPoint, }; +use libp2p_identity::PeerId; use std::{cmp, task::Context, task::Poll}; /// Implementation of `IntoConnectionHandler` that combines two protocols into one. diff --git a/swarm/src/keep_alive.rs b/swarm/src/keep_alive.rs index cbc778cfc0a..119b8ac86b1 100644 --- a/swarm/src/keep_alive.rs +++ b/swarm/src/keep_alive.rs @@ -6,7 +6,8 @@ use crate::handler::{ }; use crate::{ConnectionDenied, THandler, THandlerInEvent, THandlerOutEvent}; use libp2p_core::upgrade::DeniedUpgrade; -use libp2p_core::{Endpoint, Multiaddr, PeerId}; +use libp2p_core::{Endpoint, Multiaddr}; +use libp2p_identity::PeerId; use std::task::{Context, Poll}; use void::Void; diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index af82226f8a0..0d44eada560 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -101,7 +101,7 @@ pub mod derive_prelude { pub use libp2p_core::ConnectedPoint; pub use libp2p_core::Endpoint; pub use libp2p_core::Multiaddr; - pub use libp2p_core::PeerId; + pub use libp2p_identity::PeerId; } pub use behaviour::{ @@ -139,8 +139,9 @@ use libp2p_core::{ multihash::Multihash, muxing::StreamMuxerBox, transport::{self, ListenerId, TransportError, TransportEvent}, - Endpoint, Multiaddr, Negotiated, PeerId, ProtocolName, Transport, + Endpoint, Multiaddr, Negotiated, ProtocolName, Transport, }; +use libp2p_identity::PeerId; use registry::{AddressIntoIter, Addresses}; use smallvec::SmallVec; use std::collections::{HashMap, HashSet}; @@ -1955,8 +1956,9 @@ mod tests { use libp2p_core::multiaddr::multiaddr; use libp2p_core::transport::memory::MemoryTransportError; use libp2p_core::transport::TransportEvent; - use libp2p_core::{identity, multiaddr, transport, upgrade}; + use libp2p_core::{multiaddr, transport, upgrade}; use libp2p_core::{Endpoint, UpgradeError}; + use libp2p_identity as identity; use libp2p_plaintext as plaintext; use libp2p_yamux as yamux; use quickcheck::*; diff --git a/swarm/src/test.rs b/swarm/src/test.rs index d89b1cb20fc..caf4fb99a85 100644 --- a/swarm/src/test.rs +++ b/swarm/src/test.rs @@ -26,7 +26,8 @@ use crate::{ ConnectionDenied, ConnectionHandler, ConnectionId, NetworkBehaviour, NetworkBehaviourAction, PollParameters, THandler, THandlerInEvent, THandlerOutEvent, }; -use libp2p_core::{multiaddr::Multiaddr, transport::ListenerId, ConnectedPoint, Endpoint, PeerId}; +use libp2p_core::{multiaddr::Multiaddr, transport::ListenerId, ConnectedPoint, Endpoint}; +use libp2p_identity::PeerId; use std::collections::HashMap; use std::task::{Context, Poll}; diff --git a/swarm/tests/swarm_derive.rs b/swarm/tests/swarm_derive.rs index 6d5b78e9e3d..e7e2e471ab1 100644 --- a/swarm/tests/swarm_derive.rs +++ b/swarm/tests/swarm_derive.rs @@ -435,7 +435,7 @@ fn generated_out_event_derive_debug() { #[test] fn custom_out_event_no_type_parameters() { - use libp2p_core::PeerId; + use libp2p_identity::PeerId; use libp2p_swarm::{ConnectionId, NetworkBehaviourAction, PollParameters}; use std::task::Context; use std::task::Poll; diff --git a/transports/dns/Cargo.toml b/transports/dns/Cargo.toml index a53fa2d5e15..73a5e88dcc3 100644 --- a/transports/dns/Cargo.toml +++ b/transports/dns/Cargo.toml @@ -12,6 +12,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] libp2p-core = { version = "0.39.0", path = "../../core" } +libp2p-identity = { version = "0.1.0", path = "../../identity" } log = "0.4.1" futures = "0.3.26" async-std-resolver = { version = "0.22", optional = true } diff --git a/transports/dns/src/lib.rs b/transports/dns/src/lib.rs index 8ea3967ccbc..7de86ba358c 100644 --- a/transports/dns/src/lib.rs +++ b/transports/dns/src/lib.rs @@ -580,8 +580,9 @@ mod tests { use libp2p_core::{ multiaddr::{Multiaddr, Protocol}, transport::{TransportError, TransportEvent}, - PeerId, Transport, + Transport, }; + use libp2p_identity::PeerId; #[test] fn basic_resolve() { diff --git a/transports/noise/Cargo.toml b/transports/noise/Cargo.toml index a5475765b1f..a792df0a326 100644 --- a/transports/noise/Cargo.toml +++ b/transports/noise/Cargo.toml @@ -13,6 +13,7 @@ bytes = "1" curve25519-dalek = "3.0.0" futures = "0.3.26" libp2p-core = { version = "0.39.0", path = "../../core" } +libp2p-identity = { version = "0.1.0", path = "../../identity", features = ["ed25519"] } log = "0.4" quick-protobuf = "0.8" once_cell = "1.17.1" diff --git a/transports/noise/src/io/handshake.rs b/transports/noise/src/io/handshake.rs index 1a6a8694ca2..672f24ef7ce 100644 --- a/transports/noise/src/io/handshake.rs +++ b/transports/noise/src/io/handshake.rs @@ -32,7 +32,7 @@ use crate::LegacyConfig; use crate::NoiseError; use bytes::Bytes; use futures::prelude::*; -use libp2p_core::identity; +use libp2p_identity as identity; use quick_protobuf::{BytesReader, MessageRead, MessageWrite, Writer}; use std::io; diff --git a/transports/noise/src/lib.rs b/transports/noise/src/lib.rs index 05a0d4d93a0..c1c120f38a6 100644 --- a/transports/noise/src/lib.rs +++ b/transports/noise/src/lib.rs @@ -72,7 +72,9 @@ use crate::handshake::State; use crate::io::handshake; use futures::future::BoxFuture; use futures::prelude::*; -use libp2p_core::{identity, InboundUpgrade, OutboundUpgrade, PeerId, UpgradeInfo}; +use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; +use libp2p_identity as identity; +use libp2p_identity::PeerId; use std::pin::Pin; use zeroize::Zeroize; @@ -270,7 +272,7 @@ pub enum NoiseError { #[error(transparent)] Noise(#[from] snow::Error), #[error("Invalid public key")] - InvalidKey(#[from] identity::error::DecodingError), + InvalidKey(#[from] libp2p_identity::DecodingError), #[error("Only keys of length 32 bytes are supported")] InvalidLength, #[error("Remote authenticated with an unexpected public key")] @@ -282,7 +284,7 @@ pub enum NoiseError { #[error(transparent)] InvalidPayload(DecodeError), #[error(transparent)] - SigningError(#[from] identity::error::SigningError), + SigningError(#[from] libp2p_identity::SigningError), } #[derive(Debug, thiserror::Error)] diff --git a/transports/noise/src/protocol.rs b/transports/noise/src/protocol.rs index 7ec9746d5bc..e61bbd1f0ed 100644 --- a/transports/noise/src/protocol.rs +++ b/transports/noise/src/protocol.rs @@ -24,7 +24,7 @@ pub mod x25519; pub mod x25519_spec; use crate::NoiseError; -use libp2p_core::identity; +use libp2p_identity as identity; use rand::SeedableRng; use zeroize::Zeroize; diff --git a/transports/noise/src/protocol/x25519.rs b/transports/noise/src/protocol/x25519.rs index 2e3689beb8b..9dcf5f8d73a 100644 --- a/transports/noise/src/protocol/x25519.rs +++ b/transports/noise/src/protocol/x25519.rs @@ -28,7 +28,8 @@ use crate::{NoiseConfig, NoiseError, Protocol, ProtocolParams}; use curve25519_dalek::edwards::CompressedEdwardsY; use libp2p_core::UpgradeInfo; -use libp2p_core::{identity, identity::ed25519}; +use libp2p_identity as identity; +use libp2p_identity::ed25519; use once_cell::sync::Lazy; use rand::Rng; use sha2::{Digest, Sha512}; @@ -281,7 +282,7 @@ impl snow::types::Dh for Keypair { #[cfg(test)] mod tests { use super::*; - use libp2p_core::identity::ed25519; + use libp2p_identity::ed25519; use quickcheck::*; // The x25519 public key obtained through ed25519 keypair conversion diff --git a/transports/noise/src/protocol/x25519_spec.rs b/transports/noise/src/protocol/x25519_spec.rs index 87973463521..0924bdd51e4 100644 --- a/transports/noise/src/protocol/x25519_spec.rs +++ b/transports/noise/src/protocol/x25519_spec.rs @@ -23,8 +23,8 @@ //! [libp2p-noise-spec]: https://github.com/libp2p/specs/tree/master/noise use crate::{NoiseConfig, NoiseError, Protocol, ProtocolParams}; -use libp2p_core::identity; use libp2p_core::UpgradeInfo; +use libp2p_identity as identity; use rand::Rng; use x25519_dalek::{x25519, X25519_BASEPOINT_BYTES}; use zeroize::Zeroize; diff --git a/transports/noise/tests/smoke.rs b/transports/noise/tests/smoke.rs index c92435e4c3e..2b71b115b99 100644 --- a/transports/noise/tests/smoke.rs +++ b/transports/noise/tests/smoke.rs @@ -25,7 +25,8 @@ use futures::{ }; use libp2p_core::transport::Transport; use libp2p_core::upgrade::{apply_inbound, apply_outbound, Negotiated}; -use libp2p_core::{identity, transport, upgrade}; +use libp2p_core::{transport, upgrade}; +use libp2p_identity as identity; use libp2p_noise::{ Keypair, NoiseAuthenticated, NoiseConfig, NoiseError, NoiseOutput, RemoteIdentity, X25519Spec, }; diff --git a/transports/plaintext/Cargo.toml b/transports/plaintext/Cargo.toml index 7d5843d32be..5e080e89cb0 100644 --- a/transports/plaintext/Cargo.toml +++ b/transports/plaintext/Cargo.toml @@ -15,6 +15,7 @@ asynchronous-codec = "0.6" bytes = "1" futures = "0.3.26" libp2p-core = { version = "0.39.0", path = "../../core" } +libp2p-identity = { version = "0.1.0", path = "../../identity" } log = "0.4.8" quick-protobuf = "0.8" unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] } @@ -22,6 +23,7 @@ void = "1.0.2" [dev-dependencies] env_logger = "0.10.0" +libp2p-identity = { path = "../../identity", features = ["ed25519"] } quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" } rand = "0.8" diff --git a/transports/plaintext/src/handshake.rs b/transports/plaintext/src/handshake.rs index 8ce24f9df22..3f70f515a09 100644 --- a/transports/plaintext/src/handshake.rs +++ b/transports/plaintext/src/handshake.rs @@ -25,7 +25,7 @@ use crate::PlainText2Config; use asynchronous_codec::{Framed, FramedParts}; use bytes::{Bytes, BytesMut}; use futures::prelude::*; -use libp2p_core::{PeerId, PublicKey}; +use libp2p_identity::{PeerId, PublicKey}; use log::{debug, trace}; use quick_protobuf::{BytesReader, MessageRead, MessageWrite, Writer}; use std::io::{Error as IoError, ErrorKind as IoErrorKind}; diff --git a/transports/plaintext/src/lib.rs b/transports/plaintext/src/lib.rs index c4a6a2ed011..aeea2763d4d 100644 --- a/transports/plaintext/src/lib.rs +++ b/transports/plaintext/src/lib.rs @@ -28,7 +28,10 @@ use bytes::Bytes; use futures::future::BoxFuture; use futures::future::{self, Ready}; use futures::prelude::*; -use libp2p_core::{identity, InboundUpgrade, OutboundUpgrade, PeerId, PublicKey, UpgradeInfo}; +use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; +use libp2p_identity as identity; +use libp2p_identity::PeerId; +use libp2p_identity::PublicKey; use log::debug; use std::{ io, iter, diff --git a/transports/plaintext/tests/smoke.rs b/transports/plaintext/tests/smoke.rs index d1316309c64..047d606f8f7 100644 --- a/transports/plaintext/tests/smoke.rs +++ b/transports/plaintext/tests/smoke.rs @@ -22,7 +22,8 @@ use futures::{ io::{AsyncReadExt, AsyncWriteExt}, StreamExt, }; -use libp2p_core::{identity, multiaddr::Multiaddr, transport::Transport, upgrade}; +use libp2p_core::{multiaddr::Multiaddr, transport::Transport, upgrade}; +use libp2p_identity as identity; use libp2p_plaintext::PlainText2Config; use log::debug; use quickcheck::QuickCheck; diff --git a/transports/pnet/Cargo.toml b/transports/pnet/Cargo.toml index 7c7c70f3754..7b60c35b5df 100644 --- a/transports/pnet/Cargo.toml +++ b/transports/pnet/Cargo.toml @@ -20,6 +20,7 @@ pin-project = "1.0.2" [dev-dependencies] libp2p-core = { path = "../../core", features = ["rsa", "ecdsa", "secp256k1"] } +libp2p-identity = { path = "../../identity", features = ["ed25519"] } libp2p-noise = { path = "../noise" } libp2p-swarm = { path = "../../swarm", features = ["tokio"] } libp2p-tcp = { path = "../tcp", features = ["tokio"] } diff --git a/transports/pnet/tests/smoke.rs b/transports/pnet/tests/smoke.rs index 9084c4e626b..4fa1f0c7483 100644 --- a/transports/pnet/tests/smoke.rs +++ b/transports/pnet/tests/smoke.rs @@ -106,7 +106,7 @@ where ::ListenerUpgrade: Send, ::Dial: Send, { - let identity = libp2p_core::identity::Keypair::generate_ed25519(); + let identity = libp2p_identity::Keypair::generate_ed25519(); let transport = transport .and_then(move |socket, _| pnet.handshake(socket)) .upgrade(Version::V1) diff --git a/transports/quic/Cargo.toml b/transports/quic/Cargo.toml index dc8112137af..02e3bc392e0 100644 --- a/transports/quic/Cargo.toml +++ b/transports/quic/Cargo.toml @@ -16,6 +16,7 @@ futures-timer = "3.0.2" if-watch = "3.0.0" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-tls = { version = "0.1.0", path = "../tls" } +libp2p-identity = { version = "0.1.0", path = "../../identity" } log = "0.4" parking_lot = "0.12.0" quinn-proto = { version = "0.9.0", default-features = false, features = ["tls-rustls"] } diff --git a/transports/quic/src/connection/connecting.rs b/transports/quic/src/connection/connecting.rs index 3124885e772..e9a7d3e5f2c 100644 --- a/transports/quic/src/connection/connecting.rs +++ b/transports/quic/src/connection/connecting.rs @@ -24,7 +24,7 @@ use crate::{Connection, Error}; use futures::prelude::*; use futures_timer::Delay; -use libp2p_core::PeerId; +use libp2p_identity::PeerId; use std::{ pin::Pin, task::{Context, Poll}, diff --git a/transports/quic/src/endpoint.rs b/transports/quic/src/endpoint.rs index 024062e379a..319ce571276 100644 --- a/transports/quic/src/endpoint.rs +++ b/transports/quic/src/endpoint.rs @@ -91,7 +91,7 @@ pub struct Config { impl Config { /// Creates a new configuration object with default values. - pub fn new(keypair: &libp2p_core::identity::Keypair) -> Self { + pub fn new(keypair: &libp2p_identity::Keypair) -> Self { let client_tls_config = Arc::new(libp2p_tls::make_client_config(keypair, None).unwrap()); let server_tls_config = Arc::new(libp2p_tls::make_server_config(keypair).unwrap()); Self { diff --git a/transports/quic/src/lib.rs b/transports/quic/src/lib.rs index 8195bb3b136..af6dd1871dd 100644 --- a/transports/quic/src/lib.rs +++ b/transports/quic/src/lib.rs @@ -34,7 +34,7 @@ //! use libp2p_quic as quic; //! use libp2p_core::{Multiaddr, Transport}; //! -//! let keypair = libp2p_core::identity::Keypair::generate_ed25519(); +//! let keypair = libp2p_identity::Keypair::generate_ed25519(); //! let quic_config = quic::Config::new(&keypair); //! //! let mut quic_transport = quic::async_std::Transport::new(quic_config); diff --git a/transports/quic/src/transport.rs b/transports/quic/src/transport.rs index 54c1fec9e30..9aadbeb93f4 100644 --- a/transports/quic/src/transport.rs +++ b/transports/quic/src/transport.rs @@ -33,8 +33,9 @@ use if_watch::IfEvent; use libp2p_core::{ multiaddr::{Multiaddr, Protocol}, transport::{ListenerId, TransportError, TransportEvent}, - PeerId, Transport, + Transport, }; +use libp2p_identity::PeerId; use std::collections::hash_map::{DefaultHasher, Entry}; use std::collections::{HashMap, VecDeque}; use std::fmt; @@ -761,7 +762,7 @@ mod test { #[cfg(feature = "async-std")] #[async_std::test] async fn test_close_listener() { - let keypair = libp2p_core::identity::Keypair::generate_ed25519(); + let keypair = libp2p_identity::Keypair::generate_ed25519(); let config = Config::new(&keypair); let mut transport = crate::async_std::Transport::new(config); assert!(poll_fn(|cx| Pin::new(&mut transport).as_mut().poll(cx)) @@ -830,7 +831,7 @@ mod test { #[cfg(feature = "tokio")] #[tokio::test] async fn test_dialer_drop() { - let keypair = libp2p_core::identity::Keypair::generate_ed25519(); + let keypair = libp2p_identity::Keypair::generate_ed25519(); let config = Config::new(&keypair); let mut transport = crate::tokio::Transport::new(config); diff --git a/transports/quic/tests/smoke.rs b/transports/quic/tests/smoke.rs index 41e7f6ac039..2e8914140c4 100644 --- a/transports/quic/tests/smoke.rs +++ b/transports/quic/tests/smoke.rs @@ -9,7 +9,8 @@ use futures_timer::Delay; use libp2p_core::muxing::{StreamMuxerBox, StreamMuxerExt, SubstreamBox}; use libp2p_core::transport::{Boxed, OrTransport, TransportEvent}; use libp2p_core::transport::{ListenerId, TransportError}; -use libp2p_core::{multiaddr::Protocol, upgrade, Multiaddr, PeerId, Transport}; +use libp2p_core::{multiaddr::Protocol, upgrade, Multiaddr, Transport}; +use libp2p_identity::PeerId; use libp2p_noise as noise; use libp2p_quic as quic; use libp2p_tcp as tcp; @@ -207,7 +208,7 @@ async fn wrapped_with_delay() { #[async_std::test] #[ignore] // Transport currently does not validate PeerId. Enable once we make use of PeerId validation in rustls. async fn wrong_peerid() { - use libp2p_core::PeerId; + use libp2p_identity::PeerId; let (a_peer_id, mut a_transport) = create_default_transport::(); let (b_peer_id, mut b_transport) = create_default_transport::(); @@ -492,8 +493,8 @@ macro_rules! swap_protocol { }; } -fn generate_tls_keypair() -> libp2p_core::identity::Keypair { - libp2p_core::identity::Keypair::generate_ed25519() +fn generate_tls_keypair() -> libp2p_identity::Keypair { + libp2p_identity::Keypair::generate_ed25519() } fn create_default_transport() -> (PeerId, Boxed<(PeerId, StreamMuxerBox)>) { diff --git a/transports/quic/tests/stream_compliance.rs b/transports/quic/tests/stream_compliance.rs index fc652f0d854..ec4c3121819 100644 --- a/transports/quic/tests/stream_compliance.rs +++ b/transports/quic/tests/stream_compliance.rs @@ -62,7 +62,7 @@ async fn connected_peers() -> (quic::Connection, quic::Connection) { } fn new_transport() -> quic::async_std::Transport { - let keypair = libp2p_core::identity::Keypair::generate_ed25519(); + let keypair = libp2p_identity::Keypair::generate_ed25519(); let mut config = quic::Config::new(&keypair); config.handshake_timeout = Duration::from_secs(1); diff --git a/transports/tcp/Cargo.toml b/transports/tcp/Cargo.toml index 43f512e759f..4d89d80e389 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -17,6 +17,7 @@ futures-timer = "3.0" if-watch = "3.0.0" libc = "0.2.80" libp2p-core = { version = "0.39.0", path = "../../core" } +libp2p-identity = { version = "0.1.0", path = "../../identity" } log = "0.4.11" socket2 = { version = "0.4.0", features = ["all"] } tokio = { version = "1.19.0", default-features = false, features = ["net"], optional = true } diff --git a/transports/tcp/src/lib.rs b/transports/tcp/src/lib.rs index 52d23d0a52d..78f6c3f4656 100644 --- a/transports/tcp/src/lib.rs +++ b/transports/tcp/src/lib.rs @@ -858,8 +858,8 @@ mod tests { channel::{mpsc, oneshot}, future::poll_fn, }; - use libp2p_core::PeerId; use libp2p_core::Transport as _; + use libp2p_identity::PeerId; #[test] fn multiaddr_to_tcp_conversion() { diff --git a/transports/tls/Cargo.toml b/transports/tls/Cargo.toml index 6dc94686b88..97ed6e8298d 100644 --- a/transports/tls/Cargo.toml +++ b/transports/tls/Cargo.toml @@ -12,6 +12,7 @@ exclude = ["src/test_assets"] futures = { version = "0.3.26", default-features = false } futures-rustls = "0.22.2" libp2p-core = { version = "0.39.0", path = "../../core" } +libp2p-identity = { version = "0.1.0", path = "../../identity" } rcgen = "0.10.0" ring = "0.16.20" thiserror = "1.0.39" @@ -28,7 +29,8 @@ features = ["dangerous_configuration"] # Must enable this to allow for custom ve [dev-dependencies] hex = "0.4.3" hex-literal = "0.3.4" -libp2p-core = { path = "../../core", features = ["rsa", "ecdsa", "secp256k1"] } +libp2p-core = { path = "../../core" } +libp2p-identity = { path = "../../identity", features = ["ed25519", "rsa", "secp256k1", "ecdsa"] } libp2p-swarm = { path = "../../swarm" } libp2p-yamux = { path = "../../muxers/yamux" } tokio = { version = "1.21.1", features = ["full"] } diff --git a/transports/tls/src/certificate.rs b/transports/tls/src/certificate.rs index d5a5bf892cf..6321fa26400 100644 --- a/transports/tls/src/certificate.rs +++ b/transports/tls/src/certificate.rs @@ -22,7 +22,8 @@ //! //! This module handles generation, signing, and verification of certificates. -use libp2p_core::{identity, PeerId}; +use libp2p_identity as identity; +use libp2p_identity::PeerId; use x509_parser::{prelude::*, signature_algorithm::SignatureAlgorithm}; /// The libp2p Public Key Extension is a X.509 extension diff --git a/transports/tls/src/lib.rs b/transports/tls/src/lib.rs index 6bf22eea3f3..00a4878856d 100644 --- a/transports/tls/src/lib.rs +++ b/transports/tls/src/lib.rs @@ -29,7 +29,8 @@ pub mod certificate; mod upgrade; mod verifier; -use libp2p_core::{identity::Keypair, PeerId}; +use libp2p_identity::Keypair; +use libp2p_identity::PeerId; use std::sync::Arc; pub use futures_rustls::TlsStream; diff --git a/transports/tls/src/upgrade.rs b/transports/tls/src/upgrade.rs index 4efb3471d7f..d1c9a6cefb4 100644 --- a/transports/tls/src/upgrade.rs +++ b/transports/tls/src/upgrade.rs @@ -24,7 +24,9 @@ use futures::future::BoxFuture; use futures::AsyncWrite; use futures::{AsyncRead, FutureExt}; use futures_rustls::TlsStream; -use libp2p_core::{identity, InboundUpgrade, OutboundUpgrade, PeerId, UpgradeInfo}; +use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; +use libp2p_identity as identity; +use libp2p_identity::PeerId; use rustls::{CommonState, ServerName}; use std::net::{IpAddr, Ipv4Addr}; use std::sync::Arc; diff --git a/transports/tls/src/verifier.rs b/transports/tls/src/verifier.rs index b6378d650b1..29e4ab989e5 100644 --- a/transports/tls/src/verifier.rs +++ b/transports/tls/src/verifier.rs @@ -24,7 +24,7 @@ //! and signatures allegedly by the given certificates. use crate::certificate; -use libp2p_core::PeerId; +use libp2p_identity::PeerId; use rustls::{ cipher_suite::{ TLS13_AES_128_GCM_SHA256, TLS13_AES_256_GCM_SHA384, TLS13_CHACHA20_POLY1305_SHA256, diff --git a/transports/tls/tests/smoke.rs b/transports/tls/tests/smoke.rs index 37be61c0caf..46c6bd167e3 100644 --- a/transports/tls/tests/smoke.rs +++ b/transports/tls/tests/smoke.rs @@ -56,7 +56,7 @@ async fn can_establish_connection() { } fn make_swarm() -> Swarm { - let identity = libp2p_core::identity::Keypair::generate_ed25519(); + let identity = libp2p_identity::Keypair::generate_ed25519(); let transport = MemoryTransport::default() .upgrade(Version::V1) diff --git a/transports/webrtc/Cargo.toml b/transports/webrtc/Cargo.toml index e8686fe21ef..d268d4ff208 100644 --- a/transports/webrtc/Cargo.toml +++ b/transports/webrtc/Cargo.toml @@ -20,6 +20,7 @@ hex = "0.4" if-watch = "3.0" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-noise = { version = "0.42.0", path = "../../transports/noise" } +libp2p-identity = { version = "0.1.0", path = "../../identity" } log = "0.4" multihash = { version = "0.17.0", default-features = false, features = ["sha2"] } quick-protobuf = "0.8" diff --git a/transports/webrtc/examples/listen_ping.rs b/transports/webrtc/examples/listen_ping.rs index b6cf16e693e..2073e96755c 100644 --- a/transports/webrtc/examples/listen_ping.rs +++ b/transports/webrtc/examples/listen_ping.rs @@ -1,8 +1,8 @@ use anyhow::Result; use futures::StreamExt; -use libp2p_core::identity; use libp2p_core::muxing::StreamMuxerBox; use libp2p_core::Transport; +use libp2p_identity as identity; use libp2p_ping as ping; use libp2p_swarm::{keep_alive, NetworkBehaviour, Swarm}; use rand::thread_rng; diff --git a/transports/webrtc/src/tokio/error.rs b/transports/webrtc/src/tokio/error.rs index f91011ffd46..4899a077b4b 100644 --- a/transports/webrtc/src/tokio/error.rs +++ b/transports/webrtc/src/tokio/error.rs @@ -18,7 +18,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use libp2p_core::PeerId; +use libp2p_identity::PeerId; use thiserror::Error; /// Error in WebRTC. diff --git a/transports/webrtc/src/tokio/transport.rs b/transports/webrtc/src/tokio/transport.rs index 29ab7614037..5c4c77700e0 100644 --- a/transports/webrtc/src/tokio/transport.rs +++ b/transports/webrtc/src/tokio/transport.rs @@ -21,11 +21,11 @@ use futures::{future::BoxFuture, prelude::*, stream::SelectAll, stream::Stream}; use if_watch::{tokio::IfWatcher, IfEvent}; use libp2p_core::{ - identity, multiaddr::{Multiaddr, Protocol}, transport::{ListenerId, TransportError, TransportEvent}, - PeerId, }; +use libp2p_identity as identity; +use libp2p_identity::PeerId; use webrtc::peer_connection::configuration::RTCConfiguration; use std::net::IpAddr; diff --git a/transports/webrtc/src/tokio/upgrade.rs b/transports/webrtc/src/tokio/upgrade.rs index 9375d58417c..23dd978ae92 100644 --- a/transports/webrtc/src/tokio/upgrade.rs +++ b/transports/webrtc/src/tokio/upgrade.rs @@ -23,7 +23,8 @@ mod noise; use futures::channel::oneshot; use futures::future::Either; use futures_timer::Delay; -use libp2p_core::{identity, PeerId}; +use libp2p_identity as identity; +use libp2p_identity::PeerId; use rand::distributions::Alphanumeric; use rand::{thread_rng, Rng}; use webrtc::api::setting_engine::SettingEngine; diff --git a/transports/webrtc/src/tokio/upgrade/noise.rs b/transports/webrtc/src/tokio/upgrade/noise.rs index 37c999389a1..ad387510fc4 100644 --- a/transports/webrtc/src/tokio/upgrade/noise.rs +++ b/transports/webrtc/src/tokio/upgrade/noise.rs @@ -19,7 +19,9 @@ // DEALINGS IN THE SOFTWARE. use futures::{AsyncRead, AsyncWrite, AsyncWriteExt}; -use libp2p_core::{identity, InboundUpgrade, OutboundUpgrade, PeerId, UpgradeInfo}; +use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; +use libp2p_identity as identity; +use libp2p_identity::PeerId; use libp2p_noise::{Keypair, NoiseConfig, X25519Spec}; use crate::tokio::fingerprint::Fingerprint; diff --git a/transports/webrtc/tests/smoke.rs b/transports/webrtc/tests/smoke.rs index 26779d13ce9..67d2f95ae33 100644 --- a/transports/webrtc/tests/smoke.rs +++ b/transports/webrtc/tests/smoke.rs @@ -24,7 +24,8 @@ use futures::stream::StreamExt; use futures::{future, ready, AsyncReadExt, AsyncWriteExt, FutureExt, SinkExt}; use libp2p_core::muxing::{StreamMuxerBox, StreamMuxerExt}; use libp2p_core::transport::{Boxed, TransportEvent}; -use libp2p_core::{Multiaddr, PeerId, Transport}; +use libp2p_core::{Multiaddr, Transport}; +use libp2p_identity::PeerId; use libp2p_webrtc as webrtc; use rand::{thread_rng, RngCore}; use std::future::Future; @@ -61,8 +62,8 @@ fn concurrent_connections_and_streams_tokio() { .quickcheck(prop as fn(_, _) -> _); } -fn generate_tls_keypair() -> libp2p_core::identity::Keypair { - libp2p_core::identity::Keypair::generate_ed25519() +fn generate_tls_keypair() -> libp2p_identity::Keypair { + libp2p_identity::Keypair::generate_ed25519() } fn create_transport() -> (PeerId, Boxed<(PeerId, StreamMuxerBox)>) { diff --git a/transports/websocket/Cargo.toml b/transports/websocket/Cargo.toml index 1dc18733dc2..c0f70dd07d8 100644 --- a/transports/websocket/Cargo.toml +++ b/transports/websocket/Cargo.toml @@ -15,6 +15,7 @@ futures-rustls = "0.22" either = "1.5.3" futures = "0.3.26" libp2p-core = { version = "0.39.0", path = "../../core" } +libp2p-identity = { version = "0.1.0", path = "../../identity" } log = "0.4.8" parking_lot = "0.12.0" quicksink = "0.1" diff --git a/transports/websocket/src/lib.rs b/transports/websocket/src/lib.rs index e7ab5e0a0cd..f9b289422fd 100644 --- a/transports/websocket/src/lib.rs +++ b/transports/websocket/src/lib.rs @@ -287,7 +287,8 @@ where mod tests { use super::WsConfig; use futures::prelude::*; - use libp2p_core::{multiaddr::Protocol, Multiaddr, PeerId, Transport}; + use libp2p_core::{multiaddr::Protocol, Multiaddr, Transport}; + use libp2p_identity::PeerId; use libp2p_tcp as tcp; #[test]