payjoin / rust-payjoin

Supercharged payment batching to save you fees and preserve your privacy
https://payjoindevkit.org
85 stars 36 forks source link

Encode `&ohttp=` and `&exp=` parameters in the `&pj=` URL as a fragment instead of top-level bip21 params. #298

Closed DanGould closed 2 months ago

DanGould commented 3 months ago

Right now Payjoin V2 encodes &ohttp= and &exp= as bip21 URI query keys since that seemed natural as bip78 used them for &pjos=. However, this may present a few problems down the line.

Instead of bip21 URI query keys like this

bitcoin:tb1qamy39l62neydk8hmvcfhzewpp3n906d2y335rd?pjos=0&pj=https://payjo.in/AoMhJgAzb-5vB7XspWSTbCaa2vkpucHZ6n2ZixU7vwY8&ohttp=AQAgbLIT3-hgHP5dAGB574bdCyTeJvJR4n7hLJ4B8dxgYDMABAABAAM&exp=1719258352

They should be percent-encoded as fragment paramerters in the &pj= url:

bitcoin:tb1qamy39l62neydk8hmvcfhzewpp3n906d2y335rd?pjos=0&pj=https://payjo.in/AoMhJgAzb-5vB7XspWSTbCaa2vkpucHZ6n2ZixU7vwY8%23ohttp%3DAQAgbLIT3-hgHP5dAGB574bdCyTeJvJR4n7hLJ4B8dxgYDMABAABAAM%26exp%3D1719258352

This solves problems.

  1. BIP21 parsers would otherwise need to update to support the new ohttp and exp parameters. URL parsers already parse the fragment out of a URL.
  2. QR encoders can encode everything in the &pj= parameter in alphanumeric mode which is more dense but excludes '?', '=', '&'. Each time bip21 uri params switch therefore, the QR encoded incurs overhead to switch between alphanumeric and bytes mode which can be more costly than the advantage.
  3. This stops introducing a precedence problem where multiple bip21 params could be used by conflicting protocols

To be done as part of #216