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