8 unstable releases (3 breaking)

0.4.0 Oct 29, 2023
0.3.2 Oct 27, 2023
0.2.1 Nov 20, 2022
0.2.0 Sep 13, 2022
0.1.1 Sep 11, 2022

#24 in #const-fn

Download history 13/week @ 2024-01-12 24/week @ 2024-01-19 2/week @ 2024-01-26 8/week @ 2024-02-02 16/week @ 2024-02-09 32/week @ 2024-02-16 46/week @ 2024-02-23 30/week @ 2024-03-01 26/week @ 2024-03-08 18/week @ 2024-03-15 4/week @ 2024-03-22 83/week @ 2024-03-29

136 downloads per month
Used in 3 crates (via ethprim)

MIT/Apache

35KB
709 lines

Implementation of Ethereum 32-byte digests for Rust.

This crate provides a Digest type for representing Ethereum 32-byte digests.

Additionally it includes macros for digest constants, both from hexidecimal strings, but also by compile-time Keccak-256 hashing inputs. Under the hood, they are implemented with const fn and do not use procedural macros.

Usage

Just add a dependency to your Cargo.toml:

[dependencies]
ethdigest = "*"

For complete documentation checkout docs.rs.


lib.rs:

Implementation of Ethereum digest and hashing for Rust.

This crate provides a Digest type for representing an Ethereum 32-byte digest as well as various Keccak-256 hashing utilities for computing them.

Macros

There are a couple of exported macros for creating compile-time digest constants:

  • digest!: hexadecimal constant
  • keccak!: compute constant from a pre-image

Under the hood, they are implemented with const fn and do not use procedural macros.

Features

  • default std: Additional integration with Rust standard library types. Notably, this includes std::error::Error implementation on the ParseDigestError and conversions from Vec<u8>.
  • serde: Serialization traits for the serde crate. Note that the implementation is very much geared towards JSON serialization with serde_json.
  • sha3: Use the Rust Crypto Keccak-256 implementation (provided by the sha3 crate) instead of the built-in one. Note that the keccak! macro will always use the built-in Keccak-256 implementation for computing digests, as sha3 does not expose a const fn API.

Dependencies

~0–450KB