From d9fea6f848d331cb2179ec40dab78c4430e25c4d Mon Sep 17 00:00:00 2001 From: DanGould Date: Mon, 20 Jan 2025 13:15:33 -0500 Subject: [PATCH 1/6] Axe `send`, `receive` feature separation These features were separated when v1 was first-class, but is not relevant with v2 being first-class, since the server hosting constraint was removed by the design of v2. All downstream implementations I am aware of are interested in implementing both send and receive features. Close #393 --- contrib/coverage.sh | 2 +- contrib/lint.sh | 2 +- flake.nix | 2 +- payjoin-cli/Cargo.toml | 2 +- payjoin/Cargo.toml | 4 +--- payjoin/src/hpke.rs | 4 ---- payjoin/src/lib.rs | 5 ----- payjoin/tests/integration.rs | 1 - 8 files changed, 5 insertions(+), 17 deletions(-) diff --git a/contrib/coverage.sh b/contrib/coverage.sh index 73a8e79b8..261165a7c 100755 --- a/contrib/coverage.sh +++ b/contrib/coverage.sh @@ -3,6 +3,6 @@ set -e # https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#merge-coverages-generated-under-different-test-conditions cargo llvm-cov clean --workspace # remove artifacts that may affect the coverage results -cargo llvm-cov --no-report --features=send,receive +cargo llvm-cov --no-report # v1 configuration cargo llvm-cov --no-report --features=v2,_danger-local-https,io cargo llvm-cov report --lcov --output-path lcov.info # generate report without tests diff --git a/contrib/lint.sh b/contrib/lint.sh index 5660a8b17..8f26acd91 100755 --- a/contrib/lint.sh +++ b/contrib/lint.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash set -e -cargo clippy --all-targets --keep-going --features=send,receive -- -D warnings +cargo clippy --all-targets --keep-going -- -D warnings # v1 configuration cargo clippy --all-targets --keep-going --features=v2,_danger-local-https,io -- -D warnings diff --git a/flake.nix b/flake.nix index 020633ef5..b14fcecc1 100644 --- a/flake.nix +++ b/flake.nix @@ -88,7 +88,7 @@ inherit src; }) ) { - "payjoin" = "--features v2,send,receive"; + "payjoin" = "--features v2"; "payjoin-cli" = "--features v1,v2"; "payjoin-directory" = ""; }; diff --git a/payjoin-cli/Cargo.toml b/payjoin-cli/Cargo.toml index b0aba6d3e..72af889c0 100644 --- a/payjoin-cli/Cargo.toml +++ b/payjoin-cli/Cargo.toml @@ -37,7 +37,7 @@ hyper = { version = "1", features = ["http1", "server"], optional = true } hyper-rustls = { version = "0.26", optional = true } hyper-util = { version = "0.1", optional = true } log = "0.4.7" -payjoin = { version = "0.22.0", features = ["send", "receive", "base64"] } +payjoin = { version = "0.22.0", features = ["base64"] } rcgen = { version = "0.11.1", optional = true } reqwest = { version = "0.12", default-features = false } rustls = { version = "0.22.4", optional = true } diff --git a/payjoin/Cargo.toml b/payjoin/Cargo.toml index fb243123e..d9a61cc87 100644 --- a/payjoin/Cargo.toml +++ b/payjoin/Cargo.toml @@ -16,8 +16,6 @@ exclude = ["tests"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -send = [] -receive = ["bitcoin/rand"] base64 = ["bitcoin/base64"] v2 = ["bitcoin/rand", "bitcoin/serde", "hpke", "dep:http", "bhttp", "ohttp", "serde", "url/serde" ] #[doc = "Functions to fetch OHTTP keys via CONNECT proxy using reqwest. Enables `v2` since only `v2` uses OHTTP."] @@ -54,4 +52,4 @@ tracing = "0.1.40" tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } [package.metadata.docs.rs] -features = ["send", "receive", "base64", "v2", "io"] +features = ["base64", "v2", "io"] diff --git a/payjoin/src/hpke.rs b/payjoin/src/hpke.rs index deef9cfc3..3cf360d02 100644 --- a/payjoin/src/hpke.rs +++ b/payjoin/src/hpke.rs @@ -169,7 +169,6 @@ impl<'de> serde::Deserialize<'de> for HpkePublicKey { } /// Message A is sent from the sender to the receiver containing an Original PSBT payload -#[cfg(feature = "send")] pub fn encrypt_message_a( body: Vec, reply_pk: &HpkePublicKey, @@ -192,7 +191,6 @@ pub fn encrypt_message_a( Ok(message_a.to_vec()) } -#[cfg(feature = "receive")] pub fn decrypt_message_a( message_a: &[u8], receiver_sk: HpkeSecretKey, @@ -223,7 +221,6 @@ pub fn decrypt_message_a( } /// Message B is sent from the receiver to the sender containing a Payjoin PSBT payload or an error -#[cfg(feature = "receive")] pub fn encrypt_message_b( mut plaintext: Vec, receiver_keypair: &HpkeKeyPair, @@ -246,7 +243,6 @@ pub fn encrypt_message_b( Ok(message_b.to_vec()) } -#[cfg(feature = "send")] pub fn decrypt_message_b( message_b: &[u8], receiver_pk: HpkePublicKey, diff --git a/payjoin/src/lib.rs b/payjoin/src/lib.rs index 92b3fd7ab..b36d82f3c 100644 --- a/payjoin/src/lib.rs +++ b/payjoin/src/lib.rs @@ -19,10 +19,8 @@ pub extern crate bitcoin; -#[cfg(feature = "receive")] pub mod receive; -#[cfg(feature = "send")] pub mod send; #[cfg(feature = "v2")] @@ -39,11 +37,8 @@ pub(crate) mod bech32; #[cfg(feature = "io")] pub mod io; -#[cfg(any(feature = "send", feature = "receive"))] pub(crate) mod psbt; -#[cfg(any(feature = "send", all(feature = "receive", feature = "v2")))] mod request; -#[cfg(any(feature = "send", all(feature = "receive", feature = "v2")))] pub use request::*; mod uri; diff --git a/payjoin/tests/integration.rs b/payjoin/tests/integration.rs index b1a0ae179..37cb6e06f 100644 --- a/payjoin/tests/integration.rs +++ b/payjoin/tests/integration.rs @@ -1,4 +1,3 @@ -#[cfg(all(feature = "send", feature = "receive"))] mod integration { use std::collections::HashMap; use std::env; From 4e575a7b1c58aa567e9b72bfe8062dd9c326c593 Mon Sep 17 00:00:00 2001 From: DanGould Date: Mon, 20 Jan 2025 13:28:32 -0500 Subject: [PATCH 2/6] Make distinct `payjoin/{v1,v2}` features This way you can enable just the one you're interested in without the additional noise of details you will not use See #392 --- contrib/coverage.sh | 2 +- contrib/lint.sh | 2 +- payjoin-cli/Cargo.toml | 2 +- payjoin-cli/contrib/test.sh | 2 +- payjoin/Cargo.toml | 1 + payjoin/src/lib.rs | 1 - 6 files changed, 5 insertions(+), 5 deletions(-) diff --git a/contrib/coverage.sh b/contrib/coverage.sh index 261165a7c..37fe6f3dc 100755 --- a/contrib/coverage.sh +++ b/contrib/coverage.sh @@ -3,6 +3,6 @@ set -e # https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#merge-coverages-generated-under-different-test-conditions cargo llvm-cov clean --workspace # remove artifacts that may affect the coverage results -cargo llvm-cov --no-report # v1 configuration +cargo llvm-cov --no-report --features=v1 cargo llvm-cov --no-report --features=v2,_danger-local-https,io cargo llvm-cov report --lcov --output-path lcov.info # generate report without tests diff --git a/contrib/lint.sh b/contrib/lint.sh index 8f26acd91..951da6ffe 100755 --- a/contrib/lint.sh +++ b/contrib/lint.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash set -e -cargo clippy --all-targets --keep-going -- -D warnings # v1 configuration +cargo clippy --all-targets --keep-going --features=v1 -- -D warnings cargo clippy --all-targets --keep-going --features=v2,_danger-local-https,io -- -D warnings diff --git a/payjoin-cli/Cargo.toml b/payjoin-cli/Cargo.toml index 72af889c0..2cfe195fc 100644 --- a/payjoin-cli/Cargo.toml +++ b/payjoin-cli/Cargo.toml @@ -22,7 +22,7 @@ path = "src/main.rs" default = ["v1"] native-certs = ["reqwest/rustls-tls-native-roots"] _danger-local-https = ["rcgen", "reqwest/rustls-tls", "rustls", "hyper-rustls", "payjoin/_danger-local-https", "tokio-rustls"] -v1 = ["hyper", "hyper-util", "http-body-util"] +v1 = ["payjoin/v1","hyper", "hyper-util", "http-body-util"] v2 = ["payjoin/v2", "payjoin/io"] [dependencies] diff --git a/payjoin-cli/contrib/test.sh b/payjoin-cli/contrib/test.sh index 657a464db..6578444c9 100755 --- a/payjoin-cli/contrib/test.sh +++ b/payjoin-cli/contrib/test.sh @@ -2,4 +2,4 @@ set -e cargo test --locked --package payjoin-cli --verbose --no-default-features --features=_danger-local-https,v2 --test e2e -cargo test --locked --package payjoin-cli --verbose --features=_danger-local-https +cargo test --locked --package payjoin-cli --verbose --features=v1,_danger-local-https diff --git a/payjoin/Cargo.toml b/payjoin/Cargo.toml index d9a61cc87..45587c006 100644 --- a/payjoin/Cargo.toml +++ b/payjoin/Cargo.toml @@ -17,6 +17,7 @@ exclude = ["tests"] [features] base64 = ["bitcoin/base64"] +v1 = ["bitcoin/rand"] v2 = ["bitcoin/rand", "bitcoin/serde", "hpke", "dep:http", "bhttp", "ohttp", "serde", "url/serde" ] #[doc = "Functions to fetch OHTTP keys via CONNECT proxy using reqwest. Enables `v2` since only `v2` uses OHTTP."] io = ["v2", "reqwest/rustls-tls"] diff --git a/payjoin/src/lib.rs b/payjoin/src/lib.rs index b36d82f3c..c0ef5527e 100644 --- a/payjoin/src/lib.rs +++ b/payjoin/src/lib.rs @@ -20,7 +20,6 @@ pub extern crate bitcoin; pub mod receive; - pub mod send; #[cfg(feature = "v2")] From 590295ae8a3d0bcf55f6a6148c218cd9138472b5 Mon Sep 17 00:00:00 2001 From: DanGould Date: Mon, 20 Jan 2025 13:31:00 -0500 Subject: [PATCH 3/6] Make `payjoin/v2` a default feature This marks Payjoin v2 (BIP 77) is a first-class citizen of the crate. --- contrib/coverage.sh | 4 ++-- contrib/lint.sh | 4 ++-- payjoin-cli/Cargo.toml | 4 ++-- payjoin-cli/contrib/test.sh | 2 +- payjoin/Cargo.toml | 1 + 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/contrib/coverage.sh b/contrib/coverage.sh index 37fe6f3dc..935385de9 100755 --- a/contrib/coverage.sh +++ b/contrib/coverage.sh @@ -3,6 +3,6 @@ set -e # https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#merge-coverages-generated-under-different-test-conditions cargo llvm-cov clean --workspace # remove artifacts that may affect the coverage results -cargo llvm-cov --no-report --features=v1 -cargo llvm-cov --no-report --features=v2,_danger-local-https,io +cargo llvm-cov --no-report --no-default-features --features=v1 +cargo llvm-cov --no-report --no-default-features --features=v2,_danger-local-https,io cargo llvm-cov report --lcov --output-path lcov.info # generate report without tests diff --git a/contrib/lint.sh b/contrib/lint.sh index 951da6ffe..47be4b974 100755 --- a/contrib/lint.sh +++ b/contrib/lint.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash set -e -cargo clippy --all-targets --keep-going --features=v1 -- -D warnings -cargo clippy --all-targets --keep-going --features=v2,_danger-local-https,io -- -D warnings +cargo clippy --all-targets --keep-going --no-default-features --features=v1 -- -D warnings +cargo clippy --all-targets --keep-going --no-default-features --features=v2,_danger-local-https,io -- -D warnings diff --git a/payjoin-cli/Cargo.toml b/payjoin-cli/Cargo.toml index 2cfe195fc..29990c221 100644 --- a/payjoin-cli/Cargo.toml +++ b/payjoin-cli/Cargo.toml @@ -19,7 +19,7 @@ path = "src/main.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default = ["v1"] +default = ["v2"] native-certs = ["reqwest/rustls-tls-native-roots"] _danger-local-https = ["rcgen", "reqwest/rustls-tls", "rustls", "hyper-rustls", "payjoin/_danger-local-https", "tokio-rustls"] v1 = ["payjoin/v1","hyper", "hyper-util", "http-body-util"] @@ -37,7 +37,7 @@ hyper = { version = "1", features = ["http1", "server"], optional = true } hyper-rustls = { version = "0.26", optional = true } hyper-util = { version = "0.1", optional = true } log = "0.4.7" -payjoin = { version = "0.22.0", features = ["base64"] } +payjoin = { version = "0.22.0", features = ["base64"], default-features = false } rcgen = { version = "0.11.1", optional = true } reqwest = { version = "0.12", default-features = false } rustls = { version = "0.22.4", optional = true } diff --git a/payjoin-cli/contrib/test.sh b/payjoin-cli/contrib/test.sh index 6578444c9..71ffc5952 100755 --- a/payjoin-cli/contrib/test.sh +++ b/payjoin-cli/contrib/test.sh @@ -2,4 +2,4 @@ set -e cargo test --locked --package payjoin-cli --verbose --no-default-features --features=_danger-local-https,v2 --test e2e -cargo test --locked --package payjoin-cli --verbose --features=v1,_danger-local-https +cargo test --locked --package payjoin-cli --verbose --no-default-features --features=v1,_danger-local-https diff --git a/payjoin/Cargo.toml b/payjoin/Cargo.toml index 45587c006..450b5d824 100644 --- a/payjoin/Cargo.toml +++ b/payjoin/Cargo.toml @@ -16,6 +16,7 @@ exclude = ["tests"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] +default = ["v2"] base64 = ["bitcoin/base64"] v1 = ["bitcoin/rand"] v2 = ["bitcoin/rand", "bitcoin/serde", "hpke", "dep:http", "bhttp", "ohttp", "serde", "url/serde" ] From fd99b1ca777024d2ffddf2ad0cea5fce1ba45511 Mon Sep 17 00:00:00 2001 From: DanGould Date: Mon, 20 Jan 2025 14:10:59 -0500 Subject: [PATCH 4/6] Fix `v2` not in scope for docs v1-only config --- payjoin/src/send/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/payjoin/src/send/mod.rs b/payjoin/src/send/mod.rs index 95aafcfda..f45f8f30f 100644 --- a/payjoin/src/send/mod.rs +++ b/payjoin/src/send/mod.rs @@ -2,8 +2,11 @@ //! //! This module contains types and methods used to implement sending via Payjoin. //! -//! For most use cases, it is recommended to start with the [`v2`] module, as it is -//! backwards compatible and provides the latest features. If you specifically need to use +//! For most use cases, we recommended enabling the `v2` feature, as it is +//! backwards compatible and provides the most convenient experience for users and implementors. +#![cfg_attr(feature = "v2", doc = "To use version 2, refer to [`v2`] module documentation.")] +//! +//! If you specifically need to use //! version 1, refer to the [`v1`] module documentation. use std::str::FromStr; From ecb747430995557f0c44b8ad589054055655a5d1 Mon Sep 17 00:00:00 2001 From: DanGould Date: Mon, 20 Jan 2025 14:24:48 -0500 Subject: [PATCH 5/6] Lint v1 payjoin-cli/e2e tests --- payjoin-cli/tests/e2e.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/payjoin-cli/tests/e2e.rs b/payjoin-cli/tests/e2e.rs index f86690b6d..2df2ef155 100644 --- a/payjoin-cli/tests/e2e.rs +++ b/payjoin-cli/tests/e2e.rs @@ -69,13 +69,13 @@ mod e2e { .arg("--rpchost") .arg(&receiver_rpchost) .arg("--cookie-file") - .arg(&cookie_file) + .arg(cookie_file) .arg("--db-path") .arg(&receiver_db_path_clone) .arg("receive") .arg(RECEIVE_SATS) .arg("--port") - .arg(&port.to_string()) + .arg(port.to_string()) .arg("--pj-endpoint") .arg(&pj_endpoint) .stdout(Stdio::piped()) @@ -110,7 +110,7 @@ mod e2e { .arg("--rpchost") .arg(&sender_rpchost) .arg("--cookie-file") - .arg(&cookie_file) + .arg(cookie_file) .arg("--db-path") .arg(&sender_db_path_clone) .arg("send") From 9b9ee814bfb527ffee12ca5c1309b0317fd0c66b Mon Sep 17 00:00:00 2001 From: DanGould Date: Mon, 20 Jan 2025 14:21:05 -0500 Subject: [PATCH 6/6] Configure v1 checks to use `_danger-local-https` Without this configuration some checks would be ignored. Close #499 --- contrib/coverage.sh | 2 +- contrib/lint.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/coverage.sh b/contrib/coverage.sh index 935385de9..ff090c9f2 100755 --- a/contrib/coverage.sh +++ b/contrib/coverage.sh @@ -3,6 +3,6 @@ set -e # https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#merge-coverages-generated-under-different-test-conditions cargo llvm-cov clean --workspace # remove artifacts that may affect the coverage results -cargo llvm-cov --no-report --no-default-features --features=v1 +cargo llvm-cov --no-report --no-default-features --features=v1,_danger-local-https cargo llvm-cov --no-report --no-default-features --features=v2,_danger-local-https,io cargo llvm-cov report --lcov --output-path lcov.info # generate report without tests diff --git a/contrib/lint.sh b/contrib/lint.sh index 47be4b974..9b279da44 100755 --- a/contrib/lint.sh +++ b/contrib/lint.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash set -e -cargo clippy --all-targets --keep-going --no-default-features --features=v1 -- -D warnings +cargo clippy --all-targets --keep-going --no-default-features --features=v1,_danger-local-https -- -D warnings cargo clippy --all-targets --keep-going --no-default-features --features=v2,_danger-local-https,io -- -D warnings