Created
May 19, 2020 21:53
-
-
Save MorganaUzhgorod/760586eb2df6c150e84f2b5f33ae1cab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const crypto = require("crypto"); | |
const sign = (data, key, method, route) => { | |
var md = crypto.createHash("sha1"); | |
md.update( | |
JSON.stringify(data) | |
.concat(key.toString()) | |
.concat(method.toString()) | |
.concat(route.toString()) | |
); | |
return md.digest("hex"); | |
}; | |
const verify = (data, key, method, route, hash) => { | |
let hashToVerify = sign(data, key, method, route); | |
return hashToVerify === hash; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment