-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ABW-3969] Shield Setup Select Factors - utility functions #297
Conversation
factor_sources: Vec<FactorSource>, | ||
) -> SelectedFactorSourcesStatus { | ||
if factor_sources.is_empty() { | ||
SelectedFactorSourcesStatus::Insufficient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm 1
is never enough for a whole shield. So this must be PER ROLE and which role is it? Primary
("Access")?
If so the enum and this method should make it clear that it is for Primary
.
(Or if it is dynamic it should be for_role: RoleKind
as input, and then we should not return just an enum but rather a struct with the status and the role)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Post-our sync:
Delegate this to MatrixBuilder
In MatrixBuilder:
We should probably NOT let this be a STATIC, even if we wont use the internal state of the MatrixBuilder
initially we still might want to in the future. So I would do these changes:
- change it to be on
&self
(i.e. not "static") - change it to take a
for_role: RoleKind
factor_sources: Vec<FactorSource>, | ||
) -> Vec<FactorSource> { | ||
let mut sorted = factor_sources; | ||
sorted.sort_by_key(|fs| fs.factor_source_kind().display_order()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the perpetual naming challenge for these kind of things... :) I think let mut sorted = factor_sources
is misleading, since it is in fact not sorted yet!
Luckily In Rust we have ownership!
so:
let mut unsorted = factor_sources;
unsorted.sort....
let sorted = unsorted;
// no `unsorted` can never be referenced again! it has been consumed! Rust owns!
sorted
InternalSecurityShieldBuilder::sorted_factor_sources_for_selection( | ||
factor_sources.into_internal(), | ||
); | ||
factors.into_iter().map(FactorSource::from).collect() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think:
factors.into_iter().map(FactorSource::from).collect()
can be changed to just:
factors.into_type()
import Foundation | ||
import SargonUniFFI | ||
|
||
extension SecurityShieldBuilder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably not needed since should be member method, not global free standing func.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kept sortedFactorSourcesForSelection
as a static function since it’s just a utility function and doesn’t need to involve the shield builder or imply that it can be modified.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #297 +/- ##
=====================================
Coverage 93.3% 93.3%
=====================================
Files 1095 1095
Lines 22922 22962 +40
Branches 77 77
=====================================
+ Hits 21387 21427 +40
Misses 1521 1521
Partials 14 14
Flags with carried forward coverage won't be shown. Click here to find out more.
|
#[derive( | ||
Clone, Copy, Debug, PartialEq, Eq, InternalConversion, uniffi::Enum, | ||
)] | ||
pub enum SelectedFactorSourcesStatus { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SelectedFactorSourcesForRoleStatus
?
factor_sources: Vec<FactorSource>, | ||
) -> SelectedFactorSourcesStatus { | ||
if factor_sources.is_empty() { | ||
SelectedFactorSourcesStatus::Insufficient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Post-our sync:
Delegate this to MatrixBuilder
In MatrixBuilder:
We should probably NOT let this be a STATIC, even if we wont use the internal state of the MatrixBuilder
initially we still might want to in the future. So I would do these changes:
- change it to be on
&self
(i.e. not "static") - change it to take a
for_role: RoleKind
/// The selected factor sources form an invalid combination for the specified role | ||
/// in the Security Shield building process. | ||
/// | ||
/// Example: A Password factor source cannot be used alone for the Primary role. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example seems to fall more under the Insufficient
category
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the host’s perspective, this should fall under the Invalid
category and display a generic error message. If the Primary role has threshold
set to 1
, then adding a Password factor source satisfies the threshold condition, but it’s still invalid. It could fall under the Insufficient
category if we have a dynamic threshold that updates based on the available factor sources. Do we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is threshold important in the context of selecting the factors before going in the Access setup build screen?
Also, if there are no roles selected the status is Insufficient, but if you have password it is considered Invalid, when IMO it is a case of insufficient - you need one more factor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very UI specific type and we have in the UI 3 error/warning states:
- User need to select at least 1 factor ->
Insufficient
- It is recommended to select at least 2 factors ->
Suboptimal
- Any other invalid combinations for a specific role (Access) ->
Invalid
Based on that, this case falls under Invalid
, even if it doesn't sound correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am confused here - what is any other combinations? Shouldn't we display only the factors that are allowed to be selected in treshold Access role?
So then the only "Invalid" scenario is that the password cannot be alone, some other might be added in the future sure.
- User need to select at least 1 factor -> Insufficient
- It is recommended to select at least 2 factors -> Suboptimal
- Any other invalid combinations for a specific role (Access) -> Invalid
So the Wallet will display red for 1 and 3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So then the only "Invalid" scenario is that the password cannot be alone, some other might be added in the future sure.
Exactly
So the Wallet will display red for 1 and 3?
Yes. 3 will have a "read more" where the user can read more about the rules
}) | ||
} | ||
|
||
pub fn selected_factor_sources_for_role_status( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is meant to be used in Select Factors for Transactions screen? If so, do we need an instance of a builder to validate the selected combination of the factors?
Additionally, the fact that it returns SelectedFactorSourcesForRoleStatus
, implies that the builder might contain invalid factors, but AFAIK we are actively trying to prevent this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need an instance of a builder
Not necessarily, @CyonAlexRDX suggested this. Also, it seems easier since all the current validation functions are on a builder instance.
implies that the builder might contain invalid factors
Not the factors themselves, but in the context of a specific role.
pub fn security_shield_builder_sorted_factor_sources_for_selection( | ||
factor_sources: Vec<FactorSource>, | ||
) -> Vec<FactorSource> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't Sargon load the list of factor sources itself, sort and filter the appropriate factor sources?
// ==== STATIC ==== | ||
// ================ | ||
impl SecurityShieldBuilder { | ||
pub fn sorted_factor_sources_for_selection( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this specific for Select Factors for Transactions, aka for Access role? If so, then it should be specific. Also not all factor sources can be used for Access role, thus some filtering need to happen as well AFAIK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Security questions and trusted contact (not supported in MVP) cannot be used for Access role, we can filter them out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct, these should be filtered out accordingly.
@@ -118,6 +118,20 @@ impl FactorSourceKind { | |||
} | |||
} | |||
|
|||
impl FactorSourceKind { | |||
pub fn display_order(&self) -> u8 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO in the context of this PR, it should be specific display order for Select Factor for Access Role, not generic order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM .
We can always iterate if we need adjust it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to include the filtering also
Changelog
sorted_factor_sources_for_selection function
, which handles the logic for sorting a list of factor sources on theSelect Factors
screen.selected_factor_sources_status
function, which returns a newly added enum,SelectedFactorSourcesStatus
, representing the status of selected factor sources in the Security Shield building process.allCases
forSecurityProblemKind