const text = 'An obscure body in the S-K System, your majesty. The inhabitants refer to it as the planet Earth.'; async function digestMessage(message) { const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8); // hash the message const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); // convert bytes to hex string return hashHex; } const digestHex = await digestMessage(text); // first seven characters of sha-256 are considered unique to certain extent console.log(digestHex.slice(0,7)); // nore on mdn https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest