Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refactor, add ts and wasm #1

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,222 changes: 2,869 additions & 353 deletions Cargo.lock

Large diffs are not rendered by default.

106 changes: 33 additions & 73 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,74 +1,34 @@
[package]
name = "tle"
version = "0.1.0"
edition = "2021"
description = "timelock encryption imlementation using BF-IBE"
license = "Apache-2.0"
repository = "https://github.com/ideal-lab5/etf-sdk"
authors = ["Tony Riemer <driemworks@idealabs.network>"]
rust-version = "1.63"
homepage = "https://idealabs.network"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = ["derive", "max-encoded-len"] }
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.204", default-features = false, features = ["derive", "alloc"] }
aes-gcm = { version = "0.10.2", default-features = false, features = ["alloc", "aes", "rand_core"] }
array-bytes = "6.1.0"
generic-array = "0.14.7"
sha2 = { version = "0.10.2", default-features = false }
sha3 = { version = "0.10.0", default-features = false }
# arkworks dependencies
ark-std = { version = "0.4.0", default-features = false }
ark-ff = { version = "0.4.0", default-features = false }
ark-poly = { version = "0.4.0", default-features = false }
ark-ec = { version = "0.4.0", default-features = false }

ark-serialize = { version = "0.4.0", default-features = false }
ark-bls12-381 = { version = "0.4.0", features = ["curve"], default-features = false }
ark-bls12-377 = { version = "0.4.0", features = ["curve"], default-features = false }

serde_json = { version = "1.0.108", default-features = false, features = ["alloc"] }
serde_cbor = {version = "0.11.2", default-features = false }
chacha20poly1305 = { version = "0.10.1", default-features = false}

rand_core = "0.6.4"
rand_chacha = { version = "0.3.1", default-features = false }
w3f-bls = { version = "=0.1.3", default-features = false }

[dev-dependencies]
hex = "0.4.3"
ark-ed-on-bls12-381 = { version = "^0.4.0", default-features = false, features = [ "r1cs" ] }
simulacrum = "0.3.0"
criterion = { version = "0.4", features = ["html_reports"] }

[[bench]]
name = "tlock_single_commitee_dynamic_data"
harness = false

[[bench]]
name = "tlock_dynamic_committee_static_data"
harness = false

