diff --git a/.tarpaulin.toml b/.tarpaulin.toml index 1a5914e5..a87a0335 100644 --- a/.tarpaulin.toml +++ b/.tarpaulin.toml @@ -2,6 +2,7 @@ exclude-files = [ "crates/rules-uniffi/src/unneeded_when_moved_to_sargon.rs", "crates/rules-uniffi/src/error_conversion.rs", + "crates/rules/src/move_to_sargon.rs", ] verbose = false force-clean = true diff --git a/crates/rules/src/matrices/matrix_of_factor_source_ids.rs b/crates/rules/src/matrices/matrix_of_factor_source_ids.rs index 8ba9568e..2221cf0f 100644 --- a/crates/rules/src/matrices/matrix_of_factor_source_ids.rs +++ b/crates/rules/src/matrices/matrix_of_factor_source_ids.rs @@ -77,6 +77,29 @@ impl MatrixOfFactorSourceIds { builder.build().unwrap() } + pub fn sample_config_24() -> Self { + let mut builder = MatrixBuilder::new(); + + // Primary + // TODO: Ask Matt about this, does he mean Threshold(1) or Override? + builder + .add_factor_source_to_primary_override(FactorSourceID::sample_device()) + .unwrap(); + + // Recovery + builder + .add_factor_source_to_recovery_override(FactorSourceID::sample_ledger()) + .unwrap(); + + // Confirmation + builder + .add_factor_source_to_confirmation_override(FactorSourceID::sample_ledger_other()) + .unwrap(); + + // Build + builder.build().unwrap() + } + pub fn sample_config_11() -> Self { let mut builder = MatrixBuilder::new(); @@ -113,7 +136,7 @@ impl HasSampleValues for MatrixOfFactorSourceIds { } fn sample_other() -> Self { - Self::sample_config_12() + Self::sample_config_24() } } @@ -132,6 +155,12 @@ mod tests { #[test] fn inequality() { assert_ne!(SUT::sample(), SUT::sample_other()); + assert_ne!(SUT::sample().primary(), SUT::sample_other().primary()); + assert_ne!(SUT::sample().recovery(), SUT::sample_other().recovery()); + assert_ne!( + SUT::sample().confirmation(), + SUT::sample_other().confirmation() + ); } #[test] @@ -208,36 +237,22 @@ mod tests { r#" { "primary_role": { - "threshold": 2, - "threshold_factors": [ - { - "discriminator": "fromHash", - "fromHash": { - "kind": "ledgerHQHardwareWallet", - "body": "ab59987eedd181fe98e512c1ba0f5ff059f11b5c7c56f15614dcc9fe03fec58b" - } - }, + "threshold": 0, + "threshold_factors": [], + "override_factors": [ { "discriminator": "fromHash", "fromHash": { - "kind": "passphrase", - "body": "181ab662e19fac3ad9f08d5c673b286d4a5ed9cd3762356dc9831dc42427c1b9" + "kind": "device", + "body": "f1a93d324dd0f2bff89963ab81ed6e0c2ee7e18c0827dc1d3576b2d9f26bbd0a" } } - ], - "override_factors": [] + ] }, "recovery_role": { "threshold": 0, "threshold_factors": [], "override_factors": [ - { - "discriminator": "fromHash", - "fromHash": { - "kind": "device", - "body": "f1a93d324dd0f2bff89963ab81ed6e0c2ee7e18c0827dc1d3576b2d9f26bbd0a" - } - }, { "discriminator": "fromHash", "fromHash": { @@ -254,8 +269,8 @@ mod tests { { "discriminator": "fromHash", "fromHash": { - "kind": "passphrase", - "body": "181ab662e19fac3ad9f08d5c673b286d4a5ed9cd3762356dc9831dc42427c1b9" + "kind": "ledgerHQHardwareWallet", + "body": "52ef052a0642a94279b296d6b3b17dedc035a7ae37b76c1d60f11f2725100077" } } ] diff --git a/crates/rules/src/roles/role_with_factor_instances.rs b/crates/rules/src/roles/role_with_factor_instances.rs index 5300b934..a3bcc3c8 100644 --- a/crates/rules/src/roles/role_with_factor_instances.rs +++ b/crates/rules/src/roles/role_with_factor_instances.rs @@ -85,94 +85,47 @@ pub(crate) type RecoveryRoleWithFactorInstances = RoleWithFactorInstances<{ ROLE pub(crate) type ConfirmationRoleWithFactorInstances = RoleWithFactorInstances<{ ROLE_CONFIRMATION }>; -impl PrimaryRoleWithFactorInstances { - // TODO: MFA Rules change this, this might not be compatible with the rules! - pub fn sample_primary() -> Self { - Self::with_factors( - // RoleKind::Primary, - 1, [ - HierarchicalDeterministicFactorInstance::sample_mainnet_account_device_factor_fs_0_securified_at_index(0).into() - ], [ - HierarchicalDeterministicFactorInstance::sample_mainnet_account_device_factor_fs_10_securified_at_index(0).into() - ]) - } - - // TODO: MFA Rules change this, this might not be compatible with the rules! - pub fn sample_primary_other() -> Self { - Self::with_factors( - // RoleKind::Primary, - 1, - [HierarchicalDeterministicFactorInstance::sample_mainnet_account_device_factor_fs_0_securified_at_index(10).into(),], - [HierarchicalDeterministicFactorInstance::sample_mainnet_account_device_factor_fs_10_securified_at_index(60).into()], - ) - } -} - -impl RecoveryRoleWithFactorInstances { - // TODO: MFA Rules change this, this might not be compatible with the rules! - pub fn sample_recovery() -> Self { - Self::with_factors( - // RoleKind::Recovery, - 0,[], [HierarchicalDeterministicFactorInstance::sample_mainnet_account_device_factor_fs_10_securified_at_index(237).into()] - ) +impl HasSampleValues for PrimaryRoleWithFactorInstances { + fn sample() -> Self { + MatrixOfFactorInstances::sample().primary_role } - // TODO: MFA Rules change this, this might not be compatible with the rules! - pub fn sample_recovery_other() -> Self { - Self::with_factors( - // RoleKind::Recovery, - 0,[], [HierarchicalDeterministicFactorInstance::sample_mainnet_account_device_factor_fs_10_securified_at_index(42).into()] - ) + fn sample_other() -> Self { + MatrixOfFactorInstances::sample_other().primary_role } } -impl ConfirmationRoleWithFactorInstances { - // TODO: MFA Rules change this, this might not be compatible with the rules! - pub fn sample_confirmation() -> Self { - Self::with_factors( - // RoleKind::Confirmation, - 0,[], [HierarchicalDeterministicFactorInstance::sample_mainnet_account_device_factor_fs_0_securified_at_index(1).into(), HierarchicalDeterministicFactorInstance::sample_mainnet_account_device_factor_fs_10_securified_at_index(2).into()] - ) +impl HasSampleValues for ConfirmationRoleWithFactorInstances { + fn sample() -> Self { + MatrixOfFactorInstances::sample().confirmation_role } - // TODO: MFA Rules change this, this might not be compatible with the rules! - pub fn sample_confirmation_other() -> Self { - Self::with_factors( - // RoleKind::Confirmation, - 0,[], [HierarchicalDeterministicFactorInstance::sample_mainnet_account_device_factor_fs_0_securified_at_index(10).into(), HierarchicalDeterministicFactorInstance::sample_mainnet_account_device_factor_fs_10_securified_at_index(20).into()] - ) + fn sample_other() -> Self { + MatrixOfFactorInstances::sample_other().confirmation_role } } -/* -impl HasSampleValues for PrimaryRoleWithFactorInstances { +impl HasSampleValues for RecoveryRoleWithFactorInstances { fn sample() -> Self { - Self::sample_primary() + MatrixOfFactorInstances::sample().recovery_role } fn sample_other() -> Self { - Self::sample_primary_other() + MatrixOfFactorInstances::sample_other().recovery_role } } #[cfg(test)] -mod tests { +mod primary_tests { use super::*; #[allow(clippy::upper_case_acronyms)] - type SUT = RoleWithFactorInstances; + type SUT = PrimaryRoleWithFactorInstances; #[test] fn equality() { - assert_eq!(SUT::sample_primary(), SUT::sample_primary()); - assert_eq!(SUT::sample_primary_other(), SUT::sample_primary_other()); - assert_eq!(SUT::sample_recovery(), SUT::sample_recovery()); - assert_eq!(SUT::sample_recovery_other(), SUT::sample_recovery_other()); - assert_eq!(SUT::sample_confirmation(), SUT::sample_confirmation()); - assert_eq!( - SUT::sample_confirmation_other(), - SUT::sample_confirmation_other() - ); + assert_eq!(SUT::sample(), SUT::sample()); + assert_eq!(SUT::sample_other(), SUT::sample_other()); } #[test] @@ -180,31 +133,10 @@ mod tests { assert_ne!(SUT::sample(), SUT::sample_other()); } - #[test] - fn hash() { - let hash = HashSet::::from_iter([ - SUT::sample_primary(), - SUT::sample_primary_other(), - SUT::sample_recovery(), - SUT::sample_recovery_other(), - SUT::sample_confirmation(), - SUT::sample_confirmation_other(), - // Duplicates should be removed - SUT::sample_primary(), - SUT::sample_primary_other(), - SUT::sample_recovery(), - SUT::sample_recovery_other(), - SUT::sample_confirmation(), - SUT::sample_confirmation_other(), - ]); - assert_eq!(hash.len(), 6); - } - #[test] #[should_panic] fn primary_role_non_securified_threshold_instances_is_err() { let _ = SUT::with_factors( - RoleKind::Primary, 1, [ HierarchicalDeterministicFactorInstance::sample_mainnet_account_device_factor_fs_10_unsecurified_at_index(0).into() @@ -220,8 +152,7 @@ mod tests { &sut, r#" { - "role": "primary", - "threshold": 1, + "threshold": 2, "threshold_factors": [ { "factorSourceID": { @@ -247,15 +178,13 @@ mod tests { } } } - } - ], - "override_factors": [ + }, { "factorSourceID": { "discriminator": "fromHash", "fromHash": { - "kind": "device", - "body": "5255999c65076ce9ced5a1881f1a621bba1ce3f1f68a61df462d96822a5190cd" + "kind": "ledgerHQHardwareWallet", + "body": "ab59987eedd181fe98e512c1ba0f5ff059f11b5c7c56f15614dcc9fe03fec58b" } }, "badge": { @@ -265,7 +194,7 @@ mod tests { "hierarchicalDeterministicPublicKey": { "publicKey": { "curve": "curve25519", - "compressedData": "e0293d4979bc303ea4fe361a62baf9c060c7d90267972b05c61eead9ef3eed3e" + "compressedData": "92cd6838cd4e7b0523ed93d498e093f71139ffd5d632578189b39a26005be56b" }, "derivationPath": { "scheme": "cap26", @@ -275,10 +204,48 @@ mod tests { } } } - ] + ], + "override_factors": [] } "#, ); } } -*/ + +#[cfg(test)] +mod confirmation_tests { + use super::*; + + #[allow(clippy::upper_case_acronyms)] + type SUT = ConfirmationRoleWithFactorInstances; + + #[test] + fn equality() { + assert_eq!(SUT::sample(), SUT::sample()); + assert_eq!(SUT::sample_other(), SUT::sample_other()); + } + + #[test] + fn inequality() { + assert_ne!(SUT::sample(), SUT::sample_other()); + } +} + +#[cfg(test)] +mod recovery_tests { + use super::*; + + #[allow(clippy::upper_case_acronyms)] + type SUT = RecoveryRoleWithFactorInstances; + + #[test] + fn equality() { + assert_eq!(SUT::sample(), SUT::sample()); + assert_eq!(SUT::sample_other(), SUT::sample_other()); + } + + #[test] + fn inequality() { + assert_ne!(SUT::sample(), SUT::sample_other()); + } +} diff --git a/crates/rules/src/security_structure_of_factors/security_structure_of_factor_source_ids.rs b/crates/rules/src/security_structure_of_factors/security_structure_of_factor_source_ids.rs index f1daa31b..4b68d7b2 100644 --- a/crates/rules/src/security_structure_of_factors/security_structure_of_factor_source_ids.rs +++ b/crates/rules/src/security_structure_of_factors/security_structure_of_factor_source_ids.rs @@ -120,36 +120,22 @@ mod tests { }, "matrix_of_factors": { "primary_role": { - "threshold": 2, - "threshold_factors": [ - { - "discriminator": "fromHash", - "fromHash": { - "kind": "ledgerHQHardwareWallet", - "body": "ab59987eedd181fe98e512c1ba0f5ff059f11b5c7c56f15614dcc9fe03fec58b" - } - }, + "threshold": 0, + "threshold_factors": [], + "override_factors": [ { "discriminator": "fromHash", "fromHash": { - "kind": "passphrase", - "body": "181ab662e19fac3ad9f08d5c673b286d4a5ed9cd3762356dc9831dc42427c1b9" + "kind": "device", + "body": "f1a93d324dd0f2bff89963ab81ed6e0c2ee7e18c0827dc1d3576b2d9f26bbd0a" } } - ], - "override_factors": [] + ] }, "recovery_role": { "threshold": 0, "threshold_factors": [], "override_factors": [ - { - "discriminator": "fromHash", - "fromHash": { - "kind": "device", - "body": "f1a93d324dd0f2bff89963ab81ed6e0c2ee7e18c0827dc1d3576b2d9f26bbd0a" - } - }, { "discriminator": "fromHash", "fromHash": { @@ -166,8 +152,8 @@ mod tests { { "discriminator": "fromHash", "fromHash": { - "kind": "passphrase", - "body": "181ab662e19fac3ad9f08d5c673b286d4a5ed9cd3762356dc9831dc42427c1b9" + "kind": "ledgerHQHardwareWallet", + "body": "52ef052a0642a94279b296d6b3b17dedc035a7ae37b76c1d60f11f2725100077" } } ]