use crate::prelude::*;
use blake3::{Hasher, OutputReader};
use leb128::write::unsigned as write_varint;
pub struct CryptoAddress {
hasher: Hasher,
}
impl FieldAddress for CryptoAddress {
fn unordered(&self) -> (Self, Self) {
(
Self::root(),
Self {
hasher: self.hasher.clone(),
},
)
}
fn root() -> Self {
profile_method!(root);
Self {
hasher: Hasher::new(),
}
}
fn child(&self, number: u64) -> Self {
profile_method!(child);
let mut hasher = self.hasher.clone();
write_varint(&mut hasher, number + 1).unwrap();
Self { hasher }
}
}
impl CryptoAddress {
pub(crate) fn finish(self, payload: &[u8]) -> OutputReader {
profile_method!(finish);
let Self { mut hasher, .. } = self;
hasher.update(&[0]);
hasher.update(payload);
hasher.finalize_xof()
}
}