Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use of rand from generated addresses, nonces, salts, and issuer pks #1135

Merged
merged 9 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions soroban-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ soroban-env-host = { workspace = true, features = [] }
soroban-ledger-snapshot = { workspace = true }
stellar-strkey = { workspace = true }
arbitrary = { version = "1.3.0", features = ["derive"], optional = true }
serde = { version = "1.0.0", features = ["derive"] }
serde_json = "1.0.0"
ed25519-dalek = { version = "2.0.0", features = ["rand_core"], optional = true }
# match the version of rand used in dalek
rand = "0.8.5"
Expand Down
15 changes: 8 additions & 7 deletions soroban-sdk/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{unwrap::UnwrapInfallible, Bytes, Vec};
/// that allow customizing authentication logic and adding custom authorization
/// rules.
///
/// In tests Addresses should be generated via `Address::random()`.
/// In tests Addresses should be generated via `Address::generate()`.
#[derive(Clone)]
pub struct Address {
env: Env,
Expand Down Expand Up @@ -299,18 +299,19 @@ impl Address {
}
}

#[cfg(not(target_family = "wasm"))]
#[cfg(any(not(target_family = "wasm"), test, feature = "testutils"))]
use crate::env::xdr::Hash;
#[cfg(any(test, feature = "testutils"))]
use crate::testutils::random;
use crate::unwrap::UnwrapOptimized;

#[cfg(any(test, feature = "testutils"))]
#[cfg_attr(feature = "docs", doc(cfg(feature = "testutils")))]
impl crate::testutils::Address for Address {
fn random(env: &Env) -> Self {
let sc_addr = ScVal::Address(ScAddress::Contract(Hash(random())));
Self::try_from_val(env, &sc_addr).unwrap()
fn generate(env: &Env) -> Self {
Self::try_from_val(
env,
&ScAddress::Contract(Hash(env.with_generator(|mut g| g.address()))),
)
.unwrap()
}
}

Expand Down
Loading