Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 467aecf

Browse files
authored
Merge pull request #2032 from drwasho/drwasho/hashMessage
feat: Endpoint to hash a message
2 parents ce555f2 + 35e080e commit 467aecf

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

api/endpoints.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ func post(i *jsonAPIHandler, path string, w http.ResponseWriter, r *http.Request
115115
i.POSTBulkUpdateCurrency(w, r)
116116
case strings.HasPrefix(path, "/ob/resendordermessage"):
117117
i.POSTResendOrderMessage(w, r)
118+
case strings.HasPrefix(path, "/ob/hashmessage"):
119+
i.POSTHashMessage(w, r)
118120
default:
119121
ErrorResponse(w, http.StatusNotFound, "Not Found")
120122
}

api/jsonapi.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4406,3 +4406,26 @@ func (i *jsonAPIHandler) GETScanOfflineMessages(w http.ResponseWriter, r *http.R
44064406
}
44074407
SanitizedResponse(w, `{}`)
44084408
}
4409+
4410+
func (i *jsonAPIHandler) POSTHashMessage(w http.ResponseWriter, r *http.Request) {
4411+
type hashRequest struct {
4412+
Content string `json:"content"`
4413+
}
4414+
var (
4415+
req hashRequest
4416+
err = json.NewDecoder(r.Body).Decode(&req)
4417+
)
4418+
if err != nil {
4419+
ErrorResponse(w, http.StatusBadRequest, err.Error())
4420+
return
4421+
}
4422+
4423+
messageHash, err := ipfs.EncodeMultihash([]byte(req.Content))
4424+
if err != nil {
4425+
ErrorResponse(w, http.StatusBadRequest, err.Error())
4426+
return
4427+
}
4428+
4429+
SanitizedResponse(w, fmt.Sprintf(`{"hash": "%s"}`,
4430+
messageHash.B58String()))
4431+
}

0 commit comments

Comments
 (0)