From 88c786224d96ee6f72f7e8a21f5113111f406d87 Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Sat, 4 Jul 2026 11:58:30 -0400 Subject: [PATCH] add com.atproto.identity.resolveHandle --- internal/api/resolve_handle.go | 43 ++++++++++++++++++++++++++++++++++ internal/api/server.go | 2 ++ 2 files changed, 45 insertions(+) create mode 100644 internal/api/resolve_handle.go diff --git a/internal/api/resolve_handle.go b/internal/api/resolve_handle.go new file mode 100644 index 0000000..fc8331c --- /dev/null +++ b/internal/api/resolve_handle.go @@ -0,0 +1,43 @@ +package api + +import ( + "context" + "encoding/json" + "log" + "net/http" + "time" + + "github.com/bluesky-social/indigo/api/atproto" + "github.com/bluesky-social/indigo/atproto/syntax" +) + +func (s *Server) ResolveHandle(w http.ResponseWriter, r *http.Request) { + query := r.URL.Query() + + rawHandle := query.Get("handle") + if rawHandle == "" { + http.Error(w, "handle is required", http.StatusBadRequest) + return + } + + handle, err := syntax.ParseHandle(rawHandle) + if err != nil { + http.Error(w, "invalid handle", http.StatusBadRequest) + return + } + + resolveCtx, cancel := context.WithTimeout(r.Context(), 10*time.Second) + defer cancel() + + identity, err := s.Directory.LookupHandle(resolveCtx, handle) + if err != nil { + log.Println("resolve handle:", err) + http.Error(w, "internal error", http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(atproto.IdentityResolveHandle_Output{ + Did: identity.DID.String(), + }) +} diff --git a/internal/api/server.go b/internal/api/server.go index 955f9b0..d759558 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -24,6 +24,8 @@ func (s *Server) Run(addr string) error { mux.HandleFunc("GET /xrpc/blue.microcosm.identity.resolveMiniDoc", s.GetMiniDidDoc) + mux.HandleFunc("GET /xrpc/com.atproto.identity.resolveHandle", s.ResolveHandle) + return http.ListenAndServe(addr, withCORS(mux)) } -- 2.51.2