diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-04 08:50:29 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-04 09:23:48 +0000 |
| commit | b3031800cd95601c2d9cd2d24034364d1496b073 (patch) | |
| tree | de91247ecaef26dd59d209ea2d7df3e1772a4c62 /grasp-audit | |
| parent | 15d3b0f859c2c5bc74ac602159c26fbccf475cb4 (diff) | |
Migrate to standard NIP-01 't' tags for audit events
- Changed from custom single-letter tags (g, r, c) to standard 't' tags
- Tag values now use descriptive prefixes:
- 'grasp-audit-test-event' (marker tag)
- 'audit-{run-id}' (run identification)
- 'audit-cleanup-after-{timestamp}' (cleanup time)
- Updated audit_tags() in src/audit.rs
- Updated query filtering in src/client.rs
- Updated all tests to verify 't' tag usage
- All tests passing: 12/12 unit tests, 1/1 integration test
- CLI verified working with new tag scheme
This follows standard Nostr conventions and avoids potential
conflicts with other uses of single-letter tags. The 't' tag
is specifically designed for categorization/topics per NIP-01.
Diffstat (limited to 'grasp-audit')
| -rw-r--r-- | grasp-audit/TAG_MIGRATION.md | 151 | ||||
| -rw-r--r-- | grasp-audit/src/audit.rs | 54 | ||||
| -rw-r--r-- | grasp-audit/src/client.rs | 13 |
3 files changed, 179 insertions, 39 deletions
diff --git a/grasp-audit/TAG_MIGRATION.md b/grasp-audit/TAG_MIGRATION.md new file mode 100644 index 0000000..aaba729 --- /dev/null +++ b/grasp-audit/TAG_MIGRATION.md | |||
| @@ -0,0 +1,151 @@ | |||
| 1 | # Tag Migration to Standard NIP-01 "t" Tags | ||
| 2 | |||
| 3 | **Date:** November 4, 2025 | ||
| 4 | **Status:** ✅ Complete | ||
| 5 | |||
| 6 | ## Overview | ||
| 7 | |||
| 8 | Migrated audit system tags from custom single-letter tags (`g`, `r`, `c`) to standard NIP-01 "t" tags (hashtags) to avoid conflicts and follow Nostr conventions. | ||
| 9 | |||
| 10 | ## Motivation | ||
| 11 | |||
| 12 | The previous tag scheme used: | ||
| 13 | - `g` tag for `grasp-audit` marker | ||
| 14 | - `r` tag for `audit-run-id` | ||
| 15 | - `c` tag for `audit-cleanup` timestamp | ||
| 16 | |||
| 17 | However, this could conflict with other uses of these single-letter tags. The "t" tag is the standard NIP-01 tag type for categorization/topics, making it the appropriate choice for audit event tagging. | ||
| 18 | |||
| 19 | ## Changes Made | ||
| 20 | |||
| 21 | ### Tag Structure | ||
| 22 | |||
| 23 | **Before:** | ||
| 24 | ```rust | ||
| 25 | vec![ | ||
| 26 | Tag::custom(TagKind::SingleLetter(g_tag), vec!["grasp-audit"]), | ||
| 27 | Tag::custom(TagKind::SingleLetter(r_tag), vec![run_id]), | ||
| 28 | Tag::custom(TagKind::SingleLetter(c_tag), vec![cleanup_timestamp]), | ||
| 29 | ] | ||
| 30 | ``` | ||
| 31 | |||
| 32 | **After:** | ||
| 33 | ```rust | ||
| 34 | vec![ | ||
| 35 | Tag::custom(TagKind::SingleLetter(t_tag), vec!["grasp-audit-test-event"]), | ||
| 36 | Tag::custom(TagKind::SingleLetter(t_tag), vec![format!("audit-{}", run_id)]), | ||
| 37 | Tag::custom(TagKind::SingleLetter(t_tag), vec![format!("audit-cleanup-after-{}", timestamp)]), | ||
| 38 | ] | ||
| 39 | ``` | ||
| 40 | |||
| 41 | ### Tag Values | ||
| 42 | |||
| 43 | | Purpose | Old Tag | Old Value | New Tag | New Value | | ||
| 44 | |---------|---------|-----------|---------|-----------| | ||
| 45 | | Marker | `g` | `grasp-audit` | `t` | `grasp-audit-test-event` | | ||
| 46 | | Run ID | `r` | `ci-{uuid}` | `t` | `audit-ci-{uuid}` | | ||
| 47 | | Cleanup | `c` | `{timestamp}` | `t` | `audit-cleanup-after-{timestamp}` | | ||
| 48 | |||
| 49 | ### Example Event Tags | ||
| 50 | |||
| 51 | ```json | ||
| 52 | [ | ||
| 53 | ["t", "grasp-audit-test-event"], | ||
| 54 | ["t", "audit-ci-a1b2c3d4-e5f6-7890-abcd-ef1234567890"], | ||
| 55 | ["t", "audit-cleanup-after-1730707200"] | ||
| 56 | ] | ||
| 57 | ``` | ||
| 58 | |||
| 59 | ## Files Modified | ||
| 60 | |||
| 61 | ### `src/audit.rs` | ||
| 62 | - Updated `audit_tags()` to use "t" tags | ||
| 63 | - Updated tests to check for "t" tag kind | ||
| 64 | - All values now prefixed for clarity | ||
| 65 | |||
| 66 | ### `src/client.rs` | ||
| 67 | - Updated `query()` to filter by "t" tags | ||
| 68 | - Changed from `.custom_tag(g_tag, ...)` to `.custom_tag(t_tag, ...)` | ||
| 69 | |||
| 70 | ## Benefits | ||
| 71 | |||
| 72 | 1. **Standards Compliance**: Uses standard NIP-01 hashtag mechanism | ||
| 73 | 2. **No Conflicts**: "t" tag is designed for categorization | ||
| 74 | 3. **Better Namespacing**: Values prefixed with `audit-` to avoid collisions | ||
| 75 | 4. **Queryable**: Standard tag filtering works as expected | ||
| 76 | 5. **Self-Documenting**: Tag values clearly indicate their purpose | ||
| 77 | |||
| 78 | ## Testing | ||
| 79 | |||
| 80 | All tests pass with the new tag scheme: | ||
| 81 | |||
| 82 | ```bash | ||
| 83 | # Unit tests | ||
| 84 | ✓ 12/12 tests passing | ||
| 85 | |||
| 86 | # Integration tests | ||
| 87 | ✓ 1/1 test passing (NIP-01 smoke tests) | ||
| 88 | |||
| 89 | # CLI verification | ||
| 90 | ✓ All 6 smoke tests pass | ||
| 91 | ``` | ||
| 92 | |||
| 93 | ## Backwards Compatibility | ||
| 94 | |||
| 95 | ⚠️ **Breaking Change**: Events created with old tags will not be found by new queries. | ||
| 96 | |||
| 97 | This is acceptable because: | ||
| 98 | - System is in alpha/development | ||
| 99 | - Old events are test data only | ||
| 100 | - Cleanup happens automatically via timestamps | ||
| 101 | - No production deployments exist yet | ||
| 102 | |||
| 103 | ## Migration Path | ||
| 104 | |||
| 105 | For future tag changes: | ||
| 106 | 1. Consider versioning in tag values (e.g., `grasp-audit-v2-test-event`) | ||
| 107 | 2. Support querying both old and new tags during transition | ||
| 108 | 3. Document breaking changes clearly | ||
| 109 | 4. Provide migration tools if needed | ||
| 110 | |||
| 111 | ## References | ||
| 112 | |||
| 113 | - **NIP-01**: https://github.com/nostr-protocol/nips/blob/master/01.md | ||
| 114 | - **Tag Standardization**: "t" tags for topics/categories | ||
| 115 | - **Previous Implementation**: Commit `8190a3a` (custom g/r/c tags) | ||
| 116 | - **Current Implementation**: Uses standard "t" tags | ||
| 117 | |||
| 118 | ## Verification | ||
| 119 | |||
| 120 | To verify the new tag structure: | ||
| 121 | |||
| 122 | ```bash | ||
| 123 | # Run tests | ||
| 124 | nix develop -c cargo test --lib | ||
| 125 | nix develop -c cargo test -- --ignored | ||
| 126 | |||
| 127 | # Run CLI | ||
| 128 | nix develop -c cargo run -- audit \ | ||
| 129 | --relay ws://localhost:7000 \ | ||
| 130 | --mode ci \ | ||
| 131 | --spec nip01-smoke | ||
| 132 | |||
| 133 | # Check event structure (example) | ||
| 134 | # Events will have tags like: | ||
| 135 | # ["t", "grasp-audit-test-event"] | ||
| 136 | # ["t", "audit-ci-{uuid}"] | ||
| 137 | # ["t", "audit-cleanup-after-{timestamp}"] | ||
| 138 | ``` | ||
| 139 | |||
| 140 | ## Next Steps | ||
| 141 | |||
| 142 | - [ ] Update documentation to reflect new tag scheme | ||
| 143 | - [ ] Consider adding tag validation helpers | ||
| 144 | - [ ] Document tag format in API/spec documentation | ||
| 145 | - [ ] Add examples showing tag usage | ||
| 146 | |||
| 147 | --- | ||
| 148 | |||
| 149 | **Status:** ✅ Migration complete and verified | ||
| 150 | **All tests passing:** 13/13 (12 unit + 1 integration) | ||
| 151 | **CLI verified:** ✅ Working correctly | ||
diff --git a/grasp-audit/src/audit.rs b/grasp-audit/src/audit.rs index e902ace..fad4bf2 100644 --- a/grasp-audit/src/audit.rs +++ b/grasp-audit/src/audit.rs | |||
| @@ -65,22 +65,21 @@ impl AuditConfig { | |||
| 65 | pub fn audit_tags(&self) -> Vec<Tag> { | 65 | pub fn audit_tags(&self) -> Vec<Tag> { |
| 66 | use nostr_sdk::prelude::{Alphabet, SingleLetterTag}; | 66 | use nostr_sdk::prelude::{Alphabet, SingleLetterTag}; |
| 67 | 67 | ||
| 68 | // Use "t" tags for categorization (standard NIP-01 hashtag type) | ||
| 69 | let t_tag = SingleLetterTag::lowercase(Alphabet::T); | ||
| 70 | |||
| 68 | vec![ | 71 | vec![ |
| 69 | // Use single-letter tags for filtering support | ||
| 70 | // "g" = grasp-audit marker | ||
| 71 | Tag::custom( | 72 | Tag::custom( |
| 72 | TagKind::SingleLetter(SingleLetterTag::lowercase(Alphabet::G)), | 73 | TagKind::SingleLetter(t_tag), |
| 73 | vec!["grasp-audit"] | 74 | vec!["grasp-audit-test-event"] |
| 74 | ), | 75 | ), |
| 75 | // "r" = audit run ID | ||
| 76 | Tag::custom( | 76 | Tag::custom( |
| 77 | TagKind::SingleLetter(SingleLetterTag::lowercase(Alphabet::R)), | 77 | TagKind::SingleLetter(t_tag), |
| 78 | vec![self.run_id.clone()] | 78 | vec![format!("audit-{}", self.run_id)] |
| 79 | ), | 79 | ), |
| 80 | // "c" = cleanup timestamp | ||
| 81 | Tag::custom( | 80 | Tag::custom( |
| 82 | TagKind::SingleLetter(SingleLetterTag::lowercase(Alphabet::C)), | 81 | TagKind::SingleLetter(t_tag), |
| 83 | vec![self.cleanup_after.to_string()] | 82 | vec![format!("audit-cleanup-after-{}", self.cleanup_after.as_u64())] |
| 84 | ), | 83 | ), |
| 85 | ] | 84 | ] |
| 86 | } | 85 | } |
| @@ -159,35 +158,30 @@ mod tests { | |||
| 159 | 158 | ||
| 160 | assert_eq!(tags.len(), 3); | 159 | assert_eq!(tags.len(), 3); |
| 161 | 160 | ||
| 162 | let g_tag = SingleLetterTag::lowercase(Alphabet::G); | 161 | let t_tag = SingleLetterTag::lowercase(Alphabet::T); |
| 163 | let r_tag = SingleLetterTag::lowercase(Alphabet::R); | ||
| 164 | let c_tag = SingleLetterTag::lowercase(Alphabet::C); | ||
| 165 | 162 | ||
| 166 | // Check "g" tag (grasp-audit marker) | 163 | // All tags should be "t" tags (hashtags) |
| 167 | assert!(tags.iter().any(|t| { | 164 | for tag in &tags { |
| 168 | if let TagKind::SingleLetter(letter) = t.kind() { | 165 | if let TagKind::SingleLetter(letter) = tag.kind() { |
| 169 | letter == g_tag | 166 | assert_eq!(letter, t_tag); |
| 170 | } else { | 167 | } else { |
| 171 | false | 168 | panic!("Expected SingleLetter tag"); |
| 172 | } | 169 | } |
| 170 | } | ||
| 171 | |||
| 172 | // Check for "t" tag with "grasp-audit-test-event" | ||
| 173 | assert!(tags.iter().any(|t| { | ||
| 174 | t.content() == Some("grasp-audit-test-event") | ||
| 173 | })); | 175 | })); |
| 174 | 176 | ||
| 175 | // Check "r" tag (audit run ID) | 177 | // Check for "t" tag with "audit-{run_id}" |
| 176 | assert!(tags.iter().any(|t| { | 178 | assert!(tags.iter().any(|t| { |
| 177 | if let TagKind::SingleLetter(letter) = t.kind() { | 179 | t.content().map(|c| c.starts_with("audit-ci-")).unwrap_or(false) |
| 178 | letter == r_tag | ||
| 179 | } else { | ||
| 180 | false | ||
| 181 | } | ||
| 182 | })); | 180 | })); |
| 183 | 181 | ||
| 184 | // Check "c" tag (cleanup timestamp) | 182 | // Check for "t" tag with "audit-cleanup-after-{timestamp}" |
| 185 | assert!(tags.iter().any(|t| { | 183 | assert!(tags.iter().any(|t| { |
| 186 | if let TagKind::SingleLetter(letter) = t.kind() { | 184 | t.content().map(|c| c.starts_with("audit-cleanup-after-")).unwrap_or(false) |
| 187 | letter == c_tag | ||
| 188 | } else { | ||
| 189 | false | ||
| 190 | } | ||
| 191 | })); | 185 | })); |
| 192 | } | 186 | } |
| 193 | 187 | ||
diff --git a/grasp-audit/src/client.rs b/grasp-audit/src/client.rs index d78b33c..4831d3f 100644 --- a/grasp-audit/src/client.rs +++ b/grasp-audit/src/client.rs | |||
| @@ -95,16 +95,11 @@ impl AuditClient { | |||
| 95 | 95 | ||
| 96 | if self.config.mode == AuditMode::CI { | 96 | if self.config.mode == AuditMode::CI { |
| 97 | // In CI mode, only see our own audit events | 97 | // In CI mode, only see our own audit events |
| 98 | // Filter by "g" tag (grasp-audit marker) and "r" tag (run ID) | 98 | // Filter by "t" tags (hashtags) |
| 99 | let t_tag = SingleLetterTag::lowercase(Alphabet::T); | ||
| 99 | filter = filter | 100 | filter = filter |
| 100 | .custom_tag( | 101 | .custom_tag(t_tag, "grasp-audit-test-event") |
| 101 | SingleLetterTag::lowercase(Alphabet::G), | 102 | .custom_tag(t_tag, format!("audit-{}", self.config.run_id)); |
| 102 | "grasp-audit" | ||
| 103 | ) | ||
| 104 | .custom_tag( | ||
| 105 | SingleLetterTag::lowercase(Alphabet::R), | ||
| 106 | &self.config.run_id | ||
| 107 | ); | ||
| 108 | } | 103 | } |
| 109 | // In Production mode, see all events (no filter modification) | 104 | // In Production mode, see all events (no filter modification) |
| 110 | 105 | ||