this repo has no description
at main 1.8 kB view raw
1//! Example demonstrating lexicon schema resolution via DNS + XRPC 2//! 3//! Run with: cargo run --example resolve_lexicon --features dns 4 5use jacquard_common::types::string::Nsid; 6use jacquard_identity::{ 7 JacquardResolver, 8 lexicon_resolver::{LexiconAuthorityResolver, LexiconSchemaResolver}, 9 resolver::ResolverOptions, 10}; 11 12#[tokio::main] 13async fn main() -> miette::Result<()> { 14 // Set up resolver with DNS enabled 15 let http = reqwest::Client::new(); 16 let opts = ResolverOptions::default(); 17 let resolver = JacquardResolver::new_dns(http, opts); 18 19 // Test NSID - using app.bsky.feed.post as a known lexicon 20 let nsid = 21 Nsid::new("app.bsky.feed.post").map_err(|e| miette::miette!("invalid NSID: {}", e))?; 22 23 println!("Resolving lexicon for: {}", nsid); 24 println!(); 25 println!("Resolving authority via DNS..."); 26 match resolver.resolve_lexicon_authority(&nsid).await { 27 Ok(did) => { 28 println!("Authority DID: {}", did); 29 } 30 Err(e) => { 31 eprintln!("Failed to resolve authority: {:?}", e); 32 return Err(e.into()); 33 } 34 } 35 36 println!(); 37 println!("Fetching full lexicon schema..."); 38 match resolver.resolve_lexicon_schema(&nsid).await { 39 Ok(schema) => { 40 println!("Successfully fetched schema"); 41 println!(" NSID: {}", schema.nsid); 42 println!(" Repo: {}", schema.repo); 43 println!(" CID: {}", schema.cid); 44 println!(" Doc ID: {}", schema.doc.id); 45 println!( 46 "\nSchema:\n{}", 47 serde_json::to_string_pretty(&schema.doc).unwrap() 48 ) 49 } 50 Err(e) => { 51 eprintln!("Failed to resolve schema: {:?}", e); 52 return Err(e.into()); 53 } 54 } 55 56 Ok(()) 57}