From bd7962db21257a6e6b957225ce14fc47fa4a47a5 Mon Sep 17 00:00:00 2001 From: cygnet <131168104+cygnet3@users.noreply.github.com> Date: Thu, 17 Aug 2023 15:28:32 +0200 Subject: [PATCH] Downgrade secp256k1 to 0.24 (#15) --- Cargo.toml | 2 +- src/receiving.rs | 2 +- src/utils.rs | 4 ++-- tests/common/utils.rs | 20 ++++++++++++++++---- tests/vector_tests.rs | 14 +++++++++----- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7a0efcc..8d2e4a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["lib"] [dependencies] # bdk = {version = "0.20.0", features= ["all-keys"] } -secp256k1 = {version = "0.27", features = ["bitcoin-hashes-std"] } +secp256k1 = {version = "0.24", features = ["bitcoin-hashes-std"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" hex = "0.4" diff --git a/src/receiving.rs b/src/receiving.rs index b0147f1..369eb87 100644 --- a/src/receiving.rs +++ b/src/receiving.rs @@ -180,7 +180,7 @@ pub fn verify_and_calculate_signatures( ) -> Result> { let secp = secp256k1::Secp256k1::new(); let msg = Message::from_hashed_data::(b"message"); - let aux = secp256k1::hashes::sha256::Hash::hash(b"random auxiliary data").to_byte_array(); + let aux = secp256k1::hashes::sha256::Hash::hash(b"random auxiliary data").into_inner(); let mut res: Vec = vec![]; for output in add_to_wallet { diff --git a/src/utils.rs b/src/utils.rs index d799593..62d8706 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -7,7 +7,7 @@ use crate::{error::Error, structs::Outpoint}; pub type Result = std::result::Result; pub fn sha256(message: &[u8]) -> [u8; 32] { - sha256::Hash::hash(message).to_byte_array() + sha256::Hash::hash(message).into_inner() } pub fn ser_uint32(u: u32) -> Vec { @@ -35,5 +35,5 @@ pub fn hash_outpoints(sending_data: &HashSet) -> Result<[u8; 32]> { engine.write_all(&v).unwrap(); } - Ok(sha256::Hash::from_engine(engine).to_byte_array()) + Ok(sha256::Hash::from_engine(engine).into_inner()) } diff --git a/tests/common/utils.rs b/tests/common/utils.rs index 6b86510..dff6d0a 100644 --- a/tests/common/utils.rs +++ b/tests/common/utils.rs @@ -1,6 +1,14 @@ -use std::{collections::HashSet, fs::File, io::{Read, Write}, str::FromStr}; +use std::{ + collections::HashSet, + fs::File, + io::{Read, Write}, + str::FromStr, +}; -use secp256k1::{PublicKey, SecretKey, XOnlyPublicKey, hashes::{sha256, Hash}, Scalar}; +use secp256k1::{ + hashes::{sha256, Hash}, + PublicKey, Scalar, SecretKey, XOnlyPublicKey, +}; use serde_json::from_str; use silentpayments::structs::Outpoint; @@ -86,7 +94,11 @@ pub fn get_a_sum_secret_keys(input: &Vec<(SecretKey, bool)>) -> SecretKey { result } -pub fn compute_ecdh_shared_secret(a_sum: SecretKey, B_scan: PublicKey, outpoints_hash: Scalar) -> PublicKey { +pub fn compute_ecdh_shared_secret( + a_sum: SecretKey, + B_scan: PublicKey, + outpoints_hash: Scalar, +) -> PublicKey { let secp = secp256k1::Secp256k1::new(); let diffie_hellman = B_scan.mul_tweak(&secp, &a_sum.into()).unwrap(); @@ -114,5 +126,5 @@ pub fn hash_outpoints(sending_data: &HashSet) -> [u8; 32] { engine.write_all(&v).unwrap(); } - sha256::Hash::from_engine(engine).to_byte_array() + sha256::Hash::from_engine(engine).into_inner() } diff --git a/tests/vector_tests.rs b/tests/vector_tests.rs index bf2e56b..2e66cca 100644 --- a/tests/vector_tests.rs +++ b/tests/vector_tests.rs @@ -5,18 +5,21 @@ use silentpayments::receiving; #[cfg(test)] mod tests { - use std::{collections::{HashSet, HashMap}, str::FromStr}; + use std::{ + collections::{HashMap, HashSet}, + str::FromStr, + }; - use secp256k1::{SecretKey, PublicKey, Scalar}; + use secp256k1::{PublicKey, Scalar, SecretKey}; use silentpayments::sending::{decode_scan_pubkey, generate_recipient_pubkeys}; use crate::{ common::{ structs::TestData, utils::{ - self, decode_input_pub_keys, decode_outpoints, + self, compute_ecdh_shared_secret, decode_input_pub_keys, decode_outpoints, decode_outputs_to_check, decode_priv_keys, decode_recipients, - get_a_sum_secret_keys, hash_outpoints, compute_ecdh_shared_secret, + get_a_sum_secret_keys, hash_outpoints, }, }, receiving::{ @@ -61,7 +64,8 @@ mod tests { let ecdh_shared_secret = compute_ecdh_shared_secret(a_sum, B_scan, outpoints_hash); ecdh_shared_secrets.insert(B_scan, ecdh_shared_secret); } - let outputs = generate_recipient_pubkeys(silent_addresses, ecdh_shared_secrets).unwrap(); + let outputs = + generate_recipient_pubkeys(silent_addresses, ecdh_shared_secrets).unwrap(); for output_pubkeys in &outputs { for pubkey in output_pubkeys.1 {