use axum::Json; use serde::Serialize; use std::env; #[derive(Serialize)] #[serde(rename_all = "camelCase")] pub struct DidDocument { #[serde(rename = "@context")] context: Vec, id: String, verification_method: Vec, service: Vec, } #[derive(Serialize)] #[serde(rename_all = "camelCase")] struct VerificationMethod { id: String, #[serde(rename = "type")] type_: String, controller: String, public_key_multibase: Option, } #[derive(Serialize)] #[serde(rename_all = "camelCase")] struct Service { id: String, #[serde(rename = "type")] type_: String, service_endpoint: String, } pub async fn did_document() -> Json { let domain = env::var("APP_VIEW_DOMAIN").unwrap_or_else(|_| "api.blacksky.community".to_string()); let did_id = format!("did:web:{domain}"); let endpoint = format!("https://{domain}"); Json(DidDocument { context: vec![ "https://www.w3.org/ns/did/v1".to_string(), "https://w3id.org/security/multikey/v1".to_string(), ], verification_method: vec![VerificationMethod { id: format!("{did_id}#atproto"), type_: "Multikey".to_string(), controller: did_id.clone(), public_key_multibase: Some( "z42tusbpVy6BCE8tqcQAkvvRi9W3M7LEqLWNdTxtW2KicMNJ".to_string(), ), }], service: vec![Service { id: "#bsky_appview".to_string(), type_: "BskyAppView".to_string(), service_endpoint: endpoint, }], id: did_id, }) }