diff --git a/src/commonTest/kotlin/fr/acinq/lightning/payment/OfferManagerTestsCommon.kt b/src/commonTest/kotlin/fr/acinq/lightning/payment/OfferManagerTestsCommon.kt index 437de6889..8d1c55f0e 100644 --- a/src/commonTest/kotlin/fr/acinq/lightning/payment/OfferManagerTestsCommon.kt +++ b/src/commonTest/kotlin/fr/acinq/lightning/payment/OfferManagerTestsCommon.kt @@ -63,6 +63,15 @@ class OfferManagerTestsCommon : LightningTestSuite() { return offer } + private fun decryptPathId(invoice: Bolt12Invoice, trampolineKey: PrivateKey): OfferPaymentMetadata.V1 { + val blindedRoute = invoice.blindedPaths.first().route.route + assertEquals(2, blindedRoute.encryptedPayloads.size) + val (_, nextBlinding) = RouteBlinding.decryptPayload(trampolineKey, blindedRoute.blindingKey, blindedRoute.encryptedPayloads.first()).right!! + val (lastPayload, _) = RouteBlinding.decryptPayload(TestConstants.Alice.nodeParams.nodePrivateKey, nextBlinding, blindedRoute.encryptedPayloads.last()).right!! + val pathId = RouteBlindingEncryptedData.read(lastPayload.toByteArray()).right!!.pathId!! + return OfferPaymentMetadata.fromPathId(TestConstants.Alice.nodeParams.nodeId, pathId) as OfferPaymentMetadata.V1 + } + @Test fun `pay offer through the same trampoline node`() = runSuspendTest { // Alice and Bob use the same trampoline node. @@ -276,17 +285,8 @@ class OfferManagerTestsCommon : LightningTestSuite() { assertEquals(OfferInvoiceReceived(payOffer, payInvoice.invoice), bobOfferManager.eventsFlow.first()) assertEquals(payOffer, payInvoice.payOffer) - val blindedRoute = payInvoice.invoice.blindedPaths.first().route.route - val (firstPayload, secondBlinding) = RouteBlinding.decryptPayload(aliceTrampolineKey, blindedRoute.blindingKey, blindedRoute.encryptedPayloads.first()).right!! - var blinding = secondBlinding - var lastPayload = firstPayload - for (encryptedPayload in blindedRoute.encryptedPayloads.drop(1)) { - val (payload, nextBlinding) = RouteBlinding.decryptPayload(TestConstants.Alice.nodeParams.nodePrivateKey, blinding, encryptedPayload).right!! - blinding = nextBlinding - lastPayload = payload - } - val pathId = RouteBlindingEncryptedData.read(lastPayload.toByteArray()).right!!.pathId!! - val metadata = OfferPaymentMetadata.fromPathId(TestConstants.Alice.nodeParams.nodeId, pathId) as OfferPaymentMetadata.V1 + // The payer note is correctly included in the payment metadata. + val metadata = decryptPathId(payInvoice.invoice, aliceTrampolineKey) assertEquals(payerNote, metadata.payerNote) } @@ -314,18 +314,10 @@ class OfferManagerTestsCommon : LightningTestSuite() { assertEquals(OfferInvoiceReceived(payOffer, payInvoice.invoice), bobOfferManager.eventsFlow.first()) assertEquals(payOffer, payInvoice.payOffer) - val blindedRoute = payInvoice.invoice.blindedPaths.first().route.route - val (firstPayload, secondBlinding) = RouteBlinding.decryptPayload(aliceTrampolineKey, blindedRoute.blindingKey, blindedRoute.encryptedPayloads.first()).right!! - var blinding = secondBlinding - var lastPayload = firstPayload - for (encryptedPayload in blindedRoute.encryptedPayloads.drop(1)) { - val (payload, nextBlinding) = RouteBlinding.decryptPayload(TestConstants.Alice.nodeParams.nodePrivateKey, blinding, encryptedPayload).right!! - blinding = nextBlinding - lastPayload = payload - } - val pathId = RouteBlindingEncryptedData.read(lastPayload.toByteArray()).right!!.pathId!! - val metadata = OfferPaymentMetadata.fromPathId(TestConstants.Alice.nodeParams.nodeId, pathId) as OfferPaymentMetadata.V1 + // The payer note is truncated in the payment metadata. + val metadata = decryptPathId(payInvoice.invoice, aliceTrampolineKey) assertEquals(64, metadata.payerNote!!.length) assertEquals(payerNote.take(63), metadata.payerNote!!.take(63)) } + } \ No newline at end of file