MCPcopy Create free account
hub / github.com/daodst/chat / QueryInviteRes

Function QueryInviteRes

federationapi/routing/new_func.go:34–97  ·  view source on GitHub ↗
(
	httpReq *http.Request,
)

Source from the content-addressed store, hash-verified

32var errMissingUserID = errors.New("'user_id' must be supplied")
33
34func QueryInviteRes(
35 httpReq *http.Request,
36) util.JSONResponse {
37 // 1, ,,chat_addr
38 req := queryReq{}
39 resErr := httputil.UnmarshalJSONRequest(httpReq, &req)
40 if resErr != nil {
41 return *resErr
42 }
43 if req.QuerySign == "" || req.Invitee == "" || req.PubKey == "" {
44 return util.JSONResponse{
45 Code: http.StatusBadRequest,
46 JSON: jsonerror.BadJSON("invalid params"),
47 }
48 }
49 // 1.1,
50 pubKeyBytes, err := hex.DecodeString(req.PubKey)
51 if err != nil {
52 return util.JSONResponse{
53 Code: http.StatusBadRequest,
54 JSON: jsonerror.Unknown("err hex fmt of PubKey"),
55 }
56 }
57 signBytes, err := hex.DecodeString(req.QuerySign)
58 if err != nil {
59 return util.JSONResponse{
60 Code: http.StatusBadRequest,
61 JSON: jsonerror.Unknown("err hex fmt of QuerySign"),
62 }
63 }
64 msgBytes := []byte(req.Timestamp)
65 pubKeyChat := ethsecp256k1.PubKey{Key: pubKeyBytes}
66 addressHexChat := sdk.AccAddress(pubKeyChat.Address()).String()
67 //addressHex := pubKey.Address().String()
68 recoveredChatAddress := strings.ToLower(addressHexChat)
69
70 if !pubKeyChat.VerifySignature(msgBytes, signBytes) {
71 return util.JSONResponse{
72 Code: http.StatusBadRequest,
73 JSON: jsonerror.BadJSON("check sign err"),
74 }
75 }
76 // 2, chat_addrlocalpart :1, 2,,,
77 localPart, err := new_feature.GetLocalByChatAddr(recoveredChatAddress)
78 if err != nil {
79 util.GetLogger(httpReq.Context()).WithError(err).Error("new_feature.GetLocalByChatAddr")
80 }
81 if localPart == "" {
82 localPart = req.Localpart
83 }
84 // 3, ,get/user/by/phone
85 res, err := new_feature.QueryInviteRes(localPart, req.Invitee)
86 if err != nil {
87 return util.JSONResponse{
88 Code: http.StatusInternalServerError,
89 JSON: jsonerror.Unknown(err.Error()),
90 }
91 }

Callers

nothing calls this directly

Calls 4

AddressMethod · 0.80
ContextMethod · 0.80
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected