Skip to content

Commit

Permalink
Work around '#' escaping bug in bip21 crate
Browse files Browse the repository at this point in the history
bip21 dependency temporarily specified to use bugfix PR branch

The `pj` parameter of the BIP 21 URL is itself a URL which contains a
fragment.

This is not escaped by bip21 during serialization, which according to
RFC 3986 truncates the `pj` parameter, making everything that follows
part of the fragment.

Deserialization likewise ignores #, parsing it as part of the value
which round trips with the incorrect serialization behavior.

Temporarily depend on bugfix pr branch for bip21
  • Loading branch information
nothingmuch committed Oct 23, 2024
1 parent a9b9a34 commit ba0378c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
3 changes: 1 addition & 2 deletions Cargo-minimal.lock
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ dependencies = [
[[package]]
name = "bip21"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebe7a7f5928d264879d5b65eb18a72ea1890c57f22d62ee2eba93f207a6a020b"
source = "git+https://github.com/Kixunil/bip21.git?rev=refs/pull/26/head#413f845cc1a77dc85592e1a41a87624826052e1d"
dependencies = [
"bitcoin",
"percent-encoding-rfc3986",
Expand Down
3 changes: 1 addition & 2 deletions Cargo-recent.lock
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ dependencies = [
[[package]]
name = "bip21"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebe7a7f5928d264879d5b65eb18a72ea1890c57f22d62ee2eba93f207a6a020b"
source = "git+https://github.com/Kixunil/bip21.git?rev=refs/pull/26/head#413f845cc1a77dc85592e1a41a87624826052e1d"
dependencies = [
"bitcoin",
"percent-encoding-rfc3986",
Expand Down
2 changes: 1 addition & 1 deletion payjoin-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ v2 = ["payjoin/v2", "payjoin/io"]
[dependencies]
anyhow = "1.0.70"
async-trait = "0.1"
bip21 = "0.5.0"
bip21 = { git = "https://github.com/Kixunil/bip21.git", rev = "refs/pull/26/head" }
bitcoincore-rpc = "0.19.0"
clap = { version = "~4.0.32", features = ["derive"] }
config = "0.13.3"
Expand Down
2 changes: 1 addition & 1 deletion payjoin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ danger-local-https = ["io", "reqwest/rustls-tls", "rustls"]

[dependencies]
bitcoin = { version = "0.32.2", features = ["base64"] }
bip21 = "0.5.0"
bip21 = { git = "https://github.com/Kixunil/bip21.git", rev = "refs/pull/26/head" }
hpke = { package = "bitcoin-hpke", version = "0.13.0", optional = true }
log = { version = "0.4.14"}
http = { version = "1", optional = true }
Expand Down
19 changes: 15 additions & 4 deletions payjoin/src/uri/url_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,20 @@ mod tests {
#[test]
fn test_valid_v2_url_fragment_on_bip21() {
let uri = "bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?amount=0.01\
&pj=https://example.com\
#ohttp%3DAQO6SMScPUqSo60A7MY6Ak2hDO0CGAxz7BLYp60syRu0gw";
let uri = Uri::try_from(uri).unwrap().assume_checked().check_pj_supported().unwrap();
assert!(uri.extras.endpoint().ohttp().is_some());
&pj=https://example.com/\
%23ohttp%3DAQO6SMScPUqSo60A7MY6Ak2hDO0CGAxz7BLYp60syRu0gw\
&pjos=0";
let pjuri = Uri::try_from(uri).unwrap().assume_checked().check_pj_supported().unwrap();

assert!(pjuri.extras.endpoint().ohttp().is_some());
assert_eq!(format!("{}", pjuri), uri);

let reordered = "bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?amount=0.01\
&pjos=0&pj=https://example.com/\
%23ohttp%3DAQO6SMScPUqSo60A7MY6Ak2hDO0CGAxz7BLYp60syRu0gw";
let pjuri =
Uri::try_from(reordered).unwrap().assume_checked().check_pj_supported().unwrap();
assert!(pjuri.extras.endpoint().ohttp().is_some());
assert_eq!(format!("{}", pjuri), uri);
}
}

0 comments on commit ba0378c

Please sign in to comment.