@@ -30,7 +30,7 @@ extern crate serde;
3030#[ cfg( feature = "std" ) ]
3131use std:: time:: SystemTime ;
3232
33- use bech32:: primitives:: decode:: CheckedHrpstringError ;
33+ use bech32:: primitives:: decode:: { CheckedHrpstringError , UncheckedHrpstring } ;
3434use bech32:: Fe32 ;
3535use bitcoin:: hashes:: { sha256, Hash } ;
3636use bitcoin:: { Address , Network , PubkeyHash , ScriptHash , WitnessProgram , WitnessVersion } ;
@@ -48,6 +48,7 @@ use core::iter::FilterMap;
4848use core:: num:: ParseIntError ;
4949use core:: ops:: Deref ;
5050use core:: slice:: Iter ;
51+ use core:: str:: FromStr ;
5152use core:: time:: Duration ;
5253
5354#[ cfg( feature = "serde" ) ]
@@ -80,6 +81,10 @@ use crate::prelude::*;
8081pub use crate :: de:: FromBase32 ;
8182#[ cfg( fuzzing) ]
8283pub use crate :: ser:: Base32Iterable ;
84+ #[ cfg( not( fuzzing) ) ]
85+ use crate :: de:: FromBase32 ;
86+ #[ cfg( not( fuzzing) ) ]
87+ use crate :: ser:: Base32Iterable ;
8388
8489/// Errors that indicate what is wrong with the invoice. They have some granularity for debug
8590/// reasons, but should generally result in an "invalid BOLT11 invoice" message for the user.
@@ -1189,6 +1194,24 @@ impl RawBolt11Invoice {
11891194 pub fn currency ( & self ) -> Currency {
11901195 self . hrp . currency . clone ( )
11911196 }
1197+
1198+ /// Convert to HRP prefix and Fe32 encoded data part.
1199+ /// Can be used to transmit unsigned invoices for remote signing.
1200+ pub fn to_raw ( & self ) -> ( String , Vec < Fe32 > ) {
1201+ ( self . hrp . to_string ( ) , self . data . fe_iter ( ) . collect ( ) )
1202+ }
1203+
1204+ /// Convert from HRP prefix and Fe32 encoded data part.
1205+ /// Can be used to receive unsigned invoices for remote signing.
1206+ pub fn from_raw ( hrp : & str , data : & [ Fe32 ] ) -> Result < Self , Bolt11ParseError > {
1207+ let raw_hrp: RawHrp = RawHrp :: from_str ( hrp) ?;
1208+ let data_part = RawDataPart :: from_base32 ( data) ?;
1209+
1210+ Ok ( Self {
1211+ hrp : raw_hrp,
1212+ data : data_part,
1213+ } )
1214+ }
11921215}
11931216
11941217impl PositiveTimestamp {
0 commit comments