seda_sdk_rs/
keccak256.rs

1//! Keccak-256 hashing for the `seda_runtime_sdk` for oracle programs.
2//!
3//! This module provides the [`keccak256`] function to compute the Keccak-256 hash of a message
4//! using the VM's FFI interface.
5
6///
7/// Computes the Keccak-256 hash of a message.
8///
9/// The Keccak-256 hash function is a cryptographic hash function that produces a 32-byte (256-bit) hash value.
10///
11/// # Examples
12///
13/// ```no_run
14/// use seda_sdk_rs::keccak256::keccak256;
15///
16/// let message = b"Hello, world!".to_vec();
17/// let hash = keccak256(message);
18/// assert_eq!(hash.len(), 32);
19/// ```
20pub fn keccak256(message: Vec<u8>) -> Vec<u8> {
21    let result_length = unsafe { super::raw::keccak256(message.as_ptr(), message.len() as u32) };
22    let mut result_data_ptr = vec![0; result_length as usize];
23
24    unsafe {
25        super::raw::call_result_write(result_data_ptr.as_mut_ptr(), result_length);
26    }
27
28    result_data_ptr
29}