How to create a POW nostr key pair

How to create a POW nostr key pair

Mads @npub1rpes5hhk6mxun5ddt5kecxfm8y3xdr0h5jwal32mc6mxafr48hxsaj2et2


Also: what is POW, what is nostr, what is a key-pair??

    To start out, I'd like to say that I have had no technical background whatsoever before deciding to run my own bitcoin lightning node ~2 years ago. (This decision was made because I couldn't understand what lightning was or how it worked without actually doing it myself).  This was, and continues to be, a great learning experience, but I would still call myself un-technical after going through that process.  If you are also un-technical or just want a good intro into running lightning nodes, check out plebnet.wiki and/or join plebnet.org (a telegram community) for some help and resources!  

    That being said, I am going to try and explain my understanding of nostr and what I did to create a POW key-pair, but please know that I may be very wrong in my understanding & terms.  

    I'm not exactly sure where I heard about nostr or how to get "on" nostr, but I am in the habit of following smart plebs down interesting rabbit holes to try and understand how things work.  Here is my understanding of nostr:  it is an open communications network created, but not necessarily run by, @fiatjaf.  After the code for this network was released, anyone can spin it up and make of it what they want.  It allows computers called 'relays' to pass messages back and forth around the internet.  Every day users, like myself, do not currently need a personal relay, as they can connect to any publicly available relay to send and receive messages through.  There is a benefit in connecting to the same relays as those who you want to hear from or interact with, because if you are using different relays - you may not be able to see each others notes.  

    'Clients' are another term that new nostr-ers may hear frequently.  Common clients that I have interacted with so far tend to be apps, or web-apps that are created for the average user to interact with the nostr network.  If you were to interact without a client, I think you would have to code up a bunch of your own stuff to interpret the computer code and information being passed around.  Clients make things nice and organized in a way that many are used to with social media platforms. I am currently using Damus on iOS most of the time - and it is coming to the app store soon!  Damus is a client that allows users to send notes and view notes of others that you follow, or view notes from all of the relays you follow on a global feed.  You can also create a profile and send encrypted DM's using Damus, as well as like notes from others with 🤙!  There are limitless options for what clients could be in the future - think outside the box and not just typical social media type uses of this open communication protocol!  

    To 'log-in' and interact with nostr, you must have a nostr public and private key pair.  The public key will allow other users to find you, and the private key is used to sign each use of the public key.  When you go to interact with many/most of the popular nostr clients available, you can have a key pairing automatically generated.  The private key is very important to be kept private and there is a lot of good information out there for best practices with this.  I don't actually know how the clients spin up and hand out key-pairs or if this will be more difficult as more keys are taken up.  Something to come back to...

    Anyway, as nostr and its users expand, public relays may be overrun with spam/bots and can also get clogged up with too much usage weighing on them.  One way that has been hypothesized to circumvent these issues is by relays restricting the connections to them.  This is already happening with different filters deciding who is able to connect or 'use' some relays.  

    A nostr dev named @Cameri threw out the idea of running a relay that filters pubkeys by only allowing those which have a certain amount of POW or 'Proof of Work' in their generation.  (I didn't know that was a thing with these keys, but decided to find out more).  A proof of work key pairing is one that has to be 'mined' using a specific amount of computer effort/energy.  The amount of effort that @Cameri chose for the keys allowed on his POW relay is a difficulty of 32, which means the public key of the generated key pair must have at least 32 leading zero bits (aka the public key must start with at least 32 0s before any other letters and numbers).  The more leading 0s, the more difficult ‘work’ a computer must do to generate the key.

    There is a GitHub code created to mine nostr key pairings called ‘rana.’  To mine my key I used command line in my command prompt terminal on my computer.  (Using command line is something I did learn while in the process of setting up my lightning node, but it is also fairly easy to use when directly following instructions).  I was also told I needed to install 'rust' onto my computer before installing the key mining code.  I went to the rust website - https://www.rust-lang.org/tools/install - and followed the recommended installation for my computer.  I went with the prompts for a basic/personal user and installed the Visual Studio C++ Build tools as well because they were a part of that installation.  At the end of installation, I was briefly stuck in a loop saying that I needed to reload my current shell because I just kept opening and closing the same shell that was installed with rust.  Eventually I just happened to open my regular command line terminal and realized that was all I needed to do... always learning!  

    Next up was installing the code called 'rana' that allows for mining nostr keys.  This was pretty simple - in the command prompt terminal on my computer, I typed 'cargo install rana' (without quotes) and pressed enter.  Rana was quickly installed and then all I had to do next was direct it to mine a key with specific qualifications!  For a POW difficulty of 32, I typed 'rana --difficulty=32' (again, without the quotes) and pressed enter!  Here is what it looked like - 


C:\Users\Mads>rana --difficulty=32

Started mining process with a difficulty of: 32 (pow: 32)

Benchmarking a single core for 5 seconds...

A single core can mine roughly 9109 h/s!

Searching for prefix of 32 specific bits

This is estimated to take about 117877.02 seconds

Mining using 4 cores...


    This process took a little bit of time - at least a day or two on my computer... but that time and the effort by the computers is what will set apart my key-pair from an easy to create key-pair!  This is the ‘work’ in proof of work, and the ‘proof’ will be my key-pair with a public key with lots of 0s at the beginning of it.  

    During the downtime waiting for the key to be mined, I also found out from @rajwinder that you can mine vanity public keys using this same 'rana' code!  I had some fun with that while I waited!  The command to mine a vanity key in rana is 'rana --vanity-n=mads' (no quotes and also replace 'mads' with whatever letters/numbers? you choose)!  The longer the 'vanity' name/letters, the more difficult it is to create.  

    After a day or so of waiting for my computer to mine a key pair, I finally got my POW key!  It is important to copy down the private and public keys (but absolutely the private) somewhere safe and unaccessible to others.  After safely recording your keys, it is good to return to your command line and press control+C because if not, the computer will continue mining keys and using lots of energy. 

    To now use this key pairing to connect in to nostr, a recommended safe way to store the key for ease of signing in to clients is a browser extension called nos2x.  Using the chrome browser, I went to https://chrome.google.com/webstore/category/extensions and then searched for @fiatjaf to find the correct extension.  After searching @fiatjaf, the nos2x extension was top of page with an image of 3 brown/orange keys.  I installed the extension to my chrome browser.  Once it was installed, I selected it and clicked on options.  There, I pasted my private key into the Private Key field and hit save and closed the page.  In the same browser I then went to astral.ninja to confirm I had done everything correctly.  When the page first loads, it asks you for your key, and if you are using the nos2x extension, there is an option to 'use public key from extension,' which is what I selected.  A popup from nos2x popped up asking if I wanted to authorize astral.ninja (and for what length of time).  I selected the 'authorize for 5 min' option.  Voila! Now set up and signed in with my key, I successfully added @Cameri's relay that is only available to POW difficulty of +32 pubkeys! 


*Lastly, @Cameri had mentioned none of this process would work & I’d be kicked off of his relay if I did not do a how-to write up to share for others coming from a non technical background… so I wrote this mini novel and am sharing!


   


Report Page