Skip to content

Commit

Permalink
Mv QuoteInputData to entropy-shared
Browse files Browse the repository at this point in the history
  • Loading branch information
ameba23 committed Aug 12, 2024
1 parent 11f4b39 commit f795f69
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ serde ={ version="1.0", default-features=false, features=["derive"] }
serde_derive="1.0.147"
strum ="0.26.3"
strum_macros="0.26.4"
blake2 ={ version="0.10.4", default-features=false }

sp-runtime ={ version="32.0.0", default-features=false, optional=true, features=["serde"] }
sp-std ={ version="12.0.0", default-features=false }
Expand Down
20 changes: 20 additions & 0 deletions crates/shared/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#![allow(dead_code)]
use super::constants::VERIFICATION_KEY_LENGTH;
use blake2::{Blake2b512, Digest};
#[cfg(not(feature = "wasm"))]
use codec::alloc::vec::Vec;
use codec::{Decode, Encode};
Expand Down Expand Up @@ -99,3 +100,22 @@ pub enum HashingAlgorithm {

/// A compressed, serialized [synedrion::ecdsa::VerifyingKey<k256::Secp256k1>]
pub type EncodedVerifyingKey = [u8; VERIFICATION_KEY_LENGTH as usize];

/// Input data to be included in a TDX attestation
pub struct QuoteInputData(pub [u8; 64]);

impl QuoteInputData {
pub fn new(
account_id: [u8; 32],
x25519_public_key: X25519PublicKey,
nonce: [u8; 32],
block_number: u32,
) -> Self {
let mut hasher = Blake2b512::new();
hasher.update(account_id);
hasher.update(x25519_public_key);
hasher.update(nonce);
hasher.update(block_number.to_be_bytes());
Self(hasher.finalize().into())
}
}
28 changes: 6 additions & 22 deletions crates/threshold-signature-server/src/validator/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use crate::{
AppState,
};
use axum::{body::Bytes, extract::State, http::StatusCode};
use blake2::{Blake2b512, Digest};
use entropy_kvdb::kv_manager::{helpers::serialize as key_serialize, KvManager};
use entropy_protocol::Subsession;
pub use entropy_protocol::{
Expand Down Expand Up @@ -392,30 +391,15 @@ pub async fn attest(
let (signer, x25519_secret) = get_signer_and_x25519_secret(&app_state.kv_store).await?;
let public_key = x25519_dalek::PublicKey::from(&x25519_secret);

let input_data =
QuoteInputData::new(signer.signer().public().into(), public_key, nonce, block_number);
let input_data = entropy_shared::QuoteInputData::new(
signer.signer().public().into(),
*public_key.as_bytes(),
nonce,
block_number,
);

let quote = tdx_quote::Quote::mock(signing_key.clone(), input_data.0);
// Here we would submit an attest extrinsic to the chain - but for now we just include it in the
// response
Ok((StatusCode::OK, format!("{:?}", quote)))
}

/// Input data to be included in a TDX attestation
pub struct QuoteInputData(pub [u8; 64]);

impl QuoteInputData {
pub fn new(
account_id: AccountId32,
x25519_public_key: x25519_dalek::PublicKey,
nonce: [u8; 32],
block_number: u32,
) -> Self {
let mut hasher = Blake2b512::new();
hasher.update(account_id.0);
hasher.update(x25519_public_key.as_bytes());
hasher.update(nonce);
hasher.update(block_number.to_be_bytes());
Self(hasher.finalize().into())
}
}

0 comments on commit f795f69

Please sign in to comment.