workflows: use HAL for showing mnemonic and mnemonic quiz
What changed, and why it matters
This commit is a straightforward internal refactoring of how the BitBox02 wallet shows the recovery seed phrase and its confirmation quiz. It routes those screens through a hardware abstraction layer (HAL) so the same code can be tested with fake/mock hardware and reused on future devices. There is no user-facing behavior change and no security fix or vulnerability present in the diff.
No security action required. Treat as normal code-review/merge for refactoring and testability.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change adds two async methods to the Workflows trait (show_mnemonic, quiz_mnemonic_word) and implements them in RealWorkflows by delegating to the existing mnemonic::show_mnemonic and mnemonic::confirm_word functions. show_and_confirm_mnemonic is updated to call these methods through hal.ui() instead of invoking the concrete functions directly. Visibility of the concrete functions is widened from private to public so the trait implementation can call them. Test implementations (TestingWorkflows, C unit-test stubs) are extended with stub/todo implementations. No logic, cryptography, or UI text is altered.
Changed components
src/rust/bitbox02-rust/src/workflow.rssrc/rust/bitbox02-rust/src/workflow/mnemonic.rssrc/rust/bitbox02-rust/src/workflow/mnemonic_c_unit_tests.rssrc/rust/bitbox02-rust/src/workflow/testing.rsInspect captured patch +51 / −6
diff --git a/src/rust/bitbox02-rust/src/workflow.rs b/src/rust/bitbox02-rust/src/workflow.rs
index 826441b..9901e49 100644
--- a/src/rust/bitbox02-rust/src/workflow.rs
+++ b/src/rust/bitbox02-rust/src/workflow.rs
@@ -68,6 +68,17 @@ pub trait Workflows {
label_middle: Option<&str>,
label_right: Option<&str>,
) -> trinary_choice::TrinaryChoice;
+
+ /// Display the BIP39 mnemonic to the user.
+ async fn show_mnemonic(&mut self, words: &[&str]) -> Result<(), cancel::Error>;
+
+ /// Display these BIP39 mnemonic word choices to the user as part of the quiz to confirm the
+ /// user backuped up the mnemonic correctly.
+ async fn quiz_mnemonic_word(
+ &mut self,
+ choices: &[&str],
+ title: &str,
+ ) -> Result<u8, cancel::Error>;
}
pub struct RealWorkflows;
@@ -132,4 +143,16 @@ impl Workflows for RealWorkflows {
) -> trinary_choice::TrinaryChoice {
trinary_choice::choose(message, label_left, label_middle, label_right).await
}
+
+ async fn show_mnemonic(&mut self, words: &[&str]) -> Result<(), cancel::Error> {
+ mnemonic::show_mnemonic(words).await
+ }
+
+ async fn quiz_mnemonic_word(
+ &mut self,
+ choices: &[&str],
+ title: &str,
+ ) -> Result<u8, cancel::Error> {
+ mnemonic::confirm_word(choices, title).await
+ }
}
diff --git a/src/rust/bitbox02-rust/src/workflow/mnemonic.rs b/src/rust/bitbox02-rust/src/workflow/mnemonic.rs
index aee6807..7835bbb 100644
--- a/src/rust/bitbox02-rust/src/workflow/mnemonic.rs
+++ b/src/rust/bitbox02-rust/src/workflow/mnemonic.rs
@@ -77,7 +77,7 @@ fn create_random_unique_words(word: &str, length: u8) -> (u8, Vec<zeroize::Zeroi
}
/// Displays all mnemonic words in a scroll-through screen.
-async fn show_mnemonic(words: &[&str]) -> Result<(), CancelError> {
+pub async fn show_mnemonic(words: &[&str]) -> Result<(), CancelError> {
let result = RefCell::new(None);
let mut component = bitbox02::ui::menu_create(bitbox02::ui::MenuParams {
words,
@@ -94,7 +94,7 @@ async fn show_mnemonic(words: &[&str]) -> Result<(), CancelError> {
}
/// Displays the `choices` to the user, returning the index of the selected choice.
-async fn confirm_word(choices: &[&str], title: &str) -> Result<u8, CancelError> {
+pub async fn confirm_word(choices: &[&str], title: &str) -> Result<u8, CancelError> {
let result = RefCell::new(None);
let mut component = bitbox02::ui::menu_create(bitbox02::ui::MenuParams {
words: choices,
@@ -125,7 +125,7 @@ pub async fn show_and_confirm_mnemonic(
.map_err(|_| CancelError::Cancelled)?;
// Part 1) Scroll through words
- show_mnemonic(words).await?;
+ hal.ui().show_mnemonic(words).await?;
// Can only succeed due to `accept_only`.
let _ = hal
@@ -147,9 +147,9 @@ pub async fn show_and_confirm_mnemonic(
choices.push("Back to\nrecovery words");
let back_idx = (choices.len() - 1) as u8;
loop {
- match confirm_word(&choices, &title).await? {
+ match hal.ui().quiz_mnemonic_word(&choices, &title).await? {
selected_idx if selected_idx == correct_idx => break,
- selected_idx if selected_idx == back_idx => show_mnemonic(words).await?,
+ selected_idx if selected_idx == back_idx => hal.ui().show_mnemonic(words).await?,
_ => hal.ui().status("Incorrect word\nTry again", false).await,
}
}
diff --git a/src/rust/bitbox02-rust/src/workflow/mnemonic_c_unit_tests.rs b/src/rust/bitbox02-rust/src/workflow/mnemonic_c_unit_tests.rs
index e40412f..6fd74e6 100644
--- a/src/rust/bitbox02-rust/src/workflow/mnemonic_c_unit_tests.rs
+++ b/src/rust/bitbox02-rust/src/workflow/mnemonic_c_unit_tests.rs
@@ -17,6 +17,14 @@ pub use super::cancel::Error as CancelError;
use alloc::string::String;
use alloc::string::ToString;
+pub async fn show_mnemonic(_words: &[&str]) -> Result<(), CancelError> {
+ panic!("unused")
+}
+
+pub async fn confirm_word(_choices: &[&str], _title: &str) -> Result<u8, CancelError> {
+ panic!("unused")
+}
+
pub async fn show_and_confirm_mnemonic(
_hal: &mut impl crate::hal::Hal,
words: &[&str],
diff --git a/src/rust/bitbox02-rust/src/workflow/testing.rs b/src/rust/bitbox02-rust/src/workflow/testing.rs
index 13c5dc7..07d1b80 100644
--- a/src/rust/bitbox02-rust/src/workflow/testing.rs
+++ b/src/rust/bitbox02-rust/src/workflow/testing.rs
@@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-use super::{Workflows, confirm, menu, sdcard, transaction, trinary_choice, trinary_input_string};
+use super::{
+ Workflows, cancel, confirm, menu, sdcard, transaction, trinary_choice, trinary_input_string,
+};
use alloc::boxed::Box;
use alloc::string::String;
@@ -155,6 +157,18 @@ impl Workflows for TestingWorkflows<'_> {
) -> trinary_choice::TrinaryChoice {
todo!("not used in unit tests yet");
}
+
+ async fn show_mnemonic(&mut self, _words: &[&str]) -> Result<(), cancel::Error> {
+ todo!("not used in unit tests yet");
+ }
+
+ async fn quiz_mnemonic_word(
+ &mut self,
+ _choices: &[&str],
+ _title: &str,
+ ) -> Result<u8, cancel::Error> {
+ todo!("not used in unit tests yet");
+ }
}
impl<'a> TestingWorkflows<'a> {
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.