nbd-wtf / nostr-tools

Tools for developing Nostr clients.
The Unlicense
685 stars 188 forks source link

Add stable sortEvents function #398

Closed alexgleason closed 4 months ago

alexgleason commented 4 months ago

Adds a function to sort events, which is often needed when gathering events from untrusted sources such as relays.

Events are sorted reverse-chronologically by the created_at timestamp. If there is a tie with created_at, it sorts lexicographically by the event ID.

fiatjaf commented 4 months ago

NIP-01 says this about replaceable events:

In case of replaceable events with the same timestamp, the event with the lowest id (first in lexical order) should be retained, and the other discarded.

Does this match your function?

alexgleason commented 4 months ago

Yes it does :+1: Cool.