diff --git a/moksha-wallet/src/secret.rs b/moksha-wallet/src/secret.rs index 7e76a6d7..a1a9b23b 100644 --- a/moksha-wallet/src/secret.rs +++ b/moksha-wallet/src/secret.rs @@ -58,7 +58,7 @@ impl DeterministicSecret { Ok(key.private_key().to_bytes().to_vec()) } - pub fn derive_secret(&self, keyset_id: u32, counter: u32) -> Result { + fn derive_secret(&self, keyset_id: u32, counter: u32) -> Result { let key = self.derive_private_key(keyset_id, counter, DerivationType::Secret)?; Ok(hex::encode(key)) } @@ -78,7 +78,7 @@ impl DeterministicSecret { .collect::>()) } - pub fn derive_blinding_factor( + fn derive_blinding_factor( &self, keyset_id: u32, counter: u32, @@ -148,4 +148,35 @@ mod tests { } Ok(()) } + + #[test] + fn test_secret_range() -> anyhow::Result<()> { + let phrase = + "half depart obvious quality work element tank gorilla view sugar picture humble"; + let deterministic_secret = DeterministicSecret::from_seed_words(phrase)?; + + let secrets = [ + "485875df74771877439ac06339e284c3acfcd9be7abf3bc20b516faeadfe77ae", + "8f2b39e8e594a4056eb1e6dbb4b0c38ef13b1b2c751f64f810ec04ee35b77270", + "bc628c79accd2364fd31511216a0fab62afd4a18ff77a20deded7b858c9860c8", + "59284fd1650ea9fa17db2b3acf59ecd0f2d52ec3261dd4152785813ff27a33bf", + "576c23393a8b31cc8da6688d9c9a96394ec74b40fdaf1f693a6bb84284334ea0", + ]; + + let blinding_factors = [ + "ad00d431add9c673e843d4c2bf9a778a5f402b985b8da2d5550bf39cda41d679", + "967d5232515e10b81ff226ecf5a9e2e2aff92d66ebc3edf0987eb56357fd6248", + "b20f47bb6ae083659f3aa986bfa0435c55c6d93f687d51a01f26862d9b9a4899", + "fb5fca398eb0b1deb955a2988b5ac77d32956155f1c002a373535211a2dfdc29", + "5f09bfbfe27c439a597719321e061e2e40aad4a36768bb2bcc3de547c9644bf9", + ]; + + let range = deterministic_secret.derive_range(864559728, 0, 5)?; + + for (i, (secret, blinding_factor)) in range.iter().enumerate() { + assert_eq!(secrets[i], secret); + assert_eq!(blinding_factors[i], hex::encode(&blinding_factor[..])); + } + Ok(()) + } }