keyfork-mnemonic-generate: add correct amount of bits to bitvec

This commit is contained in:
Ryan Heywood 2023-08-16 06:40:17 -05:00
parent 4feb2b6bce
commit 0d768a6eef
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
1 changed files with 10 additions and 3 deletions

View File

@ -130,10 +130,17 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut hasher = Sha256::new();
hasher.update(&entropy);
let hash = hasher.finalize();
let checksum = &hash[..bit_size / 32 / 8];
let checksum = u8_to_bitslice(&hash[1]);
let seed = [&entropy[..bit_size / 8], checksum].concat();
let seed_bits = seed.iter().flat_map(u8_to_bitslice).collect::<Vec<_>>();
let mut seed_bits = entropy[..bit_size / 8]
.iter()
.flat_map(u8_to_bitslice)
.collect::<Vec<_>>();
seed_bits.extend(if bit_size == 256 {
&checksum[..8]
} else {
&checksum[..4]
});
let words = seed_bits
.chunks_exact(11)
.map(|chunk| wordlist[bitslice_to_usize(chunk.try_into().expect("11 bit chunks"))].clone())