Skip to content
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-4051] API to perform Spot Check #372

Merged
merged 9 commits into from
Feb 10, 2025
Merged

Conversation

matiasbzurovski
Copy link
Contributor

@matiasbzurovski matiasbzurovski commented Feb 5, 2025

Changelog

  • Adds a new fn perform_spot_check(&self, input: SpotCheckInput) -> bool implemented by FactorSourceIDFromHash, FactorSource & FactorSourceID. This determines whether the associated id was created with the same input than provided.
  • Adds a new function on SargonOS to trigger a Factor Source spot check. This will use a new host interactor that will be responsible for presenting the corresponding UI for user to perform the check. To do so, it will use the function described on previous point.

Copy link

codecov bot commented Feb 5, 2025

Codecov Report

Attention: Patch coverage is 87.00000% with 13 lines in your changes missing coverage. Please review.

Project coverage is 92.66%. Comparing base (a18623a) to head (6c355b1).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...Profile/Factor/FactorSourceID+Wrap+Functions.swift 33.33% 6 Missing ⚠️
...argonOS/ThrowingHostInteractor+Static+Shared.swift 0.00% 3 Missing ⚠️
...factors/factors/src/factor_source_id_spot_check.rs 96.87% 1 Missing ⚠️
...ava/com/radixdlt/sargon/extensions/FactorSource.kt 0.00% 1 Missing ⚠️
...a/com/radixdlt/sargon/extensions/FactorSourceId.kt 50.00% 1 Missing ⚠️
...dixdlt/sargon/extensions/FactorSourceIdFromHash.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #372      +/-   ##
==========================================
- Coverage   92.68%   92.66%   -0.03%     
==========================================
  Files        1184     1187       +3     
  Lines       26689    26781      +92     
  Branches       85       85              
==========================================
+ Hits        24737    24816      +79     
- Misses       1941     1954      +13     
  Partials       11       11              
Flag Coverage Δ
kotlin 98.64% <25.00%> (-0.23%) ⬇️
rust 92.29% <98.66%> (+0.01%) ⬆️
swift 92.66% <57.14%> (-0.22%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

pub enum SpotCheckResponse {
/// The user retrieved the id of a Ledger device.
/// Used for the identification of `LedgerHardwareWalletFactorSource`.
Ledger { id: Exactly32Bytes },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arculus can be added with FactorSourceIdFromHash

pub trait SpotCheckInteractor: Send + Sync {
async fn spot_check(
&self,
factor_source_id: FactorSourceIDFromHash,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not use FactorSource? I imagine that Hosts will have to load the factor source again using the id so we display the information to the user, no?

@matiasbzurovski matiasbzurovski marked this pull request as ready for review February 6, 2025 14:17
factor_source: FactorSource,
) -> Result<bool> {
self.wrapped
.trigger_spot_check(factor_source.into_internal(), false)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the spot check is triggered by the hosts, it will never allow skip

}

impl FactorSourceKind {
fn is_software(&self) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Iwould like a doc here. this is to say that derivation takes place in Radix controlled software? (sargon / hosts)?

because it is not about STORAGE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add some docs and rename to something more descriptive, but this is just to validate that the FactorSourceKind is one with which we should use SpotCheckInput::Software to validate its id.

I am actually wondering if these checks (lines 35, 42 & 50) are actually worthy.. because the FactorSourceIDFromHash built when using incorrect combination of SpotCheckInput & FactorSourceKind would actually result in a different FactorSourceIDFromHash than the original one (unless the original one was incorrectly built)

Comment on lines 35 to 37
if kind != FactorSourceKind::LedgerHQHardwareWallet {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have an error of sort to identify this scenario, as it would be a programmer error. Maybe a CommonError would be useful.


impl FactorSourceIDSpotCheck for FactorSourceIDFromHash {
fn perform_spot_check(&self, input: SpotCheckInput) -> bool {
FactorSourceID::from(*self).perform_spot_check(input)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead move the whole code starting from line 32 here? since that is specific to FactorSourceIDFromHash.

| FactorSourceKind::SecurityQuestions => true,
FactorSourceKind::LedgerHQHardwareWallet
| FactorSourceKind::ArculusCard
| FactorSourceKind::TrustedContact => false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be software I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FactorSourceIDFromAddress is not supported for spot check so doesn't make a difference

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but still it is not hardware kind.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notice that the function has been renamed a few commits ago into expects_software_spot_check_input, which for TrustedContact isn't true since it doesn't expect any spot check input, but I can change if you prefer


/// An enum indicating the result of a spot check.
///
/// Note that there isn't a failure case since user never fails a spot check: it either succeeds,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarification - abort will be error thrown from the host side, HostInteractionAborted is the error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updating docs

@@ -26,7 +26,7 @@ pub struct LedgerHardwareWalletFactorSource {
pub hint: LedgerHardwareWalletHint,
}

fn new_ledger_with_mwp(
unsafe fn new_ledger_with_mwp(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing /// # Safety see other places


#[derive(Clone)]
pub enum SpotCheckUser {
Failure(CommonError),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skipped is past tense of a verb, Valid and Failure are not verbs. Pick a part of speech kind and use for all variants? :)

| FactorSourceKind::SecurityQuestions => true,
FactorSourceKind::LedgerHQHardwareWallet
| FactorSourceKind::ArculusCard
| FactorSourceKind::TrustedContact => false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but still it is not hardware kind.

@matiasbzurovski matiasbzurovski merged commit 72766db into main Feb 10, 2025
11 of 13 checks passed
@matiasbzurovski matiasbzurovski deleted the mb/ABW-4051-spot-check branch February 10, 2025 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants