rename auth-related fields on WebSocket struct.

This commit is contained in:
fiatjaf 2023-11-29 12:23:21 -03:00
parent 888ac8c1c0
commit 84d01dc1d3
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
2 changed files with 8 additions and 8 deletions

View File

@ -44,9 +44,9 @@ func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request) {
rand.Read(challenge)
ws := &WebSocket{
conn: conn,
Challenge: hex.EncodeToString(challenge),
WaitingForAuth: make(chan struct{}),
conn: conn,
Challenge: hex.EncodeToString(challenge),
Authed: make(chan struct{}),
}
ctx = context.WithValue(ctx, WS_KEY, ws)
@ -177,8 +177,8 @@ func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request) {
case *nostr.AuthEnvelope:
if rl.ServiceURL != "" {
if pubkey, ok := nip42.ValidateAuthEvent(&env.Event, ws.Challenge, rl.ServiceURL); ok {
ws.Authed = pubkey
close(ws.WaitingForAuth)
ws.AuthedPublicKey = pubkey
close(ws.Authed)
ctx = context.WithValue(ctx, AUTH_CONTEXT_KEY, pubkey)
ws.WriteJSON(nostr.OKEnvelope{EventID: env.Event.ID, OK: true})
} else {

View File

@ -11,9 +11,9 @@ type WebSocket struct {
mutex sync.Mutex
// nip42
Challenge string
Authed string
WaitingForAuth chan struct{}
Challenge string
AuthedPublicKey string
Authed chan struct{}
}
func (ws *WebSocket) WriteJSON(any any) error {