Skip to content

Commit

Permalink
derive and analyze input
Browse files Browse the repository at this point in the history
  • Loading branch information
CyonAlexRDX committed Sep 20, 2024
1 parent 90baa3f commit f6f1533
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use crate::prelude::*;

async fn _account_recovery_scan(

Check warning on line 3 in src/recovery_securify_cache/account_recover_scan/account_recovery_scanning.rs

View check run for this annotation

Codecov / codecov/patch

src/recovery_securify_cache/account_recover_scan/account_recovery_scanning.rs#L3

Added line #L3 was not covered by tests
input: DeriveAndAnalyzeInputAccountRecoveryScan,
) -> Result<DerivationAndAnalysisAccountRecoveryScan> {
let input = DeriveAndAnalyzeInput::from(input);
let analysis = derive_and_analyze(input).await?;
DerivationAndAnalysisAccountRecoveryScan::try_from(analysis)
}

pub async fn account_recovery_scan(

Check warning on line 11 in src/recovery_securify_cache/account_recover_scan/account_recovery_scanning.rs

View check run for this annotation

Codecov / codecov/patch

src/recovery_securify_cache/account_recover_scan/account_recovery_scanning.rs#L11

Added line #L11 was not covered by tests
factor_sources: IndexSet<HDFactorSource>,
gateway: Arc<dyn Gateway>,
) -> Result<AccountRecoveryScanOutcome> {
let analysis = _account_recovery_scan(DeriveAndAnalyzeInputAccountRecoveryScan::new(
factor_sources,
gateway,
))
.await?;
Ok(AccountRecoveryScanOutcome::from(analysis))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use crate::prelude::*;

pub struct DeriveAndAnalyzeInputAccountRecoveryScan {
factor_sources: IndexSet<HDFactorSource>,
gateway: Arc<dyn Gateway>,
}
impl DeriveAndAnalyzeInputAccountRecoveryScan {
pub fn new(factor_sources: IndexSet<HDFactorSource>, gateway: Arc<dyn Gateway>) -> Self {

Check warning on line 8 in src/recovery_securify_cache/account_recover_scan/derive_and_analyze_input_account_recovery_scan.rs

View check run for this annotation

Codecov / codecov/patch

src/recovery_securify_cache/account_recover_scan/derive_and_analyze_input_account_recovery_scan.rs#L8

Added line #L8 was not covered by tests
Self {
factor_sources,
gateway,
}
}
}
impl From<DeriveAndAnalyzeInputAccountRecoveryScan> for DeriveAndAnalyzeInput {
fn from(value: DeriveAndAnalyzeInputAccountRecoveryScan) -> Self {

Check warning on line 16 in src/recovery_securify_cache/account_recover_scan/derive_and_analyze_input_account_recovery_scan.rs

View check run for this annotation

Codecov / codecov/patch

src/recovery_securify_cache/account_recover_scan/derive_and_analyze_input_account_recovery_scan.rs#L16

Added line #L16 was not covered by tests
Self::new(
value.factor_sources.clone(),
value

Check warning on line 19 in src/recovery_securify_cache/account_recover_scan/derive_and_analyze_input_account_recovery_scan.rs

View check run for this annotation

Codecov / codecov/patch

src/recovery_securify_cache/account_recover_scan/derive_and_analyze_input_account_recovery_scan.rs#L18-L19

Added lines #L18 - L19 were not covered by tests
.factor_sources
.into_iter()
.map(|f| f.factor_source_id())

Check warning on line 22 in src/recovery_securify_cache/account_recover_scan/derive_and_analyze_input_account_recovery_scan.rs

View check run for this annotation

Codecov / codecov/patch

src/recovery_securify_cache/account_recover_scan/derive_and_analyze_input_account_recovery_scan.rs#L22

Added line #L22 was not covered by tests
.collect(),
None,
value.gateway,

Check warning on line 25 in src/recovery_securify_cache/account_recover_scan/derive_and_analyze_input_account_recovery_scan.rs

View check run for this annotation

Codecov / codecov/patch

src/recovery_securify_cache/account_recover_scan/derive_and_analyze_input_account_recovery_scan.rs#L24-L25

Added lines #L24 - L25 were not covered by tests
true,
None,

Check warning on line 27 in src/recovery_securify_cache/account_recover_scan/derive_and_analyze_input_account_recovery_scan.rs

View check run for this annotation

Codecov / codecov/patch

src/recovery_securify_cache/account_recover_scan/derive_and_analyze_input_account_recovery_scan.rs#L27

Added line #L27 was not covered by tests
)
}
}
4 changes: 4 additions & 0 deletions src/recovery_securify_cache/account_recover_scan/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
mod account_recovery_scan_outcome;
mod account_recovery_scanning;
mod derivation_and_analysis_account_recovery_scan;
mod derive_and_analyze_input_account_recovery_scan;

pub use account_recovery_scan_outcome::*;
pub use account_recovery_scanning::*;
pub use derivation_and_analysis_account_recovery_scan::*;
pub use derive_and_analyze_input_account_recovery_scan::*;
46 changes: 46 additions & 0 deletions src/recovery_securify_cache/derivation_and_analysis/input.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#![allow(unused)]

use crate::prelude::*;

pub struct ProfileNextIndexAnalyzer {}

pub struct DeriveAndAnalyzeInput {
factor_sources: IndexSet<HDFactorSource>,
ids_of_new_factor_sources: IndexSet<FactorSourceIDFromHash>,
cache: Option<PreDerivedKeysCache>,
gateway: Arc<dyn Gateway>,

/// "Gateway required"
is_onchain_analysis_required: bool,

profile_next_index_analyzer: Option<ProfileNextIndexAnalyzer>,
}

impl DeriveAndAnalyzeInput {
/// # Panics
/// Panics if some IDs of `ids_of_new_factor_sources` are not found in `factor_sources`
pub fn new(

Check warning on line 22 in src/recovery_securify_cache/derivation_and_analysis/input.rs

View check run for this annotation

Codecov / codecov/patch

src/recovery_securify_cache/derivation_and_analysis/input.rs#L22

Added line #L22 was not covered by tests
factor_sources: IndexSet<HDFactorSource>,
ids_of_new_factor_sources: IndexSet<FactorSourceIDFromHash>,
cache: Option<PreDerivedKeysCache>,
gateway: Arc<dyn Gateway>,
is_onchain_analysis_required: bool,
profile_next_index_analyzer: Option<ProfileNextIndexAnalyzer>,
) -> Self {
assert!(

Check warning on line 30 in src/recovery_securify_cache/derivation_and_analysis/input.rs

View check run for this annotation

Codecov / codecov/patch

src/recovery_securify_cache/derivation_and_analysis/input.rs#L30

Added line #L30 was not covered by tests
ids_of_new_factor_sources
.iter()
.all(|id| factor_sources.iter().any(|f| f.factor_source_id() == *id)),
"Discrepancy! Some IDs of new factor sources are not found in factor sources!"
);

Self {
factor_sources,
ids_of_new_factor_sources,
cache,
gateway,
is_onchain_analysis_required,
profile_next_index_analyzer,
}
}
}
5 changes: 5 additions & 0 deletions src/recovery_securify_cache/derivation_and_analysis/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod input;
mod output;

pub use input::*;
pub use output::*;
File renamed without changes.
17 changes: 17 additions & 0 deletions src/recovery_securify_cache/derivation_and_analysis/output/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
mod derivation_and_analysis;
mod probably_free_factor_instances;
mod recovered_securified_entities;
mod recovered_unsecurified_entities;
mod securified_entity;
mod unrecovered_securified_entities;
mod unrecovered_securified_entity;
mod unsecurified_entity;

pub use derivation_and_analysis::*;
pub use probably_free_factor_instances::*;
pub use recovered_securified_entities::*;
pub use recovered_unsecurified_entities::*;
pub use securified_entity::*;
pub use unrecovered_securified_entities::*;
pub use unrecovered_securified_entity::*;
pub use unsecurified_entity::*;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ use crate::prelude::*;
/// - `VECI` Addition: NO
/// - Gateway Required: NO (but beneficial to use it if host is online to
/// analyze if FactorInstance are free.)
async fn derive_and_analyze() -> Result<DerivationAndAnalysis> {
pub async fn derive_and_analyze(input: DeriveAndAnalyzeInput) -> Result<DerivationAndAnalysis> {

Check warning on line 68 in src/recovery_securify_cache/derive_and_analyze.rs

View check run for this annotation

Codecov / codecov/patch

src/recovery_securify_cache/derive_and_analyze.rs#L68

Added line #L68 was not covered by tests
todo!()
}

async fn _account_recovery_scan() -> Result<DerivationAndAnalysisAccountRecoveryScan> {
let analysis = derive_and_analyze().await?;
DerivationAndAnalysisAccountRecoveryScan::try_from(analysis)
}

pub async fn account_recovery_scan() -> Result<AccountRecoveryScanOutcome> {
let analysis = _account_recovery_scan().await?;
Ok(AccountRecoveryScanOutcome::from(analysis))
}
17 changes: 2 additions & 15 deletions src/recovery_securify_cache/mod.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
mod account_recover_scan;
mod derivation_and_analysis;
mod playground;
mod derive_and_analyze;
mod pre_derived_keys_cache;
mod probably_free_factor_instances;
mod recovered_securified_entities;
mod recovered_unsecurified_entities;
mod securified_entity;
mod unrecovered_securified_entities;
mod unrecovered_securified_entity;
mod unsecurified_entity;

pub use account_recover_scan::*;
pub use derivation_and_analysis::*;
pub use derive_and_analyze::*;
pub use pre_derived_keys_cache::*;
pub use probably_free_factor_instances::*;
pub use recovered_securified_entities::*;
pub use recovered_unsecurified_entities::*;
pub use securified_entity::*;
pub use unrecovered_securified_entities::*;
pub use unrecovered_securified_entity::*;
pub use unsecurified_entity::*;
2 changes: 0 additions & 2 deletions src/recovery_securify_cache/pre_derived_keys_cache.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::prelude::*;

use super::probably_free_factor_instances;

#[derive(Debug)]
pub struct PreDerivedKeysCache;

Expand Down

0 comments on commit f6f1533

Please sign in to comment.