Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a hashes endpoint #600

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
42 changes: 32 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Are these dependencies needed when the std feature is not enabled? Might be worth making them optional.


[features]
default=["std"]
Expand Down
4 changes: 3 additions & 1 deletion crates/shared/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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"))]
Expand Down
1 change: 1 addition & 0 deletions crates/threshold-signature-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 7 additions & 3 deletions crates/threshold-signature-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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},
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

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<Vec<HashingAlgorithm>> {
let hashing_algos = HashingAlgorithm::iter().collect::<Vec<_>>();
Json(hashing_algos)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

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]
Expand All @@ -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<HashingAlgorithm> = response.json().await.unwrap();
assert_eq!(
algorithms,
vec![
HashingAlgorithm::Sha1,
HashingAlgorithm::Sha2,
HashingAlgorithm::Sha3,
HashingAlgorithm::Keccak,
HashingAlgorithm::Custom(0),
]
);
}