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

feat: ledger stax + flex support #6588

Merged
merged 8 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub enum AppSW {
MetadataSignatureFail = 0xB00D,
WrongApduLength = 0x6e03, // See ledger-device-rust-sdk/ledger_device_sdk/src/io.rs:16
UserCancelled = 0x6e04, // See ledger-device-rust-sdk/ledger_device_sdk/src/io.rs:16
Ok = 0x9000,
}

impl TryFrom<u16> for AppSW {
Expand All @@ -46,6 +47,7 @@ impl TryFrom<u16> for AppSW {
0xB00D => Ok(AppSW::MetadataSignatureFail),
0x6e03 => Ok(AppSW::WrongApduLength),
0x6e04 => Ok(AppSW::UserCancelled),
0x9000 => Ok(AppSW::Ok),
_ => Err(String::from("Invalid value for AppSW (") + utils::u16_to_string(value).as_str() + ")"),
}
}
Expand Down Expand Up @@ -153,6 +155,7 @@ mod test {
(0xB00D, AppSW::MetadataSignatureFail),
(0x6e03, AppSW::WrongApduLength),
(0x6e04, AppSW::UserCancelled),
(0x9000, AppSW::Ok),
];

for (value, expected_app_sw) in &mappings {
Expand Down Expand Up @@ -202,6 +205,9 @@ mod test {
AppSW::UserCancelled => {
assert_eq!(AppSW::try_from(*value).unwrap(), *expected_app_sw);
},
AppSW::Ok => {
assert_eq!(AppSW::try_from(*value).unwrap(), *expected_app_sw);
},
}
}
}
Expand Down
16 changes: 9 additions & 7 deletions applications/minotari_ledger_wallet/wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ minotari_ledger_wallet_common = { path = "../common" }

blake2 = { version = "0.10", default-features = false }
borsh = { version = "1.2", default-features = false }
critical-section = { version = "1.1.1" }
digest = { version = "0.10", default-features = false }
embedded-alloc = "0.5.0"
include_gif = "1.0.1"
ledger_device_sdk = "1.7"
ledger_device_sdk = "1.15"
rand_core = { version = "0.6", default_features = false }
zeroize = { version = "1", default-features = false }

Expand All @@ -32,8 +30,8 @@ once_cell = { version = "=1.18.0", default-features = false }
ignored = ["once_cell"]

[profile.release]
opt-level = 's'
lto = "fat" # same as `true`
opt-level = 'z'
lto = true
panic = "abort"

[features]
Expand All @@ -46,13 +44,17 @@ flags = "0"
path = ["44'/535348'"]
name = "MinoTari Wallet"

[package.metadata.ledger.nanos]
icon = "key.gif"

[package.metadata.ledger.nanox]
icon = "key_14x14.gif"

[package.metadata.ledger.nanosplus]
icon = "key_14x14.gif"

[package.metadata.ledger.stax]
icon = "key_32x32.gif"

[package.metadata.ledger.flex]
icon = "key_40x40.gif"

