aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-06-06 00:31:54 -0700
committerAdam Soltys <[email protected]>2023-06-06 00:31:59 -0700
commit4b5c6dde01fd99fc5962420be37fb850f1fdaeb5 (patch)
tree2f031a817bd474377b9005750ab1ceba3ab29f56
parent503dd491e537389d48fe2f1ee69e1b0d68330de8 (diff)
downloadcoinos-server-4b5c6dde01fd99fc5962420be37fb850f1fdaeb5.tar.gz
coinos-server-4b5c6dde01fd99fc5962420be37fb850f1fdaeb5.zip
pass webhook secret
-rw-r--r--index.js2
-rw-r--r--lib/invoices.js23
-rw-r--r--lib/webhooks.js9
-rw-r--r--routes/invoices.js4
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);
}
},