use sha2::{Digest, Sha256};
pub fn hash32(data: &[u8]) -> [u8; 32] {
let mut h = Sha256::new();
h.update(data);
let out = h.finalize();
let mut slot = [0u8; 32];
slot.copy_from_slice(&out);
slot
}
pub fn derive_slot(namespace: &[u8], parts: &[&[u8]]) -> [u8; 32] {
let mut h = Sha256::new();
h.update(b"trth:sdk:slot:v1");
h.update(&[0u8]);
h.update(namespace);
for part in parts {
h.update(&[0xFF]);
h.update(part);
}
let out = h.finalize();
let mut slot = [0u8; 32];
slot.copy_from_slice(&out);
slot
}
#[inline]
pub fn index_u64(i: u64) -> [u8; 8] {
i.to_le_bytes()
}
#[inline]
pub fn namespace(label: &str) -> [u8; 32] {
hash32(label.as_bytes())
}