Qualify the BOLT 12 semantic error
authorJeffrey Czyz <jkczyz@gmail.com>
Thu, 13 Jul 2023 21:28:55 +0000 (16:28 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Fri, 14 Jul 2023 20:04:43 +0000 (15:04 -0500)
To avoid a naming conflict in bindings with BOLT 11 semantic error,
qualify the BOLT 12 semantic error type.

fuzz/src/invoice_request_deser.rs
fuzz/src/offer_deser.rs
fuzz/src/refund_deser.rs
lightning/src/offers/invoice.rs
lightning/src/offers/invoice_error.rs
lightning/src/offers/invoice_request.rs
lightning/src/offers/offer.rs
lightning/src/offers/parse.rs
lightning/src/offers/refund.rs

index dbf62fac7dfe72700880303169719265e1831480..ca9d06ab1f8612d3f6c5bf212c191d27c0cb9cc6 100644 (file)
@@ -16,7 +16,7 @@ use lightning::ln::PaymentHash;
 use lightning::ln::features::BlindedHopFeatures;
 use lightning::offers::invoice::{BlindedPayInfo, UnsignedBolt12Invoice};
 use lightning::offers::invoice_request::InvoiceRequest;
-use lightning::offers::parse::SemanticError;
+use lightning::offers::parse::Bolt12SemanticError;
 use lightning::util::ser::Writeable;
 
 #[inline]
@@ -71,7 +71,7 @@ fn privkey(byte: u8) -> SecretKey {
 
 fn build_response<'a, T: secp256k1::Signing + secp256k1::Verification>(
        invoice_request: &'a InvoiceRequest, secp_ctx: &Secp256k1<T>
-) -> Result<UnsignedBolt12Invoice<'a>, SemanticError> {
+) -> Result<UnsignedBolt12Invoice<'a>, Bolt12SemanticError> {
        let entropy_source = Randomness {};
        let paths = vec![
                BlindedPath::new_for_message(&[pubkey(43), pubkey(44), pubkey(42)], &entropy_source, secp_ctx).unwrap(),
index 213742d8c085b86aba02f0188df4b0d6e08240e3..53f67a3380db07d322f8b1fe1c72a75301e34cc0 100644 (file)
@@ -12,7 +12,7 @@ use crate::utils::test_logger;
 use core::convert::{Infallible, TryFrom};
 use lightning::offers::invoice_request::UnsignedInvoiceRequest;
 use lightning::offers::offer::{Amount, Offer, Quantity};
-use lightning::offers::parse::SemanticError;
+use lightning::offers::parse::Bolt12SemanticError;
 use lightning::util::ser::Writeable;
 
 #[inline]
@@ -41,13 +41,13 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
 
 fn build_response<'a>(
        offer: &'a Offer, pubkey: PublicKey
-) -> Result<UnsignedInvoiceRequest<'a>, SemanticError> {
+) -> Result<UnsignedInvoiceRequest<'a>, Bolt12SemanticError> {
        let mut builder = offer.request_invoice(vec![42; 64], pubkey)?;
 
        builder = match offer.amount() {
                None => builder.amount_msats(1000).unwrap(),
                Some(Amount::Bitcoin { amount_msats }) => builder.amount_msats(amount_msats + 1)?,
-               Some(Amount::Currency { .. }) => return Err(SemanticError::UnsupportedCurrency),
+               Some(Amount::Currency { .. }) => return Err(Bolt12SemanticError::UnsupportedCurrency),
        };
 
        builder = match offer.supported_quantity() {
index b1c729d9e5c0a99d05032d9ed99469b83294d523..81b614d602b269259a9ce67fadbc86307c583334 100644 (file)
@@ -15,7 +15,7 @@ use lightning::sign::EntropySource;
 use lightning::ln::PaymentHash;
 use lightning::ln::features::BlindedHopFeatures;
 use lightning::offers::invoice::{BlindedPayInfo, UnsignedBolt12Invoice};
-use lightning::offers::parse::SemanticError;
+use lightning::offers::parse::Bolt12SemanticError;
 use lightning::offers::refund::Refund;
 use lightning::util::ser::Writeable;
 
@@ -60,7 +60,7 @@ fn privkey(byte: u8) -> SecretKey {
 
 fn build_response<'a, T: secp256k1::Signing + secp256k1::Verification>(
        refund: &'a Refund, signing_pubkey: PublicKey, secp_ctx: &Secp256k1<T>
-) -> Result<UnsignedBolt12Invoice<'a>, SemanticError> {
+) -> Result<UnsignedBolt12Invoice<'a>, Bolt12SemanticError> {
        let entropy_source = Randomness {};
        let paths = vec![
                BlindedPath::new_for_message(&[pubkey(43), pubkey(44), pubkey(42)], &entropy_source, secp_ctx).unwrap(),
index 03bb9553625cfe4d292812c65b163c8e59812700..279e31dd66a78cf86691ca9c9e2d7f83653a189b 100644 (file)
@@ -112,7 +112,7 @@ use crate::ln::msgs::DecodeError;
 use crate::offers::invoice_request::{INVOICE_REQUEST_PAYER_ID_TYPE, INVOICE_REQUEST_TYPES, IV_BYTES as INVOICE_REQUEST_IV_BYTES, InvoiceRequest, InvoiceRequestContents, InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef};
 use crate::offers::merkle::{SignError, SignatureTlvStream, SignatureTlvStreamRef, TlvStream, WithoutSignatures, self};
 use crate::offers::offer::{Amount, OFFER_TYPES, OfferTlvStream, OfferTlvStreamRef};
-use crate::offers::parse::{Bolt12ParseError, ParsedMessage, SemanticError};
+use crate::offers::parse::{Bolt12ParseError, Bolt12SemanticError, ParsedMessage};
 use crate::offers::payer::{PAYER_METADATA_TYPE, PayerTlvStream, PayerTlvStreamRef};
 use crate::offers::refund::{IV_BYTES as REFUND_IV_BYTES, Refund, RefundContents};
 use crate::offers::signer;
@@ -168,7 +168,7 @@ impl<'a> InvoiceBuilder<'a, ExplicitSigningPubkey> {
        pub(super) fn for_offer(
                invoice_request: &'a InvoiceRequest, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>,
                created_at: Duration, payment_hash: PaymentHash
-       ) -> Result<Self, SemanticError> {
+       ) -> Result<Self, Bolt12SemanticError> {
                let amount_msats = Self::check_amount_msats(invoice_request)?;
                let signing_pubkey = invoice_request.contents.inner.offer.signing_pubkey();
                let contents = InvoiceContents::ForOffer {
@@ -184,7 +184,7 @@ impl<'a> InvoiceBuilder<'a, ExplicitSigningPubkey> {
        pub(super) fn for_refund(
                refund: &'a Refund, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, created_at: Duration,
                payment_hash: PaymentHash, signing_pubkey: PublicKey
-       ) -> Result<Self, SemanticError> {
+       ) -> Result<Self, Bolt12SemanticError> {
                let amount_msats = refund.amount_msats();
                let contents = InvoiceContents::ForRefund {
                        refund: refund.contents.clone(),
@@ -201,7 +201,7 @@ impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
        pub(super) fn for_offer_using_keys(
                invoice_request: &'a InvoiceRequest, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>,
                created_at: Duration, payment_hash: PaymentHash, keys: KeyPair
-       ) -> Result<Self, SemanticError> {
+       ) -> Result<Self, Bolt12SemanticError> {
                let amount_msats = Self::check_amount_msats(invoice_request)?;
                let signing_pubkey = invoice_request.contents.inner.offer.signing_pubkey();
                let contents = InvoiceContents::ForOffer {
@@ -217,7 +217,7 @@ impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
        pub(super) fn for_refund_using_keys(
                refund: &'a Refund, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, created_at: Duration,
                payment_hash: PaymentHash, keys: KeyPair,
-       ) -> Result<Self, SemanticError> {
+       ) -> Result<Self, Bolt12SemanticError> {
                let amount_msats = refund.amount_msats();
                let signing_pubkey = keys.public_key();
                let contents = InvoiceContents::ForRefund {
@@ -232,16 +232,16 @@ impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
 }
 
 impl<'a, S: SigningPubkeyStrategy> InvoiceBuilder<'a, S> {
-       fn check_amount_msats(invoice_request: &InvoiceRequest) -> Result<u64, SemanticError> {
+       fn check_amount_msats(invoice_request: &InvoiceRequest) -> Result<u64, Bolt12SemanticError> {
                match invoice_request.amount_msats() {
                        Some(amount_msats) => Ok(amount_msats),
                        None => match invoice_request.contents.inner.offer.amount() {
                                Some(Amount::Bitcoin { amount_msats }) => {
                                        amount_msats.checked_mul(invoice_request.quantity().unwrap_or(1))
-                                               .ok_or(SemanticError::InvalidAmount)
+                                               .ok_or(Bolt12SemanticError::InvalidAmount)
                                },
-                               Some(Amount::Currency { .. }) => Err(SemanticError::UnsupportedCurrency),
-                               None => Err(SemanticError::MissingAmount),
+                               Some(Amount::Currency { .. }) => Err(Bolt12SemanticError::UnsupportedCurrency),
+                               None => Err(Bolt12SemanticError::MissingAmount),
                        },
                }
        }
@@ -258,9 +258,9 @@ impl<'a, S: SigningPubkeyStrategy> InvoiceBuilder<'a, S> {
 
        fn new(
                invreq_bytes: &'a Vec<u8>, contents: InvoiceContents, keys: Option<KeyPair>
-       ) -> Result<Self, SemanticError> {
+       ) -> Result<Self, Bolt12SemanticError> {
                if contents.fields().payment_paths.is_empty() {
-                       return Err(SemanticError::MissingPaths);
+                       return Err(Bolt12SemanticError::MissingPaths);
                }
 
                Ok(Self {
@@ -331,10 +331,10 @@ impl<'a, S: SigningPubkeyStrategy> InvoiceBuilder<'a, S> {
 impl<'a> InvoiceBuilder<'a, ExplicitSigningPubkey> {
        /// Builds an unsigned [`Bolt12Invoice`] after checking for valid semantics. It can be signed by
        /// [`UnsignedBolt12Invoice::sign`].
-       pub fn build(self) -> Result<UnsignedBolt12Invoice<'a>, SemanticError> {
+       pub fn build(self) -> Result<UnsignedBolt12Invoice<'a>, Bolt12SemanticError> {
                #[cfg(feature = "std")] {
                        if self.invoice.is_offer_or_refund_expired() {
-                               return Err(SemanticError::AlreadyExpired);
+                               return Err(Bolt12SemanticError::AlreadyExpired);
                        }
                }
 
@@ -347,10 +347,10 @@ impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
        /// Builds a signed [`Bolt12Invoice`] after checking for valid semantics.
        pub fn build_and_sign<T: secp256k1::Signing>(
                self, secp_ctx: &Secp256k1<T>
-       ) -> Result<Bolt12Invoice, SemanticError> {
+       ) -> Result<Bolt12Invoice, Bolt12SemanticError> {
                #[cfg(feature = "std")] {
                        if self.invoice.is_offer_or_refund_expired() {
-                               return Err(SemanticError::AlreadyExpired);
+                               return Err(Bolt12SemanticError::AlreadyExpired);
                        }
                }
 
@@ -853,7 +853,7 @@ impl TryFrom<ParsedMessage<FullInvoiceTlvStream>> for Bolt12Invoice {
                )?;
 
                let signature = match signature {
-                       None => return Err(Bolt12ParseError::InvalidSemantics(SemanticError::MissingSignature)),
+                       None => return Err(Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingSignature)),
                        Some(signature) => signature,
                };
                let pubkey = contents.fields().signing_pubkey;
@@ -864,7 +864,7 @@ impl TryFrom<ParsedMessage<FullInvoiceTlvStream>> for Bolt12Invoice {
 }
 
 impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
-       type Error = SemanticError;
+       type Error = Bolt12SemanticError;
 
        fn try_from(tlv_stream: PartialInvoiceTlvStream) -> Result<Self, Self::Error> {
                let (
@@ -878,11 +878,11 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
                ) = tlv_stream;
 
                let payment_paths = match (blindedpay, paths) {
-                       (_, None) => return Err(SemanticError::MissingPaths),
-                       (None, _) => return Err(SemanticError::InvalidPayInfo),
-                       (_, Some(paths)) if paths.is_empty() => return Err(SemanticError::MissingPaths),
+                       (_, None) => return Err(Bolt12SemanticError::MissingPaths),
+                       (None, _) => return Err(Bolt12SemanticError::InvalidPayInfo),
+                       (_, Some(paths)) if paths.is_empty() => return Err(Bolt12SemanticError::MissingPaths),
                        (Some(blindedpay), Some(paths)) if paths.len() != blindedpay.len() => {
-                               return Err(SemanticError::InvalidPayInfo);
+                               return Err(Bolt12SemanticError::InvalidPayInfo);
                        },
                        (Some(blindedpay), Some(paths)) => {
                                blindedpay.into_iter().zip(paths.into_iter()).collect::<Vec<_>>()
@@ -890,7 +890,7 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
                };
 
                let created_at = match created_at {
-                       None => return Err(SemanticError::MissingCreationTime),
+                       None => return Err(Bolt12SemanticError::MissingCreationTime),
                        Some(timestamp) => Duration::from_secs(timestamp),
                };
 
@@ -899,19 +899,19 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
                        .map(Duration::from_secs);
 
                let payment_hash = match payment_hash {
-                       None => return Err(SemanticError::MissingPaymentHash),
+                       None => return Err(Bolt12SemanticError::MissingPaymentHash),
                        Some(payment_hash) => payment_hash,
                };
 
                let amount_msats = match amount {
-                       None => return Err(SemanticError::MissingAmount),
+                       None => return Err(Bolt12SemanticError::MissingAmount),
                        Some(amount) => amount,
                };
 
                let features = features.unwrap_or_else(Bolt12InvoiceFeatures::empty);
 
                let signing_pubkey = match node_id {
-                       None => return Err(SemanticError::MissingSigningPubkey),
+                       None => return Err(Bolt12SemanticError::MissingSigningPubkey),
                        Some(node_id) => node_id,
                };
 
@@ -923,7 +923,7 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
                match offer_tlv_stream.node_id {
                        Some(expected_signing_pubkey) => {
                                if fields.signing_pubkey != expected_signing_pubkey {
-                                       return Err(SemanticError::InvalidSigningPubkey);
+                                       return Err(Bolt12SemanticError::InvalidSigningPubkey);
                                }
 
                                let invoice_request = InvoiceRequestContents::try_from(
@@ -961,7 +961,7 @@ mod tests {
        use crate::offers::invoice_request::InvoiceRequestTlvStreamRef;
        use crate::offers::merkle::{SignError, SignatureTlvStreamRef, self};
        use crate::offers::offer::{OfferBuilder, OfferTlvStreamRef, Quantity};
-       use crate::offers::parse::{Bolt12ParseError, SemanticError};
+       use crate::offers::parse::{Bolt12ParseError, Bolt12SemanticError};
        use crate::offers::payer::PayerTlvStreamRef;
        use crate::offers::refund::RefundBuilder;
        use crate::offers::test_utils::*;
@@ -1180,7 +1180,7 @@ mod tests {
                        .build()
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::AlreadyExpired),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::AlreadyExpired),
                }
        }
 
@@ -1208,7 +1208,7 @@ mod tests {
                        .build()
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::AlreadyExpired),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::AlreadyExpired),
                }
        }
 
@@ -1253,7 +1253,7 @@ mod tests {
                        payment_paths(), payment_hash(), now(), &expanded_key, &secp_ctx
                ) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InvalidMetadata),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidMetadata),
                }
 
                let desc = "foo".to_string();
@@ -1269,7 +1269,7 @@ mod tests {
                        payment_paths(), payment_hash(), now(), &expanded_key, &secp_ctx
                ) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InvalidMetadata),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidMetadata),
                }
        }
 
@@ -1376,7 +1376,7 @@ mod tests {
                        .respond_with_no_std(payment_paths(), payment_hash(), now())
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InvalidAmount),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidAmount),
                }
        }
 
@@ -1502,7 +1502,7 @@ mod tests {
 
                match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingPaths)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingPaths)),
                }
 
                let mut tlv_stream = invoice.as_tlv_stream();
@@ -1510,7 +1510,7 @@ mod tests {
 
                match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::InvalidPayInfo)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::InvalidPayInfo)),
                }
 
                let empty_payment_paths = vec![];
