|
| 1 | +//! # Crypto |
| 2 | +//! This crate contains common cryptography tools used in the development of Secret Contracts |
| 3 | +//! running on the Secret Network. |
| 4 | +//! |
| 5 | +//! Note: It has a deep dependency tree and increases compilation times significantly. |
| 6 | +//! |
| 7 | +//! Add the following to your `cargo.toml` file: |
| 8 | +//! |
| 9 | +//! ```toml |
| 10 | +//! [dependencies] |
| 11 | +//! secret-toolkit = { version = "0.3.0", features = ["crypto"] } |
| 12 | +//! secret-toolkit-crypto = { version = "0.3.0", features = ["hash", "rand", "ecc-secp256k1"] } |
| 13 | +//! ``` |
| 14 | +//! |
| 15 | +//! ## Example usage: |
| 16 | +//! ```rust |
| 17 | +//! use secret_toolkit::{ |
| 18 | +//! crypto::secp256k1::{PrivateKey, PublicKey, Signature}, |
| 19 | +//! crypto::{sha_256, Prng}, |
| 20 | +//! }; |
| 21 | +//! |
| 22 | +//! let entropy: String = "secret".to_owned(); |
| 23 | +//! let prng_seed: Vec<u8> = sha_256(base64::encode(entropy.clone()).as_bytes()).to_vec(); |
| 24 | +//! |
| 25 | +//! let mut rng = Prng::new(prng_seed, entropy.as_bytes()); |
| 26 | +//! |
| 27 | +//! let private_key: PrivateKey = PrivateKey::parse(&rng.randbytes()); |
| 28 | +//! let public_key: PublicKey = private_key.pubkey(); |
| 29 | +//! |
| 30 | +//! let message: &[u8] = b"message"; |
| 31 | +//! let signature: Signature = private_key.sign(message, deps.api); |
| 32 | +//! ``` |
| 33 | +//! |
| 34 | +//! ### Cargo Features |
| 35 | +//! - `["hash"]` - Provides an easy-to-use `sha256` function. Uses [sha2](https://crates.io/crates/sha2). |
| 36 | +//! - `["rand"]` - Used to generate pseudo-random numbers. Uses [rand_chacha] and [rand_core]. |
| 37 | +//! - `["ecc-secp256k1"]` - Contains types and methods for working with secp256k1 keys and signatures, |
| 38 | +//! as well as standard constants for key sizes. Uses [secp256k1](https://crates.io/crates/secp256k1). |
| 39 | +//! |
1 | 40 | #[cfg(feature = "hash")]
|
2 | 41 | mod hash;
|
3 | 42 | #[cfg(feature = "rand")]
|
|
0 commit comments