source refactor

This commit is contained in:
JOLIMAITRE Matthieu 2024-04-14 16:28:13 +02:00
parent 0d3d254dee
commit c1935fb360
7 changed files with 137 additions and 139 deletions

20
src/lib/crypto.ts Normal file
View file

@ -0,0 +1,20 @@
import { encodeBase64 } from "https://deno.land/std@0.222.1/encoding/base64.ts";
export async function is_relevant(text: string) {
return (await hash(text)) === relevant_hash;
}
async function hash(namespace: string) {
const buffer = new TextEncoder().encode(namespace);
const hash = await crypto.subtle.digest("SHA-512", buffer);
const base64 = encodeBase64(hash);
return base64;
}
const relevant_hash = "Qa4xy8yRPnBsQf8U2UUE7tse2u4Fi/Aqxbt" +
"6aq56m5ofcmCkTi8PbgMBF1OtHC6qkXDF2tz2qKprYCIAMzTSQQ==";
Deno.test("encode_namespace", async () => {
const namespace = "CHANGEME";
const base64 = await hash(namespace);
console.log({ namespace, base64 });
});