Rust AppView - highly experimental!
at experiments 54 lines 1.6 kB view raw
1use serde::{Deserialize, Serialize}; 2 3#[derive(Debug, Deserialize, Serialize)] 4#[serde(rename_all = "camelCase")] 5pub struct PlcAuditLogEntry { 6 pub did: String, 7 pub created_at: chrono::DateTime<chrono::Utc>, 8 // Other fields exist but we only need createdAt 9} 10 11#[derive(Debug, Deserialize, Serialize)] 12#[serde(rename_all = "camelCase")] 13pub struct DidDocument { 14 #[serde(default, rename = "@context")] 15 pub context: Vec<String>, 16 pub id: String, 17 /// Ordered set (no duplicates) of aliases and names for this account, in the form of URIs 18 pub also_known_as: Option<Vec<String>>, 19 pub service: Option<Vec<DidService>>, 20 pub verification_method: Option<Vec<DidVerificationMethod>>, 21} 22 23impl DidDocument { 24 pub fn find_service_by_id(&self, service: &str) -> Option<&DidService> { 25 self.service 26 .as_ref() 27 .and_then(|services| services.iter().find(|s| s.id == service)) 28 } 29 30 pub fn find_verif_method_by_type(&self, ty: &str) -> Option<&DidVerificationMethod> { 31 self.verification_method 32 .as_ref() 33 .and_then(|methods| methods.iter().find(|m| m.ty == ty)) 34 } 35} 36 37#[derive(Debug, Deserialize, Serialize)] 38#[serde(rename_all = "camelCase")] 39pub struct DidService { 40 pub id: String, 41 #[serde(rename = "type")] 42 pub ty: String, 43 pub service_endpoint: String, 44} 45 46#[derive(Debug, Deserialize, Serialize)] 47#[serde(rename_all = "camelCase")] 48pub struct DidVerificationMethod { 49 pub id: String, 50 #[serde(rename = "type")] 51 pub ty: String, 52 pub controller: String, 53 pub public_key_multibase: String, 54}