Skip to content

Commit

Permalink
Get context from querystring
Browse files Browse the repository at this point in the history
  • Loading branch information
ameba23 committed Nov 21, 2024
1 parent b0eff14 commit 921a59f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
19 changes: 17 additions & 2 deletions crates/threshold-signature-server/src/attestation/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -78,13 +83,19 @@ 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.
///
/// This is used by node operators to get a quote for use in the `validate`, `change_endpoint`
/// and `change_tss_accounts` extrinsics.
pub async fn get_attest(
State(app_state): State<AppState>,
Query(context_querystring): Query<QuoteContextQuery>,
) -> Result<(StatusCode, Vec<u8>), AttestationErr> {
let (signer, x25519_secret) = get_signer_and_x25519_secret(&app_state.kv_store).await?;
let api = get_api(&app_state.configuration.endpoint).await?;
Expand All @@ -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))
Expand Down
8 changes: 6 additions & 2 deletions crates/threshold-signature-server/src/attestation/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&quote_bytes).unwrap();

let query =
Expand Down

0 comments on commit 921a59f

Please sign in to comment.