Download client/modules/searchTokenHash.ts from abhijeetsarkargis/MiniSearch: direct link, hf CLI and curl.
- Browser
- Download file 997 Bytes
-
https://huggingface.co/spaces/abhijeetsarkargis/MiniSearch/resolve/main/client/modules/searchTokenHash.ts
- Command line
-
hf download hf://spaces/abhijeetsarkargis/MiniSearch/client/modules/searchTokenHash.ts
-
curl -L -o searchTokenHash.ts https://huggingface.co/spaces/abhijeetsarkargis/MiniSearch/resolve/main/client/modules/searchTokenHash.ts
997 Bytes
| import { argon2Verify, argon2id } from "hash-wasm"; | |
| import { addLogEntry } from "./logEntries"; | |
| import { getLastSearchTokenHash, updateLastSearchTokenHash } from "./pubSub"; | |
| export async function getSearchTokenHash() { | |
| const password = VITE_SEARCH_TOKEN; | |
| const lastSearchTokenHash = getLastSearchTokenHash(); | |
| try { | |
| const lastSearchTokenHashIsValid = await argon2Verify({ | |
| password, | |
| hash: lastSearchTokenHash, | |
| }); | |
| if (lastSearchTokenHashIsValid) { | |
| addLogEntry("Using cached search token hash"); | |
| return lastSearchTokenHash; | |
| } | |
| } catch (error) { | |
| void error; | |
| } | |
| const salt = new Uint8Array(16); | |
| crypto.getRandomValues(salt); | |
| const newSearchTokenHash = await argon2id({ | |
| password, | |
| salt, | |
| parallelism: 1, | |
| iterations: 16, | |
| memorySize: 512, | |
| hashLength: 8, | |
| outputType: "encoded", | |
| }); | |
| updateLastSearchTokenHash(newSearchTokenHash); | |
| addLogEntry("New search token hash generated"); | |
| return newSearchTokenHash; | |
| } | |