diff --git a/zebra-chain/src/orchard/commitment.rs b/zebra-chain/src/orchard/commitment.rs index ed589775..8ccb136e 100644 --- a/zebra-chain/src/orchard/commitment.rs +++ b/zebra-chain/src/orchard/commitment.rs @@ -3,8 +3,6 @@ // #[cfg(test)] // mod test_vectors; -pub mod sinsemilla_hashes; - use std::{convert::TryFrom, fmt, io}; use bitvec::prelude::*; diff --git a/zebra-chain/src/orchard/keys.rs b/zebra-chain/src/orchard/keys.rs index c04e0832..e632f8ea 100644 --- a/zebra-chain/src/orchard/keys.rs +++ b/zebra-chain/src/orchard/keys.rs @@ -151,15 +151,29 @@ impl FromStr for SpendingKey { } impl SpendingKey { - /// Generate a new _SpendingKey_. + /// Generate a new `SpendingKey`. + /// + /// When generating, we check that the corresponding `SpendAuthorizingKey` + /// is not zero, else fail. + /// + /// pub fn new(csprng: &mut T) -> Self where T: RngCore + CryptoRng, { - let mut bytes = [0u8; 32]; - csprng.fill_bytes(&mut bytes); + loop { + let mut bytes = [0u8; 32]; + csprng.fill_bytes(&mut bytes); - Self::from(bytes) + let sk = Self::from(bytes); + + // "if ask = 0, discard this key and repeat with a new sk" + if SpendAuthorizingKey::from(sk).0 == pallas::Scalar::zero() { + continue; + } + + break sk; + } } }