Introduction
Most people think of the Lightning Network as a payment network for fast and cheap bitcoin transactions. But did you know that you can use your Lightning wallet to easily, securely and anonymously log in to certain services?
Passwords
The most common authentication method on the Internet today is username and password. It's a decades-old concept that works quite well. But what are its drawbacks?
For convenience, users often choose simple passwords that can be guessed or cracked by brute force. Alternatively, they use the same passwords across multiple services, leading to the fact that if the password leaks, attackers can hijack identities on multiple platforms at the same time. They just try the same combination on other services.
Lightning?
But what if we had an alternative way of logging in where we didn't need a username or password and the whole concept will be secure enough? Is that realistic?
The technology we will introduce in this post is the LNURL-auth protocol. LNURL is a set of protocols that extend the capabilities of the Lightning Network (we have already introduced one of them in the post about the Lightning address) and specifically LNURL-auth takes care of logging.
And how do I imagine this in practice? Simple - you open a website supporting this technology, scan a QR code with your Lightning wallet (as if you were paying a traditional invoice) and you are logged in. It couldn't be simpler. But how does that work and is it even safe?
Principle
An integral part of all Lightning wallets is the private key. As with on-chain bitcoin, this is a random number that you must not disclose to anyone and whose knowledge proves ownership of your bitcoins.
In practice, the website sends you random data that you sign with your private key and return a pair - a signature and a public key. The service then verifies the signature, and if it is correct, you have successfully confirmed your identity. This is done by knowing your private key, as only you own it and without it, a valid signature cannot be created.
In reality, you do not use the identical private key that you have as proof of ownership of your bitcoins, but depending on the URL of the website, a different key is derived for each website.
It may sound complicated for some beginners, but really it's just that your identity is tied to your private key, and as long as no one steals it, all you have to do is simply scan QR codes to log in to various services.
Your only concern is to keep this key safe - but for this you can usually use the well-known seed-phrase (12 to 24 words used to recover the master private key).
Advantages and disadvantages
What are the advantages over the traditional login with a username and password?
- You don't need to create, remember or store any passwords.
- You don't even need to fill in a username, you just "scan QR code".
- Your password (in this case a private key) never travels over the network, so it cannot be intercepted.
- Your private key is derived differently for each service, so your identity cannot be correlated across multiple services (such as if you use the same email or username).
- Speed and simplicity.
What about the disadvantages?
- So far, very few services support this type of login.
- You must have a Lightning wallet that supports this technology.
- Whoever gets full access to your wallet has your identity.
- You are responsible for keeping your seed-phrase safe.
Practice
From the preceding paragraphs, it should be clear that you will need a lightning wallet. In this particular case, I would strongly recommend one where you actually own your private keys (so called non-custodial), i.e. Phoenix or Breez for example. Or your own node via Zeus.
There is a support for this feature in BlueWallet as well, but since it is custodial by default (third party holds the private keys for you), I would not recommend it for this case. Neither Wallet of Satoshi nor Muun wallets support LNURL-auth technology yet.
You must then back up your wallet correctly, as you will lose your identity if you lose it. And of course, you should set up some kind of additional authentication when accessing your wallet (PIN, fingerprint, FaceID, etc.).
Some may find this way of storing your identity dangerous, but if a potential attacker gets into your phone and bypass biometrics to steal your identity from the wallet itself, he can steal your passwords from any password manager in the same way...
And that's it - you don't have to use the wallet itself to pay, you don't even have to have a single satoshi on it.
And where can you try Lightning login? For example here on Stacker.News :)
Conclusion
Lightning authentication is an interesting concept that is very secure, anonymous, and user-friendly by simply scanning QR codes.
But the technology itself is still in its very early days, so we'll have to wait a while for wider support, both on the service and wallet side.
At the same time, however, it is also important to point out that there is no "real person identification" and anyone can create countless keys/wallets - i.e. identities. This issue must therefore be dealt with separately.
Anyway, you don't pay anything for the test, so go ahead!
Addition?
Wait, that's it? If you're a bit of a geek and are interested in such concepts in depth, let's take a more technical look at the LNURL-auth protocol together.
Every non-custodial wallet has a master private key (if not, we have a solution for that too). The derivation path m/138'/0 contains the so-called hashingKey. We will put this together with the service URL into the HMAC function:
output = HMAC-SHA256(hashingKey, domain from URL string)
We take the first 16 bytes from the output and split them into 4 equally sized parts. This gives us a derivation path for the so-called linkingKey, i.e. a key that is unique for each service (URL):
linkingKey = m/138'/<part1>/<part2>/<part3>/<part4>
After scanning the QR code, the wallet decodes the bech32 and gets an HTTPS link, for example:
https://web.com?tag=login&k1=random_data&action=login
The tag parameter tells us that this is LNURL-auth and the action specifies the login (it can also be, for example, a registration, etc.). The very important parameter k1 contains 32 bytes of random data that we need to sign with our linkingPrivKey.
After the user has agreed to the login dialog, the wallet responds with the same URL, only adding the sig and key parameters to it:
- sig = signed random data k1 over the secp256k1 curve using the linkingPrivKey private key
- key = public key linkingKey
https://web.com?tag=login&k1=random_data&action=login&sig=signature&key=public_key
The service then verifies the signature and, if it is correct, assigns the user an identity based on his linkingKey, or alternatively creates a new one if it is a registration.
More details and specification itself: