From 3fb03626be7a1672919c99540777a1e6733e955c Mon Sep 17 00:00:00 2001 From: DanGould Date: Thu, 30 Jan 2025 00:13:06 -0500 Subject: [PATCH 1/6] Make `send::v1` `pub(crate)` without feature `receive` already does this. Make send reflect receive visibility. --- payjoin/src/send/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/payjoin/src/send/mod.rs b/payjoin/src/send/mod.rs index 04f27a8d3..860dd2e99 100644 --- a/payjoin/src/send/mod.rs +++ b/payjoin/src/send/mod.rs @@ -24,7 +24,12 @@ use crate::psbt::PsbtExt; compile_error!("This crate currently only supports 32 bit and 64 bit architectures"); mod error; + +#[cfg(feature = "v1")] pub mod v1; +#[cfg(not(feature = "v1"))] +pub(crate) mod v1; + #[cfg(feature = "v2")] pub mod v2; From ff4d783d666039df7f5805093fc2a9970ba78b8d Mon Sep 17 00:00:00 2001 From: DanGould Date: Thu, 30 Jan 2025 00:13:40 -0500 Subject: [PATCH 2/6] Tag modules with features that enable them Indicate modules enabled by feature flags. --- payjoin/Cargo.toml | 3 ++- payjoin/src/lib.rs | 4 ++++ payjoin/src/receive/mod.rs | 2 ++ payjoin/src/send/mod.rs | 2 ++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/payjoin/Cargo.toml b/payjoin/Cargo.toml index 80b672412..b3752d516 100644 --- a/payjoin/Cargo.toml +++ b/payjoin/Cargo.toml @@ -49,4 +49,5 @@ tokio = { version = "1.12.0", features = ["full"] } tracing = "0.1.40" [package.metadata.docs.rs] -features = ["base64", "v2", "io"] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] \ No newline at end of file diff --git a/payjoin/src/lib.rs b/payjoin/src/lib.rs index 6aba44145..0f6179fb8 100644 --- a/payjoin/src/lib.rs +++ b/payjoin/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(docsrs, feature(doc_cfg))] + //! # Payjoin implementation in Rust //! //! **Important: this crate is WIP!** @@ -36,9 +38,11 @@ pub use crate::ohttp::OhttpKeys; #[cfg(any(feature = "v2", feature = "directory"))] pub(crate) mod bech32; #[cfg(feature = "directory")] +#[cfg_attr(docsrs, doc(cfg(feature = "directory")))] pub mod directory; #[cfg(feature = "io")] +#[cfg_attr(docsrs, doc(cfg(feature = "io")))] pub mod io; #[cfg(feature = "_core")] pub(crate) mod psbt; diff --git a/payjoin/src/receive/mod.rs b/payjoin/src/receive/mod.rs index 26629b967..19a3798d9 100644 --- a/payjoin/src/receive/mod.rs +++ b/payjoin/src/receive/mod.rs @@ -9,11 +9,13 @@ mod error; pub(crate) mod optional_parameters; #[cfg(feature = "v1")] +#[cfg_attr(docsrs, doc(cfg(feature = "v1")))] pub mod v1; #[cfg(not(feature = "v1"))] pub(crate) mod v1; #[cfg(feature = "v2")] +#[cfg_attr(docsrs, doc(cfg(feature = "v2")))] pub mod v2; /// Helper to construct a pair of (txin, psbtin) with some built-in validation diff --git a/payjoin/src/send/mod.rs b/payjoin/src/send/mod.rs index 860dd2e99..717ad703c 100644 --- a/payjoin/src/send/mod.rs +++ b/payjoin/src/send/mod.rs @@ -26,11 +26,13 @@ compile_error!("This crate currently only supports 32 bit and 64 bit architectur mod error; #[cfg(feature = "v1")] +#[cfg_attr(docsrs, doc(cfg(feature = "v1")))] pub mod v1; #[cfg(not(feature = "v1"))] pub(crate) mod v1; #[cfg(feature = "v2")] +#[cfg_attr(docsrs, doc(cfg(feature = "v2")))] pub mod v2; type InternalResult = Result; From ea1b8e6c56d3ee26029a3bffaff6f0bdad16b261 Mon Sep 17 00:00:00 2001 From: DanGould Date: Thu, 30 Jan 2025 00:08:58 -0500 Subject: [PATCH 3/6] Private request content-type const visibility These are encapsulated in the Request impl and pollute the docs. --- payjoin/src/request.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/payjoin/src/request.rs b/payjoin/src/request.rs index 0adbf3b72..e1355365b 100644 --- a/payjoin/src/request.rs +++ b/payjoin/src/request.rs @@ -1,9 +1,9 @@ use url::Url; -pub const V1_REQ_CONTENT_TYPE: &str = "text/plain"; +const V1_REQ_CONTENT_TYPE: &str = "text/plain"; #[cfg(feature = "v2")] -pub const V2_REQ_CONTENT_TYPE: &str = "message/ohttp-req"; +const V2_REQ_CONTENT_TYPE: &str = "message/ohttp-req"; /// Represents data that needs to be transmitted to the receiver or payjoin directory. /// Ensure the `Content-Length` is set to the length of `body`. (most libraries do this automatically) From ee82e2cdf6aa4966d623d272393820acde21ca5e Mon Sep 17 00:00:00 2001 From: DanGould Date: Thu, 30 Jan 2025 00:23:52 -0500 Subject: [PATCH 4/6] Remove obsolete base64 feature base64 handling is done inside the state machine now. --- payjoin-cli/Cargo.toml | 2 +- payjoin/Cargo.toml | 1 - payjoin/src/lib.rs | 2 -- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/payjoin-cli/Cargo.toml b/payjoin-cli/Cargo.toml index 6a9793d67..b974a9d46 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 = ["base64"], default-features = false } +payjoin = { version = "0.22.0", 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/Cargo.toml b/payjoin/Cargo.toml index b3752d516..d10ef0f31 100644 --- a/payjoin/Cargo.toml +++ b/payjoin/Cargo.toml @@ -17,7 +17,6 @@ exclude = ["tests"] [features] default = ["v2"] -base64 = ["bitcoin/base64"] #[doc = "Core features for payjoin state machines"] _core = ["bitcoin/rand", "serde_json", "url", "bitcoin_uri"] directory = [] diff --git a/payjoin/src/lib.rs b/payjoin/src/lib.rs index 0f6179fb8..296f5a7b3 100644 --- a/payjoin/src/lib.rs +++ b/payjoin/src/lib.rs @@ -53,8 +53,6 @@ pub use request::*; #[cfg(feature = "_core")] mod uri; -#[cfg(feature = "base64")] -pub use bitcoin::base64; #[cfg(feature = "_core")] pub use uri::{PjParseError, PjUri, Uri, UriExt}; #[cfg(feature = "_core")] From e968eda401c42793cea5d4f3f6a67848169874c3 Mon Sep 17 00:00:00 2001 From: DanGould Date: Thu, 30 Jan 2025 00:40:29 -0500 Subject: [PATCH 5/6] Document public modules Describe with a broad brush to improve them from nothing. --- payjoin/src/directory.rs | 2 ++ payjoin/src/io.rs | 2 ++ payjoin/src/receive/mod.rs | 11 +++++++++++ payjoin/src/receive/v1/mod.rs | 2 +- payjoin/src/receive/v2/mod.rs | 1 + payjoin/src/send/v1.rs | 2 +- payjoin/src/send/v2/mod.rs | 2 +- 7 files changed, 19 insertions(+), 3 deletions(-) diff --git a/payjoin/src/directory.rs b/payjoin/src/directory.rs index 87de53d38..41267b811 100644 --- a/payjoin/src/directory.rs +++ b/payjoin/src/directory.rs @@ -1,3 +1,5 @@ +//! Types relevant to the Payjoin Directory as defined in BIP 77. + pub const ENCAPSULATED_MESSAGE_BYTES: usize = 8192; /// A 64-bit identifier used to identify Payjoin Directory entries. diff --git a/payjoin/src/io.rs b/payjoin/src/io.rs index ea9ccd34a..6fe2f9e7b 100644 --- a/payjoin/src/io.rs +++ b/payjoin/src/io.rs @@ -1,3 +1,5 @@ +//! IO-related types and functions. Specifically, fetching OHTTP keys from a payjoin directory. + use reqwest::{Client, Proxy}; use crate::{OhttpKeys, Url}; diff --git a/payjoin/src/receive/mod.rs b/payjoin/src/receive/mod.rs index 19a3798d9..1e1885b30 100644 --- a/payjoin/src/receive/mod.rs +++ b/payjoin/src/receive/mod.rs @@ -1,3 +1,14 @@ +//! Receive Payjoin +//! +//! This module contains types and methods used to implement receiving via Payjoin. +//! +//! 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 bitcoin::{psbt, AddressType, TxIn, TxOut}; pub(crate) use error::InternalPayloadError; pub use error::{Error, JsonError, OutputSubstitutionError, PayloadError, SelectionError}; diff --git a/payjoin/src/receive/v1/mod.rs b/payjoin/src/receive/v1/mod.rs index e895a20b7..1ea2f9c04 100644 --- a/payjoin/src/receive/v1/mod.rs +++ b/payjoin/src/receive/v1/mod.rs @@ -1,4 +1,4 @@ -//! Receive Payjoin v1 +//! Receive BIP 78 Payjoin v1 //! //! This module contains types and methods used to receive payjoin via BIP78. //! Usage is pretty simple: diff --git a/payjoin/src/receive/v2/mod.rs b/payjoin/src/receive/v2/mod.rs index 6470a8182..77661fa3c 100644 --- a/payjoin/src/receive/v2/mod.rs +++ b/payjoin/src/receive/v2/mod.rs @@ -1,3 +1,4 @@ +//! Receive BIP 77 Payjoin v2 use std::str::FromStr; use std::time::{Duration, SystemTime}; diff --git a/payjoin/src/send/v1.rs b/payjoin/src/send/v1.rs index 0b56ea07f..be5b9e7c8 100644 --- a/payjoin/src/send/v1.rs +++ b/payjoin/src/send/v1.rs @@ -1,4 +1,4 @@ -//! Send Payjoin +//! Send BIP 78 Payjoin v1 //! //! This module contains types and methods used to implement sending via [BIP78 //! Payjoin](https://github.com/bitcoin/bips/blob/master/bip-0078.mediawiki). diff --git a/payjoin/src/send/v2/mod.rs b/payjoin/src/send/v2/mod.rs index ce010ae66..90f8938d5 100644 --- a/payjoin/src/send/v2/mod.rs +++ b/payjoin/src/send/v2/mod.rs @@ -1,4 +1,4 @@ -//! Send Payjoin +//! Send BIP 77 Payjoin v2 //! //! This module contains types and methods used to implement sending via [BIP77 //! Payjoin](https://github.com/bitcoin/bips/pull/1483). From 3b9eee30cc18d476b72889c2aab3fd05a324983c Mon Sep 17 00:00:00 2001 From: DanGould Date: Thu, 30 Jan 2025 13:46:17 -0500 Subject: [PATCH 6/6] Don't feature gate module documentation Excessive feature gates lead to needless confusion. --- payjoin/src/receive/mod.rs | 4 ++-- payjoin/src/send/mod.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/payjoin/src/receive/mod.rs b/payjoin/src/receive/mod.rs index 1e1885b30..be56b8497 100644 --- a/payjoin/src/receive/mod.rs +++ b/payjoin/src/receive/mod.rs @@ -4,10 +4,10 @@ //! //! 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.")] +//! To use version 2, refer to `receive::v2` module documentation. //! //! If you specifically need to use -//! version 1, refer to the [`v1`] module documentation. +//! version 1, refer to the `receive::v1` module documentation after enabling the `v1` feature. use bitcoin::{psbt, AddressType, TxIn, TxOut}; pub(crate) use error::InternalPayloadError; diff --git a/payjoin/src/send/mod.rs b/payjoin/src/send/mod.rs index 717ad703c..ea54f5852 100644 --- a/payjoin/src/send/mod.rs +++ b/payjoin/src/send/mod.rs @@ -4,10 +4,10 @@ //! //! 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.")] +//! To use version 2, refer to `send::v2` module documentation. //! //! If you specifically need to use -//! version 1, refer to the [`v1`] module documentation. +//! version 1, refer to the `send::v1` module documentation after enabling the `v1` feature. use std::str::FromStr;