@@ -48,6 +48,7 @@ use core::iter::FilterMap;
48
48
use core:: num:: ParseIntError ;
49
49
use core:: ops:: Deref ;
50
50
use core:: slice:: Iter ;
51
+ use core:: str:: FromStr ;
51
52
use core:: time:: Duration ;
52
53
53
54
#[ cfg( feature = "serde" ) ]
@@ -78,8 +79,12 @@ use crate::prelude::*;
78
79
/// Re-export serialization traits
79
80
#[ cfg( fuzzing) ]
80
81
pub use crate :: de:: FromBase32 ;
82
+ #[ cfg( not( fuzzing) ) ]
83
+ use crate :: de:: FromBase32 ;
81
84
#[ cfg( fuzzing) ]
82
85
pub use crate :: ser:: Base32Iterable ;
86
+ #[ cfg( not( fuzzing) ) ]
87
+ use crate :: ser:: Base32Iterable ;
83
88
84
89
/// Errors that indicate what is wrong with the invoice. They have some granularity for debug
85
90
/// reasons, but should generally result in an "invalid BOLT11 invoice" message for the user.
@@ -1086,9 +1091,6 @@ impl RawBolt11Invoice {
1086
1091
1087
1092
/// Calculate the hash of the encoded `RawBolt11Invoice` which should be signed.
1088
1093
pub fn signable_hash ( & self ) -> [ u8 ; 32 ] {
1089
- #[ cfg( not( fuzzing) ) ]
1090
- use crate :: ser:: Base32Iterable ;
1091
-
1092
1094
Self :: hash_from_parts ( self . hrp . to_string ( ) . as_bytes ( ) , self . data . fe_iter ( ) )
1093
1095
}
1094
1096
@@ -1189,6 +1191,21 @@ impl RawBolt11Invoice {
1189
1191
pub fn currency ( & self ) -> Currency {
1190
1192
self . hrp . currency . clone ( )
1191
1193
}
1194
+
1195
+ /// Convert to HRP prefix and Fe32 encoded data part.
1196
+ /// Can be used to transmit unsigned invoices for remote signing.
1197
+ pub fn to_raw ( & self ) -> ( String , Vec < Fe32 > ) {
1198
+ ( self . hrp . to_string ( ) , self . data . fe_iter ( ) . collect ( ) )
1199
+ }
1200
+
1201
+ /// Convert from HRP prefix and Fe32 encoded data part.
1202
+ /// Can be used to receive unsigned invoices for remote signing.
1203
+ pub fn from_raw ( hrp : & str , data : & [ Fe32 ] ) -> Result < Self , Bolt11ParseError > {
1204
+ let raw_hrp: RawHrp = RawHrp :: from_str ( hrp) ?;
1205
+ let data_part = RawDataPart :: from_base32 ( data) ?;
1206
+
1207
+ Ok ( Self { hrp : raw_hrp, data : data_part } )
1208
+ }
1192
1209
}
1193
1210
1194
1211
impl PositiveTimestamp {
0 commit comments