This is calling for a middleware. I envision using something like this:
app.post("/challenges", userOnly, verifySignature("challengeSubmit"), async (req, res) => {
// ...
}
That means the middleware would need to be curried:
const verifySignature = messageId => (req, res, next) => {
// ...
const verifyOptions = { ...req.body }
verifyOptions.messageId = messageId
}
I also showed in the snippet a way to avoid creating a different verifyOptions for each case, which is handy to abstract the code in a middleware. We know the required options must come from the client in the request's body, so we just pass all that to the verifySignature call ¯\_(ツ)_/¯
Given the current code works, we might want to open an enhancement issue for this.
Originally posted by @dgrcode in #48 (comment)