8 lines
359 B
TypeScript
8 lines
359 B
TypeScript
|
export async function hashString(message = ""): Promise<string> {
|
||
|
const msgUint8 = new TextEncoder().encode(message);
|
||
|
const hashBuffer = await window.crypto.subtle.digest("SHA-256", msgUint8);
|
||
|
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
||
|
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
||
|
return hashHex;
|
||
|
}
|