aboutsummaryrefslogtreecommitdiffstats
path: root/lib/register.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-12-03 14:34:23 -0800
committerAdam Soltys <[email protected]>2024-12-03 14:34:23 -0800
commit0a318bf04d7691b47f65e1aa431a618d9bd935c0 (patch)
tree01d4aeeaa1c238c19c214f9daae12d892ad18d01 /lib/register.ts
parentf011ed304da9d72549ec0d967a7500cfe487765f (diff)
downloadcoinos-server-0a318bf04d7691b47f65e1aa431a618d9bd935c0.tar.gz
coinos-server-0a318bf04d7691b47f65e1aa431a618d9bd935c0.zip
return nwc and token on registration
Diffstat (limited to 'lib/register.ts')
-rw-r--r--lib/register.ts13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/register.ts b/lib/register.ts
index 139aefcf..7fd1f680 100644
--- a/lib/register.ts
+++ b/lib/register.ts
@@ -8,6 +8,12 @@ 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 { encrypt as nip49encrypt } from "nostr-tools/nip49";
+
+import { nip19 } from "nostr-tools";
+
const valid = /^[\p{L}\p{N}]{2,24}$/u;
export default async (user, ip) => {
let { password, pubkey, username } = user;
@@ -46,11 +52,17 @@ export default async (user, ip) => {
}
}
+ const sk = randomBytes(32);
+ user.pubkey ||= bytesToHex(getPublicKey(sk));
+ 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));
const account = JSON.stringify({
id,
@@ -59,6 +71,7 @@ export default async (user, ip) => {
});
db.multi()
+ .set(getPublicKey(user.nwc), user.id)
.set(`user:${id}`, JSON.stringify(user))
.set(`user:${username}`, id)
.set(`user:${pubkey}`, id)