Skip to content

Commit

Permalink
refactor: remove chrono as dependency (#4344)
Browse files Browse the repository at this point in the history
Description
---
Remove dependency on chrono for birthday calculation in cipherseed

Motivation and Context
---
The wallet recovery uses a few extra days before the actual birthday when scanning, so being accurate to the timezone is not necessary, and certainly doesn't need an extra crate to calculate it.

How Has This Been Tested?
---
tests
  • Loading branch information
stringhandler authored Jul 26, 2022
1 parent 3d92eb0 commit 5f88bfa
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 158 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
153 changes: 0 additions & 153 deletions applications/launchpad/tarilabs.Dockerfile

This file was deleted.

1 change: 0 additions & 1 deletion base_layer/key_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ arrayvec = "0.7.1"
argon2 = { version = "0.2", features = ["std"] }
blake2 = "0.9.1"
chacha20 = "0.7.1"
chrono = { version = "0.4.19", default-features = false, features = ["serde"] }
clear_on_drop = "=0.2.4"
console_error_panic_hook = "0.1.7"
crc32fast = "1.2.1"
Expand Down
10 changes: 7 additions & 3 deletions base_layer/key_manager/src/cipher_seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::{convert::TryFrom, mem::size_of};
use std::{
convert::TryFrom,
mem::size_of,
time::{SystemTime, UNIX_EPOCH},
};

use argon2::{password_hash::SaltString, Argon2, PasswordHasher};
use arrayvec::ArrayVec;
Expand All @@ -34,6 +38,7 @@ use chacha20::{
use crc32fast::Hasher as CrcHasher;
use digest::Update;
use rand::{rngs::OsRng, RngCore};
use serde::{Deserialize, Serialize};
use tari_utilities::ByteArray;

use crate::{
Expand Down Expand Up @@ -82,7 +87,6 @@ pub const CIPHER_SEED_MAC_BYTES: usize = 5;
/// The Birthday is included to enable more efficient recoveries. Knowing the birthday of the seed phrase means we
/// only have to scan the blocks in the chain since that day for full recovery, rather than scanning the entire
/// blockchain.
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct CipherSeed {
Expand All @@ -96,7 +100,7 @@ impl CipherSeed {
#[cfg(not(target_arch = "wasm32"))]
pub fn new() -> Self {
const SECONDS_PER_DAY: u64 = 24 * 60 * 60;
let days = u64::try_from(chrono::Utc::now().timestamp()).unwrap() / SECONDS_PER_DAY;
let days = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs() / SECONDS_PER_DAY;
let birthday = u16::try_from(days).unwrap_or(0u16);
CipherSeed::new_with_birthday(birthday)
}
Expand Down

0 comments on commit 5f88bfa

Please sign in to comment.