-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added new examples nip46 signer and client, other fixes to examples. …
…In progress NIP46Signer
- Loading branch information
monty
committed
Jun 8, 2024
1 parent
c2ec126
commit e8b038d
Showing
8 changed files
with
253 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import asyncio | ||
import logging | ||
from monstr.signing.nip46 import NIP46Signer | ||
from monstr.client.client import Client | ||
from monstr.event.event import Event | ||
|
||
# url to relay used for talking to the signer | ||
RELAY = 'ws://localhost:8080' | ||
|
||
|
||
async def do_post(url, text): | ||
""" | ||
Example showing how to post a text note (Kind 1) to relay | ||
using nip46 signer - we don't have access locally to the keys | ||
""" | ||
|
||
# bunker://... e.g. printed out by nip46_signer_service.py | ||
con_str = input('connection string: ').strip() | ||
|
||
# we'll make post and they'll be signed by the bunker at con_str | ||
my_signer = NIP46Signer(connection=con_str) | ||
|
||
# from here it's just a signer interface same as if we were using BasicKeySigner | ||
async with Client(url) as c: | ||
n_msg = await my_signer.ready_post(Event(kind=Event.KIND_TEXT_NOTE, | ||
content=text)) | ||
c.publish(n_msg) | ||
|
||
|
||
if __name__ == "__main__": | ||
logging.getLogger().setLevel(logging.DEBUG) | ||
text = 'hello using NIP46 signer' | ||
|
||
asyncio.run(do_post(RELAY, text)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import asyncio | ||
import logging | ||
from monstr.encrypt import Keys | ||
from monstr.signing.nip46 import NIP46ServerConnection | ||
from monstr.signing.signing import BasicKeySigner | ||
|
||
# url to relay used for talking to the signer | ||
RELAY = 'ws://localhost:8080' | ||
|
||
|
||
async def run_signer(): | ||
""" | ||
Run a service that'll sign events via NIP46 for some random keys | ||
""" | ||
# rnd generate some keys | ||
n_keys = Keys() | ||
|
||
# create the signing service | ||
my_signer = NIP46ServerConnection(signer=BasicKeySigner(n_keys), | ||
relay=RELAY) | ||
|
||
# output info needed for client to connect to the signer | ||
print(await my_signer.bunker_url) | ||
|
||
# wait forever... | ||
while True: | ||
await asyncio.sleep(0.1) | ||
|
||
if __name__ == "__main__": | ||
logging.getLogger().setLevel(logging.DEBUG) | ||
asyncio.run(run_signer()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__='0.1.7' | ||
__version__='0.1.8' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters