Repository navigation
Description
A typical wallet architecture separates responsibilities between a wallet management system and one or more signers. Examples include shared or hybrid custody setups like Casa or Liana, or hardware wallet configurations such as Ledger with Ledger Live. In this model, the signer focuses solely on managing private keys and signing. Signers often lack the necessary resources to progress a Payjoin session’s typestate. Resources required for advancing a Payjoin session include persistent storage, a network connection, and, in some typestate transitions, access to a Bitcoin node (check_broadcast_suitability). Under the new SEL paradigm introduced in Payjoin 0.24, the resource rich wallet management system advances the session typestate. However, transitioning beyond the receiver’s provisionalProposal typestate requires signing.
Application developers may attempt to extract the PSBT containing the contributed inputs, sign it, and then inject the finalized PSBT into the finalize_proposal closure. However, this approach fails because the receiver has not yet applied its expected fee contribution at the time of signing. As a result, the signed PSBT reflects incorrect fee contributions and will be rejected by the sender.
At the time of writing, two potential solutions exist but I am sure there are more.
- Introduce a new receiver typestate after fee application
Applying fees to the PSBT introduces new information that should be preserved independently of signing. Currently, fee application and signing are tightly coupled. Introducing a new typestate to represent a “fee-applied” PSBT would allow this data to be stored and retrieved through session history. The history interface should clearly indicate that this PSBT is ready for signing. Additionally, we should consider adding a new state transition method to provisional_proposal that accepts a finalized PSBT directly.
application developers are currently forced to work around the current API like this:
let psbt = ... // finalized PSBT from the signer
let proposal = proposal
.finalize_proposal(
|_| {
Ok(psbt)
},
None,
None,
)
.save(persister)?;- Expose
apply_fee()as a public method
A less invasive change to rust-payjoin would be to expose the apply_fee() method publicly. This would allow applications to apply fee contributions during the provisionalProposal typestate, save the resulting PSBT, sign it, and inject the finalized PSBT into finalize_proposal.
Activity
benalleng commentedon Jul 11, 2025
What is the initial reason for keeping
.apply_fee()private before now, just not useful outside of this specific case?spacebear21 commentedon Jul 11, 2025
I'm in favor of introducing a new typestate like
ProvisionalProposal::apply_fee()->ProvisionalProposalWithFee.If the fee application is done in a prior state, wouldn't
ProvisionalProposalWithFee::finalize_proposal()work just fine for simple signers?arminsabouri commentedon Jul 11, 2025
I am not entirely sure. Perhaps because rust-payjoin assumes what ever entity is progressing the typestate also has access to the keys.
arminsabouri commentedon Jul 11, 2025
To be clear I am not advocating that we remove the current state transition (
finalize_proposal). Just that we should have a method that allows you to transition the state if you already have a finalized psbt. i.ecommit_finalized_psbt(&self, psbt: &Psbt). This is only useful if signing is happening outside the wallet managment service.DanGould commentedon Jul 11, 2025
Whatever decision is made, I'd much rather have one code path, even if it requires multiple calls, than two parallel branching and reuniting code paths for the sake of simplicity.
My understanding is that the problem is that the fee application might be done in a completely separate and asynchronous process to signing and the program should be treated as though it could even shut down between these phases? If so, I agree with the state separation strategy. It was built this way assuming the constraint you're describing didn't exist.
I'd prefer more descriptive state transition names than "
ProvisionalProposalWithFee". Perhaps the existingWantsInputstoWantsFeeRange(where min/max receiver fee preferences can be applied) toProvisionalProposal(or a newWantsSignertype which carries more meaning) toPayjoinProposalNow I'm wondering even if it's possible for a receiver to have multiple signers, and if this design with a separate but explicit
WantsSigneris sufficient with singlefinalize_proposalfunction or if we need to support adding signatures + a separate commitment as we do with WantsInputs/WantsOutputsFundamentally this issue presents as solution-oriented. Please make sure we understand the problem before executing a particular solution.
Separate out fee application into own typestate
Separate out fee application into own typestate
Separate out fee application into own typestate
spacebear21 commentedon Jul 16, 2025
Carrying over this comment by @arminsabouri in #881 (comment) regarding renaming
ProvisionalProposaltoWantsSigner:DanGould commentedon Jul 16, 2025
whether or not this is a payjoin concern is valid. That's what I'm asking
arminsabouri commentedon Jul 16, 2025
I understand the rationale for "more descriptive state transition names" but not for the typestate names suggested. I would advocate for more general alternatives for the provisional proposal typestate (
WantsFinalizedInputsorWantsFinalizedPsbt) for the same rationale listed in my original comment. #870 (comment)Separate out fee application into own typestate
Separate out fee application into own typestate
DanGould commentedon Jul 17, 2025
Ah yep it was the first thing that came to mind. My understanding is that both signing and input finalizer psbt roles are left to execute at the sender at that time there, where signing took precedence in my mind. I'm sure your decision wrt name will suffice.
spacebear21 commentedon Jul 17, 2025
Just making sure I understand the issue, currently Liana does this:
Instead of something like:
Because Liana must get the PSBT from DB in order to sign it? I don't totally understand the requirement here.
Letting callers pass any arbitrary PSBT to the PayjoinProposal state seems like it would break the typestate mold since we can no longer guarantee that the PSBT being finalized is a valid payjoin PSBT?
spacebear21 commentedon Jul 17, 2025
Another thing I noticed while staring at this:
finalize_proposaltakes a closurewallet_process_psbtfor the signing operation, but that parameter name is tightly coupled with the specific bitcoin-cli rpc command. This closure should be renamed to e.g.apply_receiver_signatures.Separate out fee application into own typestate (#881)
Separate out fee application into own typestate
arminsabouri commentedon Jul 28, 2025
Apologies I missed this comment.
Yes, this is correct. The Liana gui application responsible for signing will pull PSBTs from the Liana Deamon process. Lianad will in turn pull PSBTs from a database table. When we apply the reciever fee preferences to the payjoin PSBT we then save it in Lianad's PSBT table. One way to prevent an arbituary PSBT from being provided to
finalize_proposalis to compare ntxid against the previous typestate.DanGould commentedon Sep 2, 2025
Closed by #881 ? @arminsabouri
arminsabouri commentedon Sep 2, 2025
yes!
Separate out fee application into own typestate (#881)