pub struct ExchangeInput<'a> {
pub model: &'a str,
pub request_body: &'a [u8],
pub response_body: &'a [u8],
pub chat_id: &'a str,
pub now_unix: u64,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct AttestationChecks {
pub gpu_nras_pass: bool,
pub dcap_quote_valid: bool,
pub report_data_binds_key_and_nonce: bool,
pub compose_matches_mr_config: bool,
pub policy_accepts: bool,
pub debug_disabled: bool,
pub event_log_rtmr_ok: Option<bool>,
pub base_measurements_match: bool,
pub tcb_status: Option<String>,
pub tcb_level_acceptable: bool,
}
impl AttestationChecks {
pub fn failed() -> Self {
Self {
gpu_nras_pass: false,
dcap_quote_valid: false,
report_data_binds_key_and_nonce: false,
compose_matches_mr_config: false,
policy_accepts: false,
debug_disabled: false,
event_log_rtmr_ok: None,
base_measurements_match: false,
tcb_status: None,
tcb_level_acceptable: false,
}
}
pub fn all_pass(&self) -> bool {
self.gpu_nras_pass
&& self.dcap_quote_valid
&& self.report_data_binds_key_and_nonce
&& self.compose_matches_mr_config
&& self.policy_accepts
&& self.debug_disabled
&& self.event_log_rtmr_ok == Some(true)
&& self.base_measurements_match
&& self.tcb_level_acceptable
}
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct AttestationVerdict {
pub model: String,
pub verified: bool,
pub attested_addresses: Vec<String>,
pub trust_boundary: String,
pub nonce: String,
pub checks: AttestationChecks,
pub verified_at_unix: u64,
}
impl AttestationVerdict {
pub fn unverified(model: impl Into<String>, nonce: impl Into<String>, now_unix: u64) -> Self {
Self {
model: model.into(),
verified: false,
attested_addresses: Vec::new(),
trust_boundary: String::new(),
nonce: nonce.into(),
checks: AttestationChecks::failed(),
verified_at_unix: now_unix,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum IntegrityProof {
NearChatSignature {
text: String,
signature: String,
signing_address: String,
},
AciReceipt {
receipt: serde_json::Value,
gateway_attestation: serde_json::Value,
},
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct VerifiedExchange {
pub provider: String,
pub model: String,
pub request_hash: String,
pub response_hash: String,
pub attestation: AttestationVerdict,
pub integrity: IntegrityProof,
pub verified: bool,
}
#[derive(Debug, thiserror::Error)]
pub enum VerifyError {
#[error("transport error fetching {what}: {source}")]
Transport {
what: &'static str,
#[source]
source: Box<dyn std::error::Error + Send + Sync>,
},
#[error("malformed {what}: {detail}")]
Malformed { what: &'static str, detail: String },
#[error("attestation policy misconfigured: {0}")]
Policy(String),
#[error("no confidential verifier registered for provider {0:?}")]
UnknownProvider(String),
}