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 /lib/register.ts | |
| parent | ed4538ca280c7f4a0f0221ae214626234a1a4974 (diff) | |
| download | coinos-server-bec6c516f63b84720192a9a3909c09fccfce7143.tar.gz coinos-server-bec6c516f63b84720192a9a3909c09fccfce7143.zip | |
fix pubkey registration
Diffstat (limited to 'lib/register.ts')
| -rw-r--r-- | lib/register.ts | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/lib/register.ts b/lib/register.ts index 7fd1f680..36b9d443 100644 --- a/lib/register.ts +++ b/lib/register.ts @@ -1,22 +1,18 @@ -import { got } from "got"; -import { authenticator } from "otplib"; -import { v4 } from "uuid"; - import config from "$config"; import countries from "$lib/countries"; import { db } from "$lib/db"; import { l, warn } from "$lib/logging"; import { fail, getUser } from "$lib/utils"; - import { bytesToHex, randomBytes } from "@noble/hashes/utils"; -import { getPublicKey } from "nostr"; +import { got } from "got"; +import { getPublicKey, nip19 } from "nostr-tools"; import { encrypt as nip49encrypt } from "nostr-tools/nip49"; - -import { nip19 } from "nostr-tools"; +import { authenticator } from "otplib"; +import { v4 } from "uuid"; const valid = /^[\p{L}\p{N}]{2,24}$/u; export default async (user, ip) => { - let { password, pubkey, username } = user; + let { password, username } = user; l("registering", username); if (!username) fail("Username required"); @@ -53,14 +49,15 @@ export default async (user, ip) => { } const sk = randomBytes(32); - user.pubkey ||= bytesToHex(getPublicKey(sk)); + const pubkey = getPublicKey(sk); + user.pubkey = pubkey; user.nsec = nip49encrypt(sk, password); - user.currencies = [...new Set([user.currency, "CAD", "USD"])]; user.fiat = false; user.otpsecret = authenticator.generateSecret(); user.migrated = true; user.locktime = 300; + user.npub = nip19.npubEncode(user.pubkey); user.nwc = bytesToHex(randomBytes(32)); |
