2024-08-26 23:20:45 +00:00
|
|
|
import { msatsToSats } from '@/lib/format'
|
|
|
|
|
2024-11-16 00:38:14 +00:00
|
|
|
export * from '@/wallets/phoenixd'
|
2024-08-26 23:20:45 +00:00
|
|
|
|
|
|
|
export async function testCreateInvoice ({ url, secondaryPassword }) {
|
|
|
|
return await createInvoice(
|
|
|
|
{ msats: 1000, description: 'SN test invoice', expiry: 1 },
|
|
|
|
{ url, secondaryPassword })
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function createInvoice (
|
|
|
|
{ msats, description, descriptionHash, expiry },
|
|
|
|
{ url, secondaryPassword }
|
|
|
|
) {
|
|
|
|
// https://phoenix.acinq.co/server/api#create-bolt11-invoice
|
|
|
|
const path = '/createinvoice'
|
|
|
|
|
|
|
|
const headers = new Headers()
|
|
|
|
headers.set('Authorization', 'Basic ' + Buffer.from(':' + secondaryPassword).toString('base64'))
|
|
|
|
headers.set('Content-type', 'application/x-www-form-urlencoded')
|
|
|
|
|
|
|
|
const body = new URLSearchParams()
|
|
|
|
body.append('description', description)
|
|
|
|
body.append('amountSat', msatsToSats(msats))
|
|
|
|
|
|
|
|
const res = await fetch(url + path, {
|
|
|
|
method: 'POST',
|
|
|
|
headers,
|
|
|
|
body
|
|
|
|
})
|
|
|
|
if (!res.ok) {
|
2024-11-08 19:26:40 +00:00
|
|
|
throw new Error(`POST ${res.url}: ${res.status} ${res.statusText}`)
|
2024-08-26 23:20:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const payment = await res.json()
|
|
|
|
return payment.serialized
|
|
|
|
}
|