@@ -1519,7 +1519,7 @@ mod tests {
 
                match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingPaths)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingPaths)),
                }
 
                let mut payment_paths = payment_paths();
@@ -1529,7 +1529,7 @@ mod tests {
 
                match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::InvalidPayInfo)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::InvalidPayInfo)),
                }
        }
 
@@ -1558,7 +1558,7 @@ mod tests {
                match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingCreationTime));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingCreationTime));
                        },
                }
        }
@@ -1610,7 +1610,7 @@ mod tests {
                match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingPaymentHash));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingPaymentHash));
                        },
                }
        }
@@ -1639,7 +1639,7 @@ mod tests {
 
                match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingAmount)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingAmount)),
                }
        }
 
@@ -1758,7 +1758,7 @@ mod tests {
                match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingSigningPubkey));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingSigningPubkey));
                        },
                }
 
@@ -1769,7 +1769,7 @@ mod tests {
                match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::InvalidSigningPubkey));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::InvalidSigningPubkey));
                        },
                }
        }
@@ -1790,7 +1790,7 @@ mod tests {
 
                match Bolt12Invoice::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingSignature)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingSignature)),
                }
        }
 
index 7345bc14d69b0a97b69e47e185a2b5ff716dcc07..122049b9295438b0147224a76c6efbc75455146c 100644 (file)
@@ -11,7 +11,7 @@
 
 use crate::io;
 use crate::ln::msgs::DecodeError;
