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:
parent
0d579892a8
commit
bdf71d3ea9
1 changed files with 20 additions and 30 deletions
|
|
@ -268,42 +268,32 @@ async def _create_default_pay_link(account: Account, wallet) -> None:
|
|||
|
||||
async def _publish_nostr_metadata_event(account: Account) -> None:
|
||||
"""Publish a Nostr kind 0 metadata event for a new user"""
|
||||
try:
|
||||
import importlib
|
||||
import sys
|
||||
import secp256k1
|
||||
import coincurve
|
||||
|
||||
# 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
|
||||
metadata = {
|
||||
"name": account.username,
|
||||
"display_name": account.username,
|
||||
"about": f"LNbits user: {account.username}",
|
||||
}
|
||||
# Create Nostr kind 0 metadata event
|
||||
metadata = {
|
||||
"name": account.username,
|
||||
"display_name": account.username,
|
||||
"about": f"LNbits user: {account.username}",
|
||||
}
|
||||
|
||||
event = {
|
||||
"kind": 0,
|
||||
"created_at": int(time.time()),
|
||||
"tags": [],
|
||||
"content": json.dumps(metadata),
|
||||
}
|
||||
event = {
|
||||
"kind": 0,
|
||||
"created_at": int(time.time()),
|
||||
"tags": [],
|
||||
"content": json.dumps(metadata),
|
||||
}
|
||||
|
||||
# Sign the event using LNbits utilities
|
||||
from lnbits.utils.nostr import sign_event
|
||||
# Convert hex private key to coincurve PrivateKey
|
||||
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
|
||||
signed_event = sign_event(event, account.pubkey, private_key)
|
||||
|
||||
# Sign the event
|
||||
signed_event = sign_event(event, account.pubkey, private_key)
|
||||
|
||||
# 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
|
||||
# Publish directly to nostrrelay database (hacky but works around WebSocket issues)
|
||||
await _insert_event_into_nostrrelay(signed_event, account.username)
|
||||
|
||||
|
||||
async def _insert_event_into_nostrrelay(event: dict, username: str) -> None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue