JS Async not working with Microstudio? - SHA256
I wanted to write a little cryptographie lib, so I was implementing some hash functions.
E.g: SHA256
//javascript
async function sha256(message) {
// encode as UTF-8
const msgBuffer = new TextEncoder().encode(message);
// hash the message
const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);
// convert ArrayBuffer to Array
const hashArray = Array.from(new Uint8Array(hashBuffer));
// convert bytes to hex string
const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join('');
return hashHex;
}
global.sha256=sha256
When I do smth like:
const plaintext = 'Hello, World!';
generateHash(plaintext).then(hash => console.log('SHA-256 Hash:', hash));
everthing works fine. But if I call this method sha256() from init() in microstudio - its getting an empty object as respose. Can anyone help me there?