-use crate::offers::parse::SemanticError;
+use crate::offers::parse::Bolt12SemanticError;
 use crate::util::ser::{HighZeroBytesDroppedBigSize, Readable, WithoutLength, Writeable, Writer};
 use crate::util::string::UntrustedString;
 
@@ -93,8 +93,8 @@ impl Readable for InvoiceError {
        }
 }
 
-impl From<SemanticError> for InvoiceError {
-       fn from(error: SemanticError) -> Self {
+impl From<Bolt12SemanticError> for InvoiceError {
+       fn from(error: Bolt12SemanticError) -> Self {
                InvoiceError {
                        erroneous_field: None,
                        message: UntrustedString(format!("{:?}", error)),
index 6c70a5968eb2210d354ff32b3840d040d0ad9db7..f014bf120021b52b613a6726f988e8fb6b076f1b 100644 (file)
@@ -68,7 +68,7 @@ use crate::ln::msgs::DecodeError;
 use crate::offers::invoice::{BlindedPayInfo, DerivedSigningPubkey, ExplicitSigningPubkey, InvoiceBuilder};
 use crate::offers::merkle::{SignError, SignatureTlvStream, SignatureTlvStreamRef, self};
 use crate::offers::offer::{Offer, OfferContents, OfferTlvStream, OfferTlvStreamRef};
-use crate::offers::parse::{Bolt12ParseError, ParsedMessage, SemanticError};
+use crate::offers::parse::{Bolt12ParseError, ParsedMessage, Bolt12SemanticError};
 use crate::offers::payer::{PayerContents, PayerTlvStream, PayerTlvStreamRef};
 use crate::offers::signer::{Metadata, MetadataMaterial};
 use crate::util::ser::{HighZeroBytesDroppedBigSize, SeekReadable, WithoutLength, Writeable, Writer};
@@ -171,10 +171,10 @@ impl<'a, 'b, P: PayerIdStrategy, T: secp256k1::Signing> InvoiceRequestBuilder<'a
        /// by the offer.
        ///
        /// Successive calls to this method will override the previous setting.
-       pub fn chain(mut self, network: Network) -> Result<Self, SemanticError> {
+       pub fn chain(mut self, network: Network) -> Result<Self, Bolt12SemanticError> {
                let chain = ChainHash::using_genesis_block(network);
                if !self.offer.supports_chain(chain) {
-                       return Err(SemanticError::UnsupportedChain);
+                       return Err(Bolt12SemanticError::UnsupportedChain);
                }
 
                self.invoice_request.chain = Some(chain);
@@ -187,7 +187,7 @@ impl<'a, 'b, P: PayerIdStrategy, T: secp256k1::Signing> InvoiceRequestBuilder<'a
        /// Successive calls to this method will override the previous setting.
        ///
        /// [`quantity`]: Self::quantity
-       pub fn amount_msats(mut self, amount_msats: u64) -> Result<Self, SemanticError> {
+       pub fn amount_msats(mut self, amount_msats: u64) -> Result<Self, Bolt12SemanticError> {
                self.invoice_request.offer.check_amount_msats_for_quantity(
                        Some(amount_msats), self.invoice_request.quantity
                )?;
@@ -199,7 +199,7 @@ impl<'a, 'b, P: PayerIdStrategy, T: secp256k1::Signing> InvoiceRequestBuilder<'a
        /// does not conform to [`Offer::is_valid_quantity`].
        ///
        /// Successive calls to this method will override the previous setting.
-       pub fn quantity(mut self, quantity: u64) -> Result<Self, SemanticError> {
+       pub fn quantity(mut self, quantity: u64) -> Result<Self, Bolt12SemanticError> {
                self.invoice_request.offer.check_quantity(Some(quantity))?;
                self.invoice_request.quantity = Some(quantity);
                Ok(self)
@@ -215,17 +215,17 @@ impl<'a, 'b, P: PayerIdStrategy, T: secp256k1::Signing> InvoiceRequestBuilder<'a
 
        fn build_with_checks(mut self) -> Result<
                (UnsignedInvoiceRequest<'a>, Option<KeyPair>, Option<&'b Secp256k1<T>>),
-               SemanticError
+               Bolt12SemanticError
        > {
                #[cfg(feature = "std")] {
                        if self.offer.is_expired() {
-                               return Err(SemanticError::AlreadyExpired);
+                               return Err(Bolt12SemanticError::AlreadyExpired);
                        }
                }
 
                let chain = self.invoice_request.chain();
                if !self.offer.supports_chain(chain) {
-                       return Err(SemanticError::UnsupportedChain);
+                       return Err(Bolt12SemanticError::UnsupportedChain);
                }
 
                if chain == self.offer.implied_chain() {
@@ -233,7 +233,7 @@ impl<'a, 'b, P: PayerIdStrategy, T: secp256k1::Signing> InvoiceRequestBuilder<'a
                }
 
                if self.offer.amount().is_none() && self.invoice_request.amount_msats.is_none() {
-                       return Err(SemanticError::MissingAmount);
+                       return Err(Bolt12SemanticError::MissingAmount);
                }
 
                self.invoice_request.offer.check_quantity(self.invoice_request.quantity)?;
@@ -290,7 +290,7 @@ impl<'a, 'b, P: PayerIdStrategy, T: secp256k1::Signing> InvoiceRequestBuilder<'a
 impl<'a, 'b, T: secp256k1::Signing> InvoiceRequestBuilder<'a, 'b, ExplicitPayerId, T> {
        /// Builds an unsigned [`InvoiceRequest`] after checking for valid semantics. It can be signed
        /// by [`UnsignedInvoiceRequest::sign`].
-       pub fn build(self) -> Result<UnsignedInvoiceRequest<'a>, SemanticError> {
+       pub fn build(self) -> Result<UnsignedInvoiceRequest<'a>, Bolt12SemanticError> {
                let (unsigned_invoice_request, keys, _) = self.build_with_checks()?;
                debug_assert!(keys.is_none());
                Ok(unsigned_invoice_request)
@@ -299,7 +299,7 @@ impl<'a, 'b, T: secp256k1::Signing> InvoiceRequestBuilder<'a, 'b, ExplicitPayerI
 
 impl<'a, 'b, T: secp256k1::Signing> InvoiceRequestBuilder<'a, 'b, DerivedPayerId, T> {
        /// Builds a signed [`InvoiceRequest`] after checking for valid semantics.
-       pub fn build_and_sign(self) -> Result<InvoiceRequest, SemanticError> {
+       pub fn build_and_sign(self) -> Result<InvoiceRequest, Bolt12SemanticError> {
                let (unsigned_invoice_request, keys, secp_ctx) = self.build_with_checks()?;
                debug_assert!(keys.is_some());
 
@@ -481,7 +481,7 @@ impl InvoiceRequest {
        #[cfg(feature = "std")]
        pub fn respond_with(
                &self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash
-       ) -> Result<InvoiceBuilder<ExplicitSigningPubkey>, SemanticError> {
+       ) -> Result<InvoiceBuilder<ExplicitSigningPubkey>, Bolt12SemanticError> {
                let created_at = std::time::SystemTime::now()
                        .duration_since(std::time::SystemTime::UNIX_EPOCH)
                        .expect("SystemTime::now() should come after SystemTime::UNIX_EPOCH");
@@ -511,9 +511,9 @@ impl InvoiceRequest {
        pub fn respond_with_no_std(
                &self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
                created_at: core::time::Duration
-       ) -> Result<InvoiceBuilder<ExplicitSigningPubkey>, SemanticError> {
+       ) -> Result<InvoiceBuilder<ExplicitSigningPubkey>, Bolt12SemanticError> {
                if self.features().requires_unknown_bits() {
-                       return Err(SemanticError::UnknownRequiredFeatures);
+                       return Err(Bolt12SemanticError::UnknownRequiredFeatures);
                }
 
                InvoiceBuilder::for_offer(self, payment_paths, created_at, payment_hash)
@@ -532,7 +532,7 @@ impl InvoiceRequest {
        pub fn verify_and_respond_using_derived_keys<T: secp256k1::Signing>(
                &self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
                expanded_key: &ExpandedKey, secp_ctx: &Secp256k1<T>
-       ) -> Result<InvoiceBuilder<DerivedSigningPubkey>, SemanticError> {
+       ) -> Result<InvoiceBuilder<DerivedSigningPubkey>, Bolt12SemanticError> {
                let created_at = std::time::SystemTime::now()
                        .duration_since(std::time::SystemTime::UNIX_EPOCH)
                        .expect("SystemTime::now() should come after SystemTime::UNIX_EPOCH");
@@ -554,14 +554,14 @@ impl InvoiceRequest {
        pub fn verify_and_respond_using_derived_keys_no_std<T: secp256k1::Signing>(
                &self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
                created_at: core::time::Duration, expanded_key: &ExpandedKey, secp_ctx: &Secp256k1<T>
-       ) -> Result<InvoiceBuilder<DerivedSigningPubkey>, SemanticError> {
+       ) -> Result<InvoiceBuilder<DerivedSigningPubkey>, Bolt12SemanticError> {
                if self.features().requires_unknown_bits() {
-                       return Err(SemanticError::UnknownRequiredFeatures);
+                       return Err(Bolt12SemanticError::UnknownRequiredFeatures);
                }
 
                let keys = match self.verify(expanded_key, secp_ctx) {
-                       Err(()) => return Err(SemanticError::InvalidMetadata),
-                       Ok(None) => return Err(SemanticError::InvalidMetadata),
+                       Err(()) => return Err(Bolt12SemanticError::InvalidMetadata),
+                       Ok(None) => return Err(Bolt12SemanticError::InvalidMetadata),
                        Ok(Some(keys)) => keys,
                };
 
@@ -722,7 +722,7 @@ impl TryFrom<Vec<u8>> for InvoiceRequest {
                )?;
 
                let signature = match signature {
-                       None => return Err(Bolt12ParseError::InvalidSemantics(SemanticError::MissingSignature)),
+                       None => return Err(Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingSignature)),
                        Some(signature) => signature,
                };
                merkle::verify_signature(&signature, SIGNATURE_TAG, &bytes, contents.payer_id)?;
@@ -732,7 +732,7 @@ impl TryFrom<Vec<u8>> for InvoiceRequest {
 }
 
 impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
-       type Error = SemanticError;
+       type Error = Bolt12SemanticError;
 
        fn try_from(tlv_stream: PartialInvoiceRequestTlvStream) -> Result<Self, Self::Error> {
                let (
@@ -742,17 +742,17 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
                ) = tlv_stream;
 
                let payer = match metadata {
-                       None => return Err(SemanticError::MissingPayerMetadata),
+                       None => return Err(Bolt12SemanticError::MissingPayerMetadata),
                        Some(metadata) => PayerContents(Metadata::Bytes(metadata)),
                };
                let offer = OfferContents::try_from(offer_tlv_stream)?;
 
                if !offer.supports_chain(chain.unwrap_or_else(|| offer.implied_chain())) {
-                       return Err(SemanticError::UnsupportedChain);
+                       return Err(Bolt12SemanticError::UnsupportedChain);
                }
 
                if offer.amount().is_none() && amount.is_none() {
-                       return Err(SemanticError::MissingAmount);
+                       return Err(Bolt12SemanticError::MissingAmount);
                }
 
                offer.check_quantity(quantity)?;
@@ -761,7 +761,7 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
                let features = features.unwrap_or_else(InvoiceRequestFeatures::empty);
 
                let payer_id = match payer_id {
-                       None => return Err(SemanticError::MissingPayerId),
+                       None => return Err(Bolt12SemanticError::MissingPayerId),
                        Some(payer_id) => payer_id,
                };
 
@@ -792,7 +792,7 @@ mod tests {
        use crate::offers::invoice::{Bolt12Invoice, SIGNATURE_TAG as INVOICE_SIGNATURE_TAG};
        use crate::offers::merkle::{SignError, SignatureTlvStreamRef, self};
        use crate::offers::offer::{Amount, OfferBuilder, OfferTlvStreamRef, Quantity};
-       use crate::offers::parse::{Bolt12ParseError, SemanticError};
+       use crate::offers::parse::{Bolt12ParseError, Bolt12SemanticError};
        use crate::offers::payer::PayerTlvStreamRef;
        use crate::offers::test_utils::*;
        use crate::util::ser::{BigSize, Writeable};
@@ -882,7 +882,7 @@ mod tests {
                        .build()
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::AlreadyExpired),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::AlreadyExpired),
                }
        }
 
@@ -1091,7 +1091,7 @@ mod tests {
                        .chain(Network::Bitcoin)
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::UnsupportedChain),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedChain),
                }
 
                match OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1102,7 +1102,7 @@ mod tests {
                        .build()
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::UnsupportedChain),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedChain),
                }
        }
 
@@ -1149,7 +1149,7 @@ mod tests {
                        .amount_msats(999)
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InsufficientAmount),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InsufficientAmount),
                }
 
                match OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1161,7 +1161,7 @@ mod tests {
                        .amount_msats(1000)
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InsufficientAmount),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InsufficientAmount),
                }
 
                match OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1171,7 +1171,7 @@ mod tests {
                        .amount_msats(MAX_VALUE_MSAT + 1)
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InvalidAmount),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidAmount),
                }
 
                match OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1184,7 +1184,7 @@ mod tests {
                        .build()
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InsufficientAmount),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InsufficientAmount),
                }
 
                match OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1193,7 +1193,7 @@ mod tests {
                        .build()
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::MissingAmount),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::MissingAmount),
                }
 
                match OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1205,7 +1205,7 @@ mod tests {
                        .build()
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InvalidAmount),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidAmount),
                }
        }
 
@@ -1260,7 +1260,7 @@ mod tests {
                        .quantity(2)
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::UnexpectedQuantity),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::UnexpectedQuantity),
                }
 
                let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1285,7 +1285,7 @@ mod tests {
                        .quantity(11)
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InvalidQuantity),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidQuantity),
                }
 
                let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1309,7 +1309,7 @@ mod tests {
                        .build()
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::MissingQuantity),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::MissingQuantity),
                }
 
                match OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1320,7 +1320,7 @@ mod tests {
                        .build()
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::MissingQuantity),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::MissingQuantity),
                }
        }
 