[workspace]
1 change: 1 addition & 0 deletions applications/minotari_ledger_wallet/wallet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ ledgerctl install app_nanosplus.json
```
```
ledgerctl install .\target\nanosplus\release\app_nanosplus.json
ledgerctl install .\target\stax\release\app_stax.json
```

**Notes for Windows users:**
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion applications/minotari_ledger_wallet/wallet/ledger_app.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[app]
build_directory = "./"
sdk = "Rust"
devices = ["nanos", "nanox", "nanos+"]
devices = ["nanox", "nanos+", "stax", "flex"]
29 changes: 23 additions & 6 deletions applications/minotari_ledger_wallet/wallet/src/app_ui/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
// SPDX-License-Identifier: BSD-3-Clause

use include_gif::include_gif;
use ledger_device_sdk::{
io::{Comm, Event},
ui::{
bitmaps::{Glyph, BACK, CERTIFICATE, DASHBOARD_X},
gadgets::{EventOrPageIndex, MultiPageMenu, Page},
},
use ledger_device_sdk::io::Comm;
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
use ledger_device_sdk::io::Event;
#[cfg(any(target_os = "stax", target_os = "flex"))]
use ledger_device_sdk::nbgl::{NbglGlyph, NbglHomeAndSettings};
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
use ledger_device_sdk::ui::{
bitmaps::{Glyph, BACK, CERTIFICATE, DASHBOARD_X},
gadgets::{EventOrPageIndex, MultiPageMenu, Page},
};

#[cfg(not(any(target_os = "stax", target_os = "flex")))]
use crate::Instruction;

#[cfg(not(any(target_os = "stax", target_os = "flex")))]
fn ui_about_menu(comm: &mut Comm) -> Event<Instruction> {
let pages = [
&Page::from((["MinoTari Wallet", "(c) 2024 The Tari Project"], true)),
Expand All @@ -26,6 +31,7 @@ fn ui_about_menu(comm: &mut Comm) -> Event<Instruction> {
}
}

#[cfg(not(any(target_os = "stax", target_os = "flex")))]
pub fn ui_menu_main(comm: &mut Comm) -> Event<Instruction> {
const APP_ICON: Glyph = Glyph::from_include(include_gif!("key.gif"));
let pages = [
Expand All @@ -45,3 +51,14 @@ pub fn ui_menu_main(comm: &mut Comm) -> Event<Instruction> {
}
}
}

#[cfg(any(target_os = "stax", target_os = "flex"))]
pub fn ui_menu_main(_: &mut Comm) -> NbglHomeAndSettings {
// Load glyph from 64x64 4bpp gif file with include_gif macro. Creates an NBGL compatible glyph.
const FERRIS: NbglGlyph = NbglGlyph::from_include(include_gif!("key_64x64.gif", NBGL));
SWvheerden marked this conversation as resolved.
Show resolved Hide resolved

// Display the home screen.
NbglHomeAndSettings::new()
.glyph(&FERRIS)
SWvheerden marked this conversation as resolved.
Show resolved Hide resolved
.infos("MinoTari Wallet", env!("CARGO_PKG_VERSION"), "The Tari Project")
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

use core::ops::Deref;

use ledger_device_sdk::{io::Comm, ui::gadgets::SingleMessage};
use ledger_device_sdk::io::Comm;
#[cfg(any(target_os = "stax", target_os = "flex"))]
use ledger_device_sdk::nbgl::NbglStatus;
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
use ledger_device_sdk::ui::gadgets::SingleMessage;
use tari_crypto::{ristretto::RistrettoPublicKey, tari_utilities::ByteArray};
use zeroize::Zeroizing;

Expand All @@ -17,7 +21,15 @@ use crate::{
pub fn handler_get_dh_shared_secret(comm: &mut Comm) -> Result<(), AppSW> {
let data = comm.get_data().map_err(|_| AppSW::WrongApduLength)?;
if data.len() != 56 {
SingleMessage::new("Invalid data length").show_and_wait();
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
{
SingleMessage::new("Invalid data length").show_and_wait();
}
#[cfg(any(target_os = "stax", target_os = "flex"))]
{
NbglStatus::new().text(&"Invalid data length").show(false);
}

return Err(AppSW::WrongApduLength);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ use digest::{
consts::{U32, U64},
Digest,
};
use ledger_device_sdk::{
io::Comm,
ui::{
bitmaps::{CROSSMARK, EYE, VALIDATE_14},
gadgets::{Field, MultiFieldReview, SingleMessage},
},
#[cfg(any(target_os = "stax", target_os = "flex"))]
use include_gif::include_gif;
use ledger_device_sdk::io::Comm;
#[cfg(any(target_os = "stax", target_os = "flex"))]
use ledger_device_sdk::nbgl::{Field, NbglGlyph, NbglReview, NbglStatus};
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
use ledger_device_sdk::ui::{
bitmaps::{CROSSMARK, EYE, VALIDATE_14},
gadgets::{Field, MultiFieldReview, SingleMessage},
};
use minotari_ledger_wallet_common::{
get_public_spend_key_bytes_from_tari_dual_address,
Expand Down Expand Up @@ -77,7 +80,16 @@ pub fn handler_get_one_sided_metadata_signature(comm: &mut Comm) -> Result<(), A
let receiver_address = match tari_dual_address_display(&receiver_address_bytes) {
Ok(address) => address,
Err(e) => {
SingleMessage::new(&format!("Error: {:?}", e.to_string())).show_and_wait();
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
{
SingleMessage::new(&format!("Error: {:?}", e.to_string())).show_and_wait();
}
#[cfg(any(target_os = "stax", target_os = "flex"))]
{
NbglStatus::new()
.text(&format!("Error: {:?}", e.to_string()))
.show(false);
}
return Err(AppSW::MetadataSignatureFail);
},
};
Expand All @@ -95,17 +107,35 @@ pub fn handler_get_one_sided_metadata_signature(comm: &mut Comm) -> Result<(), A
value: &format!("{}", receiver_address),
},
];
let review = MultiFieldReview::new(
&fields,
&["Review ", "Transaction"],
Some(&EYE),
"Approve",
Some(&VALIDATE_14),
"Reject",
Some(&CROSSMARK),
);
if !review.show() {
return Err(AppSW::UserCancelled);
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
{
let review = MultiFieldReview::new(
&fields,
&["Review ", "Transaction"],
Some(&EYE),
"Approve",
Some(&VALIDATE_14),
"Reject",
Some(&CROSSMARK),
);
if !review.show() {
return Err(AppSW::UserCancelled);
}
}
#[cfg(any(target_os = "stax", target_os = "flex"))]
{
// Load glyph from 64x64 4bpp gif file with include_gif macro. Creates an NBGL compatible glyph.
const FERRIS: NbglGlyph = NbglGlyph::from_include(include_gif!("key_64x64.gif", NBGL));
Copy link
Contributor

Choose a reason for hiding this comment

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

Same with FERRIS

What's an NBGL campatible glyph anyway? What's NBGL?

// Create NBGL review. Maximum number of fields and string buffer length can be customised
// with constant generic parameters of NbglReview. Default values are 32 and 1024 respectively.
let review: NbglReview = NbglReview::new()
.titles("Review transaction\nto send", "", "Sign transaction\nto send")
.glyph(&FERRIS);

//
if !review.show(&fields[0..2]) {
return Err(AppSW::UserCancelled);
}
}

let value_as_private_key: RistrettoSecretKey = value_u64.into();
Expand All @@ -128,7 +158,16 @@ pub fn handler_get_one_sided_metadata_signature(comm: &mut Comm) -> Result<(), A
match get_public_spend_key_bytes_from_tari_dual_address(&receiver_address_bytes) {
Ok(bytes) => get_key_from_canonical_bytes::<RistrettoPublicKey>(&bytes)?,
Err(e) => {
SingleMessage::new(&format!("Error: {:?}", e.to_string())).show_and_wait();
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
{
SingleMessage::new(&format!("Error: {:?}", e.to_string())).show_and_wait();
}
#[cfg(any(target_os = "stax", target_os = "flex"))]
{
NbglStatus::new()
.text(&format!("Error: {:?}", e.to_string()))
.show(false);
}
return Err(AppSW::MetadataSignatureFail);
},
};
Expand Down Expand Up @@ -159,7 +198,16 @@ pub fn handler_get_one_sided_metadata_signature(comm: &mut Comm) -> Result<(), A
) {
Ok(sig) => sig,
Err(e) => {
SingleMessage::new(&format!("Signing error: {:?}", e.to_string())).show_and_wait();
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
{
SingleMessage::new(&format!("Signing error: {:?}", e.to_string())).show_and_wait();
}
#[cfg(any(target_os = "stax", target_os = "flex"))]
{
NbglStatus::new()
.text(&format!("Signing error: {:?}", e.to_string()))
.show(false);
}
return Err(AppSW::MetadataSignatureFail);
},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
// Copyright 2024 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

use ledger_device_sdk::{io::Comm, ui::gadgets::SingleMessage};
use ledger_device_sdk::io::Comm;
#[cfg(any(target_os = "stax", target_os = "flex"))]
use ledger_device_sdk::nbgl::NbglStatus;
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
use ledger_device_sdk::ui::gadgets::SingleMessage;
use tari_crypto::{keys::PublicKey, ristretto::RistrettoPublicKey, tari_utilities::ByteArray};

use crate::{utils::derive_from_bip32_key, AppSW, KeyType, RESPONSE_VERSION};

pub fn handler_get_public_key(comm: &mut Comm) -> Result<(), AppSW> {
let data = comm.get_data().map_err(|_| AppSW::WrongApduLength)?;
if data.len() != 24 {
SingleMessage::new("Invalid data length").show_and_wait();
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
{
SingleMessage::new("Invalid data length").show_and_wait();
}
#[cfg(any(target_os = "stax", target_os = "flex"))]
{
NbglStatus::new().text(&"Invalid data length").show(false);
}
return Err(AppSW::WrongApduLength);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
// Copyright 2024 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

use ledger_device_sdk::{io::Comm, ui::gadgets::SingleMessage};
use ledger_device_sdk::io::Comm;
#[cfg(any(target_os = "stax", target_os = "flex"))]
use ledger_device_sdk::nbgl::NbglStatus;
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
use ledger_device_sdk::ui::gadgets::SingleMessage;
use tari_crypto::{keys::PublicKey, ristretto::RistrettoPublicKey, tari_utilities::ByteArray};

use crate::{utils::derive_from_bip32_key, AppSW, KeyType, RESPONSE_VERSION, STATIC_SPEND_INDEX};

pub fn handler_get_public_spend_key(comm: &mut Comm) -> Result<(), AppSW> {
let data = comm.get_data().map_err(|_| AppSW::WrongApduLength)?;
if data.len() != 8 {
SingleMessage::new("Invalid data length").show_and_wait();
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
{
SingleMessage::new("Invalid data length").show_and_wait();
}
#[cfg(any(target_os = "stax", target_os = "flex"))]
{
NbglStatus::new().text(&"Invalid data length").show(false);
}
return Err(AppSW::WrongApduLength);
}

Expand Down
Loading
Loading