File
Blob: src/worker/services/crypto.ts
| 1 | export 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 | |
| 9 | export 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 | }; |