Use crypto.randomBytes for unique CLN invoice label (#1074)
This commit is contained in:
parent
40131da8bd
commit
2ec0a1a559
|
@ -1,10 +1,10 @@
|
|||
import fetch from 'node-fetch'
|
||||
import https from 'https'
|
||||
import crypto from 'crypto'
|
||||
|
||||
export const createInvoice = async ({ socket, rune, cert, label, description, msats, expiry }) => {
|
||||
const agent = cert ? new https.Agent({ ca: Buffer.from(cert, 'base64') }) : undefined
|
||||
const url = 'https://' + socket + '/v1/invoice'
|
||||
const randomId = Math.floor(Math.random() * 1000)
|
||||
const res = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
@ -16,8 +16,9 @@ export const createInvoice = async ({ socket, rune, cert, label, description, ms
|
|||
},
|
||||
agent,
|
||||
body: JSON.stringify({
|
||||
// why does CLN require a unique label?
|
||||
label: description ? `${description} ${randomId}` : randomId,
|
||||
// CLN requires a unique label for every invoice
|
||||
// see https://docs.corelightning.org/reference/lightning-invoice
|
||||
label: crypto.randomBytes(16).toString('hex'),
|
||||
description,
|
||||
amount_msat: msats,
|
||||
expiry
|
||||
|
|
Loading…
Reference in New Issue