V1 (#106)
This commit is contained in:
parent
83c94e94db
commit
0fc26d096f
52 changed files with 6684 additions and 3120 deletions
|
|
@ -13,7 +13,7 @@ class NostrEvent(BaseModel):
|
|||
kind: int
|
||||
tags: List[List[str]] = []
|
||||
content: str = ""
|
||||
sig: Optional[str]
|
||||
sig: Optional[str] = None
|
||||
|
||||
def serialize(self) -> List:
|
||||
return [0, self.pubkey, self.created_at, self.kind, self.tags, self.content]
|
||||
|
|
@ -41,7 +41,7 @@ class NostrEvent(BaseModel):
|
|||
f"Invalid public key: '{self.pubkey}' for event '{self.id}'"
|
||||
)
|
||||
|
||||
valid_signature = pub_key.schnorr_verify(
|
||||
valid_signature = self.sig and pub_key.schnorr_verify(
|
||||
bytes.fromhex(event_id), bytes.fromhex(self.sig), None, raw=True
|
||||
)
|
||||
if not valid_signature:
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ import asyncio
|
|||
import json
|
||||
from asyncio import Queue
|
||||
from threading import Thread
|
||||
from typing import Callable, List
|
||||
from typing import Callable, List, Optional
|
||||
|
||||
from loguru import logger
|
||||
from websocket import WebSocketApp
|
||||
|
||||
from lnbits.app import settings
|
||||
from lnbits.settings import settings
|
||||
from lnbits.helpers import encrypt_internal_message, urlsafe_short_hash
|
||||
|
||||
from .event import NostrEvent
|
||||
|
|
@ -17,7 +17,7 @@ class NostrClient:
|
|||
def __init__(self):
|
||||
self.recieve_event_queue: Queue = Queue()
|
||||
self.send_req_queue: Queue = Queue()
|
||||
self.ws: WebSocketApp = None
|
||||
self.ws: Optional[WebSocketApp] = None
|
||||
self.subscription_id = "nostrmarket-" + urlsafe_short_hash()[:32]
|
||||
self.running = False
|
||||
|
||||
|
|
@ -30,7 +30,6 @@ class NostrClient:
|
|||
async def connect_to_nostrclient_ws(self) -> WebSocketApp:
|
||||
logger.debug(f"Connecting to websockets for 'nostrclient' extension...")
|
||||
|
||||
|
||||
relay_endpoint = encrypt_internal_message("relay")
|
||||
on_open, on_message, on_error, on_close = self._ws_handlers()
|
||||
ws = WebSocketApp(
|
||||
|
|
@ -57,19 +56,18 @@ class NostrClient:
|
|||
await asyncio.sleep(5)
|
||||
|
||||
req = await self.send_req_queue.get()
|
||||
assert self.ws
|
||||
self.ws.send(json.dumps(req))
|
||||
except Exception as ex:
|
||||
logger.warning(ex)
|
||||
await asyncio.sleep(60)
|
||||
|
||||
|
||||
async def get_event(self):
|
||||
value = await self.recieve_event_queue.get()
|
||||
if isinstance(value, ValueError):
|
||||
raise value
|
||||
return value
|
||||
|
||||
|
||||
async def publish_nostr_event(self, e: NostrEvent):
|
||||
await self.send_req_queue.put(["EVENT", e.dict()])
|
||||
|
||||
|
|
@ -119,7 +117,7 @@ class NostrClient:
|
|||
|
||||
asyncio.create_task(unsubscribe_with_delay(subscription_id, duration))
|
||||
|
||||
async def user_profile_temp_subscribe(self, public_key: str, duration=5) -> List:
|
||||
async def user_profile_temp_subscribe(self, public_key: str, duration=5):
|
||||
try:
|
||||
profile_filter = [{"kinds": [0], "authors": [public_key]}]
|
||||
subscription_id = "profile-" + urlsafe_short_hash()[:32]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue