|
|
|
@ -4,6 +4,9 @@ let text_encoder;
|
|
|
|
// TODO - remove this and use global `crypto` when we drop Node 18
|
|
|
|
// TODO - remove this and use global `crypto` when we drop Node 18
|
|
|
|
let crypto;
|
|
|
|
let crypto;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @param {string} module_name */
|
|
|
|
|
|
|
|
const obfuscated_import = (module_name) => import(/* @vite-ignore */ module_name);
|
|
|
|
|
|
|
|
|
|
|
|
/** @param {string} data */
|
|
|
|
/** @param {string} data */
|
|
|
|
export async function sha256(data) {
|
|
|
|
export async function sha256(data) {
|
|
|
|
text_encoder ??= new TextEncoder();
|
|
|
|
text_encoder ??= new TextEncoder();
|
|
|
|
@ -12,8 +15,8 @@ export async function sha256(data) {
|
|
|
|
crypto ??= globalThis.crypto?.subtle?.digest
|
|
|
|
crypto ??= globalThis.crypto?.subtle?.digest
|
|
|
|
? globalThis.crypto
|
|
|
|
? globalThis.crypto
|
|
|
|
: // @ts-ignore - we don't install node types in the prod build
|
|
|
|
: // @ts-ignore - we don't install node types in the prod build
|
|
|
|
// don't use 'node:crypto' because static analysers will think we rely on node when we don't
|
|
|
|
// don't use import('node:crypto') directly because static analysers will think we rely on node when we don't
|
|
|
|
(await import(/* @vite-ignore */ 'node:' + 'crypto')).webcrypto;
|
|
|
|
(await obfuscated_import('node:crypto')).webcrypto;
|
|
|
|
|
|
|
|
|
|
|
|
const hash_buffer = await crypto.subtle.digest('SHA-256', text_encoder.encode(data));
|
|
|
|
const hash_buffer = await crypto.subtle.digest('SHA-256', text_encoder.encode(data));
|
|
|
|
|
|
|
|
|
|
|
|
|