2023-02-24 16:41:47 +00:00
import { getPublicKey } from 'nostr'
2024-03-20 00:37:31 +00:00
import models from '@/api/models'
import { lnurlPayMetadataString } from '@/lib/lnurl'
import { LNURLP _COMMENT _MAX _LENGTH } from '@/lib/constants'
2021-10-07 18:37:59 +00:00
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 ( {
2022-05-19 14:22:25 +00:00
callback : ` ${ process . env . PUBLIC _URL } /api/lnurlp/ ${ username } /pay ` , // The URL from LN SERVICE which will accept the pay request parameters
2021-10-07 18:37:59 +00:00
minSendable : 1000 , // Min amount LN SERVICE is willing to receive, can not be less than 1 or more than `maxSendable`
2022-08-30 20:33:39 +00:00
maxSendable : 1000000000 ,
2021-10-07 21:03:54 +00:00
metadata : lnurlPayMetadataString ( username ) , // Metadata json which must be presented as raw string here, this is required to pass signature verification at a later step
2023-09-24 01:14:49 +00:00
commentAllowed : LNURLP _COMMENT _MAX _LENGTH , // LUD-12 Comments for payRequests https://github.com/lnurl/luds/blob/luds/12.md
2023-10-03 19:35:53 +00:00
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 }
} ,
2023-02-14 18:46:34 +00:00
tag : 'payRequest' , // Type of LNURL
2023-09-24 01:14:49 +00:00
nostrPubkey : process . env . NOSTR _PRIVATE _KEY ? getPublicKey ( process . env . NOSTR _PRIVATE _KEY ) : undefined ,
allowsNostr : ! ! process . env . NOSTR _PRIVATE _KEY
2021-10-07 18:37:59 +00:00
} )
}