upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/docs/archive/2025-11-04-nostr-sdk-upgrade.md
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-11-04 09:31:57 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-11-04 09:31:57 +0000
commit22557f15d6a7b77f72d4597fc05aa06346495a33 (patch)
treee31e0cdecfc4cb1e28246227a7ef295b71687b09 /docs/archive/2025-11-04-nostr-sdk-upgrade.md
parentb3031800cd95601c2d9cd2d24034364d1496b073 (diff)
docs: major cleanup and reorganization
- Archive 30 completed session documents to docs/archive/ - Extract learnings to docs/learnings/ (nix-flakes, nostr-sdk, grasp-audit) - Create CURRENT_STATUS.md as single source of truth - Create AGENTS.md with documentation guidelines - Create docs/archive/README.md for archive organization - Clean root directory: 32 files → 4 files Root directory now contains only: - README.md (project overview) - AGENTS.md (documentation guidelines) - CURRENT_STATUS.md (current state) - CLEANUP_SUMMARY.md (cleanup report) All historical documents preserved in docs/archive/ with proper dating. All reusable knowledge extracted to docs/learnings/. Benefits: - Easy to find current information - Clear document lifecycle - No more documentation sprawl - Learnings are accessible and reusable - Better onboarding for new developers/agents File counts: - Root: 4 (was 32) - Permanent docs: 7 - Learnings: 3 (new) - Archive: 32 (new) - Total: 49 well-organized docs
Diffstat (limited to 'docs/archive/2025-11-04-nostr-sdk-upgrade.md')
-rw-r--r--docs/archive/2025-11-04-nostr-sdk-upgrade.md346
1 files changed, 346 insertions, 0 deletions
diff --git a/docs/archive/2025-11-04-nostr-sdk-upgrade.md b/docs/archive/2025-11-04-nostr-sdk-upgrade.md
new file mode 100644
index 0000000..052b851
--- /dev/null
+++ b/docs/archive/2025-11-04-nostr-sdk-upgrade.md
@@ -0,0 +1,346 @@
1# nostr-sdk 0.35 → 0.43 Upgrade Guide
2
3**Date:** November 4, 2025
4**Status:** ✅ Complete - All tests passing
5**Upgrade:** nostr-sdk 0.35.0 → 0.43.0 (8 minor versions)
6
7---
8
9## Summary
10
11Successfully upgraded `grasp-audit` from **nostr-sdk 0.35** to **nostr-sdk 0.43**, fixing all breaking API changes. The upgrade brings us to the latest stable version with improved APIs and better performance.
12
13---
14
15## Breaking Changes Fixed
16
17### 1. EventBuilder::to_event() → sign_with_keys()
18
19**Change:** Event signing method renamed and simplified.
20
21**Before (0.35):**
22```rust
23let event = EventBuilder::new(kind, content, tags)
24 .to_event(keys)?;
25```
26
27**After (0.43):**
28```rust
29let event = EventBuilder::new(kind, content)
30 .tags(tags)
31 .sign_with_keys(keys)?;
32```
33
34**Rationale:** Better separation of concerns - tags are added via builder pattern, signing is explicit.
35
36**Files Changed:**
37- `src/audit.rs` - `AuditEventBuilder::build()`
38- `src/specs/nip01_smoke.rs` - Test event creation
39
40---
41
42### 2. EventBuilder::new() Signature Changed
43
44**Change:** Tags parameter removed from constructor.
45
46**Before (0.35):**
47```rust
48EventBuilder::new(kind, content, tags)
49```
50
51**After (0.43):**
52```rust
53EventBuilder::new(kind, content)
54 .tags(tags)
55```
56
57**Rationale:** Cleaner API - use builder pattern for optional parameters.
58
59**Files Changed:**
60- `src/audit.rs`
61- `src/specs/nip01_smoke.rs`
62
63---
64
65### 3. Client::new() Takes Ownership of Keys
66
67**Change:** Client now takes ownership of signer instead of reference.
68
69**Before (0.35):**
70```rust
71let keys = Keys::generate();
72let client = Client::new(&keys);
73// keys still available
74```
75
76**After (0.43):**
77```rust
78let keys = Keys::generate();
79let client = Client::new(keys.clone());
80// Need to clone if we want to keep keys
81```
82
83**Rationale:** Allows Client to own the signer, enabling more flexible signer types.
84
85**Files Changed:**
86- `src/client.rs` - `AuditClient::new()`
87- `src/client.rs` - Test `test_event_builder()`
88
89---
90
91### 4. Relay::is_connected() No Longer Async
92
93**Change:** Connection status check is now synchronous.
94
95**Before (0.35):**
96```rust
97if relay.is_connected().await {
98 // ...
99}
100```
101
102**After (0.43):**
103```rust
104if relay.is_connected() {
105 // ...
106}
107```
108
109**Rationale:** Status check doesn't require async operation.
110
111**Files Changed:**
112- `src/client.rs` - `AuditClient::is_connected()`
113
114---
115
116### 5. Client::get_events_of() → fetch_events()
117
118**Change:** Query API completely redesigned.
119
120**Before (0.35):**
121```rust
122let events = client
123 .get_events_of(vec![filter], EventSource::relays(Some(timeout)))
124 .await?;
125// Returns Vec<Event>
126```
127
128**After (0.43):**
129```rust
130let events = client
131 .fetch_events(filter, timeout)
132 .await?;
133// Returns Events (iterable collection)
134
135// Convert to Vec<Event>
136let vec: Vec<Event> = events.into_iter().collect();
137```
138
139**Rationale:**
140- Simpler API - single filter instead of vec
141- Better type safety - `Events` type instead of `Vec<Event>`
142- Removed confusing `EventSource` parameter
143
144**Files Changed:**
145- `src/client.rs` - `AuditClient::query()`
146- `src/client.rs` - `AuditClient::subscribe()`
147
148---
149
150### 6. Filter::custom_tag() Takes Single Value
151
152**Change:** Custom tag values are now single strings instead of arrays.
153
154**Before (0.35):**
155```rust
156filter.custom_tag(tag, ["value"])
157filter.custom_tag(tag, [&string_ref])
158```
159
160**After (0.43):**
161```rust
162filter.custom_tag(tag, "value")
163filter.custom_tag(tag, &string_ref)
164```
165
166**Rationale:** Simplified API for common case of single tag value.
167
168**Files Changed:**
169- `src/client.rs` - `AuditClient::query()` filter construction
170
171---
172
173### 7. Client::send_event() Takes Reference
174
175**Change:** Send event now takes a reference instead of ownership.
176
177**Before (0.35):**
178```rust
179let event_id = client.send_event(event).await?;
180```
181
182**After (0.43):**
183```rust
184let output = client.send_event(&event).await?;
185let event_id = *output.id();
186```
187
188**Rationale:** Allows reusing events, better memory efficiency.
189
190**Files Changed:**
191- `src/client.rs` - `AuditClient::send_event()`
192
193---
194
195### 8. Multiple Filters Handling
196
197**Change:** No direct multi-filter query method.
198
199**Before (0.35):**
200```rust
201let events = client.get_events_of(vec![filter1, filter2], timeout).await?;
202```
203
204**After (0.43):**
205```rust
206// Fetch each filter separately and combine
207let mut all_events = Vec::new();
208for filter in filters {
209 let events = client.fetch_events(filter, timeout).await?;
210 all_events.extend(events.into_iter());
211}
212```
213
214**Rationale:** Simpler API surface, explicit about multiple queries.
215
216**Files Changed:**
217- `src/client.rs` - `AuditClient::subscribe()`
218
219---
220
221## Migration Checklist
222
223- [x] Update `Cargo.toml` dependency: `nostr-sdk = "0.43"`
224- [x] Fix `EventBuilder::new()` calls - remove tags parameter
225- [x] Fix `EventBuilder::to_event()` → `sign_with_keys()`
226- [x] Fix `Client::new()` calls - clone keys instead of reference
227- [x] Fix `Relay::is_connected()` - remove `.await`
228- [x] Fix `Client::get_events_of()` → `fetch_events()`
229- [x] Fix `EventSource::relays()` usage - remove entirely
230- [x] Fix `Filter::custom_tag()` - single value instead of array
231- [x] Fix `Client::send_event()` - pass reference
232- [x] Fix multiple filter queries - loop and combine
233- [x] Update tests
234- [x] Verify all unit tests pass
235- [x] Verify CLI builds
236- [x] Verify examples build
237
238---
239
240## Test Results
241
242### Unit Tests
243```bash
244$ cargo test --lib
245running 13 tests
246test result: ok. 12 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out
247```
248
249### Build Status
250```bash
251$ cargo build
252Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.73s
253
254$ cargo build --bin grasp-audit
255Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.56s
256
257$ cargo build --example simple_audit
258Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.67s
259```
260
261### CLI Verification
262```bash
263$ ./target/debug/grasp-audit --help
264GRASP audit and compliance testing tool
265
266Usage: grasp-audit <COMMAND>
267
268Commands:
269 audit Run audit tests against a server
270 help Print this message or the help of the given subcommand(s)
271
272Options:
273 -h, --help Print help
274```
275
276---
277
278## Benefits of 0.43
279
280### API Improvements
281- **Cleaner EventBuilder API**: Builder pattern for tags
282- **Explicit signing**: `sign_with_keys()` is more descriptive than `to_event()`
283- **Simpler queries**: Single filter instead of vec reduces complexity
284- **Better type safety**: `Events` type vs. `Vec<Event>`
285
286### Performance
287- **Reduced allocations**: Reference passing in `send_event()`
288- **Sync status checks**: No async overhead for `is_connected()`
289
290### Future Compatibility
291- On latest stable release
292- Better positioned for future updates
293- Access to latest NIP implementations
294
295---
296
297## Backward Compatibility
298
299**Breaking:** This upgrade is **NOT** backward compatible with nostr-sdk 0.35.
300
301If you need to stay on 0.35:
302```toml
303[dependencies]
304nostr-sdk = "=0.35.0" # Pin to exact version
305```
306
307---
308
309## Files Modified
310
3111. **Cargo.toml** - Updated dependency version
3122. **src/audit.rs** - EventBuilder API changes
3133. **src/client.rs** - Client, query, and filter API changes
3144. **src/specs/nip01_smoke.rs** - Test event creation
315
316---
317
318## Next Steps
319
320### Immediate
321- ✅ All compilation errors fixed
322- ✅ All unit tests passing
323- ✅ CLI builds successfully
324- ⏳ Integration tests (require running relay)
325
326### Future Optimizations
327- Consider using `Events` type directly instead of converting to `Vec<Event>`
328- Explore new 0.43 features (check changelog)
329- Review if any deprecated methods are used
330- Check for new NIPs supported in 0.43
331
332---
333
334## References
335
336- [nostr-sdk 0.43.0 on crates.io](https://crates.io/crates/nostr-sdk/0.43.0)
337- [rust-nostr GitHub](https://github.com/rust-nostr/nostr)
338- [nostr-sdk documentation](https://docs.rs/nostr-sdk/0.43.0)
339
340---
341
342## Conclusion
343
344The upgrade to nostr-sdk 0.43 was successful. All breaking changes have been addressed, and the code now uses the latest stable APIs. The test suite passes completely, demonstrating that functionality is preserved while benefiting from API improvements and bug fixes in the newer version.
345
346**Recommendation:** Keep up with nostr-sdk releases to avoid large upgrade gaps in the future. The rust-nostr team maintains good backward compatibility within minor versions, so staying current reduces upgrade friction.