Replying to Avatar DanConwayDev

From ec102f34318cdf985e667183e89f12de229d9af8 Mon Sep 17 00:00:00 2001

From: DanConwayDev

Date: Tue, 19 Aug 2025 09:10:08 +0100

Subject: [PATCH] nostr: `Nip05Address::parse` succeed without local part

add robustness to `Nip05Address::parse`

---

crates/nostr/src/nips/nip05.rs | 34 ++++++++++++++++++++++++++++++++++

1 file changed, 34 insertions(+)

diff --git a/crates/nostr/src/nips/nip05.rs b/crates/nostr/src/nips/nip05.rs

index ce61072..b3f6f11 100644

--- a/crates/nostr/src/nips/nip05.rs

+++ b/crates/nostr/src/nips/nip05.rs

@@ -72,6 +72,11 @@ impl fmt::Display for Nip05Address {

impl Nip05Address {

/// Parse a NIP-05 address (i.e., `yuki@yukikishimoto.com`).

pub fn parse(address: &str) -> Result {

+ let address = if address.contains('@') {

+ address

+ } else {

+ &format!("_@{address}")

+ };

// Split the address into parts

let mut split: Split = address.split('@');

@@ -237,6 +242,35 @@ mod tests {

}

#[test]

+ fn test_verify_nip05_without_local() {

+ // nostr.json

+ let json: &str = r#"{

+ "names": {

+ "yuki": "68d81165918100b7da43fc28f7d1fc12554466e1115886b9e7bb326f65ec4272",

+ "_": "68d81165918100b7da43fc28f7d1fc12554466e1115886b9e7bb326f65ec4272"

+ }

+ }"#;

+ let json: Value = serde_json::from_str(json).unwrap();

+

+ let address = Nip05Address::parse("yukikishimoto.com").unwrap();

+ assert_eq!(

+ address.url().to_string(),

+ "https://yukikishimoto.com/.well-known/nostr.json?name=_"

+ );

+ assert_eq!(address.name(), "_");

+

+ let public_key =

+ PublicKey::from_hex("68d81165918100b7da43fc28f7d1fc12554466e1115886b9e7bb326f65ec4272")

+ .unwrap();

+ assert!(verify_from_json(&public_key, &address, &json));

+

+ let public_key =

+ PublicKey::from_hex("b2d670de53b27691c0c3400225b65c35a26d06093bcc41f48ffc71e0907f9d4a")

+ .unwrap();

+ assert!(!verify_from_json(&public_key, &address, &json));

+ }

+

+ #[test]

fn test_nip05_profile_from_json() {

// nostr.json

let json = r#"{

--

libgit2 1.9.1

Thanks, I've released it ad patch (v0.43.1)

Reply to this note

Please Login to reply.

Discussion

No replies yet.