diff options
| author | Adam Soltys <[email protected]> | 2024-12-30 21:57:14 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-12-30 21:57:14 -0800 |
| commit | bec6c516f63b84720192a9a3909c09fccfce7143 (patch) | |
| tree | 55bedf969606def5e0b623ae559f7a598033b110 /routes | |
| parent | ed4538ca280c7f4a0f0221ae214626234a1a4974 (diff) | |
| download | coinos-server-bec6c516f63b84720192a9a3909c09fccfce7143.tar.gz coinos-server-bec6c516f63b84720192a9a3909c09fccfce7143.zip | |
fix pubkey registration
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/users.ts | 13 |
1 files changed, 11 insertions, 2 deletions
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, |
