Payjoin-in-Potentiam: Externally fund an LSP channel open with one transaction
As stated by Jesse Posner and ZmnSCPxj, “moving funds from an onchain-only address to Lightning Network is slow, especially if you desire trust-minimization,” opening their Swap-in-Potentiam proposal.
That proposal involves a contract between two parties, Alice (the funds owner) and Bob (a potential swap partner), with the contract having two branches: one for onchain/channel transactions and another with a time lock for Alice. The protocol requires cooperation from a Lightning Service Provider (LSP) and is particularly useful for mobile wallet users who want to efficiently transfer funds from the blockchain layer to the Lightning layer without waiting for additional confirmations. For a detailed explanation and sequence, please refer to the original discussion on the Lightning-dev mailing list.
Swap-in-potentiam execution requires two transactions:
- Funds a swap address
- Opens the lightning channel from funds in that address
Payjoin interaction enables the external funds to directly fund a channel opening from the LSP without a swap output address ever being posted on chain. Instead, the first transaction funding a swap address is replaced using payjoin output substitution so only the combined result is ever posted to the blockchain.
Payjoin in Potentiam
The swap-in-potentiam proposal requires a commitment transaction to the swap-in-potentiam LSP address, after which the LSP has unilateral ability to open the channel or the funder can claw back after a timeout. If instead of broadcasting a transaction to such an address a funder first sends the transaction as a PSBT to the LSP, the LSP replaces the swap-in-potentiam address in the original PSBT for a channel opening address in a payjoin PSBT via payment output substitution* to actualize the swap-in in a single transaction. The payjoin PSBT containing the funder input and the channel open output is returned to the funder, who then signs and broadcasts the transaction.
In the case the transaction is not sign and broadcast, the LSP can still broadcast the original PSBT’s transaction with the swap-in-potentiam address output and proceed in that protocol to open a channel, or otherwise Alice could claw back funds after a timeout. This shares approximately the same flow with an earlier Lightning payjoin idea but has an LSP open the channel rather than an edge node itself.
* BIP 78 payjoin output substitution recommends a match between input and output script types, but I see this as an undesirable fingerprint that should be avoided and have campaigned for this change in the spec.
Swap-in-Potentiam Sequence Diagram
Swap-in-Potentiam Diagram ASCII
Source of Funds Alice (Node) Bob (LSP) Blockchain | | | | | (Swap Address derived from Bob's Pubkey) | | | | | | <-- 1. Swap Address ------- | | | | | | | | --- 2. Tx to Swap Address-----------------------------------------------> | | | | | | | | 3. Confirmation | | | | | | | <- 4. Negotiate Open -> | | | | | | | | 5. Sign and Broadcast Tx -> | | | | | | | | 6. Confirmation | | | | |
- Alice sends a swap-in-potentiam address derived from Alice and Bob keys to source of funds.
- Bob funds the Swap Address.
- The transaction funding the Swap Address is confirmed.
- Alice and Bob derive a lightning channel open address.
- Bob signs and broadcast the channel opening tx spending the swap address.
- The transaction is confirmed by the blockchain, completing the channel open between Alice and Bob
Payjoin-in-Potentiam Sequence Diagram
Payjoin-in-Potentiam Diagram ASCII
Source of Funds Alice (Node) Bob (LSP) Blockchain | | | | | (Swap Address derived from Bob's Pubkey) | | | | | | <-- 1. Swap Address URI------ | | | | | | | | --- 2. Original PSBT ----------------------------------------> | | | | | | | | <---- 3. Negotiate Open -----> | | | | | | | <------------------------------------ 4. Output Substitution payjoin PSBT | | (Swap Address to Lightning Channel Address) | | | | | | --- 5. Signed payjoin to channel -------------------------------------------------------> | | | | | | | | 6. Confirmation | | | | |
- Alice sends a swap-in-potentiam address derived from Alice and Bob keys to source of funds in a bip21 payjoin URI.
- The Source funds the swap-in-potentiam address in a finalized original PSBT which he sends to Bob.
- Alice and Bob derive a lightning channel open address.
- Bob performs output substitution, replacing the swap-in-potentiam address with a Lightning channel address in the PSBT and sending the result to the Source.
- The Source of Funds checks that the payjoin PSBT doesn’t overspend its inputs, signs, and broadcasts the payjoin.
- The transaction is confirmed by the blockchain, completing the channel open between Alice and Bob.
In the optimistic case that both nodes are able to communicate in a timely fashion, only one transaction is broadcast to the same effect as swap-in-potentiam. If not, there is a safe fallback.
Swap-in-potentiam already assumes a cooperating LSP. In the case they’re not cooperative, funds are locked for some time. If the sender goes offline or otherwise does not broadcast the payjoin the original PSBT can be broadcast to open a channel via swap-in-potentiam.