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

Adding new device factor source #380

Merged
merged 33 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
acce421
Initial setup new factor adding builder
sergiupuhalschi-rdx Feb 7, 2025
a79d8cd
WIP
sergiupuhalschi-rdx Feb 10, 2025
fb37f0b
Uniffi export
sergiupuhalschi-rdx Feb 11, 2025
8661ecb
WIP
sergiupuhalschi-rdx Feb 11, 2025
3e5616d
WIP
sergiupuhalschi-rdx Feb 12, 2025
1f0097b
WIP
sergiupuhalschi-rdx Feb 12, 2025
73b1483
Merge branch 'main' into sp/add-new-factor-builder
sergiupuhalschi-rdx Feb 12, 2025
32a32f1
PR comments
sergiupuhalschi-rdx Feb 13, 2025
dab1d1c
Address comments
sergiupuhalschi-rdx Feb 13, 2025
7d76099
Merge branch 'main' into sp/add-new-factor-builder
sergiupuhalschi-rdx Feb 13, 2025
284abe8
WIP
sergiupuhalschi-rdx Feb 13, 2025
93bb0ec
WIP
sergiupuhalschi-rdx Feb 14, 2025
c59b561
WIP
sergiupuhalschi-rdx Feb 14, 2025
4a9113b
Merge main
sergiupuhalschi-rdx Feb 14, 2025
aa0e36a
WIP
sergiupuhalschi-rdx Feb 17, 2025
6bebee0
Remove unnecessary test
sergiupuhalschi-rdx Feb 17, 2025
6e92c10
WIP
sergiupuhalschi-rdx Feb 17, 2025
ea6d363
Add tests
sergiupuhalschi-rdx Feb 17, 2025
7efc3b8
Add tests
sergiupuhalschi-rdx Feb 17, 2025
5d12b26
Add test
sergiupuhalschi-rdx Feb 18, 2025
3edd3e1
Fix fn cfg
sergiupuhalschi-rdx Feb 18, 2025
a3232f6
Fix typo
sergiupuhalschi-rdx Feb 18, 2025
14fab67
Expose function
sergiupuhalschi-rdx Feb 18, 2025
32cc180
PR review
sergiupuhalschi-rdx Feb 19, 2025
c1272b4
Expose error
sergiupuhalschi-rdx Feb 19, 2025
e6af3bd
Improve random indices generating
sergiupuhalschi-rdx Feb 19, 2025
cdf3635
PR review
sergiupuhalschi-rdx Feb 20, 2025
55cc10e
PR review
sergiupuhalschi-rdx Feb 20, 2025
1660d38
Release 1.2.2
sergiupuhalschi-rdx Feb 20, 2025
9ad682b
Review comments
sergiupuhalschi-rdx Feb 20, 2025
5ca9092
Review comments
sergiupuhalschi-rdx Feb 20, 2025
9df9ba4
Improve API
sergiupuhalschi-rdx Feb 20, 2025
7e9c279
Improve API
sergiupuhalschi-rdx Feb 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions crates/core/error/src/common_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,12 @@ pub enum CommonError {
EntityIsNotControlledByAnAccessControllerOnLedger {
entity_bech32m_encoded_address: String,
} = 10265,

#[error("Invalid mnemonic words")]
InvalidMnemonicWords { indices_in_mnemonic: Vec<usize> } = 10266,

#[error("Factor source already exists")]
FactorSourceAlreadyExists = 10267,
}

impl CommonError {
Expand Down
62 changes: 60 additions & 2 deletions crates/factors/factors/src/factor_source.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::cmp::Ordering;

use crate::prelude::*;
use host_info::prelude::HostInfo;
use short_string::prelude::DisplayName;
use std::cmp::Ordering;

#[allow(clippy::large_enum_variant)]
#[derive(
Expand Down Expand Up @@ -155,6 +156,63 @@
}
}

impl FactorSource {
pub fn with_details(
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is mostly constrained by mnemonic_with_passphrase, so I would add an its name the mention of MWP, to know this applies only to the kinds of factor sources which have their id derived from MWP.

factor_source_kind: FactorSourceKind,
mnemonic_with_passphrase: MnemonicWithPassphrase,
name: String,
host_info: HostInfo,
) -> Result<Self> {
let display_name = DisplayName::new(name)?;
let id_from_hash =

Check warning on line 167 in crates/factors/factors/src/factor_source.rs

View check run for this annotation

Codecov / codecov/patch

crates/factors/factors/src/factor_source.rs#L167

Added line #L167 was not covered by tests
FactorSourceIDFromHash::from_mnemonic_with_passphrase(
factor_source_kind,
&mnemonic_with_passphrase,

Check warning on line 170 in crates/factors/factors/src/factor_source.rs

View check run for this annotation

Codecov / codecov/patch

crates/factors/factors/src/factor_source.rs#L169-L170

Added lines #L169 - L170 were not covered by tests
);

match factor_source_kind {

Check warning on line 173 in crates/factors/factors/src/factor_source.rs

View check run for this annotation

Codecov / codecov/patch

crates/factors/factors/src/factor_source.rs#L173

Added line #L173 was not covered by tests
FactorSourceKind::Device => {
let is_main = false;
let hint = DeviceFactorSourceHint::with_info_and_label(
&host_info,
mnemonic_with_passphrase.mnemonic.word_count,
display_name.value(),
);
Ok(FactorSource::from(DeviceFactorSource::babylon_with_hint(
is_main,
id_from_hash,
hint,
)))
}
FactorSourceKind::OffDeviceMnemonic => {
let hint = OffDeviceMnemonicHint::new(
display_name,
mnemonic_with_passphrase.mnemonic.word_count,
);
Ok(FactorSource::from(OffDeviceMnemonicFactorSource::new(
id_from_hash,
hint,
)))
}
FactorSourceKind::Password => {
let hint = PasswordFactorSourceHint::new(display_name.value());
Ok(FactorSource::from(PasswordFactorSource::new(
id_from_hash,
hint,
)))
}
FactorSourceKind::LedgerHQHardwareWallet
| FactorSourceKind::ArculusCard
| FactorSourceKind::SecurityQuestions
| FactorSourceKind::TrustedContact => {
Err(CommonError::InvalidFactorSourceKind {
bad_value: factor_source_kind.to_string(),
})
}
}
}
}

impl PartialOrd for FactorSource {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ impl DeviceFactorSource {
host_info,
mnemonic_with_passphrase.mnemonic.word_count,
);
Self::babylon_with_hint(is_main, id, hint)
}

pub fn babylon_with_hint(
is_main: bool,
id: FactorSourceIDFromHash,
hint: DeviceFactorSourceHint,
) -> Self {
Self::new(id, FactorSourceCommon::new_bdfs(is_main), hint)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,17 @@ impl DeviceFactorSourceHint {
}

pub fn with_info(host_info: &HostInfo, word_count: BIP39WordCount) -> Self {
Self::with_info_and_label(host_info, word_count, label_default())
}

pub fn with_info_and_label(
host_info: &HostInfo,
word_count: BIP39WordCount,
label: impl AsRef<str>,
) -> Self {
let description = host_info.description.clone();
Self::new(
label_default(),
label,
description.name,
description.model,
host_info.host_os.version(),
Expand Down
1 change: 1 addition & 0 deletions crates/system/os/factors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ log = { workspace = true }
paste = { workspace = true }
preinterpret = { workspace = true }
pretty_assertions = { workspace = true }
rand = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
serde_with = { workspace = true }
Expand Down
Loading
Loading