diff options
| author | Jeff Thibault <jdthibault2@gmail.com> | 2022-08-13 13:52:14 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-13 13:52:14 -0400 |
| commit | ef0f8a1186631dd7808614960cd11168139aa28e (patch) | |
| tree | 01c0b6c89ab301b6e21103f2894655bd7bf2c688 | |
| parent | a902083bac9b95ec1ed9e4e1dc1d018b4a7f2696 (diff) | |
rename and rewrite to be more generic
| -rw-r--r-- | 22.md | 29 |
1 files changed, 18 insertions, 11 deletions
| @@ -1,31 +1,38 @@ | |||
| 1 | NIP-22 | 1 | NIP-22 |
| 2 | ====== | 2 | ====== |
| 3 | 3 | ||
| 4 | Unacceptable Event `created_at` time | 4 | Event `created_at` Limits |
| 5 | --------------------------- | 5 | --------------------------- |
| 6 | 6 | ||
| 7 | `draft` `optional` `author:jeffthibault` | 7 | `draft` `optional` `author:jeffthibault` |
| 8 | 8 | ||
| 9 | Relays may support notifying clients that the event they published has an unacceptable `created_at` time. A relay will consider the `created_at` time unacceptable if the `created_at` time is more than **[limit]** before the event was received by the relay (in the past) OR if the `created_at` time is later than the time the event was received by the relay (in the future). | 9 | Relays may define both upper and lower limits for which they will consider an event's `created_at` time to be acceptable if it is within those limits. Both the upper and lower limits MUST be unix timestamps to match the format of the event's `created_at` field. The upper limit restricts how far into the future an event's `created_at` time can be set to and the lower limit restricts how far into the past an event's `created_at` time can be set to. |
| 10 | 10 | ||
| 11 | If a relay supports this NIP, the relay SHOULD send the client a `NOTICE` message saying the event was not stored because the `created_at` time was unacceptable. | 11 | If a relay supports this NIP, the relay SHOULD send the client a `NOTICE` message saying the event was not stored when the `created_at` time is not within the upper and lower limits. |
| 12 | 12 | ||
| 13 | Client Behavior | 13 | Client Behavior |
| 14 | --------------- | 14 | --------------- |
| 15 | 15 | ||
| 16 | Clients SHOULD use the `supported_nips` field to learn if a relay supports event `created_at` time checks. | 16 | Clients SHOULD use the `supported_nips` field to learn if a relay uses event `created_at` time limits as defined by this NIP. |
| 17 | 17 | ||
| 18 | Motivation | 18 | Motivation |
| 19 | ---------- | 19 | ---------- |
| 20 | 20 | ||
| 21 | The motivation for this NIP is to prevent clients from saying they published an event *significantly* earlier than they actually did or saying they published an event in the future. | 21 | The motivation for this NIP is to formalize a way for relays to restrict event timestamps to times they deem to be acceptable and allow clients to be aware of relays that have these restrictions. |
| 22 | 22 | ||
| 23 | The event `created_at` field is just a unix timestamp (integer) so one could set it to a time in the past or future. For example, the `created_at` field could be set to a time 10 years ago even though it was created today and it could still be a valid event. One could also set the `created_at` field to a time 10 years in the future and it could still be a valid event. This NIP aims to set a maximum amount of time elapsed between when an event was created and when it was *actually* published and prevent events from being from the future. | 23 | The event `created_at` field is just a unix timestamp and can be set to a time in the past or future. For example, the `created_at` field can be set to a time 20 years ago even though it was created today and still be a valid event. It can also be set to a time 20 years in the future and still be a valid event. This NIP aims to define a way for relays that do not want to store events with *any* timestamp to set their own restrictions. |
| 24 | 24 | ||
| 25 | Relay Logic | 25 | A wide adoption of this could create a better UX on clients as well because it would decrease the liklihood of the user seeing events from dates such as 1984 or 2084, which could be confusing. |
| 26 | ----------- | ||
| 27 | 26 | ||
| 28 | ``` | 27 | Python Example |
| 29 | if time.now - event.created_at > limit OR event.created_at > time.now: | 28 | -------------- |
| 30 | send NOTICE | 29 | |
| 30 | ```python | ||
| 31 | import time | ||
| 32 | |||
| 33 | UPPER_LIMIT = int(time.now) + 900 # Define upper limit as 15 minutes into the future | ||
| 34 | LOWER_LIMIT = int(time.now) - 86400 # Define lower limit as 1 day into the past | ||
| 35 | |||
| 36 | if event.created_at < LOWER_LIMIT or event.created_at > UPPER_LIMIT: | ||
| 37 | ws.send('["NOTICE", "The event created_at field is out of the acceptable range for this relay and was not stored."]') | ||
| 31 | ``` | 38 | ``` |