Skip to main content

ssz/
union.rs

1//! Helpers for SSZ Union types (used by `Option<T>` and derived enums).
2//!
3//! The wire form of a Union is `selector_byte || payload`. The hash form
4//! mixes the selector via `mix_in_selector` over the payload root.
5
6use digest::Digest;
7use digest::typenum::U32;
8
9use crate::merkle::mix_in_selector;
10
11/// Compute the hash for an `Option<T>`-style Union root. The selector
12/// (0 for None, 1 for Some) is mixed in via the standard `mix_in_selector`.
13#[inline]
14pub fn option_selector_hash<D: Digest<OutputSize = U32>>(
15    payload_root: [u8; 32],
16    selector: u8,
17) -> [u8; 32] {
18    mix_in_selector::<D>(payload_root, selector)
19}