Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add .gitignore #1

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/nostr-python.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,52 @@
# nostr-python
a nostr protocol with python


client:
1. Connect to relay -
websockets : https://relay.nekolicio.us/
nostr-watcher : https://relay.nekolicio.us/watcher/
usage at terminal : python3 client-sender.py --host relay.nekolicio.us/ --message "Hi !"

2. Send event (ref protocol)- in json
```
["EVENT", <event JSON >] :

{
"id": <32-bytes lowercase hex-encoded sha256 of the serialized event data>,
"pubkey": <32-bytes lowercase hex-encoded public key of the event creator>,
"created_at": <unix timestamp in seconds>,
"kind": <integer>,
"tags": [
["e", <32-bytes hex of the id of another event>, <recommended relay URL>],
["p", <32-bytes hex of a pubkey>, <recommended relay URL>],
... // other kinds of tags may be included later
],
"content": <arbitrary string>,
"sig": <64-bytes hex of the signature of the sha256 hash of the serialized event data, which is the same as the "id" field>
}
```
simplied as -

```
["EVENT", <event JSON >] :

{
"id": ...,
"pubkey": ...,
"created_at": ...,
"kind": 1,
"tags": [],
"content": "First try nostr-python OK !",
"sig": ...
}
```

3. Disconnect


Ref:
https://github.com/nostr-protocol/nostr
https://snyk.io/advisor/npm-package/[email protected]
https://github.com/jeffthibault/python-nostr
https://www.nostr.net/
47 changes: 47 additions & 0 deletions client-sender.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python3

import time
import json
import ssl
import asyncio
import websockets
#from nostr.relay_manager import RelayManager
import secp256k1
#rom hashlib import sha256
#from nostr.key import PrivateKey
import argparse
RELAY_Timeout_DURATION = 60




async def send_message(host,messages):
uri = "wss://{}".format(host)
event = {
'id': None,
'sig': None,
'content':messages,
'created_at':None,
'kind':1,
'pubkey': None,
'tag':[]
}

data = [0,event['kind'],event['tag'],event['content']]
serialzed = json.dumps(data,separators=(',',':'),ensure_ascii=False).encode()

async with websockets.connect(uri) as websocket:
payload = [
'EVENT',
event
]
await websocket.send(json.dumps(payload))



if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--host')
parser.add_argument('--message')
args = parser.parse_args()
asyncio.run(send_message(args.host,args.message))
52 changes: 52 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.