A library for ATProtocol identities.

feature: Add com.atproto.identity.resolveHandle to atproto-client

Changed files
+81
crates
atproto-client
+75
crates/atproto-client/src/com_atproto_identity.rs
···
··· 1 + //! AT Protocol identity XRPC methods implementation. 2 + //! 3 + //! This module provides client implementations for com.atproto.identity namespace methods, 4 + //! including handle resolution functionality. 5 + 6 + use std::collections::HashMap; 7 + 8 + use anyhow::Result; 9 + use serde::{Deserialize, de::DeserializeOwned}; 10 + 11 + use crate::{ 12 + client::{get_dpop_json, get_json, DPoPAuth}, errors::SimpleError, url::URLBuilder 13 + }; 14 + 15 + /// Response from the com.atproto.identity.resolveHandle XRPC method. 16 + /// 17 + /// This enum represents either a successful handle resolution containing a DID, 18 + /// or an error response from the server. 19 + #[cfg_attr(debug_assertions, derive(Debug))] 20 + #[derive(Deserialize, Clone)] 21 + #[serde(untagged)] 22 + pub enum ResolveHandleResponse { 23 + /// Successful handle resolution response. 24 + Response { 25 + /// The DID that the handle resolves to. 26 + did: String, 27 + 28 + /// Additional fields not part of the standard response 29 + #[serde(flatten)] 30 + extra: HashMap<String, serde_json::Value>, 31 + }, 32 + 33 + /// Error response from the server 34 + Error(SimpleError), 35 + } 36 + 37 + /// Resolves an AT Protocol handle to its associated DID. 38 + /// 39 + /// Makes an XRPC call to com.atproto.identity.resolveHandle to resolve 40 + /// a handle (e.g., "user.bsky.social") to its corresponding DID. 41 + /// 42 + /// # Arguments 43 + /// 44 + /// * `http_client` - The HTTP client to use for the request 45 + /// * `dpop_auth` - Optional DPoP authentication credentials 46 + /// * `base_url` - The base URL of the AT Protocol service 47 + /// * `handle` - The handle to resolve 48 + /// 49 + /// # Returns 50 + /// 51 + /// Returns a `ResolveHandleResponse` containing either the resolved DID 52 + /// or an error response from the server. 53 + pub async fn resolve_handle<T: DeserializeOwned>( 54 + http_client: &reqwest::Client, 55 + dpop_auth: Option<&DPoPAuth>, 56 + base_url: &str, 57 + handle: String, 58 + ) -> Result<ResolveHandleResponse> { 59 + let mut url_builder = URLBuilder::new(base_url); 60 + url_builder.path("/xrpc/com.atproto.identity.resolveHandle"); 61 + 62 + url_builder.param("handle", &handle); 63 + 64 + let url = url_builder.build(); 65 + 66 + if let Some(dpop_auth) = dpop_auth { 67 + get_dpop_json(http_client, dpop_auth, &url) 68 + .await 69 + .and_then(|value| serde_json::from_value(value).map_err(|err| err.into())) 70 + } else { 71 + get_json(http_client, &url) 72 + .await 73 + .and_then(|value| serde_json::from_value(value).map_err(|err| err.into())) 74 + } 75 + }
+6
crates/atproto-client/src/lib.rs
··· 24 25 mod com_atproto_repo; 26 mod com_atproto_server; 27 28 /// AT Protocol namespace modules. 29 pub mod com { ··· 36 /// Server operations for AT Protocol authentication and session management. 37 pub mod server { 38 pub use crate::com_atproto_server::*; 39 } 40 } 41 }
··· 24 25 mod com_atproto_repo; 26 mod com_atproto_server; 27 + mod com_atproto_identity; 28 29 /// AT Protocol namespace modules. 30 pub mod com { ··· 37 /// Server operations for AT Protocol authentication and session management. 38 pub mod server { 39 pub use crate::com_atproto_server::*; 40 + } 41 + 42 + /// Identity operations for AT Protocol handle and DID resolution. 43 + pub mod identity { 44 + pub use crate::com_atproto_identity::*; 45 } 46 } 47 }