Centralise the NIP-05 wildcard check (name != "_") on the data class itself.

This commit is contained in:
davotoula
2026-05-06 17:28:36 +02:00
parent d2e04a6726
commit fe2cb7da66
5 changed files with 24 additions and 4 deletions
@@ -36,6 +36,12 @@ data class Nip05Id(
*/
fun toDisplayValue(): String = if (name == "_") domain else assemble(name, domain)
/**
* False when [name] is the NIP-05 wildcard `"_"`; use to gate rendering of
* the local part when name and domain are shown as separate widgets.
*/
fun hasLocalPart(): Boolean = name != "_"
fun toUserUrl(): String = userUrl(name, domain)
fun toDomainUrl(): String = domainUrl(domain)
@@ -123,6 +123,20 @@ class Nip05Test {
assertEquals("example.com", nip05.toDisplayValue())
}
@Test
fun `hasLocalPart is true for regular name`() {
val nip05 = Nip05Id.parse("alice@example.com")
assertNotNull(nip05)
assertEquals(true, nip05.hasLocalPart())
}
@Test
fun `hasLocalPart is false for underscore name`() {
val nip05 = Nip05Id.parse("_@example.com")
assertNotNull(nip05)
assertEquals(false, nip05.hasLocalPart())
}
@Test
fun `test json parsing with relays`() {
val parsedNip05 = Nip05Id.parse("bob@test.com")