Skip to content

Commit 82190c7

Browse files
authored
Merge pull request #40 from scrtlabs/permit-hrp-refactor
Permit hrp refactor
2 parents 86f5f62 + 69954b7 commit 82190c7

File tree

18 files changed

+236
-125
lines changed

18 files changed

+236
-125
lines changed

Releses.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
# Release notes for the Secret Toolkit
22

3-
## Next Release
3+
## Next Release (v0.3.0)
44
* Added `clear` method to `AppendStore` and `DequeStore` to quickly reset the collections (#34)
55
* docs.rs documentation now includes all sub-crates
66
* BUGFIX: `secret-toolkit::snip721::Metadata` was severely out of date with the SNIP-721 specification, and not useful.
77
It is now compatible with deployed SNIP-721 contracts.
88
* Added `types` module under the `util` package, to standardize often used types.
99
* Added `secret-toolkit::viewing_key`, which can be imported by enabling the `viewing-key` feature.
10+
* Added `secret-toolkit::permit::PubKey::canonical_address()`
11+
* Types in `secret-toolkit::permit::Permit` are now generic over the type of permissions they accept.
12+
13+
### Breaking
14+
* `secret-toolkit::permit::validate()` Now supports validating any type of Cosmos address.
15+
Interface changes: Now takes a reference to the current token address instead
16+
of taking it by value and an optional hrp string.
17+
In addition, it returns a String and not HumanAddr.
18+
* Renamed `secret-toolkit::permit::Permission` to `secret-toolkit::permit::TokenPermission`.
19+
* `secret-toolkit-crypto` now has features `["hash", "rng" and "ecc-secp256k1"]` which are all off by default - enable those you need
20+
* `secret-toolkit-crypto::secp256k1::PublicKey::parse` now returns `StdResult<Self>`
21+
* Changes to `secret-toolkit::crypto::secp256k1::PrivateKey::sign`:
22+
* The `data` argument is now any slice of bytes, and not the hash of a slice of data.
23+
* the `Api` from `deps.api` is now required as the second argument as we now use the precompiled implementation.
24+
* Changes to `secret-toolkit::crypto::secp256k1::PublicKey::verify`:
25+
* the `Api` from `deps.api` is now required as the third argument as we now use the precompiled implementation.
26+
* `secret-toolkit-incubator` now has features `["cashmap", "generational-store"]` which are all off by default
1027

1128
## v0.2.0
1229
This release includes a ton of new features, and a few breaking changes in various interfaces.

packages/crypto/Cargo.toml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "secret-toolkit-crypto"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
edition = "2018"
55
authors = ["SCRT Labs <info@scrtlabs.com>"]
66
license-file = "../../LICENSE"
@@ -10,14 +10,16 @@ description = "Cryptographic tools for writing Secret Contracts"
1010
categories = ["cryptography::cryptocurrencies", "wasm"]
1111
keywords = ["secret-network", "secret-contracts", "secret-toolkit"]
1212

13-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
13+
[features]
14+
hash = ["sha2"]
15+
rand = ["rand_chacha", "rand_core"]
16+
ecc-secp256k1 = ["secp256k1"]
17+
1418
[dependencies]
15-
rand_chacha = { version = "0.2.2", default-features = false }
16-
rand_core = { version = "0.5.1", default-features = false }
17-
sha2 = { version = "0.9.1", default-features = false }
18-
libsecp256k1 = { version = "0.3.5", default-features = false, features = [
19-
"hmac"
20-
] }
19+
rand_chacha = { version = "0.2.2", default-features = false, optional = true }
20+
rand_core = { version = "0.5.1", default-features = false, optional = true }
21+
sha2 = { version = "0.9.1", default-features = false, optional = true }
22+
secp256k1 = { version = "0.21.3", optional = true }
2123
cosmwasm-std = { package = "secret-cosmwasm-std", version = "0.10" }
2224

2325
[dev-dependencies]

packages/crypto/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
#[cfg(feature = "hash")]
12
mod hash;
3+
#[cfg(feature = "rand")]
24
mod rng;
5+
#[cfg(feature = "ecc-secp256k1")]
36
pub mod secp256k1;
47

8+
#[cfg(feature = "hash")]
59
pub use hash::{sha_256, SHA256_HASH_SIZE};
10+
11+
#[cfg(feature = "rand")]
612
pub use rng::Prng;

packages/crypto/src/secp256k1.rs

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
pub use secp256k1::util::{MESSAGE_SIZE, SIGNATURE_SIZE};
1+
pub use secp256k1::constants::{COMPACT_SIGNATURE_SIZE as SIGNATURE_SIZE, MESSAGE_SIZE};
2+
use secp256k1::ecdsa::Signature as SecpSignature;
23

3-
use cosmwasm_std::StdError;
4+
use cosmwasm_std::{Api, StdError};
45

5-
pub const PRIVATE_KEY_SIZE: usize = secp256k1::util::SECRET_KEY_SIZE;
6-
pub const PUBLIC_KEY_SIZE: usize = secp256k1::util::FULL_PUBLIC_KEY_SIZE;
7-
pub const COMPRESSED_PUBLIC_KEY_SIZE: usize = secp256k1::util::COMPRESSED_PUBLIC_KEY_SIZE;
6+
pub const PRIVATE_KEY_SIZE: usize = secp256k1::constants::SECRET_KEY_SIZE;
7+
pub const PUBLIC_KEY_SIZE: usize = secp256k1::constants::UNCOMPRESSED_PUBLIC_KEY_SIZE;
8+
pub const COMPRESSED_PUBLIC_KEY_SIZE: usize = secp256k1::constants::PUBLIC_KEY_SIZE;
89

910
pub struct PrivateKey {
1011
inner: secp256k1::SecretKey,
@@ -15,70 +16,75 @@ pub struct PublicKey {
1516
}
1617

1718
pub struct Signature {
18-
inner: secp256k1::Signature,
19+
inner: SecpSignature,
1920
}
2021

2122
impl PrivateKey {
2223
pub fn parse(raw: &[u8; PRIVATE_KEY_SIZE]) -> Result<Self, StdError> {
23-
secp256k1::SecretKey::parse(raw)
24+
secp256k1::SecretKey::from_slice(raw)
2425
.map(|key| PrivateKey { inner: key })
2526
.map_err(|err| StdError::generic_err(format!("Error parsing PrivateKey: {}", err)))
2627
}
2728

2829
pub fn serialize(&self) -> [u8; PRIVATE_KEY_SIZE] {
29-
self.inner.serialize()
30+
self.inner.serialize_secret()
3031
}
3132

3233
pub fn pubkey(&self) -> PublicKey {
34+
let secp = secp256k1::Secp256k1::new();
3335
PublicKey {
34-
inner: secp256k1::PublicKey::from_secret_key(&self.inner),
36+
inner: secp256k1::PublicKey::from_secret_key(&secp, &self.inner),
3537
}
3638
}
3739

38-
pub fn sign(&self, data: &[u8; MESSAGE_SIZE]) -> Signature {
39-
let msg = secp256k1::Message::parse(data);
40-
let sig = secp256k1::sign(&msg, &self.inner);
40+
pub fn sign<A: Api>(&self, data: &[u8], api: A) -> Signature {
41+
let serialized_key = &self.serialize();
42+
// will never fail since we guarantee that the inputs are valid.
43+
let sig_bytes = api.secp256k1_sign(data, serialized_key).unwrap();
44+
let sig = SecpSignature::from_compact(&sig_bytes).unwrap();
4145

42-
Signature { inner: sig.0 }
46+
Signature { inner: sig }
4347
}
4448
}
4549

4650
impl PublicKey {
4751
pub fn parse(p: &[u8]) -> Result<PublicKey, StdError> {
48-
secp256k1::PublicKey::parse_slice(p, None)
52+
secp256k1::PublicKey::from_slice(p)
4953
.map(|key| PublicKey { inner: key })
5054
.map_err(|err| StdError::generic_err(format!("Error parsing PublicKey: {}", err)))
5155
}
5256

5357
pub fn serialize(&self) -> [u8; PUBLIC_KEY_SIZE] {
54-
self.inner.serialize()
58+
self.inner.serialize_uncompressed()
5559
}
5660

5761
pub fn serialize_compressed(&self) -> [u8; COMPRESSED_PUBLIC_KEY_SIZE] {
58-
self.inner.serialize_compressed()
62+
self.inner.serialize()
5963
}
6064

61-
pub fn verify(&self, data: &[u8; MESSAGE_SIZE], signature: Signature) -> bool {
62-
let msg = secp256k1::Message::parse(data);
63-
secp256k1::verify(&msg, &signature.inner, &self.inner)
65+
pub fn verify<A: Api>(&self, data: &[u8; MESSAGE_SIZE], signature: Signature, api: A) -> bool {
66+
let sig = &signature.serialize();
67+
let pk = &self.serialize();
68+
// will never fail since we guarantee that the inputs are valid.
69+
api.secp256k1_verify(data, sig, pk).unwrap()
6470
}
6571
}
6672

6773
impl Signature {
68-
pub fn parse(p: &[u8; SIGNATURE_SIZE]) -> Signature {
69-
Signature {
70-
inner: secp256k1::Signature::parse(p),
71-
}
74+
pub fn parse(p: &[u8; SIGNATURE_SIZE]) -> Result<Signature, StdError> {
75+
SecpSignature::from_compact(p)
76+
.map(|sig| Signature { inner: sig })
77+
.map_err(|err| StdError::generic_err(format!("Error parsing Signature: {}", err)))
7278
}
7379

7480
pub fn parse_slice(p: &[u8]) -> Result<Signature, StdError> {
75-
secp256k1::Signature::parse_slice(p)
81+
SecpSignature::from_compact(p)
7682
.map(|sig| Signature { inner: sig })
7783
.map_err(|err| StdError::generic_err(format!("Error parsing Signature: {}", err)))
7884
}
7985

8086
pub fn serialize(&self) -> [u8; SIGNATURE_SIZE] {
81-
self.inner.serialize()
87+
self.inner.serialize_compact()
8288
}
8389
}
8490

packages/incubator/Cargo.toml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "secret-toolkit-incubator"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
edition = "2018"
55
authors = ["SCRT Labs <info@scrtlabs.com>"]
66
license-file = "../../LICENSE"
@@ -11,8 +11,13 @@ categories = ["cryptography::cryptocurrencies", "wasm"]
1111
keywords = ["secret-network", "secret-contracts", "secret-toolkit"]
1212

1313
[dependencies]
14-
serde = "1.0"
15-
siphasher = "0.3.0"
16-
cosmwasm-std = { package = "secret-cosmwasm-std", version = "0.10" }
17-
cosmwasm-storage = { package = "secret-cosmwasm-storage", version = "0.10" }
18-
secret-toolkit-serialization = { version = "0.2", path = "../serialization" }
14+
serde = { version = "1.0", optional = true }
15+
siphasher = { version = "0.3.0", optional = true }
16+
cosmwasm-std = { package = "secret-cosmwasm-std", version = "0.10", optional = true }
17+
cosmwasm-storage = { package = "secret-cosmwasm-storage", version = "0.10", optional = true }
18+
secret-toolkit-serialization = { version = "0.3", path = "../serialization", optional = true }
19+
20+
[features]
21+
cashmap = ["siphasher", "cosmwasm-storage", "serde", "secret-toolkit-serialization", "cosmwasm-std"]
22+
generational-store = ["secret-toolkit-serialization", "serde", "cosmwasm-std"]
23+
maxheap = ["secret-toolkit-serialization", "serde", "cosmwasm-std"]

packages/incubator/src/lib.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
#[cfg(feature = "cashmap")]
12
pub mod cashmap;
2-
pub mod generational_store;
3-
pub mod maxheap;
4-
3+
#[cfg(feature = "cashmap")]
54
pub use cashmap::{CashMap, ReadOnlyCashMap};
5+
6+
#[cfg(feature = "generational-store")]
7+
pub mod generational_store;
8+
#[cfg(feature = "generational-store")]
69
pub use generational_store::{GenerationalStore, GenerationalStoreMut};
7-
pub use maxheap::{MaxHeapStore, MaxHeapStoreMut};
10+
11+
#[cfg(feature = "maxheap")]
12+
pub mod maxheap;
13+
#[cfg(feature = "maxheap")]
14+
pub use maxheap::{MaxHeapStore, MaxHeapStoreMut};

packages/permit/Cargo.toml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "secret-toolkit-permit"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
edition = "2018"
55
authors = ["SCRT Labs <info@scrtlabs.com>"]
66
license-file = "../../LICENSE"
@@ -11,11 +11,12 @@ categories = ["cryptography::cryptocurrencies", "wasm"]
1111
keywords = ["secret-network", "secret-contracts", "secret-toolkit"]
1212

1313
[dependencies]
14+
15+
cosmwasm-std = { package = "secret-cosmwasm-std", version = "0.10.1" }
16+
1417
serde = "1.0"
18+
ripemd160 = { version = "0.9.1", default-features = false }
1519
schemars = "0.7"
20+
bech32 = "0.8.1"
1621
remain = "0.2.2"
17-
ripemd160 = "0.9.1"
18-
secp256k1 = "0.20.3"
19-
cosmwasm-std = { package = "secret-cosmwasm-std", version = "0.10" }
20-
secret-toolkit-crypto = { version = "0.2", path = "../crypto" }
21-
secret-toolkit-utils = { version = "0.2", path = "../utils" }
22+
secret-toolkit-crypto = { version = "0.3.0", path = "../crypto", features=["hash", "ecc-secp256k1"] }

0 commit comments

Comments
 (0)