MCPcopy Create free account
hub / github.com/NextDotID/proof_server / proofExists

Function proofExists

controller/proof_exists.go:27–70  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

25}
26
27func proofExists(c *gin.Context) {
28 req := ProofExistsRequest{}
29 if err := c.BindQuery(&req); err != nil {
30 errorResp(c, http.StatusBadRequest, xerrors.Errorf("Param error"))
31 return
32 }
33 if !proofExistsCheckRequest(&req) {
34 errorResp(c, http.StatusBadRequest, xerrors.Errorf("Param missing"))
35 return
36 }
37
38 personaPubkey, err := crypto.StringToPubkey(req.PersonaPubkeyHex)
39 if err != nil {
40 errorResp(c, http.StatusBadRequest, xerrors.Errorf("Public key unmarshal error"))
41 return
42 }
43 found := model.Proof{}
44 tx := model.ReadOnlyDB.Where(
45 "persona = ? AND platform = ? AND (identity = ? OR alt_id = ?)",
46 model.MarshalPersona(personaPubkey),
47 req.Platform,
48 strings.ToLower(req.Identity),
49 strings.ToLower(req.Identity),
50 ).Find(&found)
51
52 if tx.Error != nil {
53 errorResp(c, http.StatusInternalServerError, xerrors.Errorf("Error in DB: %w", err))
54 return
55 }
56 if found.ID == int64(0) { // Not found
57 errorResp(c, http.StatusNotFound, xerrors.Errorf("Record not found for %s: %s", req.Platform, req.Identity))
58 return
59 }
60 if found.IsOutdated() {
61 go triggerRevalidate(found.ID)
62 }
63
64 c.JSON(http.StatusOK, ProofExistsResponse{
65 CreatedAt: strconv.FormatInt(found.CreatedAt.Unix(), 10),
66 LastCheckedAt: strconv.FormatInt(found.LastCheckedAt.Unix(), 10),
67 IsValid: found.IsValid,
68 InvalidReason: found.InvalidReason,
69 })
70}
71
72func proofExistsCheckRequest(req *ProofExistsRequest) bool {
73 return req.Identity != "" && req.Platform != "" && req.PersonaPubkeyHex != ""

Callers

nothing calls this directly

Calls 7

IsOutdatedMethod · 0.95
StringToPubkeyFunction · 0.92
MarshalPersonaFunction · 0.92
proofExistsCheckRequestFunction · 0.85
triggerRevalidateFunction · 0.85
FindMethod · 0.80
errorRespFunction · 0.70

Tested by

no test coverage detected