forc_crypto/
keccak256.rs

1
2
3
4
5
6
7
8
9
use serde_json::json;
use sha3::{Digest, Keccak256};

/// Hashes a given data using Keccak256
pub fn hash<T: Into<Vec<u8>>>(data: T) -> anyhow::Result<serde_json::Value> {
    let mut hasher = Keccak256::new();
    hasher.update(data.into());
    Ok(json!(hex::encode(hasher.finalize())))
}