diff options
| author | Adam Soltys <[email protected]> | 2026-02-28 15:24:48 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-02-28 15:24:48 -0800 |
| commit | caf1f126d0569670712e26fa2f6ac3127605cd91 (patch) | |
| tree | 01a5ef46d8bd9d6157a7a1961b803a8f907f4f46 /lib | |
| parent | 32f01e3e328db0006a55c6324625b49d60244b66 (diff) | |
| download | coinos-server-caf1f126d0569670712e26fa2f6ac3127605cd91.tar.gz coinos-server-caf1f126d0569670712e26fa2f6ac3127605cd91.zip | |
hash pins
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/migrate.ts | 28 |
1 files changed, 28 insertions, 0 deletions
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; |
