I am learning LNURL authentication but having some trouble with the basics. I would love some help!
I made this post yesterday but didn't get many eyes #196782
I will post the contents here:
I have most of this figured out I think. Originally I could create a signature and successfully authenticate using the generated URL, but it wasn't for the correct account. I had since learned a lot about what I need to do to get the correct account at the right derivation path but in that process I lost the original code.
My current code is as follows, but does not successfully authenticate. I am using SN to test. I am looking for any successful authentication to SN, regardless of if its the correct from the derivation path or not.
I have NO IDEA what my original code did to work and its driving me crazy.
const bitcoin = require('bitcoinjs-lib') const bitcoinmsg = require('bitcoinjs-message') const bs58 = require('bs58') const ecc = require('tiny-secp256k1') const secp256k1 = require('secp256k1') const { BIP32Factory } = require('bip32') const bip32 = BIP32Factory(ecc) const bip39 = require('bip39') const {bech32} = require("bech32") const {ECPairFactory} = require('ecpair') const ECPair = ECPairFactory(ecc) const crypto = require('crypto') function getqueryparams(url) { const paramarr = url.slice(url.indexOf('?') + 1).split('&') const params = {} paramarr.map(param => { const [key, val] = param.split('=') params[key] = decodeURIComponent(val) }) return params; } function getbaseurl(url) { return url.slice(0, url.indexOf('?')) } function bech32decode(lnurl) { const { prefix: hrp, words: datapart } = bech32.decode(lnurl, 2000) const bytearray = bech32.fromWords(datapart) return Buffer.from(bytearray).toString() } const testkey = crypto.generateKeyPairSync('ec', {namedCurve: 'secp256k1',}).privateKey const phrase = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon" const lnurl = "" const decodedlnurl = bech32decode(lnurl) const baseurl = getbaseurl(decodedlnurl) const k1 = getqueryparams(decodedlnurl)['k1'] const k1hash = bitcoin.crypto.sha256(Buffer.from(k1, 'hex')) const seed = bip39.mnemonicToSeedSync(phrase) const root = bip32.fromSeed(seed) const child = root.derivePath("m/138'/0'/0'/0/0") // will get the right path later const keyPair = ECPair.fromPrivateKey(child.privateKey) const signature = keyPair.sign(k1hash) const derSignature = bitcoin.script.signature.encode(signature, bitcoin.Transaction.SIGHASH_ALL) const verify = keyPair.verify(k1hash, signature); const domaintest = 'stacker.news' const url = `${decodedlnurl}&sig=${derSignature.toString('hex')}&key=${child.publicKey.toString('hex')}` console.log(url)
I've seen your post but had no answer so I just tipped you so someone else maybe sees it
But I am definitely also interested in what you are doing
You are basically trying to create the wallet part of LNURL-auth, right?
reply
Yup! It is possible and there is actually an app that does this: https://github.com/GetIn-id/
It is what I currently use to authenticate with SN but it got me curious and I wanted to try creating my own little tool to do the same thing in nodejs.
GetIn is cool because it generates a seed phrase just like you would use to store Bitcoin and then you can generate profiles off that phrase to log into individual sites with. I want to build a similar app, but I have a different vision in mind than they do on the overall direction I want to take the app.
This link contains a lot of detail on implementation and links to the specific LUDS #98600
The biggest challenge so far is the documentation. If you get stuck and need to search for examples, the examples are most likely outdated because the libraries used have since changed some things around or gotten rid of functions entirely. So a good portion of my journey has been re working all these steps in isolation because it wasn't often clear that the documentation or example is outdated.
It is also frustrating that documentation has no consistency. Why does LUDS 05 show an example in Scala but LUDS 04 is in python?
It is just growing pains of both young documentation (most of it did not exist more than 2 years ago) and outdated documentation due to libraries updating. Positive changes overall but is challenging to navigate.
Thanks for helping with visibility. This is a burner account. I have returned the sats.
reply
I will take a look at your code when I have more time. Hopefully next week
reply
I appreciate it! I wonder if there is a discord or something for devs building stuff on Bitcoin. That could be very useful.
reply
reply
Yep this in an actual invite: https://discord.gg/j3d5PKW6
reply
Ty daddy
reply
I think you need to post an invite first. That link leads me to a "weird place" as Discord calls it, lol
reply
Weird places are the best places to be. Discord does not know how to party.
reply
Don't hesitate to remind me if I have forgotten it :) I also want to learn this stuff
I think I saw some lightning dev discords but I don't remember where
reply