Giter VIP home page Giter VIP logo

secret-toolkit's Introduction

Secret Contract Development Toolkit

This Rust package is a collection of sub-packages that contain common tools used in development of Secret Contracts running on the Secret Network.

The main package in this repository is secret-toolkit under packages/toolkit, which is a wrapper around the other packages. For example secret-toolkit-storage is exported under secret_toolkit::storage. If you only need some of the tools from the toolkit, you may get better compile times by depending on the different components directly.

Each of the subpackages is imported with a feature flag, and most subpackages are included in the default flags. The exceptions to this are:

  • "crypto" - has a deep dependency tree and increases compilation times significantly
  • "permit" - depends on "crypto" and imports it automatically
  • "incubator" - includes experimental functionality. Minor version releases may cause breaking changes in this subpackage.

While the packages in this repository are designed with Secret Network's runtime in mind, some of them may work well with the vanilla CosmWasm libraries and runtimes as well, or only require minimal modifications to be compatible with them.

License

The license file in the top directory of this repository applies to all packages it contains.

secret-toolkit's People

Contributors

assafmo avatar baedrik avatar blake-regalia avatar cashmaney avatar darwinzer0 avatar eladr7 avatar eshelb avatar floppydisck avatar fsoaresdev avatar itshaseebsaeed avatar kent-3 avatar liorbond avatar pumpkinseed avatar reuvenpo avatar sacredwx avatar srdtrk avatar toml01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

secret-toolkit's Issues

`pad_handle_result` shouldn't pad plaintext attributes

When add_attribute_plaintext is called on a Response, it adds an Attribute with encrypted: false:
https://github.com/scrtlabs/cosmwasm/blob/6c639b5a85ef66f87d72284dc68ae051eab09007/packages/std/src/results/response.rs#L112-L122

but when pad_handle_result is called on the Response, it pads all attributes (both plaintext and encrypted), causing problems for plaintext ones since a bunch of spaces are appended to the plaintext attribute key, preventing clients from accessing the key in the response JSON (without resorting to matching by pattern - which is obviously not desired nor intended).

for attribute in &mut response.attributes {
// Safety: These two are safe because we know the characters that
// `space_pad` appends are valid UTF-8
unsafe { space_pad(attribute.key.as_mut_vec(), block_size) };
unsafe { space_pad(attribute.value.as_mut_vec(), block_size) };
}

Implement helpers for SNIP-21, SNIP-22, and SNIP-23 interfaces

Extend the methods available under secret_toolkit::snip20 to also include the new interface specified in:
SNIP-21, SNIP-22, and SNIP-23.

Alternatively, implement new modules called snip21, snip22, and snip23 which include versions of the modified interfaces that are aware of the new features, as well as support for the new message types.

NOTE: at the time of writing SNIP-23 is not finalized yet so it's a lower priority.

UPDATE 2022-01-19:

We ended up including all new SNIP-2x functionality in the snip20 module. As far as I'm concerned we can still reshuffle this as discussed in this thread and release a new version, but for now let's experiment with it and see what feedback we get.

Standard answers for common use cases

Example:
A very common way to answer a handle message is simply { "status": "success" } or { "status": "failure" }.
Every time we do that we have to write something along the lines of:

Ok(HandleResponse {
        messages,
        log: vec![],
        data: Some(to_binary(&HandleAnswer::Send { status: Success })?),
    })

For this we of course have to declare:

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum ResponseStatus {
    Success,
    Failure,
}

#[derive(Serialize, Deserialize, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HandleAnswer {
    Send {
        status: ResponseStatus,
    },
    ...
}

This is a lot of code and it's kind of annoying.
We should provide a standard implementation for common use cases that coders can use as a one-liner.

Support for permits outside contracts

We can move permit validation to a service outside the contracts - should improve performance and gas usage, which will help standardize and prevent mistakes

Panic! when trying to revoke_permit(Branch cw-v1.0)

Secret-toolkit's(Branch = cosmwasm-v1.0) revoke-permit functions panics because apparently, you cannot store an empty value in the storage.
Here's the revoke_permit function that is trying to store an empty value.
Cw-0.10 doesn't have this condition before. Seems like it was added after version 0.10. This check here is causing this error.

I suggest we store permit name or any random value to avoid this error.

Support failed queries

The current implementation of the snip20 and snip721 modules fails to parse the query response if it was an error.
This isn't great. The library should know how to handle those cases. This came up while playing around with queries that require a VK, and providing the wrong VK.

secp256k1 unit tests dont compile

I ran into this issue because I was trying to unit test my own functions which rely on secp256k1. It looks like the sign and verify functions need deps.api to be given as input. But even after I gave it as input it still fails during runtime because the mock version of dependencies spits out an empty array when you sign something which secp256k1 doesn't like at all. Is there any workaround for this? Or a simple fix?

Standard admin interface implementation

Implementation of common actions an admin can do in a contract:

  • Stop
  • Resume
  • Change admin
  • ..

Ideally this would also implement the underlying action of these messages - e.g. encapsulate saving to storage, etc..

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.