Skip to content

Commit

Permalink
tweaks to docs and ignore readme doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
reuvenpo committed Sep 4, 2022
1 parent 18af00d commit 0d5f2bf
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 79 deletions.
44 changes: 43 additions & 1 deletion packages/crypto/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,46 @@

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

This package contains all the tools related to crypto
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:

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

## Example usage:

```ignore
# extern crate secret_toolkit_crypto;
# use secret_toolkit_crypto::{sha_256, Prng, secp256k1::{PrivateKey, PublicKey, Signature}};
# use base64;
# use cosmwasm_std::{StdError, testing::mock_dependencies};
# fn main() -> Result<(), StdError> {
# let deps = mock_dependencies(20, &[]);
let entropy: String = "secret".to_owned();
let prng_seed: Vec<u8> = sha_256(base64::encode(&entropy.clone()).as_bytes()).to_vec();
let mut rng = Prng::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](https://crates.io/crates/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](https://crates.io/crates/secp256k1).
45 changes: 1 addition & 44 deletions packages/crypto/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,4 @@
//! # Crypto
//! 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:
//!
//! ```toml
//! [dependencies]
//! secret-toolkit = { version = "0.3.0", features = ["crypto"] }
//! secret-toolkit-crypto = { version = "0.3.0", features = ["hash", "rand", "ecc-secp256k1"] }
//! ```
//!
//! ## Example usage:
//!
//! ```ignore
//! # extern crate secret_toolkit_crypto;
//!
//! # use secret_toolkit_crypto::{sha_256, Prng, secp256k1::{PrivateKey, PublicKey, Signature}};
//! # use base64;
//! # use cosmwasm_std::{StdError, testing::mock_dependencies};
//!
//! # fn main() -> Result<(), StdError> {
//! # let deps = mock_dependencies(20, &[]);
//! let entropy: String = "secret".to_owned();
//! let prng_seed: Vec<u8> = sha_256(base64::encode(&entropy.clone()).as_bytes()).to_vec();
//!
//! let mut rng = Prng::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](https://crates.io/crates/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](https://crates.io/crates/secp256k1).
#![doc = include_str!("../Readme.md")]

#[cfg(feature = "hash")]
mod hash;
Expand Down
10 changes: 5 additions & 5 deletions packages/incubator/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ This package contains tools that are not yet final and may change or contain unk
## Max heap storage

A "max heap store" is a storage wrapper that implements a binary tree maxheap data structure.
https://en.wikipedia.org/wiki/Min-max_heap
Implementation based on https://algorithmtutor.com/Data-Structures/Tree/Binary-Heaps/
<https://en.wikipedia.org/wiki/Min-max_heap>
Implementation based on <https://algorithmtutor.com/Data-Structures/Tree/Binary-Heaps/>

* Insertion O(log n)
* Remove max O(log n)
Expand All @@ -17,7 +17,7 @@ Implementation based on https://algorithmtutor.com/Data-Structures/Tree/Binary-H

The usage of `MaxHeapStoreMut` and `MaxHeapStore` are modeled on `AppendStoreMut` and `AppendStore`, respectively. To add an item to the heap use `insert` and to take the top value off use `remove`, which also returns the item that was removed. To peek at the max value without removing, use the `get_max` function. Duplicate items can be added to the heap.

```rust
```ignore
let mut storage = MockStorage::new();
let mut heap_store = MaxHeapStoreMut::attach_or_create(&mut storage)?;
heap_store.insert(&1234)?;
Expand All @@ -35,7 +35,7 @@ assert_eq!(heap_store.remove(), Ok(1234));

In order to use a custom struct with `MaxHeapStore` you will need to implement the appropriate Ordering traits. The following is an example with a custom struct `Tx` that uses the `amount` field to determine order in the heap:

