|
3 | 3 | //! running on the Secret Network.
|
4 | 4 | //!
|
5 | 5 | //! Note: It has a deep dependency tree and increases compilation times significantly.
|
6 |
| -//! |
| 6 | +//! |
7 | 7 | //! Add the following to your `cargo.toml` file:
|
8 |
| -//! |
| 8 | +//! |
9 | 9 | //! ```toml
|
10 | 10 | //! [dependencies]
|
11 | 11 | //! secret-toolkit = { version = "0.3.0", features = ["crypto"] }
|
12 | 12 | //! secret-toolkit-crypto = { version = "0.3.0", features = ["hash", "rand", "ecc-secp256k1"] }
|
13 | 13 | //! ```
|
14 |
| -//! |
| 14 | +//! |
15 | 15 | //! ## Example usage:
|
16 |
| -//! ```rust |
17 |
| -//! use secret_toolkit::{ |
18 |
| -//! crypto::secp256k1::{PrivateKey, PublicKey, Signature}, |
19 |
| -//! crypto::{sha_256, Prng}, |
20 |
| -//! }; |
21 | 16 | //!
|
| 17 | +//! ```ignore |
| 18 | +//! # extern crate secret_toolkit_crypto; |
| 19 | +//! |
| 20 | +//! # use secret_toolkit_crypto::{sha_256, Prng, secp256k1::{PrivateKey, PublicKey, Signature}}; |
| 21 | +//! # use base64; |
| 22 | +//! # use cosmwasm_std::{StdError, testing::mock_dependencies}; |
| 23 | +//! |
| 24 | +//! # fn main() -> Result<(), StdError> { |
| 25 | +//! # let deps = mock_dependencies(20, &[]); |
22 | 26 | //! let entropy: String = "secret".to_owned();
|
23 |
| -//! let prng_seed: Vec<u8> = sha_256(base64::encode(entropy.clone()).as_bytes()).to_vec(); |
| 27 | +//! let prng_seed: Vec<u8> = sha_256(base64::encode(&entropy.clone()).as_bytes()).to_vec(); |
24 | 28 | //!
|
25 |
| -//! let mut rng = Prng::new(prng_seed, entropy.as_bytes()); |
| 29 | +//! let mut rng = Prng::new(&prng_seed, entropy.as_bytes()); |
26 | 30 | //!
|
27 |
| -//! let private_key: PrivateKey = PrivateKey::parse(&rng.randbytes()); |
| 31 | +//! let private_key: PrivateKey = PrivateKey::parse(&rng.rand_bytes())?; |
28 | 32 | //! let public_key: PublicKey = private_key.pubkey();
|
29 | 33 | //!
|
30 | 34 | //! let message: &[u8] = b"message";
|
31 | 35 | //! let signature: Signature = private_key.sign(message, deps.api);
|
| 36 | +//! # Ok(()) |
| 37 | +//! # } |
32 | 38 | //! ```
|
33 |
| -//! |
| 39 | +//! |
34 | 40 | //! ### Cargo Features
|
35 | 41 | //! - `["hash"]` - Provides an easy-to-use `sha256` function. Uses [sha2](https://crates.io/crates/sha2).
|
36 | 42 | //! - `["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, |
| 43 | +//! - `["ecc-secp256k1"]` - Contains types and methods for working with secp256k1 keys and signatures, |
38 | 44 | //! as well as standard constants for key sizes. Uses [secp256k1](https://crates.io/crates/secp256k1).
|
39 | 45 | //!
|
| 46 | +
|
| 47 | +// fn hello() { |
| 48 | +// sha_256(data) |
| 49 | +// } |
| 50 | + |
| 51 | +// mod tom { |
| 52 | +// use crate::sha_256; |
| 53 | + |
| 54 | +// fn langer() { |
| 55 | +// sha_256(data) |
| 56 | +// } |
| 57 | +// } |
| 58 | + |
40 | 59 | #[cfg(feature = "hash")]
|
41 | 60 | mod hash;
|
42 | 61 | #[cfg(feature = "rand")]
|
|
0 commit comments