Check lnurl pay invoice description hash (#4931)

This commit is contained in:
benthecarman 2022-12-28 09:19:48 -06:00 committed by GitHub
parent 48a2a8f5e6
commit ffee1a804e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View File

@ -30,6 +30,7 @@ class LnURLClientTest extends BitcoinSAsyncTest {
val amt = pay.minSendable.toLnCurrencyUnit val amt = pay.minSendable.toLnCurrencyUnit
client.getInvoice(pay, amt).map { inv => client.getInvoice(pay, amt).map { inv =>
assert(inv.amount.contains(amt)) assert(inv.amount.contains(amt))
assert(inv.lnTags.descriptionHash.exists(_.hash == pay.metadataHash))
} }
case _: LnURLWithdrawResponse => case _: LnURLWithdrawResponse =>
fail("Incorrect response parsed") fail("Incorrect response parsed")

View File

@ -6,6 +6,8 @@ import play.api.libs.json._
import org.bitcoins.commons.serializers.JsonReaders._ import org.bitcoins.commons.serializers.JsonReaders._
import org.bitcoins.commons.serializers.JsonWriters._ import org.bitcoins.commons.serializers.JsonWriters._
import org.bitcoins.core.protocol.ln.LnInvoice import org.bitcoins.core.protocol.ln.LnInvoice
import org.bitcoins.crypto._
import scodec.bits.ByteVector
import java.net._ import java.net._
@ -48,6 +50,9 @@ object LnURLJsonModels {
extends LnURLResponse { extends LnURLResponse {
override val tag: LnURLTag = PayRequest override val tag: LnURLTag = PayRequest
lazy val metadataJs: JsValue = Json.parse(metadata) lazy val metadataJs: JsValue = Json.parse(metadata)
lazy val metadataHash: Sha256Digest =
CryptoUtil.sha256(ByteVector(metadata.getBytes))
} }
implicit val LnURLPayResponseReads: Reads[LnURLPayResponse] = implicit val LnURLPayResponseReads: Reads[LnURLPayResponse] =