package nostr // Tag represents a single Nostr tag, which is an array of strings. // The first element is the tag key, followed by its values. type Tag []string // Key returns the tag key (first element), or empty string if tag is empty. func (t Tag) Key() string { if len(t) == 0 { return "" } return t[0] } // Value returns the first value (second element), or empty string if not present. func (t Tag) Value() string { if len(t) < 2 { return "" } return t[1] } // Tags represents a collection of tags. type Tags []Tag // Find returns the first tag matching the given key, or nil if not found. func (tags Tags) Find(key string) Tag { for _, tag := range tags { if tag.Key() == key { return tag } } return nil } // FindAll returns all tags matching the given key. func (tags Tags) FindAll(key string) Tags { var result Tags for _, tag := range tags { if tag.Key() == key { result = append(result, tag) } } return result } // GetD returns the value of the "d" tag, used for addressable events. func (tags Tags) GetD() string { tag := tags.Find("d") if tag == nil { return "" } return tag.Value() } // ContainsValue checks if any tag with the given key contains the specified value. func (tags Tags) ContainsValue(key, value string) bool { for _, tag := range tags { if tag.Key() == key && tag.Value() == value { return true } } return false }