mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-01-19 05:43:55 +01:00
Qualify the BOLT 12 parse error
To avoid a naming conflict in bindings with BOLT 11 parse error, qualify the BOLT 12 parse error type.
This commit is contained in:
parent
d94227cc13
commit
5627d7cc1f
@ -9,7 +9,7 @@
|
||||
|
||||
use crate::utils::test_logger;
|
||||
use core::convert::TryFrom;
|
||||
use lightning::offers::parse::{Bech32Encode, ParseError};
|
||||
use lightning::offers::parse::{Bech32Encode, Bolt12ParseError};
|
||||
|
||||
#[inline]
|
||||
pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
|
||||
@ -35,8 +35,8 @@ impl AsRef<[u8]> for Bytes {
|
||||
}
|
||||
|
||||
impl TryFrom<Vec<u8>> for Bytes {
|
||||
type Error = ParseError;
|
||||
fn try_from(data: Vec<u8>) -> Result<Self, ParseError> {
|
||||
type Error = Bolt12ParseError;
|
||||
fn try_from(data: Vec<u8>) -> Result<Self, Bolt12ParseError> {
|
||||
Ok(Bytes(data))
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@
|
||||
//! # fn create_payment_paths() -> Vec<(BlindedPayInfo, BlindedPath)> { unimplemented!() }
|
||||
//! # fn create_payment_hash() -> PaymentHash { unimplemented!() }
|
||||
//! #
|
||||
//! # fn parse_invoice_request(bytes: Vec<u8>) -> Result<(), lightning::offers::parse::ParseError> {
|
||||
//! # fn parse_invoice_request(bytes: Vec<u8>) -> Result<(), lightning::offers::parse::Bolt12ParseError> {
|
||||
//! let payment_paths = create_payment_paths();
|
||||
//! let payment_hash = create_payment_hash();
|
||||
//! let secp_ctx = Secp256k1::new();
|
||||
@ -62,7 +62,7 @@
|
||||
//! # Ok(())
|
||||
//! # }
|
||||
//!
|
||||
//! # fn parse_refund(bytes: Vec<u8>) -> Result<(), lightning::offers::parse::ParseError> {
|
||||
//! # fn parse_refund(bytes: Vec<u8>) -> Result<(), lightning::offers::parse::Bolt12ParseError> {
|
||||
//! # let payment_paths = create_payment_paths();
|
||||
//! # let payment_hash = create_payment_hash();
|
||||
//! # let secp_ctx = Secp256k1::new();
|
||||
@ -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::{ParseError, ParsedMessage, SemanticError};
|
||||
use crate::offers::parse::{Bolt12ParseError, ParsedMessage, SemanticError};
|
||||
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;
|
||||
@ -728,7 +728,7 @@ impl Writeable for InvoiceContents {
|
||||
}
|
||||
|
||||
impl TryFrom<Vec<u8>> for Bolt12Invoice {
|
||||
type Error = ParseError;
|
||||
type Error = Bolt12ParseError;
|
||||
|
||||
fn try_from(bytes: Vec<u8>) -> Result<Self, Self::Error> {
|
||||
let parsed_invoice = ParsedMessage::<FullInvoiceTlvStream>::try_from(bytes)?;
|
||||
@ -840,7 +840,7 @@ type PartialInvoiceTlvStreamRef<'a> = (
|
||||
);
|
||||
|
||||
impl TryFrom<ParsedMessage<FullInvoiceTlvStream>> for Bolt12Invoice {
|
||||
type Error = ParseError;
|
||||
type Error = Bolt12ParseError;
|
||||
|
||||
fn try_from(invoice: ParsedMessage<FullInvoiceTlvStream>) -> Result<Self, Self::Error> {
|
||||
let ParsedMessage { bytes, tlv_stream } = invoice;
|
||||
@ -853,7 +853,7 @@ impl TryFrom<ParsedMessage<FullInvoiceTlvStream>> for Bolt12Invoice {
|
||||
)?;
|
||||
|
||||
let signature = match signature {
|
||||
None => return Err(ParseError::InvalidSemantics(SemanticError::MissingSignature)),
|
||||
None => return Err(Bolt12ParseError::InvalidSemantics(SemanticError::MissingSignature)),
|
||||
Some(signature) => signature,
|
||||
};
|
||||
let pubkey = contents.fields().signing_pubkey;
|
||||
@ -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::{ParseError, SemanticError};
|
||||
use crate::offers::parse::{Bolt12ParseError, SemanticError};
|
||||
use crate::offers::payer::PayerTlvStreamRef;
|
||||
use crate::offers::refund::RefundBuilder;
|
||||
use crate::offers::test_utils::*;
|
||||
@ -1502,7 +1502,7 @@ mod tests {
|
||||
|
||||
match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingPaths)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::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, ParseError::InvalidSemantics(SemanticError::InvalidPayInfo)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::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, ParseError::InvalidSemantics(SemanticError::MissingPaths)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::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, ParseError::InvalidSemantics(SemanticError::InvalidPayInfo)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::InvalidPayInfo)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1558,7 +1558,7 @@ mod tests {
|
||||
match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingCreationTime));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingCreationTime));
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1610,7 +1610,7 @@ mod tests {
|
||||
match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingPaymentHash));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingPaymentHash));
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1639,7 +1639,7 @@ mod tests {
|
||||
|
||||
match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingAmount)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingAmount)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1758,7 +1758,7 @@ mod tests {
|
||||
match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingSigningPubkey));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingSigningPubkey));
|
||||
},
|
||||
}
|
||||
|
||||
@ -1769,7 +1769,7 @@ mod tests {
|
||||
match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::InvalidSigningPubkey));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::InvalidSigningPubkey));
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1790,7 +1790,7 @@ mod tests {
|
||||
|
||||
match Bolt12Invoice::try_from(buffer) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingSignature)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingSignature)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1814,7 +1814,7 @@ mod tests {
|
||||
match Bolt12Invoice::try_from(buffer) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSignature(secp256k1::Error::InvalidSignature));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSignature(secp256k1::Error::InvalidSignature));
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1839,7 +1839,7 @@ mod tests {
|
||||
|
||||
match Bolt12Invoice::try_from(encoded_invoice) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => assert_eq!(e, ParseError::Decode(DecodeError::InvalidValue)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::Decode(DecodeError::InvalidValue)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@
|
||||
//! use lightning::offers::offer::Offer;
|
||||
//! use lightning::util::ser::Writeable;
|
||||
//!
|
||||
//! # fn parse() -> Result<(), lightning::offers::parse::ParseError> {
|
||||
//! # fn parse() -> Result<(), lightning::offers::parse::Bolt12ParseError> {
|
||||
//! let secp_ctx = Secp256k1::new();
|
||||
//! let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32])?);
|
||||
//! let pubkey = PublicKey::from(keys);
|
||||
@ -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::{ParseError, ParsedMessage, SemanticError};
|
||||
use crate::offers::parse::{Bolt12ParseError, ParsedMessage, SemanticError};
|
||||
use crate::offers::payer::{PayerContents, PayerTlvStream, PayerTlvStreamRef};
|
||||
use crate::offers::signer::{Metadata, MetadataMaterial};
|
||||
use crate::util::ser::{HighZeroBytesDroppedBigSize, SeekReadable, WithoutLength, Writeable, Writer};
|
||||
@ -708,7 +708,7 @@ type PartialInvoiceRequestTlvStreamRef<'a> = (
|
||||
);
|
||||
|
||||
impl TryFrom<Vec<u8>> for InvoiceRequest {
|
||||
type Error = ParseError;
|
||||
type Error = Bolt12ParseError;
|
||||
|
||||
fn try_from(bytes: Vec<u8>) -> Result<Self, Self::Error> {
|
||||
let invoice_request = ParsedMessage::<FullInvoiceRequestTlvStream>::try_from(bytes)?;
|
||||
@ -722,7 +722,7 @@ impl TryFrom<Vec<u8>> for InvoiceRequest {
|
||||
)?;
|
||||
|
||||
let signature = match signature {
|
||||
None => return Err(ParseError::InvalidSemantics(SemanticError::MissingSignature)),
|
||||
None => return Err(Bolt12ParseError::InvalidSemantics(SemanticError::MissingSignature)),
|
||||
Some(signature) => signature,
|
||||
};
|
||||
merkle::verify_signature(&signature, SIGNATURE_TAG, &bytes, contents.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::{ParseError, SemanticError};
|
||||
use crate::offers::parse::{Bolt12ParseError, SemanticError};
|
||||
use crate::offers::payer::PayerTlvStreamRef;
|
||||
use crate::offers::test_utils::*;
|
||||
use crate::util::ser::{BigSize, Writeable};
|
||||
@ -1438,7 +1438,7 @@ mod tests {
|
||||
|
||||
match InvoiceRequest::try_from(buffer) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnsupportedChain)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::UnsupportedChain)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1483,7 +1483,7 @@ mod tests {
|
||||
|
||||
match InvoiceRequest::try_from(buffer) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingAmount)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::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, ParseError::InvalidSemantics(SemanticError::InsufficientAmount)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::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, ParseError::InvalidSemantics(SemanticError::UnsupportedCurrency));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::UnsupportedCurrency));
|
||||
},
|
||||
}
|
||||
|
||||
@ -1533,7 +1533,7 @@ mod tests {
|
||||
|
||||
match InvoiceRequest::try_from(buffer) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::InvalidAmount)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::InvalidAmount)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1573,7 +1573,7 @@ mod tests {
|
||||
match InvoiceRequest::try_from(buffer) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnexpectedQuantity));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::UnexpectedQuantity));
|
||||
},
|
||||
}
|
||||
|
||||
@ -1609,7 +1609,7 @@ mod tests {
|
||||
|
||||
match InvoiceRequest::try_from(buffer) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::InvalidQuantity)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::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, ParseError::InvalidSemantics(SemanticError::MissingQuantity)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::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, ParseError::InvalidSemantics(SemanticError::MissingQuantity)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingQuantity)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1678,7 +1678,7 @@ mod tests {
|
||||
match InvoiceRequest::try_from(buffer) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingPayerMetadata));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingPayerMetadata));
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1698,7 +1698,7 @@ mod tests {
|
||||
|
||||
match InvoiceRequest::try_from(buffer) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingPayerId)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingPayerId)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1718,7 +1718,7 @@ mod tests {
|
||||
match InvoiceRequest::try_from(buffer) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingSigningPubkey));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingSigningPubkey));
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1736,7 +1736,7 @@ mod tests {
|
||||
|
||||
match InvoiceRequest::try_from(buffer) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingSignature)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingSignature)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1757,7 +1757,7 @@ mod tests {
|
||||
match InvoiceRequest::try_from(buffer) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSignature(secp256k1::Error::InvalidSignature));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSignature(secp256k1::Error::InvalidSignature));
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1782,7 +1782,7 @@ mod tests {
|
||||
|
||||
match InvoiceRequest::try_from(encoded_invoice_request) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => assert_eq!(e, ParseError::Decode(DecodeError::InvalidValue)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::Decode(DecodeError::InvalidValue)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
//!
|
||||
//! use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey};
|
||||
//! use lightning::offers::offer::{Offer, OfferBuilder, Quantity};
|
||||
//! use lightning::offers::parse::ParseError;
|
||||
//! use lightning::offers::parse::Bolt12ParseError;
|
||||
//! use lightning::util::ser::{Readable, Writeable};
|
||||
//!
|
||||
//! # use lightning::blinded_path::BlindedPath;
|
||||
@ -35,7 +35,7 @@
|
||||
//! # fn create_another_blinded_path() -> BlindedPath { unimplemented!() }
|
||||
//! #
|
||||
//! # #[cfg(feature = "std")]
|
||||
//! # fn build() -> Result<(), ParseError> {
|
||||
//! # fn build() -> Result<(), Bolt12ParseError> {
|
||||
//! let secp_ctx = Secp256k1::new();
|
||||
//! let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
|
||||
//! let pubkey = PublicKey::from(keys);
|
||||
@ -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, ParseError, ParsedMessage, SemanticError};
|
||||
use crate::offers::parse::{Bech32Encode, Bolt12ParseError, ParsedMessage, SemanticError};
|
||||
use crate::offers::signer::{Metadata, MetadataMaterial, self};
|
||||
use crate::util::ser::{HighZeroBytesDroppedBigSize, WithoutLength, Writeable, Writer};
|
||||
use crate::util::string::PrintableString;
|
||||
@ -768,7 +768,7 @@ impl Bech32Encode for Offer {
|
||||
}
|
||||
|
||||
impl FromStr for Offer {
|
||||
type Err = ParseError;
|
||||
type Err = Bolt12ParseError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, <Self as FromStr>::Err> {
|
||||
Self::from_bech32_str(s)
|
||||
@ -776,7 +776,7 @@ impl FromStr for Offer {
|
||||
}
|
||||
|
||||
impl TryFrom<Vec<u8>> for Offer {
|
||||
type Error = ParseError;
|
||||
type Error = Bolt12ParseError;
|
||||
|
||||
fn try_from(bytes: Vec<u8>) -> Result<Self, Self::Error> {
|
||||
let offer = ParsedMessage::<OfferTlvStream>::try_from(bytes)?;
|
||||
@ -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::{ParseError, SemanticError};
|
||||
use crate::offers::parse::{Bolt12ParseError, SemanticError};
|
||||
use crate::offers::test_utils::*;
|
||||
use crate::util::ser::{BigSize, Writeable};
|
||||
use crate::util::string::PrintableString;
|
||||
@ -1305,7 +1305,7 @@ mod tests {
|
||||
|
||||
match Offer::try_from(encoded_offer) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingAmount)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::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, ParseError::InvalidSemantics(SemanticError::InvalidAmount)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::InvalidAmount)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1337,7 +1337,7 @@ mod tests {
|
||||
match Offer::try_from(encoded_offer) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingDescription));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingDescription));
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1427,7 +1427,7 @@ mod tests {
|
||||
match Offer::try_from(encoded_offer) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingSigningPubkey));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingSigningPubkey));
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1444,14 +1444,14 @@ mod tests {
|
||||
|
||||
match Offer::try_from(encoded_offer) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => assert_eq!(e, ParseError::Decode(DecodeError::InvalidValue)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::Decode(DecodeError::InvalidValue)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod bech32_tests {
|
||||
use super::{Offer, ParseError};
|
||||
use super::{Bolt12ParseError, Offer};
|
||||
use bitcoin::bech32;
|
||||
use crate::ln::msgs::DecodeError;
|
||||
|
||||
@ -1493,7 +1493,7 @@ mod bech32_tests {
|
||||
for encoded_offer in &offers {
|
||||
match encoded_offer.parse::<Offer>() {
|
||||
Ok(_) => panic!("Valid offer: {}", encoded_offer),
|
||||
Err(e) => assert_eq!(e, ParseError::InvalidContinuation),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidContinuation),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1504,7 +1504,7 @@ mod bech32_tests {
|
||||
let encoded_offer = "lni1pqps7sjqpgtyzm3qv4uxzmtsd3jjqer9wd3hy6tsw35k7msjzfpy7nz5yqcnygrfdej82um5wf5k2uckyypwa3eyt44h6txtxquqh7lz5djge4afgfjn7k4rgrkuag0jsd5xvxg";
|
||||
match encoded_offer.parse::<Offer>() {
|
||||
Ok(_) => panic!("Valid offer: {}", encoded_offer),
|
||||
Err(e) => assert_eq!(e, ParseError::InvalidBech32Hrp),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidBech32Hrp),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1513,7 +1513,7 @@ mod bech32_tests {
|
||||
let encoded_offer = "lno1pqps7sjqpgtyzm3qv4uxzmtsd3jjqer9wd3hy6tsw35k7msjzfpy7nz5yqcnygrfdej82um5wf5k2uckyypwa3eyt44h6txtxquqh7lz5djge4afgfjn7k4rgrkuag0jsd5xvxo";
|
||||
match encoded_offer.parse::<Offer>() {
|
||||
Ok(_) => panic!("Valid offer: {}", encoded_offer),
|
||||
Err(e) => assert_eq!(e, ParseError::Bech32(bech32::Error::InvalidChar('o'))),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::Bech32(bech32::Error::InvalidChar('o'))),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1522,7 +1522,7 @@ mod bech32_tests {
|
||||
let encoded_offer = "lno1pqps7sjqpgtyzm3qv4uxzmtsd3jjqer9wd3hy6tsw35k7msjzfpy7nz5yqcnygrfdej82um5wf5k2uckyypwa3eyt44h6txtxquqh7lz5djge4afgfjn7k4rgrkuag0jsd5xvxgqqqqq";
|
||||
match encoded_offer.parse::<Offer>() {
|
||||
Ok(_) => panic!("Valid offer: {}", encoded_offer),
|
||||
Err(e) => assert_eq!(e, ParseError::Decode(DecodeError::InvalidValue)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::Decode(DecodeError::InvalidValue)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,24 +29,24 @@ mod sealed {
|
||||
use bitcoin::bech32::{FromBase32, ToBase32};
|
||||
use core::convert::TryFrom;
|
||||
use core::fmt;
|
||||
use super::ParseError;
|
||||
use super::Bolt12ParseError;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
/// Indicates a message can be encoded using bech32.
|
||||
pub trait Bech32Encode: AsRef<[u8]> + TryFrom<Vec<u8>, Error=ParseError> {
|
||||
pub trait Bech32Encode: AsRef<[u8]> + TryFrom<Vec<u8>, Error=Bolt12ParseError> {
|
||||
/// Human readable part of the message's bech32 encoding.
|
||||
const BECH32_HRP: &'static str;
|
||||
|
||||
/// Parses a bech32-encoded message into a TLV stream.
|
||||
fn from_bech32_str(s: &str) -> Result<Self, ParseError> {
|
||||
fn from_bech32_str(s: &str) -> Result<Self, Bolt12ParseError> {
|
||||
// Offer encoding may be split by '+' followed by optional whitespace.
|
||||
let encoded = match s.split('+').skip(1).next() {
|
||||
Some(_) => {
|
||||
for chunk in s.split('+') {
|
||||
let chunk = chunk.trim_start();
|
||||
if chunk.is_empty() || chunk.contains(char::is_whitespace) {
|
||||
return Err(ParseError::InvalidContinuation);
|
||||
return Err(Bolt12ParseError::InvalidContinuation);
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ mod sealed {
|
||||
let (hrp, data) = bech32::decode_without_checksum(encoded.as_ref())?;
|
||||
|
||||
if hrp != Self::BECH32_HRP {
|
||||
return Err(ParseError::InvalidBech32Hrp);
|
||||
return Err(Bolt12ParseError::InvalidBech32Hrp);
|
||||
}
|
||||
|
||||
let data = Vec::<u8>::from_base32(&data)?;
|
||||
@ -116,10 +116,8 @@ impl<T: SeekReadable> TryFrom<Vec<u8>> for ParsedMessage<T> {
|
||||
}
|
||||
|
||||
/// Error when parsing a bech32 encoded message using [`str::parse`].
|
||||
///
|
||||
/// This is not exported to bindings users as its name conflicts with the BOLT 11 ParseError type.
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum ParseError {
|
||||
pub enum Bolt12ParseError {
|
||||
/// The bech32 encoding does not conform to the BOLT 12 requirements for continuing messages
|
||||
/// across multiple parts (i.e., '+' followed by whitespace).
|
||||
InvalidContinuation,
|
||||
@ -195,25 +193,25 @@ pub enum SemanticError {
|
||||
MissingSignature,
|
||||
}
|
||||
|
||||
impl From<bech32::Error> for ParseError {
|
||||
impl From<bech32::Error> for Bolt12ParseError {
|
||||
fn from(error: bech32::Error) -> Self {
|
||||
Self::Bech32(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DecodeError> for ParseError {
|
||||
impl From<DecodeError> for Bolt12ParseError {
|
||||
fn from(error: DecodeError) -> Self {
|
||||
Self::Decode(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SemanticError> for ParseError {
|
||||
impl From<SemanticError> for Bolt12ParseError {
|
||||
fn from(error: SemanticError) -> Self {
|
||||
Self::InvalidSemantics(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<secp256k1::Error> for ParseError {
|
||||
impl From<secp256k1::Error> for Bolt12ParseError {
|
||||
fn from(error: secp256k1::Error) -> Self {
|
||||
Self::InvalidSignature(error)
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
//!
|
||||
//! use bitcoin::network::constants::Network;
|
||||
//! use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey};
|
||||
//! use lightning::offers::parse::ParseError;
|
||||
//! use lightning::offers::parse::Bolt12ParseError;
|
||||
//! use lightning::offers::refund::{Refund, RefundBuilder};
|
||||
//! use lightning::util::ser::{Readable, Writeable};
|
||||
//!
|
||||
@ -40,7 +40,7 @@
|
||||
//! # fn create_another_blinded_path() -> BlindedPath { unimplemented!() }
|
||||
//! #
|
||||
//! # #[cfg(feature = "std")]
|
||||
//! # fn build() -> Result<(), ParseError> {
|
||||
//! # fn build() -> Result<(), Bolt12ParseError> {
|
||||
//! let secp_ctx = Secp256k1::new();
|
||||
//! let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
|
||||
//! let pubkey = PublicKey::from(keys);
|
||||
@ -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, ParseError, ParsedMessage, SemanticError};
|
||||
use crate::offers::parse::{Bech32Encode, Bolt12ParseError, ParsedMessage, SemanticError};
|
||||
use crate::offers::payer::{PayerContents, PayerTlvStream, PayerTlvStreamRef};
|
||||
use crate::offers::signer::{Metadata, MetadataMaterial, self};
|
||||
use crate::util::ser::{SeekReadable, WithoutLength, Writeable, Writer};
|
||||
@ -606,7 +606,7 @@ impl Bech32Encode for Refund {
|
||||
}
|
||||
|
||||
impl FromStr for Refund {
|
||||
type Err = ParseError;
|
||||
type Err = Bolt12ParseError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, <Self as FromStr>::Err> {
|
||||
Refund::from_bech32_str(s)
|
||||
@ -614,7 +614,7 @@ impl FromStr for Refund {
|
||||
}
|
||||
|
||||
impl TryFrom<Vec<u8>> for Refund {
|
||||
type Error = ParseError;
|
||||
type Error = Bolt12ParseError;
|
||||
|
||||
fn try_from(bytes: Vec<u8>) -> Result<Self, Self::Error> {
|
||||
let refund = ParsedMessage::<RefundTlvStream>::try_from(bytes)?;
|
||||
@ -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::{ParseError, SemanticError};
|
||||
use crate::offers::parse::{Bolt12ParseError, SemanticError};
|
||||
use crate::offers::payer::PayerTlvStreamRef;
|
||||
use crate::offers::test_utils::*;
|
||||
use crate::util::ser::{BigSize, Writeable};
|
||||
@ -1082,7 +1082,7 @@ mod tests {
|
||||
match Refund::try_from(tlv_stream.to_bytes()) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingPayerMetadata));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingPayerMetadata));
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1101,7 +1101,7 @@ mod tests {
|
||||
match Refund::try_from(tlv_stream.to_bytes()) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingDescription));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingDescription));
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1120,7 +1120,7 @@ mod tests {
|
||||
match Refund::try_from(tlv_stream.to_bytes()) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingAmount));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingAmount));
|
||||
},
|
||||
}
|
||||
|
||||
@ -1130,7 +1130,7 @@ mod tests {
|
||||
match Refund::try_from(tlv_stream.to_bytes()) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::InvalidAmount));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::InvalidAmount));
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1149,7 +1149,7 @@ mod tests {
|
||||
match Refund::try_from(tlv_stream.to_bytes()) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingPayerId));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingPayerId));
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1218,7 +1218,7 @@ mod tests {
|
||||
match Refund::try_from(tlv_stream.to_bytes()) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnexpectedMetadata));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::UnexpectedMetadata));
|
||||
},
|
||||
}
|
||||
|
||||
@ -1229,7 +1229,7 @@ mod tests {
|
||||
match Refund::try_from(tlv_stream.to_bytes()) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnexpectedChain));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::UnexpectedChain));
|
||||
},
|
||||
}
|
||||
|
||||
@ -1240,7 +1240,7 @@ mod tests {
|
||||
match Refund::try_from(tlv_stream.to_bytes()) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnexpectedAmount));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::UnexpectedAmount));
|
||||
},
|
||||
}
|
||||
|
||||
@ -1251,7 +1251,7 @@ mod tests {
|
||||
match Refund::try_from(tlv_stream.to_bytes()) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnexpectedFeatures));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::UnexpectedFeatures));
|
||||
},
|
||||
}
|
||||
|
||||
@ -1261,7 +1261,7 @@ mod tests {
|
||||
match Refund::try_from(tlv_stream.to_bytes()) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnexpectedQuantity));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::UnexpectedQuantity));
|
||||
},
|
||||
}
|
||||
|
||||
@ -1272,7 +1272,7 @@ mod tests {
|
||||
match Refund::try_from(tlv_stream.to_bytes()) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => {
|
||||
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnexpectedSigningPubkey));
|
||||
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::UnexpectedSigningPubkey));
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1292,7 +1292,7 @@ mod tests {
|
||||
|
||||
match Refund::try_from(encoded_refund) {
|
||||
Ok(_) => panic!("expected error"),
|
||||
Err(e) => assert_eq!(e, ParseError::Decode(DecodeError::InvalidValue)),
|
||||
Err(e) => assert_eq!(e, Bolt12ParseError::Decode(DecodeError::InvalidValue)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ use crate::ln::msgs::DecodeError;
|
||||
use crate::offers::invoice_error::InvoiceError;
|
||||
use crate::offers::invoice_request::InvoiceRequest;
|
||||
use crate::offers::invoice::Bolt12Invoice;
|
||||
use crate::offers::parse::ParseError;
|
||||
use crate::offers::parse::Bolt12ParseError;
|
||||
use crate::util::logger::Logger;
|
||||
use crate::util::ser::{Readable, ReadableArgs, Writeable, Writer};
|
||||
|
||||
@ -72,11 +72,11 @@ impl OffersMessage {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse(tlv_type: u64, bytes: Vec<u8>) -> Result<Self, ParseError> {
|
||||
fn parse(tlv_type: u64, bytes: Vec<u8>) -> Result<Self, Bolt12ParseError> {
|
||||
match tlv_type {
|
||||
INVOICE_REQUEST_TLV_TYPE => Ok(Self::InvoiceRequest(InvoiceRequest::try_from(bytes)?)),
|
||||
INVOICE_TLV_TYPE => Ok(Self::Invoice(Bolt12Invoice::try_from(bytes)?)),
|
||||
_ => Err(ParseError::Decode(DecodeError::InvalidValue)),
|
||||
_ => Err(Bolt12ParseError::Decode(DecodeError::InvalidValue)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -103,12 +103,12 @@ impl<L: Logger + ?Sized> ReadableArgs<(u64, &L)> for OffersMessage {
|
||||
|
||||
match Self::parse(tlv_type, bytes) {
|
||||
Ok(message) => Ok(message),
|
||||
Err(ParseError::Decode(e)) => Err(e),
|
||||
Err(ParseError::InvalidSemantics(e)) => {
|
||||
Err(Bolt12ParseError::Decode(e)) => Err(e),
|
||||
Err(Bolt12ParseError::InvalidSemantics(e)) => {
|
||||
log_trace!(logger, "Invalid semantics for TLV type {}: {:?}", tlv_type, e);
|
||||
Err(DecodeError::InvalidValue)
|
||||
},
|
||||
Err(ParseError::InvalidSignature(e)) => {
|
||||
Err(Bolt12ParseError::InvalidSignature(e)) => {
|
||||
log_trace!(logger, "Invalid signature for TLV type {}: {:?}", tlv_type, e);
|
||||
Err(DecodeError::InvalidValue)
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user