From 83b89851a59b617970c8f3dc5bef2ade450cb877 Mon Sep 17 00:00:00 2001 From: Vic <88121568+vicariousdrama@users.noreply.github.com> Date: Wed, 29 May 2024 10:47:10 +0000 Subject: [PATCH] fix: phoenixd wallet description field supports lnurlp (#2514) * Fix for phoenixd and lnurlp nostr usage - Support description, restricted to 128 characters - Support descriptionHash Co-authored-by: Pavol Rusnak Co-authored-by: Vic --- lnbits/wallets/phoenixd.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lnbits/wallets/phoenixd.py b/lnbits/wallets/phoenixd.py index 17e112de5..b1eec9bb1 100644 --- a/lnbits/wallets/phoenixd.py +++ b/lnbits/wallets/phoenixd.py @@ -1,5 +1,6 @@ import asyncio import base64 +import hashlib import json import urllib.parse from typing import AsyncGenerator, Dict, Optional @@ -17,7 +18,6 @@ from .base import ( PaymentStatus, PaymentSuccessStatus, StatusResponse, - UnsupportedError, Wallet, ) @@ -87,17 +87,28 @@ class PhoenixdWallet(Wallet): unhashed_description: Optional[bytes] = None, **kwargs, ) -> InvoiceResponse: - if description_hash or unhashed_description: - raise UnsupportedError("description_hash") try: msats_amount = amount data: Dict = { "amountSat": f"{msats_amount}", - "description": memo, "externalId": "", } + # Either 'description' (string) or 'descriptionHash' must be supplied + # PhoenixD description limited to 128 characters + if description_hash: + data["descriptionHash"] = description_hash.hex() + else: + desc = memo + if desc is None and unhashed_description: + desc = unhashed_description.decode() + desc = desc or "" + if len(desc) > 128: + data["descriptionHash"] = hashlib.sha256(desc.encode()).hexdigest() + else: + data["description"] = desc + r = await self.client.post( "/createinvoice", data=data,