package testpds import ( "encoding/json" "net/http" ) // DIDWebForURL returns the did:web identifier for a local http://host:port // URL, percent-encoding the port colon as did:web requires. It is the DID a // `-tags testmode` build resolves back to that URL by fetching // http://host:port/.well-known/did.json. func DIDWebForURL(rawURL string) string { return "did:web:" + didWebForHost(rawURL) } // HoldDIDDocumentHandler serves a minimal did:web document for a test server // standing in for a hold: both the #atproto_pds and #atcr_hold services point // at baseURL, and no keys are declared. Mount it at /.well-known/did.json so // the test-mode identity directory can resolve the server's DID. func HoldDIDDocumentHandler(did, baseURL string) http.HandlerFunc { doc := map[string]any{ "@context": []string{"https://www.w3.org/ns/did/v1"}, "id": did, "service": []map[string]string{ {"id": "#atproto_pds", "type": "AtprotoPersonalDataServer", "serviceEndpoint": baseURL}, {"id": "#atcr_hold", "type": "AtcrHoldService", "serviceEndpoint": baseURL}, }, } return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/did+ld+json") _ = json.NewEncoder(w).Encode(doc) } }