Crates.io | doughnut-rs |
lib.rs | doughnut-rs |
version | 0.2.2 |
source | src |
created_at | 2024-02-13 06:00:06.451087 |
updated_at | 2024-02-20 21:46:49.989156 |
description | The official rust doughnut codec |
homepage | |
repository | https://github.com/futureversecom/trn-doughnut-rs |
max_upload_size | |
id | 1137987 |
size | 170,020 |
Rust implementation of the doughnut binary codec.
Currently compliant with version 0, 1 spec.
use doughnut_rs::v1::DoughnutV1;
let encoded_doughnut = vec![ <some bytes> ];
let doughnut = DoughnutV1::new(&encoded_doughnut)?;
Query permission topping
let topping: &[u8] = doughnut.get_topping("something")?;
Check a doughnut is valid to be used by a user (who
) at a timestamp (when
).
use doughnut_rs::traits::DoughnutApi;
// ..
assert!(
doughnut.validate(who, when).is_ok()
)
Verify a doughnut's signature (requires "crypto"
feature in "no_std"
mode and rust nightly)
use doughnut_rs::traits::DoughnutVerify;
// ..
assert!(doughnut.verify().is_ok());
Sign a doughnut (requires "crypto"
feature in "no_std"
mode and rust nightly)
use doughnut_rs::traits::Signing;
let mut doughnut = DoughnutV1 { ... };
// ECDSA
assert!(doughnut.sign_ecdsa(<secret_key_bytes>).is_ok());
// EIP191
assert!(doughnut.sign_eip191(<secret_key_bytes>).is_ok());
The following checks should pass
# Do the usual
cargo +nightly fmt && \
cargo check && \
cargo test
# Check 'no std' mode compiles
cargo check --no-default-features
# Check crypto functionality in 'no std' mode
cargo +nightly check --no-default-features
This crate also provides generated JS bindings using wasm-pack. See the js dir for usage.
To generate the package run:
# install wasm pack
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
# build
cd js/ && yarn build
# Run tests
yarn test