From bda262810bbb52cb9046fc3a8cd7ee96cc7441de Mon Sep 17 00:00:00 2001 From: Simon Wicky Date: Fri, 5 Sep 2025 15:03:47 +0200 Subject: [PATCH] changes due to crate moving --- Cargo.lock | 1 + common/crypto/Cargo.toml | 1 + common/crypto/src/asymmetric/x25519/mod.rs | 10 +++++++++ .../src/mixnet_listener.rs | 3 +++ nym-ip-packet-client/src/connect.rs | 21 +++++++------------ nym-wg-gateway-client/src/deprecated.rs | 2 +- nym-wg-gateway-client/src/error.rs | 5 +---- nym-wg-gateway-client/src/lib.rs | 8 +++---- 8 files changed, 27 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ecd71d5488..54cca208b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5571,6 +5571,7 @@ dependencies = [ "aead", "aes", "aes-gcm-siv", + "base64 0.22.1", "blake3", "bs58", "cipher", diff --git a/common/crypto/Cargo.toml b/common/crypto/Cargo.toml index 6e1f8cfb12..804488f5ad 100644 --- a/common/crypto/Cargo.toml +++ b/common/crypto/Cargo.toml @@ -11,6 +11,7 @@ repository = { workspace = true } aes-gcm-siv = { workspace = true, optional = true } aes = { workspace = true, optional = true } aead = { workspace = true, optional = true } +base64.workspace = true bs58 = { workspace = true } blake3 = { workspace = true, features = ["traits-preview"], optional = true } ctr = { workspace = true, optional = true } diff --git a/common/crypto/src/asymmetric/x25519/mod.rs b/common/crypto/src/asymmetric/x25519/mod.rs index 9b73adb910..3f41319a97 100644 --- a/common/crypto/src/asymmetric/x25519/mod.rs +++ b/common/crypto/src/asymmetric/x25519/mod.rs @@ -1,6 +1,7 @@ // Copyright 2021-2023 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 +use base64::Engine; use nym_pemstore::traits::{PemStorableKey, PemStorableKeyPair}; use std::fmt::{self, Debug, Display, Formatter}; use std::str::FromStr; @@ -158,6 +159,15 @@ impl PublicKey { .map_err(|source| KeyRecoveryError::MalformedPublicKeyString { source })?; Self::from_bytes(&bytes) } + + pub fn from_base64(s: &str) -> Option { + let bytes = base64::engine::general_purpose::STANDARD.decode(s).ok()?; + Self::from_bytes(&bytes).ok() + } + + pub fn to_base64(&self) -> String { + base64::engine::general_purpose::STANDARD.encode(self.as_bytes()) + } } impl FromStr for PublicKey { diff --git a/nym-authenticator-client/src/mixnet_listener.rs b/nym-authenticator-client/src/mixnet_listener.rs index 2e20aac30a..113148b8ce 100644 --- a/nym-authenticator-client/src/mixnet_listener.rs +++ b/nym-authenticator-client/src/mixnet_listener.rs @@ -1,6 +1,9 @@ // Copyright 2025 - Nym Technologies SA // SPDX-License-Identifier: GPL-3.0-only +// To remove with the Registration Client PR +#![allow(clippy::unwrap_used)] + use std::sync::Arc; use futures::StreamExt; diff --git a/nym-ip-packet-client/src/connect.rs b/nym-ip-packet-client/src/connect.rs index 8d3c8c87ec..f499e2373f 100644 --- a/nym-ip-packet-client/src/connect.rs +++ b/nym-ip-packet-client/src/connect.rs @@ -1,9 +1,11 @@ // Copyright 2023-2024 - Nym Technologies SA // SPDX-License-Identifier: GPL-3.0-only +// To remove with the Registration Client PR +#![allow(clippy::unwrap_used)] + use std::{sync::Arc, time::Duration}; -use nym_gateway_directory::IpPacketRouterAddress; use nym_ip_packet_requests::IpPair; use nym_sdk::mixnet::{ InputMessage, MixnetClient, MixnetClientSender, MixnetMessageSender, Recipient, @@ -59,10 +61,7 @@ impl IprClientConnect { } } - pub async fn connect( - &mut self, - ip_packet_router_address: IpPacketRouterAddress, - ) -> Result { + pub async fn connect(&mut self, ip_packet_router_address: Recipient) -> Result { if self.connected != ConnectionState::Disconnected { return Err(Error::AlreadyConnected); } @@ -83,20 +82,14 @@ impl IprClientConnect { } } - async fn connect_inner( - &mut self, - ip_packet_router_address: IpPacketRouterAddress, - ) -> Result { + async fn connect_inner(&mut self, ip_packet_router_address: Recipient) -> Result { let request_id = self.send_connect_request(ip_packet_router_address).await?; debug!("Waiting for reply..."); self.listen_for_connect_response(request_id).await } - async fn send_connect_request( - &self, - ip_packet_router_address: IpPacketRouterAddress, - ) -> Result { + async fn send_connect_request(&self, ip_packet_router_address: Recipient) -> Result { let (request, request_id) = IpPacketRequest::new_connect_request(None); // We use 20 surbs for the connect request because typically the IPR is configured to have @@ -104,7 +97,7 @@ impl IprClientConnect { let surbs = 20; self.mixnet_sender .send(create_input_message( - Recipient::from(ip_packet_router_address), + ip_packet_router_address, request, surbs, )) diff --git a/nym-wg-gateway-client/src/deprecated.rs b/nym-wg-gateway-client/src/deprecated.rs index 10262683bc..65a9d47950 100644 --- a/nym-wg-gateway-client/src/deprecated.rs +++ b/nym-wg-gateway-client/src/deprecated.rs @@ -7,8 +7,8 @@ use nym_authenticator_client::{ use nym_authenticator_requests::{v3, v4, v5}; use nym_credentials_interface::CredentialSpendingData; use nym_crypto::asymmetric::encryption; -use nym_gateway_directory::Recipient; use nym_node_requests::api::v1::gateway::client_interfaces::wireguard::models::PeerPublicKey; +use nym_sdk::mixnet::Recipient; use crate::error::{Error, Result}; diff --git a/nym-wg-gateway-client/src/error.rs b/nym-wg-gateway-client/src/error.rs index 719604d6b4..9223c04a12 100644 --- a/nym-wg-gateway-client/src/error.rs +++ b/nym-wg-gateway-client/src/error.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only use nym_credentials_interface::TicketType; -use nym_gateway_directory::NodeIdentity; +use nym_sdk::mixnet::NodeIdentity; #[derive(Debug, thiserror::Error)] pub enum Error { @@ -15,9 +15,6 @@ pub enum Error { #[error(transparent)] AuthenticatorClientError(#[from] nym_authenticator_client::Error), - #[error(transparent)] - MetadataClientError(#[from] nym_wg_metadata_client::error::MetadataClientError), - #[error("error that should stop auto retrying")] NoRetry { #[source] diff --git a/nym-wg-gateway-client/src/lib.rs b/nym-wg-gateway-client/src/lib.rs index 49c6225274..3d425a6e2f 100644 --- a/nym-wg-gateway-client/src/lib.rs +++ b/nym-wg-gateway-client/src/lib.rs @@ -18,13 +18,11 @@ use nym_authenticator_client::{ use nym_authenticator_requests::{v2, v3, v4, v5}; use nym_bandwidth_controller::PreparedCredential; use nym_credentials_interface::TicketType; -use nym_crypto::asymmetric::{encryption, x25519::KeyPair}; -use nym_gateway_directory::{NodeIdentity, Recipient}; +use nym_crypto::asymmetric::{encryption, x25519::KeyPair, x25519::PublicKey}; use nym_node_requests::api::v1::gateway::client_interfaces::wireguard::models::PeerPublicKey; use nym_pemstore::KeyPairPath; -use nym_sdk::mixnet::CredentialStorage; +use nym_sdk::mixnet::{CredentialStorage, NodeIdentity, Recipient}; use nym_validator_client::QueryHttpRpcNyxdClient; -use nym_wg_go::PublicKey; use rand::{rngs::OsRng, CryptoRng, RngCore}; use tracing::{debug, error, trace}; @@ -272,7 +270,7 @@ impl WgGatewayClient { ); let gateway_data = GatewayData { - public_key: PublicKey::from(registered_data.pub_key().to_bytes()), + public_key: registered_data.pub_key().inner().into(), endpoint: SocketAddr::from_str(&format!( "{}:{}", gateway_host,