1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package pds
import (
"net/http"
"github.com/johnandersen777/socialweb-computer-kcp/internal/kit/httpjson"
)
func (s *Server) handleWellKnownDID(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(s.serviceDID))
}
func (s *Server) handleWellKnownDIDDocument(w http.ResponseWriter, r *http.Request) {
doc := map[string]any{
"@context": []string{
"https://www.w3.org/ns/did/v1",
"https://w3id.org/security/multikey/v1",
},
"id": s.serviceDID,
}
if len(s.cfg.AlsoKnownAs) > 0 {
doc["alsoKnownAs"] = append([]string(nil), s.cfg.AlsoKnownAs...)
}
if s.cfg.OAuth != nil && s.cfg.OAuth.Signer.Key != nil {
if pub, err := s.cfg.OAuth.Signer.Key.PublicKey(); err == nil {
doc["verificationMethod"] = []map[string]any{{
"id": s.serviceDID + "#atproto",
"type": "Multikey",
"controller": s.serviceDID,
"publicKeyMultibase": pub.Multibase(),
}}
}
}
endpoint := s.cfg.PublicBaseURL
if endpoint == "" {
endpoint = s.publicURL(r)
}
doc["service"] = []map[string]any{{
"id": "#atproto_pds",
"type": "AtprotoPersonalDataServer",
"serviceEndpoint": endpoint,
}}
httpjson.Write(w, http.StatusOK, doc)
}