From 9d4adb9afd591ccef8827902034378acd700c6f8 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 31 Jul 2025 12:35:11 +0100 Subject: fix: nip05 breaking changes in rust-nostr as its now 'bring your own transport' --- src/lib/client.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/lib/client.rs') 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::{ Event, event::{TagKind, TagStandard, UnsignedEvent}, filter::{Alphabet, MatchEventOptions}, - nips::{nip01::Coordinate, nip19::Nip19Coordinate}, + nips::{ + nip01::Coordinate, + nip05::{Nip05Address, Nip05Profile}, + nip19::Nip19Coordinate, + }, signer::SignerBackend, }; use nostr_database::{NostrDatabase, SaveEventStatus}; @@ -43,6 +47,7 @@ use nostr_sdk::{ ClientOptions, EventBuilder, EventId, Kind, NostrSigner, PublicKey, RelayUrl, SingleLetterTag, Timestamp, Url, prelude::RelayLimits, }; +use serde_json::Value; use crate::{ get_dirs, @@ -884,6 +889,26 @@ pub async fn fetch_public_key(signer: &Arc) -> Result Result { + let addr_deconstructed = Nip05Address::parse(nip05_addr) + .context(format!("cannot parse nip05 address: {nip05_addr}"))?; + let json_res: Value = reqwest::Client::new() + .get(addr_deconstructed.url().to_string()) + .send() + .await + .context(format!( + "nip05 server is not responding for address: {nip05_addr}" + ))? + .json() + .await + .context(format!( + "nip05 server response did not respond with json when querying address: {nip05_addr}" + ))?; + Nip05Profile::from_json(&addr_deconstructed, &json_res).context(format!( + "cannot get public key for nip05 address: {nip05_addr}" + )) +} + fn pb_style() -> Result { Ok( ProgressStyle::with_template(" {spinner} {prefix} {msg} {timeout_in}")?.with_key( -- cgit v1.2.3