Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions ddk/examples/stateless_descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ fn main() {
min_timeout_interval: 100,
max_timeout_interval: 500,
now_unix: util::NOW_UNIX,
payout_script_overrides: None,
},
&accepter.funding_secret_key,
)
Expand All @@ -66,8 +67,14 @@ fn main() {
}],
)
.expect("offer descriptor signing");
let sign_result =
sign_accept(&offer, &accept, &offerer.funding_secret_key, &offer_psbt).expect("sign");
let sign_result = sign_accept(
&offer,
&accept,
&offerer.funding_secret_key,
&offer_psbt,
None,
)
.expect("sign");

let mut accept_psbt = create_funding_psbt(&offer, &accept).expect("funding psbt");
signing::sign_funding_psbt_with_descriptor(
Expand All @@ -82,7 +89,7 @@ fn main() {
)
.expect("accept descriptor signing");
let funding_transaction =
finalize_sign(&offer, &accept, &sign_result.sign, &accept_psbt).expect("finalize");
finalize_sign(&offer, &accept, &sign_result.sign, &accept_psbt, None).expect("finalize");

println!(
"completed funding transaction {} with {} signed inputs",
Expand Down
13 changes: 10 additions & 3 deletions ddk/examples/stateless_external_psbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fn main() {
min_timeout_interval: 100,
max_timeout_interval: 500,
now_unix: util::NOW_UNIX,
payout_script_overrides: None,
},
&accepter.funding_secret_key,
)
Expand All @@ -68,8 +69,14 @@ fn main() {
&offerer.derivations(),
)
.expect("offer xpriv signing");
let sign_result =
sign_accept(&offer, &accept, &offerer.funding_secret_key, &offer_psbt).expect("sign");
let sign_result = sign_accept(
&offer,
&accept,
&offerer.funding_secret_key,
&offer_psbt,
None,
)
.expect("sign");

// The accept party serializes the PSBT and hands it to the external wallet.
let psbt = create_funding_psbt(&offer, &accept).expect("funding psbt");
Expand All @@ -85,7 +92,7 @@ fn main() {
// Inputs belonging to the offer party are still unsigned in `returned`;
// finalize_sign only requires the accept party's inputs to be finalized.
let funding_transaction =
finalize_sign(&offer, &accept, &sign_result.sign, &returned).expect("finalize");
finalize_sign(&offer, &accept, &sign_result.sign, &returned, None).expect("finalize");

println!(
"completed funding transaction {} with {} signed inputs",
Expand Down
7 changes: 6 additions & 1 deletion ddk/examples/stateless_splice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ async fn main() {
min_timeout_interval: 100,
max_timeout_interval: 500,
now_unix: util::NOW_UNIX,
payout_script_overrides: None,
},
&accepter_keys.funding_secret_key(temp_id_a).unwrap(),
)
Expand All @@ -193,6 +194,7 @@ async fn main() {
&accept_a,
&offerer_keys.funding_secret_key(temp_id_a).unwrap(),
&offer_a_psbt,
None,
)
.expect("sign A");

Expand All @@ -207,7 +209,7 @@ async fn main() {
.await
.expect("accept A wallet signing");
let funding_tx_a =
finalize_sign(&offer_a, &accept_a, &sign_a.sign, &accept_a_psbt).expect("finalize A");
finalize_sign(&offer_a, &accept_a, &sign_a.sign, &accept_a_psbt, None).expect("finalize A");

// ----- Contract B: splice A's funding output into a new contract. -----
let splice_serial = 900;
Expand Down Expand Up @@ -259,6 +261,7 @@ async fn main() {
min_timeout_interval: 100,
max_timeout_interval: 500,
now_unix: util::NOW_UNIX,
payout_script_overrides: None,
},
&accepter_keys.funding_secret_key(temp_id_b).unwrap(),
)
Expand Down Expand Up @@ -288,6 +291,7 @@ async fn main() {
&offerer_keys.funding_secret_key(temp_id_b).unwrap(),
&offer_b_psbt,
std::slice::from_ref(&offer_prior_key),
None,
)
.expect("sign B");

Expand All @@ -303,6 +307,7 @@ async fn main() {
&sign_b.sign,
&accept_b_psbt,
std::slice::from_ref(&accept_prior_key),
None,
)
.expect("finalize B");

Expand Down
13 changes: 10 additions & 3 deletions ddk/examples/stateless_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ async fn main() {
min_timeout_interval: 100,
max_timeout_interval: 500,
now_unix: util::NOW_UNIX,
payout_script_overrides: None,
},
&accepter.funding_secret_key,
)
Expand All @@ -154,8 +155,14 @@ async fn main() {
)
.await
.expect("offer wallet signing");
let sign_result =
sign_accept(&offer, &accept, &offerer.funding_secret_key, &offer_psbt).expect("sign");
let sign_result = sign_accept(
&offer,
&accept,
&offerer.funding_secret_key,
&offer_psbt,
None,
)
.expect("sign");

let mut accept_psbt = create_funding_psbt(&offer, &accept).expect("funding psbt");
signing::sign_funding_psbt_with_wallet(
Expand All @@ -168,7 +175,7 @@ async fn main() {
.await
.expect("accept wallet signing");
let funding_transaction =
finalize_sign(&offer, &accept, &sign_result.sign, &accept_psbt).expect("finalize");
finalize_sign(&offer, &accept, &sign_result.sign, &accept_psbt, None).expect("finalize");

println!(
"completed funding transaction {} with {} signed inputs",
Expand Down
13 changes: 10 additions & 3 deletions ddk/examples/stateless_xpriv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fn main() {
min_timeout_interval: 100,
max_timeout_interval: 500,
now_unix: util::NOW_UNIX,
payout_script_overrides: None,
},
&accepter.funding_secret_key,
)
Expand All @@ -60,8 +61,14 @@ fn main() {
&offerer.derivations(),
)
.expect("offer xpriv signing");
let sign_result =
sign_accept(&offer, &accept, &offerer.funding_secret_key, &offer_psbt).expect("sign");
let sign_result = sign_accept(
&offer,
&accept,
&offerer.funding_secret_key,
&offer_psbt,
None,
)
.expect("sign");

// Accept party: sign its funding input and complete the funding transaction.
let mut accept_psbt = create_funding_psbt(&offer, &accept).expect("funding psbt");
Expand All @@ -74,7 +81,7 @@ fn main() {
)
.expect("accept xpriv signing");
let funding_transaction =
finalize_sign(&offer, &accept, &sign_result.sign, &accept_psbt).expect("finalize");
finalize_sign(&offer, &accept, &sign_result.sign, &accept_psbt, None).expect("finalize");

// Broadcasting stays with the caller, e.g. `chain.send_transaction(&funding_transaction)`.
println!(
Expand Down
11 changes: 7 additions & 4 deletions ddk/src/contract/accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use super::context::{
use super::create::validate_offer;
use super::error::ContractError;
use super::psbt::build_funding_psbt;
use super::types::{random_serial_id, AcceptOfferParams, AcceptResult};
use super::types::{random_serial_id, AcceptOfferParams, AcceptResult, PayoutScriptOverrides};

/// Validates an offer and creates the accepting party's wire message.
///
Expand All @@ -33,6 +33,7 @@ pub fn accept_offer(
min_timeout_interval,
max_timeout_interval,
now_unix,
payout_script_overrides,
} = params;

validate_offer(offer, min_timeout_interval, max_timeout_interval, now_unix)?;
Expand Down Expand Up @@ -62,7 +63,7 @@ pub fn accept_offer(
accept_collateral,
&party.funding_inputs,
)?;
let context = build_context(offer, &accept_params)?;
let context = build_context(offer, &accept_params, payout_script_overrides.as_ref())?;
let adaptor_signatures = create_adaptor_signatures(
&secp,
&context,
Expand Down Expand Up @@ -104,8 +105,9 @@ pub fn accept_offer(
pub fn create_dlc_transactions(
offer: &OfferDlc,
accept: &AcceptDlc,
payout_script_overrides: Option<&PayoutScriptOverrides>,
) -> Result<DlcTransactions, ContractError> {
Ok(context_from_messages(offer, accept)?.transactions)
Ok(context_from_messages(offer, accept, payout_script_overrides)?.transactions)
}

/// Rebuilds a signed contract's transactions under the [`ddk_dlc::FeeRule`]
Expand All @@ -117,6 +119,7 @@ pub fn create_signed_dlc_transactions(
offer: &OfferDlc,
accept: &AcceptDlc,
sign: &SignDlc,
payout_script_overrides: Option<&PayoutScriptOverrides>,
) -> Result<DlcTransactions, ContractError> {
Ok(signed_context(offer, accept, sign)?.transactions)
Ok(signed_context(offer, accept, sign, payout_script_overrides)?.transactions)
}
39 changes: 32 additions & 7 deletions ddk/src/contract/advanced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use ddk_messages::{
use super::context::{self, context_from_messages};
use super::error::ContractError;
use super::psbt;
use super::types::{DlcInputSigningKey, Party, SignResult};
use super::types::{DlcInputSigningKey, Party, PayoutScriptOverrides, SignResult};

/// Converts a Bitcoin witness into a wire funding signature.
pub fn funding_signature_from_witness(witness: Witness) -> FundingSignature {
Expand Down Expand Up @@ -61,9 +61,10 @@ pub fn create_cet_adaptor_signatures(
offer: &OfferDlc,
accept: &AcceptDlc,
funding_secret_key: &SecretKey,
payout_script_overrides: Option<&PayoutScriptOverrides>,
) -> Result<Vec<EcdsaAdaptorSignature>, ContractError> {
let secp = Secp256k1::new();
let context = context_from_messages(offer, accept)?;
let context = context_from_messages(offer, accept, payout_script_overrides)?;
context::create_adaptor_signatures(
&secp,
&context,
Expand All @@ -81,9 +82,10 @@ pub fn verify_cet_adaptor_signatures(
party: Party,
refund_signature: &ddk_dlc::secp256k1_zkp::ecdsa::Signature,
adaptor_signatures: &CetAdaptorSignatures,
payout_script_overrides: Option<&PayoutScriptOverrides>,
) -> Result<(), ContractError> {
let secp = Secp256k1::new();
let context = context_from_messages(offer, accept)?;
let context = context_from_messages(offer, accept, payout_script_overrides)?;
let (funding_pubkey, error): (_, fn(String) -> ContractError) = match party {
Party::Offer => (offer.funding_pubkey, ContractError::InvalidSign),
Party::Accept => (accept.funding_pubkey, ContractError::InvalidAccept),
Expand Down Expand Up @@ -118,7 +120,7 @@ pub fn compute_contract_id(
offer: &OfferDlc,
accept: &AcceptDlc,
) -> Result<[u8; 32], ContractError> {
let context = context_from_messages(offer, accept)?;
let context = context_from_messages(offer, accept, None)?;
Ok(context::contract_id_from_transactions(
&context.transactions,
&offer.temporary_contract_id,
Expand All @@ -135,8 +137,15 @@ pub fn sign_accept_with_funding_signatures(
accept: &AcceptDlc,
funding_secret_key: &SecretKey,
funding_signatures: FundingSignatures,
payout_script_overrides: Option<&PayoutScriptOverrides>,
) -> Result<SignResult, ContractError> {
super::sign::sign_accept_internal(offer, accept, funding_secret_key, funding_signatures)
super::sign::sign_accept_internal(
offer,
accept,
funding_secret_key,
funding_signatures,
payout_script_overrides,
)
}

/// Completes the funding transaction from externally produced accept-side witnesses.
Expand All @@ -150,8 +159,16 @@ pub fn finalize_sign_with_funding_signatures(
accept: &AcceptDlc,
sign: &SignDlc,
funding_signatures: FundingSignatures,
payout_script_overrides: Option<&PayoutScriptOverrides>,
) -> Result<Transaction, ContractError> {
super::finalize::finalize_sign_internal(offer, accept, sign, funding_signatures, &[])
super::finalize::finalize_sign_internal(
offer,
accept,
sign,
funding_signatures,
&[],
payout_script_overrides,
)
}

/// Splice-aware variant of [`finalize_sign_with_funding_signatures`].
Expand All @@ -166,6 +183,14 @@ pub fn finalize_sign_spliced_with_funding_signatures(
sign: &SignDlc,
funding_signatures: FundingSignatures,
dlc_input_keys: &[DlcInputSigningKey],
payout_script_overrides: Option<&PayoutScriptOverrides>,
) -> Result<Transaction, ContractError> {
super::finalize::finalize_sign_internal(offer, accept, sign, funding_signatures, dlc_input_keys)
super::finalize::finalize_sign_internal(
offer,
accept,
sign,
funding_signatures,
dlc_input_keys,
payout_script_overrides,
)
}
Loading
Loading