pull/17338/head
Elliott Johnson 8 months ago
parent 7a5886de7c
commit 479deb61c6

@ -1,9 +1,14 @@
// TODO - remove this and use global `crypto` when we drop Node 18
// @ts-ignore - we don't install node types in the prod build
import { webcrypto } from 'node:crypto';
let text_encoder;
/** @param {string} data */
export async function sha256(data) {
text_encoder ??= new TextEncoder();
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
const hash_buffer = await webcrypto.subtle.digest('SHA-256', text_encoder.encode(data));
// @ts-ignore - we don't install node types in the prod build
return Buffer.from(hash_buffer).toString('base64');
}

Loading…
Cancel
Save