@bennyblader/ddk-rn 0.3.13 → 0.3.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -282,7 +282,7 @@ checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675"
282
282
 
283
283
  [[package]]
284
284
  name = "ddk_ffi"
285
- version = "0.3.13"
285
+ version = "0.3.15"
286
286
  dependencies = [
287
287
  "bip39",
288
288
  "bitcoin",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "ddk_ffi"
3
- version = "0.3.13"
3
+ version = "0.3.15"
4
4
  edition = "2021"
5
5
  license = "MIT"
6
6
  description = "rust-dlc language bindings"
@@ -620,8 +620,7 @@ pub fn verify_fund_tx_signature(
620
620
  input.previous_output.txid == input_txid && input.previous_output.vout == vout
621
621
  })
622
622
  .ok_or(DLCError::InvalidArgument(format!(
623
- "Input index not found in {}",
624
- input_txid
623
+ "Input index not found in {input_txid}"
625
624
  )))?;
626
625
 
627
626
  // Create a simple P2WPKH script for verification
@@ -629,13 +628,7 @@ pub fn verify_fund_tx_signature(
629
628
  let script = bitcoin::ScriptBuf::new_p2wpkh(&wpkh);
630
629
 
631
630
  // Parse signature
632
- let sig = if signature.len() == 64 {
633
- EcdsaSignature::from_compact(&signature).map_err(|_| DLCError::InvalidSignature)?
634
- } else {
635
- // Remove sighash type byte and parse DER
636
- let sig_bytes = &signature[..signature.len() - 1];
637
- EcdsaSignature::from_der(sig_bytes).map_err(|_| DLCError::InvalidSignature)?
638
- };
631
+ let sig = EcdsaSignature::from_compact(&signature).map_err(|_| DLCError::InvalidSignature)?;
639
632
 
640
633
  let secp = Secp256k1::verification_only();
641
634
  match dlc::verify_tx_input_sig(
@@ -678,8 +671,7 @@ pub fn get_raw_funding_transaction_input_signature(
678
671
  input.previous_output.txid == prev_txid && input.previous_output.vout == prev_tx_vout
679
672
  })
680
673
  .ok_or(DLCError::InvalidArgument(format!(
681
- "Input index not found in {}",
682
- prev_txid
674
+ "Input index not found in {prev_txid}"
683
675
  )))?;
684
676
 
685
677
  let secp = get_secp_context();
@@ -723,8 +715,7 @@ pub fn sign_fund_transaction_input(
723
715
  input.previous_output.txid == prev_txid && input.previous_output.vout == prev_tx_vout
724
716
  })
725
717
  .ok_or(DLCError::InvalidArgument(format!(
726
- "Input index not found in {}",
727
- prev_txid
718
+ "Input index not found in {prev_txid}"
728
719
  )))?;
729
720
 
730
721
  let secp = Secp256k1::signing_only();
