diff --git a/lib/cln.js b/lib/cln.js index 034457f8..b11b2f1d 100644 --- a/lib/cln.js +++ b/lib/cln.js @@ -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