@@ -17,7 +17,7 @@ import fr.acinq.lightning.message.OnionMessages
1717import fr.acinq.lightning.message.OnionMessages.Destination
1818import fr.acinq.lightning.message.OnionMessages.IntermediateNode
1919import fr.acinq.lightning.message.OnionMessages.buildMessage
20- import fr.acinq.lightning.utils.currentTimestampMillis
20+ import fr.acinq.lightning.utils.currentTimestampSeconds
2121import fr.acinq.lightning.utils.toByteVector
2222import fr.acinq.lightning.wire.*
2323import kotlinx.coroutines.flow.MutableSharedFlow
@@ -153,14 +153,19 @@ class OfferManager(val nodeParams: NodeParams, val walletParams: WalletParams, v
153153 else -> {
154154 val amount = request.requestedAmount
155155 val preimage = randomBytes32()
156- val truncatedPayerNote = (request.payerNote ? : request.offer.description)?.let {
157- if (it.length <= 64 ) {
158- it
159- } else {
160- it.take(63 ) + " …"
161- }
162- }
163- val metadata = OfferPaymentMetadata .V1 (request.offer.offerId, amount, preimage, request.payerId, truncatedPayerNote, request.quantity, currentTimestampMillis()).toPathId(nodeParams.nodePrivateKey)
156+ val (truncatedPayerNote, truncatedDescription) = OfferPaymentMetadata .truncateNotes(request.payerNote, request.offer.description)
157+ val expirySeconds = request.offer.expirySeconds ? : nodeParams.bolt12InvoiceExpiry.inWholeSeconds
158+ val metadata = OfferPaymentMetadata .V2 (
159+ offerId = request.offer.offerId,
160+ amount = amount,
161+ preimage = preimage,
162+ createdAtSeconds = currentTimestampSeconds(),
163+ relativeExpirySeconds = expirySeconds,
164+ description = truncatedDescription,
165+ payerKey = request.payerId,
166+ payerNote = truncatedPayerNote,
167+ quantity = request.quantity_opt
168+ ).toPathId(nodeParams.nodePrivateKey)
164169 val recipientPayload = RouteBlindingEncryptedData (TlvStream (RouteBlindingEncryptedDataTlv .PathId (metadata))).write().toByteVector()
165170 val cltvExpiryDelta = remoteChannelUpdates.maxOfOrNull { it.cltvExpiryDelta } ? : walletParams.invoiceDefaultRoutingFees.cltvExpiryDelta
166171 val paymentInfo = OfferTypes .PaymentInfo (
@@ -191,7 +196,7 @@ class OfferManager(val nodeParams: NodeParams, val walletParams: WalletParams, v
191196 ).write().toByteVector()
192197 val blindedRoute = RouteBlinding .create(randomKey(), listOf (remoteNodeId, nodeParams.nodeId), listOf (remoteNodePayload, recipientPayload)).route
193198 val path = Bolt12Invoice .Companion .PaymentBlindedContactInfo (OfferTypes .ContactInfo .BlindedPath (blindedRoute), paymentInfo)
194- val invoice = Bolt12Invoice (request, preimage, blindedPrivateKey, nodeParams.bolt12InvoiceExpiry.inWholeSeconds , nodeParams.features.bolt12Features(), listOf (path))
199+ val invoice = Bolt12Invoice (request, preimage, blindedPrivateKey, expirySeconds , nodeParams.features.bolt12Features(), listOf (path))
195200 val destination = Destination .BlindedPath (replyPath)
196201 when (val invoiceMessage = buildMessage(randomKey(), randomKey(), intermediateNodes(destination), destination, TlvStream (OnionMessagePayloadTlv .Invoice (invoice.records)))) {
197202 is Left -> {
@@ -233,7 +238,7 @@ class OfferManager(val nodeParams: NodeParams, val walletParams: WalletParams, v
233238 pathId != null && pathId.size() != 32 -> false
234239 else -> {
235240 val expected = deterministicOffer(nodeParams.chainHash, nodeParams.nodePrivateKey, walletParams.trampolineNode.id, offer.amount, offer.description, pathId?.let { ByteVector32 (it) })
236- expected == Pair (offer, blindedPrivateKey)
241+ expected == OfferTypes . OfferAndKey (offer, blindedPrivateKey)
237242 }
238243 }
239244
@@ -249,7 +254,7 @@ class OfferManager(val nodeParams: NodeParams, val walletParams: WalletParams, v
249254 amount : MilliSatoshi ? ,
250255 description : String? ,
251256 pathId : ByteVector32 ? ,
252- ): Pair < OfferTypes .Offer , PrivateKey > {
257+ ): OfferTypes .OfferAndKey {
253258 // We generate a deterministic session key based on:
254259 // - a custom tag indicating that this is used in the Bolt 12 context
255260 // - the offer parameters (amount, description and pathId)
0 commit comments