upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/lib/client.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/client.rs')
-rw-r--r--src/lib/client.rs27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/lib/client.rs b/src/lib/client.rs
index c1e7e69..b27f9b1 100644
--- a/src/lib/client.rs
+++ b/src/lib/client.rs
@@ -33,7 +33,11 @@ use nostr::{
33 Event, 33 Event,
34 event::{TagKind, TagStandard, UnsignedEvent}, 34 event::{TagKind, TagStandard, UnsignedEvent},
35 filter::{Alphabet, MatchEventOptions}, 35 filter::{Alphabet, MatchEventOptions},
36 nips::{nip01::Coordinate, nip19::Nip19Coordinate}, 36 nips::{
37 nip01::Coordinate,
38 nip05::{Nip05Address, Nip05Profile},
39 nip19::Nip19Coordinate,
40 },
37 signer::SignerBackend, 41 signer::SignerBackend,
38}; 42};
39use nostr_database::{NostrDatabase, SaveEventStatus}; 43use nostr_database::{NostrDatabase, SaveEventStatus};
@@ -43,6 +47,7 @@ use nostr_sdk::{
43 ClientOptions, EventBuilder, EventId, Kind, NostrSigner, PublicKey, RelayUrl, SingleLetterTag, 47 ClientOptions, EventBuilder, EventId, Kind, NostrSigner, PublicKey, RelayUrl, SingleLetterTag,
44 Timestamp, Url, prelude::RelayLimits, 48 Timestamp, Url, prelude::RelayLimits,
45}; 49};
50use serde_json::Value;
46 51
47use crate::{ 52use crate::{
48 get_dirs, 53 get_dirs,
@@ -884,6 +889,26 @@ pub async fn fetch_public_key(signer: &Arc<dyn NostrSigner>) -> Result<nostr::Pu
884 } 889 }
885} 890}
886 891
892pub async fn nip05_query(nip05_addr: &str) -> Result<Nip05Profile> {
893 let addr_deconstructed = Nip05Address::parse(nip05_addr)
894 .context(format!("cannot parse nip05 address: {nip05_addr}"))?;
895 let json_res: Value = reqwest::Client::new()
896 .get(addr_deconstructed.url().to_string())
897 .send()
898 .await
899 .context(format!(
900 "nip05 server is not responding for address: {nip05_addr}"
901 ))?
902 .json()
903 .await
904 .context(format!(
905 "nip05 server response did not respond with json when querying address: {nip05_addr}"
906 ))?;
907 Nip05Profile::from_json(&addr_deconstructed, &json_res).context(format!(
908 "cannot get public key for nip05 address: {nip05_addr}"
909 ))
910}
911
887fn pb_style() -> Result<ProgressStyle> { 912fn pb_style() -> Result<ProgressStyle> {
888 Ok( 913 Ok(
889 ProgressStyle::with_template(" {spinner} {prefix} {msg} {timeout_in}")?.with_key( 914 ProgressStyle::with_template(" {spinner} {prefix} {msg} {timeout_in}")?.with_key(