aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-02-28 15:24:48 -0800
committerAdam Soltys <[email protected]>2026-02-28 15:24:48 -0800
commitcaf1f126d0569670712e26fa2f6ac3127605cd91 (patch)
tree01a5ef46d8bd9d6157a7a1961b803a8f907f4f46
parent32f01e3e328db0006a55c6324625b49d60244b66 (diff)
downloadcoinos-server-caf1f126d0569670712e26fa2f6ac3127605cd91.tar.gz
coinos-server-caf1f126d0569670712e26fa2f6ac3127605cd91.zip
hash pins
-rw-r--r--index.ts2
-rw-r--r--lib/migrate.ts28
-rw-r--r--routes/users.ts2
3 files changed, 31 insertions, 1 deletions
diff --git a/index.ts b/index.ts
index 15762f26..d40bae55 100644
--- a/index.ts
+++ b/index.ts
@@ -8,6 +8,7 @@ import { fixBolt12, listenForLightning, replay } from "$lib/lightning";
import { startHealthCheck } from "$lib/health";
import { getLocations } from "$lib/locations";
import {
+ hashPins,
migrateAccounts,
migrateAutowithdraw,
migrateBalancesToTB,
@@ -49,6 +50,7 @@ try {
migrateToMicrosats().then((n) => n && console.log(`Migrated ${n} users to microsats`));
migrateAutowithdraw().then((n) => n && console.log(`Migrated autowithdraw to ${n} accounts`));
migrateFundsToTB().then((n) => n && console.log(`Migrated ${n} funds to TB`));
+ hashPins().then((n) => n && console.log(`Hashed ${n} user PINs`));
} catch (e) {
console.log(e);
}
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;
diff --git a/routes/users.ts b/routes/users.ts
index 1d0f9bcb..4d07a288 100644
--- a/routes/users.ts
+++ b/routes/users.ts
@@ -272,7 +272,7 @@ export default {
}
if (user.pin && !(pin === user.pin)) fail("Pin required");
- if (typeof newpin !== "undefined" && newpin.length === 6) user.pin = newpin;
+ if (typeof newpin !== "undefined" && (newpin.length === 6 || newpin.length === 64)) user.pin = newpin;
if (user.pin === "delete") user.pin = undefined;
if (username) {