Add NIP-45, which defines a COUNT verb

This commit is contained in:
Jonathan Staab 2023-01-03 20:11:17 -08:00 committed by fiatjaf
parent 45e6af1ad9
commit e219ec6470
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
2 changed files with 34 additions and 0 deletions

31
45.md Normal file
View File

@ -0,0 +1,31 @@
NIP-45
======
Event Counts
--------------
`draft` `optional` `author:staab`
Relays may support the `COUNT` verb, which provide a mechanism for obtaining event counts.
## Motivation
Some queries a client may want to execute against connected relays are prohibitively expensive, for example, in order to retrieve follower counts for a given pubkey, a client must query all kind-3 events referring to a given pubkey and count them. The result may be cached, either by a client or by a separate indexing server as an alternative, but both options erode the decentralization of the network by creating a second-layer protocol on top of Nostr.
## Filters and return values
This NIP defines a verb called `COUNT`, which accepts a subscription id and a filter as specified in [NIP 01](01.md).
Counts are returned using a `COUNT` response in the form `{count: <integer>}`. Relays may use probabilistic counts to reduce compute requirements.
Examples:
```
# Followers count
["COUNT", "", {kinds: [3], '#p': [<pubkey>]}]
["COUNT", "", {count: 238}]
# Count posts and reactions
["COUNT", "", {kinds: [1, 7], authors: [<pubkey>]}]
["COUNT", "", {count: 5}]
```

View File

@ -33,6 +33,7 @@ NIPs stand for **Nostr Implementation Possibilities**. They exist to document wh
- [NIP-39: External Identities in Profiles](39.md)
- [NIP-40: Expiration Timestamp](40.md)
- [NIP-42: Authentication of clients to relays](42.md)
- [NIP-45: Counting results](45.md)
- [NIP-46: Nostr Connect](46.md)
- [NIP-50: Keywords filter](50.md)
- [NIP-51: Lists](51.md)
@ -88,6 +89,7 @@ NIPs stand for **Nostr Implementation Possibilities**. They exist to document wh
| REQ | used to request events and subscribe to new updates | [1](01.md) |
| CLOSE | used to stop previous subscriptions | [1](01.md) |
| AUTH | used to send authentication events | [42](42.md) |
| COUNT | used to request event counts | [45](45.md) |
### Relay to Client
| type | description | NIP |
@ -97,6 +99,7 @@ NIPs stand for **Nostr Implementation Possibilities**. They exist to document wh
| EOSE | used to notify clients all stored events have been sent | [15](15.md) |
| OK | used to notify clients if an EVENT was successful | [20](20.md) |
| AUTH | used to send authentication challenges | [42](42.md) |
| COUNT | used to send requested event counts to clients | [45](45.md) |
Please update these lists when proposing NIPs introducing new event kinds.