hojas/nostr_notes/First steps.md

79 lines
2.9 KiB
Markdown
Raw Normal View History

2023-12-09 19:27:21 +01:00
I've been reading too much about this without dipping my toes, so here it goes.
I want to run a relay locally, create two identities and get them talking to each other.
I'll be using Python stuff so that I can look under the hood if necessary.
- Python client: https://github.com/BrightonBTC/bija
- Python relay: https://github.com/monty888/nostrpy
Goals:
1. [x] Create a private/public key pair.
2. [x] Connect to a popular relay and read stuff.
3. [ ] Set up my own local relay and talk with myself.
# Creating a private/public key pair
So, from what I'm reading, a private key is simply a 256 bit number, usually encoded in hex. I can easily create that with:
```shell
openssl rand -hex 32
```
So I got myself this nice private key: `39d583bc40f732b0c35dfe1a5b1124c5b51b6599f78c6d60f59f31c4581d524b`. Now I just need it's public sibling to get going.
I decided to cook the public key myself with this library: https://github.com/jeffthibault/python-nostr. Install it was a pain, everything kept breaking. In the end, I:
- Downloaded Python 3.9
- Cloned the `python-nostr` repo
- Made a venv and installed `python-nostr` in there
So, I managed to get my public key like this:
```python
from nostr.key import PrivateKey
private_key = PrivateKey(raw_secret=bytes.fromhex("39d583bc40f732b0c35dfe1a5b1124c5b51b6599f78c6d60f59f31c4581d524b"))
public_key = private_key.public_key
print(f"Private key: {private_key.bech32()}")
print(f"Public key: {public_key.bech32()}")
```
And apparently, my private key and public key in bech32 format are:
- Private: nsec1882c80zq7uetps6alcd9kyfyck63keve77xx6c84nucugkqa2f9s5r7rrg
- Public: npub1zer6sezx3a6g7ef9qanv9qnqamcn4j2fez366skhfkpvffkpmvhsf65huy
In hex:
- Private: 39d583bc40f732b0c35dfe1a5b1124c5b51b6599f78c6d60f59f31c4581d524b
- Public: 1647a864468f748f65250766c28260eef13ac949c8a3ad42d74d82c4a6c1db2f
# Connect to a popular relay
Ok. Part 1, getting a client setup. I'll try with: https://github.com/BrightonBTC/bija.
Docker didn't work, weird errors left and right. I went ahead and simply installed as a python script.
Okay nice, I loaded my private keys and we are live. Now I need to find someone's pubkey to search for their messages.
I settled for dergigi, this is his pubkey: `npub1dergggklka99wwrs92yz8wdjs952h2ux2ha2ed598ngwu9w7a6fsh9xzpc`
Andn I found him. Cooooolio.
# Set up my own local relay and talk with myself
Okay, this one will be a bit tougher for sure.
First, I don't even know if bija can't connect to my own home relay. The first time I opened, it automatically showed me a bunch of cool relays and I just accepted those, so I don't know how to add another one. I'm gonna check.
Okay, it can connect to a `wss://` address. Apparently `wss` stands for web socket, which is an alternative protocol to http. Man, I'm growing old and outdated.
Anyways. If I set up a relay and manage to get that `wss://` thingy from it, I should be able to connect.