I have a vanilla javascript project that uses ClosureCompiler to generate a minified js file. This file is an SDK that people would include in their own websites. I need to compute a SHA-256 hash but its turning out to be trickier than it should be.
What I want:
const data = "test"
const hashedData = SHA256(data);
Requirements:
- Should be synchronous.
- Should work with vanilla javascript.
- Should compile with closure compiler.
- Should not require dependency on an external website. I am fine with copying the code from an external library into my own project. But it should be a trusted/reliable library like SJCL.
What I have tried:
Webcrypto.subtle: This returns a Promise, not a string. It would need me to make my SHA256 function async. Which would require a lot of re-architecture.
SJCL: Does not compile with Closure Compiler.