Skip to content

Commit 95428dd

Browse files
authored
Merge pull request #87 from scrtlabs/0.9
v0.9.0
2 parents 0c901b6 + ae49a4c commit 95428dd

File tree

16 files changed

+91
-45
lines changed

16 files changed

+91
-45
lines changed

Cargo.toml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "secret-toolkit"
3-
version = "0.8.2"
3+
version = "0.9.0"
44
edition = "2021"
55
authors = ["SCRT Labs <[email protected]>"]
66
license-file = "LICENSE"
@@ -36,15 +36,15 @@ utils = ["secret-toolkit-utils"]
3636
viewing-key = ["secret-toolkit-viewing-key"]
3737

3838
[dependencies]
39-
secret-toolkit-crypto = { version = "0.8", path = "packages/crypto", optional = true }
40-
secret-toolkit-incubator = { version = "0.8", path = "packages/incubator", optional = true }
41-
secret-toolkit-permit = { version = "0.8", path = "packages/permit", optional = true }
42-
secret-toolkit-serialization = { version = "0.8", path = "packages/serialization", optional = true }
43-
secret-toolkit-snip20 = { version = "0.8", path = "packages/snip20", optional = true }
44-
secret-toolkit-snip721 = { version = "0.8", path = "packages/snip721", optional = true }
45-
secret-toolkit-storage = { version = "0.8", path = "packages/storage", optional = true }
46-
secret-toolkit-utils = { version = "0.8", path = "packages/utils", optional = true }
47-
secret-toolkit-viewing-key = { version = "0.8", path = "packages/viewing_key", optional = true }
39+
secret-toolkit-crypto = { version = "0.9", path = "packages/crypto", optional = true }
40+
secret-toolkit-incubator = { version = "0.9", path = "packages/incubator", optional = true }
41+
secret-toolkit-permit = { version = "0.9", path = "packages/permit", optional = true }
42+
secret-toolkit-serialization = { version = "0.9", path = "packages/serialization", optional = true }
43+
secret-toolkit-snip20 = { version = "0.9", path = "packages/snip20", optional = true }
44+
secret-toolkit-snip721 = { version = "0.9", path = "packages/snip721", optional = true }
45+
secret-toolkit-storage = { version = "0.9", path = "packages/storage", optional = true }
46+
secret-toolkit-utils = { version = "0.9", path = "packages/utils", optional = true }
47+
secret-toolkit-viewing-key = { version = "0.9", path = "packages/viewing_key", optional = true }
4848

4949

5050
[workspace]
@@ -57,5 +57,7 @@ members = ["packages/*"]
5757
[workspace.dependencies]
5858
schemars = { version = "0.8.11" }
5959
serde = { version = "1.0" }
60-
cosmwasm-std = { git = "https://github.com/scrtlabs/cosmwasm", tag = "v1.1.9-secret" }
61-
cosmwasm-storage = { git = "https://github.com/scrtlabs/cosmwasm", tag = "v1.1.9-secret" }
60+
cosmwasm-std = { package = "secret-cosmwasm-std", version = "1.1.10", features = [
61+
"random",
62+
] }
63+
cosmwasm-storage = { package = "secret-cosmwasm-storage", version = "1.1.10" }

Releases.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
## Unreleased
44

