Skip to content

Commit

Permalink
Feature/get public keys (#59)
Browse files Browse the repository at this point in the history
* add /api/v1/eth2/publicKeys endpoint for compatibility with validator clients

* add file
  • Loading branch information
JasonVranek authored Mar 23, 2024
1 parent b28ba61 commit 03a92fc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/bin/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ async fn main() {
puffersecuresigner::enclave::shared::handlers::list_bls_keys::handler,
),
)
// Endpoint to list all bls pubkeys - used by the validator client
.route(
"/api/v1/eth2/publicKeys",
axum::routing::get(
puffersecuresigner::enclave::shared::handlers::list_bls_keys_for_vc::handler,
),
)
// Endpoint to request a signature using BLS sk
.route(
"/api/v1/eth2/sign/:bls_pk_hex",
Expand Down
22 changes: 22 additions & 0 deletions src/enclave/shared/handlers/list_bls_keys_for_vc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use axum::{response::IntoResponse, Json};
use log::{error, info};

use crate::{io::key_management, strip_0x_prefix};

pub async fn handler() -> axum::response::Response {
info!("list_bls_keys_for_vc()");
match key_management::list_bls_keys() {
Ok(list_res) => {
// safely prepend the response with "0x" to match the expected format
let list_res = list_res.iter().map(|x| {
let stripped: &str = strip_0x_prefix!(x);
format!("0x{}", stripped)
}).collect::<Vec<String>>();
(axum::http::status::StatusCode::OK, Json(list_res)).into_response()
}
Err(e) => {
error!("list_bls_keys_for_vc() failed with: {:?}", e);
axum::http::status::StatusCode::INTERNAL_SERVER_ERROR.into_response()
}
}
}
1 change: 1 addition & 0 deletions src/enclave/shared/handlers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod health;
pub mod list_bls_keys;
pub mod list_bls_keys_for_vc;
pub mod list_eth_keys;
pub mod secure_sign_bls;

Expand Down

0 comments on commit 03a92fc

Please sign in to comment.