allowNostr vs alllowsNostr

This commit is contained in:
callebtc 2023-03-22 00:47:37 +01:00
commit 50f9b505cd
2 changed files with 20 additions and 14 deletions

View file

@ -48,15 +48,15 @@ async def api_lnurl_callback(
min = link.min * 1000 min = link.min * 1000
max = link.max * 1000 max = link.max * 1000
amount_received = amount amount = amount
if amount_received < min: if amount < min:
return LnurlErrorResponse( return LnurlErrorResponse(
reason=f"Amount {amount_received} is smaller than minimum {min}." reason=f"Amount {amount} is smaller than minimum {min}."
).dict() ).dict()
elif amount_received > max: elif amount > max:
return LnurlErrorResponse( return LnurlErrorResponse(
reason=f"Amount {amount_received} is greater than maximum {max}." reason=f"Amount {amount} is greater than maximum {max}."
).dict() ).dict()
comment = request.query_params.get("comment") comment = request.query_params.get("comment")
@ -79,21 +79,22 @@ async def api_lnurl_callback(
extra["comment"] = (comment,) extra["comment"] = (comment,)
nostr = request.query_params.get("nostr") nostr = request.query_params.get("nostr")
nostr_description = ""
if nostr: if nostr:
extra["nostr"] = nostr extra["nostr"] = nostr
# print("HASHING THIS")
nostr_description = json.dumps(nostr)[1:-1] # remove leading and trailing "
# print(nostr_description)
import hashlib
print(hashlib.sha256(nostr_description.encode()).hexdigest())
if lnaddress and link.username and link.domain: if lnaddress and link.username and link.domain:
extra["lnaddress"] = f"{link.username}@{link.domain}" extra["lnaddress"] = f"{link.username}@{link.domain}"
print("HASHING THIS")
nostr_description = json.dumps(nostr)[1:-1] # remove leading and trailing "
print(nostr_description)
import hashlib
print(hashlib.sha256(nostr_description.encode()).hexdigest())
payment_hash, payment_request = await create_invoice( payment_hash, payment_request = await create_invoice(
wallet_id=link.wallet, wallet_id=link.wallet,
amount=int(amount_received / 1000), amount=int(amount / 1000),
memo=link.description, memo=link.description,
unhashed_description=nostr_description.encode() unhashed_description=nostr_description.encode()
if nostr if nostr
@ -149,7 +150,7 @@ async def api_lnurl_response(request: Request, link_id, lnaddress=False):
if link.comment_chars > 0: if link.comment_chars > 0:
params["commentAllowed"] = link.comment_chars params["commentAllowed"] = link.comment_chars
params["allowNostr"] = True params["allowsNostr"] = True
params[ params[
"nostrPubkey" "nostrPubkey"
] = "749b4d4dfc6b00a5e6c9a88d8a220c46c069ff8f027dcf312f040475e059554a" # private: de1af06647137d49b2277faa86f96effc94257a7b7efd6f5dcc52bea08a4746b ] = "749b4d4dfc6b00a5e6c9a88d8a220c46c069ff8f027dcf312f040475e059554a" # private: de1af06647137d49b2277faa86f96effc94257a7b7efd6f5dcc52bea08a4746b

View file

@ -65,6 +65,7 @@ async def on_invoice_paid(payment: Payment):
payment.payment_hash, -1, False, "Unexpected Error", str(ex) payment.payment_hash, -1, False, "Unexpected Error", str(ex)
) )
# NIP-57
nostr = payment.extra.get("nostr") nostr = payment.extra.get("nostr")
if nostr: if nostr:
from ..nostrclient.nostr.event import Event from ..nostrclient.nostr.event import Event
@ -92,11 +93,15 @@ async def on_invoice_paid(payment: Payment):
tags.append([t, tag]) tags.append([t, tag])
tags.append(["bolt11", payment.bolt11]) tags.append(["bolt11", payment.bolt11])
tags.append(["description", nostr]) tags.append(["description", nostr])
zap_receipt = Event(kind=9735, tags=tags, content="asd") zap_receipt = Event(
kind=9735, tags=tags, content=payment.extra.get("comment") or ""
)
private_key.sign_event(zap_receipt) private_key.sign_event(zap_receipt)
def send_event(_): def send_event(_):
# logger.debug(f"Sending zap: {zap_receipt.to_message()}")
ws.send(zap_receipt.to_message()) ws.send(zap_receipt.to_message())
ws.close()
from lnbits.core import bolt11 from lnbits.core import bolt11