Skip to content

Commit

Permalink
chore: remove rand
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Apr 9, 2024
1 parent 6f39374 commit a6d4f18
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 37 deletions.
23 changes: 11 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions moksha-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ anyhow = "1.0.79"
url = "2.5.0"
base64 = "0.22.0"
bitcoin_hashes = "0.13.0"
rand = "0.8.5"
secp256k1 = { version = "0.28.2", features = ["rand", "serde"] }
serde = { version = "1.0.196", features = ["derive"] }
serde_json = "1.0.113"
Expand All @@ -30,7 +29,7 @@ utoipa = { version = "4.2.0" }
# getrandom is transitive dependency of rand
# on wasm, we need to enable the js backend
# see https://docs.rs/getrandom/latest/getrandom/#indirect-dependencies and https://docs.rs/getrandom/latest/getrandom/#webassembly-support
getrandom = { version = "0.2.11", features = ["js"] }
getrandom = { version = "0.2.14", features = ["js"] }

[dev-dependencies]
anyhow = "1.0.79"
Expand Down
9 changes: 0 additions & 9 deletions moksha-core/src/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
//! The `SplitAmount` struct represents a split amount, with a `Vec<u64>` field for the split amounts. The struct provides a `create_secrets` method that generates a vector of random strings for use as secrets in the split transaction. The struct also implements the `IntoIterator` trait, which allows it to be iterated over as a vector of `u64` values.
//!
//! Both the `Amount` and `SplitAmount` structs are serializable and deserializable using serde.
use rand::distributions::Alphanumeric;
use rand::Rng;
#[derive(Debug, Clone)]
pub struct Amount(pub u64);
Expand Down Expand Up @@ -66,13 +64,6 @@ fn split_amount(amount: u64) -> Vec<u64> {
.collect::<Vec<u64>>()
}

pub fn generate_random_string() -> String {
rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(24)
.map(char::from)
.collect()
}

#[cfg(test)]
mod tests {
Expand Down
15 changes: 1 addition & 14 deletions moksha-core/src/keyset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,12 @@ use utoipa::ToSchema;
use bitcoin_hashes::{sha256, Hash};

use itertools::Itertools;
use rand::RngCore;
use secp256k1::{PublicKey, Secp256k1, SecretKey};

use crate::{error::MokshaCoreError, primitives::CurrencyUnit};

const MAX_ORDER: u64 = 64;

pub fn generate_hash() -> String {
let mut rng = rand::thread_rng();
let mut random = [0u8; 32];
rng.fill_bytes(&mut random);
sha256::Hash::hash(&random).to_string()
}

#[derive(Debug, Clone)]
pub struct MintKeyset {
Expand Down Expand Up @@ -205,7 +198,7 @@ pub fn derive_pubkey(seed: &str) -> Result<PublicKey, MokshaCoreError> {

#[cfg(test)]
mod tests {
use crate::keyset::{derive_pubkey, generate_hash, KeysetId};
use crate::keyset::{derive_pubkey, KeysetId};
use pretty_assertions::assert_eq;
use secp256k1::PublicKey;
use std::collections::HashMap;
Expand All @@ -218,12 +211,6 @@ mod tests {
Ok(())
}

#[test]
fn test_generate_hash() {
let hash = generate_hash();
assert_eq!(hash.len(), 64);
}

#[test]
fn test_derive_pubkey() -> anyhow::Result<()> {
let result = derive_pubkey("supersecretprivatekey")?;
Expand Down

0 comments on commit a6d4f18

Please sign in to comment.