From 098881e9db6203f5b3e26b9adc99b4fa958dd530 Mon Sep 17 00:00:00 2001 From: esraa Date: Mon, 1 Jul 2024 17:56:39 +0300 Subject: [PATCH 1/2] Dont display `ResponseError::Validation` error.. ..to end users. --- payjoin/src/send/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/payjoin/src/send/error.rs b/payjoin/src/send/error.rs index ab76d9e9..69a3f1a8 100644 --- a/payjoin/src/send/error.rs +++ b/payjoin/src/send/error.rs @@ -351,7 +351,7 @@ impl Display for ResponseError { Self::WellKnown(e) => e.fmt(f), // Don't display unknowns to end users, only debug logs Self::Unrecognized { .. } => write!(f, "The receiver sent an unrecognized error."), - Self::Validation(e) => write!(f, "The receiver sent an invalid response: {}", e), + Self::Validation(_) => write!(f, "The receiver sent an invalid response."), } } } From 68c2e4f9ec9d7dfbf97ddc64d7c28def2dc6caf3 Mon Sep 17 00:00:00 2001 From: jbesraa Date: Wed, 26 Jun 2024 21:22:54 +0300 Subject: [PATCH 2/2] Rewrite `send::error::ResponseError` docs --- payjoin/src/send/error.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/payjoin/src/send/error.rs b/payjoin/src/send/error.rs index 69a3f1a8..fad708d9 100644 --- a/payjoin/src/send/error.rs +++ b/payjoin/src/send/error.rs @@ -269,19 +269,24 @@ impl From for CreateRequestError { fn from(value: InternalCreateRequestError) -> Self { CreateRequestError(value) } } -/// Represent an error returned by the receiver. +/// Represent an error returned by Payjoin receiver. pub enum ResponseError { - /// `WellKnown` errors following the BIP78 spec - /// https://github.com/bitcoin/bips/blob/master/bip-0078.mediawiki#user-content-Receivers_well_known_errors - /// These errors are displayed to end users. + /// `WellKnown` Errors are defined in the [`BIP78::ReceiverWellKnownError`] spec. /// - /// The `WellKnownError` represents `errorCode` and `message`. + /// It is safe to display `WellKnown` errors to end users. + /// + /// [`BIP78::ReceiverWellKnownError`]: https://github.com/bitcoin/bips/blob/master/bip-0078.mediawiki#user-content-Receivers_well_known_errors WellKnown(WellKnownError), - /// `Unrecognized` errors are errors that are not well known and are only displayed in debug logs. - /// They are not displayed to end users. + /// `Unrecognized` Errors are NOT defined in the [`BIP78::ReceiverWellKnownError`] spec. + /// + /// Its not safe to display `Unrecognized` errors to end users as they could be used + /// maliciously to phish a non technical user. Only display them in debug logs. + /// + /// [`BIP78::ReceiverWellKnownError`]: https://github.com/bitcoin/bips/blob/master/bip-0078.mediawiki#user-content-Receivers_well_known_errors Unrecognized { error_code: String, message: String }, - /// `Validation` errors are errors that are caused by malformed responses. - /// They are only displayed in debug logs. + /// Errors caused by malformed responses. + /// + /// These errors are only displayed in debug logs. Validation(ValidationError), } @@ -445,7 +450,7 @@ mod tests { }); assert_eq!( ResponseError::from_json(invalid_json_error).to_string(), - "The receiver sent an invalid response: couldn't decode as PSBT or JSON" + "The receiver sent an invalid response." ); } }