Created
February 10, 2022 13:58
-
-
Save MarvinMiles/f041205d872b0d8547d054eafeafe2a5 to your computer and use it in GitHub Desktop.
Telegram user authentication in JavaScript via Web Crypto API (dependency-free)
For those who faced the same problem with me, this is the code in JS
const crypto = require("crypto"); function validate(data, token) { const secretKey = crypto.createHash("sha256").update(token).digest(); const data_check_string = Object.keys(message) .filter((key) => key !== "hash") .map((key) => `${key}=${message[key]}`) .sort() .join("\n"); const check_hash = crypto .createHmac("sha256", secretKey) .update(data_check_string) .digest("hex"); return check_hash == data.hash; }
Provided By Link
Good day, i dont know if you could help me, no matter what i do i kept getting a mismatch, please how do i prepare the data from front-end before sending it to backend for hashing? do i need to hash it at the frontend before sending it to the backend? i will really appreciate your help.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@MarvinMiles thanks a lot
@abc-1211 thanks , I had the same problem as you, recommended to replace "message" with "data"