Skip to content

Commit cfc69d3

Browse files
committed
Validate compact offer
1 parent 3f09590 commit cfc69d3

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

modules/core/src/commonMain/kotlin/fr/acinq/lightning/payment/OfferManager.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ class OfferManager(val nodeParams: NodeParams, val walletParams: WalletParams, v
8181
return OnionMessages.decryptMessage(nodeParams.nodePrivateKey, msg, logger)?.let { decrypted ->
8282
val invoiceRequestTlvs = decrypted.content.records.get<OnionMessagePayloadTlv.InvoiceRequest>()?.tlvs
8383
when {
84-
decrypted.useCompactRoute -> {
85-
logger.warning { "unhandled compact route" }
86-
null
87-
}
8884
invoiceRequestTlvs != null -> when (val invoiceRequest = OfferTypes.InvoiceRequest.validate(invoiceRequestTlvs)) {
8985
is Left -> {
9086
logger.warning { "received invalid invoice_request: ${invoiceRequest.value}" }
@@ -240,6 +236,9 @@ class OfferManager(val nodeParams: NodeParams, val walletParams: WalletParams, v
240236
/** This function verifies that the offer provided was generated by us. */
241237
private fun isOurOffer(offer: OfferTypes.Offer, pathId: ByteVector?, blindedPrivateKey: PrivateKey): Boolean = when {
242238
pathId != null && pathId.size() != 32 -> false
239+
// Compact offers are randomly generated, but they don't store the nonce in the path_id to save space.
240+
// It is instead the wallet's responsibility to store the corresponding blinded public key(s).
241+
pathId == null && nodeParams.compactOfferKeys.value.contains(blindedPrivateKey.publicKey()) -> offer.isMinimal()
243242
else -> {
244243
val expected = deterministicOffer(nodeParams.chainHash, nodeParams.nodePrivateKey, walletParams.trampolineNode.id, offer.amount, offer.description, pathId?.let { ByteVector32(it) })
245244
expected == OfferTypes.OfferAndKey(offer, blindedPrivateKey)

modules/core/src/commonMain/kotlin/fr/acinq/lightning/wire/OfferTypes.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,8 @@ object OfferTypes {
758758

759759
val offerId: ByteVector32 = rootHash(records)
760760

761+
fun isMinimal(): Boolean = records.records.filterNot { it is OfferChains || it is OfferPaths || it is OfferIssuerId}.isEmpty() && records.unknown.isEmpty()
762+
761763
companion object {
762764
val hrp = "lno"
763765

0 commit comments

Comments
 (0)