Fixed sync handshake

This commit is contained in:
2026-10-23 10:19:30 +02:00
parent 8f58e15f0f
commit 3316fc0275
8 changed files with 593 additions and 226 deletions
@@ -35,14 +35,31 @@ export function updateHasherSettings(salt?: string, minLength?: number | string)
* Validates if candidate is already a HashID generated by this hasher.
*/
export function isHashId(candidate: string | null | undefined): boolean {
if (!candidate || typeof candidate !== 'string' || candidate.length < HASHER_SETTINGS.minHashLength) {
if (
!candidate ||
typeof candidate !== 'string' ||
candidate.length < HASHER_SETTINGS.minHashLength ||
/^\d+$/.test(candidate)
) {
return false;
}
try {
const decodedNumbers = hasher.decode(candidate);
if (Array.isArray(decodedNumbers) && decodedNumbers.length > 0) return true;
if (
Array.isArray(decodedNumbers) &&
decodedNumbers.length > 0 &&
hasher.encode(decodedNumbers as number[]) === candidate
) {
return true;
}
const decodedHex = hasher.decodeHex(candidate);
if (decodedHex && decodedHex.length > 0) return true;
if (
decodedHex &&
decodedHex.length > 0 &&
hasher.encodeHex(decodedHex) === candidate
) {
return true;
}
} catch {
return false;
}