11use std:: borrow:: Cow ;
22use std:: convert:: TryFrom ;
3+ #[ cfg( feature = "v2" ) ]
4+ use std:: str:: FromStr ;
35
46use bitcoin:: address:: { Error , NetworkChecked , NetworkUnchecked } ;
57use bitcoin:: { Address , Amount , Network } ;
68use url:: Url ;
79
10+ #[ cfg( feature = "v2" ) ]
11+ use crate :: v2:: DecodeOhttpKeysError ;
812#[ cfg( feature = "v2" ) ]
913use crate :: OhttpKeys ;
1014
@@ -238,13 +242,10 @@ impl<'a> bip21::SerializeParams for &'a PayjoinExtras {
238242 ( "pjos" , if self . disable_output_substitution { "1" } else { "0" } . to_string( ) ) ,
239243 ] ;
240244 #[ cfg( feature = "v2" ) ]
241- if let Some ( ohttp_keys) = self . ohttp_keys . clone ( ) . and_then ( |c| c. encode ( ) . ok ( ) ) {
242- let config =
243- bitcoin:: base64:: Config :: new ( bitcoin:: base64:: CharacterSet :: UrlSafe , false ) ;
244- let base64_ohttp_keys = bitcoin:: base64:: encode_config ( ohttp_keys, config) ;
245- params. push ( ( "ohttp" , base64_ohttp_keys) ) ;
245+ if let Some ( ohttp) = self . ohttp_keys . clone ( ) . map ( |ohttp_keys| ohttp_keys. to_string ( ) ) {
246+ params. push ( ( "ohttp" , ohttp) ) ;
246247 } else {
247- log:: warn!( "Failed to encode ohttp config , ignoring" ) ;
248+ log:: warn!( "No ohttp keys found , ignoring" ) ;
248249 }
249250 params. into_iter ( )
250251 }
@@ -266,13 +267,10 @@ impl<'a> bip21::de::DeserializationState<'a> for DeserializationState {
266267 match key {
267268 #[ cfg( feature = "v2" ) ]
268269 "ohttp" if self . ohttp . is_none ( ) => {
269- let base64_config = Cow :: try_from ( value) . map_err ( InternalPjParseError :: NotUtf8 ) ?;
270- let config_bytes =
271- bitcoin:: base64:: decode_config ( & * base64_config, bitcoin:: base64:: URL_SAFE )
272- . map_err ( InternalPjParseError :: NotBase64 ) ?;
273- let config = OhttpKeys :: decode ( & config_bytes)
270+ let ohttp_encoded = Cow :: try_from ( value) . map_err ( InternalPjParseError :: NotUtf8 ) ?;
271+ let ohttp_keys = OhttpKeys :: from_str ( & ohttp_encoded)
274272 . map_err ( InternalPjParseError :: DecodeOhttpKeys ) ?;
275- self . ohttp = Some ( config ) ;
273+ self . ohttp = Some ( ohttp_keys ) ;
276274 Ok ( bip21:: de:: ParamKind :: Known )
277275 }
278276 #[ cfg( feature = "v2" ) ]
@@ -332,8 +330,6 @@ impl std::fmt::Display for PjParseError {
332330 }
333331 InternalPjParseError :: MissingEndpoint => write ! ( f, "Missing payjoin endpoint" ) ,
334332 InternalPjParseError :: NotUtf8 ( _) => write ! ( f, "Endpoint is not valid UTF-8" ) ,
335- #[ cfg( feature = "v2" ) ]
336- InternalPjParseError :: NotBase64 ( _) => write ! ( f, "ohttp config is not valid base64" ) ,
337333 InternalPjParseError :: BadEndpoint ( _) => write ! ( f, "Endpoint is not valid" ) ,
338334 #[ cfg( feature = "v2" ) ]
339335 InternalPjParseError :: DecodeOhttpKeys ( _) => write ! ( f, "ohttp config is not valid" ) ,
@@ -350,11 +346,9 @@ enum InternalPjParseError {
350346 MultipleParams ( & ' static str ) ,
351347 MissingEndpoint ,
352348 NotUtf8 ( core:: str:: Utf8Error ) ,
353- #[ cfg( feature = "v2" ) ]
354- NotBase64 ( bitcoin:: base64:: DecodeError ) ,
355349 BadEndpoint ( url:: ParseError ) ,
356350 #[ cfg( feature = "v2" ) ]
357- DecodeOhttpKeys ( ohttp :: Error ) ,
351+ DecodeOhttpKeys ( DecodeOhttpKeysError ) ,
358352 UnsecureEndpoint ,
359353}
360354
0 commit comments