generate new keys

This commit is contained in:
callebtc 2023-03-22 17:49:43 +01:00
commit c2e58fa1b4
3 changed files with 36 additions and 19 deletions

View file

@ -7,6 +7,18 @@ from fastapi.staticfiles import StaticFiles
from lnbits.db import Database
from lnbits.helpers import template_renderer
from lnbits.tasks import catch_everything_and_restart
from loguru import logger
try:
from ..nostrclient.nostr.event import Event
from ..nostrclient.nostr.key import PrivateKey, PublicKey
nostrclient_present = True
nostr_privatekey = PrivateKey()
nostr_publickey: PublicKey = nostr_privatekey.public_key
logger.debug(f"LNURLP Zaps Nostr pubkey: {nostr_publickey.hex()}")
except ImportError:
nostrclient_present = False
db = Database("ext_lnurlp")

View file

@ -12,6 +12,13 @@ from .crud import increment_pay_link, get_pay_link, get_address_data
from loguru import logger
from urllib.parse import urlparse
import json
from . import nostrclient_present, nostr_publickey
if nostrclient_present:
try:
from ..nostrclient.nostr.key import PrivateKey, PublicKey
except ImportError:
nostrclient_present = False
@lnurlp_ext.get(
@ -144,8 +151,7 @@ async def api_lnurl_response(request: Request, link_id, lnaddress=False):
if link.comment_chars > 0:
params["commentAllowed"] = link.comment_chars
if nostrclient_present:
params["allowsNostr"] = True
params[
"nostrPubkey"
] = "749b4d4dfc6b00a5e6c9a88d8a220c46c069ff8f027dcf312f040475e059554a" # private: de1af06647137d49b2277faa86f96effc94257a7b7efd6f5dcc52bea08a4746b
params["nostrPubkey"] = nostr_publickey.hex()
return params

View file

@ -12,6 +12,14 @@ from websocket import WebSocketApp
from lnbits.settings import settings
from .crud import get_pay_link
from threading import Thread
from . import nostrclient_present, nostr_privatekey
if nostrclient_present:
try:
from ..nostrclient.nostr.event import Event
from ..nostrclient.nostr.key import PrivateKey, PublicKey
except ImportError:
nostrclient_present = False
async def wait_for_paid_invoices():
@ -67,9 +75,7 @@ async def on_invoice_paid(payment: Payment):
# NIP-57
nostr = payment.extra.get("nostr")
if nostr:
from ..nostrclient.nostr.event import Event
from ..nostrclient.nostr.key import PrivateKey, PublicKey
if nostrclient_present and nostr:
event_json = json.loads(nostr)
@ -79,13 +85,6 @@ async def on_invoice_paid(payment: Payment):
]
return res[0] if res else None
private_key = PrivateKey(
bytes.fromhex(
"de1af06647137d49b2277faa86f96effc94257a7b7efd6f5dcc52bea08a4746b"
)
)
p_tag = get_tag(event_json, "p")
tags = []
for t in ["p", "e"]:
tag = get_tag(event_json, t)
@ -96,7 +95,7 @@ async def on_invoice_paid(payment: Payment):
zap_receipt = Event(
kind=9735, tags=tags, content=payment.extra.get("comment") or ""
)
private_key.sign_event(zap_receipt)
nostr_privatekey.sign_event(zap_receipt)
def send_event(_):
logger.debug(f"Sending zap: {zap_receipt.to_message()}")