diff options
| author | Adam Soltys <[email protected]> | 2020-06-23 14:39:41 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2020-06-23 14:39:41 -0700 |
| commit | d6af21064d106e6179d76e0dddee049c5e7c0fc5 (patch) | |
| tree | d6cf57a7659a6e60ad80992c8f93dcc59c11c770 /lib | |
| parent | 3c46dc86b753cdfd71da7b8bb86710032668b5eb (diff) | |
| download | coinos-server-d6af21064d106e6179d76e0dddee049c5e7c0fc5.tar.gz coinos-server-d6af21064d106e6179d76e0dddee049c5e7c0fc5.zip | |
lnurl auth
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sockets.js | 18 | ||||
| -rw-r--r-- | lib/whitelist.js | 32 |
2 files changed, 29 insertions, 21 deletions
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", +]; |
