| | 1 | | namespace NostrSure.Domain.Entities; |
| | 2 | |
|
| | 3 | | public sealed class NostrTag |
| | 4 | | { |
| 140 | 5 | | public string Name { get; } |
| 202 | 6 | | public IReadOnlyList<string> Values { get; } |
| | 7 | |
|
| 96 | 8 | | public NostrTag(string name, IEnumerable<string> values) |
| 96 | 9 | | { |
| 96 | 10 | | if (string.IsNullOrWhiteSpace(name)) |
| 1 | 11 | | throw new ArgumentException("Tag name must not be empty", nameof(name)); |
| 95 | 12 | | Name = name.ToLowerInvariant(); |
| 95 | 13 | | Values = values?.ToList() ?? throw new ArgumentNullException(nameof(values)); |
| 95 | 14 | | } |
| | 15 | |
|
| | 16 | | public static NostrTag FromArray(IReadOnlyList<string> arr) |
| 26 | 17 | | { |
| 26 | 18 | | if (arr == null || arr.Count == 0) |
| 0 | 19 | | throw new ArgumentException("Tag array must have at least one element"); |
| 26 | 20 | | return new NostrTag(arr[0], arr.Skip(1)); |
| 26 | 21 | | } |
| | 22 | |
|
| | 23 | | // Optional: Validate known tag types |
| | 24 | | public bool IsValid() |
| 20 | 25 | | { |
| | 26 | | // Example: "p" and "e" tags must have a second element that is a 64-char hex string |
| 20 | 27 | | if ((Name == "p" || Name == "e") && (Values.Count < 1 || Values[0].Length != 64)) |
| 6 | 28 | | return false; |
| | 29 | | // Add more rules as needed |
| 14 | 30 | | return true; |
| 20 | 31 | | } |
| | 32 | | } |
| | 33 | |
|