#secret-toolkit #secret-network #secret-contracts

secret-toolkit-crypto

Cryptographic tools for writing Secret Contracts

9 releases (5 breaking)

new 0.10.3 Feb 20, 2025
0.10.2 Dec 11, 2024
0.10.1 Nov 13, 2024
0.10.0 Oct 18, 2023
0.2.0 Jan 16, 2022

#7 in #secret-toolkit

Download history 68/week @ 2024-10-30 32/week @ 2024-11-06 164/week @ 2024-11-13 146/week @ 2024-11-20 63/week @ 2024-11-27 127/week @ 2024-12-04 699/week @ 2024-12-11 230/week @ 2024-12-18 55/week @ 2024-12-25 45/week @ 2025-01-01 45/week @ 2025-01-08 127/week @ 2025-01-15 91/week @ 2025-01-22 30/week @ 2025-01-29 195/week @ 2025-02-05 158/week @ 2025-02-12

482 downloads per month
Used in 5 crates (4 directly)

Custom license

23KB
267 lines

Secret Contract Development Toolkit - Crypto Tools

⚠️ This package is a sub-package of the secret-toolkit package. Please see its crate page for more context.

This crate contains common cryptography tools used in the development of Secret Contracts running on the Secret Network.

Note: It has a deep dependency tree and increases compilation times significantly.

Add the following to your cargo.toml file:

[dependencies]
secret-toolkit = { version = "0.10.3", features = ["crypto"] }
secret-toolkit-crypto = { version = "0.10.3", features = ["hash", "rand", "ecc-secp256k1"] }

Example usage

# extern crate secret_toolkit_crypto;

# use secret_toolkit_crypto::{sha_256, ContractPrng, secp256k1::{PrivateKey, PublicKey, Signature}};
# use base64;
# use cosmwasm_std::{StdError, testing::mock_dependencies};

# fn main() -> Result<(), StdError> {
let deps = mock_dependencies();
let entropy: String = "secret".to_owned();
let prng_seed: Vec<u8> = sha_256(base64::encode(&entropy.clone()).as_bytes()).to_vec();

let mut rng = ContractPrng::new(&prng_seed, entropy.as_bytes());

let private_key: PrivateKey = PrivateKey::parse(&rng.rand_bytes())?;
let public_key: PublicKey = private_key.pubkey();

let message: &[u8] = b"message";
let signature: Signature = private_key.sign(message, deps.api);
# Ok(())
# }

Cargo Features

  • ["hash"] - Provides an easy-to-use sha256 function. Uses sha2.
  • ["rand"] - Used to generate pseudo-random numbers. Uses [rand_chacha] and [rand_core].
  • ["ecc-secp256k1"] - Contains types and methods for working with secp256k1 keys and signatures, as well as standard constants for key sizes. Uses secp256k1.

Dependencies

~3–6MB
~115K SLoC