Skip to content

Commit 4c383a3

Browse files
committed
Qualify the BOLT 11 raw invoice types
A previous commit qualified the BOLT 11 invoice type, so any related types should be similarly qualified, if public.
1 parent 93ead4a commit 4c383a3

File tree

4 files changed

+64
-64
lines changed

4 files changed

+64
-64
lines changed

lightning-invoice/src/de.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
2424
use secp256k1::PublicKey;
2525

2626
use super::{Bolt11Invoice, Sha256, TaggedField, ExpiryTime, MinFinalCltvExpiryDelta, Fallback, PayeePubKey, InvoiceSignature, PositiveTimestamp,
27-
SemanticError, PrivateRoute, ParseError, ParseOrSemanticError, Description, RawTaggedField, Currency, RawHrp, SiPrefix, RawInvoice,
28-
constants, SignedRawInvoice, RawDataPart, InvoiceFeatures};
27+
SemanticError, PrivateRoute, ParseError, ParseOrSemanticError, Description, RawTaggedField, Currency, RawHrp, SiPrefix, RawBolt11Invoice,
28+
constants, SignedRawBolt11Invoice, RawDataPart, InvoiceFeatures};
2929

3030
use self::hrp_sm::parse_hrp;
3131

@@ -231,7 +231,7 @@ impl FromStr for Bolt11Invoice {
231231
type Err = ParseOrSemanticError;
232232

233233
fn from_str(s: &str) -> Result<Self, <Self as FromStr>::Err> {
234-
let signed = s.parse::<SignedRawInvoice>()?;
234+
let signed = s.parse::<SignedRawBolt11Invoice>()?;
235235
Ok(Bolt11Invoice::from_signed(signed)?)
236236
}
237237
}
@@ -253,7 +253,7 @@ impl FromStr for Bolt11Invoice {
253253
///
254254
/// let parsed_1 = invoice.parse::<Bolt11Invoice>();
255255
///
256-
/// let parsed_2 = match invoice.parse::<SignedRawInvoice>() {
256+
/// let parsed_2 = match invoice.parse::<SignedRawBolt11Invoice>() {
257257
/// Ok(signed) => match Bolt11Invoice::from_signed(signed) {
258258
/// Ok(invoice) => Ok(invoice),
259259
/// Err(e) => Err(ParseOrSemanticError::SemanticError(e)),
@@ -264,7 +264,7 @@ impl FromStr for Bolt11Invoice {
264264
/// assert!(parsed_1.is_ok());
265265
/// assert_eq!(parsed_1, parsed_2);
266266
/// ```
267-
impl FromStr for SignedRawInvoice {
267+
impl FromStr for SignedRawBolt11Invoice {
268268
type Err = ParseError;
269269

270270
fn from_str(s: &str) -> Result<Self, Self::Err> {
@@ -283,12 +283,12 @@ impl FromStr for SignedRawInvoice {
283283
let raw_hrp: RawHrp = hrp.parse()?;
284284
let data_part = RawDataPart::from_base32(&data[..data.len()-104])?;
285285

286-
Ok(SignedRawInvoice {
287-
raw_invoice: RawInvoice {
286+
Ok(SignedRawBolt11Invoice {
287+
raw_invoice: RawBolt11Invoice {
288288
hrp: raw_hrp,
289289
data: data_part,
290290
},
291-
hash: RawInvoice::hash_from_parts(
291+
hash: RawBolt11Invoice::hash_from_parts(
292292
hrp.as_bytes(),
293293
&data[..data.len()-104]
294294
),
@@ -972,14 +972,14 @@ mod test {
972972
use lightning::ln::features::InvoiceFeatures;
973973
use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
974974
use crate::TaggedField::*;
975-
use crate::{SiPrefix, SignedRawInvoice, InvoiceSignature, RawInvoice, RawHrp, RawDataPart,
975+
use crate::{SiPrefix, SignedRawBolt11Invoice, InvoiceSignature, RawBolt11Invoice, RawHrp, RawDataPart,
976976
Currency, Sha256, PositiveTimestamp};
977977

978978
// Feature bits 9, 15, and 99 are set.
979979
let expected_features = InvoiceFeatures::from_le_bytes(vec![0, 130, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8]);
980980
let invoice_str = "lnbc25m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5vdhkven9v5sxyetpdeessp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs9q5sqqqqqqqqqqqqqqqpqsq67gye39hfg3zd8rgc80k32tvy9xk2xunwm5lzexnvpx6fd77en8qaq424dxgt56cag2dpt359k3ssyhetktkpqh24jqnjyw6uqd08sgptq44qu";
981-
let invoice = SignedRawInvoice {
982-
raw_invoice: RawInvoice {
981+
let invoice = SignedRawBolt11Invoice {
982+
raw_invoice: RawBolt11Invoice {
983983
hrp: RawHrp {
984984
currency: Currency::Bitcoin,
985985
raw_amount: Some(25),
@@ -1018,15 +1018,15 @@ mod test {
10181018
fn test_raw_signed_invoice_deserialization() {
10191019
use crate::TaggedField::*;
10201020
use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
1021-
use crate::{SignedRawInvoice, InvoiceSignature, RawInvoice, RawHrp, RawDataPart, Currency, Sha256,
1021+
use crate::{SignedRawBolt11Invoice, InvoiceSignature, RawBolt11Invoice, RawHrp, RawDataPart, Currency, Sha256,
10221022
PositiveTimestamp};
10231023

10241024
assert_eq!(
10251025
"lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmw\
10261026
wd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d73gafnh3cax9rn449d9p5uxz9\
10271027
ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ecky03ylcqca784w".parse(),
1028-
Ok(SignedRawInvoice {
1029-
raw_invoice: RawInvoice {
1028+
Ok(SignedRawBolt11Invoice {
1029+
raw_invoice: RawBolt11Invoice {
10301030
hrp: RawHrp {
10311031
currency: Currency::Bitcoin,
10321032
raw_amount: None,

lightning-invoice/src/lib.rs

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ pub struct InvoiceBuilder<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S:
251251
/// [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr
252252
#[derive(Eq, PartialEq, Debug, Clone, Hash, Ord, PartialOrd)]
253253
pub struct Bolt11Invoice {
254-
signed_invoice: SignedRawInvoice,
254+
signed_invoice: SignedRawBolt11Invoice,
255255
}
256256

257257
/// Represents the description of an invoice which has to be either a directly included string or
@@ -268,23 +268,23 @@ pub enum InvoiceDescription<'f> {
268268
Hash(&'f Sha256),
269269
}
270270

271-
/// Represents a signed [`RawInvoice`] with cached hash. The signature is not checked and may be
271+
/// Represents a signed [`RawBolt11Invoice`] with cached hash. The signature is not checked and may be
272272
/// invalid.
273273
///
274274
/// # Invariants
275-
/// The hash has to be either from the deserialized invoice or from the serialized [`RawInvoice`].
275+
/// The hash has to be either from the deserialized invoice or from the serialized [`RawBolt11Invoice`].
276276
#[derive(Eq, PartialEq, Debug, Clone, Hash, Ord, PartialOrd)]
277-
pub struct SignedRawInvoice {
278-
/// The rawInvoice that the signature belongs to
279-
raw_invoice: RawInvoice,
277+
pub struct SignedRawBolt11Invoice {
278+
/// The raw invoice that the signature belongs to
279+
raw_invoice: RawBolt11Invoice,
280280

281-
/// Hash of the [`RawInvoice`] that will be used to check the signature.
281+
/// Hash of the [`RawBolt11Invoice`] that will be used to check the signature.
282282
///
283-
/// * if the `SignedRawInvoice` was deserialized the hash is of from the original encoded form,
283+
/// * if the `SignedRawBolt11Invoice` was deserialized the hash is of from the original encoded form,
284284
/// since it's not guaranteed that encoding it again will lead to the same result since integers
285285
/// could have been encoded with leading zeroes etc.
286-
/// * if the `SignedRawInvoice` was constructed manually the hash will be the calculated hash
287-
/// from the [`RawInvoice`]
286+
/// * if the `SignedRawBolt11Invoice` was constructed manually the hash will be the calculated hash
287+
/// from the [`RawBolt11Invoice`]
288288
hash: [u8; 32],
289289

290290
/// signature of the payment request
@@ -297,15 +297,15 @@ pub struct SignedRawInvoice {
297297
///
298298
/// For methods without docs see the corresponding methods in [`Bolt11Invoice`].
299299
#[derive(Eq, PartialEq, Debug, Clone, Hash, Ord, PartialOrd)]
300-
pub struct RawInvoice {
300+
pub struct RawBolt11Invoice {
301301
/// human readable part
302302
pub hrp: RawHrp,
303303

304304
/// data part
305305
pub data: RawDataPart,
306306
}
307307

308-
/// Data of the [`RawInvoice`] that is encoded in the human readable part.
308+
/// Data of the [`RawBolt11Invoice`] that is encoded in the human readable part.
309309
///
310310
/// This is not exported to bindings users as we don't yet support `Option<Enum>`
311311
#[derive(Eq, PartialEq, Debug, Clone, Hash, Ord, PartialOrd)]
@@ -320,7 +320,7 @@ pub struct RawHrp {
320320
pub si_prefix: Option<SiPrefix>,
321321
}
322322

323-
/// Data of the [`RawInvoice`] that is encoded in the data part
323+
/// Data of the [`RawBolt11Invoice`] that is encoded in the data part
324324
#[derive(Eq, PartialEq, Debug, Clone, Hash, Ord, PartialOrd)]
325325
pub struct RawDataPart {
326326
/// generation time of the invoice
@@ -621,9 +621,9 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S: tb::Bool, M: tb::Boo
621621
}
622622

623623
impl<D: tb::Bool, H: tb::Bool, C: tb::Bool, S: tb::Bool, M: tb::Bool> InvoiceBuilder<D, H, tb::True, C, S, M> {
624-
/// Builds a [`RawInvoice`] if no [`CreationError`] occurred while construction any of the
624+
/// Builds a [`RawBolt11Invoice`] if no [`CreationError`] occurred while construction any of the
625625
/// fields.
626-
pub fn build_raw(self) -> Result<RawInvoice, CreationError> {
626+
pub fn build_raw(self) -> Result<RawBolt11Invoice, CreationError> {
627627

628628
// If an error occurred at any time before, return it now
629629
if let Some(e) = self.error {
@@ -647,7 +647,7 @@ impl<D: tb::Bool, H: tb::Bool, C: tb::Bool, S: tb::Bool, M: tb::Bool> InvoiceBui
647647
tagged_fields,
648648
};
649649

650-
Ok(RawInvoice {
650+
Ok(RawBolt11Invoice {
651651
hrp,
652652
data,
653653
})
@@ -850,21 +850,21 @@ impl<M: tb::Bool> InvoiceBuilder<tb::True, tb::True, tb::True, tb::True, tb::Tru
850850
}
851851

852852

853-
impl SignedRawInvoice {
854-
/// Disassembles the `SignedRawInvoice` into its three parts:
853+
impl SignedRawBolt11Invoice {
854+
/// Disassembles the `SignedRawBolt11Invoice` into its three parts:
855855
/// 1. raw invoice
856856
/// 2. hash of the raw invoice
857857
/// 3. signature
858-
pub fn into_parts(self) -> (RawInvoice, [u8; 32], InvoiceSignature) {
858+
pub fn into_parts(self) -> (RawBolt11Invoice, [u8; 32], InvoiceSignature) {
859859
(self.raw_invoice, self.hash, self.signature)
860860
}
861861

862-
/// The [`RawInvoice`] which was signed.
863-
pub fn raw_invoice(&self) -> &RawInvoice {
862+
/// The [`RawBolt11Invoice`] which was signed.
863+
pub fn raw_invoice(&self) -> &RawBolt11Invoice {
864864
&self.raw_invoice
865865
}
866866

867-
/// The hash of the [`RawInvoice`] that was signed.
867+
/// The hash of the [`RawBolt11Invoice`] that was signed.
868868
pub fn signable_hash(&self) -> &[u8; 32] {
869869
&self.hash
870870
}
@@ -968,7 +968,7 @@ macro_rules! find_all_extract {
968968
}
969969

970970
#[allow(missing_docs)]
971-
impl RawInvoice {
971+
impl RawBolt11Invoice {
972972
/// Hash the HRP as bytes and signatureless data part.
973973
fn hash_from_parts(hrp_bytes: &[u8], data_without_signature: &[u5]) -> [u8; 32] {
974974
let preimage = construct_invoice_preimage(hrp_bytes, data_without_signature);
@@ -977,31 +977,31 @@ impl RawInvoice {
977977
hash
978978
}
979979

980-
/// Calculate the hash of the encoded `RawInvoice` which should be signed.
980+
/// Calculate the hash of the encoded `RawBolt11Invoice` which should be signed.
981981
pub fn signable_hash(&self) -> [u8; 32] {
982982
use bech32::ToBase32;
983983

984-
RawInvoice::hash_from_parts(
984+
RawBolt11Invoice::hash_from_parts(
985985
self.hrp.to_string().as_bytes(),
986986
&self.data.to_base32()
987987
)
988988
}
989989

990990
/// Signs the invoice using the supplied `sign_method`. This function MAY fail with an error of
991-
/// type `E`. Since the signature of a [`SignedRawInvoice`] is not required to be valid there
991+
/// type `E`. Since the signature of a [`SignedRawBolt11Invoice`] is not required to be valid there
992992
/// are no constraints regarding the validity of the produced signature.
993993
///
994994
/// This is not exported to bindings users as we don't currently support passing function pointers into methods
995995
/// explicitly.
996-
pub fn sign<F, E>(self, sign_method: F) -> Result<SignedRawInvoice, E>
996+
pub fn sign<F, E>(self, sign_method: F) -> Result<SignedRawBolt11Invoice, E>
997997
where F: FnOnce(&Message) -> Result<RecoverableSignature, E>
998998
{
999999
let raw_hash = self.signable_hash();
10001000
let hash = Message::from_slice(&raw_hash[..])
10011001
.expect("Hash is 32 bytes long, same as MESSAGE_SIZE");
10021002
let signature = sign_method(&hash)?;
10031003

1004-
Ok(SignedRawInvoice {
1004+
Ok(SignedRawBolt11Invoice {
10051005
raw_invoice: self,
10061006
hash: raw_hash,
10071007
signature: InvoiceSignature(signature),
@@ -1143,13 +1143,13 @@ impl From<PositiveTimestamp> for SystemTime {
11431143
}
11441144

11451145
impl Bolt11Invoice {
1146-
/// The hash of the [`RawInvoice`] that was signed.
1146+
/// The hash of the [`RawBolt11Invoice`] that was signed.
11471147
pub fn signable_hash(&self) -> [u8; 32] {
11481148
self.signed_invoice.hash
11491149
}
11501150

11511151
/// Transform the `Bolt11Invoice` into its unchecked version.
1152-
pub fn into_signed_raw(self) -> SignedRawInvoice {
1152+
pub fn into_signed_raw(self) -> SignedRawBolt11Invoice {
11531153
self.signed_invoice
11541154
}
11551155

@@ -1252,7 +1252,7 @@ impl Bolt11Invoice {
12521252
Ok(())
12531253
}
12541254

1255-
/// Constructs a `Bolt11Invoice` from a [`SignedRawInvoice`] by checking all its invariants.
1255+
/// Constructs a `Bolt11Invoice` from a [`SignedRawBolt11Invoice`] by checking all its invariants.
12561256
/// ```
12571257
/// use lightning_invoice::*;
12581258
///
@@ -1268,11 +1268,11 @@ impl Bolt11Invoice {
12681268
/// 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\
12691269
/// j5r6drg6k6zcqj0fcwg";
12701270
///
1271-
/// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
1271+
/// let signed = invoice.parse::<SignedRawBolt11Invoice>().unwrap();
12721272
///
12731273
/// assert!(Bolt11Invoice::from_signed(signed).is_ok());
12741274
/// ```
1275-
pub fn from_signed(signed_invoice: SignedRawInvoice) -> Result<Self, SemanticError> {
1275+
pub fn from_signed(signed_invoice: SignedRawBolt11Invoice) -> Result<Self, SemanticError> {
12761276
let invoice = Bolt11Invoice {
12771277
signed_invoice,
12781278
};
@@ -1599,15 +1599,15 @@ impl Deref for InvoiceSignature {
15991599
}
16001600
}
16011601

1602-
impl Deref for SignedRawInvoice {
1603-
type Target = RawInvoice;
1602+
impl Deref for SignedRawBolt11Invoice {
1603+
type Target = RawBolt11Invoice;
16041604

1605-
fn deref(&self) -> &RawInvoice {
1605+
fn deref(&self) -> &RawBolt11Invoice {
16061606
&self.raw_invoice
16071607
}
16081608
}
16091609

1610-
/// Errors that may occur when constructing a new [`RawInvoice`] or [`Bolt11Invoice`]
1610+
/// Errors that may occur when constructing a new [`RawBolt11Invoice`] or [`Bolt11Invoice`]
16111611
#[derive(Eq, PartialEq, Debug, Clone)]
16121612
pub enum CreationError {
16131613
/// The supplied description string was longer than 639 __bytes__ (see [`Description::new`])
@@ -1651,7 +1651,7 @@ impl Display for CreationError {
16511651
#[cfg(feature = "std")]
16521652
impl std::error::Error for CreationError { }
16531653

1654-
/// Errors that may occur when converting a [`RawInvoice`] to a [`Bolt11Invoice`]. They relate to
1654+
/// Errors that may occur when converting a [`RawBolt11Invoice`] to a [`Bolt11Invoice`]. They relate to
16551655
/// the requirements sections in BOLT #11
16561656
#[derive(Eq, PartialEq, Debug, Clone)]
16571657
pub enum SemanticError {
@@ -1760,10 +1760,10 @@ mod test {
17601760

17611761
#[test]
17621762
fn test_calc_invoice_hash() {
1763-
use crate::{RawInvoice, RawHrp, RawDataPart, Currency, PositiveTimestamp};
1763+
use crate::{RawBolt11Invoice, RawHrp, RawDataPart, Currency, PositiveTimestamp};
17641764
use crate::TaggedField::*;
17651765

1766-
let invoice = RawInvoice {
1766+
let invoice = RawBolt11Invoice {
17671767
hrp: RawHrp {
17681768
currency: Currency::Bitcoin,
17691769
raw_amount: None,
@@ -1797,11 +1797,11 @@ mod test {
17971797
use secp256k1::Secp256k1;
17981798
use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
17991799
use secp256k1::{SecretKey, PublicKey};
1800-
use crate::{SignedRawInvoice, InvoiceSignature, RawInvoice, RawHrp, RawDataPart, Currency, Sha256,
1800+
use crate::{SignedRawBolt11Invoice, InvoiceSignature, RawBolt11Invoice, RawHrp, RawDataPart, Currency, Sha256,
18011801
PositiveTimestamp};
18021802

1803-
let invoice = SignedRawInvoice {
1804-
raw_invoice: RawInvoice {
1803+
let invoice = SignedRawBolt11Invoice {
1804+
raw_invoice: RawBolt11Invoice {
18051805
hrp: RawHrp {
18061806
currency: Currency::Bitcoin,
18071807
raw_amount: None,
@@ -1866,12 +1866,12 @@ mod test {
18661866
use lightning::ln::features::InvoiceFeatures;
18671867
use secp256k1::Secp256k1;
18681868
use secp256k1::SecretKey;
1869-
use crate::{Bolt11Invoice, RawInvoice, RawHrp, RawDataPart, Currency, Sha256, PositiveTimestamp,
1869+
use crate::{Bolt11Invoice, RawBolt11Invoice, RawHrp, RawDataPart, Currency, Sha256, PositiveTimestamp,
18701870
SemanticError};
18711871

18721872
let private_key = SecretKey::from_slice(&[42; 32]).unwrap();
18731873
let payment_secret = lightning::ln::PaymentSecret([21; 32]);
1874-
let invoice_template = RawInvoice {
1874+
let invoice_template = RawBolt11Invoice {
18751875
hrp: RawHrp {
18761876
currency: Currency::Bitcoin,
18771877
raw_amount: None,

lightning-invoice/src/ser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use bech32::{ToBase32, u5, WriteBase32, Base32Len};
44
use crate::prelude::*;
55

66
use super::{Bolt11Invoice, Sha256, TaggedField, ExpiryTime, MinFinalCltvExpiryDelta, Fallback, PayeePubKey, InvoiceSignature, PositiveTimestamp,
7-
PrivateRoute, Description, RawTaggedField, Currency, RawHrp, SiPrefix, constants, SignedRawInvoice, RawDataPart};
7+
PrivateRoute, Description, RawTaggedField, Currency, RawHrp, SiPrefix, constants, SignedRawBolt11Invoice, RawDataPart};
88

99
/// Converts a stream of bytes written to it to base32. On finalization the according padding will
1010
/// be applied. That means the results of writing two data blocks with one or two `BytesToBase32`
@@ -112,7 +112,7 @@ impl Display for Bolt11Invoice {
112112
}
113113
}
114114

115-
impl Display for SignedRawInvoice {
115+
impl Display for SignedRawBolt11Invoice {
116116
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
117117
let hrp = self.raw_invoice.hrp.to_string();
118118
let mut data = self.raw_invoice.data.to_base32();

0 commit comments

Comments
 (0)