Allow dot in usernames per NIP-05 local-part spec

Extend usernameRE to [a-z0-9_.-], preserve dots in SanitizeForUsername,
and add tests for validation, sanitization, and nip05 sync precedence.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-05 06:10:14 +00:00
parent 7a1ceb49c3
commit bbfc64733a
4 changed files with 19 additions and 6 deletions

View File

@@ -42,8 +42,9 @@ var (
ErrUsernameTaken = errors.New("username taken")
)
// Username rules: 1-30 chars, [a-z0-9_-], lowercase, must start with alnum.
var usernameRE = regexp.MustCompile(`^[a-z0-9][a-z0-9_-]{0,29}$`)
// Username rules: 1-30 chars, [a-z0-9_.-], lowercase, must start with alnum.
// Dot is allowed per NIP-05 local-part spec.
var usernameRE = regexp.MustCompile(`^[a-z0-9][a-z0-9_.-]{0,29}$`)
func ValidateUsername(name string, reserved []string) error {
name = strings.ToLower(strings.TrimSpace(name))