@@ -1387,7 +1387,7 @@ mod tests {
                        .respond_with_no_std(payment_paths(), payment_hash(), now())
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::UnknownRequiredFeatures),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::UnknownRequiredFeatures),
                }
        }
 
@@ -1438,7 +1438,7 @@ mod tests {
 
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::UnsupportedChain)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::UnsupportedChain)),
                }
        }
 
@@ -1483,7 +1483,7 @@ mod tests {
 
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingAmount)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingAmount)),
                }
 
                let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1499,7 +1499,7 @@ mod tests {
 
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::InsufficientAmount)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::InsufficientAmount)),
                }
 
                let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1515,7 +1515,7 @@ mod tests {
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::UnsupportedCurrency));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::UnsupportedCurrency));
                        },
                }
 
@@ -1533,7 +1533,7 @@ mod tests {
 
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::InvalidAmount)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::InvalidAmount)),
                }
        }
 
@@ -1573,7 +1573,7 @@ mod tests {
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::UnexpectedQuantity));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::UnexpectedQuantity));
                        },
                }
 
@@ -1609,7 +1609,7 @@ mod tests {
 
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::InvalidQuantity)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::InvalidQuantity)),
                }
 
                let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1642,7 +1642,7 @@ mod tests {
 
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingQuantity)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingQuantity)),
                }
 
                let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1658,7 +1658,7 @@ mod tests {
 
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingQuantity)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingQuantity)),
                }
        }
 
