···11package atproto
2233-import "fmt"
33+import (
44+ "fmt"
55+ "regexp"
66+)
4758// NSID (Namespaced Identifier) constants for Arabica lexicons.
69// The domain is reversed following ATProto conventions: arabica.social -> social.arabica
···1518 NSIDBrewer = NSIDBase + ".brewer"
1619 NSIDGrinder = NSIDBase + ".grinder"
1720 NSIDRoaster = NSIDBase + ".roaster"
2121+2222+ // MaxRKeyLength is the maximum allowed length for a record key
2323+ MaxRKeyLength = 512
1824)
2525+2626+// rkeyRegex validates AT Protocol record keys (rkeys).
2727+// Valid rkeys contain only alphanumeric characters, hyphens, underscores, colons, and periods.
2828+// They must start with an alphanumeric character and be 1-512 characters long.
2929+// TIDs are the most common format: 13 lowercase base32 characters (e.g., "3kfk4slgu6s2h").
3030+var rkeyRegex = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,511}$`)
3131+3232+// ValidateRKey checks if an rkey is valid according to AT Protocol spec.
3333+// Returns true if valid, false otherwise.
3434+func ValidateRKey(rkey string) bool {
3535+ if rkey == "" || len(rkey) > MaxRKeyLength {
3636+ return false
3737+ }
3838+ // Reserved rkeys that should not be used
3939+ if rkey == "." || rkey == ".." {
4040+ return false
4141+ }
4242+ return rkeyRegex.MatchString(rkey)
4343+}
19442045// BuildATURI constructs an AT-URI from a DID, collection NSID, and record key
2146func BuildATURI(did, collection, rkey string) string {