use serde::Deserialize; #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct DidDocument { #[serde(default, rename = "@context")] pub context: Vec, pub id: String, /// Ordered set (no duplicates) of aliases and names for this account, in the form of URIs pub also_known_as: Option>, pub service: Option>, pub verification_method: Option>, } impl DidDocument { pub fn find_service_by_id(&self, service: &str) -> Option<&DidService> { self.service .as_ref() .and_then(|services| services.iter().find(|s| s.id == service)) } pub fn find_verif_method_by_type(&self, ty: &str) -> Option<&DidVerificationMethod> { self.verification_method .as_ref() .and_then(|methods| methods.iter().find(|m| m.ty == ty)) } } #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct DidService { pub id: String, #[serde(rename = "type")] pub ty: String, pub service_endpoint: String, } #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct DidVerificationMethod { pub id: String, #[serde(rename = "type")] pub ty: String, pub controller: String, pub public_key_multibase: String, }