From 95d68b0920260661e4c1109b4ca83c53923d8944 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 22 Mar 2023 12:58:53 +0100 Subject: [PATCH 1/9] Remove `multiaddr` dependency from `libp2p-identity` --- Cargo.lock | 1 - identity/CHANGELOG.md | 8 ++++++++ identity/Cargo.toml | 3 +-- identity/src/peer_id.rs | 40 ---------------------------------------- 4 files changed, 9 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e1f482786e0..efb67b3a533 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2434,7 +2434,6 @@ dependencies = [ "ed25519-dalek", "libsecp256k1", "log", - "multiaddr", "multihash", "p256 0.12.0", "prost", diff --git a/identity/CHANGELOG.md b/identity/CHANGELOG.md index e74f4004b0c..3dbb76dabd9 100644 --- a/identity/CHANGELOG.md +++ b/identity/CHANGELOG.md @@ -1,3 +1,11 @@ +# 0.2.0 - unreleased + +- Remove `PeerId::try_from_multiaddr`. + `multiaddr::Protocol::P2p` is now type-safe and contains a `PeerId` directly, rendering this function obsolete. + See [PR XXXX]. + +[PR XXXX]: https://github.com/libp2p/rust-libp2p/pull/XXXX + # 0.1.1 - Add `From` impl for specific keypairs. diff --git a/identity/Cargo.toml b/identity/Cargo.toml index 83af0c96201..cb916afc3f5 100644 --- a/identity/Cargo.toml +++ b/identity/Cargo.toml @@ -17,7 +17,6 @@ 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 } @@ -38,7 +37,7 @@ 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" ] +peerid = [ "multihash", "bs58", "rand", "thiserror" ] [dev-dependencies] quickcheck = { package = "quickcheck-ext", path = "../misc/quickcheck-ext" } diff --git a/identity/src/peer_id.rs b/identity/src/peer_id.rs index ae9ffc80c0a..106baa75ce5 100644 --- a/identity/src/peer_id.rs +++ b/identity/src/peer_id.rs @@ -18,7 +18,6 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use multiaddr::{Multiaddr, Protocol}; use multihash::{Code, Error, Multihash}; use rand::Rng; use std::{convert::TryFrom, fmt, str::FromStr}; @@ -91,17 +90,6 @@ impl PeerId { } } - /// Tries to extract a [`PeerId`] from the given [`Multiaddr`]. - /// - /// In case the given [`Multiaddr`] ends with `/p2p/`, this function - /// will return the encapsulated [`PeerId`], otherwise it will return `None`. - pub fn try_from_multiaddr(address: &Multiaddr) -> Option { - address.iter().last().and_then(|p| match p { - Protocol::P2p(hash) => PeerId::from_multihash(hash).ok(), - _ => None, - }) - } - /// Generates a random peer ID from a cryptographically secure PRNG. /// /// This is useful for randomly walking on a DHT, or for testing purposes. @@ -288,32 +276,4 @@ mod tests { assert_eq!(peer_id, PeerId::from_bytes(&peer_id.to_bytes()).unwrap()); } } - - #[test] - fn extract_peer_id_from_multi_address() { - let address = "/memory/1234/p2p/12D3KooWGQmdpzHXCqLno4mMxWXKNFQHASBeF99gTm2JR8Vu5Bdc" - .to_string() - .parse() - .unwrap(); - - #[allow(deprecated)] - let peer_id = PeerId::try_from_multiaddr(&address).unwrap(); - - assert_eq!( - peer_id, - "12D3KooWGQmdpzHXCqLno4mMxWXKNFQHASBeF99gTm2JR8Vu5Bdc" - .parse() - .unwrap() - ); - } - - #[test] - 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()); - } } From baaf8c8e07ff7b8fe7d9d2999a37e30ebc398177 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 22 Mar 2023 13:32:04 +0100 Subject: [PATCH 2/9] Bump `libp2p-identity` version --- Cargo.lock | 2 +- core/Cargo.toml | 2 +- identity/Cargo.toml | 2 +- libp2p/Cargo.toml | 2 +- misc/allow-block-list/Cargo.toml | 2 +- misc/connection-limits/Cargo.toml | 2 +- misc/keygen/Cargo.toml | 2 +- misc/metrics/Cargo.toml | 2 +- muxers/mplex/Cargo.toml | 2 +- protocols/autonat/Cargo.toml | 2 +- protocols/dcutr/Cargo.toml | 2 +- protocols/floodsub/Cargo.toml | 2 +- protocols/gossipsub/Cargo.toml | 2 +- protocols/identify/Cargo.toml | 2 +- protocols/kad/Cargo.toml | 2 +- protocols/mdns/Cargo.toml | 2 +- protocols/perf/Cargo.toml | 2 +- protocols/ping/Cargo.toml | 2 +- protocols/relay/Cargo.toml | 2 +- protocols/rendezvous/Cargo.toml | 2 +- protocols/request-response/Cargo.toml | 2 +- swarm-test/Cargo.toml | 2 +- swarm/Cargo.toml | 4 ++-- transports/dns/Cargo.toml | 2 +- transports/noise/Cargo.toml | 2 +- transports/plaintext/Cargo.toml | 2 +- transports/quic/Cargo.toml | 2 +- transports/tcp/Cargo.toml | 2 +- transports/tls/Cargo.toml | 2 +- transports/webrtc/Cargo.toml | 2 +- transports/websocket/Cargo.toml | 2 +- 31 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index efb67b3a533..907f5d3ff28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2425,7 +2425,7 @@ dependencies = [ [[package]] name = "libp2p-identity" -version = "0.1.1" +version = "0.2.0" dependencies = [ "asn1_der", "base64 0.21.0", diff --git a/core/Cargo.toml b/core/Cargo.toml index f05c912ad72..4f031698187 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -16,7 +16,7 @@ fnv = "1.0" futures = { version = "0.3.27", features = ["executor", "thread-pool"] } futures-timer = "3" instant = "0.1.11" -libp2p-identity = { version = "0.1", path = "../identity", features = ["peerid", "ed25519"] } +libp2p-identity = { version = "0.2", 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"] } diff --git a/identity/Cargo.toml b/identity/Cargo.toml index cb916afc3f5..88cdd1c3e37 100644 --- a/identity/Cargo.toml +++ b/identity/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libp2p-identity" -version = "0.1.1" +version = "0.2.0" edition = "2021" description = "Data structures and algorithms for identifying peers in libp2p." rust-version = "1.60.0" diff --git a/libp2p/Cargo.toml b/libp2p/Cargo.toml index 33176cfaf95..a9c59f48987 100644 --- a/libp2p/Cargo.toml +++ b/libp2p/Cargo.toml @@ -103,7 +103,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-identity = { version = "0.2.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/misc/allow-block-list/Cargo.toml b/misc/allow-block-list/Cargo.toml index a175876179f..5a9b0688692 100644 --- a/misc/allow-block-list/Cargo.toml +++ b/misc/allow-block-list/Cargo.toml @@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity", features = ["peerid"] } +libp2p-identity = { version = "0.2.0", path = "../../identity", features = ["peerid"] } void = "1" [dev-dependencies] diff --git a/misc/connection-limits/Cargo.toml b/misc/connection-limits/Cargo.toml index 3bf2675beb4..33b4eaf5ed6 100644 --- a/misc/connection-limits/Cargo.toml +++ b/misc/connection-limits/Cargo.toml @@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity", features = ["peerid"] } +libp2p-identity = { version = "0.2.0", path = "../../identity", features = ["peerid"] } void = "1" [dev-dependencies] diff --git a/misc/keygen/Cargo.toml b/misc/keygen/Cargo.toml index bd9cdc4b4a9..51e554dad8d 100644 --- a/misc/keygen/Cargo.toml +++ b/misc/keygen/Cargo.toml @@ -16,4 +16,4 @@ serde = { version = "1.0.157", 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" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } diff --git a/misc/metrics/Cargo.toml b/misc/metrics/Cargo.toml index 63a017b4923..a2ef4c86746 100644 --- a/misc/metrics/Cargo.toml +++ b/misc/metrics/Cargo.toml @@ -26,7 +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" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } prometheus-client = "0.19.0" [target.'cfg(not(target_os = "unknown"))'.dependencies] diff --git a/muxers/mplex/Cargo.toml b/muxers/mplex/Cargo.toml index 240a5ab0cd9..87813e15447 100644 --- a/muxers/mplex/Cargo.toml +++ b/muxers/mplex/Cargo.toml @@ -15,7 +15,7 @@ bytes = "1" futures = "0.3.27" asynchronous-codec = "0.6" libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4" nohash-hasher = "0.2" parking_lot = "0.12" diff --git a/protocols/autonat/Cargo.toml b/protocols/autonat/Cargo.toml index 8fc4f15c1f4..ef4ae6ea46a 100644 --- a/protocols/autonat/Cargo.toml +++ b/protocols/autonat/Cargo.toml @@ -18,7 +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" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4" rand = "0.8" quick-protobuf = "0.8" diff --git a/protocols/dcutr/Cargo.toml b/protocols/dcutr/Cargo.toml index c79aac026cf..0395abae7ab 100644 --- a/protocols/dcutr/Cargo.toml +++ b/protocols/dcutr/Cargo.toml @@ -18,7 +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" } +libp2p-identity = { version = "0.2.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/Cargo.toml b/protocols/floodsub/Cargo.toml index 22a772f8259..e86bf64226a 100644 --- a/protocols/floodsub/Cargo.toml +++ b/protocols/floodsub/Cargo.toml @@ -17,7 +17,7 @@ fnv = "1.0" futures = "0.3.27" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-swarm = { version = "0.42.0", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.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/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index ef82ee553ac..8684112dbb8 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -13,7 +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" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } bytes = "1.4" byteorder = "1.3.4" fnv = "1.0.7" diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index a9b5eea2e6f..f6418a6c718 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -16,7 +16,7 @@ futures = "0.3.27" 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" } +libp2p-identity = { version = "0.2.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/kad/Cargo.toml b/protocols/kad/Cargo.toml index aa76253fe88..4332be3941c 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -21,7 +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" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } rand = "0.8" sha2 = "0.10.0" smallvec = "1.6.1" diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml index 37a2e4fc7e1..a99d8e2fc21 100644 --- a/protocols/mdns/Cargo.toml +++ b/protocols/mdns/Cargo.toml @@ -17,7 +17,7 @@ futures = "0.3.27" 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" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4.14" rand = "0.8.3" smallvec = "1.6.1" diff --git a/protocols/perf/Cargo.toml b/protocols/perf/Cargo.toml index fb69cc03ab5..3fb068f5b26 100644 --- a/protocols/perf/Cargo.toml +++ b/protocols/perf/Cargo.toml @@ -19,7 +19,7 @@ futures = "0.3.26" instant = "0.1.11" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-dns = { version = "0.39.0", path = "../../transports/dns", features = ["async-std"] } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } libp2p-noise = { version = "0.42.0", path = "../../transports/noise" } libp2p-quic = { version = "0.7.0-alpha.2", path = "../../transports/quic", features = ["async-std"] } libp2p-swarm = { version = "0.42.0", path = "../../swarm", features = ["macros", "async-std"] } diff --git a/protocols/ping/Cargo.toml b/protocols/ping/Cargo.toml index 7a8af417a05..69639e28a53 100644 --- a/protocols/ping/Cargo.toml +++ b/protocols/ping/Cargo.toml @@ -17,7 +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" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4.1" rand = "0.8" void = "1.0" diff --git a/protocols/relay/Cargo.toml b/protocols/relay/Cargo.toml index e7ec57233d6..944c8dc085f 100644 --- a/protocols/relay/Cargo.toml +++ b/protocols/relay/Cargo.toml @@ -19,7 +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", features = ["async-std"] } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.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/Cargo.toml b/protocols/rendezvous/Cargo.toml index 1575c5dd21e..3ba3b892a32 100644 --- a/protocols/rendezvous/Cargo.toml +++ b/protocols/rendezvous/Cargo.toml @@ -18,7 +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" } +libp2p-identity = { version = "0.2.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/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index d30709e65fe..3395fa636db 100644 --- a/protocols/request-response/Cargo.toml +++ b/protocols/request-response/Cargo.toml @@ -16,7 +16,7 @@ futures = "0.3.27" 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" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } rand = "0.8" smallvec = "1.6.1" diff --git a/swarm-test/Cargo.toml b/swarm-test/Cargo.toml index a6e41dc144a..22dfd178041 100644 --- a/swarm-test/Cargo.toml +++ b/swarm-test/Cargo.toml @@ -14,7 +14,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] async-trait = "0.1.57" libp2p-core = { version = "0.39.1", path = "../core" } -libp2p-identity = { version = "0.1.1", path = "../identity" } +libp2p-identity = { version = "0.2.0", path = "../identity" } libp2p-plaintext = { version = "0.39.1", path = "../transports/plaintext" } libp2p-swarm = { version = "0.42.0", path = "../swarm" } libp2p-tcp = { version = "0.39.0", path = "../transports/tcp", features = ["async-io"] } diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 47ab4489407..3a5a7f759a5 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -17,7 +17,7 @@ futures = "0.3.27" 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-identity = { version = "0.2.0", path = "../identity" } libp2p-swarm-derive = { version = "0.32.0", path = "../swarm-derive", optional = true } log = "0.4" rand = "0.8" @@ -42,7 +42,7 @@ either = "1.6.0" env_logger = "0.10" futures = "0.3.27" libp2p-identify = { path = "../protocols/identify" } -libp2p-identity = { version = "0.1.0", path = "../identity", features = ["ed25519"] } +libp2p-identity = { version = "0.2.0", path = "../identity", features = ["ed25519"] } libp2p-kad = { path = "../protocols/kad" } libp2p-ping = { path = "../protocols/ping" } libp2p-plaintext = { path = "../transports/plaintext" } diff --git a/transports/dns/Cargo.toml b/transports/dns/Cargo.toml index f3375ab4223..4c2fd8cbcaa 100644 --- a/transports/dns/Cargo.toml +++ b/transports/dns/Cargo.toml @@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4.1" futures = "0.3.27" async-std-resolver = { version = "0.22", optional = true } diff --git a/transports/noise/Cargo.toml b/transports/noise/Cargo.toml index c879583d566..d33a519d44b 100644 --- a/transports/noise/Cargo.toml +++ b/transports/noise/Cargo.toml @@ -13,7 +13,7 @@ bytes = "1" curve25519-dalek = "3.0.0" futures = "0.3.27" libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.0", path = "../../identity", features = ["ed25519"] } +libp2p-identity = { version = "0.2.0", path = "../../identity", features = ["ed25519"] } log = "0.4" quick-protobuf = "0.8" once_cell = "1.17.1" diff --git a/transports/plaintext/Cargo.toml b/transports/plaintext/Cargo.toml index 71d94d186bd..f250c3cd8a2 100644 --- a/transports/plaintext/Cargo.toml +++ b/transports/plaintext/Cargo.toml @@ -15,7 +15,7 @@ asynchronous-codec = "0.6" bytes = "1" futures = "0.3.27" libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4.8" quick-protobuf = "0.8" unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] } diff --git a/transports/quic/Cargo.toml b/transports/quic/Cargo.toml index 61a623e269c..0187067581a 100644 --- a/transports/quic/Cargo.toml +++ b/transports/quic/Cargo.toml @@ -16,7 +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" } +libp2p-identity = { version = "0.2.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/tcp/Cargo.toml b/transports/tcp/Cargo.toml index c4a5ee6b4ce..ed745787768 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -17,7 +17,7 @@ futures-timer = "3.0" if-watch = "3.0.0" libc = "0.2.140" libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.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/tls/Cargo.toml b/transports/tls/Cargo.toml index 64647c7fb51..0bf948a4124 100644 --- a/transports/tls/Cargo.toml +++ b/transports/tls/Cargo.toml @@ -12,7 +12,7 @@ exclude = ["src/test_assets"] futures = { version = "0.3.27", default-features = false } futures-rustls = "0.22.2" libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } rcgen = "0.10.0" ring = "0.16.20" thiserror = "1.0.39" diff --git a/transports/webrtc/Cargo.toml b/transports/webrtc/Cargo.toml index 6f18265cd27..aca636ad255 100644 --- a/transports/webrtc/Cargo.toml +++ b/transports/webrtc/Cargo.toml @@ -20,7 +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" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4" multihash = { version = "0.17.0", default-features = false, features = ["sha2"] } quick-protobuf = "0.8" diff --git a/transports/websocket/Cargo.toml b/transports/websocket/Cargo.toml index ab829ffdc7a..39fcf59680d 100644 --- a/transports/websocket/Cargo.toml +++ b/transports/websocket/Cargo.toml @@ -15,7 +15,7 @@ futures-rustls = "0.22" either = "1.5.3" futures = "0.3.27" libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { version = "0.2.0", path = "../../identity" } log = "0.4.8" parking_lot = "0.12.0" quicksink = "0.1" From bac21d28f422dfad00698c37384a10c4733260fb Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 22 Mar 2023 13:32:37 +0100 Subject: [PATCH 3/9] Upgrade to `multihash 0.18.0` --- Cargo.lock | 21 +++++++++++++++++---- identity/Cargo.toml | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 907f5d3ff28..041d330a75b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2264,7 +2264,7 @@ dependencies = [ "libp2p-noise", "log", "multiaddr", - "multihash", + "multihash 0.17.0", "multistream-select", "once_cell", "parking_lot 0.12.1", @@ -2434,7 +2434,7 @@ dependencies = [ "ed25519-dalek", "libsecp256k1", "log", - "multihash", + "multihash 0.18.0", "p256 0.12.0", "prost", "quick-protobuf", @@ -2923,7 +2923,7 @@ dependencies = [ "libp2p-ping", "libp2p-swarm", "log", - "multihash", + "multihash 0.17.0", "quick-protobuf", "quick-protobuf-codec", "quickcheck", @@ -3166,7 +3166,7 @@ dependencies = [ "byteorder", "data-encoding", "multibase", - "multihash", + "multihash 0.17.0", "percent-encoding", "serde", "static_assertions", @@ -3203,6 +3203,19 @@ dependencies = [ "unsigned-varint", ] +[[package]] +name = "multihash" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15e5d911412e631e1de11eb313e4dd71f73fd964401102aab23d6c8327c431ba" +dependencies = [ + "core2", + "digest 0.10.6", + "multihash-derive", + "sha2 0.10.6", + "unsigned-varint", +] + [[package]] name = "multihash-derive" version = "0.8.1" diff --git a/identity/Cargo.toml b/identity/Cargo.toml index 88cdd1c3e37..34e1ff81b45 100644 --- a/identity/Cargo.toml +++ b/identity/Cargo.toml @@ -17,7 +17,7 @@ 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" -multihash = { version = "0.17.0", default-features = false, features = ["std", "multihash-impl", "identity", "sha2"], optional = true } +multihash = { version = "0.18.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" From eb8dfc19f7d808cf707daaa04f2f53a92f66cd98 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 22 Mar 2023 23:46:15 +1100 Subject: [PATCH 4/9] Update identity/CHANGELOG.md --- identity/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/identity/CHANGELOG.md b/identity/CHANGELOG.md index 3dbb76dabd9..ee332316b69 100644 --- a/identity/CHANGELOG.md +++ b/identity/CHANGELOG.md @@ -2,9 +2,9 @@ - Remove `PeerId::try_from_multiaddr`. `multiaddr::Protocol::P2p` is now type-safe and contains a `PeerId` directly, rendering this function obsolete. - See [PR XXXX]. + See [PR 3656]. -[PR XXXX]: https://github.com/libp2p/rust-libp2p/pull/XXXX +[PR 3656]: https://github.com/libp2p/rust-libp2p/pull/3656 # 0.1.1 From eac13185bce93dae8c651a11e3f8a6d61be06cd7 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 6 Jun 2023 13:02:32 +0200 Subject: [PATCH 5/9] Update `libp2p-identity` to latest multihash --- Cargo.lock | 134 +++++++++++++++++++++++++++++----------- Cargo.toml | 2 +- identity/Cargo.toml | 2 +- identity/src/peer_id.rs | 18 +++--- 4 files changed, 111 insertions(+), 45 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1d37d3001b9..5d8d7e2f744 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -617,6 +617,12 @@ dependencies = [ "futures-lite", ] +[[package]] +name = "bs58" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" + [[package]] name = "bs58" version = "0.5.0" @@ -1330,6 +1336,18 @@ dependencies = [ "signature 1.6.4", ] +[[package]] +name = "ecdsa" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12844141594ad74185a926d030f3b605f6a903b4e3fec351f3ea338ac5b7637e" +dependencies = [ + "der 0.6.1", + "elliptic-curve 0.12.3", + "rfc6979 0.3.1", + "signature 2.0.0", +] + [[package]] name = "ecdsa" version = "0.16.6" @@ -2256,7 +2274,7 @@ dependencies = [ "base64 0.21.2", "clap", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "serde", "serde_json", "zeroize", @@ -2313,7 +2331,7 @@ dependencies = [ "libp2p-floodsub", "libp2p-gossipsub", "libp2p-identify", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-kad", "libp2p-mdns", "libp2p-metrics", @@ -2344,7 +2362,7 @@ version = "0.2.0" dependencies = [ "async-std", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-swarm", "libp2p-swarm-derive", "libp2p-swarm-test", @@ -2362,7 +2380,7 @@ dependencies = [ "futures-timer", "instant", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-request-response", "libp2p-swarm", "libp2p-swarm-test", @@ -2378,7 +2396,7 @@ dependencies = [ "async-std", "libp2p-core", "libp2p-identify", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-ping", "libp2p-swarm", "libp2p-swarm-derive", @@ -2398,7 +2416,7 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-mplex", "libp2p-noise", "log", @@ -2434,7 +2452,7 @@ dependencies = [ "libp2p-core", "libp2p-dns", "libp2p-identify", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-noise", "libp2p-ping", "libp2p-plaintext", @@ -2474,7 +2492,7 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "log", "parking_lot", "smallvec", @@ -2491,7 +2509,7 @@ dependencies = [ "fnv", "futures", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-swarm", "log", "quick-protobuf", @@ -2520,7 +2538,7 @@ dependencies = [ "hex_fmt", "instant", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2550,7 +2568,7 @@ dependencies = [ "futures", "futures-timer", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-swarm", "libp2p-swarm-test", "log", @@ -2562,13 +2580,38 @@ dependencies = [ "void", ] +[[package]] +name = "libp2p-identity" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e2d584751cecb2aabaa56106be6be91338a60a0f4e420cf2af639204f596fc1" +dependencies = [ + "asn1_der", + "bs58 0.4.0", + "ed25519-dalek", + "libsecp256k1", + "log", + "multiaddr", + "multihash 0.17.0", + "p256 0.12.0", + "quick-protobuf", + "rand 0.8.5", + "ring", + "sec1 0.3.0", + "serde", + "sha2 0.10.6", + "thiserror", + "void", + "zeroize", +] + [[package]] name = "libp2p-identity" version = "0.2.0" dependencies = [ "asn1_der", "base64 0.21.2", - "bs58", + "bs58 0.5.0", "criterion", "ed25519-dalek", "hex-literal", @@ -2606,7 +2649,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-identify", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2635,7 +2678,7 @@ dependencies = [ "futures", "if-watch", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2659,7 +2702,7 @@ dependencies = [ "libp2p-dcutr", "libp2p-gossipsub", "libp2p-identify", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-kad", "libp2p-ping", "libp2p-relay", @@ -2679,7 +2722,7 @@ dependencies = [ "env_logger 0.10.0", "futures", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-muxer-test-harness", "libp2p-plaintext", "libp2p-tcp", @@ -2713,7 +2756,7 @@ dependencies = [ "futures", "futures_ringbuf", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "log", "once_cell", "quick-protobuf", @@ -2739,7 +2782,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-dns", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-quic", "libp2p-request-response", "libp2p-swarm", @@ -2767,7 +2810,7 @@ dependencies = [ "futures-timer", "instant", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-swarm", "libp2p-swarm-test", "log", @@ -2786,7 +2829,7 @@ dependencies = [ "futures", "futures_ringbuf", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "log", "quick-protobuf", "quickcheck-ext", @@ -2800,7 +2843,7 @@ version = "0.23.0" dependencies = [ "futures", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-noise", "libp2p-swarm", "libp2p-tcp", @@ -2826,7 +2869,7 @@ dependencies = [ "futures-timer", "if-watch", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-muxer-test-harness", "libp2p-noise", "libp2p-tcp", @@ -2854,7 +2897,7 @@ dependencies = [ "futures-timer", "instant", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-ping", "libp2p-plaintext", "libp2p-swarm", @@ -2882,7 +2925,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-identify", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-noise", "libp2p-ping", "libp2p-swarm", @@ -2909,7 +2952,7 @@ dependencies = [ "futures_ringbuf", "instant", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-noise", "libp2p-swarm", "libp2p-swarm-test", @@ -2938,7 +2981,7 @@ dependencies = [ "instant", "libp2p-core", "libp2p-identify", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-kad", "libp2p-ping", "libp2p-plaintext", @@ -2976,7 +3019,7 @@ dependencies = [ "futures", "futures-timer", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-plaintext", "libp2p-swarm", "libp2p-tcp", @@ -2997,7 +3040,7 @@ dependencies = [ "if-watch", "libc", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "log", "socket2 0.5.3", "tokio", @@ -3012,7 +3055,7 @@ dependencies = [ "hex", "hex-literal", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-swarm", "libp2p-yamux", "rcgen 0.10.0", @@ -3064,7 +3107,7 @@ dependencies = [ "hex-literal", "if-watch", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-noise", "libp2p-ping", "libp2p-swarm", @@ -3097,7 +3140,7 @@ dependencies = [ "futures-rustls 0.22.2", "libp2p-core", "libp2p-dns", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-tcp", "log", "parking_lot", @@ -3353,11 +3396,9 @@ dependencies = [ [[package]] name = "multihash" version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e5d911412e631e1de11eb313e4dd71f73fd964401102aab23d6c8327c431ba" +source = "git+https://github.com/multiformats/rust-multihash#a5e3a5cbeba0bedbeff738cdc93d64aa3c4569f6" dependencies = [ "core2", - "multihash-derive", "unsigned-varint", ] @@ -3385,7 +3426,7 @@ dependencies = [ "futures", "futures_ringbuf", "libp2p-core", - "libp2p-identity", + "libp2p-identity 0.1.2", "libp2p-plaintext", "libp2p-swarm", "libp2p-yamux", @@ -3580,6 +3621,18 @@ dependencies = [ "sha2 0.10.6", ] +[[package]] +name = "p256" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49c124b3cbce43bcbac68c58ec181d98ed6cc7e6d0aa7c3ba97b2563410b0e55" +dependencies = [ + "ecdsa 0.15.1", + "elliptic-curve 0.12.3", + "primeorder 0.12.1", + "sha2 0.10.6", +] + [[package]] name = "p256" version = "0.13.2" @@ -3588,7 +3641,7 @@ checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" dependencies = [ "ecdsa 0.16.6", "elliptic-curve 0.13.4", - "primeorder", + "primeorder 0.13.1", "sha2 0.10.6", ] @@ -3844,6 +3897,15 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "primeorder" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b54f7131b3dba65a2f414cf5bd25b66d4682e4608610668eae785750ba4c5b2" +dependencies = [ + "elliptic-curve 0.12.3", +] + [[package]] name = "primeorder" version = "0.13.1" diff --git a/Cargo.toml b/Cargo.toml index 8400238368d..98e5e264421 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,7 +70,7 @@ libp2p-dns = { version = "0.40.0", path = "transports/dns" } libp2p-floodsub = { version = "0.43.0", path = "protocols/floodsub" } libp2p-gossipsub = { version = "0.45.0", path = "protocols/gossipsub" } libp2p-identify = { version = "0.43.0", path = "protocols/identify" } -libp2p-identity = { version = "0.2.0", path = "identity" } +libp2p-identity = { version = "0.1.0" } libp2p-kad = { version = "0.44.0", path = "protocols/kad" } libp2p-mdns = { version = "0.44.0", path = "protocols/mdns" } libp2p-metrics = { version = "0.13.0", path = "misc/metrics" } diff --git a/identity/Cargo.toml b/identity/Cargo.toml index 8f22a144703..1495551f5e5 100644 --- a/identity/Cargo.toml +++ b/identity/Cargo.toml @@ -17,7 +17,7 @@ bs58 = { version = "0.5.0", optional = true } ed25519-dalek = { version = "1.0.1", optional = true } libsecp256k1 = { version = "0.7.0", optional = true } log = "0.4" -multihash = { version = "0.18.0", default-features = false, features = ["std"], optional = true } +multihash = { git = "https://github.com/multiformats/rust-multihash", optional = true } p256 = { version = "0.13", default-features = false, features = ["ecdsa", "std", "pem"], optional = true } quick-protobuf = "0.8.1" rand = { version = "0.8", optional = true } diff --git a/identity/src/peer_id.rs b/identity/src/peer_id.rs index af2f915dc2c..30b2cb76cc6 100644 --- a/identity/src/peer_id.rs +++ b/identity/src/peer_id.rs @@ -18,7 +18,6 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use multihash::{Error, MultihashGeneric}; use rand::Rng; use sha2::Digest as _; use std::{convert::TryFrom, fmt, str::FromStr}; @@ -29,7 +28,7 @@ use thiserror::Error; /// Must be big enough to accommodate for `MAX_INLINE_KEY_LENGTH`. /// 64 satisfies that and can hold 512 bit hashes which is what the ecosystem typically uses. /// Given that this appears in our type-signature, using a "common" number here makes us more compatible. -type Multihash = MultihashGeneric<64>; +type Multihash = multihash::Multihash<64>; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -79,9 +78,9 @@ impl PeerId { } /// Parses a `PeerId` from bytes. - pub fn from_bytes(data: &[u8]) -> Result { + pub fn from_bytes(data: &[u8]) -> Result { PeerId::from_multihash(Multihash::from_bytes(data)?) - .map_err(|mh| Error::UnsupportedCode(mh.code())) + .map_err(|mh| ParseError::UnsupportedCode(mh.code())) } /// Tries to turn a `Multihash` into a `PeerId`. @@ -234,12 +233,15 @@ impl<'de> Deserialize<'de> for PeerId { } } +/// Error when parsing a [`PeerId`] from string or bytes. #[derive(Debug, Error)] pub enum ParseError { #[error("base-58 decode error: {0}")] B58(#[from] bs58::decode::Error), - #[error("decoding multihash failed")] - MultiHash, + #[error("unsupported multihash code '{0}'")] + UnsupportedCode(u64), + #[error("invalid multihash")] + InvalidMultihash(#[from] multihash::Error), } impl FromStr for PeerId { @@ -248,7 +250,9 @@ impl FromStr for PeerId { #[inline] fn from_str(s: &str) -> Result { let bytes = bs58::decode(s).into_vec()?; - PeerId::from_bytes(&bytes).map_err(|_| ParseError::MultiHash) + let peer_id = PeerId::from_bytes(&bytes)?; + + Ok(peer_id) } } From 96f09b4aaee7a5b668bb3a5f0ec0e37f1127536f Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 6 Jun 2023 13:33:07 +0200 Subject: [PATCH 6/9] Temporarily disable version check --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bd3737a49f4..f9dcb413822 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,7 +72,7 @@ jobs: tool: tomlq - name: Enforce version in `workspace.dependencies` matches latest version - if: env.CRATE != 'libp2p' + if: env.CRATE != 'libp2p' && env.CRATE != 'libp2p-identity' run: | PACKAGE_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -e -r '.packages[] | select(.name == "'"$CRATE"'") | .version') SPECIFIED_VERSION=$(tomlq "workspace.dependencies.$CRATE.version" --file ./Cargo.toml) From 3ce77ae72c707f7e15bc9291514a9beff9dac57f Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 6 Jun 2023 16:59:16 +0200 Subject: [PATCH 7/9] Update to `multihash` 0.19 --- Cargo.lock | 7 ++++--- identity/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5d8d7e2f744..16959ee0179 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2617,7 +2617,7 @@ dependencies = [ "hex-literal", "libsecp256k1", "log", - "multihash 0.18.0", + "multihash 0.19.0", "p256 0.13.2", "quick-protobuf", "quickcheck-ext", @@ -3395,8 +3395,9 @@ dependencies = [ [[package]] name = "multihash" -version = "0.18.0" -source = "git+https://github.com/multiformats/rust-multihash#a5e3a5cbeba0bedbeff738cdc93d64aa3c4569f6" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd59dcc2bbe70baabeac52cd22ae52c55eefe6c38ff11a9439f16a350a939f2" dependencies = [ "core2", "unsigned-varint", diff --git a/identity/Cargo.toml b/identity/Cargo.toml index 1495551f5e5..ca987c6b7b2 100644 --- a/identity/Cargo.toml +++ b/identity/Cargo.toml @@ -17,7 +17,7 @@ bs58 = { version = "0.5.0", optional = true } ed25519-dalek = { version = "1.0.1", optional = true } libsecp256k1 = { version = "0.7.0", optional = true } log = "0.4" -multihash = { git = "https://github.com/multiformats/rust-multihash", optional = true } +multihash = { version = "0.19.0", optional = true } p256 = { version = "0.13", default-features = false, features = ["ecdsa", "std", "pem"], optional = true } quick-protobuf = "0.8.1" rand = { version = "0.8", optional = true } From b97a3805fe23f9e12724c3142d20caa89e9e4266 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 6 Jun 2023 19:07:33 +0200 Subject: [PATCH 8/9] Remove unused function --- identity/CHANGELOG.md | 3 +++ identity/src/peer_id.rs | 14 -------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/identity/CHANGELOG.md b/identity/CHANGELOG.md index 77d79a0f669..fcf8bf6ba81 100644 --- a/identity/CHANGELOG.md +++ b/identity/CHANGELOG.md @@ -17,6 +17,9 @@ `multiaddr::Protocol::P2p` is now type-safe and contains a `PeerId` directly, rendering this function obsolete. See [PR 3656]. +- Remove `PeerId::is_public_key` because it is unused and can be implemented externally. + See [PR 3656]. + [PR 3656]: https://github.com/libp2p/rust-libp2p/pull/3656 [PR 3850]: https://github.com/libp2p/rust-libp2p/pull/3850 [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 diff --git a/identity/src/peer_id.rs b/identity/src/peer_id.rs index 30b2cb76cc6..91f5b8aa38b 100644 --- a/identity/src/peer_id.rs +++ b/identity/src/peer_id.rs @@ -117,20 +117,6 @@ impl PeerId { pub fn to_base58(&self) -> String { bs58::encode(self.to_bytes()).into_string() } - - /// Checks whether the public key passed as parameter matches the public key of this `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: &crate::PublicKey) -> Option { - let other_peer_id = PeerId::from_public_key(public_key); - - if self.multihash.code() != other_peer_id.multihash.code() { - return None; - } - - Some(self == &other_peer_id) - } } impl From for PeerId { From c44730a11ca114258869193d561ae10abf95ce59 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 6 Jun 2023 19:08:10 +0200 Subject: [PATCH 9/9] Remove test --- identity/src/peer_id.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/identity/src/peer_id.rs b/identity/src/peer_id.rs index 91f5b8aa38b..60ded4ad37c 100644 --- a/identity/src/peer_id.rs +++ b/identity/src/peer_id.rs @@ -246,14 +246,6 @@ impl FromStr for PeerId { mod tests { use super::*; - #[test] - #[cfg(feature = "ed25519")] - fn peer_id_is_public_key() { - let key = crate::Keypair::generate_ed25519().public(); - let peer_id = key.to_peer_id(); - assert_eq!(peer_id.is_public_key(&key), Some(true)); - } - #[test] #[cfg(feature = "ed25519")] fn peer_id_into_bytes_then_from_bytes() {