polymesh_api_ink/
hashing.rs

1use ink::env::hash::*;
2
3use crate::extension::new_instance;
4
5pub fn blake2_128(data: &[u8]) -> [u8; 16] {
6  let mut hash = <Blake2x128 as HashOutput>::Type::default(); // 128-bit buffer
7  ink::env::hash_bytes::<Blake2x128>(data, &mut hash);
8  hash
9}
10
11pub fn blake2_256(data: &[u8]) -> [u8; 32] {
12  let mut hash = <Blake2x256 as HashOutput>::Type::default(); // 256-bit buffer
13  ink::env::hash_bytes::<Blake2x256>(data, &mut hash);
14  hash
15}
16
17pub fn twox_64(data: &[u8]) -> [u8; 8] {
18  let runtime = new_instance();
19  runtime.twox_64(data.to_vec().into()).unwrap()
20}
21
22pub fn twox_128(data: &[u8]) -> [u8; 16] {
23  let runtime = new_instance();
24  runtime.twox_128(data.to_vec().into()).unwrap()
25}
26
27pub fn twox_256(data: &[u8]) -> [u8; 32] {
28  let runtime = new_instance();
29  runtime.twox_256(data.to_vec().into()).unwrap()
30}