25
25
#[ cfg( not( any( feature = "std" , feature = "no-std" ) ) ) ]
26
26
compile_error ! ( "at least one of the `std` or `no-std` features must be enabled" ) ;
27
27
28
- pub mod payment;
29
- pub mod utils;
30
-
31
28
extern crate bech32;
32
- # [ macro_use ] extern crate lightning ;
29
+ extern crate lightning_types ;
33
30
extern crate secp256k1;
34
31
extern crate alloc;
35
32
#[ cfg( any( test, feature = "std" ) ) ]
@@ -40,12 +37,11 @@ extern crate serde;
40
37
#[ cfg( feature = "std" ) ]
41
38
use std:: time:: SystemTime ;
42
39
43
- use bech32:: u5 ;
40
+ use bech32:: { FromBase32 , u5 } ;
44
41
use bitcoin:: { Address , Network , PubkeyHash , ScriptHash , WitnessProgram , WitnessVersion } ;
45
42
use bitcoin:: address:: Payload ;
46
43
use bitcoin:: hashes:: { Hash , sha256} ;
47
- use lightning:: ln:: features:: Bolt11InvoiceFeatures ;
48
- use lightning:: util:: invoice:: construct_invoice_preimage;
44
+ use lightning_types:: features:: Bolt11InvoiceFeatures ;
49
45
50
46
use secp256k1:: PublicKey ;
51
47
use secp256k1:: { Message , Secp256k1 } ;
@@ -64,12 +60,10 @@ use core::str;
64
60
use serde:: { Deserialize , Deserializer , Serialize , Serializer , de:: Error } ;
65
61
66
62
#[ 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 ;
70
64
#[ 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 ;
73
67
74
68
mod de;
75
69
mod ser;
@@ -139,19 +133,16 @@ pub const DEFAULT_EXPIRY_TIME: u64 = 3600;
139
133
140
134
/// Default minimum final CLTV expiry as defined by [BOLT 11].
141
135
///
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.
144
137
///
145
138
/// [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
147
139
pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA : u64 = 18 ;
148
140
149
141
/// Builder for [`Bolt11Invoice`]s. It's the most convenient and advised way to use this library. It
150
142
/// ensures that only a semantically and syntactically correct invoice can be built using it.
151
143
///
152
144
/// ```
153
145
/// extern crate secp256k1;
154
- /// extern crate lightning;
155
146
/// extern crate lightning_invoice;
156
147
/// extern crate bitcoin;
157
148
///
@@ -161,7 +152,7 @@ pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA: u64 = 18;
161
152
/// use secp256k1::Secp256k1;
162
153
/// use secp256k1::SecretKey;
163
154
///
164
- /// use lightning::ln::types ::PaymentSecret;
155
+ /// use lightning_types::payment ::PaymentSecret;
165
156
///
166
157
/// use lightning_invoice::{Currency, InvoiceBuilder};
167
158
///
@@ -970,7 +961,23 @@ macro_rules! find_all_extract {
970
961
impl RawBolt11Invoice {
971
962
/// Hash the HRP as bytes and signatureless data part.
972
963
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
+
974
981
let mut hash: [ u8 ; 32 ] = Default :: default ( ) ;
975
982
hash. copy_from_slice ( & sha256:: Hash :: hash ( & preimage) [ ..] ) ;
976
983
hash
@@ -1636,15 +1643,12 @@ pub enum CreationError {
1636
1643
/// The supplied millisatoshi amount was greater than the total bitcoin supply.
1637
1644
InvalidAmount ,
1638
1645
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.
1643
1649
MissingRouteHints ,
1644
1650
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.
1648
1652
MinFinalCltvExpiryDeltaTooShort ,
1649
1653
}
1650
1654
@@ -1877,14 +1881,14 @@ mod test {
1877
1881
#[ test]
1878
1882
fn test_check_feature_bits ( ) {
1879
1883
use crate :: TaggedField :: * ;
1880
- use lightning :: ln :: features:: Bolt11InvoiceFeatures ;
1884
+ use lightning_types :: features:: Bolt11InvoiceFeatures ;
1881
1885
use secp256k1:: Secp256k1 ;
1882
1886
use secp256k1:: SecretKey ;
1883
1887
use crate :: { Bolt11Invoice , RawBolt11Invoice , RawHrp , RawDataPart , Currency , Sha256 , PositiveTimestamp ,
1884
1888
Bolt11SemanticError } ;
1885
1889
1886
1890
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 ] ) ;
1888
1892
let invoice_template = RawBolt11Invoice {
1889
1893
hrp : RawHrp {
1890
1894
currency : Currency :: Bitcoin ,
@@ -1998,7 +2002,7 @@ mod test {
1998
2002
#[ test]
1999
2003
fn test_builder_fail ( ) {
2000
2004
use crate :: * ;
2001
- use lightning :: routing:: router :: RouteHintHop ;
2005
+ use lightning_types :: routing:: RouteHintHop ;
2002
2006
use std:: iter:: FromIterator ;
2003
2007
use secp256k1:: PublicKey ;
2004
2008
@@ -2052,7 +2056,7 @@ mod test {
2052
2056
#[ test]
2053
2057
fn test_builder_ok ( ) {
2054
2058
use crate :: * ;
2055
- use lightning :: routing:: router :: RouteHintHop ;
2059
+ use lightning_types :: routing:: RouteHintHop ;
2056
2060
use secp256k1:: Secp256k1 ;
2057
2061
use secp256k1:: { SecretKey , PublicKey } ;
2058
2062
use std:: time:: Duration ;
0 commit comments