Skip to content

Commit

Permalink
rm crate::common
Browse files Browse the repository at this point in the history
  • Loading branch information
Sosthene00 authored and cygnet3 committed Jun 3, 2024
1 parent a8e0d1b commit 2d3b5a4
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
19 changes: 0 additions & 19 deletions src/common.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
7 changes: 5 additions & 2 deletions src/receiving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/sending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 18 additions & 1 deletion src/utils/common.rs
Original file line number Diff line number Diff line change
@@ -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<SecretKey> {
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<PublicKey> {
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..`).
Expand Down

0 comments on commit 2d3b5a4

Please sign in to comment.