From 8fb5cd112dd7c8afb1f577f2de19ba1d622baa69 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sun, 12 Jan 2025 21:29:20 -0300 Subject: [PATCH] add nip40 helper. --- nip40/nip40.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 nip40/nip40.go diff --git a/nip40/nip40.go b/nip40/nip40.go new file mode 100644 index 0000000..f1cadfd --- /dev/null +++ b/nip40/nip40.go @@ -0,0 +1,22 @@ +package nip40 + +import ( + "strconv" + + "github.com/nbd-wtf/go-nostr" +) + +// GetExpiration returns the expiration timestamp for this event, or -1 if no "expiration" tag exists or +// if it is invalid. +func GetExpiration(tags nostr.Tags) nostr.Timestamp { + for _, tag := range tags { + if len(tag) >= 2 && tag[0] == "expiration" { + if ts, err := strconv.ParseInt(tag[1], 10, 64); err == nil { + return nostr.Timestamp(ts) + } else { + return -1 + } + } + } + return -1 +}