diff options
| author | Jonathan Staab <shtaab@gmail.com> | 2023-01-03 20:11:17 -0800 |
|---|---|---|
| committer | fiatjaf <fiatjaf@gmail.com> | 2023-04-05 18:41:14 -0300 |
| commit | e219ec64701d89e6b2c3f3ca8fd426d0aefdcb9c (patch) | |
| tree | 43dc4d0d6d4bd01dd239f0141bbdae802526f873 | |
| parent | 45e6af1ad9d10e66417c07b995e497171653f0c1 (diff) | |
Add NIP-45, which defines a COUNT verb
| -rw-r--r-- | 45.md | 31 | ||||
| -rw-r--r-- | README.md | 3 |
2 files changed, 34 insertions, 0 deletions
| @@ -0,0 +1,31 @@ | |||
| 1 | NIP-45 | ||
| 2 | ====== | ||
| 3 | |||
| 4 | Event Counts | ||
| 5 | -------------- | ||
| 6 | |||
| 7 | `draft` `optional` `author:staab` | ||
| 8 | |||
| 9 | Relays may support the `COUNT` verb, which provide a mechanism for obtaining event counts. | ||
| 10 | |||
| 11 | ## Motivation | ||
| 12 | |||
| 13 | 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. | ||
| 14 | |||
| 15 | ## Filters and return values | ||
| 16 | |||
| 17 | This NIP defines a verb called `COUNT`, which accepts a subscription id and a filter as specified in [NIP 01](01.md). | ||
| 18 | |||
| 19 | Counts are returned using a `COUNT` response in the form `{count: <integer>}`. Relays may use probabilistic counts to reduce compute requirements. | ||
| 20 | |||
| 21 | Examples: | ||
| 22 | |||
| 23 | ``` | ||
| 24 | # Followers count | ||
| 25 | ["COUNT", "", {kinds: [3], '#p': [<pubkey>]}] | ||
| 26 | ["COUNT", "", {count: 238}] | ||
| 27 | |||
| 28 | # Count posts and reactions | ||
| 29 | ["COUNT", "", {kinds: [1, 7], authors: [<pubkey>]}] | ||
| 30 | ["COUNT", "", {count: 5}] | ||
| 31 | ``` | ||
| @@ -33,6 +33,7 @@ NIPs stand for **Nostr Implementation Possibilities**. They exist to document wh | |||
| 33 | - [NIP-39: External Identities in Profiles](39.md) | 33 | - [NIP-39: External Identities in Profiles](39.md) |
| 34 | - [NIP-40: Expiration Timestamp](40.md) | 34 | - [NIP-40: Expiration Timestamp](40.md) |
| 35 | - [NIP-42: Authentication of clients to relays](42.md) | 35 | - [NIP-42: Authentication of clients to relays](42.md) |
| 36 | - [NIP-45: Counting results](45.md) | ||
| 36 | - [NIP-46: Nostr Connect](46.md) | 37 | - [NIP-46: Nostr Connect](46.md) |
| 37 | - [NIP-50: Keywords filter](50.md) | 38 | - [NIP-50: Keywords filter](50.md) |
| 38 | - [NIP-51: Lists](51.md) | 39 | - [NIP-51: Lists](51.md) |
| @@ -88,6 +89,7 @@ NIPs stand for **Nostr Implementation Possibilities**. They exist to document wh | |||
| 88 | | REQ | used to request events and subscribe to new updates | [1](01.md) | | 89 | | REQ | used to request events and subscribe to new updates | [1](01.md) | |
| 89 | | CLOSE | used to stop previous subscriptions | [1](01.md) | | 90 | | CLOSE | used to stop previous subscriptions | [1](01.md) | |
| 90 | | AUTH | used to send authentication events | [42](42.md) | | 91 | | AUTH | used to send authentication events | [42](42.md) | |
| 92 | | COUNT | used to request event counts | [45](45.md) | | ||
| 91 | 93 | ||
| 92 | ### Relay to Client | 94 | ### Relay to Client |
| 93 | | type | description | NIP | | 95 | | type | description | NIP | |
| @@ -97,6 +99,7 @@ NIPs stand for **Nostr Implementation Possibilities**. They exist to document wh | |||
| 97 | | EOSE | used to notify clients all stored events have been sent | [15](15.md) | | 99 | | EOSE | used to notify clients all stored events have been sent | [15](15.md) | |
| 98 | | OK | used to notify clients if an EVENT was successful | [20](20.md) | | 100 | | OK | used to notify clients if an EVENT was successful | [20](20.md) | |
| 99 | | AUTH | used to send authentication challenges | [42](42.md) | | 101 | | AUTH | used to send authentication challenges | [42](42.md) | |
| 102 | | COUNT | used to send requested event counts to clients | [45](45.md) | | ||
| 100 | 103 | ||
| 101 | Please update these lists when proposing NIPs introducing new event kinds. | 104 | Please update these lists when proposing NIPs introducing new event kinds. |
| 102 | 105 | ||