diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-07-31 12:35:11 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-07-31 12:35:11 +0100 |
| commit | 9d4adb9afd591ccef8827902034378acd700c6f8 (patch) | |
| tree | 46956e4b56f98e3b5d59a285ff08207d659fcc14 /src/lib/client.rs | |
| parent | 8fe7737a491d6056d6e865bfdecd02e3dda3e8f5 (diff) | |
fix: nip05 breaking changes in rust-nostr
as its now 'bring your own transport'
Diffstat (limited to 'src/lib/client.rs')
| -rw-r--r-- | src/lib/client.rs | 27 |
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 | }; |
| 39 | use nostr_database::{NostrDatabase, SaveEventStatus}; | 43 | use 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 | }; |
| 50 | use serde_json::Value; | ||
| 46 | 51 | ||
| 47 | use crate::{ | 52 | use 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 | ||
| 892 | pub 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 | |||
| 887 | fn pb_style() -> Result<ProgressStyle> { | 912 | fn 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( |