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

Commit 35e080e

Browse files
committed
feat: Endpoint to hash a message
This will take a string and encode it as a multihash + convert it to a Base 58 string in the same way we do to our coupons. This makes it easy for clients to determine if a given coupon matches a listing's coupon secret.
1 parent ce555f2 commit 35e080e

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)