STORY
How might we allow mobile apps to connect to a lightning enabled website for payments*?
AUTHOR
Joined 2022.06.23
DATE
VOTES
sats
COMMENTS

How might we allow mobile apps to connect to a lightning enabled website for payments*?

@Braj asked me how voting on BOLT.FUN works, and if it is only possible with a WebLN / WebBTC enabled wallet IN the browser. There's the Alby extension, Blixt and Breez mobile wallets which both contain WebLN enabled browsers. So short answer is yes, for now.

Here's some context of a payment flow that this website supports. We use the lightning address that makers put in their profiles to generate invoices. Once the website fetches that invoice we call the following function.

webln.sendPayment(response)

The wallet connected to the website is able to retrieve the invoice. If approved, it would pay the invoice and send the pre-image as a response back to the website. Since BOLT.FUN is not part of the payment we depend on getting the preimage that the wallet returns back after a successful payment in order to know if we can increment the votes in our database.

Problem

For authentication we use lnurl-auth as a way to let people access their maker profiles. lnurl-auth already defines a spec for allowing web services and wallets to talk to one another so that's no big deal to scan a QR on our website from a mobile lnurl-auth enabled app. It already works pretty good.

We need a similar mechanism for payments! Through WebLN/WebBTC we can exchange payment data between a website and wallet but the two things are coupled too tightly right now.

Solutions 🤷‍♀️

ZEBEDEE and Alby have recently launched oAuth APIs for their custodial lightning wallets. I've not had a chance to test them out yet, but this could be really cool way to onboard developers who use services like Auth0 in their toolkits as they can be added as a custom identity provider. While this could be an easy way to connect any application (mobile or web) to a custodial bitcoin wallet it's a bit ick if we want to have a self-custody solution #GOALS!

One possible solution on my mind is having a solution like WalletConnect. I believe they use a web socket connection to achieve the connection between a wallet and website.

  1. The website can have a websocket connection link for the current session that is presented in a QR code.

  2. Open the QR Scanner in the bitcoin app and capture the connection string

  3. The app establishes a websocket connection in a browser (webview) by inserting itself as the WebLN Provider on the website through websockets.

Does this make sense? I'm sure there's something I'm missing lets discuss.