-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for multiple senders and one reciever (NS1R)
The following is an expansion of the BIP77 protocol that allows for multiple senders to opt in to a optimisitic merge with other potential senders at a cost of an additional round of communication. The protocol does not introduce new message types instead it re-uses the existing v2 structs. Everything touching NS1R is feature gated behind the `multi_party` flag. The remaining work is two fold: 1. Sender validation. v2 Senders have thorough validation on the payjoin PSBT they recieved . Some of the validation invalidates valid multiparty responses. We would need to build and write unit tests for the multi party sender validation. 2. Multi party version of `try_preserving_privacy`. Currently when the v2 reciever is assembling a payjoin it calls in the v1 `try_preserving_privacy` method which invalidates for txs with > 2 outputs. We would either need to relax this constraint or write a bespoke version of `try_preserving_privacy` that optimizes for the multiparty case. The latter is more favorable in my opnion.
- Loading branch information
1 parent
cef3d52
commit ccc4ba9
Showing
13 changed files
with
807 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use core::fmt; | ||
use std::error; | ||
|
||
#[derive(Debug)] | ||
pub struct MultiPartyError(InternalMultiPartyError); | ||
|
||
#[derive(Debug)] | ||
pub(crate) enum InternalMultiPartyError { | ||
/// Not enough proposals | ||
NotEnoughProposals, | ||
/// Proposal version not supported | ||
ProposalVersionNotSupported(usize), | ||
/// Optimistic merge not supported | ||
OptimisticMergeNotSupported, | ||
/// Bitcoin Internal Error | ||
BitcoinExtractTxError(bitcoin::psbt::ExtractTxError), | ||
/// Input in Finalized Proposal is missing witness or script_sig | ||
InputMissingWitnessOrScriptSig, | ||
/// Failed to combine psbts | ||
FailedToCombinePsbts(bitcoin::psbt::Error), | ||
} | ||
|
||
impl From<InternalMultiPartyError> for MultiPartyError { | ||
fn from(e: InternalMultiPartyError) -> Self { MultiPartyError(e) } | ||
} | ||
|
||
impl fmt::Display for MultiPartyError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match &self.0 { | ||
InternalMultiPartyError::NotEnoughProposals => write!(f, "Not enough proposals"), | ||
InternalMultiPartyError::ProposalVersionNotSupported(v) => | ||
write!(f, "Proposal version not supported: {}", v), | ||
InternalMultiPartyError::OptimisticMergeNotSupported => | ||
write!(f, "Optimistic merge not supported"), | ||
InternalMultiPartyError::BitcoinExtractTxError(e) => | ||
write!(f, "Bitcoin extract tx error: {:?}", e), | ||
InternalMultiPartyError::InputMissingWitnessOrScriptSig => | ||
write!(f, "Input in Finalized Proposal is missing witness or script_sig"), | ||
InternalMultiPartyError::FailedToCombinePsbts(e) => | ||
write!(f, "Failed to combine psbts: {:?}", e), | ||
} | ||
} | ||
} | ||
|
||
impl error::Error for MultiPartyError { | ||
fn source(&self) -> Option<&(dyn error::Error + 'static)> { | ||
match &self.0 { | ||
InternalMultiPartyError::NotEnoughProposals => None, | ||
InternalMultiPartyError::ProposalVersionNotSupported(_) => None, | ||
InternalMultiPartyError::OptimisticMergeNotSupported => None, | ||
InternalMultiPartyError::BitcoinExtractTxError(e) => Some(e), | ||
InternalMultiPartyError::InputMissingWitnessOrScriptSig => None, | ||
InternalMultiPartyError::FailedToCombinePsbts(e) => Some(e), | ||
} | ||
} | ||
} |
Oops, something went wrong.