Skip to content

Commit eafc91f

Browse files
committed
Ensure that isOurOffer works for the default offer
The default offer also uses an empty `path_id` in the blinded path (because it doesn't need to store any randomness), so an empty `path_id` doesn't necessarily means that we're using a compact offer.
1 parent a6fce18 commit eafc91f

File tree

1 file changed

+6
-6
lines changed
  • modules/core/src/commonMain/kotlin/fr/acinq/lightning/payment

1 file changed

+6
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,11 @@ class OfferManager(val nodeParams: NodeParams, val walletParams: WalletParams, v
235235

236236
/** This function verifies that the offer provided was generated by us. */
237237
private fun isOurOffer(offer: OfferTypes.Offer, pathId: ByteVector?, blindedPrivateKey: PrivateKey): Boolean = when {
238-
pathId == null -> { // Compact offer
239-
nodeParams.compactOfferKeys.value.contains(blindedPrivateKey.publicKey())
240-
}
241-
pathId.size() != 32 -> false
242-
else -> { // Deterministic offer
238+
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()) -> true
242+
else -> {
243243
val expected = deterministicOffer(nodeParams.chainHash, nodeParams.nodePrivateKey, walletParams.trampolineNode.id, offer.amount, offer.description, pathId?.let { ByteVector32(it) })
244244
expected == OfferTypes.OfferAndKey(offer, blindedPrivateKey)
245245
}
@@ -290,7 +290,7 @@ class OfferManager(val nodeParams: NodeParams, val walletParams: WalletParams, v
290290
val tweak = "bolt 12 compact offer".encodeToByteArray().byteVector() +
291291
Crypto.sha256("offer nonce".encodeToByteArray().byteVector() + nonce)
292292
val sessionKey = PrivateKey(Crypto.sha256(tweak + trampolineNodeId.value + nodePrivateKey.value).byteVector32())
293-
return OfferTypes.Offer.createBlindedOffer(chainHash, nodePrivateKey, trampolineNodeId, null, null, Features.empty, sessionKey, null, true)
293+
return OfferTypes.Offer.createBlindedOffer(chainHash, nodePrivateKey, trampolineNodeId, null, null, Features.empty, sessionKey, null, allowCompactFormat = true)
294294
}
295295
}
296296
}

0 commit comments

Comments
 (0)