Skip to content

Commit

Permalink
GeneralRoleWithHDFIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajjon committed Nov 29, 2024
1 parent 4ed67dd commit 307bcd8
Show file tree
Hide file tree
Showing 11 changed files with 315 additions and 83 deletions.
1 change: 1 addition & 0 deletions crates/rules/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ pretty_assertions = "1.4.1"
serde_json = { version = "1.0.133", features = ["preserve_order"] }
assert-json-diff = "2.0.2"
once_cell = "1.20.2"
itertools = "0.13.0"
9 changes: 6 additions & 3 deletions crates/rules/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ pub mod prelude {
pub(crate) use sargon::{
BIP39Passphrase, BaseIsFactorSource, CommonError, DerivationPreset, DisplayName,
FactorInstance, FactorInstances, FactorSource, FactorSourceID, FactorSourceIDFromHash,
FactorSourceKind, FactorSources, HasSampleValues, HierarchicalDeterministicFactorInstance,
Identifiable, IndexMap, IndexSet, IsMaybeKeySpaceAware, KeySpace, Mnemonic,
MnemonicWithPassphrase, RoleKind,
FactorSourceKind, FactorSources, HasRoleKindObjectSafe, HasSampleValues,
HierarchicalDeterministicFactorInstance, Identifiable, IndexMap, IndexSet,
IsMaybeKeySpaceAware, IsSecurityStateAware, KeySpace, Mnemonic, MnemonicWithPassphrase,
RoleKind,
};

pub(crate) use itertools::*;

#[cfg(test)]
pub(crate) use sargon::JustKV;

Expand Down
15 changes: 15 additions & 0 deletions crates/rules/src/matrices/abstract_matrix_builder_or_built.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::prelude::*;

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AbstractMatrixBuilderOrBuilt<F, T, U> {
#[serde(skip)]
#[doc(hidden)]
Expand All @@ -18,6 +19,20 @@ impl<F, T, U> AbstractMatrixBuilderOrBuilt<F, T, U> {

pub type AbstractMatrixBuilt<F> = AbstractMatrixBuilderOrBuilt<F, (), ()>;

impl<F> AbstractMatrixBuilt<F> {
pub fn primary(&self) -> &AbstractBuiltRoleWithFactor<{ ROLE_PRIMARY }, F> {
&self.primary_role
}

pub fn recovery(&self) -> &AbstractBuiltRoleWithFactor<{ ROLE_RECOVERY }, F> {
&self.recovery_role
}

pub fn confirmation(&self) -> &AbstractBuiltRoleWithFactor<{ ROLE_CONFIRMATION }, F> {
&self.confirmation_role
}
}

impl<F: std::cmp::Eq + std::hash::Hash> AbstractMatrixBuilt<F> {
pub fn all_factors(&self) -> HashSet<&F> {
let mut factors = HashSet::new();
Expand Down
20 changes: 10 additions & 10 deletions crates/rules/src/matrices/matrix_of_factor_instances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ mod tests {
&sut,
r#"
{
"primary_role": {
"primaryRole": {
"threshold": 2,
"threshold_factors": [
"thresholdFactors": [
{
"factorSourceID": {
"discriminator": "fromHash",
Expand Down Expand Up @@ -210,12 +210,12 @@ mod tests {
}
}
],
"override_factors": []
"overrideFactors": []
},
"recovery_role": {
"recoveryRole": {
"threshold": 0,
"threshold_factors": [],
"override_factors": [
"thresholdFactors": [],
"overrideFactors": [
{
"factorSourceID": {
"discriminator": "fromHash",
Expand Down Expand Up @@ -268,10 +268,10 @@ mod tests {
}
]
},
"confirmation_role": {
"confirmationRole": {
"threshold": 0,
"threshold_factors": [],
"override_factors": [
"thresholdFactors": [],
"overrideFactors": [
{
"factorSourceID": {
"discriminator": "fromHash",
Expand Down Expand Up @@ -299,7 +299,7 @@ mod tests {
}
]
},
"number_of_days_until_auto_confirm": 14
"numberOfDaysUntilAutoConfirm": 14
}
"#,
);
Expand Down
58 changes: 22 additions & 36 deletions crates/rules/src/matrices/matrix_of_factor_source_ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,6 @@ impl MatrixOfFactorSourceIds {
}
}

impl MatrixOfFactorSourceIds {
pub fn primary(&self) -> &PrimaryRoleWithFactorSourceIds {
&self.primary_role
}

pub fn recovery(&self) -> &RecoveryRoleWithFactorSourceIds {
&self.recovery_role
}

pub fn confirmation(&self) -> &ConfirmationRoleWithFactorSourceIds {
&self.confirmation_role
}
}

impl MatrixOfFactorSourceIds {
pub fn sample_config_12() -> Self {
let mut builder = MatrixBuilder::new();
Expand Down Expand Up @@ -169,10 +155,10 @@ mod tests {
assert_eq_after_json_roundtrip(
&sut,
r#"
{
"primary_role": {
{
"primaryRole": {
"threshold": 2,
"threshold_factors": [
"thresholdFactors": [
{
"discriminator": "fromHash",
"fromHash": {
Expand All @@ -188,12 +174,12 @@ mod tests {
}
}
],
"override_factors": []
"overrideFactors": []
},
"recovery_role": {
"recoveryRole": {
"threshold": 0,
"threshold_factors": [],
"override_factors": [
"thresholdFactors": [],
"overrideFactors": [
{
"discriminator": "fromHash",
"fromHash": {
Expand All @@ -210,10 +196,10 @@ mod tests {
}
]
},
"confirmation_role": {
"confirmationRole": {
"threshold": 0,
"threshold_factors": [],
"override_factors": [
"thresholdFactors": [],
"overrideFactors": [
{
"discriminator": "fromHash",
"fromHash": {
Expand All @@ -223,7 +209,7 @@ mod tests {
}
]
},
"number_of_days_until_auto_confirm": 14
"numberOfDaysUntilAutoConfirm": 14
}
"#,
);
Expand All @@ -235,11 +221,11 @@ mod tests {
assert_eq_after_json_roundtrip(
&sut,
r#"
{
"primary_role": {
{
"primaryRole": {
"threshold": 0,
"threshold_factors": [],
"override_factors": [
"thresholdFactors": [],
"overrideFactors": [
{
"discriminator": "fromHash",
"fromHash": {
Expand All @@ -249,10 +235,10 @@ mod tests {
}
]
},
"recovery_role": {
"recoveryRole": {
"threshold": 0,
"threshold_factors": [],
"override_factors": [
"thresholdFactors": [],
"overrideFactors": [
{
"discriminator": "fromHash",
"fromHash": {
Expand All @@ -262,10 +248,10 @@ mod tests {
}
]
},
"confirmation_role": {
"confirmationRole": {
"threshold": 0,
"threshold_factors": [],
"override_factors": [
"thresholdFactors": [],
"overrideFactors": [
{
"discriminator": "fromHash",
"fromHash": {
Expand All @@ -275,7 +261,7 @@ mod tests {
}
]
},
"number_of_days_until_auto_confirm": 14
"numberOfDaysUntilAutoConfirm": 14
}
"#,
);
Expand Down
1 change: 1 addition & 0 deletions crates/rules/src/roles/abstract_role_builder_or_built.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
use crate::prelude::*;

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AbstractRoleBuilderOrBuilt<const R: u8, F, T> {
#[serde(skip)]
#[doc(hidden)]
Expand Down
Loading

0 comments on commit 307bcd8

Please sign in to comment.