Skip to content

Commit

Permalink
playground: sketching ideas based on the important realization that A…
Browse files Browse the repository at this point in the history
…ddFactorSource, Recovery, Derive&Securify-Without-or-with-Empty-Cache are all essentially the same operation. Deriving many keys, scanning Gateway (and Profile if not recovery) and matching against those 'filters' known keys and putting beleived-to-be-'free' keys into the cache.
  • Loading branch information
CyonAlexRDX committed Sep 18, 2024
1 parent b21e091 commit 8ab2f51
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/factor_instance_provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ pub use cache::*;
pub use derivation_request::*;
pub use factor_instance_provider::*;
pub use gateway::*;
use indexmap::IndexSet;
pub use profile_extensions::*;
pub use securify::*;
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

mod derivation;
mod factor_instance_provider;
mod playground;
mod recovery;
mod samples;
mod signing;
Expand Down Expand Up @@ -34,6 +35,8 @@ pub mod prelude {
pub(crate) use indexmap::{IndexMap, IndexSet};
pub(crate) use itertools::Itertools;
pub(crate) use std::cell::RefCell;
pub(crate) use std::future::Future;
pub(crate) use std::pin::Pin;
pub(crate) use std::time::SystemTime;
pub(crate) use uuid::Uuid;

Expand Down
88 changes: 88 additions & 0 deletions src/playground.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#![allow(unused)]

use crate::prelude::*;

/// "Probably" since we might not have all the information to be sure, since
/// Gateway might not keep track of past FactorInstances, some of the FactorInstances
/// in KeySpace::Securified might in fact have been used in the past for some entity.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProbablyFreeFactorInstances(IndexSet<HierarchicalDeterministicFactorInstance>);

enum ScanHookDecision {
/// "Probably" since we might not have all the information to be sure, since
/// Gateway might not keep track of past FactorInstances, some of the FactorInstances
/// in KeySpace::Securified might in fact have been used in the past for some entity.
ProbablyIsFree(HierarchicalDeterministicFactorInstance),
UnsecurifiedEntityRecovered(AccountOrPersona),
SecurifiedEntityReferencesFactor {
entity_address: AddressOfAccountOrPersona,
factor_instance: HierarchicalDeterministicFactorInstance,
},
}

type OnFactorInstance = Box<
dyn FnOnce(
HierarchicalDeterministicFactorInstance,
) -> Pin<Box<dyn Future<Output = ScanHookDecision>>>,
>;
struct ScanHook {
on_factor_instance: OnFactorInstance,
}

async fn scan(
factor_sources: IndexSet<HDFactorSource>,
profile_scan_hook: impl Into<Option<ScanHook>>,
gateway_scan_hook: impl Into<Option<ScanHook>>,
) -> Result<(IndexSet<AccountOrPersona>, ProbablyFreeFactorInstances)> {
todo!()
}
impl dyn GatewayReadonly {
fn scan_hook(&self) -> ScanHook {

Check warning on line 40 in src/playground.rs

View check run for this annotation

Codecov / codecov/patch

src/playground.rs#L40

Added line #L40 was not covered by tests
todo!()
}
}
impl Profile {
fn scan_hook(&self) -> ScanHook {

Check warning on line 45 in src/playground.rs

View check run for this annotation

Codecov / codecov/patch

src/playground.rs#L45

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

async fn add_factor_source(

Check warning on line 49 in src/playground.rs

View check run for this annotation

Codecov / codecov/patch

src/playground.rs#L49

Added line #L49 was not covered by tests
&mut self,
factor_source: HDFactorSource,
derivation_interactors: Arc<dyn KeysDerivationInteractors>,
gateway_scan_hook: ScanHook,
) -> Result<()> {
let (found_entities, probably_free) = scan(
IndexSet::just(factor_source),
self.scan_hook(),
gateway_scan_hook,
)
.await?;
todo!()
}

async fn add_factor_source_with_gateway(

Check warning on line 64 in src/playground.rs

View check run for this annotation

Codecov / codecov/patch

src/playground.rs#L64

Added line #L64 was not covered by tests
&mut self,
factor_source: HDFactorSource,
derivation_interactors: Arc<dyn KeysDerivationInteractors>,
gateway: Arc<dyn GatewayReadonly>,
) -> Result<()> {
self.add_factor_source(factor_source, derivation_interactors, gateway.scan_hook())
.await
}
}

async fn recovery(

Check warning on line 75 in src/playground.rs

View check run for this annotation

Codecov / codecov/patch

src/playground.rs#L75

Added line #L75 was not covered by tests
factor_sources: IndexSet<HDFactorSource>,
gateway_scan_hook: ScanHook,
) -> Result<(Profile, ProbablyFreeFactorInstances)> {
let (found_entities, probably_free) = scan(factor_sources, None, gateway_scan_hook).await?;
todo!()
}

async fn recovery_with_gateway(

Check warning on line 83 in src/playground.rs

View check run for this annotation

Codecov / codecov/patch

src/playground.rs#L83

Added line #L83 was not covered by tests
factor_sources: IndexSet<HDFactorSource>,
gateway: Arc<dyn GatewayReadonly>,
) -> Result<(Profile, ProbablyFreeFactorInstances)> {
recovery(factor_sources, gateway.scan_hook()).await
}

0 comments on commit 8ab2f51

Please sign in to comment.