Skip to content
File

Blob: src/worker/services/crypto.ts

typescript13 lines
1export const encodeBase64Url = (bytes: Uint8Array): string => {
2 let binary = "";
3 for (let i = 0; i < bytes.length; i += 1) {
4 binary += String.fromCharCode(bytes[i]);
5 }
6 return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
7};
8 
9export const sha256 = async (input: string): Promise<string> => {
10 const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(input));
11 return encodeBase64Url(new Uint8Array(digest));
12};