cleanup policy, add zap receipt to policy checker

This commit is contained in:
Amarpreet Minhas 2024-09-23 21:16:58 -04:00
parent 1dee5dec55
commit f5ed963e73

View file

@ -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())
}