Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse and set ohttp= parameter from pj URL fragment #300

Merged
merged 5 commits into from
Jul 11, 2024

Conversation

DanGould
Copy link
Contributor

@DanGould DanGould commented Jun 24, 2024

Close #298

This introduces a Url extension trait called payjoin::uri::UrlExt which can set and get ohttp= as a fragment rather than a URI parameter. Doing so allows BIP 77 payjoin v2 parameters to be compliant with any BIP 21 bitcoin URI parser that already supports &pj= without introducing new params. This seems to simplify the v1/v2 feature gates too.

This change also handles subdirectory parsing differently since the URL no longer ends with the subdirectory, but also the fragment. This introduces new V2 errors. On my first attempt I added subdirectory parsing and setting to UrlExt, but opted to remove that since it's out of scope for fragment handling and it would probably need to be considered to be feature gated behind send/receive which could make the uri module messier. (But also perhaps not since UriExt is private and send/receive gates can be enforced in those higher module abstractions where UriExt is depended upon).

The UriExt is unit tested.

I'm not sure how to best handle the difference between Ul paths with or without a trailing slash. Technically the latter is a true subdirectory but for our purposes, we're actually using HTTP endpoints that don't differentiate. Our parser should probably prefer one to another. I'm inclined to prefer fewer characters for simplicity.

e.g.

https://localhost:53429/A8xaMow612_1aiU15nyhQz0RorgIegqftrT7Yo19xKWc#ohttp=AQAgJLHcnSjkWH3Qc6ix2GOSPdyPH3OSu0-YL3NPbLd2Dx8ABAABAAM

vs

https://localhost:53429/A8xaMow612_1aiU15nyhQz0RorgIegqftrT7Yo19xKWc/#ohttp=AQAgJLHcnSjkWH3Qc6ix2GOSPdyPH3OSu0-YL3NPbLd2Dx8ABAABAAM

This was done as prerequisite to #299 since I believe exp should be a payjoin-specific fragment parameter as well that gets added to UriExt

@DanGould DanGould changed the title Fragment Parse and set ohttp= parameter from pj URL fragment Jun 25, 2024
@DanGould DanGould added the api label Jun 26, 2024
@DanGould DanGould force-pushed the fragment branch 5 times, most recently from 9f0e415 to 101c429 Compare June 27, 2024 04:16
@DanGould DanGould mentioned this pull request Jun 29, 2024
DanGould added a commit that referenced this pull request Jul 2, 2024
Refactor `OhttpKeys` so that #300 can just focus on semantics.

- First Commit removes a clippy warning
- 2nd reduces unnecessary base64 verbosity. base64 dependency was being
used where psbt.to_string was fine, and the custom configs were being
built where confs could do
- 3rd removes a vestigial PartialEq implementation
- 4th disambiguates `Display` and `Serialize` roles. [OHTTP KeyConfigs
encoding](https://www.ietf.org/rfc/rfc9458.html#name-key-configuration-encoding)
for serialization is well specified by the rfc. We're using string
representations in URLs and configs just for Payjoin V2 which is a
separate thing
@DanGould DanGould force-pushed the fragment branch 5 times, most recently from 0bbef22 to b2c5127 Compare July 8, 2024 17:28
@DanGould DanGould marked this pull request as ready for review July 8, 2024 17:35
@DanGould DanGould requested a review from spacebear21 July 8, 2024 18:53
Copy link
Collaborator

@spacebear21 spacebear21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. It would be helpful to add a unit test that parses a full BIP21 URI, in addition to just the pj URL. Specifically, a BIP21 URI with multiple parameters and & separators to validate the logic in set_ohttp

payjoin/src/send/error.rs Outdated Show resolved Hide resolved
payjoin/src/uri/error.rs Outdated Show resolved Hide resolved
@DanGould
Copy link
Contributor Author

DanGould commented Jul 9, 2024

Thanks for the approval but this is probably still not the correct abstraction, which is why I haven't re-requested review (I don't think I did at least).

I wrote the tests you recommended locally and they would fail because this doesn't yet percent-encode the fragment '=' and '&' characters. They conflict with the bip21 params. So I think that such tess should be working to justify our new abstraction before it's merged

DanGould added 2 commits July 11, 2024 13:55
This extension trait defines functions to parse and set the ohttp parameter
in the fragment of a `pj=` URL.

Close payjoin#298
Copy link
Collaborator

@spacebear21 spacebear21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK e97238a

@DanGould DanGould merged commit 87f9f06 into payjoin:master Jul 11, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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