From f664aa54776d5e06f146ed67923af158e3f065c0 Mon Sep 17 00:00:00 2001 From: Armin Sabouri Date: Mon, 25 Nov 2024 13:06:14 -0500 Subject: [PATCH 1/2] docs(send): add additional function docs --- payjoin/src/send/mod.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/payjoin/src/send/mod.rs b/payjoin/src/send/mod.rs index f31bb6f0..2d161413 100644 --- a/payjoin/src/send/mod.rs +++ b/payjoin/src/send/mod.rs @@ -235,11 +235,16 @@ impl<'a> SenderBuilder<'a> { #[derive(Clone, PartialEq, Eq)] #[cfg_attr(feature = "v2", derive(Serialize, Deserialize))] pub struct Sender { + /// The original PSBT. psbt: Psbt, + /// The payjoin directory subdirectory to send the request to. endpoint: Url, + /// Disallow reciever to substitute original outputs. disable_output_substitution: bool, + /// (maxadditionalfeecontribution, additionalfeeoutputindex) fee_contribution: Option<(bitcoin::Amount, usize)>, min_fee_rate: FeeRate, + /// Script of the person being paid payee: ScriptBuf, } @@ -350,6 +355,7 @@ impl V1Context { #[cfg(feature = "v2")] pub struct V2PostContext { + /// The payjoin directory subdirectory to send the request to. endpoint: Url, psbt_ctx: PsbtContext, hpke_ctx: HpkeContext, @@ -383,6 +389,7 @@ impl V2PostContext { #[cfg(feature = "v2")] #[derive(Debug, Clone)] pub struct V2GetContext { + /// The payjoin directory subdirectory to send the request to. endpoint: Url, psbt_ctx: PsbtContext, hpke_ctx: HpkeContext, @@ -558,7 +565,7 @@ impl PsbtContext { Ok(()) } - // version and lock time + /// Check that the version and lock time are the same as in the original PSBT. fn basic_checks(&self, proposal: &Psbt) -> InternalResult<()> { check_eq!( proposal.unsigned_tx.version, @@ -638,9 +645,9 @@ impl PsbtContext { Ok(()) } - // Restore Original PSBT utxos that the receiver stripped. - // The BIP78 spec requires utxo information to be removed, but many wallets - // require it to be present to sign. + /// Restore Original PSBT utxos that the receiver stripped. + /// The BIP78 spec requires utxo information to be removed, but many wallets + /// require it to be present to sign. fn restore_original_utxos(&self, proposal: &mut Psbt) -> InternalResult<()> { let mut original_inputs = self.original_psbt.input_pairs().peekable(); let proposal_inputs = @@ -714,6 +721,8 @@ impl PsbtContext { } } +/// Ensure that the payee's output scriptPubKey appears in the list of outputs exactly once, +/// and that the payee's output amount matches the requested amount. fn check_single_payee( psbt: &Psbt, script_pubkey: &Script, @@ -763,6 +772,7 @@ fn clear_unneeded_fields(psbt: &mut Psbt) { } } +/// Ensure that an additional fee output is sufficient to pay for the specified additional fee fn check_fee_output_amount( output: &TxOut, fee: bitcoin::Amount, @@ -779,6 +789,7 @@ fn check_fee_output_amount( } } +/// Find the sender's change output index by eliminating the payee's output as a candidate. fn find_change_index( psbt: &Psbt, payee: &Script, @@ -805,6 +816,8 @@ fn find_change_index( Ok(Some((check_fee_output_amount(output, fee, clamp_fee_contribution)?, index))) } +/// Check that the change output index is not out of bounds +/// and that the additional fee contribution is not less than specified. fn check_change_index( psbt: &Psbt, payee: &Script, From 3b0f0be41d3b7904d48eb95e99860769c6b11796 Mon Sep 17 00:00:00 2001 From: Armin Sabouri Date: Tue, 26 Nov 2024 11:34:27 -0500 Subject: [PATCH 2/2] chore(receive): fix typos --- payjoin/src/receive/v2/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/payjoin/src/receive/v2/mod.rs b/payjoin/src/receive/v2/mod.rs index c62bc8c4..a91f75d0 100644 --- a/payjoin/src/receive/v2/mod.rs +++ b/payjoin/src/receive/v2/mod.rs @@ -97,7 +97,7 @@ impl Receiver { } } - /// Extratct an OHTTP Encapsulated HTTP GET request for the Original PSBT + /// Extract an OHTTP Encapsulated HTTP GET request for the Original PSBT pub fn extract_req(&mut self) -> Result<(Request, ohttp::ClientResponse), SessionError> { if SystemTime::now() > self.context.expiry { return Err(InternalSessionError::Expired(self.context.expiry).into()); @@ -237,7 +237,7 @@ impl UncheckedProposal { /// /// Receiver MUST check that the Original PSBT from the sender /// can be broadcast, i.e. `testmempoolaccept` bitcoind rpc returns { "allowed": true,.. } - /// for `extract_tx_to_sheculed_broadcast()` before calling this method. + /// for `extract_tx_to_schedule_broadcast()` before calling this method. /// /// Do this check if you generate bitcoin uri to receive Payjoin on sender request without manual human approval, like a payment processor. /// Such so called "non-interactive" receivers are otherwise vulnerable to probing attacks.