11 lines
453 B
JavaScript
11 lines
453 B
JavaScript
import { createHash } from "node:crypto";
|
|||
|
|
const fastHash = /*@__PURE__*/ (() => globalThis.process?.getBuiltinModule?.("crypto")?.hash)();
|
||
|
|
const algorithm = "sha256";
|
||
|
|
const encoding = "base64url";
|
||
|
|
function digest(data) {
|
||
|
|
if (fastHash) return fastHash(algorithm, data, encoding);
|
||
|
|
const h = createHash(algorithm).update(data);
|
||
|
|
return globalThis.process?.versions?.webcontainer ? h.digest().toString(encoding) : h.digest(encoding);
|
||
|
|
}
|
||
|
|
export { digest };
|