From f5ed963e739ed9ea87895955249191d00378bbaa Mon Sep 17 00:00:00 2001 From: Asara Date: Mon, 23 Sep 2024 21:16:58 -0400 Subject: [PATCH] cleanup policy, add zap receipt to policy checker --- nostr/policies.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/nostr/policies.go b/nostr/policies.go index 4730da1..35fe774 100644 --- a/nostr/policies.go +++ b/nostr/policies.go @@ -14,21 +14,34 @@ func RejectUnregisteredNpubs(ctx context.Context, event *nostr.Event) (reject bo var err error l := gologger.Get(config.GetConfig().LogLevel).With().Caller().Logger() - // always allow seals, lightning ephemeral messages, auth messages, addressable events - if event.Kind == 13 || event.Kind == 21000 || event.Kind == 22242 || event.Kind == 30078 || event.Kind == 1059 { + // always allow the following kinds + // 13: nip-59 seals + // 21000: lightning.pub rpc + // 22242: nip-42 client auth + // 30078: nip-78 addressable events + switch event.Kind { + case 13, 21000, 22242, 30078: return false, "" } - // ensure pubkey has authenticated + // ensure pubkey has authenticated their pubkey authenticatedUser := khatru.GetAuthed(ctx) if authenticatedUser == "" { l.Debug().Msgf("kind: %v, pubkey not authed: %s", event.Kind, event.PubKey) return true, fmt.Sprintf("auth-required: interacting with this relay requires authentication") } + // check if the message is by or for someone who is registered npubs := []string{authenticatedUser} - // add recipients of dms/private dms/gift wraps/signature requests to npubs list - if event.Kind == 4 || event.Kind == 14 || event.Kind == 1059 || event.Kind == 24133 { + // in addition to the registered users, others can use the relay for the following kinds + // as long as a registered user is tagged in the `p` tag + // 4: nip-04 encrypted dms + // 14: nip-17 private dms + // 1059: nip-59 gift wraps + // 9735: nip-57 zap receipt + // 24133: nip-46 nostr connect + switch event.Kind { + case 4, 14, 1059, 9735, 24133: for _, npub := range event.Tags.GetAll([]string{"p"}) { npubs = append(npubs, npub.Value()) }