atrium_identity/handle/
atproto_resolver.rs1use super::HandleResolver;
2use super::dns_resolver::{DnsHandleResolver, DnsHandleResolverConfig, DnsTxtResolver};
3use super::well_known_resolver::{WellKnownHandleResolver, WellKnownHandleResolverConfig};
4use crate::Error;
5use crate::error::Result;
6use atrium_api::types::string::{Did, Handle};
7use atrium_common::resolver::Resolver;
8use atrium_xrpc::HttpClient;
9use std::sync::Arc;
10
11#[derive(Clone, Debug)]
12pub struct AtprotoHandleResolverConfig<R, T> {
13 pub dns_txt_resolver: R,
14 pub http_client: Arc<T>,
15}
16
17pub struct AtprotoHandleResolver<R, T> {
18 dns: DnsHandleResolver<R>,
19 http: WellKnownHandleResolver<T>,
20}
21
22impl<R, T> AtprotoHandleResolver<R, T> {
23 pub fn new(config: AtprotoHandleResolverConfig<R, T>) -> Self {
24 Self {
25 dns: DnsHandleResolver::new(DnsHandleResolverConfig {
26 dns_txt_resolver: config.dns_txt_resolver,
27 }),
28 http: WellKnownHandleResolver::new(WellKnownHandleResolverConfig {
29 http_client: config.http_client,
30 }),
31 }
32 }
33}
34
35impl<R, T> Resolver for AtprotoHandleResolver<R, T>
36where
37 R: DnsTxtResolver + Send + Sync + 'static,
38 T: HttpClient + Send + Sync + 'static,
39{
40 type Input = Handle;
41 type Output = Did;
42 type Error = Error;
43
44 async fn resolve(&self, handle: &Self::Input) -> Result<Self::Output> {
45 let d_fut = self.dns.resolve(handle);
46 let h_fut = self.http.resolve(handle);
47 if let Ok(did) = d_fut.await { Ok(did) } else { h_fut.await }
48 }
49}
50
51impl<R, T> HandleResolver for AtprotoHandleResolver<R, T>
52where
53 R: DnsTxtResolver + Send + Sync + 'static,
54 T: HttpClient + Send + Sync + 'static,
55{
56}