MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / handleRealityKeypair

Function handleRealityKeypair

internal/serverapi/tools.go:16–36  ·  view source on GitHub ↗

handleRealityKeypair 生成 Reality 所需的 X25519 密钥对和 Short ID。

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

14
15// handleRealityKeypair 生成 Reality 所需的 X25519 密钥对和 Short ID。
16func handleRealityKeypair(w http.ResponseWriter, r *http.Request) {
17 if r.Method != http.MethodGet {
18 writeMethodNotAllowed(w, http.MethodGet)
19 return
20 }
21 key, err := ecdh.X25519().GenerateKey(rand.Reader)
22 if err != nil {
23 internalError(w, r, err)
24 return
25 }
26 var sidBytes [8]byte
27 if _, err := rand.Read(sidBytes[:]); err != nil {
28 internalError(w, r, err)
29 return
30 }
31 writeJSON(w, http.StatusOK, map[string]any{
32 "private_key": base64.RawURLEncoding.EncodeToString(key.Bytes()),
33 "public_key": base64.RawURLEncoding.EncodeToString(key.PublicKey().Bytes()),
34 "short_id": hex.EncodeToString(sidBytes[:]),
35 })
36}

Callers

nothing calls this directly

Calls 4

writeMethodNotAllowedFunction · 0.85
internalErrorFunction · 0.85
writeJSONFunction · 0.70
ReadMethod · 0.45

Tested by

no test coverage detected