use crate::sign::EntropySource;
use crate::io;
use crate::blinded_path::BlindedPath;
-use crate::ln::PaymentHash;
+use crate::ln::types::PaymentHash;
use crate::ln::channelmanager::PaymentId;
use crate::ln::features::InvoiceRequestFeatures;
use crate::ln::inbound_payment::{ExpandedKey, IV_LEN, Nonce};
<$builder>::for_offer(&$contents, payment_paths, created_at, payment_hash, signing_pubkey)
}
+
+ #[cfg(test)]
+ #[allow(dead_code)]
+ pub(super) fn respond_with_no_std_using_signing_pubkey(
+ &$self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
+ created_at: core::time::Duration, signing_pubkey: PublicKey
+ ) -> Result<$builder, Bolt12SemanticError> {
+ debug_assert!($contents.contents.inner.offer.signing_pubkey().is_none());
+
+ if $contents.invoice_request_features().requires_unknown_bits() {
+ return Err(Bolt12SemanticError::UnknownRequiredFeatures);
+ }
+
+ <$builder>::for_offer(&$contents, payment_paths, created_at, payment_hash, signing_pubkey)
+ }
} }
macro_rules! invoice_request_verify_method { ($self: ident, $self_type: ty) => {
let InvoiceRequestContents {
payer_id,
inner: InvoiceRequestContentsWithoutPayerId {
- payer: _, offer: _, chain: _, amount_msats, features, quantity, payer_note
+ payer: _, offer: _, chain: _, amount_msats: _, features: _, quantity, payer_note
},
} = &self.inner.contents;
InvoiceRequestFields {
payer_id: *payer_id,
- amount_msats: *amount_msats,
- features: features.clone(),
quantity: *quantity,
payer_note_truncated: payer_note.clone()
.map(|mut s| { s.truncate(PAYER_NOTE_LIMIT); UntrustedString(s) }),
quantity: self.quantity,
payer_id: None,
payer_note: self.payer_note.as_ref(),
+ paths: None,
};
(payer, offer, invoice_request)
/// [`Refund::payer_id`]: crate::offers::refund::Refund::payer_id
pub(super) const INVOICE_REQUEST_PAYER_ID_TYPE: u64 = 88;
+// This TLV stream is used for both InvoiceRequest and Refund, but not all TLV records are valid for
+// InvoiceRequest as noted below.
tlv_stream!(InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef, INVOICE_REQUEST_TYPES, {
(80, chain: ChainHash),
(82, amount: (u64, HighZeroBytesDroppedBigSize)),
(86, quantity: (u64, HighZeroBytesDroppedBigSize)),
(INVOICE_REQUEST_PAYER_ID_TYPE, payer_id: PublicKey),
(89, payer_note: (String, WithoutLength)),
+ // Only used for Refund since the onion message of an InvoiceRequest has a reply path.
+ (90, paths: (Vec<BlindedPath>, WithoutLength)),
});
type FullInvoiceRequestTlvStream =
let (
PayerTlvStream { metadata },
offer_tlv_stream,
- InvoiceRequestTlvStream { chain, amount, features, quantity, payer_id, payer_note },
+ InvoiceRequestTlvStream {
+ chain, amount, features, quantity, payer_id, payer_note, paths,
+ },
) = tlv_stream;
let payer = match metadata {
Some(payer_id) => payer_id,
};
+ if paths.is_some() {
+ return Err(Bolt12SemanticError::UnexpectedPaths);
+ }
+
Ok(InvoiceRequestContents {
inner: InvoiceRequestContentsWithoutPayerId {
payer, offer, chain, amount_msats: amount, features, quantity, payer_note,
/// A possibly transient pubkey used to sign the invoice request.
pub payer_id: PublicKey,
- /// The amount to pay in msats (i.e., the minimum lightning-payable unit for [`chain`]), which
- /// must be greater than or equal to [`Offer::amount`], converted if necessary.
- ///
- /// [`chain`]: InvoiceRequest::chain
- pub amount_msats: Option<u64>,
-
- /// Features pertaining to requesting an invoice.
- pub features: InvoiceRequestFeatures,
-
/// The quantity of the offer's item conforming to [`Offer::is_valid_quantity`].
pub quantity: Option<u64>,
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
write_tlv_fields!(writer, {
(0, self.payer_id, required),
- (2, self.amount_msats.map(|v| HighZeroBytesDroppedBigSize(v)), option),
- (4, WithoutLength(&self.features), required),
- (6, self.quantity.map(|v| HighZeroBytesDroppedBigSize(v)), option),
- (8, self.payer_note_truncated.as_ref().map(|s| WithoutLength(&s.0)), option),
+ (2, self.quantity.map(|v| HighZeroBytesDroppedBigSize(v)), option),
+ (4, self.payer_note_truncated.as_ref().map(|s| WithoutLength(&s.0)), option),
});
Ok(())
}
fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
_init_and_read_len_prefixed_tlv_fields!(reader, {
(0, payer_id, required),
- (2, amount_msats, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
- (4, features, (option, encoding: (InvoiceRequestFeatures, WithoutLength))),
- (6, quantity, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
- (8, payer_note_truncated, (option, encoding: (String, WithoutLength))),
+ (2, quantity, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
+ (4, payer_note_truncated, (option, encoding: (String, WithoutLength))),
});
- let features = features.unwrap_or(InvoiceRequestFeatures::empty());
Ok(InvoiceRequestFields {
- payer_id: payer_id.0.unwrap(), amount_msats, features, quantity,
+ payer_id: payer_id.0.unwrap(),
+ quantity,
payer_note_truncated: payer_note_truncated.map(|s| UntrustedString(s)),
})
}
quantity: None,
payer_id: Some(&payer_pubkey()),
payer_note: None,
+ paths: None,
},
SignatureTlvStreamRef { signature: Some(&invoice_request.signature()) },
),
let invoice_request = offer.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
.chain(Network::Testnet).unwrap()
- .amount_msats(1001).unwrap()
.quantity(1).unwrap()
.payer_note("0".repeat(PAYER_NOTE_LIMIT * 2))
.build().unwrap()
fields,
InvoiceRequestFields {
payer_id: payer_pubkey(),
- amount_msats: Some(1001),
- features: InvoiceRequestFeatures::empty(),
quantity: Some(1),
payer_note_truncated: Some(UntrustedString("0".repeat(PAYER_NOTE_LIMIT))),
}