@@ -1678,7 +1678,7 @@ mod tests {
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingPayerMetadata));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingPayerMetadata));
                        },
                }
        }
@@ -1698,7 +1698,7 @@ mod tests {
 
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingPayerId)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingPayerId)),
                }
        }
 
@@ -1718,7 +1718,7 @@ mod tests {
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingSigningPubkey));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingSigningPubkey));
                        },
                }
        }
@@ -1736,7 +1736,7 @@ mod tests {
 
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingSignature)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingSignature)),
                }
        }
 
index 1168aff94329a1d1d236e6c518494c542daef8b2..d801be9d26fb969c0b89af9b84a5e7408726efea 100644 (file)
@@ -82,7 +82,7 @@ use crate::ln::inbound_payment::{ExpandedKey, IV_LEN, Nonce};
 use crate::ln::msgs::MAX_VALUE_MSAT;
 use crate::offers::invoice_request::{DerivedPayerId, ExplicitPayerId, InvoiceRequestBuilder};
 use crate::offers::merkle::TlvStream;
-use crate::offers::parse::{Bech32Encode, Bolt12ParseError, ParsedMessage, SemanticError};
+use crate::offers::parse::{Bech32Encode, Bolt12ParseError, Bolt12SemanticError, ParsedMessage};
 use crate::offers::signer::{Metadata, MetadataMaterial, self};
 use crate::util::ser::{HighZeroBytesDroppedBigSize, WithoutLength, Writeable, Writer};
 use crate::util::string::PrintableString;
