nips/22.md

39 lines
2.1 KiB
Markdown
Raw Normal View History

NIP-22
======
2022-08-13 13:52:14 -04:00
Event `created_at` Limits
---------------------------
`draft` `optional` `author:jeffthibault`
2022-08-13 13:52:14 -04:00
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.
2022-08-13 13:52:14 -04:00
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.
Client Behavior
---------------
2022-08-13 13:52:14 -04:00
Clients SHOULD use the `supported_nips` field to learn if a relay uses event `created_at` time limits as defined by this NIP.
Motivation
----------
2022-08-13 13:52:14 -04:00
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.
2022-08-13 13:52:14 -04:00
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.
2022-07-22 12:53:54 -04:00
2022-08-13 13:52:14 -04:00
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.
2022-07-22 12:53:54 -04:00
2022-08-13 13:52:14 -04:00
Python Example
--------------
```python
import time
UPPER_LIMIT = int(time.now) + 900 # Define upper limit as 15 minutes into the future
LOWER_LIMIT = int(time.now) - 86400 # Define lower limit as 1 day into the past
if event.created_at < LOWER_LIMIT or event.created_at > UPPER_LIMIT:
ws.send('["NOTICE", "The event created_at field is out of the acceptable range for this relay and was not stored."]')
2022-07-22 12:53:54 -04:00
```