```rust
```ignore
#[derive(Serialize, Deserialize, Clone, Debug, Eq)]
pub struct Tx {
address: HumanAddr,
Expand Down Expand Up @@ -110,7 +110,7 @@ In effect, this example is a graph structure where the nodes are elements and th

See tests in `generational_store.rs` for more examples, including iteration.

```rust
```ignore
let mut storage = MockStorage::new();
let mut gen_store = GenerationalStoreMut::attach_or_create(&mut storage)?;
let alpha = gen_store.insert(String::from("Alpha"));
Expand Down
2 changes: 2 additions & 0 deletions packages/incubator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![doc = include_str!("../Readme.md")]

#[cfg(feature = "generational-store")]
pub mod generational_store;
#[cfg(feature = "generational-store")]
Expand Down
2 changes: 2 additions & 0 deletions packages/permit/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![doc = include_str!("../Readme.md")]

pub mod funcs;
pub mod state;
pub mod structs;
Expand Down
2 changes: 2 additions & 0 deletions packages/serialization/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![doc = include_str!("../Readme.md")]

use serde::{de::DeserializeOwned, Serialize};

use cosmwasm_std::StdResult;
Expand Down
8 changes: 4 additions & 4 deletions packages/snip20/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ You can create a HandleMsg variant and call the `to_cosmos_msg` function to gene
Or you can call the individual function for each Handle message to generate the appropriate callback CosmosMsg.

Example:
```rust
```ignore
let recipient = HumanAddr("ADDRESS_TO_TRANSFER_TO".to_string());
let amount = Uint128(10000);
let padding = None;
Expand Down Expand Up @@ -41,7 +41,7 @@ You probably have also noticed that CreateViewingKey is not supported. This is
## Queries

These are the types that SNIP20 tokens can return from queries
```rust
```ignore
pub struct TokenInfo {
pub name: String,
pub symbol: String,
Expand Down Expand Up @@ -127,7 +127,7 @@ You can create a QueryMsg variant and call the `query` function to query a SNIP2
Or you can call the individual function for each query.

Example:
```rust
```ignore
let address = HumanAddr("ADDRESS_WHOSE_BALANCE_IS_BEING_REQUESTED".to_string());
let key = "THE_VIEWING_KEY_PREVIOUSLY_SET_BY_THE_ADDRESS".to_string();
let block_size = 256;
Expand All @@ -137,4 +137,4 @@ Example:
let balance =
balance_query(&deps.querier, address, key, block_size, callback_code_hash, contract_addr)?;
```
In this example, we are doing a Balance query for the specified address/key pair and storing the response in the balance variable, which is of the Balance type defined above. The query message is padded to blocks of 256 bytes.
In this example, we are doing a Balance query for the specified address/key pair and storing the response in the balance variable, which is of the Balance type defined above. The query message is padded to blocks of 256 bytes.
2 changes: 2 additions & 0 deletions packages/snip20/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![doc = include_str!("../Readme.md")]

pub mod batch;
pub mod handle;
pub mod query;
Expand Down
8 changes: 4 additions & 4 deletions packages/snip721/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ You can create a HandleMsg variant and call the `to_cosmos_msg` function to gene
Or you can call the individual function for each Handle message to generate the appropriate callback CosmosMsg.

Example:
```rust
```ignore
let recipient = HumanAddr("ADDRESS_TO_TRANSFER_TO".to_string());
let token_id = "TOKEN_ID".to_string();
let memo = Some("TRANSFER_MEMO".to_string());
Expand Down Expand Up @@ -43,7 +43,7 @@ You probably have also noticed that CreateViewingKey is not supported. This is
## Queries

These are the types that the SNIP-721 toolkit queries can return
```rust
```ignore
pub struct ContractInfo {
pub name: String,
pub symbol: String,
Expand Down Expand Up @@ -166,7 +166,7 @@ You can create a QueryMsg variant and call the `query` function to query a SNIP-
Or you can call the individual function for each query.

Example:
```rust
```ignore
let token_id = "TOKEN_ID".to_string();
let viewer = Some(ViewerInfo {
address: HumanAddr("VIEWER'S_ADDRESS".to_string()),
Expand All @@ -180,4 +180,4 @@ Example:
let nft_dossier =
nft_dossier_query(&deps.querier, token_id, viewer, include_expired, block_size, callback_code_hash, contract_addr)?;
```
In this example, we are doing an NftDossier query on the token named "TOKEN_ID", supplying the address and viewing key of the querier, and storing the response in the nft_dossier variable, which is of the NftDossier type defined above. Because no `include_expired` was specified, the response defaults to only displaying approvals that have not expired, but approvals will only be displayed if the viewer is the owner of the token. The query message is padded to blocks of 256 bytes.
In this example, we are doing an NftDossier query on the token named "TOKEN_ID", supplying the address and viewing key of the querier, and storing the response in the nft_dossier variable, which is of the NftDossier type defined above. Because no `include_expired` was specified, the response defaults to only displaying approvals that have not expired, but approvals will only be displayed if the viewer is the owner of the token. The query message is padded to blocks of 256 bytes.
2 changes: 2 additions & 0 deletions packages/snip721/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![doc = include_str!("../Readme.md")]

//#![allow(clippy::field_reassign_with_default)]
pub mod expiration;
pub mod handle;
Expand Down
2 changes: 1 addition & 1 deletion packages/snip721/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct Metadata {

/// metadata extension
/// You can add any metadata fields you need here. These fields are based on
/// https://docs.opensea.io/docs/metadata-standards and are the metadata fields that
/// <https://docs.opensea.io/docs/metadata-standards> and are the metadata fields that
/// Stashh uses for robust NFT display. Urls should be prefixed with `http://`, `https://`, `ipfs://`, or
/// `ar://`
#[derive(Serialize, Deserialize, JsonSchema, Clone, PartialEq, Debug, Default)]
Expand Down
3 changes: 2 additions & 1 deletion packages/storage/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#[doc = include_str!("../Readme.md")]
#![doc = include_str!("../Readme.md")]

pub mod append_store;
pub mod deque_store;
pub mod item;
Expand Down
2 changes: 2 additions & 0 deletions packages/toolkit/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![doc = include_str!("../Readme.md")]

#[cfg(feature = "crypto")]
pub use secret_toolkit_crypto as crypto;
#[cfg(feature = "incubator")]
Expand Down
Loading

0 comments on commit 0d5f2bf

Please sign in to comment.