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 | |
| parent | 8fe7737a491d6056d6e865bfdecd02e3dda3e8f5 (diff) | |
fix: nip05 breaking changes in rust-nostr
as its now 'bring your own transport'
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/client.rs | 27 | ||||
| -rw-r--r-- | src/lib/git/nostr_url.rs | 6 | ||||
| -rw-r--r-- | src/lib/login/fresh.rs | 7 |
3 files changed, 32 insertions, 8 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( |
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; | |||
| 2 | use std::{collections::HashMap, str::FromStr}; | 2 | use std::{collections::HashMap, str::FromStr}; |
| 3 | 3 | ||
| 4 | use anyhow::{Context, Error, Result, anyhow, bail}; | 4 | use anyhow::{Context, Error, Result, anyhow, bail}; |
| 5 | use nostr::nips::{nip01::Coordinate, nip05, nip19::Nip19Coordinate}; | 5 | use nostr::nips::{nip01::Coordinate, nip19::Nip19Coordinate}; |
| 6 | use nostr_sdk::{FromBech32, PublicKey, RelayUrl, ToBech32, Url}; | 6 | use nostr_sdk::{FromBech32, PublicKey, RelayUrl, ToBech32, Url}; |
| 7 | 7 | ||
| 8 | use super::{Repo, get_git_config_item, save_git_config_item}; | 8 | use super::{Repo, get_git_config_item, save_git_config_item}; |
| 9 | use crate::client::nip05_query; | ||
| 9 | 10 | ||
| 10 | #[derive(Debug, PartialEq, Default, Clone)] | 11 | #[derive(Debug, PartialEq, Default, Clone)] |
| 11 | pub enum ServerProtocol { | 12 | pub enum ServerProtocol { |
| @@ -206,8 +207,7 @@ impl NostrUrlDecoded { | |||
| 206 | if s.len() == 2 { s[1] } else { s[0] } | 207 | if s.len() == 2 { s[1] } else { s[0] } |
| 207 | }; | 208 | }; |
| 208 | term.write_line(&format!("fetching pubic key info from {domain}..."))?; | 209 | term.write_line(&format!("fetching pubic key info from {domain}..."))?; |
| 209 | // TODO we now need to implement our own wrapper for this | 210 | let res = nip05_query(npub_or_nip05).await.context(format!( |
| 210 | let res = nip05::profile(npub_or_nip05, None).await.context(format!( | ||
| 211 | "failed to get nostr public key for {npub_or_nip05} from {domain}" | 211 | "failed to get nostr public key for {npub_or_nip05} from {domain}" |
| 212 | ))?; | 212 | ))?; |
| 213 | term.clear_last_lines(1)?; | 213 | 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}; | |||
| 3 | use anyhow::{Context, Result, bail}; | 3 | use anyhow::{Context, Result, bail}; |
| 4 | use console::Style; | 4 | use console::Style; |
| 5 | use dialoguer::theme::{ColorfulTheme, Theme}; | 5 | use dialoguer::theme::{ColorfulTheme, Theme}; |
| 6 | use nostr::nips::{nip05, nip46::NostrConnectURI}; | 6 | use nostr::nips::nip46::NostrConnectURI; |
| 7 | use nostr_connect::client::NostrConnect; | 7 | use nostr_connect::client::NostrConnect; |
| 8 | use nostr_sdk::{EventBuilder, Keys, Metadata, NostrSigner, PublicKey, RelayUrl, ToBech32}; | 8 | use nostr_sdk::{EventBuilder, Keys, Metadata, NostrSigner, PublicKey, RelayUrl, ToBech32}; |
| 9 | use qrcode::QrCode; | 9 | use qrcode::QrCode; |
| @@ -25,7 +25,7 @@ use crate::{ | |||
| 25 | Interactor, InteractorPrompt, Printer, PromptChoiceParms, PromptConfirmParms, | 25 | Interactor, InteractorPrompt, Printer, PromptChoiceParms, PromptConfirmParms, |
| 26 | PromptInputParms, PromptPasswordParms, | 26 | PromptInputParms, PromptPasswordParms, |
| 27 | }, | 27 | }, |
| 28 | client::{Connect, send_events}, | 28 | client::{Connect, nip05_query, send_events}, |
| 29 | git::{Repo, RepoActions, remove_git_config_item, save_git_config_item}, | 29 | git::{Repo, RepoActions, remove_git_config_item, save_git_config_item}, |
| 30 | }; | 30 | }; |
| 31 | 31 | ||
| @@ -384,8 +384,7 @@ pub fn generate_nostr_connect_app( | |||
| 384 | pub async fn fetch_nip46_uri_from_nip05(nip05: &str) -> Result<NostrConnectURI> { | 384 | pub async fn fetch_nip46_uri_from_nip05(nip05: &str) -> Result<NostrConnectURI> { |
| 385 | let term = console::Term::stderr(); | 385 | let term = console::Term::stderr(); |
| 386 | term.write_line("contacting login service provider...")?; | 386 | term.write_line("contacting login service provider...")?; |
| 387 | // TODO we now need to implement our own wrapper for this | 387 | let res = nip05_query(nip05).await; |
| 388 | let res = nip05::profile(&nip05, None).await; | ||
| 389 | term.clear_last_lines(1)?; | 388 | term.clear_last_lines(1)?; |
| 390 | match res { | 389 | match res { |
| 391 | Ok(profile) => { | 390 | Ok(profile) => { |