-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add LNURL verify #10
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import { Hono } from "hono"; | ||
import { Context, Hono } from "hono"; | ||
import { nwc } from "npm:@getalby/sdk"; | ||
import { logger } from "../src/logger.ts"; | ||
import { BASE_URL, DOMAIN } from "./constants.ts"; | ||
import { DB } from "./db/db.ts"; | ||
import "./nwc/nwcPool.ts"; | ||
|
||
export function createLnurlApp(db: DB) { | ||
export function createLnurlWellKnownApp(db: DB) { | ||
const hono = new Hono(); | ||
|
||
hono.get("/:username", async (c) => { | ||
hono.get("/:username", async (c: Context) => { | ||
try { | ||
const username = c.req.param("username"); | ||
|
||
|
@@ -22,7 +22,7 @@ export function createLnurlApp(db: DB) { | |
return c.json({ | ||
tag: "payRequest", | ||
commentAllowed: 255, | ||
callback: `${BASE_URL}/.well-known/lnurlp/${username}/callback`, | ||
callback: `${BASE_URL}/lnurlp/${username}/callback`, | ||
minSendable: 1000, | ||
maxSendable: 10000000000, | ||
metadata: `[["text/identifier","${username}@${DOMAIN}"],["text/plain","Sats for ${username}"]]`, | ||
|
@@ -32,7 +32,13 @@ export function createLnurlApp(db: DB) { | |
} | ||
}); | ||
|
||
hono.get("/:username/callback", async (c) => { | ||
return hono; | ||
} | ||
|
||
export function createLnurlApp(db: DB) { | ||
const hono = new Hono(); | ||
|
||
hono.get("/:username/callback", async (c: Context) => { | ||
try { | ||
const username = c.req.param("username"); | ||
const amount = c.req.query("amount"); | ||
|
@@ -52,17 +58,45 @@ export function createLnurlApp(db: DB) { | |
}); | ||
|
||
const transaction = await nwcClient.makeInvoice({ | ||
amount: +amount, | ||
amount: Math.floor(+amount / 1000) * 1000, | ||
description: comment, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this added? you cannot have sub-millisats |
||
}); | ||
|
||
return c.json({ | ||
pr: transaction.invoice, | ||
verify: `${BASE_URL}/lnurlp/${username}/verify/${transaction.payment_hash}`, | ||
routes: [], | ||
pr: transaction.invoice, | ||
}); | ||
} catch (error) { | ||
return c.json({ status: "ERROR", reason: "" + error }); | ||
} | ||
}); | ||
|
||
hono.get("/:username/verify/:payment_hash", async (c: Context) => { | ||
try { | ||
const username = c.req.param("username"); | ||
const paymentHash = c.req.param("payment_hash"); | ||
logger.debug("LNURLp verify", { username, paymentHash }); | ||
|
||
const connectionSecret = await db.findWalletConnectionSecret(username); | ||
|
||
const nwcClient = new nwc.NWCClient({ | ||
nostrWalletConnectUrl: connectionSecret, | ||
}); | ||
|
||
const transaction = await nwcClient.lookupInvoice({ | ||
payment_hash: paymentHash, | ||
}); | ||
|
||
return c.json({ | ||
settled: !!transaction.settled_at, | ||
preimage: transaction.preimage || null, | ||
pr: transaction.invoice, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure what the spec says, but having the key in the response but a blank value makes sense to me. |
||
}); | ||
} catch (error) { | ||
return c.json({ status: "ERROR", reason: "" + error }); | ||
} | ||
}); | ||
|
||
return hono; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should not need
: Context
. In Typescript, it is inferred from the argument type. Are you sure your environment is setup correctly?