fix(nip05): stop reporting verification errors as Verified
This commit is contained in:
+1
-1
@@ -45,7 +45,7 @@ sealed interface Nip05State {
|
|||||||
|
|
||||||
fun markAsVerifying() = verificationState.tryEmit(Nip05VerifState.Verifying(TimeUtils.fiveMinutesAhead()))
|
fun markAsVerifying() = verificationState.tryEmit(Nip05VerifState.Verifying(TimeUtils.fiveMinutesAhead()))
|
||||||
|
|
||||||
fun markAsError() = verificationState.tryEmit(Nip05VerifState.Verified(TimeUtils.fiveMinutesAhead()))
|
fun markAsError() = verificationState.tryEmit(Nip05VerifState.Error(TimeUtils.fiveMinutesAhead()))
|
||||||
|
|
||||||
fun reset() = verificationState.tryEmit(Nip05VerifState.NotStarted)
|
fun reset() = verificationState.tryEmit(Nip05VerifState.NotStarted)
|
||||||
|
|
||||||
|
|||||||
+13
-6
@@ -47,14 +47,21 @@ data class Nip05Id(
|
|||||||
fun toDomainUrl(): String = domainUrl(domain)
|
fun toDomainUrl(): String = domainUrl(domain)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
// NIP-05 localpart: a-z, 0-9, -, _, .
|
||||||
|
private val LOCAL_PART_REGEX = Regex("^[a-z0-9._-]+$")
|
||||||
|
|
||||||
|
// Hostname: dot-separated labels of [a-z0-9-], no leading/trailing hyphen,
|
||||||
|
// require at least one dot so single-label garbage (e.g. "s!ayer") is rejected.
|
||||||
|
private val DOMAIN_REGEX =
|
||||||
|
Regex("^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)(\\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)+$")
|
||||||
|
|
||||||
fun parse(nip05address: String): Nip05Id? {
|
fun parse(nip05address: String): Nip05Id? {
|
||||||
val parts = nip05address.trim().lowercase().split("@")
|
val parts = nip05address.trim().lowercase().split("@")
|
||||||
|
if (parts.size != 2) return null
|
||||||
return when (parts.size) {
|
val (name, domain) = parts[0] to parts[1]
|
||||||
2 -> Nip05Id(parts[0], parts[1])
|
if (!LOCAL_PART_REGEX.matches(name)) return null
|
||||||
1 -> Nip05Id(parts[0], "_")
|
if (!DOMAIN_REGEX.matches(domain)) return null
|
||||||
else -> null
|
return Nip05Id(name, domain)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun assemble(
|
fun assemble(
|
||||||
|
|||||||
+39
@@ -94,6 +94,45 @@ class Nip05Test {
|
|||||||
assertNull(parsedNip05)
|
assertNull(parsedNip05)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `parse rejects empty localpart`() {
|
||||||
|
assertNull(Nip05Id.parse("@example.com"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `parse rejects empty domain`() {
|
||||||
|
assertNull(Nip05Id.parse("alice@"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `parse rejects domain without a dot`() {
|
||||||
|
assertNull(Nip05Id.parse("alice@localhost"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `parse rejects domain with illegal character`() {
|
||||||
|
assertNull(Nip05Id.parse("_@s!ayer"))
|
||||||
|
assertNull(Nip05Id.parse("@s!ayer"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `parse rejects localpart with illegal character`() {
|
||||||
|
assertNull(Nip05Id.parse("al!ce@example.com"))
|
||||||
|
assertNull(Nip05Id.parse("alice space@example.com"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `parse rejects bare string without at-sign`() {
|
||||||
|
assertNull(Nip05Id.parse("alice"))
|
||||||
|
assertNull(Nip05Id.parse("example.com"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `parse rejects domain label with leading or trailing hyphen`() {
|
||||||
|
assertNull(Nip05Id.parse("alice@-example.com"))
|
||||||
|
assertNull(Nip05Id.parse("alice@example-.com"))
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `execute assemble url with valid value returns nip05 url`() {
|
fun `execute assemble url with valid value returns nip05 url`() {
|
||||||
// given
|
// given
|
||||||
|
|||||||
Reference in New Issue
Block a user