Skip to content

Commit

Permalink
feature(prover): hex formatting for proofs in REST API (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
jns-ps authored Dec 10, 2024
1 parent dbc577b commit e007955
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions crates/node_types/prover/src/webserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use axum::{
routing::{get, post},
Json, Router,
};
use jmt::proof::SparseMerkleProof;
use jmt::proof::{SparseMerkleNode, SparseMerkleProof};
use prism_common::{
digest::Digest,
hashchain::{Hashchain, HashchainEntry},
Expand Down Expand Up @@ -71,7 +71,29 @@ pub struct UserKeyRequest {
#[derive(Serialize, Deserialize, ToSchema)]
pub struct UserKeyResponse {
pub hashchain: Option<Hashchain>,
pub proof: SparseMerkleProof<Hasher>,
pub proof: JmtProofResponse,
}

#[derive(Serialize, Deserialize, ToSchema)]
pub struct JmtProofResponse {
pub leaf: Option<Digest>,
pub siblings: Vec<Digest>,
}

impl From<SparseMerkleProof<Hasher>> for JmtProofResponse {
fn from(proof: SparseMerkleProof<Hasher>) -> Self {
let leaf_hash = proof.leaf().map(|node| node.hash::<Hasher>()).map(Digest::new);
let sibling_hashes = proof
.siblings()
.iter()
.map(SparseMerkleNode::hash::<Hasher>)
.map(Digest::new)
.collect();
Self {
leaf: leaf_hash,
siblings: sibling_hashes,
}
}
}

#[derive(OpenApi)]
Expand All @@ -83,7 +105,8 @@ pub struct UserKeyResponse {
UpdateProofResponse,
Hash,
UserKeyRequest,
UserKeyResponse
UserKeyResponse,
JmtProofResponse
))
)]
struct ApiDoc;
Expand Down Expand Up @@ -190,15 +213,15 @@ async fn get_hashchain(
StatusCode::OK,
Json(UserKeyResponse {
hashchain: Some(hashchain),
proof: membership_proof.proof,
proof: JmtProofResponse::from(membership_proof.proof),
}),
)
.into_response(),
HashchainResponse::NotFound(non_membership_proof) => (
StatusCode::OK,
Json(UserKeyResponse {
hashchain: None,
proof: non_membership_proof.proof,
proof: JmtProofResponse::from(non_membership_proof.proof),
}),
)
.into_response(),
Expand Down

0 comments on commit e007955

Please sign in to comment.