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 --- lib/invoices.js | 23 ++++++++++++++++++----- lib/webhooks.js | 9 +++++---- 2 files changed, 23 insertions(+), 9 deletions(-) (limited to 'lib') 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) { -- cgit v1.2.3