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 ++++++++++++++++++++++++++- src/lib/git/nostr_url.rs | 6 +++--- src/lib/login/fresh.rs | 7 +++---- 3 files changed, 32 insertions(+), 8 deletions(-) (limited to 'src/lib') 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( diff --git a/src/lib/git/nostr_url.rs b/src/lib/git/nostr_url.rs index 8abf3f7..5e92a84 100644 --- a/src/lib/git/nostr_url.rs +++ b/src/lib/git/nostr_url.rs @@ -2,10 +2,11 @@ use core::fmt; use std::{collections::HashMap, str::FromStr}; use anyhow::{Context, Error, Result, anyhow, bail}; -use nostr::nips::{nip01::Coordinate, nip05, nip19::Nip19Coordinate}; +use nostr::nips::{nip01::Coordinate, nip19::Nip19Coordinate}; use nostr_sdk::{FromBech32, PublicKey, RelayUrl, ToBech32, Url}; use super::{Repo, get_git_config_item, save_git_config_item}; +use crate::client::nip05_query; #[derive(Debug, PartialEq, Default, Clone)] pub enum ServerProtocol { @@ -206,8 +207,7 @@ impl NostrUrlDecoded { if s.len() == 2 { s[1] } else { s[0] } }; term.write_line(&format!("fetching pubic key info from {domain}..."))?; - // TODO we now need to implement our own wrapper for this - let res = nip05::profile(npub_or_nip05, None).await.context(format!( + let res = nip05_query(npub_or_nip05).await.context(format!( "failed to get nostr public key for {npub_or_nip05} from {domain}" ))?; term.clear_last_lines(1)?; diff --git a/src/lib/login/fresh.rs b/src/lib/login/fresh.rs index aec8df5..a9cf845 100644 --- a/src/lib/login/fresh.rs +++ b/src/lib/login/fresh.rs @@ -3,7 +3,7 @@ use std::{str::FromStr, sync::Arc, time::Duration}; use anyhow::{Context, Result, bail}; use console::Style; use dialoguer::theme::{ColorfulTheme, Theme}; -use nostr::nips::{nip05, nip46::NostrConnectURI}; +use nostr::nips::nip46::NostrConnectURI; use nostr_connect::client::NostrConnect; use nostr_sdk::{EventBuilder, Keys, Metadata, NostrSigner, PublicKey, RelayUrl, ToBech32}; use qrcode::QrCode; @@ -25,7 +25,7 @@ use crate::{ Interactor, InteractorPrompt, Printer, PromptChoiceParms, PromptConfirmParms, PromptInputParms, PromptPasswordParms, }, - client::{Connect, send_events}, + client::{Connect, nip05_query, send_events}, git::{Repo, RepoActions, remove_git_config_item, save_git_config_item}, }; @@ -384,8 +384,7 @@ pub fn generate_nostr_connect_app( pub async fn fetch_nip46_uri_from_nip05(nip05: &str) -> Result { let term = console::Term::stderr(); term.write_line("contacting login service provider...")?; - // TODO we now need to implement our own wrapper for this - let res = nip05::profile(&nip05, None).await; + let res = nip05_query(nip05).await; term.clear_last_lines(1)?; match res { Ok(profile) => { -- cgit v1.2.3