fix: nostr auth
This commit is contained in:
parent
2fdd3da9d0
commit
46f248d5d1
1 changed files with 8 additions and 7 deletions
|
@ -31,6 +31,7 @@ type nostrUser struct {
|
|||
type nostrWellKnown struct {
|
||||
Names map[string]string `json:"names"`
|
||||
Relays map[string][]string `json:"relays,omitempty"`
|
||||
NIP46 map[string][]string `json:"nip46,omitempty"`
|
||||
}
|
||||
|
||||
func GetNostrAddr(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -89,9 +90,14 @@ func GetNostrAddr(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
// map of nip46
|
||||
t := make(map[string][]string)
|
||||
t[user.Pubkey] = []string{"wss://relay.devvul.com"}
|
||||
|
||||
ret := nostrWellKnown{
|
||||
Names: n,
|
||||
Relays: s,
|
||||
NIP46: t,
|
||||
}
|
||||
|
||||
j, err := json.Marshal(ret)
|
||||
|
@ -134,7 +140,7 @@ 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,
|
||||
|
@ -152,11 +158,6 @@ func NewRelay(version string) *khatru.Relay {
|
|||
|
||||
func RejectUnregisteredNpubs(ctx context.Context, event *nostr.Event) (reject bool, msg string) {
|
||||
l := gologger.Get(config.GetConfig().LogLevel).With().Str("context", "nostr-reject-unregistered").Logger()
|
||||
authenticatedUser := khatru.GetAuthed(ctx)
|
||||
|
||||
if authenticatedUser == "" {
|
||||
return true, fmt.Sprintf("auth-required: user (%s) not authed", event.PubKey)
|
||||
}
|
||||
|
||||
// reject nip-04 messages to users who aren't registered
|
||||
if event.Kind == 4 {
|
||||
|
@ -185,7 +186,7 @@ func RejectUnregisteredNpubs(ctx context.Context, event *nostr.Event) (reject bo
|
|||
err := DB.QueryRow("SELECT id FROM users WHERE pubkey=$1", event.PubKey).Scan(&uid)
|
||||
if err != nil {
|
||||
l.Debug().Msgf("kind: %v, pubkey: %s, error: %s", event.Kind, event.PubKey, err.Error())
|
||||
return true, fmt.Sprintf("pubkey %s is not registered to any users", event.PubKey)
|
||||
return true, fmt.Sprintf("restricted: pubkey %s is not registered to any users", event.PubKey)
|
||||
}
|
||||
return false, ""
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue