Skip to content

Commit

Permalink
cosmrs: add getrandom feature
Browse files Browse the repository at this point in the history
Enables support for using CosmRS in environments unsupported by
`getrandom`, like non-JS WASM environments
  • Loading branch information
tony-iqlusion committed Oct 3, 2023
1 parent 25e6b59 commit 051ab39
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

8 changes: 3 additions & 5 deletions cosmrs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cosmos-sdk-proto = { version = "=0.20.0-pre", default-features = false, path = "
ecdsa = { version = "0.16", features = ["std"] }
eyre = "0.6"
k256 = { version = "0.13", features = ["ecdsa", "sha256"] }
rand_core = { version = "0.6", features = ["std"] }
rand_core = { version = "0.6", default-features = false }
serde = { version = "1", features = ["serde_derive"] }
serde_json = "1"
subtle-encoding = { version = "0.5", features = ["bech32-preview"] }
Expand All @@ -28,16 +28,14 @@ bip32 = { version = "0.5", optional = true }
tendermint-rpc = { version = "0.34", optional = true, features = ["http-client"] }
tokio = { version = "1", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2", features = ["js"] }

[dev-dependencies]
hex-literal = "0.4"

[features]
default = ["bip32"]
default = ["bip32", "getrandom"]
cosmwasm = ["cosmos-sdk-proto/cosmwasm"]
dev = ["rpc", "tokio"]
getrandom = ["rand_core/getrandom"]
grpc = ["cosmos-sdk-proto/grpc-transport", "grpc-core"]
grpc-core = ["cosmos-sdk-proto/grpc"]
rpc = ["tendermint-rpc"]
Expand Down
3 changes: 3 additions & 0 deletions cosmrs/src/crypto/secp256k1/signing_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use crate::{
};
use ecdsa::signature::{Keypair, Signer};
use k256::ecdsa::VerifyingKey;

#[cfg(feature = "getrandom")]
use rand_core::OsRng;

/// ECDSA/secp256k1 signing key (i.e. private key)
Expand Down Expand Up @@ -40,6 +42,7 @@ impl SigningKey {
}

/// Generate a random signing key.
#[cfg(feature = "getrandom")]
pub fn random() -> Self {
Self::new(Box::new(k256::ecdsa::SigningKey::random(&mut OsRng)))
}
Expand Down

0 comments on commit 051ab39

Please sign in to comment.