[features]
default = ["std"]
std = [
"codec/std",
"scale-info/std",
"sha2/std",
"sha3/std",
"ark-std/std",
"ark-ff/std",
"ark-poly/std",
"ark-ec/std",
"ark-serialize/std",
"ark-bls12-381/std",
"serde_json/std",
"serde_cbor/std",
"rand_chacha/std",
"chacha20poly1305/std",
"w3f-bls/std",
[workspace]
members = [
"tle",
"wasm",
]
resolver = "2"

[profile.release]
opt-level = 3
lto = "thin"
incremental = true
panic = 'abort'

[profile.bench]
opt-level = 3
debug = false
rpath = false
lto = "thin"
incremental = true
debug-assertions = false

[profile.dev]
opt-level = 0
panic = 'abort'

[profile.test]
opt-level = 3
lto = "thin"
incremental = true
debug-assertions = true
debug = true

[workspace.metadata.release]
dependent-version = "fix"
71 changes: 15 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,26 @@
# Timelock Encryption
# TLE: Timelock Encryption

This library enables timelock encryption using the Boneh-Franklin IBE scheme. Specifically, it allows timelock encryption to be instantiated on top of a verifiable randomness beacon, such as the [Ideal Network](https://docs.idealabs.network) or [drand](https://drand.love). The library is implemented with [arkworks](https://github.com/arkworks-rs)
TLE is an implemention of [timelock encryption](https://docs.idealabs.network/docs/learn/crypto/timelock_encryption) using the [Boneh Franklin -Idenity Based Encryption](https://crypto.stanford.edu/~dabo/papers/bfibe.pdf) scheme. Designed for versatility, it provides support for both Rust and JavaScript. In addition, it is capable of supporting multiple types of randomness beacons, including the [Ideal Network](https://docs.idealabs.network) and [drand](https://drand.love).

Currently the scheme supports several flavors of beacons, including the Drand 'quicknet', which uses BLS381 keys, and the Ideal Network beacon, which uses BLS377 keys. Both beacons use a BLS variant with tiny 48 byte signatures and 96 byte public keys, with signatures being elements of $\mathbb{G}_1$ and public keys in $\mathbb{G}_2$.
## Getting Started

This flavor of timelock encryption is a hybrid encryption scheme, using `AES_GCM` to efficiently encrypt and decrypt and size ciphertexts, while secret keys are encrypted for identities of future beacon pulses.
TLE is organized into core components and language-specific bindings to support WASM and TS:

## Usage
- **Core Library**: The [tle](./tle/) crate implements the core encryption algorithms and provides support for native Rust applications.
- **WASM bindings**: The [wasm](./wasm/) lib provides wasm bindings for the timelock encryption implementation, enabling usage of TLE in web or node.js based applications.
- **TypeScript Wrapper**: The [ts](./ts/) library is a typescript wrapper to adapt the wasm for easy integration in JavaScript projects.

### Encrypt a Message
### For Rust developers
Navigate to the tle [readme](./tle/README.md) for details on building and using tle in Rust.

This is an example of using the Ideal Network beacon to encrypt message. This same can be accomplished against Drand's quicknet. See the tlock tests [here](./src/tlock.rs) for more examples.
### For Javascript developers
Navigate to the typescript bindings [readme](./ts/README.md) for more information on integration of `tle.js` in javascript apps.

``` rust
// gather public parameters for the randomenss beacon
let pk = hex::decode("471ba929a4e2ef2790fb5f2a65ebe86598a28cbb8a58e49c6cc7292cf40cecbdf10152394ba938367ded5355ae373e01a99567467bc816864774e84b984fc16e2ae2232be6481cd4db0e378e1d6b0c2265d2aa8e0fa4e2c76958ce9f12df8e0134c431c181308a68b94b9cfba5176c3a8dd22ead9a68a077ecce7facfe4adb9e0e0a71c94a0c436d8049b03fa5352301").expect("decoding failure");
let p_pub = <TinyBLS377 as EngineBLS>::deserialize_compressed(&*pk).unwrap();
// construct an identity
// choose a future round number of the randomness beacon
let round_number: u64 = 10;
let identity = Identity::new(b"", vec![round_number.to_be_bytes()]);
// generate an ephemeral secret key 32-byte secret key
let esk = [2;32];
// encrypt using the identity
let ct = tle::<TinyBLS377, OsRng>::(p_pub, msk, &message, id, OsRng).unwrap();
```

### Decrypt a Message
## Contributing and Code of Conduct

#### Early decryption
Message can be encrypted at any time using the ephemeral secret key used to encrypt it:
``` rust
// use the same esk as in `encrypt`
let early_result = ct.aes_decrypt(esk).unwrap();
```
Contributions are welcome! Feel free to open issues for problems or feature requests while we work on setting up our contributors guidelines.

#### Timelock Decryption
Messages can also be decrypted with a signature produced by a beacon on top of the 'identity' used to construct it:
``` rust
// first get a valid siganture from the beacon
let signature = hex::decode(b"f8178b1c3c9477f7b0e37cd3e63ff3a184e1d05df3117438cd05e109b5731a52a96ae344e461bc6cb8e04f5efed34701").expect("decoding failure");
let result: DecryptionResult = ct.tld(sig).unwrap();
```
## License

## Build

From the root, run `cargo build`

## Test


### Unit tests
From the root, run `cargo test`

### Coverage
We use [tarpaulin](https://github.com/xd009642/tarpaulin) for test coverage. From the root, run:

```
cargo tarpaulin --rustflags="-C opt-level=0"
```

### Benchmarks

``` shell
cargo benchmark
```
Apache-2.0
56 changes: 0 additions & 56 deletions benches/tlock_dynamic_committee_static_data.rs

This file was deleted.

56 changes: 0 additions & 56 deletions benches/tlock_single_commitee_dynamic_data.rs

This file was deleted.

23 changes: 23 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Basic
hard_tabs = true
max_width = 80
use_small_heuristics = "Max"
# Imports
imports_granularity = "Crate"
reorder_imports = true
# Consistency
newline_style = "Unix"
# Format comments
comment_width = 100
wrap_comments = true
# Misc
chain_width = 80
spaces_around_ranges = false
binop_separator = "Back"
reorder_impl_items = false
match_arm_leading_pipes = "Preserve"
match_arm_blocks = false
match_block_trailing_comma = true
trailing_comma = "Vertical"
trailing_semicolon = false
use_field_init_shorthand = true
Loading