From d6af21064d106e6179d76e0dddee049c5e7c0fc5 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 23 Jun 2020 14:39:41 -0700 Subject: lnurl auth --- lib/sockets.js | 18 ++++++++++++------ lib/whitelist.js | 32 +++++++++++++++++--------------- 2 files changed, 29 insertions(+), 21 deletions(-) (limited to 'lib') diff --git a/lib/sockets.js b/lib/sockets.js index 4b733882..d4ca336d 100644 --- a/lib/sockets.js +++ b/lib/sockets.js @@ -6,7 +6,6 @@ wss = new WebSocket.Server({ clientTracking: false, noServer: true }); /* eslint-disable-next-line */ const pick = (O, ...K) => K.reduce((o, k) => ((o[k] = O[k]), o), {}); -sockets = {}; emit = (username, type, data) => { if (data.username !== undefined) data = pick(data, ...whitelist); @@ -37,15 +36,15 @@ const names = {}; wss.on("connection", function(ws, req) { const id = uuidv4(); - setTimeout(() => ws.user || ws.close(), 2000); + ws.send(JSON.stringify({ type: "connected" })); - ws.on("message", async (message) => { + ws.on("message", async message => { let type, data; try { - ({ type, data } = JSON.parse(message)); + ({ type, data } = JSON.parse(message)); } catch (e) { l.error("coudn't parse socket message"); - } + } let token; switch (type) { @@ -71,13 +70,17 @@ wss.on("connection", function(ws, req) { } }); let accounts = await user.getAccounts(); + let keys = await user.getKeys(); user = user.get({ plain: true }); user.accounts = accounts; + user.keys = keys; user.payments = payments; ws.user = user; ws.send(JSON.stringify({ type: "login", data: user })); - ws.send(JSON.stringify({ type: "version", data: config.clientVersion })); + ws.send( + JSON.stringify({ type: "version", data: config.clientVersion }) + ); l.info("socket open", username, id); } catch (e) { ws.close(); @@ -95,6 +98,9 @@ wss.on("connection", function(ws, req) { if (!ws.user) return; ws.token = token; break; + case "lnurl": + sessions[data] = ws; + break; default: l.warn("received socket message of unknown type", type, data); } diff --git a/lib/whitelist.js b/lib/whitelist.js index 4c44c288..af7563ed 100644 --- a/lib/whitelist.js +++ b/lib/whitelist.js @@ -1,16 +1,18 @@ whitelist = [ -'id', -'account', -'account_id', -'unit', -'username', -'address', -'symbol', -'currency', -'currencies', -'twofa', -'liquid', -'confidential', -'accounts', -'payments', -] + "id", + "account", + "account_id", + "unit", + "username", + "address", + "symbol", + "currency", + "currencies", + "twofa", + "liquid", + "confidential", + "accounts", + "payments", + "seed", + "keys", +]; -- cgit v1.2.3