diff --git a/Cargo.toml b/Cargo.toml index 9b3565b1..950f8767 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,11 +5,6 @@ members = [ "patches/option-ext", "patches/directories-next", - # monero-oxide expects `ciphersuite`, yet the `ciphersuite` in-tree here has breaking changes - # This re-exports the in-tree `ciphersuite` _without_ changes breaking to monero-oxide - # Not included in workspace to prevent having two crates with the same name (an error) - # "patches/ciphersuite", - "common/std-shims", "common/zalloc", "common/patchable-async-sleep", @@ -169,8 +164,8 @@ overflow-checks = true [patch.crates-io] # Dependencies from monero-oxide which originate from within our own tree -std-shims = { path = "common/std-shims" } -simple-request = { path = "common/request" } +std-shims = { path = "patches/std-shims" } +simple-request = { path = "patches/simple-request" } multiexp = { path = "crypto/multiexp" } flexible-transcript = { path = "crypto/transcript" } ciphersuite = { path = "patches/ciphersuite" } diff --git a/common/request/Cargo.toml b/common/request/Cargo.toml index 467d967a..75c7d67a 100644 --- a/common/request/Cargo.toml +++ b/common/request/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "simple-request" -version = "0.1.1" +version = "0.2.0" description = "A simple HTTP(S) request library" license = "MIT" -repository = "https://github.com/serai-dex/serai/tree/develop/common/simple-request" +repository = "https://github.com/serai-dex/serai/tree/develop/common/request" authors = ["Luke Parker "] keywords = ["http", "https", "async", "request", "ssl"] edition = "2021" @@ -31,5 +31,6 @@ base64ct = { version = "1", features = ["alloc"], optional = true } [features] tls = ["hyper-rustls"] +webpki-roots = ["tls", "hyper-rustls/webpki-roots"] basic-auth = ["zeroize", "base64ct"] default = ["tls"] diff --git a/common/request/src/lib.rs b/common/request/src/lib.rs index 4feffd7d..63350a1c 100644 --- a/common/request/src/lib.rs +++ b/common/request/src/lib.rs @@ -52,24 +52,30 @@ pub struct Client { } impl Client { + #[allow(clippy::unnecessary_wraps)] fn connector() -> Result { let mut res = HttpConnector::new(); res.set_keepalive(Some(core::time::Duration::from_secs(60))); res.set_nodelay(true); res.set_reuse_address(true); + #[cfg(feature = "tls")] res.enforce_http(false); #[cfg(feature = "tls")] - let res = HttpsConnectorBuilder::new() - .with_native_roots() - .map_err(|e| { - Error::ConnectionError( - format!("couldn't load system's SSL root certificates: {e:?}").into(), - ) - })? - .https_or_http() - .enable_http1() - .wrap_connector(res); + let https = HttpsConnectorBuilder::new().with_native_roots(); + #[cfg(all(feature = "tls", not(feature = "webpki-roots")))] + let https = https.map_err(|e| { + Error::ConnectionError( + format!("couldn't load system's SSL root certificates and webpki-roots unavilable: {e:?}") + .into(), + ) + })?; + // Fallback to `webpki-roots` if present + #[cfg(all(feature = "tls", feature = "webpki-roots"))] + let https = https.unwrap_or(HttpsConnectorBuilder::new().with_webpki_roots()); + #[cfg(feature = "tls")] + let res = https.https_or_http().enable_http1().wrap_connector(res); + Ok(res) } diff --git a/common/std-shims/src/lib.rs b/common/std-shims/src/lib.rs index 0ea8da07..ed40db40 100644 --- a/common/std-shims/src/lib.rs +++ b/common/std-shims/src/lib.rs @@ -17,8 +17,8 @@ pub mod error { #[rustversion::since(1.81)] pub use core::error; -#[cfg(all(feature = "alloc", not(feature = "std")))] -pub extern crate alloc as extern_alloc; +#[cfg(feature = "alloc")] +extern crate alloc as extern_alloc; #[cfg(all(feature = "alloc", not(feature = "std")))] pub use extern_alloc::{alloc, borrow, boxed, ffi, fmt, rc, slice, str, string, task, vec, format}; #[cfg(feature = "std")] @@ -30,7 +30,7 @@ pub mod sync; pub mod prelude { // Shim the `std` prelude - #[cfg(all(feature = "alloc", not(feature = "std")))] + #[cfg(feature = "alloc")] pub use extern_alloc::{ format, vec, borrow::ToOwned, diff --git a/coordinator/tributary-sdk/src/tests/transaction/mod.rs b/coordinator/tributary-sdk/src/tests/transaction/mod.rs index f5e233bd..bd0bbd37 100644 --- a/coordinator/tributary-sdk/src/tests/transaction/mod.rs +++ b/coordinator/tributary-sdk/src/tests/transaction/mod.rs @@ -7,7 +7,7 @@ use rand::{RngCore, CryptoRng, rngs::OsRng}; use blake2::{Digest, Blake2s256}; use dalek_ff_group::Ristretto; -use ciphersuite::{group::Group, *}; +use ciphersuite::*; use schnorr::SchnorrSignature; use ::tendermint::{ diff --git a/crypto/schnorrkel/Cargo.toml b/crypto/schnorrkel/Cargo.toml index 1fe90be3..24e4e24d 100644 --- a/crypto/schnorrkel/Cargo.toml +++ b/crypto/schnorrkel/Cargo.toml @@ -17,7 +17,7 @@ rustdoc-args = ["--cfg", "docsrs"] workspace = true [dependencies] -std-shims = { version = "0.1", default-features = false, features = ["alloc"] } +std-shims = { version = "0.1", path = "../../common/std-shims", default-features = false, features = ["alloc"] } rand_core = { version = "0.6", default-features = false } zeroize = { version = "1.5", default-features = false, features = ["zeroize_derive", "alloc"] } diff --git a/networks/bitcoin/Cargo.toml b/networks/bitcoin/Cargo.toml index 40823f9d..66c24a67 100644 --- a/networks/bitcoin/Cargo.toml +++ b/networks/bitcoin/Cargo.toml @@ -32,7 +32,7 @@ frost = { package = "modular-frost", path = "../../crypto/frost", version = "0.1 hex = { version = "0.4", default-features = false, optional = true } serde = { version = "1", default-features = false, features = ["derive"], optional = true } serde_json = { version = "1", default-features = false, optional = true } -simple-request = { path = "../../common/request", version = "0.1", default-features = false, features = ["tls", "basic-auth"], optional = true } +simple-request = { path = "../../common/request", version = "0.2", default-features = false, features = ["tls", "basic-auth"], optional = true } [dev-dependencies] secp256k1 = { version = "0.29", default-features = false, features = ["std"] } diff --git a/networks/ethereum/alloy-simple-request-transport/Cargo.toml b/networks/ethereum/alloy-simple-request-transport/Cargo.toml index 69dc25b4..bff76492 100644 --- a/networks/ethereum/alloy-simple-request-transport/Cargo.toml +++ b/networks/ethereum/alloy-simple-request-transport/Cargo.toml @@ -19,7 +19,7 @@ workspace = true tower = "0.5" serde_json = { version = "1", default-features = false } -simple-request = { path = "../../../common/request", version = "0.1", default-features = false } +simple-request = { path = "../../../common/request", version = "0.2", default-features = false } alloy-json-rpc = { version = "1", default-features = false } alloy-transport = { version = "1", default-features = false } diff --git a/patches/simple-request/Cargo.toml b/patches/simple-request/Cargo.toml new file mode 100644 index 00000000..80ff44ec --- /dev/null +++ b/patches/simple-request/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "simple-request" +version = "0.1.99" +description = "simple-request which patches to the latest update" +license = "MIT" +repository = "https://github.com/serai-dex/serai/tree/develop/patches/simple-request" +authors = ["Luke Parker "] +keywords = ["nostd", "no_std", "alloc", "io"] +edition = "2021" +rust-version = "1.65" + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] + +[lints] +workspace = true + +[dependencies] +simple-request = { path = "../../common/request" } + +[features] +tls = ["simple-request/tls"] diff --git a/patches/simple-request/src/lib.rs b/patches/simple-request/src/lib.rs new file mode 100644 index 00000000..c4ddd3e6 --- /dev/null +++ b/patches/simple-request/src/lib.rs @@ -0,0 +1,18 @@ +pub use simple_request::{hyper, Error, Request, Response}; + +#[derive(Clone, Debug)] +pub struct Client(simple_request::Client); + +impl Client { + pub fn with_connection_pool() -> Client { + Self(simple_request::Client::with_connection_pool().unwrap()) + } + + pub fn without_connection_pool(host: &str) -> Result { + simple_request::Client::without_connection_pool(host).map(Self) + } + + pub async fn request>(&self, request: R) -> Result, Error> { + self.0.request(request).await + } +} diff --git a/patches/std-shims/Cargo.toml b/patches/std-shims/Cargo.toml new file mode 100644 index 00000000..537c8286 --- /dev/null +++ b/patches/std-shims/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "std-shims" +version = "0.1.99" +description = "std-shims which patches to the latest update" +license = "MIT" +repository = "https://github.com/serai-dex/serai/tree/develop/patches/std-shims" +authors = ["Luke Parker "] +keywords = ["nostd", "no_std", "alloc", "io"] +edition = "2021" +rust-version = "1.65" + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] + +[lints] +workspace = true + +[dependencies] +std-shims = { path = "../../common/std-shims", default-features = false, features = ["alloc"] } + +[features] +std = ["std-shims/std"] diff --git a/patches/std-shims/src/lib.rs b/patches/std-shims/src/lib.rs new file mode 100644 index 00000000..673132ea --- /dev/null +++ b/patches/std-shims/src/lib.rs @@ -0,0 +1,5 @@ +#![cfg_attr(docsrs, feature(doc_auto_cfg))] +#![cfg_attr(not(feature = "std"), no_std)] + +pub extern crate alloc; +pub use std_shims::{str, vec, string, collections, io, sync, prelude}; diff --git a/substrate/client/Cargo.toml b/substrate/client/Cargo.toml index f8d37697..e25096f4 100644 --- a/substrate/client/Cargo.toml +++ b/substrate/client/Cargo.toml @@ -37,7 +37,7 @@ frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = async-lock = "3" -simple-request = { path = "../../common/request", version = "0.1", optional = true } +simple-request = { path = "../../common/request", version = "0.2", optional = true } bitcoin = { version = "0.32", optional = true }