eightieth times the charm

pull/17338/head
Elliott Johnson 1 week ago
parent 87aebafe6a
commit 2f394b8cc4

@ -2,15 +2,16 @@ import { BROWSER } from 'esm-env';
let text_encoder;
// TODO - remove this and use global `crypto` when we drop Node 18
/** @type {Crypto} */
// @ts-ignore - annoying type node stuff
let crypto = globalThis.crypto?.subtle?.digest ? globalThis.crypto : undefined;
let crypto;
/** @param {string} data */
export async function sha256(data) {
text_encoder ??= new TextEncoder();
// @ts-ignore - we don't install node types in the prod build
crypto ??= (await import('node:crypto')).webcrypto;
// @ts-ignore
crypto ??= globalThis.crypto?.subtle?.digest
? globalThis.crypto
: // @ts-ignore - we don't install node types in the prod build
(await import('node:crypto')).webcrypto;
const hash_buffer = await crypto.subtle.digest('SHA-256', text_encoder.encode(data));
// @ts-ignore - we don't install node types in the prod build
return base64_encode(hash_buffer);

Loading…
Cancel
Save