A library for ATProtocol identities.
1//! PLC directory client for did:plc resolution. 2//! 3//! Fetches DID documents from PLC directory servers using HTTPS requests 4//! to resolve did:plc identifiers in the AT Protocol ecosystem. 5 6use tracing::{Instrument, instrument}; 7 8use super::errors::PLCDIDError; 9use super::model::Document; 10 11/// Queries a PLC directory for a DID document. 12/// Fetches the complete DID document from the specified PLC hostname. 13#[instrument(skip(http_client), err)] 14pub async fn query( 15 http_client: &reqwest::Client, 16 plc_hostname: &str, 17 did: &str, 18) -> Result<Document, PLCDIDError> { 19 let url = format!("https://{}/{}", plc_hostname, did); 20 21 http_client 22 .get(&url) 23 .send() 24 .instrument(tracing::info_span!("http_client_get")) 25 .await 26 .map_err(|error| PLCDIDError::HttpRequestFailed { 27 url: url.clone(), 28 error, 29 })? 30 .json::<Document>() 31 .await 32 .map_err(|error| PLCDIDError::DocumentParseFailed { url, error }) 33}