Skip to content

Commit

Permalink
feat: Extend DidDocument with useful methods
Browse files Browse the repository at this point in the history
New methods:
* get_feed_gen_endpoint
* get_notif_endpoint
* get_signing_key
  • Loading branch information
tyzhnenko committed Dec 9, 2024
1 parent 7a1c92d commit ebb44e5
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions atrium-api/src/did_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ impl DidDocument {
pub fn get_pds_endpoint(&self) -> Option<String> {
self.get_service_endpoint("#atproto_pds", "AtprotoPersonalDataServer")
}
pub fn get_feed_gen_endpoint(&self) -> Option<String> {
self.get_service_endpoint("#bsky_fg", "BskyFeedGenerator")
}
pub fn get_notif_endpoint(&self) -> Option<String> {
self.get_service_endpoint("#bsky_notif", "BskyNotificationService")
}
fn get_service_endpoint(&self, id: &str, r#type: &str) -> Option<String> {
let full_id = self.id.to_string() + id;
if let Some(services) = &self.service {
Expand All @@ -62,4 +68,11 @@ impl DidDocument {
})
.unwrap_or_default()
}
pub fn get_signing_key(&self) -> Option<&VerificationMethod> {
self.verification_method.as_ref().and_then(|methods| {
methods.iter().find(|method| {
method.id == "#atproto" || method.id == format!("{}#atproto", self.id)
})
})
}
}

0 comments on commit ebb44e5

Please sign in to comment.