Nostr is an awesome protocol, according to this website:
Nostr is a simple, open protocol that enables global, decentralized, and censorship-resistant social media.
The protocol is as follows:
Exists clients and relays, the clients are run by users and anyone can run a relay. The users are identified by a public key and every event is signed. The clients fetch or send data to the relays. The relays don’t communicate each other, only to clients.
On this article I am going to show you how to fetch and send data to the relays, but first you need a pair of keys.
Generating the Nostr Keys
Assuming you already have installed nodejs, lets install the package nostr-tools
:
npm install nostr-tools
The code is the following:
import {generatePrivateKey, getPublicKey} from 'nostr-tools'
let sk = generatePrivateKey() // `sk` is a hex string
let pk = getPublicKey(sk) // `pk` is a hex string
console.log("sk: "+sk)
console.log("pk: "+pk)
If you save the code as keys_gen.js, you can run the code as:
node keys_gen.js
something like this is going to show:
sk…