@@ -30,7 +30,7 @@ extern crate serde;
30
30
#[ cfg( feature = "std" ) ]
31
31
use std:: time:: SystemTime ;
32
32
33
- use bech32:: primitives:: decode:: CheckedHrpstringError ;
33
+ use bech32:: primitives:: decode:: { CheckedHrpstringError , UncheckedHrpstring } ;
34
34
use bech32:: Fe32 ;
35
35
use bitcoin:: hashes:: { sha256, Hash } ;
36
36
use bitcoin:: { Address , Network , PubkeyHash , ScriptHash , WitnessProgram , WitnessVersion } ;
@@ -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" ) ]
@@ -80,6 +81,10 @@ use crate::prelude::*;
80
81
pub use crate :: de:: FromBase32 ;
81
82
#[ cfg( fuzzing) ]
82
83
pub use crate :: ser:: Base32Iterable ;
84
+ #[ cfg( not( fuzzing) ) ]
85
+ use crate :: de:: FromBase32 ;
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.
@@ -1189,6 +1194,24 @@ impl RawBolt11Invoice {
1189
1194
pub fn currency ( & self ) -> Currency {
1190
1195
self . hrp . currency . clone ( )
1191
1196
}
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
+ }
1192
1215
}
1193
1216
1194
1217
impl PositiveTimestamp {
0 commit comments