From bec6c516f63b84720192a9a3909c09fccfce7143 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 30 Dec 2024 21:57:14 -0800 Subject: fix pubkey registration --- routes/users.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'routes') diff --git a/routes/users.ts b/routes/users.ts index 3f453141..151bd534 100644 --- a/routes/users.ts +++ b/routes/users.ts @@ -13,9 +13,11 @@ import upload from "$lib/upload"; import { bail, fail, getUser, pick } from "$lib/utils"; import whitelist from "$lib/whitelist"; import rpc from "@coinos/rpc"; +import { randomBytes } from "@noble/hashes/utils"; import { $ } from "bun"; import jwt from "jsonwebtoken"; -import { nip19, verifyEvent } from "nostr-tools"; +import { getPublicKey, nip19, verifyEvent } from "nostr-tools"; +import { encrypt as nip49encrypt } from "nostr-tools/nip49"; import { authenticator } from "otplib"; import { v4 } from "uuid"; @@ -167,6 +169,7 @@ export default { res.send({ ...pick(user, whitelist), token }); } catch (e) { + console.log(e); err("problem registering", e.message); res.code(500).send(e.message); } @@ -538,9 +541,15 @@ export default { try { user.pin = null; - user.pubkey = null; user.cipher = null; user.salt = null; + + if (user.nsec) { + const sk = randomBytes(32); + user.pubkey = getPublicKey(sk); + user.nsec = nip49encrypt(sk, password); + } + user.password = await Bun.password.hash(password, { algorithm: "bcrypt", cost: 4, -- cgit v1.2.3