2525#[ cfg( not( any( feature = "std" , feature = "no-std" ) ) ) ]
2626compile_error ! ( "at least one of the `std` or `no-std` features must be enabled" ) ;
2727
28- pub mod payment;
29- pub mod utils;
30-
3128extern crate bech32;
32- # [ macro_use ] extern crate lightning ;
29+ extern crate lightning_types ;
3330extern crate secp256k1;
3431extern crate alloc;
3532#[ cfg( any( test, feature = "std" ) ) ]
@@ -40,12 +37,11 @@ extern crate serde;
4037#[ cfg( feature = "std" ) ]
4138use std:: time:: SystemTime ;
4239
43- use bech32:: u5 ;
40+ use bech32:: { FromBase32 , u5 } ;
4441use bitcoin:: { Address , Network , PubkeyHash , ScriptHash , WitnessProgram , WitnessVersion } ;
4542use bitcoin:: address:: Payload ;
4643use bitcoin:: hashes:: { Hash , sha256} ;
47- use lightning:: ln:: features:: Bolt11InvoiceFeatures ;
48- use lightning:: util:: invoice:: construct_invoice_preimage;
44+ use lightning_types:: features:: Bolt11InvoiceFeatures ;
4945
5046use secp256k1:: PublicKey ;
5147use secp256k1:: { Message , Secp256k1 } ;
@@ -64,12 +60,10 @@ use core::str;
6460use serde:: { Deserialize , Deserializer , Serialize , Serializer , de:: Error } ;
6561
6662#[ doc( no_inline) ]
67- pub use lightning:: ln:: types:: PaymentSecret ;
68- #[ doc( no_inline) ]
69- pub use lightning:: routing:: router:: { RouteHint , RouteHintHop } ;
63+ pub use lightning_types:: payment:: PaymentSecret ;
7064#[ doc( no_inline) ]
71- pub use lightning :: routing:: gossip :: RoutingFees ;
72- use lightning :: util :: string:: UntrustedString ;
65+ pub use lightning_types :: routing:: { RoutingFees , RouteHint , RouteHintHop } ;
66+ use lightning_types :: string:: UntrustedString ;
7367
7468mod de;
7569mod ser;
@@ -139,19 +133,16 @@ pub const DEFAULT_EXPIRY_TIME: u64 = 3600;
139133
140134/// Default minimum final CLTV expiry as defined by [BOLT 11].
141135///
142- /// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is
143- /// provided in [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
136+ /// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry.
144137///
145138/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
146- /// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
147139pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA : u64 = 18 ;
148140
149141/// Builder for [`Bolt11Invoice`]s. It's the most convenient and advised way to use this library. It
150142/// ensures that only a semantically and syntactically correct invoice can be built using it.
151143///
152144/// ```
153145/// extern crate secp256k1;
154- /// extern crate lightning;
155146/// extern crate lightning_invoice;
156147/// extern crate bitcoin;
157148///
@@ -161,7 +152,7 @@ pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA: u64 = 18;
161152/// use secp256k1::Secp256k1;
162153/// use secp256k1::SecretKey;
163154///
164- /// use lightning::ln::types ::PaymentSecret;
155+ /// use lightning_types::payment ::PaymentSecret;
165156///
166157/// use lightning_invoice::{Currency, InvoiceBuilder};
167158///
@@ -970,7 +961,23 @@ macro_rules! find_all_extract {
970961impl RawBolt11Invoice {
971962 /// Hash the HRP as bytes and signatureless data part.
972963 fn hash_from_parts ( hrp_bytes : & [ u8 ] , data_without_signature : & [ u5 ] ) -> [ u8 ; 32 ] {
973- let preimage = construct_invoice_preimage ( hrp_bytes, data_without_signature) ;
964+ let mut preimage = Vec :: < u8 > :: from ( hrp_bytes) ;
965+
966+ let mut data_part = Vec :: from ( data_without_signature) ;
967+ let overhang = ( data_part. len ( ) * 5 ) % 8 ;
968+ if overhang > 0 {
969+ // add padding if data does not end at a byte boundary
970+ data_part. push ( u5:: try_from_u8 ( 0 ) . unwrap ( ) ) ;
971+
972+ // if overhang is in (1..3) we need to add u5(0) padding two times
973+ if overhang < 3 {
974+ data_part. push ( u5:: try_from_u8 ( 0 ) . unwrap ( ) ) ;
975+ }
976+ }
977+
978+ preimage. extend_from_slice ( & Vec :: < u8 > :: from_base32 ( & data_part)
979+ . expect ( "No padding error may occur due to appended zero above." ) ) ;
980+
974981 let mut hash: [ u8 ; 32 ] = Default :: default ( ) ;
975982 hash. copy_from_slice ( & sha256:: Hash :: hash ( & preimage) [ ..] ) ;
976983 hash
@@ -1636,15 +1643,12 @@ pub enum CreationError {
16361643 /// The supplied millisatoshi amount was greater than the total bitcoin supply.
16371644 InvalidAmount ,
16381645
1639- /// Route hints were required for this invoice and were missing. Applies to
1640- /// [phantom invoices].
1641- ///
1642- /// [phantom invoices]: crate::utils::create_phantom_invoice
1646+ // TODO: These two errors are really errors with things in the `lightning` crate and thus
1647+ // shouldn't live here.
1648+ /// Route hints were required for this invoice and were missing.
16431649 MissingRouteHints ,
16441650
1645- /// The provided `min_final_cltv_expiry_delta` was less than [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
1646- ///
1647- /// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
1651+ /// The provided `min_final_cltv_expiry_delta` was less than rust-lightning's minimum.
16481652 MinFinalCltvExpiryDeltaTooShort ,
16491653}
16501654
@@ -1877,14 +1881,14 @@ mod test {
18771881 #[ test]
18781882 fn test_check_feature_bits ( ) {
18791883 use crate :: TaggedField :: * ;
1880- use lightning :: ln :: features:: Bolt11InvoiceFeatures ;
1884+ use lightning_types :: features:: Bolt11InvoiceFeatures ;
18811885 use secp256k1:: Secp256k1 ;
18821886 use secp256k1:: SecretKey ;
18831887 use crate :: { Bolt11Invoice , RawBolt11Invoice , RawHrp , RawDataPart , Currency , Sha256 , PositiveTimestamp ,
18841888 Bolt11SemanticError } ;
18851889
18861890 let private_key = SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ;
1887- let payment_secret = lightning :: ln :: types :: PaymentSecret ( [ 21 ; 32 ] ) ;
1891+ let payment_secret = lightning_types :: payment :: PaymentSecret ( [ 21 ; 32 ] ) ;
18881892 let invoice_template = RawBolt11Invoice {
18891893 hrp : RawHrp {
18901894 currency : Currency :: Bitcoin ,
@@ -1998,7 +2002,7 @@ mod test {
19982002 #[ test]
19992003 fn test_builder_fail ( ) {
20002004 use crate :: * ;
2001- use lightning :: routing:: router :: RouteHintHop ;
2005+ use lightning_types :: routing:: RouteHintHop ;
20022006 use std:: iter:: FromIterator ;
20032007 use secp256k1:: PublicKey ;
20042008
@@ -2052,7 +2056,7 @@ mod test {
20522056 #[ test]
20532057 fn test_builder_ok ( ) {
20542058 use crate :: * ;
2055- use lightning :: routing:: router :: RouteHintHop ;
2059+ use lightning_types :: routing:: RouteHintHop ;
20562060 use secp256k1:: Secp256k1 ;
20572061 use secp256k1:: { SecretKey , PublicKey } ;
20582062 use std:: time:: Duration ;
0 commit comments