tangled
alpha
login
or
join now
blooym.dev
/
jacquard
forked from
nonbinary.computer/jacquard
0
fork
atom
A better Rust ATProto crate
0
fork
atom
overview
issues
pulls
pipelines
docs cleanup
Orual
5 months ago
d5eb3508
59a1198b
+16
-33
1 changed file
expand all
collapse all
unified
split
crates
jacquard
src
identity
resolver.rs
+16
-33
crates/jacquard/src/identity/resolver.rs
···
249
250
/// Resolve DID document
251
async fn resolve_did_doc(&self, did: &Did<'_>) -> Result<DidDocResponse, IdentityError>;
0
0
252
async fn resolve_did_doc_owned(
253
&self,
254
did: &Did<'_>,
255
) -> Result<DidDocument<'static>, IdentityError> {
256
self.resolve_did_doc(did).await?.into_owned()
257
}
0
258
async fn pds_for_did(&self, did: &Did<'_>) -> Result<Url, IdentityError> {
259
let resp = self.resolve_did_doc(did).await?;
260
let doc = resp.parse()?;
···
269
}
270
doc.pds_endpoint().ok_or(IdentityError::MissingPdsEndpoint)
271
}
0
272
async fn pds_for_handle(
273
&self,
274
handle: &Handle<'_>,
···
292
///
293
/// Example
294
/// ```ignore
295
-
/// use jacquard::identity::resolver::{DefaultResolver, ResolverOptions};
296
-
/// use jacquard::client::{AuthenticatedClient, XrpcClient};
297
-
/// use jacquard::types::string::Handle;
298
-
/// use jacquard::CowStr;
299
///
300
/// // Build an auth-capable XRPC client (without a session it behaves like public/unauth)
301
/// let http = reqwest::Client::new();
302
-
/// let xrpc = AuthenticatedClient::new(http.clone(), CowStr::from("https://bsky.social"));
303
/// let resolver = DefaultResolver::new(http, xrpc, ResolverOptions::default());
304
///
305
/// // Resolve a handle to a DID
···
314
}
315
316
impl<C: crate::client::XrpcClient + Send + Sync> DefaultResolver<C> {
0
317
pub fn new(http: reqwest::Client, xrpc: C, opts: ResolverOptions) -> Self {
318
Self {
319
http,
···
325
}
326
327
#[cfg(feature = "dns")]
0
328
pub fn with_system_dns(mut self) -> Self {
329
self.dns = Some(TokioAsyncResolver::tokio(
330
ResolverConfig::default(),
···
334
}
335
336
/// Set PLC source (PLC directory or Slingshot)
337
-
///
338
-
/// Example
339
-
/// ```ignore
340
-
/// use jacquard::identity::resolver::{DefaultResolver, ResolverOptions, PlcSource};
341
-
/// let http = reqwest::Client::new();
342
-
/// let xrpc = jacquard::client::AuthenticatedClient::new(http.clone(), jacquard::CowStr::from("https://public.api.bsky.app"));
343
-
/// let resolver = DefaultResolver::new(http, xrpc, ResolverOptions::default())
344
-
/// .with_plc_source(PlcSource::slingshot_default());
345
-
/// ```
346
pub fn with_plc_source(mut self, source: PlcSource) -> Self {
347
self.opts.plc_source = source;
348
self
349
}
350
351
/// Enable/disable public unauthenticated fallback for resolveHandle
352
-
///
353
-
/// Example
354
-
/// ```ignore
355
-
/// # use jacquard::identity::resolver::{DefaultResolver, ResolverOptions};
356
-
/// # let http = reqwest::Client::new();
357
-
/// # let xrpc = jacquard::client::AuthenticatedClient::new(http.clone(), jacquard::CowStr::from("https://public.api.bsky.app"));
358
-
/// let resolver = DefaultResolver::new(http, xrpc, ResolverOptions::default())
359
-
/// .with_public_fallback_for_handle(true);
360
-
/// ```
361
pub fn with_public_fallback_for_handle(mut self, enable: bool) -> Self {
362
self.opts.public_fallback_for_handle = enable;
363
self
364
}
365
366
/// Enable/disable doc id validation
367
-
///
368
-
/// Example
369
-
/// ```ignore
370
-
/// # use jacquard::identity::resolver::{DefaultResolver, ResolverOptions};
371
-
/// # let http = reqwest::Client::new();
372
-
/// # let xrpc = jacquard::client::AuthenticatedClient::new(http.clone(), jacquard::CowStr::from("https://public.api.bsky.app"));
373
-
/// let resolver = DefaultResolver::new(http, xrpc, ResolverOptions::default())
374
-
/// .with_validate_doc_id(true);
375
-
/// ```
376
pub fn with_validate_doc_id(mut self, enable: bool) -> Self {
377
self.opts.validate_doc_id = enable;
378
self
···
682
#[derive(Debug, Clone, PartialEq, Eq)]
683
pub enum IdentityWarning {
684
/// The DID doc did not contain the expected handle alias under alsoKnownAs
685
-
HandleAliasMismatch { expected: Handle<'static> },
0
0
0
686
}
687
688
impl<C: crate::client::XrpcClient + Send + Sync> DefaultResolver<C> {
···
772
/// Slingshot mini-doc data (subset of DID doc info)
773
#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize)]
774
#[serde(rename_all = "camelCase")]
0
775
pub struct MiniDoc<'a> {
776
#[serde(borrow)]
777
pub did: Did<'a>,
···
249
250
/// Resolve DID document
251
async fn resolve_did_doc(&self, did: &Did<'_>) -> Result<DidDocResponse, IdentityError>;
252
+
253
+
/// Resolve the DID document and return an owned version
254
async fn resolve_did_doc_owned(
255
&self,
256
did: &Did<'_>,
257
) -> Result<DidDocument<'static>, IdentityError> {
258
self.resolve_did_doc(did).await?.into_owned()
259
}
260
+
/// reutrn the PDS url for a DID
261
async fn pds_for_did(&self, did: &Did<'_>) -> Result<Url, IdentityError> {
262
let resp = self.resolve_did_doc(did).await?;
263
let doc = resp.parse()?;
···
272
}
273
doc.pds_endpoint().ok_or(IdentityError::MissingPdsEndpoint)
274
}
275
+
/// Return the DIS and PDS url for a handle
276
async fn pds_for_handle(
277
&self,
278
handle: &Handle<'_>,
···
296
///
297
/// Example
298
/// ```ignore
299
+
/// # use jacquard::identity::resolver::{DefaultResolver, ResolverOptions};
300
+
/// # use jacquard::client::{AuthenticatedClient, XrpcClient};
301
+
/// # use jacquard::types::string::Handle;
302
+
/// # use jacquard::CowStr;
303
///
304
/// // Build an auth-capable XRPC client (without a session it behaves like public/unauth)
305
/// let http = reqwest::Client::new();
306
+
/// let xrpc = AuthenticatedClient::new(http.clone(), CowStr::new_static("https://bsky.social"));
307
/// let resolver = DefaultResolver::new(http, xrpc, ResolverOptions::default());
308
///
309
/// // Resolve a handle to a DID
···
318
}
319
320
impl<C: crate::client::XrpcClient + Send + Sync> DefaultResolver<C> {
321
+
/// Create a new instance of the default resolver with all options (except DNS) up front
322
pub fn new(http: reqwest::Client, xrpc: C, opts: ResolverOptions) -> Self {
323
Self {
324
http,
···
330
}
331
332
#[cfg(feature = "dns")]
333
+
/// Add default DNS resolution to the resolver
334
pub fn with_system_dns(mut self) -> Self {
335
self.dns = Some(TokioAsyncResolver::tokio(
336
ResolverConfig::default(),
···
340
}
341
342
/// Set PLC source (PLC directory or Slingshot)
0
0
0
0
0
0
0
0
0
343
pub fn with_plc_source(mut self, source: PlcSource) -> Self {
344
self.opts.plc_source = source;
345
self
346
}
347
348
/// Enable/disable public unauthenticated fallback for resolveHandle
0
0
0
0
0
0
0
0
0
349
pub fn with_public_fallback_for_handle(mut self, enable: bool) -> Self {
350
self.opts.public_fallback_for_handle = enable;
351
self
352
}
353
354
/// Enable/disable doc id validation
0
0
0
0
0
0
0
0
0
355
pub fn with_validate_doc_id(mut self, enable: bool) -> Self {
356
self.opts.validate_doc_id = enable;
357
self
···
661
#[derive(Debug, Clone, PartialEq, Eq)]
662
pub enum IdentityWarning {
663
/// The DID doc did not contain the expected handle alias under alsoKnownAs
664
+
HandleAliasMismatch {
665
+
#[allow(missing_docs)]
666
+
expected: Handle<'static>,
667
+
},
668
}
669
670
impl<C: crate::client::XrpcClient + Send + Sync> DefaultResolver<C> {
···
754
/// Slingshot mini-doc data (subset of DID doc info)
755
#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize)]
756
#[serde(rename_all = "camelCase")]
757
+
#[allow(missing_docs)]
758
pub struct MiniDoc<'a> {
759
#[serde(borrow)]
760
pub did: Did<'a>,