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

feature: add properties for JSON REST responses #204

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
22 changes: 13 additions & 9 deletions crates/common/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ use crate::{
};

#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct SignedData(pub VerifyingKey, #[serde(with = "raw_or_b64")] pub Vec<u8>);
pub struct SignedData {
pub key: VerifyingKey,
#[serde(with = "raw_or_b64")]
pub data: Vec<u8>,
}

#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Default)]
/// Represents an account or service on prism, making up the values of our state
Expand Down Expand Up @@ -169,19 +173,19 @@ impl Account {
data,
data_signature,
} => {
self.signed_data.push(SignedData(
data_signature.verifying_key.clone(),
data.clone(),
));
self.signed_data.push(SignedData {
key: data_signature.verifying_key.clone(),
data: data.clone(),
});
}
Operation::SetData {
data,
data_signature,
} => {
self.signed_data = vec![SignedData(
data_signature.verifying_key.clone(),
data.clone(),
)];
self.signed_data = vec![SignedData {
key: data_signature.verifying_key.clone(),
data: data.clone(),
}];
}
Operation::CreateAccount { id, key, .. } => {
self.id = id.clone();
Expand Down
7 changes: 6 additions & 1 deletion crates/node_types/prover/src/webserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ pub struct JmtProofResponse {
pub siblings: Vec<Digest>,
}

#[derive(Serialize, Deserialize, ToSchema)]
pub struct CommitmentResponse {
commitment: Digest,
}

impl From<SparseMerkleProof<TreeHasher>> for JmtProofResponse {
fn from(proof: SparseMerkleProof<TreeHasher>) -> Self {
let leaf_hash = proof.leaf().map(|node| node.hash::<TreeHasher>()).map(Digest::new);
Expand Down Expand Up @@ -232,7 +237,7 @@ async fn get_account(
)]
async fn get_commitment(State(session): State<Arc<Prover>>) -> impl IntoResponse {
match session.get_commitment().await {
Ok(commitment) => (StatusCode::OK, Json(commitment)).into_response(),
Ok(commitment) => (StatusCode::OK, Json(CommitmentResponse { commitment })).into_response(),
Err(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()).into_response(),
}
}
6 changes: 3 additions & 3 deletions crates/tree/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ fn test_data_ops(algorithm: CryptoAlgorithm) {
assert!(membership_proof.verify_existence(&account).is_ok());

// Verify data contents
assert_eq!(account.signed_data()[0].1, b"test data 1".to_vec());
assert_eq!(account.signed_data()[1].1, b"test data 2".to_vec());
assert_eq!(account.signed_data()[0].data, b"test data 1".to_vec());
assert_eq!(account.signed_data()[1].data, b"test data 2".to_vec());
assert_eq!(account.signed_data().len(), 2);

// Ensure that setData replaces, not appends
Expand All @@ -221,7 +221,7 @@ fn test_data_ops(algorithm: CryptoAlgorithm) {
};

// Verify data contents - should only have latest value
assert_eq!(account.signed_data()[0].1, b"replacement data".to_vec());
assert_eq!(account.signed_data()[0].data, b"replacement data".to_vec());
assert_eq!(account.signed_data().len(), 1);

// Ensure incorrectly signed data leads to error
Expand Down
Binary file modified elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
Loading