From 2d3b5a4f46507146e7f4cc94fbc35a98fd401197 Mon Sep 17 00:00:00 2001 From: Sosthene Date: Mon, 3 Jun 2024 00:16:42 +0200 Subject: [PATCH] rm crate::common --- src/common.rs | 19 ------------------- src/lib.rs | 1 - src/receiving.rs | 7 +++++-- src/sending.rs | 3 ++- src/utils.rs | 2 +- src/utils/common.rs | 19 ++++++++++++++++++- 6 files changed, 26 insertions(+), 25 deletions(-) delete mode 100644 src/common.rs diff --git a/src/common.rs b/src/common.rs deleted file mode 100644 index 0a8882e..0000000 --- a/src/common.rs +++ /dev/null @@ -1,19 +0,0 @@ -use crate::utils::hash::SharedSecretHash; -use crate::Result; -use bitcoin_hashes::Hash; -use secp256k1::{PublicKey, Scalar, Secp256k1, SecretKey}; - -pub(crate) fn calculate_t_n(ecdh_shared_secret: &PublicKey, k: u32) -> Result { - let hash = SharedSecretHash::from_ecdh_and_k(ecdh_shared_secret, k).to_byte_array(); - let sk = SecretKey::from_slice(&hash)?; - - Ok(sk) -} - -pub(crate) fn calculate_P_n(B_spend: &PublicKey, t_n: Scalar) -> Result { - let secp = Secp256k1::new(); - - let P_n = B_spend.add_exp_tweak(&secp, &t_n)?; - - Ok(P_n) -} diff --git a/src/lib.rs b/src/lib.rs index 8af890c..4b0b4f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,6 @@ //! Alternatively, have a look at [Sp client](https://github.com/cygnet3/sp-client/tree/master), //! which is a WIP wallet client for building silent payment wallets. #![allow(dead_code, non_snake_case)] -mod common; mod error; #[cfg(feature = "receiving")] diff --git a/src/receiving.rs b/src/receiving.rs index 92082f0..39b5fbc 100644 --- a/src/receiving.rs +++ b/src/receiving.rs @@ -16,8 +16,11 @@ use std::{ }; use crate::{ - common::{calculate_P_n, calculate_t_n}, - utils::{hash::LabelHash, Network}, + utils::{ + common::{calculate_P_n, calculate_t_n}, + hash::LabelHash, + Network, + }, Error, Result, }; use bech32::ToBase32; diff --git a/src/sending.rs b/src/sending.rs index 3bd8a6c..ec8a297 100644 --- a/src/sending.rs +++ b/src/sending.rs @@ -11,9 +11,10 @@ use secp256k1::{PublicKey, Secp256k1, SecretKey, XOnlyPublicKey}; use std::collections::HashMap; +use crate::utils::common::calculate_t_n; use crate::utils::sending::calculate_ecdh_shared_secret; use crate::utils::SilentPaymentAddress; -use crate::{common::calculate_t_n, Result}; +use crate::Result; /// Create outputs for a given set of silent payment recipients and their corresponding shared secrets. /// diff --git a/src/utils.rs b/src/utils.rs index 15c05ef..fcaa0fd 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -8,7 +8,7 @@ pub mod receiving; #[cfg(feature = "sending")] pub mod sending; -mod common; +pub(crate) mod common; pub use common::Network; pub use common::SilentPaymentAddress; diff --git a/src/utils/common.rs b/src/utils/common.rs index 1745b2d..6048f22 100644 --- a/src/utils/common.rs +++ b/src/utils/common.rs @@ -1,11 +1,28 @@ use core::fmt; +use crate::utils::hash::SharedSecretHash; use crate::Error; use crate::Result; use bech32::{FromBase32, ToBase32}; -use secp256k1::PublicKey; +use bitcoin_hashes::Hash; +use secp256k1::{PublicKey, Scalar, Secp256k1, SecretKey}; use serde::{Deserialize, Serialize}; +pub(crate) fn calculate_t_n(ecdh_shared_secret: &PublicKey, k: u32) -> Result { + let hash = SharedSecretHash::from_ecdh_and_k(ecdh_shared_secret, k).to_byte_array(); + let sk = SecretKey::from_slice(&hash)?; + + Ok(sk) +} + +pub(crate) fn calculate_P_n(B_spend: &PublicKey, t_n: Scalar) -> Result { + let secp = Secp256k1::new(); + + let P_n = B_spend.add_exp_tweak(&secp, &t_n)?; + + Ok(P_n) +} + /// The network format used for this silent payment address. /// /// There are three network types: Mainnet (`sp1..`), Testnet (`tsp1..`), and Regtest (`sprt1..`).