From 384e70e286d781ccdd4d52a9741275d63d864607 Mon Sep 17 00:00:00 2001 From: rhpidfyre Date: Sat, 8 Mar 2025 02:10:31 -0500 Subject: [PATCH] sha256 hash module for file hashes --- src/rt/rfwfs/hash.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/rt/rfwfs/hash.ts diff --git a/src/rt/rfwfs/hash.ts b/src/rt/rfwfs/hash.ts new file mode 100644 index 0000000..5f64006 --- /dev/null +++ b/src/rt/rfwfs/hash.ts @@ -0,0 +1,11 @@ +async function hash(inner_as_string: string) { + const encoder = new TextEncoder() + const hash = await crypto.subtle.digest("SHA-256", encoder.encode(inner_as_string)) + const hash_as_uint8 = new Uint8Array(hash) + return Array.from(hash_as_uint8).map(byte => byte.toString(16).padStart(2, "0")).join("") +} + +export default async function generate_sha256(inner_as_string: string) { + const sha256 = await hash(inner_as_string) + return sha256 +} \ No newline at end of file