diff --git a/lnbits/core/views/api.py b/lnbits/core/views/api.py index e54e30fac..70bd77946 100644 --- a/lnbits/core/views/api.py +++ b/lnbits/core/views/api.py @@ -184,11 +184,13 @@ async def api_payments_create_invoice(data: CreateInvoiceData, wallet: Wallet): lnurl_response: Union[None, bool, str] = None if data.lnurl_callback: - if "lnurl_balance_check" in data: - assert ( - data.lnurl_balance_check is not None - ), "lnurl_balance_check is required" + if data.lnurl_balance_check is not None: await save_balance_check(wallet.id, data.lnurl_balance_check) + else: + raise HTTPException( + status_code=HTTPStatus.BAD_REQUEST, + detail="lnurl_balance_check not set.", + ) async with httpx.AsyncClient() as client: try: diff --git a/lnbits/extensions/copilot/lnurl.py b/lnbits/extensions/copilot/lnurl.py index 69777c9fb..2fc3e1768 100644 --- a/lnbits/extensions/copilot/lnurl.py +++ b/lnbits/extensions/copilot/lnurl.py @@ -73,11 +73,9 @@ async def lnurl_callback( wallet_id=cp.wallet, amount=int(amount_received / 1000), memo=cp.lnurl_title, - description_hash=hashlib.sha256( - ( - LnurlPayMetadata(json.dumps([["text/plain", str(cp.lnurl_title)]])) - ).encode("utf-8") - ).digest(), + description_hash=( + LnurlPayMetadata(json.dumps([["text/plain", str(cp.lnurl_title)]])) + ).encode("utf-8"), extra={"tag": "copilot", "copilotid": cp.id, "comment": comment}, ) payResponse = {"pr": payment_request, "routes": []} diff --git a/lnbits/extensions/livestream/lnurl.py b/lnbits/extensions/livestream/lnurl.py index 861955de3..72cc1dbbe 100644 --- a/lnbits/extensions/livestream/lnurl.py +++ b/lnbits/extensions/livestream/lnurl.py @@ -90,9 +90,7 @@ async def lnurl_callback( wallet_id=ls.wallet, amount=int(amount_received / 1000), memo=await track.fullname(), - description_hash=hashlib.sha256( - (await track.lnurlpay_metadata()).encode("utf-8") - ).digest(), + description_hash=(await track.lnurlpay_metadata()).encode("utf-8"), extra={"tag": "livestream", "track": track.id, "comment": comment}, ) diff --git a/lnbits/extensions/lnaddress/lnurl.py b/lnbits/extensions/lnaddress/lnurl.py index e6a1ff486..49fd30e02 100644 --- a/lnbits/extensions/lnaddress/lnurl.py +++ b/lnbits/extensions/lnaddress/lnurl.py @@ -70,11 +70,9 @@ async def lnurl_callback(address_id, amount: int = Query(...)): json={ "out": False, "amount": int(amount_received / 1000), - "description_hash": hashlib.sha256( - (await address.lnurlpay_metadata(domain=domain.domain)).encode( - "utf-8" - ) - ).hexdigest(), + "description_hash": ( + await address.lnurlpay_metadata(domain=domain.domain) + ).encode("utf-8"), "extra": {"tag": f"Payment to {address.username}@{domain.domain}"}, }, timeout=40, diff --git a/lnbits/extensions/lnurldevice/lnurl.py b/lnbits/extensions/lnurldevice/lnurl.py index 5e25dadbe..d8bd2e019 100644 --- a/lnbits/extensions/lnurldevice/lnurl.py +++ b/lnbits/extensions/lnurldevice/lnurl.py @@ -205,9 +205,7 @@ async def lnurl_callback( wallet_id=device.wallet, amount=lnurldevicepayment.sats / 1000, memo=device.title, - description_hash=hashlib.sha256( - (await device.lnurlpay_metadata()).encode("utf-8") - ).digest(), + description_hash=(await device.lnurlpay_metadata()).encode("utf-8"), extra={"tag": "PoS"}, ) lnurldevicepayment = await update_lnurldevicepayment( diff --git a/lnbits/extensions/lnurlp/lnurl.py b/lnbits/extensions/lnurlp/lnurl.py index 2ba49e856..55f6807db 100644 --- a/lnbits/extensions/lnurlp/lnurl.py +++ b/lnbits/extensions/lnurlp/lnurl.py @@ -87,9 +87,7 @@ async def api_lnurl_callback(request: Request, link_id): wallet_id=link.wallet, amount=int(amount_received / 1000), memo=link.description, - description_hash=hashlib.sha256( - link.lnurlpay_metadata.encode("utf-8") - ).digest(), + description_hash=link.lnurlpay_metadata.encode("utf-8"), extra={ "tag": "lnurlp", "link": link.id, diff --git a/lnbits/extensions/offlineshop/lnurl.py b/lnbits/extensions/offlineshop/lnurl.py index 0bf779e47..5a2a0bcd2 100644 --- a/lnbits/extensions/offlineshop/lnurl.py +++ b/lnbits/extensions/offlineshop/lnurl.py @@ -73,9 +73,7 @@ async def lnurl_callback(request: Request, item_id: int): wallet_id=shop.wallet, amount=int(amount_received / 1000), memo=item.name, - description_hash=hashlib.sha256( - (await item.lnurlpay_metadata()).encode("utf-8") - ).digest(), + description_hash=(await item.lnurlpay_metadata()).encode("utf-8"), extra={"tag": "offlineshop", "item": item.id}, ) except Exception as exc: diff --git a/lnbits/extensions/satsdice/lnurl.py b/lnbits/extensions/satsdice/lnurl.py index 03d20502a..73c5e5540 100644 --- a/lnbits/extensions/satsdice/lnurl.py +++ b/lnbits/extensions/satsdice/lnurl.py @@ -77,9 +77,7 @@ async def api_lnurlp_callback( wallet_id=link.wallet, amount=int(amount_received / 1000), memo="Satsdice bet", - description_hash=hashlib.sha256( - link.lnurlpay_metadata.encode("utf-8") - ).digest(), + description_hash=link.lnurlpay_metadata.encode("utf-8"), extra={"tag": "satsdice", "link": link.id, "comment": "comment"}, ) diff --git a/lnbits/wallets/cliche.py b/lnbits/wallets/cliche.py index bc5c566ce..7c0347176 100644 --- a/lnbits/wallets/cliche.py +++ b/lnbits/wallets/cliche.py @@ -1,4 +1,5 @@ import asyncio +import hashlib import json from os import getenv from typing import AsyncGenerator, Dict, Optional @@ -47,9 +48,10 @@ class ClicheWallet(Wallet): description_hash: Optional[bytes] = None, ) -> InvoiceResponse: if description_hash: + description_hash_hashed = hashlib.sha256(description_hash).hexdigest() ws = create_connection(self.endpoint) ws.send( - f"create-invoice --msatoshi {amount*1000} --description_hash {description_hash.hex()}" + f"create-invoice --msatoshi {amount*1000} --description_hash {description_hash_hashed}" ) r = ws.recv() else: diff --git a/lnbits/wallets/clightning.py b/lnbits/wallets/clightning.py index fc79b3e32..5ea47339f 100644 --- a/lnbits/wallets/clightning.py +++ b/lnbits/wallets/clightning.py @@ -4,6 +4,7 @@ except ImportError: # pragma: nocover LightningRpc = None import asyncio +import hashlib import random import time from functools import partial, wraps @@ -94,7 +95,7 @@ class CLightningWallet(Wallet): if not self.supports_description_hash: raise Unsupported("description_hash") - params = [msat, label, description_hash.hex()] + params = [msat, label, hashlib.sha256(description_hash).hexdigest()] r = self.ln.call("invoicewithdescriptionhash", params) return InvoiceResponse(True, label, r["bolt11"], "") else: diff --git a/lnbits/wallets/eclair.py b/lnbits/wallets/eclair.py index ab99c699d..0a4f1f3e4 100644 --- a/lnbits/wallets/eclair.py +++ b/lnbits/wallets/eclair.py @@ -1,5 +1,6 @@ import asyncio import base64 +import hashlib import json import urllib.parse from os import getenv @@ -72,7 +73,7 @@ class EclairWallet(Wallet): data: Dict = {"amountMsat": amount * 1000} if description_hash: - data["description_hash"] = description_hash.hex() + data["description_hash"] = hashlib.sha256(description_hash).hexdigest() else: data["description"] = memo or "" diff --git a/lnbits/wallets/fake.py b/lnbits/wallets/fake.py index 3126ee46a..80a3d8c65 100644 --- a/lnbits/wallets/fake.py +++ b/lnbits/wallets/fake.py @@ -61,7 +61,7 @@ class FakeWallet(Wallet): data["timestamp"] = datetime.now().timestamp() if description_hash: data["tags_set"] = ["h"] - data["description_hash"] = description_hash.hex() + data["description_hash"] = description_hash.decode("utf-8") else: data["tags_set"] = ["d"] data["memo"] = memo diff --git a/lnbits/wallets/lnbits.py b/lnbits/wallets/lnbits.py index d2ddb7ffc..677b518aa 100644 --- a/lnbits/wallets/lnbits.py +++ b/lnbits/wallets/lnbits.py @@ -1,4 +1,5 @@ import asyncio +import hashlib import json from os import getenv from typing import AsyncGenerator, Dict, Optional @@ -59,7 +60,7 @@ class LNbitsWallet(Wallet): ) -> InvoiceResponse: data: Dict = {"out": False, "amount": amount} if description_hash: - data["description_hash"] = description_hash.hex() + data["description_hash"] = hashlib.sha256(description_hash).hexdigest() else: data["memo"] = memo or "" diff --git a/lnbits/wallets/lndgrpc.py b/lnbits/wallets/lndgrpc.py index 44fee78c3..7b23414ed 100644 --- a/lnbits/wallets/lndgrpc.py +++ b/lnbits/wallets/lndgrpc.py @@ -132,7 +132,9 @@ class LndWallet(Wallet): params: Dict = {"value": amount, "expiry": 600, "private": True} if description_hash: - params["description_hash"] = description_hash # as bytes directly + params["description_hash"] = base64.b64encode( + hashlib.sha256(description_hash).digest() + ) # as bytes directly else: params["memo"] = memo or "" diff --git a/lnbits/wallets/lndrest.py b/lnbits/wallets/lndrest.py index 575db64dd..220b5baad 100644 --- a/lnbits/wallets/lndrest.py +++ b/lnbits/wallets/lndrest.py @@ -1,5 +1,6 @@ import asyncio import base64 +import hashlib import json from os import getenv from pydoc import describe @@ -75,9 +76,9 @@ class LndRestWallet(Wallet): ) -> InvoiceResponse: data: Dict = {"value": amount, "private": True} if description_hash: - data["description_hash"] = base64.b64encode(description_hash).decode( - "ascii" - ) + data["description_hash"] = base64.b64encode( + hashlib.sha256(description_hash).digest() + ).decode("ascii") else: data["memo"] = memo or "" diff --git a/lnbits/wallets/lnpay.py b/lnbits/wallets/lnpay.py index 18b4f8bbe..7ba45a228 100644 --- a/lnbits/wallets/lnpay.py +++ b/lnbits/wallets/lnpay.py @@ -1,4 +1,5 @@ import asyncio +import hashlib import json from http import HTTPStatus from os import getenv @@ -54,7 +55,7 @@ class LNPayWallet(Wallet): ) -> InvoiceResponse: data: Dict = {"num_satoshis": f"{amount}"} if description_hash: - data["description_hash"] = description_hash.hex() + data["description_hash"] = hashlib.sha256(description_hash).hexdigest() else: data["memo"] = memo or "" diff --git a/lnbits/wallets/lntxbot.py b/lnbits/wallets/lntxbot.py index 3c758e6c1..9b0954e9e 100644 --- a/lnbits/wallets/lntxbot.py +++ b/lnbits/wallets/lntxbot.py @@ -1,4 +1,5 @@ import asyncio +import hashlib import json from os import getenv from typing import AsyncGenerator, Dict, Optional @@ -54,7 +55,7 @@ class LntxbotWallet(Wallet): ) -> InvoiceResponse: data: Dict = {"amt": str(amount)} if description_hash: - data["description_hash"] = description_hash.hex() + data["description_hash"] = hashlib.sha256(description_hash).hexdigest() else: data["memo"] = memo or "" diff --git a/lnbits/wallets/spark.py b/lnbits/wallets/spark.py index 142e388d2..55758aab0 100644 --- a/lnbits/wallets/spark.py +++ b/lnbits/wallets/spark.py @@ -1,4 +1,5 @@ import asyncio +import hashlib import json import random from os import getenv @@ -101,7 +102,7 @@ class SparkWallet(Wallet): r = await self.invoicewithdescriptionhash( msatoshi=amount * 1000, label=label, - description_hash=description_hash.hex(), + description_hash=hashlib.sha256(description_hash).hexdigest(), ) else: r = await self.invoice(