From 3e379939de93cb980bbd1b0ebb7d242576ec36b3 Mon Sep 17 00:00:00 2001 From: Doug Anderson444 Date: Thu, 19 Sep 2024 01:54:00 -0300 Subject: [PATCH] gotta expose the seed for use --- crates/seed-keeper-core/src/credentials.rs | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/crates/seed-keeper-core/src/credentials.rs b/crates/seed-keeper-core/src/credentials.rs index 42c4622..2810692 100644 --- a/crates/seed-keeper-core/src/credentials.rs +++ b/crates/seed-keeper-core/src/credentials.rs @@ -127,6 +127,11 @@ impl Wallet { encrypt(key, self.seed.clone()) } + + /// Returns the seed, decrypted + pub fn seed(&self) -> &[u8] { + &self.seed + } } #[cfg(test)] @@ -155,6 +160,8 @@ mod tests { encrypted_seed: Some(encrypted_seed.clone()), }; + println!("{:?}", credentials); + let wallet = Wallet::new(credentials)?; // Encrypt the seed @@ -197,4 +204,30 @@ mod tests { Ok(()) } + + #[test] + fn test_works_long_enough() -> Result<(), error::Error> { + let json = r#"{"username":"username","password":"password","encrypted_seed":null}"#; + + // it should deserialize the json + let credentials: Credentials = serde_json::from_str(json).map_err(|e| e.to_string())?; + + assert_eq!(credentials.username.value(), "username"); + assert_eq!(credentials.password.value(), "password"); + + Ok(()) + } + + #[test] + fn test_works_with_seed() -> Result<(), error::Error> { + let json = r#"{"username":"username","password":"password","encrypted_seed":[46,236,62,136,201,70,17,15,212,216,99,70,0,242,150,190,15,58,71,131,148,196,18,158,104,110,121,170,241,22,47,63,211,192,118,233,214,196,223,34]}"#; + + // it should deserialize the json + let credentials: Credentials = serde_json::from_str(json).map_err(|e| e.to_string())?; + + assert_eq!(credentials.username.value(), "username"); + assert_eq!(credentials.password.value(), "password"); + + Ok(()) + } }