@@ -146,7 +146,7 @@ impl<'a> OfferBuilder<'a, ExplicitMetadata, secp256k1::SignOnly> {
        /// Sets the [`Offer::metadata`] to the given bytes.
        ///
        /// Successive calls to this method will override the previous setting.
-       pub fn metadata(mut self, metadata: Vec<u8>) -> Result<Self, SemanticError> {
+       pub fn metadata(mut self, metadata: Vec<u8>) -> Result<Self, Bolt12SemanticError> {
                self.offer.metadata = Some(Metadata::Bytes(metadata));
                Ok(self)
        }
@@ -252,14 +252,14 @@ impl<'a, M: MetadataStrategy, T: secp256k1::Signing> OfferBuilder<'a, M, T> {
        }
 
        /// Builds an [`Offer`] from the builder's settings.
-       pub fn build(mut self) -> Result<Offer, SemanticError> {
+       pub fn build(mut self) -> Result<Offer, Bolt12SemanticError> {
                match self.offer.amount {
                        Some(Amount::Bitcoin { amount_msats }) => {
                                if amount_msats > MAX_VALUE_MSAT {
-                                       return Err(SemanticError::InvalidAmount);
+                                       return Err(Bolt12SemanticError::InvalidAmount);
                                }
                        },
-                       Some(Amount::Currency { .. }) => return Err(SemanticError::UnsupportedCurrency),
+                       Some(Amount::Currency { .. }) => return Err(Bolt12SemanticError::UnsupportedCurrency),
                        None => {},
                }
 
@@ -465,12 +465,12 @@ impl Offer {
        /// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
        pub fn request_invoice_deriving_payer_id<'a, 'b, ES: Deref, T: secp256k1::Signing>(
                &'a self, expanded_key: &ExpandedKey, entropy_source: ES, secp_ctx: &'b Secp256k1<T>
-       ) -> Result<InvoiceRequestBuilder<'a, 'b, DerivedPayerId, T>, SemanticError>
+       ) -> Result<InvoiceRequestBuilder<'a, 'b, DerivedPayerId, T>, Bolt12SemanticError>
        where
                ES::Target: EntropySource,
        {
                if self.features().requires_unknown_bits() {
-                       return Err(SemanticError::UnknownRequiredFeatures);
+                       return Err(Bolt12SemanticError::UnknownRequiredFeatures);
                }
 
                Ok(InvoiceRequestBuilder::deriving_payer_id(self, expanded_key, entropy_source, secp_ctx))
@@ -486,12 +486,12 @@ impl Offer {
        /// [`InvoiceRequest::payer_id`]: crate::offers::invoice_request::InvoiceRequest::payer_id
        pub fn request_invoice_deriving_metadata<ES: Deref>(
                &self, payer_id: PublicKey, expanded_key: &ExpandedKey, entropy_source: ES
-       ) -> Result<InvoiceRequestBuilder<ExplicitPayerId, secp256k1::SignOnly>, SemanticError>
+       ) -> Result<InvoiceRequestBuilder<ExplicitPayerId, secp256k1::SignOnly>, Bolt12SemanticError>
        where
                ES::Target: EntropySource,
        {
                if self.features().requires_unknown_bits() {
-                       return Err(SemanticError::UnknownRequiredFeatures);
+                       return Err(Bolt12SemanticError::UnknownRequiredFeatures);
                }
 
                Ok(InvoiceRequestBuilder::deriving_metadata(self, payer_id, expanded_key, entropy_source))
@@ -514,9 +514,9 @@ impl Offer {
        /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
        pub fn request_invoice(
                &self, metadata: Vec<u8>, payer_id: PublicKey
-       ) -> Result<InvoiceRequestBuilder<ExplicitPayerId, secp256k1::SignOnly>, SemanticError> {
+       ) -> Result<InvoiceRequestBuilder<ExplicitPayerId, secp256k1::SignOnly>, Bolt12SemanticError> {
                if self.features().requires_unknown_bits() {
-                       return Err(SemanticError::UnknownRequiredFeatures);
+                       return Err(Bolt12SemanticError::UnknownRequiredFeatures);
                }
 
                Ok(InvoiceRequestBuilder::new(self, metadata, payer_id))
@@ -572,24 +572,24 @@ impl OfferContents {
 
        pub(super) fn check_amount_msats_for_quantity(
                &self, amount_msats: Option<u64>, quantity: Option<u64>
-       ) -> Result<(), SemanticError> {
+       ) -> Result<(), Bolt12SemanticError> {
                let offer_amount_msats = match self.amount {
                        None => 0,
                        Some(Amount::Bitcoin { amount_msats }) => amount_msats,
-                       Some(Amount::Currency { .. }) => return Err(SemanticError::UnsupportedCurrency),
+                       Some(Amount::Currency { .. }) => return Err(Bolt12SemanticError::UnsupportedCurrency),
                };
 
                if !self.expects_quantity() || quantity.is_some() {
                        let expected_amount_msats = offer_amount_msats.checked_mul(quantity.unwrap_or(1))
-                               .ok_or(SemanticError::InvalidAmount)?;
+                               .ok_or(Bolt12SemanticError::InvalidAmount)?;
                        let amount_msats = amount_msats.unwrap_or(expected_amount_msats);
 
                        if amount_msats < expected_amount_msats {
-                               return Err(SemanticError::InsufficientAmount);
+                               return Err(Bolt12SemanticError::InsufficientAmount);
                        }
 
                        if amount_msats > MAX_VALUE_MSAT {
-                               return Err(SemanticError::InvalidAmount);
+                               return Err(Bolt12SemanticError::InvalidAmount);
                        }
                }
 
@@ -600,13 +600,13 @@ impl OfferContents {
                self.supported_quantity
        }
 
-       pub(super) fn check_quantity(&self, quantity: Option<u64>) -> Result<(), SemanticError> {
+       pub(super) fn check_quantity(&self, quantity: Option<u64>) -> Result<(), Bolt12SemanticError> {
                let expects_quantity = self.expects_quantity();
                match quantity {
-                       None if expects_quantity => Err(SemanticError::MissingQuantity),
-                       Some(_) if !expects_quantity => Err(SemanticError::UnexpectedQuantity),
+                       None if expects_quantity => Err(Bolt12SemanticError::MissingQuantity),
+                       Some(_) if !expects_quantity => Err(Bolt12SemanticError::UnexpectedQuantity),
                        Some(quantity) if !self.is_valid_quantity(quantity) => {
-                               Err(SemanticError::InvalidQuantity)
+                               Err(Bolt12SemanticError::InvalidQuantity)
                        },
                        _ => Ok(()),
                }
@@ -787,7 +787,7 @@ impl TryFrom<Vec<u8>> for Offer {
 }
 
 impl TryFrom<OfferTlvStream> for OfferContents {
-       type Error = SemanticError;
+       type Error = Bolt12SemanticError;
 
        fn try_from(tlv_stream: OfferTlvStream) -> Result<Self, Self::Error> {
                let OfferTlvStream {
@@ -800,15 +800,15 @@ impl TryFrom<OfferTlvStream> for OfferContents {
                let amount = match (currency, amount) {
                        (None, None) => None,
                        (None, Some(amount_msats)) if amount_msats > MAX_VALUE_MSAT => {
-                               return Err(SemanticError::InvalidAmount);
+                               return Err(Bolt12SemanticError::InvalidAmount);
                        },
                        (None, Some(amount_msats)) => Some(Amount::Bitcoin { amount_msats }),
-                       (Some(_), None) => return Err(SemanticError::MissingAmount),
+                       (Some(_), None) => return Err(Bolt12SemanticError::MissingAmount),
                        (Some(iso4217_code), Some(amount)) => Some(Amount::Currency { iso4217_code, amount }),
                };
 
                let description = match description {
-                       None => return Err(SemanticError::MissingDescription),
+                       None => return Err(Bolt12SemanticError::MissingDescription),
                        Some(description) => description,
                };
 
@@ -824,7 +824,7 @@ impl TryFrom<OfferTlvStream> for OfferContents {
                };
 
                let signing_pubkey = match node_id {
-                       None => return Err(SemanticError::MissingSigningPubkey),
+                       None => return Err(Bolt12SemanticError::MissingSigningPubkey),
                        Some(node_id) => node_id,
                };
 
@@ -856,7 +856,7 @@ mod tests {
        use crate::ln::features::OfferFeatures;
        use crate::ln::inbound_payment::ExpandedKey;
        use crate::ln::msgs::{DecodeError, MAX_VALUE_MSAT};
-       use crate::offers::parse::{Bolt12ParseError, SemanticError};
+       use crate::offers::parse::{Bolt12ParseError, Bolt12SemanticError};
        use crate::offers::test_utils::*;
        use crate::util::ser::{BigSize, Writeable};
        use crate::util::string::PrintableString;
@@ -1090,7 +1090,7 @@ mod tests {
                assert_eq!(tlv_stream.currency, Some(b"USD"));
                match builder.build() {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::UnsupportedCurrency),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedCurrency),
                }
 
                let offer = OfferBuilder::new("foo".into(), pubkey(42))
@@ -1105,7 +1105,7 @@ mod tests {
                let invalid_amount = Amount::Bitcoin { amount_msats: MAX_VALUE_MSAT + 1 };
                match OfferBuilder::new("foo".into(), pubkey(42)).amount(invalid_amount).build() {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InvalidAmount),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidAmount),
                }
        }
 
@@ -1259,7 +1259,7 @@ mod tests {
                        .request_invoice(vec![1; 32], pubkey(43))
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::UnknownRequiredFeatures),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::UnknownRequiredFeatures),
                }
        }
 
@@ -1305,7 +1305,7 @@ mod tests {
 
                match Offer::try_from(encoded_offer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingAmount)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingAmount)),
                }
 
                let mut tlv_stream = offer.as_tlv_stream();
@@ -1317,7 +1317,7 @@ mod tests {
 
                match Offer::try_from(encoded_offer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::InvalidAmount)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::InvalidAmount)),
                }
        }
 
@@ -1337,7 +1337,7 @@ mod tests {
                match Offer::try_from(encoded_offer) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingDescription));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingDescription));
                        },
                }
        }
