@@ -35,6 +35,7 @@ use clap::Parser;
|
||||
use clap_verbosity_flag::Verbosity;
|
||||
use nostr::key::Keys;
|
||||
use nostr::key::SecretKey;
|
||||
use nostr_keyring::KeyringError;
|
||||
use nostr_keyring::NostrKeyring;
|
||||
use types::RelayOrSet;
|
||||
|
||||
@@ -96,7 +97,7 @@ impl Cli {
|
||||
|
||||
match keyring.get(Self::N34_KEY_PAIR_ENTRY) {
|
||||
Ok(keys) => Ok(keys),
|
||||
Err(nostr_keyring::Error::Keyring(keyring::Error::NoEntry)) => {
|
||||
Err(nostr_keyring::Error::Keyring(KeyringError::NoEntry)) => {
|
||||
let new_keys = Keys::generate();
|
||||
keyring.set(Self::N34_KEY_PAIR_ENTRY, &new_keys)?;
|
||||
Ok(new_keys)
|
||||
|
||||
@@ -19,8 +19,8 @@ use std::str::FromStr;
|
||||
use nostr::{
|
||||
event::{EventId, Kind},
|
||||
nips::{
|
||||
self,
|
||||
nip01::Coordinate,
|
||||
nip05::{Nip05Address, Nip05Profile},
|
||||
nip19::{self, FromBech32, Nip19Coordinate},
|
||||
},
|
||||
types::RelayUrl,
|
||||
@@ -194,19 +194,25 @@ impl FromStr for NostrEvent {
|
||||
fn parse_nip5_repo(nip5: &str, repo_id: &str) -> Result<NaddrOrSet, String> {
|
||||
let (username, domain) = nip5.split_once("@").unwrap_or(("_", nip5));
|
||||
|
||||
let nip5_profile = tokio::task::block_in_place(|| {
|
||||
let nip5_address =
|
||||
Nip05Address::parse(&format!("{username}@{domain}")).map_err(|err| err.to_string())?;
|
||||
|
||||
let nip5_json = tokio::task::block_in_place(|| {
|
||||
Handle::current().block_on(async {
|
||||
nips::nip05::profile(format!("{username}@{domain}"), None)
|
||||
reqwest::get(nip5_address.url().as_str())
|
||||
.await
|
||||
.map_err(|err| err.to_string())?
|
||||
.text()
|
||||
.await
|
||||
.map_err(|err| err.to_string())
|
||||
})
|
||||
})?;
|
||||
|
||||
Ok(NaddrOrSet::Naddr(
|
||||
Nip19Coordinate::new(
|
||||
Coordinate::new(Kind::GitRepoAnnouncement, nip5_profile.public_key).identifier(repo_id),
|
||||
nip5_profile.relays,
|
||||
)
|
||||
.expect("The relays is `RelayUrl`"),
|
||||
))
|
||||
let nip5_profile =
|
||||
Nip05Profile::from_raw_json(&nip5_address, &nip5_json).map_err(|err| err.to_string())?;
|
||||
|
||||
Ok(NaddrOrSet::Naddr(Nip19Coordinate::new(
|
||||
Coordinate::new(Kind::GitRepoAnnouncement, nip5_profile.public_key).identifier(repo_id),
|
||||
nip5_profile.relays,
|
||||
)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user