diff options
| author | Adam Soltys <[email protected]> | 2024-06-04 06:15:29 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-06-04 06:15:29 -0700 |
| commit | 0b7f6a88d9e7fd3965981b3fb8987f47c3c027b8 (patch) | |
| tree | 694f7f1b2684dda4cd2b6783ec19db38a17c334c /routes | |
| parent | 0b887260788ae69fba1dace2f351a23a71862dc2 (diff) | |
| download | coinos-server-0b7f6a88d9e7fd3965981b3fb8987f47c3c027b8.tar.gz coinos-server-0b7f6a88d9e7fd3965981b3fb8987f47c3c027b8.zip | |
lnurl verify
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/lnurl.js | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/routes/lnurl.js b/routes/lnurl.js index c092d6fe..03dcc19a 100644 --- a/routes/lnurl.js +++ b/routes/lnurl.js @@ -1,6 +1,6 @@ import migrate from "$lib/migrate"; import { g, s } from "$lib/db"; -import { l, warn } from "$lib/logging"; +import { l, err, warn } from "$lib/logging"; import { bail, getUser, fail } from "$lib/utils"; import { v4 } from "uuid"; import got from "got"; @@ -92,7 +92,7 @@ export default { let memo = `Paying ${username}@${host}`; let metadata = JSON.stringify([ ["text/plain", memo], - ["text/identifier", `${username}@${host}`] + ["text/identifier", `${username}@${host}`], ]); if (nostr) { @@ -106,7 +106,7 @@ export default { } } - let { text: pr } = await generate({ + let { id: iid, text: pr } = await generate({ invoice: { amount: Math.round(amount / 1000), memo: metadata, @@ -115,9 +115,20 @@ export default { user, }); - res.send({ pr, routes: [] }); + res.send({ pr, routes: [], verify: `${URL}/api/lnurl/verify/${iid}` }); } catch (e) { bail(res, e.message); } }, + + async verify({ params: { id } }, res) { + let inv = await g(`invoice:${id}`); + + if (!inv) return res.send({ status: "ERROR", reason: "Not found" }); + + let { received, amount, preimage } = inv; + let settled = received >= amount; + + res.send({ status: "OK", settled, preimage }); + }, }; |
