Coder Social home page Coder Social logo

drand-rs's Introduction

dee: Rust cli for drand

Documentation License crates.io

Retrieve public randomness, and encrypt your files to the future. dee provides a drand client, and support for timelock encryption.

Tables of Content

Features

  • Retrieve drand randomness
  • Manages multiple beacons locally
  • Timelock encryption and decryption
  • Chain and unchained randomness
  • Signatures verification on G1 and G2
  • Customizable output format
  • Cross platform (Linux, Windows, macOS)
  • Interroperability with Go and JS implementation
  • wasm32 compatible library

What's next

  • P2P randomness retrieval
  • Offline timelock decryption

Installation

Environment CLI Command
Cargo (Rust 1.74+) cargo install dee --git https://github.com/thibmeu/drand-rs

On Linux, Windows, or macOS, you can use the pre-built binaries.

Usage

You can use the --help option to get more details about the commands and their options.

dee [OPTIONS] <COMMAND>

Manage remote beacons

Add quicknet remote beacon, and shows details about it.

dee remote add quicknet https://api.drand.sh/52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971
quicknet
dee remote show --long quicknet
URL       : https://drand.cloudflare.com/52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971
Public Key: 83cf0f2896adee7eb8b5f01fcad3912212c437e0073e911fb90022d3e760183c8c4b450b6a0a6c3ac6a5776a2d1064510d1fec758c921cc22b0e17e63aaf4bcb5ed66304de9cf809bd274ca73bab4af5a6e9c76a4bc09e76eae8991ef5ece45a
Period    : 3s
Genesis   : 2023-08-23 15:09:27.0 +00:00:00
Chain Hash: 52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971
Group Hash: f477d5c89f21a17c863a7f937c6a6d15859414d2be09cd448d4279af331c5d3e
Scheme ID : bls-unchained-g1-rfc9380
Beacon ID : quicknet

Retrieve public randomness

Retrieve round 1000 from quicknet.

dee rand -u quicknet --long 1000
Round     : 1000
Relative  : 100:09:43 ago
Absolute  : 2023-08-23 15:59:24
Randomness: fe290beca10872ef2fb164d2aa4442de4566183ec51c56ff3cd603d930e54fdd
Signature : b44679b9a59af2ec876b1a6b1ad52ea9b1615fc3982b19576350f93447cb1125e342b73a8dd2bacbe47e4b6b63ed5e39

Timelock encryption

Encrypt Hello dee! string to 30 seconds in the future, using quicknet publickey. If you wait 30 seconds before decrypting, the message is decrypted using the new quicknet signature.

echo 'Hello dee!' | dee crypt -u quicknet -r 30s > data.dee
dee crypt --decrypt data.dee
Hello dee!

Common remotes

ID Remote Timelock encryption
quicknet-cloudflare https://drand.cloudflare.com/52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971 Yes
quicknet-pl https://api.drand.sh/52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971 Yes
mainnet-cloudflare https://drand.cloudflare.com No
mainnet-pl https://api.drand.sh No

dee does not come with a default remote beacon. You should decide whichever suit your needs.

More beacons origin are available on drand website.

Security Considerations

This software has not been audited. Please use at your sole discretion. With this in mind, dee security relies on the following:

FAQ

Default configuration path

dee configuration file is available at the following

OS Path
Linux /home/alice/.config/dee/default.toml
Windows C:\Users\Alice\AppData\Roaming\dee\config\default.toml
macOS /Users/Alice/Library/Application Support/rs.dee/default.toml

Other implementations

drand API specification is at drand.love/docs/specification. drand is based on Scalable Bias-Resistant Distributed Randomness by Ewa Syta, Philipp Jovanovic, Eleftherios Kokoris Kogias, Nicolas Gailly, Linus Gasser, Ismail Khoffi, Michael J. Fischer, and Bryan Ford. The reference interroperable Go implementation is available at drand/drand.

timelock encryption was published in tlock: Practical Timelock Encryption from Threshold BLS by Nicolas Gailly, Kelsey Melissaris, and Yolan Romailler. The reference interroperable Go implementation is available at drand/tlock.

Rust libraries

dee focuses on building a cli. It relies on Rust libraries to use drand or perform timelock encryption.

If you're looking to implement your own Rust application on top of drand and/or timelock encryption, you can use the following:

  • drand_core: drand client,
  • tlock: raw tlock implementation, allowing messages up to 16 bytes,
  • tlock_age: hybrid encryption, age phassphrase is encrypted using tlock,

License

This project is under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be MIT licensed as above, without any additional terms or conditions.

drand-rs's People

Contributors

thibmeu avatar lukevalenta avatar cluelessuk avatar webmaster128 avatar

Stargazers

