rx-nostr
Version:
A library based on RxJS, which allows Nostr applications to easily communicate with relays.
22 lines (16 loc) • 429 B
text/typescript
import * as Nostr from "nostr-typedef";
export function isExpired(event: Nostr.Event, now?: number): boolean {
const tag = event.tags.find((tag) => tag[0] === "expiration");
if (!tag) {
return false;
}
try {
const timestamp = Number(tag[1]);
if (!Number.isInteger(timestamp)) {
return false;
}
return timestamp <= (now ?? Math.floor(Date.now() / 1000));
} catch {
return false;
}
}