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,12 +268,9 @@ 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 = {
@ -289,11 +286,8 @@ async def _publish_nostr_metadata_event(account: Account) -> None:
"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
private_key = secp256k1.PrivateKey(bytes.fromhex(account.prvkey))
# Sign the event # Sign the event
signed_event = sign_event(event, account.pubkey, private_key) signed_event = sign_event(event, account.pubkey, private_key)
@ -301,10 +295,6 @@ async def _publish_nostr_metadata_event(account: Account) -> None:
# Publish directly to nostrrelay database (hacky but works around WebSocket issues) # Publish directly to nostrrelay database (hacky but works around WebSocket issues)
await _insert_event_into_nostrrelay(signed_event, account.username) 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:
"""Directly insert Nostr event into nostrrelay database (hacky workaround)""" """Directly insert Nostr event into nostrrelay database (hacky workaround)"""