bee_block/helper.rs
1// Copyright 2022 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use crypto::hashes::{blake2b::Blake2b256, Digest};
5
6/// Hashes a string network name to a digit network ID.
7pub fn network_name_to_id(network_name: &str) -> u64 {
8 // PANIC: indexing and unwrapping is fine as a Blake2b256 digest has 32 bytes, we ask for 8 of them and we convert
9 // that slice to an array of 8 bytes.
10 u64::from_le_bytes(Blake2b256::digest(network_name.as_bytes())[0..8].try_into().unwrap())
11}