From 1c4d1542fdc295b81657387c2f8167df9a68750d Mon Sep 17 00:00:00 2001 From: Yuval Kogman Date: Thu, 28 Nov 2024 02:17:14 +0100 Subject: [PATCH] Uppercase scheme and host in pj uri Also places the `pj` parameter last. Following this change and assuming the bip21 # escaping bug fix is merged, the alphanumeric encoding mode can be used for the entirety of the (% escaped) pj parameter. --- payjoin/src/uri/mod.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/payjoin/src/uri/mod.rs b/payjoin/src/uri/mod.rs index 7acf6853..a790d019 100644 --- a/payjoin/src/uri/mod.rs +++ b/payjoin/src/uri/mod.rs @@ -263,9 +263,19 @@ impl bip21::SerializeParams for &PayjoinExtras { type Iterator = std::vec::IntoIter<(Self::Key, Self::Value)>; fn serialize_params(self) -> Self::Iterator { + // normalizing to uppercase enables QR alphanumeric mode encoding + // unfortunately Url normalizes these to be lowercase + let scheme = self.endpoint.scheme(); + let host = self.endpoint.host_str().expect("host must be set"); + let endpoint_str = self + .endpoint + .as_str() + .replacen(scheme, &scheme.to_uppercase(), 1) + .replacen(host, &host.to_uppercase(), 1); + vec![ - ("pj", self.endpoint.as_str().to_string()), ("pjos", if self.disable_output_substitution { "1" } else { "0" }.to_string()), + ("pj", endpoint_str), ] .into_iter() }