MiguelMedeiros / phoenix-server-js

Phoenix-Server-JS combines promise-based and WebSocket interfaces for developer convenience and efficiency.
https://npmjs.com/package/phoenix-server-js
MIT License
16 stars 3 forks source link

[Feature] Accept an LN address as an `invoice` param to method `sendLightningInvoice` #3

Closed MiguelMedeiros closed 7 months ago

MiguelMedeiros commented 7 months ago

In the sendLightningInvoice method, allow the invoice parameter to accept LN addresses and automatically get the BOLT11 invoice. The invoice parameter could then accept either an LN address or a regular BOLT11 invoice.

async sendLightningInvoice(params: {
  amountSat?: number;
  invoice: string;
}): Promise<PayInvoiceResponse> {
  // check if the invoice param is an ln address and get the invoice from the url

  // otherwise use the current invoice param
}
jaonoctus commented 7 months ago

my 2 cents: I would have another method just to 1. send a request to the lnurlp endpoint and see if it's valid; 2. send a request to the callback endpoint to generate an invoice and then you have the same bolt11 invoice to use in this sendLightningInvoice function.

MiguelMedeiros commented 7 months ago

@jaonoctus Thank you for your input! 👍

Is there just one method to retrieve the lnurlp endpoint, validate it, and obtain the bolt11 invoice?

Do you have any suggestions for a cool/comprehensive name for this method?

jaonoctus commented 7 months ago

There is no method for that on phoenixd, we need to do two http-api calls.

The validation of the first call is simple as check if there is a callback key in the response object, as well as min and max sendables in msats. We could create utils/helpers functions for that.

getLnurlp and getPaymentRequest or something similar, maybe?

MiguelMedeiros commented 7 months ago

@jaonoctus I've been thinking about creating another npm package to handle ln addresses and leave this one just for the phoenixd endpoints. So, I'm going to close this PR for now and will let you know here when I have a new npm package for this lnaddress helper.