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] Send payment from `externalId` #2

Closed gzuuus closed 7 months ago

gzuuus commented 7 months ago

I was thinking that thanks to the externalIds you could develop a kind of accounting system to have different users/accounts, and they could have access to a certain amount of funds. Do you think this would be an interesting or viable idea? The most basic way to do this, (without any authentication other than providing the externalId) would be to add a new method, for example

sendLightningInvoiceFromExtId(params: {
    amountSat?: number;
    externalId: string;
    invoice: string;
  }): Promise<PayInvoiceResponse>. 

And then limiting the amount of sats it can spend based on the paid invoices that externalId has received.

If you like the idea I can work on a pr

MiguelMedeiros commented 7 months ago

Interesting... just to see if I understood. You would first check if that externalId has received payments in your node and then do some accounting to see if it would have enough balance to send payments? Would you use the method: listIncomingPayments by passing the externalId and validate it?

If that's the case, I think I have no objections. Go ahead!

image

gzuuus commented 7 months ago

Yes, exactly, that's the idea, so you could have an accounting system over phoenixd, with more development you could make something like lnbits on top of phoenixd 👀

I have thought a bit more about how to implement this and I think it would be necessary to maintain a small DB that associates paymentId with externalId so that we can know which external id has spent what and do the necessary validations to know the externalId balance. What do you think of this? Is it within the scope of the library? The easiest way would be to use a sqlite DB, or just a json.

MiguelMedeiros commented 7 months ago

I thought you would just use an extra command and check it at the time of using it without the need for a database.

Adding a database would be out of scope. In that case it would be interesting to create an application using Phoenix + this npm package on top.

gzuuus commented 7 months ago

Yes, I agree. Can you think of a way to validate if funds were used by an externalId without needing a DB to account for this? It would be possible if phoenixd would allow an externalId to be attached to an invoice payment.

MiguelMedeiros commented 7 months ago

I believe we should adopt the KISS principle: keep it stupid simple. We can incorporate this accountability within an additional layer of abstraction and maintain its separation from this library.

MiguelMedeiros commented 7 months ago

@gzuuus, I'm going to close this PR for now.

gzuuus commented 7 months ago

@MiguelMedeiros Absolutely, let's keep it KISS. I'm going to work on this in a separate repository as it seems like an interesting idea to develop. To give you a bit more of my idea, I want to use nostr as an authentication layer. This way and using the public key as externalId and nip98 (HTTP Auth) we can have a valid e auth system.

MiguelMedeiros commented 7 months ago

Nice! Send me the link here when you have something done! 👍