From 4b5c6dde01fd99fc5962420be37fb850f1fdaeb5 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 6 Jun 2023 00:31:54 -0700 Subject: pass webhook secret --- index.js | 2 +- lib/invoices.js | 23 ++++++++++++++++++----- lib/webhooks.js | 9 +++++---- routes/invoices.js | 4 +++- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index a799ab30..f525cd9f 100644 --- a/index.js +++ b/index.js @@ -78,7 +78,7 @@ app.post("/2fa", auth, users.enable2fa); app.post("/user", auth, users.update); app.post("/reset", auth, users.reset); app.post("/upload/:type", auth, users.upload); -app.get('/users/delete/:username', users.del); +app.get("/users/delete/:username", users.del); app.post("/login", users.login); diff --git a/lib/invoices.js b/lib/invoices.js index 9e75abcb..031153d0 100644 --- a/lib/invoices.js +++ b/lib/invoices.js @@ -10,17 +10,28 @@ import bc from "$lib/bitcoin"; import ln from "$lib/ln"; export let generate = async ({ invoice, user, sender, memo }) => { - let { currency, tip, amount, rate, request_id, prompt, type } = invoice; + let { + currency, + tip, + amount, + rate, + request_id, + prompt, + type, + webhook, + secret + } = invoice; amount = parseInt(amount || 0); tip = parseInt(tip) || null; if (amount < 0) fail("amount out of range"); - if (!user) user = sender; - user = await getUser(user.username); + if (user) user = await getUser(user.username); + else if (sender) user = await getUser(sender.username); + else fail("user not provided"); - if (!user) fail("user not provided"); + console.log("USER", user); if (!currency) currency = user.currency; if (!rate) rate = store.rates[currency]; @@ -61,10 +72,12 @@ export let generate = async ({ invoice, user, sender, memo }) => { received: 0, request_id, prompt, + secret, text, tip, type, - uid: user.id + uid: user.id, + webhook }; l("creating invoice", user.username, amount, tip, currency, invoice.hash); diff --git a/lib/webhooks.js b/lib/webhooks.js index 1158fe9d..e5403b51 100644 --- a/lib/webhooks.js +++ b/lib/webhooks.js @@ -6,13 +6,13 @@ export const callWebhook = async (invoice, payment) => { try { if (!invoice || !payment) return; - let { address, received, text, webhook } = invoice; + let { address, received, text, webhook, secret } = invoice; if (webhook) { let { amount, confirmed, hash, memo } = payment; l("calling webhook", webhook, amount, hash, address, text); - let res = await got(webhook, { + let res = await got.post(webhook, { json: { address, amount, @@ -20,9 +20,10 @@ export const callWebhook = async (invoice, payment) => { hash, memo, received, - text + text, + secret } - }).res(); + }); return res; } } catch (e) { diff --git a/routes/invoices.js b/routes/invoices.js index f55d997f..fb501b27 100644 --- a/routes/invoices.js +++ b/routes/invoices.js @@ -14,9 +14,10 @@ export default { } let invoice = await g(`invoice:${hash}`); + delete invoice.secret; if (invoice) { - invoice.user = pick(await g(`user:${invoice.uid}`), whitelist); + invoice.user = pick(await g(`user:${invoice.uid}`), ['id', 'currency', 'username']); invoice.id = hash; } else if (config.classic) { invoice = await got(`${config.classic}/invoice/${pr}`).json(); @@ -36,6 +37,7 @@ export default { try { res.send(await generate({ invoice, user, sender })); } catch (e) { + console.log(e); bail(res, e.message); } }, -- cgit v1.2.3