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]
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(),
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]
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() {
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;
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(),
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;
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 {
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(),
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 {
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 {
}
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),
},
}
}
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 {
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);
}
}
/// 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);
}
}
)?;
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;
}
impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
- type Error = SemanticError;
+ type Error = Bolt12SemanticError;
fn try_from(tlv_stream: PartialInvoiceTlvStream) -> Result<Self, Self::Error> {
let (
) = 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<_>>()
};
let created_at = match created_at {
- None => return Err(SemanticError::MissingCreationTime),
+ None => return Err(Bolt12SemanticError::MissingCreationTime),
Some(timestamp) => Duration::from_secs(timestamp),
};
.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,
};
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(
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::*;
.build()
{
Ok(_) => panic!("expected error"),
- Err(e) => assert_eq!(e, SemanticError::AlreadyExpired),
+ Err(e) => assert_eq!(e, Bolt12SemanticError::AlreadyExpired),
}
}
.build()
{
Ok(_) => panic!("expected error"),
- Err(e) => assert_eq!(e, SemanticError::AlreadyExpired),
+ Err(e) => assert_eq!(e, Bolt12SemanticError::AlreadyExpired),
}
}
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();
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),
}
}
.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),
}
}
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();
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![];
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();
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)),
}
}
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));
},
}
}
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));
},
}
}
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)),
}
}
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));
},
}
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));
},
}
}
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)),
}
}
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;
}
}
-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)),
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};
/// 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);
/// 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
)?;
/// 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)
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() {
}
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)?;
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)
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());
#[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");
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)
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");
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,
};
)?;
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)?;
}
impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
- type Error = SemanticError;
+ type Error = Bolt12SemanticError;
fn try_from(tlv_stream: PartialInvoiceRequestTlvStream) -> Result<Self, Self::Error> {
let (
) = 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)?;
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,
};
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};
.build()
{
Ok(_) => panic!("expected error"),
- Err(e) => assert_eq!(e, SemanticError::AlreadyExpired),
+ Err(e) => assert_eq!(e, Bolt12SemanticError::AlreadyExpired),
}
}
.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())
.build()
{
Ok(_) => panic!("expected error"),
- Err(e) => assert_eq!(e, SemanticError::UnsupportedChain),
+ Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedChain),
}
}
.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())
.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())
.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())
.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())
.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())
.build()
{
Ok(_) => panic!("expected error"),
- Err(e) => assert_eq!(e, SemanticError::InvalidAmount),
+ Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidAmount),
}
}
.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())
.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())
.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())
.build()
{
Ok(_) => panic!("expected error"),
- Err(e) => assert_eq!(e, SemanticError::MissingQuantity),
+ Err(e) => assert_eq!(e, Bolt12SemanticError::MissingQuantity),
}
}
.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),
}
}
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)),
}
}
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())
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())
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));
},
}
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)),
}
}
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));
},
}
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())
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())
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)),
}
}
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));
},
}
}
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)),
}
}
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));
},
}
}
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)),
}
}
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;
/// 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)
}
}
/// 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 => {},
}
/// [`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))
/// [`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))
/// [`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))
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);
}
}
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(()),
}
}
impl TryFrom<OfferTlvStream> for OfferContents {
- type Error = SemanticError;
+ type Error = Bolt12SemanticError;
fn try_from(tlv_stream: OfferTlvStream) -> Result<Self, Self::Error> {
let OfferTlvStream {
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,
};
};
let signing_pubkey = match node_id {
- None => return Err(SemanticError::MissingSigningPubkey),
+ None => return Err(Bolt12SemanticError::MissingSigningPubkey),
Some(node_id) => node_id,
};
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;
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))
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),
}
}
.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),
}
}
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();
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)),
}
}
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));
},
}
}
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));
},
}
}
/// 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.
}
}
-impl From<SemanticError> for Bolt12ParseError {
- fn from(error: SemanticError) -> Self {
+impl From<Bolt12SemanticError> for Bolt12ParseError {
+ fn from(error: Bolt12SemanticError) -> Self {
Self::InvalidSemantics(error)
}
}
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};
/// [`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);
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);
}
/// 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;
}
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");
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)
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,
{
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);
}
impl TryFrom<RefundTlvStream> for RefundContents {
- type Error = SemanticError;
+ type Error = Bolt12SemanticError;
fn try_from(tlv_stream: RefundTlvStream) -> Result<Self, Self::Error> {
let (
) = 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,
};
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,
};
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};
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),
}
}
.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),
}
}
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));
},
}
}
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));
},
}
}
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));
},
}
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));
},
}
}
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));
},
}
}
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));
},
}
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));
},
}
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));
},
}
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));
},
}
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));
},
}
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));
},
}
}