From 921a59ff0e255f0722d6b51063fc0505a85d3e70 Mon Sep 17 00:00:00 2001 From: peg Date: Thu, 21 Nov 2024 12:03:05 +0100 Subject: [PATCH] Get context from querystring --- .../src/attestation/api.rs | 19 +++++++++++++++++-- .../src/attestation/tests.rs | 8 ++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/crates/threshold-signature-server/src/attestation/api.rs b/crates/threshold-signature-server/src/attestation/api.rs index c5d806272..815fc67b0 100644 --- a/crates/threshold-signature-server/src/attestation/api.rs +++ b/crates/threshold-signature-server/src/attestation/api.rs @@ -23,11 +23,16 @@ use crate::{ }, AppState, }; -use axum::{body::Bytes, extract::State, http::StatusCode}; +use axum::{ + body::Bytes, + extract::{Query, State}, + http::StatusCode, +}; use entropy_client::user::request_attestation; use entropy_kvdb::kv_manager::KvManager; use entropy_shared::{OcwMessageAttestationRequest, QuoteContext}; use parity_scale_codec::Decode; +use serde::Deserialize; use sp_core::Pair; use subxt::tx::PairSigner; use x25519_dalek::StaticSecret; @@ -78,6 +83,11 @@ pub async fn attest( Ok(StatusCode::OK) } +#[derive(Deserialize)] +pub struct QuoteContextQuery { + context: String, +} + /// Retrieve a quote by requesting a nonce from the chain and return the quote in the HTTP response /// body. /// @@ -85,6 +95,7 @@ pub async fn attest( /// and `change_tss_accounts` extrinsics. pub async fn get_attest( State(app_state): State, + Query(context_querystring): Query, ) -> Result<(StatusCode, Vec), AttestationErr> { let (signer, x25519_secret) = get_signer_and_x25519_secret(&app_state.kv_store).await?; let api = get_api(&app_state.configuration.endpoint).await?; @@ -93,7 +104,11 @@ pub async fn get_attest( // Request attestation to get nonce let nonce = request_attestation(&api, &rpc, signer.signer()).await?; - let context = QuoteContext::Validate; // TODO + let context = match context_querystring.context.as_str() { + "validate" => QuoteContext::Validate, + _ => panic!("Bad context"), + }; + let quote = create_quote(nonce, &signer, &x25519_secret, context).await?; Ok((StatusCode::OK, quote)) diff --git a/crates/threshold-signature-server/src/attestation/tests.rs b/crates/threshold-signature-server/src/attestation/tests.rs index 37314b9b9..8ba451305 100644 --- a/crates/threshold-signature-server/src/attestation/tests.rs +++ b/crates/threshold-signature-server/src/attestation/tests.rs @@ -47,8 +47,12 @@ async fn test_get_attest() { let api = get_api(&cxt.ws_url).await.unwrap(); let rpc = get_rpc(&cxt.ws_url).await.unwrap(); - let quote_bytes = - reqwest::get("http://127.0.0.1:3002/attest").await.unwrap().bytes().await.unwrap(); + let quote_bytes = reqwest::get("http://127.0.0.1:3002/attest?context=validate") + .await + .unwrap() + .bytes() + .await + .unwrap(); let quote = Quote::from_bytes("e_bytes).unwrap(); let query =