bitbox02_rust: drop workflow::transaction::UserAbort for hal::ui::UserAbort
What changed, and why it matters
This commit is a straightforward internal code cleanup. It replaces one definition of a user-cancellation error type with another identical one so that a hardware abstraction layer can be moved to its own crate. There is no change to user-facing behavior, security logic, or how transaction approvals and rejections are handled.
No security action required. Review as normal code-quality refactor if desired.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch removes workflow::transaction::UserAbort and uses hal::ui::UserAbort everywhere in the UI/hardware abstraction layer. It updates trait signatures in hal/ui.rs, implementations in hal/bitbox02/ui.rs and hal/testing/ui.rs, removes a redundant From conversion in hww/api/error.rs, and simplifies error propagation in workflow/transaction.rs. The change is purely structural refactoring with no functional difference.
Changed components
src/rust/bitbox02-rust/src/hal/bitbox02/ui.rssrc/rust/bitbox02-rust/src/hal/testing/ui.rssrc/rust/bitbox02-rust/src/hal/ui.rssrc/rust/bitbox02-rust/src/hww/api/error.rssrc/rust/bitbox02-rust/src/workflow/transaction.rsInspect captured patch +16 / −40
diff --git a/src/rust/bitbox02-rust/src/hal/bitbox02/ui.rs b/src/rust/bitbox02-rust/src/hal/bitbox02/ui.rs
index bea6293..23364df 100644
--- a/src/rust/bitbox02-rust/src/hal/bitbox02/ui.rs
+++ b/src/rust/bitbox02-rust/src/hal/bitbox02/ui.rs
@@ -4,7 +4,7 @@ use alloc::string::String;
use crate::hal::Ui;
use crate::hal::ui::UserAbort;
-use crate::workflow::{cancel, confirm, sdcard, transaction, trinary_input_string};
+use crate::workflow::{cancel, confirm, sdcard, trinary_input_string};
pub struct BitBox02Ui;
@@ -18,14 +18,10 @@ impl Ui for BitBox02Ui {
}
#[inline(always)]
- async fn verify_recipient(
- &mut self,
- recipient: &str,
- amount: &str,
- ) -> Result<(), transaction::UserAbort> {
+ async fn verify_recipient(&mut self, recipient: &str, amount: &str) -> Result<(), UserAbort> {
match bitbox02::ui::confirm_transaction_address(amount, recipient).await {
bitbox02::ui::ConfirmResponse::Approved => Ok(()),
- bitbox02::ui::ConfirmResponse::Cancelled => Err(transaction::UserAbort),
+ bitbox02::ui::ConfirmResponse::Cancelled => Err(UserAbort),
}
}
@@ -35,10 +31,10 @@ impl Ui for BitBox02Ui {
total: &str,
fee: &str,
longtouch: bool,
- ) -> Result<(), transaction::UserAbort> {
+ ) -> Result<(), UserAbort> {
match bitbox02::ui::confirm_transaction_fee(total, fee, longtouch).await {
bitbox02::ui::ConfirmResponse::Approved => Ok(()),
- bitbox02::ui::ConfirmResponse::Cancelled => Err(transaction::UserAbort),
+ bitbox02::ui::ConfirmResponse::Cancelled => Err(UserAbort),
}
}
diff --git a/src/rust/bitbox02-rust/src/hal/testing/ui.rs b/src/rust/bitbox02-rust/src/hal/testing/ui.rs
index 3310ff9..f1f079d 100644
--- a/src/rust/bitbox02-rust/src/hal/testing/ui.rs
+++ b/src/rust/bitbox02-rust/src/hal/testing/ui.rs
@@ -2,7 +2,7 @@
use crate::hal::Ui;
use crate::hal::ui::UserAbort;
-use crate::workflow::{cancel, confirm, sdcard, transaction, trinary_input_string};
+use crate::workflow::{cancel, confirm, sdcard, trinary_input_string};
use alloc::boxed::Box;
use alloc::string::String;
@@ -64,11 +64,7 @@ impl Ui for TestingUi<'_> {
Ok(())
}
- async fn verify_recipient(
- &mut self,
- recipient: &str,
- amount: &str,
- ) -> Result<(), transaction::UserAbort> {
+ async fn verify_recipient(&mut self, recipient: &str, amount: &str) -> Result<(), UserAbort> {
self.screens.push(Screen::Recipient {
recipient: recipient.into(),
amount: amount.into(),
@@ -78,7 +74,7 @@ impl Ui for TestingUi<'_> {
.as_ref()
.is_some_and(|&n| self.screens.len() - 1 == n)
{
- return Err(transaction::UserAbort);
+ return Err(UserAbort);
}
Ok(())
}
@@ -88,7 +84,7 @@ impl Ui for TestingUi<'_> {
total: &str,
fee: &str,
longtouch: bool,
- ) -> Result<(), transaction::UserAbort> {
+ ) -> Result<(), UserAbort> {
self.screens.push(Screen::TotalFee {
total: total.into(),
fee: fee.into(),
@@ -99,7 +95,7 @@ impl Ui for TestingUi<'_> {
.as_ref()
.is_some_and(|&n| self.screens.len() - 1 == n)
{
- return Err(transaction::UserAbort);
+ return Err(UserAbort);
}
Ok(())
}
diff --git a/src/rust/bitbox02-rust/src/hal/ui.rs b/src/rust/bitbox02-rust/src/hal/ui.rs
index 0b3b923..31f8c0d 100644
--- a/src/rust/bitbox02-rust/src/hal/ui.rs
+++ b/src/rust/bitbox02-rust/src/hal/ui.rs
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
-use crate::workflow::{cancel, confirm, mnemonic, sdcard, transaction, trinary_input_string};
+use crate::workflow::{cancel, confirm, mnemonic, sdcard, trinary_input_string};
use alloc::string::String;
@@ -11,18 +11,14 @@ pub trait Ui {
/// Returns `Ok(())` if the user accepts, `Err(UserAbort)` if the user rejects.
async fn confirm(&mut self, params: &confirm::Params<'_>) -> Result<(), UserAbort>;
- async fn verify_recipient(
- &mut self,
- recipient: &str,
- amount: &str,
- ) -> Result<(), transaction::UserAbort>;
+ async fn verify_recipient(&mut self, recipient: &str, amount: &str) -> Result<(), UserAbort>;
async fn verify_total_fee(
&mut self,
total: &str,
fee: &str,
longtouch: bool,
- ) -> Result<(), transaction::UserAbort>;
+ ) -> Result<(), UserAbort>;
async fn status(&mut self, title: &str, status_success: bool);
diff --git a/src/rust/bitbox02-rust/src/hww/api/error.rs b/src/rust/bitbox02-rust/src/hww/api/error.rs
index 195cead..5deaa3a 100644
--- a/src/rust/bitbox02-rust/src/hww/api/error.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/error.rs
@@ -68,12 +68,6 @@ impl core::convert::From<crate::hal::ui::UserAbort> for Error {
}
}
-impl core::convert::From<crate::workflow::transaction::UserAbort> for Error {
- fn from(_error: crate::workflow::transaction::UserAbort) -> Self {
- Error::UserAbort
- }
-}
-
impl core::convert::From<crate::workflow::sdcard::UserAbort> for Error {
fn from(_error: crate::workflow::sdcard::UserAbort) -> Self {
Error::UserAbort
diff --git a/src/rust/bitbox02-rust/src/workflow/transaction.rs b/src/rust/bitbox02-rust/src/workflow/transaction.rs
index 2c40c39..282654f 100644
--- a/src/rust/bitbox02-rust/src/workflow/transaction.rs
+++ b/src/rust/bitbox02-rust/src/workflow/transaction.rs
@@ -1,11 +1,10 @@
// SPDX-License-Identifier: Apache-2.0
use crate::hal::Ui;
+use crate::hal::ui::UserAbort;
use alloc::string::String;
-pub struct UserAbort;
-
fn format_percentage(p: f64) -> String {
let int: u64 = num_traits::float::FloatCore::round(p * 10.) as _;
util::decimal::format_no_trim(int, 1)
@@ -23,8 +22,7 @@ pub async fn verify_total_fee_maybe_warn(
hal.ui().verify_total_fee(total, fee, longtouch).await?;
if let Some(fee_percentage) = fee_percentage {
- match hal
- .ui()
+ hal.ui()
.confirm(&super::confirm::Params {
title: "High fee",
body: &format!(
@@ -34,11 +32,7 @@ pub async fn verify_total_fee_maybe_warn(
longtouch: true,
..Default::default()
})
- .await
- {
- Ok(()) => (),
- Err(crate::hal::ui::UserAbort) => return Err(UserAbort),
- }
+ .await?;
}
Ok(())
}
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.