diff --git a/src/did.rs b/src/did.rs index 974bc1e..15949dc 100644 --- a/src/did.rs +++ b/src/did.rs @@ -4,6 +4,7 @@ use trust_dns_resolver::config::{ResolverConfig, ResolverOpts}; #[derive(Debug)] pub struct DidDoc { pub did: String, + pub pds: String, } fn get_txt_did(handle: &String) -> Result { @@ -63,7 +64,28 @@ fn get_http_did(handle: &String) -> Result { } fn parse_doc(did: String, text: String) -> Result { - return Ok(DidDoc { did: String::new() }); + let text_json = match json::parse(&text) { + Ok(val) => val, + Err(_) => return Err(()), + }; + + for service in text_json["service"].members() { + if service["id"] + .as_str() + .is_some_and(|x| x.ends_with("#atproto_pds")) + && service["type"] + .as_str() + .is_some_and(|x| x == "AtprotoPersonalDataServer") + && let Some(pds) = service["serviceEndpoint"].as_str() + { + return Ok(DidDoc { + did: did, + pds: pds.to_string(), + }); + } + } + + return Err(()); } fn get_plc_doc(plc: &str) -> Result {