+pub(super) fn construct_payment_paths(
+ blinded_payinfos: Option<Vec<BlindedPayInfo>>, blinded_paths: Option<Vec<BlindedPath>>
+) -> Result<Vec<(BlindedPayInfo, BlindedPath)>, Bolt12SemanticError> {
+ match (blinded_payinfos, blinded_paths) {
+ (_, None) => Err(Bolt12SemanticError::MissingPaths),
+ (None, _) => Err(Bolt12SemanticError::InvalidPayInfo),
+ (_, Some(paths)) if paths.is_empty() => Err(Bolt12SemanticError::MissingPaths),
+ (Some(blindedpay), Some(paths)) if paths.len() != blindedpay.len() => {
+ Err(Bolt12SemanticError::InvalidPayInfo)
+ },
+ (Some(blindedpay), Some(paths)) => {
+ Ok(blindedpay.into_iter().zip(paths.into_iter()).collect::<Vec<_>>())
+ },
+ }
+}
+
+pub(super) fn check_invoice_signing_pubkey(
+ invoice_signing_pubkey: &PublicKey, offer_tlv_stream: &OfferTlvStream
+) -> Result<(), Bolt12SemanticError> {
+ match (&offer_tlv_stream.node_id, &offer_tlv_stream.paths) {
+ (Some(expected_signing_pubkey), _) => {
+ if invoice_signing_pubkey != expected_signing_pubkey {
+ return Err(Bolt12SemanticError::InvalidSigningPubkey);
+ }
+ },
+ (None, Some(paths)) => {
+ if !paths
+ .iter()
+ .filter_map(|path| path.blinded_hops.last())
+ .any(|last_hop| invoice_signing_pubkey == &last_hop.blinded_node_id)
+ {
+ return Err(Bolt12SemanticError::InvalidSigningPubkey);
+ }
+ },
+ _ => {},
+ }
+ Ok(())
+}
+