5+
## v0.9.0
6+
7+
### Features
8+
9+
- Replace `cosmwasm-std` with `secret-cosmwasm-std` in prep for crates.io packages ([#87](https://github.com/scrtlabs/secret-toolkit/pull/87)).
10+
- Add `RngCore` & `CryptoRng` trait to `Prng` ([#87](https://github.com/scrtlabs/secret-toolkit/pull/87)).
11+
- Added `from_env` function for `ContractPrng` that consumes `env.block.random` ([#87](https://github.com/scrtlabs/secret-toolkit/pull/87)).
12+
13+
### Breaking
14+
15+
- Renamed `Prng` as `ContractPrng` ([#87](https://github.com/scrtlabs/secret-toolkit/pull/87)).
16+
517
## v0.8.2
618

719
### Bug fixes

packages/crypto/Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "secret-toolkit-crypto"
3-
version = "0.8.2"
3+
version = "0.9.0"
44
edition = "2021"
55
authors = ["SCRT Labs <[email protected]>"]
66
license-file = "../../LICENSE"
@@ -14,21 +14,22 @@ keywords = ["secret-network", "secret-contracts", "secret-toolkit"]
1414
all-features = true
1515

1616
[features]
17+
default = ["hash", "ecc-secp256k1", "rand"]
1718
hash = ["sha2"]
1819
ecc-secp256k1 = ["secp256k1"]
19-
rand = ["rand_chacha", "rand_core"]
20+
rand = ["hash", "rand_chacha", "rand_core"]
2021

2122
[dependencies]
2223
rand_core = { version = "0.6.4", default-features = false, optional = true }
2324
rand_chacha = { version = "0.3.1", default-features = false, optional = true }
2425
sha2 = { version = "0.10.6", default-features = false, optional = true }
25-
secp256k1 = { version = "0.24.1", default-features = false, features = [
26+
secp256k1 = { version = "0.27.0", default-features = false, features = [
2627
"alloc",
2728
], optional = true }
2829
cosmwasm-std = { workspace = true }
2930

3031
[dev-dependencies]
31-
secp256k1 = { version = "0.24.1", default-features = false, features = [
32+
secp256k1 = { version = "0.27.0", default-features = false, features = [
3233
"alloc",
3334
"rand-std",
3435
] }

packages/crypto/Readme.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ Add the following to your `cargo.toml` file:
1111

1212
```toml
1313
[dependencies]
14-
secret-toolkit = { version = "0.8.2", features = ["crypto"] }
15-
secret-toolkit-crypto = { version = "0.8.2", features = ["hash", "rand", "ecc-secp256k1"] }
14+
secret-toolkit = { version = "0.9.0", features = ["crypto"] }
15+
secret-toolkit-crypto = { version = "0.9.0", features = ["hash", "rand", "ecc-secp256k1"] }
1616
```
1717

1818
## Example usage
1919

2020
```rust
2121
# extern crate secret_toolkit_crypto;
2222

23-
# use secret_toolkit_crypto::{sha_256, Prng, secp256k1::{PrivateKey, PublicKey, Signature}};
23+
# use secret_toolkit_crypto::{sha_256, ContractPrng, secp256k1::{PrivateKey, PublicKey, Signature}};
2424
# use base64;
2525
# use cosmwasm_std::{StdError, testing::mock_dependencies};
2626

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

32-
let mut rng = Prng::new(&prng_seed, entropy.as_bytes());
32+
let mut rng = ContractPrng::new(&prng_seed, entropy.as_bytes());
3333

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

packages/crypto/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ pub mod secp256k1;
1111
pub use hash::{sha_256, SHA256_HASH_SIZE};
1212

1313
#[cfg(feature = "rand")]
14-
pub use rng::Prng;
14+
pub use rng::ContractPrng;

packages/crypto/src/rng.rs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
use rand_chacha::ChaChaRng;
2-
use rand_core::{RngCore, SeedableRng};
2+
use rand_core::{CryptoRng, RngCore, SeedableRng};
33
use sha2::{Digest, Sha256};
44

5-
pub struct Prng {
5+
use cosmwasm_std::Env;
6+
7+
pub struct ContractPrng {
68
pub rng: ChaChaRng,
79
}
810

9-
impl Prng {
11+
impl ContractPrng {
12+
13+
pub fn from_env(env: &Env) -> Self {
14+
let seed = env.block.random.as_ref().unwrap();
15+
16+
Self::new(seed.as_slice(), &[])
17+
}
18+
1019
pub fn new(seed: &[u8], entropy: &[u8]) -> Self {
1120
let mut hasher = Sha256::new();
1221

@@ -35,6 +44,26 @@ impl Prng {
3544
}
3645
}
3746

47+
impl RngCore for ContractPrng {
48+
fn next_u32(&mut self) -> u32 {
49+
self.rng.next_u32()
50+
}
51+
52+
fn next_u64(&mut self) -> u64 {
53+
self.rng.next_u64()
54+
}
55+
56+
fn fill_bytes(&mut self, dest: &mut [u8]) {
57+
self.rng.fill_bytes(dest)
58+
}
59+
60+
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> {
61+
self.rng.try_fill_bytes(dest)
62+
}
63+
}
64+
65+
impl CryptoRng for ContractPrng {}
66+
3867
#[cfg(test)]
3968
mod tests {
4069
use super::*;
@@ -43,7 +72,7 @@ mod tests {
4372
/// different random bytes every time it is called.
4473
#[test]
4574
fn test_rng() {
46-
let mut rng = Prng::new(b"foo", b"bar!");
75+
let mut rng = ContractPrng::new(b"foo", b"bar!");
4776
let r1: [u8; 32] = [
4877
155, 11, 21, 97, 252, 65, 160, 190, 100, 126, 85, 251, 47, 73, 160, 49, 216, 182, 93,
4978
30, 185, 67, 166, 22, 34, 10, 213, 112, 21, 136, 49, 214,
@@ -68,7 +97,7 @@ mod tests {
6897

6998
#[test]
7099
fn test_rand_bytes_counter() {
71-
let mut rng = Prng::new(b"foo", b"bar");
100+
let mut rng = ContractPrng::new(b"foo", b"bar");
72101

73102
let r1: [u8; 32] = [
74103
114, 227, 179, 76, 120, 34, 236, 42, 204, 27, 153, 74, 44, 29, 158, 162, 180, 202, 165,

packages/incubator/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "secret-toolkit-incubator"
3-
version = "0.8.2"
3+
version = "0.9.0"
44
edition = "2021"
55
authors = ["SCRT Labs <[email protected]>"]
66
license-file = "../../LICENSE"
@@ -16,7 +16,7 @@ all-features = true
1616
[dependencies]
1717
serde = { workspace = true, optional = true }
1818
cosmwasm-std = { workspace = true, optional = true }
19-
secret-toolkit-serialization = { version = "0.8", path = "../serialization", optional = true }
19+
secret-toolkit-serialization = { version = "0.9", path = "../serialization", optional = true }
2020

2121
[features]
2222
generational-store = ["secret-toolkit-serialization", "serde", "cosmwasm-std"]

packages/permit/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "secret-toolkit-permit"
3-
version = "0.8.2"
3+
version = "0.9.0"
44
edition = "2021"
55
authors = ["SCRT Labs <[email protected]>"]
66
license-file = "../../LICENSE"
@@ -19,7 +19,7 @@ serde = { workspace = true }
1919
ripemd = { version = "0.1.3", default-features = false }
2020
schemars = { workspace = true }
2121
bech32 = "0.9.1"
22-
remain = "0.2.2"
23-
secret-toolkit-crypto = { version = "0.8.2", path = "../crypto", features = [
22+
remain = "0.2.8"
23+
secret-toolkit-crypto = { version = "0.9.0", path = "../crypto", features = [
2424
"hash",
2525
] }

packages/serialization/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "secret-toolkit-serialization"
3-
version = "0.8.2"
3+
version = "0.9.0"
44
edition = "2021"
55
authors = ["SCRT Labs <[email protected]>"]
66
license-file = "../../LICENSE"

packages/snip20/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "secret-toolkit-snip20"
3-
version = "0.8.2"
3+
version = "0.9.0"
44
edition = "2021"
55
authors = ["SCRT Labs <[email protected]>"]
66
license-file = "../../LICENSE"
@@ -17,4 +17,4 @@ all-features = true
1717
serde = { workspace = true }
1818
schemars = { workspace = true }
1919
cosmwasm-std = { workspace = true }
20-
secret-toolkit-utils = { version = "0.8", path = "../utils" }
20+
secret-toolkit-utils = { version = "0.9", path = "../utils" }

packages/snip721/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "secret-toolkit-snip721"
3-
version = "0.8.2"
3+
version = "0.9.0"
44
edition = "2021"
55
authors = ["SCRT Labs <[email protected]>"]
66
license-file = "../../LICENSE"
@@ -17,4 +17,4 @@ all-features = true
1717
serde = { workspace = true }
1818
schemars = { workspace = true }
1919
cosmwasm-std = { workspace = true }
20-
secret-toolkit-utils = { version = "0.8", path = "../utils" }
20+
secret-toolkit-utils = { version = "0.9", path = "../utils" }

packages/snip721/src/expiration.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,14 @@ mod test {
6161
height: 1000,
6262
time: Timestamp::from_seconds(1000000),
6363
chain_id: "test".to_string(),
64+
random: None
6465
};
6566

6667
let block_h2000_t2000000 = BlockInfo {
6768
height: 2000,
6869
time: Timestamp::from_seconds(2000000),
6970
chain_id: "test".to_string(),
71+
random: None
7072
};
7173
let exp_h1000 = Expiration::AtHeight(1000);
7274
let exp_t1000000 = Expiration::AtTime(1000000);

packages/storage/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "secret-toolkit-storage"
3-
version = "0.8.2"
3+
version = "0.9.0"
44
edition = "2021"
55
authors = ["SCRT Labs <[email protected]>"]
66
license-file = "../../LICENSE"
@@ -17,4 +17,4 @@ all-features = true
1717
serde = { workspace = true }
1818
cosmwasm-std = { workspace = true }
1919
cosmwasm-storage = { workspace = true }
20-
secret-toolkit-serialization = { version = "0.8", path = "../serialization" }
20+
secret-toolkit-serialization = { version = "0.9", path = "../serialization" }

packages/utils/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "secret-toolkit-utils"
3-
version = "0.8.2"
3+
version = "0.9.0"
44
edition = "2021"
55
authors = ["SCRT Labs <[email protected]>"]
66
license-file = "../../LICENSE"

packages/viewing_key/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "secret-toolkit-viewing-key"
3-
version = "0.8.2"
3+
version = "0.9.0"
44
edition = "2021"
55
authors = ["SCRT Labs <[email protected]>"]
66
license-file = "../../LICENSE"
@@ -20,8 +20,8 @@ base64 = "0.21.0"
2020
subtle = { version = "2.2.3", default-features = false }
2121
cosmwasm-std = { workspace = true }
2222
cosmwasm-storage = { workspace = true }
23-
secret-toolkit-crypto = { version = "0.8", path = "../crypto", features = [
23+
secret-toolkit-crypto = { version = "0.9", path = "../crypto", features = [
2424
"hash",
2525
"rand",
2626
] }
27-
secret-toolkit-utils = { version = "0.8", path = "../utils" }
27+
secret-toolkit-utils = { version = "0.9", path = "../utils" }

packages/viewing_key/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use subtle::ConstantTimeEq;
88
use cosmwasm_std::{Env, MessageInfo, StdError, StdResult, Storage};
99
use cosmwasm_storage::{PrefixedStorage, ReadonlyPrefixedStorage};
1010

11-
use secret_toolkit_crypto::{sha_256, Prng, SHA256_HASH_SIZE};
11+
use secret_toolkit_crypto::{sha_256, ContractPrng, SHA256_HASH_SIZE};
1212

1313
pub const VIEWING_KEY_SIZE: usize = SHA256_HASH_SIZE;
1414
pub const VIEWING_KEY_PREFIX: &str = "api_key_";
@@ -102,7 +102,7 @@ fn new_viewing_key(
102102
rng_entropy.extend_from_slice(info.sender.as_bytes());
103103
rng_entropy.extend_from_slice(entropy);
104104

105-
let mut rng = Prng::new(seed, &rng_entropy);
105+
let mut rng = ContractPrng::new(seed, &rng_entropy);
106106

107107
let rand_slice = rng.rand_bytes();
108108

0 commit comments

Comments
 (0)