Re-write net docs

This commit is contained in:
Jon Staab
2025-06-10 15:07:58 -07:00
parent 5b73c507b7
commit 1a81768e8e
22 changed files with 580 additions and 840 deletions
+53
View File
@@ -0,0 +1,53 @@
# Diff
Efficient event synchronization using NIP-77 Negentropy protocol.
## Core Classes
### `Difference`
Handles negentropy synchronization with a single relay for a single filter.
**Events:**
- `DifferenceEvent.Message` - Emitted with `{have, need}` arrays and relay URL
- `DifferenceEvent.Error` - Emitted when sync fails
- `DifferenceEvent.Close` - Emitted when sync completes
**Methods:**
- `close()` - Stop synchronization and cleanup
## Functions
### `diff(options)`
Check what events each relay has or needs compared to local events.
**Returns:** Array of `{relay, have, need}` objects - `have` are events the relay has that you don't, `need` are events you have that the relay doesn't.
### `pull(options)`
Fetch missing events after comparing with relays.
**Returns:** Array of retrieved events.
### `push(options)`
Publish local events that relays are missing.
## Example
```typescript
// Check what events each relay has/needs
const results = await diff({
relays: ['wss://relay1.com', 'wss://relay2.com'],
filters: [{kinds: [1], authors: ['pubkey...']}],
events: localEvents
})
// Pull events that relays have but we don't
const newEvents = await pull({
relays: ['wss://relay1.com'],
filters: [{kinds: [1]}],
events: localEvents
})
```