pwa and mobile client

This commit is contained in:
azykov@mail.ru
2026-09-29 15:55:25 +03:00
parent 657009bd6c
commit 1935acf2ff
96 changed files with 8370 additions and 58 deletions
+17
View File
@@ -0,0 +1,17 @@
import type { PinRecord } from './storage.js';
export const PIN_LENGTH = 4;
async function sha256Hex(text: string): Promise<string> {
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(text));
return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, '0')).join('');
}
export async function createPinRecord(pin: string): Promise<PinRecord> {
const salt = [...crypto.getRandomValues(new Uint8Array(16))].map((b) => b.toString(16).padStart(2, '0')).join('');
return { salt, hash: await sha256Hex(`${salt}:${pin}`) };
}
export async function checkPin(pin: string, record: PinRecord): Promise<boolean> {
return (await sha256Hex(`${record.salt}:${pin}`)) === record.hash;
}