2022-05-06 19:32:20 +00:00
|
|
|
import { createHash } from 'crypto'
|
2021-06-27 03:18:32 +00:00
|
|
|
import { bech32 } from 'bech32'
|
|
|
|
|
2022-05-06 19:32:20 +00:00
|
|
|
export function encodeLNUrl (url) {
|
2021-06-27 03:18:32 +00:00
|
|
|
const words = bech32.toWords(Buffer.from(url.toString(), 'utf8'))
|
2022-05-06 19:32:20 +00:00
|
|
|
return bech32.encode('lnurl', words, 1023)
|
2021-06-27 03:18:32 +00:00
|
|
|
}
|
2021-10-07 21:03:54 +00:00
|
|
|
|
|
|
|
export function lnurlPayMetadataString (username) {
|
|
|
|
return JSON.stringify([[
|
|
|
|
'text/plain',
|
|
|
|
`Funding @${username} on stacker.news`
|
2022-05-19 13:18:28 +00:00
|
|
|
], [
|
|
|
|
'text/identifier',
|
|
|
|
`${username}@stacker.news`
|
2021-10-07 21:03:54 +00:00
|
|
|
]])
|
|
|
|
}
|
|
|
|
|
2022-05-19 14:22:25 +00:00
|
|
|
export function lnurlPayDescriptionHashForUser (username) {
|
|
|
|
return lnurlPayDescriptionHash(lnurlPayMetadataString(username))
|
|
|
|
}
|
|
|
|
|
|
|
|
export function lnurlPayDescriptionHash (data) {
|
|
|
|
return createHash('sha256').update(data).digest('hex')
|
2021-10-07 21:03:54 +00:00
|
|
|
}
|