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