You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
works like a charm!
This commit is contained in:
@@ -8,7 +8,8 @@ EC_COMPRESSED = lib.SECP256K1_EC_COMPRESSED
|
||||
EC_UNCOMPRESSED = lib.SECP256K1_EC_UNCOMPRESSED
|
||||
|
||||
HAS_RECOVERABLE = hasattr(lib, 'secp256k1_ecdsa_sign_recoverable')
|
||||
HAS_SCHNORR = hasattr(lib, 'secp256k1_schnorrsig_sign')
|
||||
#HAS_SCHNORR = hasattr(lib, 'secp256k1_schnorrsig_sign')
|
||||
HAS_SCHNORR = hasattr(lib, 'secp256k1_schnorrsig_sign_custom') # forgot why it's called custom
|
||||
HAS_ECDH = hasattr(lib, 'secp256k1_ecdh')
|
||||
HAS_EXTRAKEYS = hasattr(lib, 'secp256k1_keypair_create')
|
||||
|
||||
@@ -231,16 +232,17 @@ class PublicKey(ECDSA):
|
||||
return bool(verified)
|
||||
|
||||
def schnorr_verify(self, msg, schnorr_sig, bip340tag, raw=False):
|
||||
print("schnorr_verify 0")
|
||||
assert self.public_key, "No public key defined"
|
||||
if not HAS_SCHNORR:
|
||||
raise Exception("secp256k1_schnorr not enabled")
|
||||
|
||||
print("schnorr_verify 1")
|
||||
msg_to_sign = _bip340_tag(msg, raw, bip340tag)
|
||||
|
||||
print("schnorr_verify 2")
|
||||
verified = lib.secp256k1_schnorrsig_verify(
|
||||
secp256k1_ctx, schnorr_sig, msg_to_sign, len(msg_to_sign),
|
||||
self.xonly_pubkey)
|
||||
|
||||
print("schnorr_verify 3")
|
||||
return bool(verified)
|
||||
|
||||
def ecdh(self, scalar, hashfn=ffi.NULL, hasharg=ffi.NULL):
|
||||
|
||||
@@ -267,11 +267,15 @@ class Lib:
|
||||
return 0
|
||||
|
||||
def secp256k1_schnorrsig_verify(self, ctx, schnorr_sig, msg, msg_len, xonly_pubkey):
|
||||
print("compat.py secp256k1_schnorrsig_verify 1")
|
||||
try:
|
||||
print("compat.py secp256k1_schnorrsig_verify 2")
|
||||
if isinstance(xonly_pubkey, FFI.CData):
|
||||
xonly_pubkey = xonly_pubkey._data
|
||||
print("compat.py secp256k1_schnorrsig_verify 3")
|
||||
return usecp256k1.schnorrsig_verify(schnorr_sig, msg, xonly_pubkey)
|
||||
except (ValueError, AttributeError):
|
||||
print("compat.py secp256k1_schnorrsig_verify error")
|
||||
return 0
|
||||
|
||||
def secp256k1_tagged_sha256(self, ctx, hash32, tag, tag_len, msg, msg_len):
|
||||
|
||||
@@ -40,7 +40,7 @@ def _run_callback(callback, *args):
|
||||
"""Add callback to queue for execution."""
|
||||
try:
|
||||
_callback_queue.append((callback, args))
|
||||
_log_debug(f"Queued callback {callback}, queue size: {len(_callback_queue)}")
|
||||
_log_debug(f"Queued callback {callback}, args={args}, queue size: {len(_callback_queue)}")
|
||||
except IndexError:
|
||||
_log_error("Callback queue full, dropping callback")
|
||||
|
||||
@@ -52,7 +52,9 @@ async def _process_callbacks_async():
|
||||
try:
|
||||
callback, args = _callback_queue.popleft()
|
||||
if callback is not None:
|
||||
_log_debug(f"Executing callback {callback} with args {args}")
|
||||
_log_debug(f"Executing callback {callback} with {len(args)} args")
|
||||
for i, arg in enumerate(args):
|
||||
_log_debug(f"Arg {i}: {arg}")
|
||||
try:
|
||||
callback(*args)
|
||||
except Exception as e:
|
||||
@@ -294,7 +296,7 @@ class WebSocketApp:
|
||||
self._start_ping_task()
|
||||
|
||||
async for msg in ws:
|
||||
_log_debug(f"Received msg: type={msg.type}, data={str(msg.data)[:30]}...")
|
||||
_log_debug(f"Received msg: type={msg.type}, data={str(msg.data)[:20]}...")
|
||||
if not self.running:
|
||||
_log_debug("Not running, breaking message loop")
|
||||
break
|
||||
@@ -309,11 +311,11 @@ class WebSocketApp:
|
||||
if msg.type == WSMsgType.TEXT:
|
||||
data = msg.data
|
||||
_run_callback(self.on_data, self, data, ABNF.OPCODE_TEXT, True)
|
||||
_run_callback(self.on_message, self, data)
|
||||
_run_callback(self.on_message, self, data) # Standard websocket-client
|
||||
elif msg.type == WSMsgType.BINARY:
|
||||
data = msg.data
|
||||
_run_callback(self.on_data, self, data, ABNF.OPCODE_BINARY, True)
|
||||
_run_callback(self.on_message, self, data)
|
||||
_run_callback(self.on_message, self, data) # Standard websocket-client
|
||||
elif msg.type == WSMsgType.ERROR or ws.ws.closed:
|
||||
_log_error("WebSocket error or closed")
|
||||
raise WebSocketConnectionClosedException("WebSocket closed")
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import json
|
||||
import ssl
|
||||
import time
|
||||
import _thread
|
||||
|
||||
from nostr.filter import Filter, Filters
|
||||
from nostr.event import Event, EventKind
|
||||
from nostr.relay_manager import RelayManager
|
||||
@@ -8,8 +10,10 @@ from nostr.message_type import ClientMessageType
|
||||
|
||||
#filters = Filters([Filter(authors=[<a nostr pubkey in hex>], kinds=[EventKind.TEXT_NOTE])])
|
||||
#filters = Filters([Filter(authors="04c915daefee38317fa734444acee390a8269fe5810b2241e5e6dd343dfbecc9", kinds=[EventKind.TEXT_NOTE])])
|
||||
#timestamp = round(time.time()-10)
|
||||
timestamp = round(time.time()-100)
|
||||
#timestamp = round(time.time()-1000)
|
||||
timestamp = round(time.time()-5000)
|
||||
#timestamp = round(time.time()-5000)
|
||||
#filters = Filters([Filter(authors="04c915daefee38317fa734444acee390a8269fe5810b2241e5e6dd343dfbecc9", kinds=[9735], since=timestamp)])
|
||||
filters = Filters([Filter(kinds=[9735], since=timestamp)])
|
||||
|
||||
@@ -36,17 +40,21 @@ print("publishing:")
|
||||
relay_manager.publish_message(message)
|
||||
time.sleep(1) # allow the messages to send
|
||||
|
||||
print("printing events:")
|
||||
#while relay_manager.message_pool.has_events():
|
||||
for _ in range(60):
|
||||
time.sleep(1)
|
||||
print(".")
|
||||
try:
|
||||
event_msg = relay_manager.message_pool.get_event()
|
||||
print(event_msg.event.content)
|
||||
except Exception as e:
|
||||
print(f"pool.get_event() got error: {e}")
|
||||
|
||||
def printevents():
|
||||
print("printing events:")
|
||||
#while relay_manager.message_pool.has_events():
|
||||
for _ in range(60):
|
||||
time.sleep(1)
|
||||
print(".")
|
||||
try:
|
||||
event_msg = relay_manager.message_pool.get_event()
|
||||
print(event_msg.event.content)
|
||||
except Exception as e:
|
||||
print(f"pool.get_event() got error: {e}")
|
||||
print("60 seconds passed, closing:")
|
||||
relay_manager.close_connections()
|
||||
|
||||
#_thread.stack_size(32*1024)
|
||||
#_thread.start_new_thread(printevents, ())
|
||||
printevents()
|
||||
|
||||
print("closing:")
|
||||
relay_manager.close_connections()
|
||||
|
||||
Reference in New Issue
Block a user