From 84d01dc1d32789ccc9b9725bf1cc8fd9f95da8f9 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Wed, 29 Nov 2023 12:23:21 -0300 Subject: [PATCH] rename auth-related fields on WebSocket struct. --- handlers.go | 10 +++++----- websocket.go | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/handlers.go b/handlers.go index c257f02..ca57854 100644 --- a/handlers.go +++ b/handlers.go @@ -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 { diff --git a/websocket.go b/websocket.go index f5ccd29..171d029 100644 --- a/websocket.go +++ b/websocket.go @@ -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 {