feat: Events and naddrs can starts with nostr:

Suggested-by: DanConwayDev <DanConwayDev@protonmail.com>
Fixes: note1jwgfl095vuhduepxxpwhdqme0dnlhawzvcal0xnl0e6d82wx5jys5z92hj
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb
2025-05-27 10:48:33 +00:00
parent 15d834dc0f
commit 1abb8e3f36
2 changed files with 6 additions and 5 deletions

View File

@@ -65,12 +65,13 @@ impl FromStr for NostrEvent {
type Err = String; type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
if s.trim().starts_with("nevent1") { let str_event = s.trim().trim_start_matches("nostr:");
let event = nip19::Nip19Event::from_bech32(s).map_err(|e| e.to_string())?; if str_event.starts_with("nevent1") {
let event = nip19::Nip19Event::from_bech32(str_event).map_err(|e| e.to_string())?;
Ok(Self::new(event.event_id, event.relays)) Ok(Self::new(event.event_id, event.relays))
} else if s.trim().starts_with("note1") { } else if str_event.starts_with("note1") {
Ok(Self::new( Ok(Self::new(
EventId::from_bech32(s).map_err(|e| e.to_string())?, EventId::from_bech32(str_event).map_err(|e| e.to_string())?,
Vec::new(), Vec::new(),
)) ))
} else { } else {

View File

@@ -83,7 +83,7 @@ pub fn parse_nostr_address_file(file_path: &Path) -> N34Result<Vec<Nip19Coordina
/// Returns an error for invalid formats, failed bech32 decoding, wrong event /// Returns an error for invalid formats, failed bech32 decoding, wrong event
/// kind. /// kind.
pub fn repo_naddr(repo: &str) -> Result<Nip19Coordinate, String> { pub fn repo_naddr(repo: &str) -> Result<Nip19Coordinate, String> {
let repo = repo.trim(); let repo = repo.trim().trim_start_matches("nostr:");
if repo.contains("/") { if repo.contains("/") {
let (nip5, repo_id) = repo.split_once("/").expect("There is a `/`"); let (nip5, repo_id) = repo.split_once("/").expect("There is a `/`");