Skip to content

Commit

Permalink
Doc KeySpace
Browse files Browse the repository at this point in the history
  • Loading branch information
CyonAlexRDX committed Oct 11, 2024
1 parent 416c2ee commit 8136341
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
15 changes: 0 additions & 15 deletions src/types/new_methods_on_sargon_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,6 @@ impl TransactionIntent {
}
}

#[derive(Clone, Copy, PartialEq, Eq, Hash, derive_more::Display, derive_more::Debug)]
pub enum KeySpace {
#[display("Unsecurified")]
#[debug("Unsecurified")]
Unsecurified,
#[display("Securified")]
#[debug("Securified")]
Securified,
}
impl KeySpace {
pub fn both() -> [Self; 2] {
[Self::Unsecurified, Self::Securified]
}
}

impl DerivationPath {
pub fn key_space(&self) -> KeySpace {
self.index.key_space()
Expand Down
6 changes: 0 additions & 6 deletions src/types/new_types/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ pub struct Entities<E: IsNetworkAware + Clone + std::hash::Hash + std::cmp::Eq>
}

impl<E: IsNetworkAware + Clone + std::hash::Hash + std::cmp::Eq> Entities<E> {
pub fn just(entity: E) -> Self {
Self {
network_id: entity.network_id(),
entities: IndexSet::just(entity),
}
}
pub fn new(network_id: NetworkID, entities: IndexSet<E>) -> Result<Self> {
if entities.is_empty() {
return Err(CommonError::EmptyCollection);
Expand Down
37 changes: 37 additions & 0 deletions src/types/new_types/key_space.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use crate::prelude::*;

/// We split the hardened derivation entity index "space" in
/// two halves. The first half is used for unsecurified entities,
/// and the second half is used for securified entities.
///
/// The Unsecurified half works as it does today, with hardened
/// `u32` values, where hardened denotes addition of `2^31`.
///
/// The Securified half is a new concept, where we offset the
/// `u32` value with half of the 2^31 space, i.e. `2^30`.
#[derive(Clone, Copy, PartialEq, Eq, Hash, derive_more::Display, derive_more::Debug)]
pub enum KeySpace {
/// Used by FactorInstances controlling
/// unsecurified entities, called "VECI"s
/// Virtual Entity Creating (Factor)Instances.
#[display("Unsecurified")]
#[debug("Unsecurified")]
Unsecurified,

/// Used by FactorInstances in MatrixOfFactorInstances
/// for securified entities.
///
/// This is the entity base index value, `u32` `+ 2^30`.
///
/// We use `6^` notation to indicate: `6' + 2^30`, where `'`,
/// is the standard notation for hardened indices.
#[display("Securified")]
#[debug("Securified")]
Securified,
}

impl KeySpace {
pub fn both() -> [Self; 2] {
[Self::Unsecurified, Self::Securified]

Check warning on line 35 in src/types/new_types/key_space.rs

View check run for this annotation

Codecov / codecov/patch

src/types/new_types/key_space.rs#L35

Added line #L35 was not covered by tests
}
}
2 changes: 2 additions & 0 deletions src/types/new_types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod accounts;
mod factor_instances;
mod is_securified_entity;
mod key_space;
mod securified_account;
mod securified_accounts;
mod securified_entity;
Expand All @@ -12,6 +13,7 @@ mod veci;
pub use accounts::*;
pub use factor_instances::*;
pub use is_securified_entity::*;
pub use key_space::*;
pub use securified_account::*;
pub use securified_accounts::*;
pub use securified_entity::*;
Expand Down

0 comments on commit 8136341

Please sign in to comment.