@@ -803,7 +794,7 @@ pub fn sign_cet(
803
794
  let adaptor_sig = vec_to_ecdsa_adaptor_signature(adaptor_signature)?;
804
795
  let oracle_sigs = oracle_signatures
805
796
  .iter()
806
- .map(|sig| vec_to_schnorr_signature(sig))
797
+ .map(|sig| vec_to_schnorr_signature(sig.as_slice()))
807
798
  .collect::<Result<Vec<_>, _>>()?;
808
799
  let funding_sk = SecretKey::from_slice(&funding_secret_key)
809
800
  .map_err(|_| DLCError::InvalidArgument("Invalid funding secret key".to_string()))?;
@@ -818,7 +809,7 @@ pub fn sign_cet(
818
809
  &[oracle_sigs],
819
810
  &funding_sk,
820
811
  &other_pk,
821
- &funding_script,
812
+ funding_script,
822
813
  Amount::from_sat(fund_output_value),
823
814
  )
824
815
  .map_err(|e| DLCError::Secp256k1Error(e.to_string()))?;
@@ -826,7 +817,7 @@ pub fn sign_cet(
826
817
  Ok(btc_tx_to_transaction(&btc_tx))
827
818
  }
828
819
 
829
- fn vec_to_schnorr_signature(signature: &Vec<u8>) -> Result<SchnorrSignature, DLCError> {
820
+ fn vec_to_schnorr_signature(signature: &[u8]) -> Result<SchnorrSignature, DLCError> {
830
821
  let sig = SchnorrSignature::from_slice(signature).map_err(|_| DLCError::InvalidSignature)?;
831
822
  Ok(sig)
832
823
  }
@@ -845,7 +836,7 @@ pub fn create_cet_adaptor_sigs_from_oracle_info(
845
836
  ) -> Result<Vec<AdaptorSignature>, DLCError> {
846
837
  let cets = cets
847
838
  .iter()
848
- .map(|cet| transaction_to_btc_tx(cet))
839
+ .map(transaction_to_btc_tx)
849
840
  .collect::<Result<Vec<_>, _>>()?;
850
841
  let oracle_infos = oracle_info
851
842
  .iter()
@@ -893,11 +884,11 @@ pub fn create_cet_adaptor_sigs_from_oracle_info(
893
884
  &cets,
894
885
  &oracle_infos,
895
886
  &funding_sk,
896
- &funding_script,
887
+ funding_script,
897
888
  Amount::from_sat(fund_output_value),
898
889
  &msgs,
899
890
  )
900
- .map_err(|e| DLCError::InvalidArgument(format!("Error from rust-dlc: {:?}", e)))?;
891
+ .map_err(|e| DLCError::Secp256k1Error(e.to_string()))?;
901
892
 
902
893
  let adaptor_sigs = adaptor_sigs
903
894
  .iter()
@@ -966,7 +957,7 @@ pub fn verify_cet_adaptor_sig_from_oracle_info(
966
957
  &btc_tx,
967
958
  &adaptor_point,
968
959
  &pubkey,
969
- &funding_script,
960
+ funding_script,
970
961
  Amount::from_sat(total_collateral),
971
962
  ) else {
972
963
  return false;
@@ -985,7 +976,7 @@ pub fn verify_cet_adaptor_sigs_from_oracle_info(
985
976
  msgs: Vec<Vec<Vec<Vec<u8>>>>,
986
977
  ) -> bool {
987
978
  cets.into_iter()
988
- .zip(adaptor_sigs.into_iter())
979
+ .zip(adaptor_sigs)
989
980
  .enumerate()
990
981
  .all(|(i, (cet, adaptor_sig))| {
991
982
  verify_cet_adaptor_sig_from_oracle_info(
@@ -1602,11 +1593,8 @@ mod tests {
1602
1593
  let script = ScriptBuf::from_bytes(script_pubkey);
1603
1594
  let sig_hash_msg =
1604
1595
  dlc::util::get_sig_hash_msg(&btc_txn, input_index, &script, Amount::from_sat(value))?;
1605
- let sig = if signature.len() == 64 {
1606
- EcdsaSignature::from_compact(&signature).map_err(|_| DLCError::InvalidSignature)
1607
- } else {
1608
- EcdsaSignature::from_der(&signature).map_err(|_| DLCError::InvalidSignature)
1609
- }?;
1596
+ let sig =
1597
+ EcdsaSignature::from_compact(&signature).map_err(|_| DLCError::InvalidSignature)?;
1610
1598
  let pk = PublicKey::from_slice(&pk).map_err(|_| DLCError::InvalidPublicKey)?;
1611
1599
  secp.verify_ecdsa(&sig_hash_msg, &sig, &pk)
1612
1600
  .map_err(|_| DLCError::InvalidSignature)?;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bennyblader/ddk-rn",
3
- "version": "0.3.13",
3
+ "version": "0.3.15",
4
4
  "description": "dlcdevkit bindings for react-native",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",