From caf1f126d0569670712e26fa2f6ac3127605cd91 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 28 Feb 2026 15:24:48 -0800 Subject: hash pins --- lib/migrate.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lib') diff --git a/lib/migrate.ts b/lib/migrate.ts index 8ea37a06..f2320390 100644 --- a/lib/migrate.ts +++ b/lib/migrate.ts @@ -206,4 +206,32 @@ export const migrateFundsToTB = async () => { return count; }; +export const hashPins = async () => { + const migrated = await db.get("pins:hashed"); + if (migrated) return 0; + + let count = 0; + + for await (const k of scan("user:*")) { + try { + const raw = await db.get(k); + if (!raw || !(raw as string).startsWith("{")) continue; + + const user = JSON.parse(raw as string); + if (!user.pin || user.pin.length !== 6) continue; + + const hash = new Bun.CryptoHasher("sha256").update(user.pin).digest("hex"); + user.pin = hash; + await s(k as string, user); + count++; + } catch (e) { + warn("pin hash migration error", k, e.message); + } + } + + await db.set("pins:hashed", Date.now().toString()); + l(`Hashed ${count} user PINs`); + return count; +}; + export default migrate; -- cgit v1.2.3