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

Function proofPayload

controller/proof_payload.go:36–91  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

34}
35
36func proofPayload(c *gin.Context) {
37 req := &ProofPayloadRequest{}
38 err := c.BindJSON(req)
39 if err != nil {
40 errorResp(c, http.StatusBadRequest, err)
41 return
42 }
43 if !proofPayloadCheckRequest(req) {
44 errorResp(c, http.StatusBadRequest, xerrors.New("param invalid"))
45 return
46 }
47
48 parsed_pubkey, err := crypto.StringToPubkey(req.PublicKey)
49 if err != nil {
50 errorResp(c, http.StatusBadRequest, xerrors.New("public key not recognized"))
51 return
52 }
53
54 previous_pc, err := model.ProofChainFindLatest(crypto.CompressedPubkeyHex(parsed_pubkey))
55 if err != nil {
56 errorResp(c, http.StatusInternalServerError, xerrors.New("previous proof not found"))
57 return
58 }
59
60 var previous_signature string
61 if previous_pc == nil {
62 previous_signature = ""
63 } else {
64 previous_signature = previous_pc.Signature
65 }
66
67 v := validator.Base{
68 Platform: req.Platform,
69 Previous: previous_signature,
70 Action: req.Action,
71 Pubkey: parsed_pubkey,
72 Identity: req.Identity,
73 Uuid: uuid.New(),
74 CreatedAt: time.Now(),
75 Extra: map[string]string{
76 "wallet_signature": req.Extra.EthereumWalletSignature,
77 },
78 }
79
80 performer := validator.BaseToInterface(&v)
81 if performer == nil {
82 errorResp(c, http.StatusBadRequest, xerrors.New("unknown platform"))
83 return
84 }
85 c.JSON(http.StatusOK, ProofPayloadResponse{
86 PostContent: performer.GeneratePostPayload(),
87 SignPayload: performer.GenerateSignPayload(),
88 CreatedAt: util.TimeToTimestampString(v.CreatedAt),
89 Uuid: v.Uuid.String(),
90 })
91}
92
93func proofPayloadCheckRequest(req *ProofPayloadRequest) bool {

Callers

nothing calls this directly

Calls 9

StringToPubkeyFunction · 0.92
ProofChainFindLatestFunction · 0.92
CompressedPubkeyHexFunction · 0.92
BaseToInterfaceFunction · 0.92
TimeToTimestampStringFunction · 0.92
proofPayloadCheckRequestFunction · 0.85
errorRespFunction · 0.70
GeneratePostPayloadMethod · 0.65
GenerateSignPayloadMethod · 0.65

Tested by

no test coverage detected