fix: nip42 support
This commit is contained in:
parent
42cf28fe1b
commit
4c4037f116
1 changed files with 11 additions and 6 deletions
|
@ -147,12 +147,11 @@ func NewRelay(version string) *khatru.Relay {
|
|||
relay.DeleteEvent = append(relay.DeleteEvent, RelayDb.DeleteEvent)
|
||||
|
||||
// apply policies
|
||||
//policies.ApplySaneDefaults(relay)
|
||||
policies.ApplySaneDefaults(relay)
|
||||
|
||||
relay.RejectEvent = append(
|
||||
relay.RejectEvent,
|
||||
RejectUnregisteredNpubs,
|
||||
policies.RejectEventsWithBase64Media,
|
||||
policies.ValidateKind,
|
||||
)
|
||||
|
||||
|
@ -171,6 +170,12 @@ func RejectUnregisteredNpubs(ctx context.Context, event *nostr.Event) (reject bo
|
|||
return false, ""
|
||||
}
|
||||
|
||||
authenticatedUser := khatru.GetAuthed(ctx)
|
||||
if authenticatedUser == "" {
|
||||
l.Debug().Msgf("pubkey not authed: %s", event.PubKey)
|
||||
return true, fmt.Sprintf("auth-required: interacting with this relay requires authentication")
|
||||
}
|
||||
|
||||
// reject nip-04 messages to users who aren't registered
|
||||
if event.Kind == 4 {
|
||||
receiver := event.Tags.GetFirst([]string{"p"}).Value()
|
||||
|
@ -181,24 +186,24 @@ func RejectUnregisteredNpubs(ctx context.Context, event *nostr.Event) (reject bo
|
|||
}
|
||||
|
||||
var sid int
|
||||
err = DB.QueryRow("SELECT id FROM users WHERE pubkey=$1", event.PubKey).Scan(&sid)
|
||||
err = DB.QueryRow("SELECT id FROM users WHERE pubkey=$1", authenticatedUser).Scan(&sid)
|
||||
if err != nil {
|
||||
sid = -1
|
||||
}
|
||||
|
||||
if rid != -1 || sid != -1 {
|
||||
l.Debug().Msgf("pubkeys %s or %s not found to be registered", receiver, event.PubKey)
|
||||
return true, fmt.Sprintf("nobody in this nip04 message is registered to the relay")
|
||||
return true, fmt.Sprintf("restricted: nobody in this nip04 message is registered to the relay")
|
||||
}
|
||||
return false, ""
|
||||
}
|
||||
|
||||
// check if user is registered
|
||||
var uid int
|
||||
err := DB.QueryRow("SELECT id FROM users WHERE pubkey=$1", event.PubKey).Scan(&uid)
|
||||
err := DB.QueryRow("SELECT id FROM users WHERE pubkey=$1", authenticatedUser).Scan(&uid)
|
||||
if err != nil {
|
||||
l.Debug().Msgf("kind: %v, pubkey: %s, error: %s", event.Kind, event.PubKey, err.Error())
|
||||
return true, fmt.Sprintf("restricted: pubkey %s is not registered to any users", event.PubKey)
|
||||
return true, fmt.Sprintf("restricted: pubkey %s is not registered to any users", authenticatedUser)
|
||||
}
|
||||
return false, ""
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue