Skip to main content

stylus_sdk/
crypto.rs

1// Copyright 2022-2024, Offchain Labs, Inc.
2// For licensing, see https://github.com/OffchainLabs/stylus-sdk-rs/blob/main/licenses/COPYRIGHT.md
3
4//! VM-accelerated cryptography.
5//!
6//! ```no_run
7//! use stylus_sdk::{alloy_primitives::address, crypto};
8//!
9//! let preimage = address!("361594F5429D23ECE0A88E4fBE529E1c49D524d8");
10//! let hash = crypto::keccak(&preimage);
11//! ```
12
13use alloy_primitives::B256;
14
15/// Efficiently computes the [`keccak256`] hash of the given preimage.
16///
17/// [`keccak256`]: https://en.wikipedia.org/wiki/SHA-3
18pub fn keccak<T: AsRef<[u8]>>(bytes: T) -> B256 {
19    alloy_primitives::keccak256(bytes)
20}