11use std:: borrow:: Cow ;
22use std:: convert:: TryFrom ;
3+ use std:: str:: FromStr ;
34
45use bitcoin:: address:: { Error , NetworkChecked , NetworkUnchecked } ;
56use bitcoin:: { Address , Amount , Network } ;
67use url:: Url ;
78
9+ use crate :: v2:: DecodeOhttpKeysError ;
810#[ cfg( feature = "v2" ) ]
911use crate :: OhttpKeys ;
1012
@@ -238,13 +240,10 @@ impl<'a> bip21::SerializeParams for &'a PayjoinExtras {
238240 ( "pjos" , if self . disable_output_substitution { "1" } else { "0" } . to_string( ) ) ,
239241 ] ;
240242 #[ 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) ) ;
243+ if let Some ( ohttp) = self . ohttp_keys . clone ( ) . map ( |ohttp_keys| ohttp_keys. to_string ( ) ) {
244+ params. push ( ( "ohttp" , ohttp) ) ;
246245 } else {
247- log:: warn!( "Failed to encode ohttp config , ignoring" ) ;
246+ log:: warn!( "No ohttp keys found , ignoring" ) ;
248247 }
249248 params. into_iter ( )
250249 }
@@ -266,13 +265,10 @@ impl<'a> bip21::de::DeserializationState<'a> for DeserializationState {
266265 match key {
267266 #[ cfg( feature = "v2" ) ]
268267 "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)
268+ let ohttp_encoded = Cow :: try_from ( value) . map_err ( InternalPjParseError :: NotUtf8 ) ?;
269+ let ohttp_keys = OhttpKeys :: from_str ( & ohttp_encoded)
274270 . map_err ( InternalPjParseError :: DecodeOhttpKeys ) ?;
275- self . ohttp = Some ( config ) ;
271+ self . ohttp = Some ( ohttp_keys ) ;
276272 Ok ( bip21:: de:: ParamKind :: Known )
277273 }
278274 #[ cfg( feature = "v2" ) ]
@@ -332,8 +328,6 @@ impl std::fmt::Display for PjParseError {
332328 }
333329 InternalPjParseError :: MissingEndpoint => write ! ( f, "Missing payjoin endpoint" ) ,
334330 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" ) ,
337331 InternalPjParseError :: BadEndpoint ( _) => write ! ( f, "Endpoint is not valid" ) ,
338332 #[ cfg( feature = "v2" ) ]
339333 InternalPjParseError :: DecodeOhttpKeys ( _) => write ! ( f, "ohttp config is not valid" ) ,
@@ -350,11 +344,9 @@ enum InternalPjParseError {
350344 MultipleParams ( & ' static str ) ,
351345 MissingEndpoint ,
352346 NotUtf8 ( core:: str:: Utf8Error ) ,
353- #[ cfg( feature = "v2" ) ]
354- NotBase64 ( bitcoin:: base64:: DecodeError ) ,
355347 BadEndpoint ( url:: ParseError ) ,
356348 #[ cfg( feature = "v2" ) ]
357- DecodeOhttpKeys ( ohttp :: Error ) ,
349+ DecodeOhttpKeys ( DecodeOhttpKeysError ) ,
358350 UnsecureEndpoint ,
359351}
360352
0 commit comments