feat: preimages for incoming payments, fundingsource saves preimage on create_invoice (#3085)

Co-authored-by: Vlad Stan <stan.v.vlad@gmail.com>
This commit is contained in:
dni ⚡
2025-04-30 11:03:19 +02:00
committed by GitHub
co-authored by Vlad Stan
parent f8b3644029
commit c4d0540e76
20 changed files with 183 additions and 106 deletions
+11 -6
View File
@@ -9,7 +9,7 @@ from loguru import logger
from lnbits.nodes.lndrest import LndRestNode
from lnbits.settings import settings
from lnbits.utils.crypto import AESCipher
from lnbits.utils.crypto import AESCipher, random_secret_and_hash
from .base import (
InvoiceResponse,
@@ -110,24 +110,28 @@ class LndRestWallet(Wallet):
unhashed_description: Optional[bytes] = None,
**kwargs,
) -> InvoiceResponse:
data: Dict = {
_data: Dict = {
"value": amount,
"private": settings.lnd_rest_route_hints,
"memo": memo or "",
}
if kwargs.get("expiry"):
data["expiry"] = kwargs["expiry"]
_data["expiry"] = kwargs["expiry"]
if description_hash:
data["description_hash"] = base64.b64encode(description_hash).decode(
_data["description_hash"] = base64.b64encode(description_hash).decode(
"ascii"
)
elif unhashed_description:
data["description_hash"] = base64.b64encode(
_data["description_hash"] = base64.b64encode(
hashlib.sha256(unhashed_description).digest()
).decode("ascii")
preimage, _payment_hash = random_secret_and_hash()
_data["r_hash"] = base64.b64encode(bytes.fromhex(_payment_hash)).decode()
_data["r_preimage"] = base64.b64encode(bytes.fromhex(preimage)).decode()
try:
r = await self.client.post(url="/v1/invoices", json=data)
r = await self.client.post(url="/v1/invoices", json=_data)
r.raise_for_status()
data = r.json()
@@ -156,6 +160,7 @@ class LndRestWallet(Wallet):
ok=True,
checking_id=checking_id,
payment_request=payment_request,
preimage=preimage,
)
except json.JSONDecodeError: