@@ -4,10 +4,12 @@ A Python library for making [Nostr](https://github.com/nostr-protocol/nostr) cli
4
4
## Usage
5
5
** Generate a key**
6
6
``` python
7
- from nostr.key import generate_private_key, get_public_key
7
+ from nostr.key import PrivateKey
8
8
9
- private_key = generate_private_key()
10
- public_key = get_public_key(private_key)
9
+ private_key = PrivateKey()
10
+ public_key = private_key.public_key
11
+ print (f " Private key: { private_key.bech32()} " )
12
+ print (f " Public key: { public_key.bech32()} " )
11
13
```
12
14
** Connect to relays**
13
15
``` python
@@ -32,19 +34,18 @@ import time
32
34
from nostr.event import Event
33
35
from nostr.relay_manager import RelayManager
34
36
from nostr.message_type import ClientMessageType
35
- from nostr.key import generate_private_key, get_public_key
37
+ from nostr.key import PrivateKey
36
38
37
39
relay_manager = RelayManager()
38
40
relay_manager.add_relay(" wss://nostr-pub.wellorder.net" )
39
41
relay_manager.add_relay(" wss://relay.damus.io" )
40
42
relay_manager.open_connections({" cert_reqs" : ssl.CERT_NONE }) # NOTE : This disables ssl certificate verification
41
43
time.sleep(1.25 ) # allow the connections to open
42
44
43
- private_key = generate_private_key()
44
- public_key = get_public_key(private_key)
45
+ private_key = PrivateKey()
45
46
46
- event = Event(public_key, " Hello Nostr" )
47
- event.sign(private_key)
47
+ event = Event(private_key. public_key.hex() , " Hello Nostr" )
48
+ event.sign(private_key.hex() )
48
49
49
50
message = json.dumps([ClientMessageType.EVENT , event.to_json_object()])
50
51
relay_manager.publish_message(message)
@@ -59,7 +60,6 @@ from nostr.filter import Filter, Filters
59
60
from nostr.event import Event, EventKind
60
61
from nostr.relay_manager import RelayManager
61
62
from nostr.message_type import ClientMessageType
62
- from nostr.key import generate_private_key, get_public_key
63
63
64
64
filters = Filters([Filter(authors = [< a nostr pubkey in hex > ], kinds = [EventKind.TEXT_NOTE ])])
65
65
subscription_id = < a string to identify a subscription>
@@ -85,13 +85,21 @@ relay_manager.close_connections()
85
85
```
86
86
87
87
## Installation
88
- 1 . Clone repository \
89
- ``` git clone https://github.com/jeffthibault/python-nostr.git ```
90
- 2 . Install dependencies in repo \
91
- ``` python -m venv venv ``` \
92
- ``` pip install -r requirements.txt ```
88
+ 1 . Clone repository
89
+ ``` bash
90
+ git clone https://github.com/jeffthibault/python-nostr.git
91
+ ```
92
+ 2 . Install dependencies in repo
93
+ ``` bash
94
+ python -m venv venv
95
+ pip install -r requirements.txt
96
+ ```
93
97
94
- Note: If the pip install fails, you might need to install wheel. Try ``` pip install wheel ``` then ``` pip install -r requirements.txt ```
98
+ Note: If the pip install fails, you might need to install ``` wheel ``` . Try the following:
99
+ ``` bash
100
+ pip install wheel
101
+ pip install -r requirements.txt
102
+ ```
95
103
96
104
## Dependencies
97
105
- [ websocket-client] ( https://github.com/websocket-client/websocket-client ) for websocket operations
0 commit comments