@@ -41,6 +41,7 @@ use crate::{HpkeKeyPair, HpkePublicKey, IntoUrl, OhttpKeys, PjUri, Request};
4141
4242mod error;
4343
44+ /// A builder to construct the properties of a [`Sender`].
4445#[ derive( Clone ) ]
4546pub struct SenderBuilder < ' a > ( pub ( crate ) v1:: SenderBuilder < ' a > ) ;
4647
@@ -123,13 +124,15 @@ impl<'a> SenderBuilder<'a> {
123124 }
124125}
125126
127+ /// A new payjoin sender, which must be persisted before initiating the payjoin flow.
126128#[ derive( Debug ) ]
127129pub struct NewSender {
128130 pub ( crate ) v1 : v1:: Sender ,
129131 pub ( crate ) reply_key : HpkeSecretKey ,
130132}
131133
132134impl NewSender {
135+ /// Saves the new [`Sender`] using the provided persister and returns the storage token.
133136 pub fn persist < P : Persister < Sender > > (
134137 & self ,
135138 persister : & mut P ,
@@ -139,6 +142,8 @@ impl NewSender {
139142 }
140143}
141144
145+ /// A payjoin V2 sender, allowing the construction of a payjoin V2 request
146+ /// and the resulting [`V2PostContext`].
142147#[ derive( Clone , PartialEq , Eq , Serialize , Deserialize ) ]
143148pub struct Sender {
144149 /// The v1 Sender.
@@ -170,6 +175,7 @@ impl Value for Sender {
170175}
171176
172177impl Sender {
178+ /// Loads a [`Sender`] from the provided persister using the storage token.
173179 pub fn load < P : Persister < Sender > > (
174180 token : P :: Token ,
175181 persister : & P ,
@@ -236,6 +242,7 @@ impl Sender {
236242 self . v1 . endpoint . receiver_pubkey ( )
237243 }
238244
245+ /// The endpoint in the Payjoin URI
239246 pub fn endpoint ( & self ) -> & Url { self . v1 . endpoint ( ) }
240247}
241248
@@ -289,15 +296,29 @@ pub(crate) fn serialize_v2_body(
289296 Ok ( format ! ( "{}\n {}" , base64, query_params) . into_bytes ( ) )
290297}
291298
299+ /// Data required to validate the POST response.
300+ ///
301+ /// This type is used to process a BIP77 POST response.
302+ /// Call [`Self::process_response`] on it to continue the BIP77 flow.
292303pub struct V2PostContext {
293- /// The payjoin directory subdirectory to send the request to.
304+ /// The endpoint in the Payjoin URI
294305 pub ( crate ) endpoint : Url ,
295306 pub ( crate ) psbt_ctx : PsbtContext ,
296307 pub ( crate ) hpke_ctx : HpkeContext ,
297308 pub ( crate ) ohttp_ctx : ohttp:: ClientResponse ,
298309}
299310
300311impl V2PostContext {
312+ /// Processes the response for the initial POST message from the sender
313+ /// client in the v2 Payjoin protocol.
314+ ///
315+ /// This function decapsulates the response using the provided OHTTP
316+ /// context. If the encapsulated response status is successful, it
317+ /// indicates that the the Original PSBT been accepted. Otherwise, it
318+ /// returns an error with the encapsulated response status code.
319+ ///
320+ /// After this function is called, the sender can poll for a Proposal PSBT
321+ /// from the receiver using the returned [`V2GetContext`].
301322 pub fn process_response ( self , response : & [ u8 ] ) -> Result < V2GetContext , EncapsulationError > {
302323 let response_array: & [ u8 ; crate :: directory:: ENCAPSULATED_MESSAGE_BYTES ] = response
303324 . try_into ( )
@@ -318,15 +339,20 @@ impl V2PostContext {
318339 }
319340}
320341
342+ /// Data required to validate the GET response.
343+ ///
344+ /// This type is used to make a BIP77 GET request and process the response.
345+ /// Call [`Self::process_response`] on it to continue the BIP77 flow.
321346#[ derive( Debug , Clone ) ]
322347pub struct V2GetContext {
323- /// The payjoin directory subdirectory to send the request to.
348+ /// The endpoint in the Payjoin URI
324349 pub ( crate ) endpoint : Url ,
325350 pub ( crate ) psbt_ctx : PsbtContext ,
326351 pub ( crate ) hpke_ctx : HpkeContext ,
327352}
328353
329354impl V2GetContext {
355+ /// Extract an OHTTP Encapsulated HTTP GET request for the Proposal PSBT
330356 pub fn extract_req (
331357 & self ,
332358 ohttp_relay : impl IntoUrl ,
@@ -354,6 +380,16 @@ impl V2GetContext {
354380 Ok ( ( Request :: new_v2 ( & url, & body) , ohttp_ctx) )
355381 }
356382
383+ /// Processes the response for the final GET message from the sender client
384+ /// in the v2 Payjoin protocol.
385+ ///
386+ /// This function decapsulates the response using the provided OHTTP
387+ /// context. A successful response can either be a Proposal PSBT or an
388+ /// ACCEPTED message indicating no Proposal PSBT is available yet.
389+ /// Otherwise, it returns an error with the encapsulated status code.
390+ ///
391+ /// After this function is called, the sender can sign and finalize the
392+ /// PSBT and broadcast the resulting Payjoin transaction to the network.
357393 pub fn process_response (
358394 & self ,
359395 response : & [ u8 ] ,
0 commit comments