use std::sync::atomic::{AtomicU64, Ordering};
#[derive(Debug)]
pub struct SeedStream {
master: u64,
counter: AtomicU64,
}
impl SeedStream {
pub const fn new(master: u64) -> Self {
Self {
master,
counter: AtomicU64::new(0),
}
}
pub const fn master(&self) -> u64 {
self.master
}
#[inline]
pub fn derive(&self, op: &str, archetype: &str, oracle: &str) -> u64 {
let mut hasher = blake3::Hasher::new_derive_key("vyre-conform-test-seed");
let n = self.counter.fetch_add(1, Ordering::Relaxed);
hasher.update(&self.master.to_le_bytes());
hasher.update(&(op.len() as u64).to_le_bytes());
hasher.update(op.as_bytes());
hasher.update(&(archetype.len() as u64).to_le_bytes());
hasher.update(archetype.as_bytes());
hasher.update(&(oracle.len() as u64).to_le_bytes());
hasher.update(oracle.as_bytes());
hasher.update(&n.to_le_bytes());
let hash = hasher.finalize();
let bytes = hash.as_bytes();
u64::from_le_bytes([
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7],
])
}
}