Arnav Kumar avatar Laura Kirsch avatar Stefano Probst avatar Amit Karamchandani Batra avatar  avatar Daan Boerlage avatar Dr. Juan Miguel Cejuela avatar Chris Farmiloe avatar Julie B. avatar AkimHR avatar Emmanuel Salomon avatar Gabor Dolla avatar Julius Rickert avatar Sandalots avatar Ayush Kumar avatar Madhav Goyal avatar nicabar avatar plein avatar Jonas Bushart avatar

Watchers

 avatar Julie B. avatar

drand-rs's Issues

Use OS certificate store when available

drand_core packages Mozilla Root certificate store. We should consider using the user certificate store instead.

ureq has an integration with rustls-native-certs and more information in their README.

We should make sure wasm32 target does not regress as this change is introduced.

Add dedicated error type for `drand_core`

drand_core uses anyhow to wrap and create errors. This prevents downstream crates to match errors easily.

drand_core should wrap errors in one or more dedicated types to address this.

Wasm compatibility: use of undeclared crate or module platform

I'm using drand-core in my smart contract based on cosmwasm that has ureq in dependencies and it has rustls-native-certs in the dependencies.

It compile successfully on running cargo test but after compile the project with this command:

docker run --rm -v "$(pwd)":/code --network="host" \
 --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
 --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
 cosmwasm/workspace-optimizer:0.15.1

I get this error:

error[E0433]: failed to resolve: use of undeclared crate or module `platform`
 --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/rustls-native-certs-0.7.0/src/lib.rs:58:42
  |
58 |     load_certs_from_env().unwrap_or_else(platform::load_native_certs)
  |                                          ^^^^^^^^ use of undeclared crate or module `platform`

In the description of this repo, I found wasm32 compatible library but I found that ureq used in dependencies not support wasm based on this issue and rustls-native-certs not support wasm based on this issue.

What should I do for this issue, It seems platform not clear in workspace-optimizer?

To reproduce the problem, do the following:

  1. run this to create project from template:
$ cargo generate --git https://github.com/CosmWasm/cw-template.git --branch 1.0 --name project
$ cd project
  1. Add drand_core = { version = "0.0.16" } to dependency of Cargo.toml
  2. run this:
$ docker run --rm -v "$(pwd)":/code --network="host" \                                        
  --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
  --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
  cosmwasm/rust-optimizer:0.15.1

Or

$ cargo wasm

Adding G1 scheme conformant with Hash to Curve RFC

drand/drand#1249 is going to introduce a new scheme that's compliant with Hash to Elliptic Curve RFC.

We should update drand_core to support this change.
The new network scheme_id is bls-unchained-g1-rfc.

Tests vectors are

{"public_key": "a1ee12542360bf75742bcade13d6134e7d5283d9eb782887c47d3d9725f05805d37b0106b7f744395bf82c175dd7434a169e998f188a657a030d588892c0cd2c01f996aaf331c4d8bc5b9734bbe261d09e7d2d39ef88b635077f262bd7bbb30f"}

{"round":3,"randomness":"9e9829dfb34bd8db3e21c28e13aefecd86e007ebd19d6bb8a5cee99c0a34798f","signature":"b98dae74f6a9d2ec79d75ba273dcfda86a45d589412860eb4c0fd056b00654dbf667c1b6884987c9aee0d43f8ba9db52"}

{"round":4,"randomness":"ec93fa3d6bdca5fa37a98641dd9b98c36ac918c52e26be9d20ff1e377993674d","signature":"962c2b2969e8f3351cf5cc457b04ecbf0c65bd79f4c1ee3bd0205f581368aaaa0cdeb1531a0709d39ef06a8ba1e1bb93"}

{"round":6,"randomness":"7b042905dec12537f58f1f3bc224bfba59817624d6705c9bc3ca2208657948c5","signature":"a054dafb27a4a4fb9e06b17b30da3e0c7b13b4ca8e1dec3c6775f81758587029aa358523f2e7e62204018347db7cbd1c"}

At the same time, we could remove the internal method scheme_id from RandomnessBeacon struct, as its only used internally and is not going to support the addition of new schemes.

Improved error messaging when adding remotes in `dee`

A very small nitpick but I noticed the following scenarios provide confusing error messages:

  • adding a remote without passing a scheme (eg https://)
  • adding a remote with a trailing slash

Loving dee though!! Gonna save me so much time ctrl-Ring for chain hashes!
I'd also be happy to pick this issue up, but probably not until next week sometime

Suggest compatible upstream at decryption time

At the moment, dee uses the default or specified uptream to decrypt files.
If the decryption fails, but the user has a saved upstream that matches the chain hash in the stanza, we could suggest them to use it instead.

This should not modify the existing upstream.

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.