pub fn dice_to_entropy<const FACES: u8, const N: usize>(
rolls: &[u8],
) -> Result<DiceEntropy<FACES, N>, EntropyError>Expand description
Fold a sequence of dice rolls into an N-byte entropy buffer,
byte-for-byte compatible with Krux upstream.
based on src/krux/pages/new_mnemonic/dice_rolls.py
rolls are formatted as a string (concatenated for FACES < 10,
hyphen-separated otherwise), SHA-256 hashed, then the first N
bytes of the digest become the entropy.
§Example
use kdk_entropy::{dice_to_entropy, DiceEntropy};
use kdk_zeroize::prelude::*;
// 50 d6 rolls (all "1") → SHA-256("1"*50) truncated to 16 bytes.
// Same bytes Krux produces for the same input.
let rolls = [1u8; 50];
let e: DiceEntropy<6, 16> = dice_to_entropy(&rolls).unwrap();
assert_eq!(
e.expose_secret(),
&[
0x3d, 0xac, 0x51, 0xa6, 0x5e, 0xc9, 0xfc, 0xfc,
0x40, 0x9a, 0x1b, 0x5f, 0x1d, 0xef, 0xe9, 0x2b,
]
);