first commit
This commit is contained in:
+9
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Hashes a string using the SHA-256 algorithm and encodes it in Base64URL format.
|
||||
*
|
||||
* @param {string} data - data message to hash.
|
||||
*
|
||||
* @returns {string} The hash of the data.
|
||||
*/
|
||||
declare function digest(data: string): string;
|
||||
export { digest };
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
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 };
|
||||
Reference in New Issue
Block a user