fix: use coincurve instead of secp256k1 for Nostr event signing

- Replace secp256k1.PrivateKey with coincurve.PrivateKey to match
  the sign_event function signature in lnbits/utils/nostr.py
- Remove internal try/except so exceptions propagate to caller,
  fixing misleading success logs when publishing actually fails

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
padreug 2025-12-31 11:10:41 +01:00
parent 0d579892a8
commit bdf71d3ea9

View file

@ -268,42 +268,32 @@ async def _create_default_pay_link(account: Account, wallet) -> None:
async def _publish_nostr_metadata_event(account: Account) -> None: async def _publish_nostr_metadata_event(account: Account) -> None:
"""Publish a Nostr kind 0 metadata event for a new user""" """Publish a Nostr kind 0 metadata event for a new user"""
try: import coincurve
import importlib
import sys
import secp256k1
# Note: We publish directly to nostrrelay database, no need to get relay URLs from lnbits.utils.nostr import sign_event
# Create Nostr kind 0 metadata event # Create Nostr kind 0 metadata event
metadata = { metadata = {
"name": account.username, "name": account.username,
"display_name": account.username, "display_name": account.username,
"about": f"LNbits user: {account.username}", "about": f"LNbits user: {account.username}",
} }
event = { event = {
"kind": 0, "kind": 0,
"created_at": int(time.time()), "created_at": int(time.time()),
"tags": [], "tags": [],
"content": json.dumps(metadata), "content": json.dumps(metadata),
} }
# Sign the event using LNbits utilities # Convert hex private key to coincurve PrivateKey
from lnbits.utils.nostr import sign_event private_key = coincurve.PrivateKey(bytes.fromhex(account.prvkey))
# Convert hex private key to secp256k1 PrivateKey # Sign the event
private_key = secp256k1.PrivateKey(bytes.fromhex(account.prvkey)) signed_event = sign_event(event, account.pubkey, private_key)
# Sign the event # Publish directly to nostrrelay database (hacky but works around WebSocket issues)
signed_event = sign_event(event, account.pubkey, private_key) await _insert_event_into_nostrrelay(signed_event, account.username)
# Publish directly to nostrrelay database (hacky but works around WebSocket issues)
await _insert_event_into_nostrrelay(signed_event, account.username)
except Exception as e:
logger.error(f"Failed to publish Nostr metadata event: {e}")
# Don't raise - we don't want user creation to fail if Nostr publishing fails
async def _insert_event_into_nostrrelay(event: dict, username: str) -> None: async def _insert_event_into_nostrrelay(event: dict, username: str) -> None: