diff --git a/CHANGELOG.md b/CHANGELOG.md index 90b8149d9..0e5f585a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ At the moment this project **does not** adhere to - Add `--setup-only` flag ([#588](https://github.com/entropyxyz/entropy-core/pull/588/)) - Add --version flag and about field to TSS ([#590](https://github.com/entropyxyz/entropy-core/pull/590/)) - Program config storage ([#593](https://github.com/entropyxyz/entropy-core/pull/593)) +- Add a hashes endpoint ([#600](https://github.com/entropyxyz/entropy-core/pull/600)) ### Changed - Crate name refactor ([#561](https://github.com/entropyxyz/entropy-core/pull/561)) diff --git a/Cargo.lock b/Cargo.lock index c49142aca..7b8f4750e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1357,8 +1357,8 @@ version = "7.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ab77dbd8adecaf3f0db40581631b995f312a8a5ae3aa9993188bb8f23d83a5b" dependencies = [ - "strum", - "strum_macros", + "strum 0.24.1", + "strum_macros 0.24.3", "unicode-width", ] @@ -2718,6 +2718,8 @@ dependencies = [ "serde", "serde_derive", "sp-std 8.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", + "strum 0.25.0", + "strum_macros 0.25.3", ] [[package]] @@ -2817,6 +2819,7 @@ dependencies = [ "snow", "sp-core 21.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "sp-keyring 24.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "strum 0.25.0", "subxt", "synedrion", "template-barebones", @@ -6421,7 +6424,7 @@ dependencies = [ "sp-npos-elections", "sp-runtime 24.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", "sp-std 8.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", - "strum", + "strum 0.24.1", ] [[package]] @@ -10926,7 +10929,7 @@ dependencies = [ "lazy_static", "sp-core 21.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "sp-runtime 24.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "strum", + "strum 0.24.1", ] [[package]] @@ -10937,7 +10940,7 @@ dependencies = [ "lazy_static", "sp-core 21.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", "sp-runtime 24.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", - "strum", + "strum 0.24.1", ] [[package]] @@ -11489,7 +11492,7 @@ checksum = "08615eea740067d9899969bc2891c68a19c315cb1f66640af9a9ecb91b13bcab" dependencies = [ "lazy_static", "maplit", - "strum", + "strum 0.24.1", ] [[package]] @@ -11615,9 +11618,15 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" dependencies = [ - "strum_macros", + "strum_macros 0.24.3", ] +[[package]] +name = "strum" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" + [[package]] name = "strum_macros" version = "0.24.3" @@ -11631,6 +11640,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "strum_macros" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.32", +] + [[package]] name = "stun" version = "0.4.4" @@ -11753,7 +11775,7 @@ dependencies = [ "filetime", "parity-wasm", "sp-maybe-compressed-blob", - "strum", + "strum 0.24.1", "tempfile", "toml 0.7.6", "walkdir", @@ -13161,8 +13183,8 @@ checksum = "87fef6d0d508f08334e0ab0e6877feb4c0ecb3956bcf2cb950699b22fedf3e9c" dependencies = [ "anyhow", "libc", - "strum", - "strum_macros", + "strum 0.24.1", + "strum_macros 0.24.3", "tempfile", "thiserror", "wasm-opt-cxx-sys", diff --git a/crates/shared/Cargo.toml b/crates/shared/Cargo.toml index bf8b254da..c70338100 100644 --- a/crates/shared/Cargo.toml +++ b/crates/shared/Cargo.toml @@ -15,6 +15,8 @@ serde_derive ="1.0.147" sp-std ={ package="sp-std", git="https://github.com/paritytech/substrate", branch="polkadot-v1.0.0", default-features=false } frame-support ={ package="frame-support", git="https://github.com/paritytech/substrate", branch="polkadot-v1.0.0", default-features=false, optional=true } node-primitives={ version="2.0.0", default-features=false, git='https://github.com/paritytech/substrate.git', branch="polkadot-v1.0.0", optional=true } +strum ="0.25.0" +strum_macros ="0.25.3" [features] default=["std"] diff --git a/crates/shared/src/types.rs b/crates/shared/src/types.rs index b4e660621..a8e1c7d76 100644 --- a/crates/shared/src/types.rs +++ b/crates/shared/src/types.rs @@ -24,6 +24,8 @@ use node_primitives::BlockNumber; use scale_info::TypeInfo; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; +#[cfg(feature = "std")] +use strum_macros::EnumIter; /// X25519 public key used by the client in non-interactive ECDH to authenticate/encrypt /// interactions with the threshold server (eg distributing threshold shares). @@ -91,7 +93,7 @@ pub struct OcwMessageProactiveRefresh { } /// 256-bit hashing algorithms for deriving the point to be signed. -#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "std", derive(Serialize, Deserialize, EnumIter))] #[derive(Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "std", serde(rename = "hash"))] #[cfg_attr(feature = "std", serde(rename_all = "lowercase"))] diff --git a/crates/threshold-signature-server/Cargo.toml b/crates/threshold-signature-server/Cargo.toml index 14983c18d..632c9cea2 100644 --- a/crates/threshold-signature-server/Cargo.toml +++ b/crates/threshold-signature-server/Cargo.toml @@ -22,6 +22,7 @@ hex ="*" reqwest-eventsource="0.4" serde_derive ="1.0.147" synedrion ="0.1" +strum ="0.25.0" # Async futures="0.3" diff --git a/crates/threshold-signature-server/src/lib.rs b/crates/threshold-signature-server/src/lib.rs index 74ccefed6..af66fd473 100644 --- a/crates/threshold-signature-server/src/lib.rs +++ b/crates/threshold-signature-server/src/lib.rs @@ -81,7 +81,10 @@ //! messages. This is opened by other threshold servers when the signing procotol is initiated. //! - [`/validator/sync_kvdb`](crate::validator::api::sync_kvdb()) - POST - Called by another //! threshold server when joining to get the key-shares from a member of their sub-group. -//! +//! - [`/version`](crate::node_info::api::version()) - Get - get the node version info +//! - [`/heathlz`](crate::health::api::healthz()) - Get - get if the node is running +//! - [`/hashes`](crate::node_info::api::heahes()) - Get - get the hashes supported by the node + //! ### For testing / development //! //! [Unsafe](crate::unsafe::api) has additional routes which are for testing and development @@ -107,13 +110,13 @@ pub mod chain_api; pub mod common; pub(crate) mod health; pub(crate) mod helpers; +pub(crate) mod node_info; pub(crate) mod sign_init; pub(crate) mod signing_client; pub(crate) mod r#unsafe; pub(crate) mod user; pub mod validation; pub(crate) mod validator; -pub(crate) mod version; use axum::{ http::Method, @@ -131,11 +134,11 @@ use validator::api::get_random_server_info; use crate::{ health::api::healthz, launch::Configuration, + node_info::api::{hashes, version as get_version}, r#unsafe::api::{delete, put, remove_keys, unsafe_get}, signing_client::{api::*, ListenerState}, user::api::*, validator::api::sync_kvdb, - version::api::version as get_version, }; pub use crate::{ helpers::{launch, validator::get_signer}, @@ -164,6 +167,7 @@ pub fn app(app_state: AppState) -> Router { .route("/validator/sync_kvdb", post(sync_kvdb)) .route("/healthz", get(healthz)) .route("/version", get(get_version)) + .route("/hashes", get(hashes)) .route("/ws", get(ws_handler)); // Unsafe routes are for testing purposes only diff --git a/crates/threshold-signature-server/src/version/api.rs b/crates/threshold-signature-server/src/node_info/api.rs similarity index 77% rename from crates/threshold-signature-server/src/version/api.rs rename to crates/threshold-signature-server/src/node_info/api.rs index a92ab0cbf..e5ca0541d 100644 --- a/crates/threshold-signature-server/src/version/api.rs +++ b/crates/threshold-signature-server/src/node_info/api.rs @@ -12,9 +12,17 @@ // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . - +use axum::Json; +use entropy_shared::types::HashingAlgorithm; +use strum::IntoEnumIterator; /// Returns the version and commit data #[tracing::instrument] pub async fn version() -> String { format!("{}-{}", env!("CARGO_PKG_VERSION"), env!("VERGEN_GIT_DESCRIBE")) } + +#[tracing::instrument] +pub async fn hashes() -> Json> { + let hashing_algos = HashingAlgorithm::iter().collect::>(); + Json(hashing_algos) +} diff --git a/crates/threshold-signature-server/src/version/mod.rs b/crates/threshold-signature-server/src/node_info/mod.rs similarity index 100% rename from crates/threshold-signature-server/src/version/mod.rs rename to crates/threshold-signature-server/src/node_info/mod.rs diff --git a/crates/threshold-signature-server/src/version/tests.rs b/crates/threshold-signature-server/src/node_info/tests.rs similarity index 67% rename from crates/threshold-signature-server/src/version/tests.rs rename to crates/threshold-signature-server/src/node_info/tests.rs index d8cbe9c40..67498bdfc 100644 --- a/crates/threshold-signature-server/src/version/tests.rs +++ b/crates/threshold-signature-server/src/node_info/tests.rs @@ -13,9 +13,9 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -use serial_test::serial; - use crate::helpers::tests::{initialize_test_logger, setup_client}; +use entropy_shared::types::HashingAlgorithm; +use serial_test::serial; #[tokio::test] #[serial] @@ -29,3 +29,23 @@ async fn version_test() { format!("{}-{}", env!("CARGO_PKG_VERSION"), env!("VERGEN_GIT_DESCRIBE")) ); } + +#[tokio::test] +#[serial] +async fn hashes_test() { + initialize_test_logger().await; + setup_client().await; + let response = reqwest::get("http://127.0.0.1:3001/hashes").await.unwrap(); + + let algorithms: Vec = response.json().await.unwrap(); + assert_eq!( + algorithms, + vec![ + HashingAlgorithm::Sha1, + HashingAlgorithm::Sha2, + HashingAlgorithm::Sha3, + HashingAlgorithm::Keccak, + HashingAlgorithm::Custom(0), + ] + ); +}