Browse Source

Merge pull request #101 from comit-network/txin-ext

Add TxInExt trait with extract_signatures method
no-contract-setup-message
Lucas Soriano 3 years ago
committed by GitHub
parent
commit
9eb83fd901
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      cfd_protocol/src/protocol.rs
  2. 11
      cfd_protocol/src/protocol/transactions.rs
  3. 23
      cfd_protocol/src/protocol/txin_ext.rs

1
cfd_protocol/src/protocol.rs

@ -27,6 +27,7 @@ use std::ops::RangeInclusive;
mod sighash_ext;
mod transaction_ext;
mod transactions;
mod txin_ext;
/// Static script to be used to create lock tx
const DUMMY_2OF2_MULTISIG: &str =

11
cfd_protocol/src/protocol/transactions.rs

@ -1,5 +1,6 @@
use crate::protocol::sighash_ext::SigHashExt;
use crate::protocol::transaction_ext::TransactionExt;
use crate::protocol::txin_ext::TxInExt;
use crate::protocol::{
commit_descriptor, compute_adaptor_point, lock_descriptor, Payout, DUMMY_2OF2_MULTISIG,
};
@ -12,7 +13,7 @@ use bdk::bitcoin::{
use bdk::descriptor::Descriptor;
use bdk::miniscript::DescriptorTrait;
use itertools::Itertools;
use secp256k1_zkp::{self, schnorrsig, EcdsaAdaptorSignature, SecretKey, Signature, SECP256K1};
use secp256k1_zkp::{self, schnorrsig, EcdsaAdaptorSignature, SecretKey, SECP256K1};
use std::collections::HashMap;
use std::iter::FromIterator;
@ -366,13 +367,7 @@ pub fn punish_transaction(
.context("commit transaction inputs != 1")?;
let publish_them_sk = input
.witness
.iter()
.filter_map(|elem| {
let elem = elem.as_slice();
Signature::from_der(&elem[..elem.len() - 1]).ok()
})
.find_map(|sig| encsig.recover(SECP256K1, &sig, &pub_them_pk.key).ok())
.find_map_signature(|sig| encsig.recover(SECP256K1, &sig, &pub_them_pk.key).ok())
.context("could not recover publish sk from commit tx")?;
let commit_outpoint = revoked_commit_tx

23
cfd_protocol/src/protocol/txin_ext.rs

@ -0,0 +1,23 @@
use bdk::bitcoin::secp256k1::Signature;
use bdk::bitcoin::TxIn;
pub(crate) trait TxInExt {
fn find_map_signature<F, R>(&self, f: F) -> Option<R>
where
F: Fn(Signature) -> Option<R>;
}
impl TxInExt for TxIn {
fn find_map_signature<F, R>(&self, f: F) -> Option<R>
where
F: Fn(Signature) -> Option<R>,
{
self.witness
.iter()
.filter_map(|elem| {
let elem = elem.as_slice();
Signature::from_der(&elem[..elem.len() - 1]).ok()
})
.find_map(f)
}
}
Loading…
Cancel
Save