Compare commits

..

1 Commits

Author SHA1 Message Date
Alexander Whitestone
6ebf54d457 fix: closes #731
Some checks failed
CI / test (pull_request) Failing after 8s
CI / validate (pull_request) Failing after 13s
Review Approval Gate / verify-review (pull_request) Failing after 3s
2026-04-12 12:39:23 -04:00
3 changed files with 16 additions and 13 deletions

View File

@@ -66,7 +66,12 @@ class NostrIdentity:
if privkey_hex:
self.privkey = int(privkey_hex, 16)
else:
self.privkey = int.from_bytes(os.urandom(32), 'big') % N
# Rejection sampling: avoid modulo bias from % N
while True:
candidate = int.from_bytes(os.urandom(32), 'big')
if 0 < candidate < N:
self.privkey = candidate
break
self.pubkey = get_pubkey(self.privkey)
def sign_event(self, event):

View File

@@ -50,23 +50,21 @@ async def broadcast_handler(websocket: websockets.WebSocketServerProtocol):
# Broadcast to all OTHER clients
if not clients:
continue
disconnected = set()
# Create broadcast tasks for efficiency
tasks = []
# Track (client, task) pairs so failed clients are identified directly
send_jobs = []
for client in clients:
if client != websocket and client.open:
tasks.append(asyncio.create_task(client.send(message)))
if tasks:
results = await asyncio.gather(*tasks, return_exceptions=True)
for i, result in enumerate(results):
send_jobs.append((client, asyncio.create_task(client.send(message))))
if send_jobs:
results = await asyncio.gather(*[job[1] for job in send_jobs], return_exceptions=True)
for (target_client, _), result in zip(send_jobs, results):
if isinstance(result, Exception):
# Find the client that failed
target_client = [c for c in clients if c != websocket][i]
logger.error(f"Failed to send to a client {target_client.remote_address}: {result}")
disconnected.add(target_client)
if disconnected:
clients.difference_update(disconnected)

View File

@@ -11,7 +11,7 @@ const ASSETS_TO_CACHE = [
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE_NAME).then(cache => {
caches.open(CachedName).then(cache => {
return cache.addAll(ASSETS_TO_CACHE);
})
);