From 6fc68dc03983f2808b39f8b6a65af8149e53af34 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Wed, 26 Mar 2025 12:56:55 -0300 Subject: [PATCH] nip70: HasEmbeddedProtected() --- nip70/nip70.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/nip70/nip70.go b/nip70/nip70.go index 4cb0755..907d965 100644 --- a/nip70/nip70.go +++ b/nip70/nip70.go @@ -1,8 +1,12 @@ package nip70 -import "github.com/nbd-wtf/go-nostr" +import ( + "strings" -func IsProtected(event *nostr.Event) bool { + "github.com/nbd-wtf/go-nostr" +) + +func IsProtected(event nostr.Event) bool { for _, tag := range event.Tags { if len(tag) == 1 && tag[0] == "-" { return true @@ -10,3 +14,16 @@ func IsProtected(event *nostr.Event) bool { } return false } + +func HasEmbeddedProtected(event nostr.Event) bool { + if event.Kind == 6 || event.Kind == 16 { + tidx := strings.Index(event.Content, `"tags":[`) + eidx := strings.Index(event.Content, `]]`) + pidx := strings.Index(event.Content, `["-"]`) + if tidx != -1 && eidx != -1 && pidx != -1 { + return pidx > tidx && pidx < eidx + } + } + + return false +}