+/// Information which is provided, encrypted, to the payment recipient when sending HTLCs.
+///
+/// This should generally be constructed with data communicated to us from the recipient (via a
+/// BOLT11 or BOLT12 invoice).
+#[derive(Clone)]
+pub struct RecipientOnionFields {
+ /// The [`PaymentSecret`] is an arbitrary 32 bytes provided by the recipient for us to repeat
+ /// in the onion. It is unrelated to `payment_hash` (or [`PaymentPreimage`]) and exists to
+ /// authenticate the sender to the recipient and prevent payment-probing (deanonymization)
+ /// attacks.
+ ///
+ /// If you do not have one, the [`Route`] you pay over must not contain multiple paths as
+ /// multi-path payments require a recipient-provided secret.
+ ///
+ /// Note that for spontaneous payments most lightning nodes do not currently support MPP
+ /// receives, thus you should generally never be providing a secret here for spontaneous
+ /// payments.
+ pub payment_secret: Option<PaymentSecret>,
+}
+
+impl RecipientOnionFields {
+ /// Creates a [`RecipientOnionFields`] from only a [`PaymentSecret`]. This is the most common
+ /// set of onion fields for today's BOLT11 invoices - most nodes require a [`PaymentSecret`]
+ /// but do not require or provide any further data.
+ pub fn secret_only(payment_secret: PaymentSecret) -> Self {
+ Self { payment_secret: Some(payment_secret) }
+ }
+
+ /// Creates a new [`RecipientOnionFields`] with no fields. This generally does not create
+ /// payable HTLCs except for spontaneous payments, i.e. this should generally only be used for
+ /// calls to [`ChannelManager::send_spontaneous_payment`].
+ ///
+ /// [`ChannelManager::send_spontaneous_payment`]: super::channelmanager::ChannelManager::send_spontaneous_payment
+ pub fn spontaneous_empty() -> Self {
+ Self { payment_secret: None }
+ }
+}
+