aboutsummaryrefslogtreecommitdiffstats
path: root/routes/users.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-10-04 09:29:21 -0700
committerAdam Soltys <[email protected]>2024-10-10 12:17:05 -0700
commit372c635714f6e7de8a0da135980697b49f207f2c (patch)
tree5c5af794a4ca18b0919cc363f65fd398bc051b8b /routes/users.ts
parent5127adbb54b7db6eccf27cc4e498d9dfcdb7a7a4 (diff)
downloadcoinos-server-372c635714f6e7de8a0da135980697b49f207f2c.tar.gz
coinos-server-372c635714f6e7de8a0da135980697b49f207f2c.zip
wip socket communication
Diffstat (limited to 'routes/users.ts')
-rw-r--r--routes/users.ts18
1 files changed, 9 insertions, 9 deletions
diff --git a/routes/users.ts b/routes/users.ts
index 6b18da28..18ef7e3b 100644
--- a/routes/users.ts
+++ b/routes/users.ts
@@ -11,12 +11,11 @@ import register from "$lib/register";
import { requirePin } from "$lib/auth";
import { v4 } from "uuid";
import { reconcile, types } from "$lib/payments";
-import { bech32 } from "bech32";
import { mail, templates } from "$lib/mail";
import upload from "$lib/upload";
import rpc from "@coinos/rpc";
-
-let { encode, decode, fromWords, toWords } = bech32;
+import { nip19 } from "nostr-tools";
+import { hex } from "@scure/base";
export default {
upload,
@@ -26,8 +25,7 @@ export default {
try {
user.balance = await g(`balance:${user.id}`);
user.prompt = !!user.prompt;
- if (user.pubkey)
- user.npub = encode("npub", toWords(Buffer.from(user.pubkey, "hex")));
+ if (user.pubkey) user.npub = nip19.npubEncode(user.pubkey);
res.send(pick(user, whitelist));
} catch (e) {
@@ -80,7 +78,7 @@ export default {
try {
if (key.startsWith("npub")) {
try {
- key = Buffer.from(fromWords(decode(key).words)).toString("hex");
+ key = hex.encode(nip19.decode(key).data as Uint8Array);
} catch (e) {}
}
@@ -115,8 +113,7 @@ export default {
"username",
];
- if (user.pubkey)
- user.npub = encode("npub", toWords(Buffer.from(user.pubkey, "hex")));
+ if (user.pubkey) user.npub = nip19.npubEncode(user.pubkey);
user.prompt = !!user.prompt;
res.send(pick(user, whitelist));
@@ -193,6 +190,9 @@ export default {
let { confirm, password, pin, newpin, pubkey, username } = body;
+ console.log("PK", pubkey);
+ console.log("SK", body.nsec);
+
if (user.pin && !(pin === user.pin)) fail("Pin required");
if (typeof newpin !== "undefined" && newpin.length === 6)
user.pin = newpin;
@@ -629,7 +629,7 @@ export default {
wallet_name: id,
descriptors: true,
disable_private_keys: true,
- load_on_startup: true
+ load_on_startup: true,
});
node = rpc({ ...config[type], wallet: id });