@@ -1427,7 +1427,7 @@ mod tests {
                match Offer::try_from(encoded_offer) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingSigningPubkey));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingSigningPubkey));
                        },
                }
        }
index 064604f3afb35bc9472ad8d1707b399102963cb3..b722499f251ad5213e1d27bbdb613da2c6aba2f7 100644 (file)
@@ -129,16 +129,14 @@ pub enum Bolt12ParseError {
        /// The bech32 decoded string could not be decoded as the expected message type.
        Decode(DecodeError),
        /// The parsed message has invalid semantics.
-       InvalidSemantics(SemanticError),
+       InvalidSemantics(Bolt12SemanticError),
        /// The parsed message has an invalid signature.
        InvalidSignature(secp256k1::Error),
 }
 
 /// Error when interpreting a TLV stream as a specific type.
-///
-/// This is not exported to bindings users as its name conflicts with the BOLT 11 SemanticError type.
 #[derive(Debug, PartialEq)]
-pub enum SemanticError {
+pub enum Bolt12SemanticError {
        /// The current [`std::time::SystemTime`] is past the offer or invoice's expiration.
        AlreadyExpired,
        /// The provided chain hash does not correspond to a supported chain.
@@ -205,8 +203,8 @@ impl From<DecodeError> for Bolt12ParseError {
        }
 }
 
-impl From<SemanticError> for Bolt12ParseError {
-       fn from(error: SemanticError) -> Self {
+impl From<Bolt12SemanticError> for Bolt12ParseError {
+       fn from(error: Bolt12SemanticError) -> Self {
                Self::InvalidSemantics(error)
        }
 }
index aea5e49a3c8e32fecd284694461fb1b4f3f1907d..2c8dffeb1516abfa7961d144581d412657861c2a 100644 (file)
@@ -88,7 +88,7 @@ use crate::ln::msgs::{DecodeError, MAX_VALUE_MSAT};
 use crate::offers::invoice::{BlindedPayInfo, DerivedSigningPubkey, ExplicitSigningPubkey, InvoiceBuilder};
 use crate::offers::invoice_request::{InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef};
 use crate::offers::offer::{OfferTlvStream, OfferTlvStreamRef};
-use crate::offers::parse::{Bech32Encode, Bolt12ParseError, ParsedMessage, SemanticError};
+use crate::offers::parse::{Bech32Encode, Bolt12ParseError, Bolt12SemanticError, ParsedMessage};
 use crate::offers::payer::{PayerContents, PayerTlvStream, PayerTlvStreamRef};
 use crate::offers::signer::{Metadata, MetadataMaterial, self};
 use crate::util::ser::{SeekReadable, WithoutLength, Writeable, Writer};
@@ -121,9 +121,9 @@ impl<'a> RefundBuilder<'a, secp256k1::SignOnly> {
        /// [`Refund::amount_msats`].
        pub fn new(
                description: String, metadata: Vec<u8>, payer_id: PublicKey, amount_msats: u64
-       ) -> Result<Self, SemanticError> {
+       ) -> Result<Self, Bolt12SemanticError> {
                if amount_msats > MAX_VALUE_MSAT {
-                       return Err(SemanticError::InvalidAmount);
+                       return Err(Bolt12SemanticError::InvalidAmount);
                }
 
                let metadata = Metadata::Bytes(metadata);
@@ -152,9 +152,9 @@ impl<'a, T: secp256k1::Signing> RefundBuilder<'a, T> {
        pub fn deriving_payer_id<ES: Deref>(
                description: String, node_id: PublicKey, expanded_key: &ExpandedKey, entropy_source: ES,
                secp_ctx: &'a Secp256k1<T>, amount_msats: u64
-       ) -> Result<Self, SemanticError> where ES::Target: EntropySource {
+       ) -> Result<Self, Bolt12SemanticError> where ES::Target: EntropySource {
                if amount_msats > MAX_VALUE_MSAT {
-                       return Err(SemanticError::InvalidAmount);
+                       return Err(Bolt12SemanticError::InvalidAmount);
                }
 
                let nonce = Nonce::from_entropy_source(entropy_source);
@@ -229,7 +229,7 @@ impl<'a, T: secp256k1::Signing> RefundBuilder<'a, T> {
        }
 
        /// Builds a [`Refund`] after checking for valid semantics.
-       pub fn build(mut self) -> Result<Refund, SemanticError> {
+       pub fn build(mut self) -> Result<Refund, Bolt12SemanticError> {
                if self.refund.chain() == self.refund.implied_chain() {
                        self.refund.chain = None;
                }
@@ -396,7 +396,7 @@ impl Refund {
        pub fn respond_with(
                &self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
                signing_pubkey: PublicKey,
-       ) -> Result<InvoiceBuilder<ExplicitSigningPubkey>, SemanticError> {
+       ) -> Result<InvoiceBuilder<ExplicitSigningPubkey>, Bolt12SemanticError> {
                let created_at = std::time::SystemTime::now()
                        .duration_since(std::time::SystemTime::UNIX_EPOCH)
                        .expect("SystemTime::now() should come after SystemTime::UNIX_EPOCH");
@@ -429,9 +429,9 @@ impl Refund {
        pub fn respond_with_no_std(
                &self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
                signing_pubkey: PublicKey, created_at: Duration
-       ) -> Result<InvoiceBuilder<ExplicitSigningPubkey>, SemanticError> {
+       ) -> Result<InvoiceBuilder<ExplicitSigningPubkey>, Bolt12SemanticError> {
                if self.features().requires_unknown_bits() {
-                       return Err(SemanticError::UnknownRequiredFeatures);
+                       return Err(Bolt12SemanticError::UnknownRequiredFeatures);
                }
 
                InvoiceBuilder::for_refund(self, payment_paths, created_at, payment_hash, signing_pubkey)
@@ -449,7 +449,7 @@ impl Refund {
        pub fn respond_using_derived_keys<ES: Deref>(
                &self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
                expanded_key: &ExpandedKey, entropy_source: ES
-       ) -> Result<InvoiceBuilder<DerivedSigningPubkey>, SemanticError>
+       ) -> Result<InvoiceBuilder<DerivedSigningPubkey>, Bolt12SemanticError>
        where
                ES::Target: EntropySource,
        {
@@ -473,12 +473,12 @@ impl Refund {
        pub fn respond_using_derived_keys_no_std<ES: Deref>(
                &self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
                created_at: core::time::Duration, expanded_key: &ExpandedKey, entropy_source: ES
-       ) -> Result<InvoiceBuilder<DerivedSigningPubkey>, SemanticError>
+       ) -> Result<InvoiceBuilder<DerivedSigningPubkey>, Bolt12SemanticError>
        where
                ES::Target: EntropySource,
        {
                if self.features().requires_unknown_bits() {
-                       return Err(SemanticError::UnknownRequiredFeatures);
+                       return Err(Bolt12SemanticError::UnknownRequiredFeatures);
                }
 
                let nonce = Nonce::from_entropy_source(entropy_source);
@@ -626,7 +626,7 @@ impl TryFrom<Vec<u8>> for Refund {
 }
 
 impl TryFrom<RefundTlvStream> for RefundContents {
-       type Error = SemanticError;
+       type Error = Bolt12SemanticError;
 
        fn try_from(tlv_stream: RefundTlvStream) -> Result<Self, Self::Error> {
                let (
@@ -639,45 +639,45 @@ impl TryFrom<RefundTlvStream> for RefundContents {
                ) = tlv_stream;
 
                let payer = match payer_metadata {
-                       None => return Err(SemanticError::MissingPayerMetadata),
+                       None => return Err(Bolt12SemanticError::MissingPayerMetadata),
                        Some(metadata) => PayerContents(Metadata::Bytes(metadata)),
                };
 
                if metadata.is_some() {
-                       return Err(SemanticError::UnexpectedMetadata);
+                       return Err(Bolt12SemanticError::UnexpectedMetadata);
                }
 
                if chains.is_some() {
-                       return Err(SemanticError::UnexpectedChain);
+                       return Err(Bolt12SemanticError::UnexpectedChain);
                }
 
                if currency.is_some() || offer_amount.is_some() {
-                       return Err(SemanticError::UnexpectedAmount);
+                       return Err(Bolt12SemanticError::UnexpectedAmount);
                }
 
                let description = match description {
-                       None => return Err(SemanticError::MissingDescription),
+                       None => return Err(Bolt12SemanticError::MissingDescription),
                        Some(description) => description,
                };
 
                if offer_features.is_some() {
-                       return Err(SemanticError::UnexpectedFeatures);
+                       return Err(Bolt12SemanticError::UnexpectedFeatures);
                }
 
                let absolute_expiry = absolute_expiry.map(Duration::from_secs);
 
                if quantity_max.is_some() {
-                       return Err(SemanticError::UnexpectedQuantity);
+                       return Err(Bolt12SemanticError::UnexpectedQuantity);
                }
 
                if node_id.is_some() {
-                       return Err(SemanticError::UnexpectedSigningPubkey);
+                       return Err(Bolt12SemanticError::UnexpectedSigningPubkey);
                }
 
                let amount_msats = match amount {
-                       None => return Err(SemanticError::MissingAmount),
+                       None => return Err(Bolt12SemanticError::MissingAmount),
                        Some(amount_msats) if amount_msats > MAX_VALUE_MSAT => {
-                               return Err(SemanticError::InvalidAmount);
+                               return Err(Bolt12SemanticError::InvalidAmount);
                        },
                        Some(amount_msats) => amount_msats,
                };
@@ -685,7 +685,7 @@ impl TryFrom<RefundTlvStream> for RefundContents {
                let features = features.unwrap_or_else(InvoiceRequestFeatures::empty);
 
                let payer_id = match payer_id {
-                       None => return Err(SemanticError::MissingPayerId),
+                       None => return Err(Bolt12SemanticError::MissingPayerId),
                        Some(payer_id) => payer_id,
                };
 
@@ -718,7 +718,7 @@ mod tests {
        use crate::ln::msgs::{DecodeError, MAX_VALUE_MSAT};
        use crate::offers::invoice_request::InvoiceRequestTlvStreamRef;
        use crate::offers::offer::OfferTlvStreamRef;
-       use crate::offers::parse::{Bolt12ParseError, SemanticError};
+       use crate::offers::parse::{Bolt12ParseError, Bolt12SemanticError};
        use crate::offers::payer::PayerTlvStreamRef;
        use crate::offers::test_utils::*;
        use crate::util::ser::{BigSize, Writeable};
@@ -795,7 +795,7 @@ mod tests {
        fn fails_building_refund_with_invalid_amount() {
                match RefundBuilder::new("foo".into(), vec![1; 32], payer_pubkey(), MAX_VALUE_MSAT + 1) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InvalidAmount),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidAmount),
                }
        }
 
@@ -1064,7 +1064,7 @@ mod tests {
                        .respond_with_no_std(payment_paths(), payment_hash(), recipient_pubkey(), now())
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::UnknownRequiredFeatures),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::UnknownRequiredFeatures),
                }
        }
 
@@ -1082,7 +1082,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingPayerMetadata));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingPayerMetadata));
                        },
                }
        }
@@ -1101,7 +1101,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingDescription));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingDescription));
                        },
                }
        }
@@ -1120,7 +1120,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingAmount));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingAmount));
                        },
                }
 
@@ -1130,7 +1130,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::InvalidAmount));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::InvalidAmount));
                        },
                }
        }
@@ -1149,7 +1149,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingPayerId));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingPayerId));
                        },
                }
        }
@@ -1218,7 +1218,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::UnexpectedMetadata));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::UnexpectedMetadata));
                        },
                }
 
@@ -1229,7 +1229,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::UnexpectedChain));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::UnexpectedChain));
                        },
                }
 
@@ -1240,7 +1240,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::UnexpectedAmount));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::UnexpectedAmount));
                        },
                }
 
@@ -1251,7 +1251,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::UnexpectedFeatures));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::UnexpectedFeatures));
                        },
                }
 
@@ -1261,7 +1261,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::UnexpectedQuantity));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::UnexpectedQuantity));
                        },
                }
 
@@ -1272,7 +1272,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::UnexpectedSigningPubkey));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::UnexpectedSigningPubkey));
                        },
                }
        }