3acaee377b
* first pass of LUD-18 support * Various LUD-18 updates * don't cache the well-known response, since it includes randomly generated single use values * validate k1 from well-known response to pay URL * only keep k1's for 10 minutes if they go unused * fix validation logic to make auth object optional * Various LUD18 updates * move k1 cache to database * store payer data in invoice db table * show payer data in invoices on satistics page * show comments and payer data on invoice page * Show lud18 data in invoice notification * PayerData component for easier display of info in invoice, notification, wallet history * `payerData` -> `invoicePayerData` in fact schema * Merge prisma migrations * lint fixes * worker job to clear out unused lnurlp requests after 30 minutes * More linting * Move migration to older * WIP review * enhance lud-18 * refine notification ui --------- Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com> Co-authored-by: keyan <keyan.kousha+huumn@gmail.com>
29 lines
1.5 KiB
JavaScript
29 lines
1.5 KiB
JavaScript
import { getPublicKey } from 'nostr'
|
|
import models from '../../../../api/models'
|
|
import { lnurlPayMetadataString } from '../../../../lib/lnurl'
|
|
import { LNURLP_COMMENT_MAX_LENGTH } from '../../../../lib/constants'
|
|
|
|
export default async ({ query: { username } }, res) => {
|
|
const user = await models.user.findUnique({ where: { name: username } })
|
|
if (!user) {
|
|
return res.status(400).json({ status: 'ERROR', reason: `user @${username} does not exist` })
|
|
}
|
|
|
|
return res.status(200).json({
|
|
callback: `${process.env.PUBLIC_URL}/api/lnurlp/${username}/pay`, // The URL from LN SERVICE which will accept the pay request parameters
|
|
minSendable: 1000, // Min amount LN SERVICE is willing to receive, can not be less than 1 or more than `maxSendable`
|
|
maxSendable: 1000000000,
|
|
metadata: lnurlPayMetadataString(username), // Metadata json which must be presented as raw string here, this is required to pass signature verification at a later step
|
|
commentAllowed: LNURLP_COMMENT_MAX_LENGTH, // LUD-12 Comments for payRequests https://github.com/lnurl/luds/blob/luds/12.md
|
|
payerData: { // LUD-18 payer data for payRequests https://github.com/lnurl/luds/blob/luds/18.md
|
|
name: { mandatory: false },
|
|
pubkey: { mandatory: false },
|
|
identifier: { mandatory: false },
|
|
email: { mandatory: false }
|
|
},
|
|
tag: 'payRequest', // Type of LNURL
|
|
nostrPubkey: process.env.NOSTR_PRIVATE_KEY ? getPublicKey(process.env.NOSTR_PRIVATE_KEY) : undefined,
|
|
allowsNostr: !!process.env.NOSTR_PRIVATE_KEY
|
|
})
|
|
}
|