Skip to content

Commit 70b5663

Browse files
authored
Merge pull request #114 from LedgerHQ/y333/nanos_nbgl_migration
Build Nano* version with NBGL
2 parents 97f0ae4 + 1bba463 commit 70b5663

File tree

75 files changed

+140
-299
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+140
-299
lines changed

Cargo.lock

Lines changed: 86 additions & 118 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[package]
22
name = "app-boilerplate-rust"
3-
version = "1.6.3"
4-
authors = ["yhql", "agrojean-ledger"]
3+
version = "1.7.0"
4+
authors = ["Ledger"]
55
edition = "2021"
66

77
[dependencies]
8-
ledger_device_sdk = "1.20.3"
8+
ledger_device_sdk = "1.21.0"
99
include_gif = "1.2.0"
1010
serde = { version="1.0.192", default-features = false, features = ["derive"] }
1111
serde-json-core = { git = "https://github.com/rust-embedded-community/serde-json-core" }
@@ -17,8 +17,8 @@ opt-level = 'z'
1717
lto = true
1818

1919
[features]
20-
default = ["pending_review_screen"]
21-
pending_review_screen = []
20+
default = ["ledger_device_sdk/nbgl"]
21+
debug = ["ledger_device_sdk/debug"]
2222

2323
[package.metadata.ledger]
2424
curve = ["secp256k1"]
@@ -39,4 +39,4 @@ icon = "crab_32x32.gif"
3939
icon = "crab_40x40.gif"
4040

4141
[lints.rust]
42-
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("stax", "flex", "nanos", "nanox", "nanosplus"))'] }
42+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(target_os, values("stax", "flex", "nanos", "nanox", "nanosplus"))'] }

crab.gif renamed to crab_16x16.gif

File renamed without changes.

src/app_ui/address.rs

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,8 @@
1818
use crate::AppSW;
1919
use alloc::format;
2020

21-
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
22-
use ledger_device_sdk::ui::{
23-
bitmaps::{CROSSMARK, EYE, VALIDATE_14},
24-
gadgets::{Field, MultiFieldReview},
25-
};
26-
27-
#[cfg(any(target_os = "stax", target_os = "flex"))]
28-
use ledger_device_sdk::nbgl::{NbglAddressReview, NbglGlyph};
29-
30-
#[cfg(any(target_os = "stax", target_os = "flex"))]
3121
use include_gif::include_gif;
22+
use ledger_device_sdk::nbgl::{NbglAddressReview, NbglGlyph};
3223

3324
// Display only the last 20 bytes of the address
3425
const DISPLAY_ADDR_BYTES_LEN: usize = 20;
@@ -39,34 +30,15 @@ pub fn ui_display_pk(addr: &[u8]) -> Result<bool, AppSW> {
3930
hex::encode(&addr[addr.len() - DISPLAY_ADDR_BYTES_LEN..]).to_uppercase()
4031
);
4132

42-
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
43-
{
44-
let my_field = [Field {
45-
name: "Address",
46-
value: addr_hex.as_str(),
47-
}];
48-
49-
let my_review = MultiFieldReview::new(
50-
&my_field,
51-
&["Confirm Address"],
52-
Some(&EYE),
53-
"Approve",
54-
Some(&VALIDATE_14),
55-
"Reject",
56-
Some(&CROSSMARK),
57-
);
58-
59-
Ok(my_review.show())
60-
}
61-
33+
// Load glyph from 64x64 4bpp gif file with include_gif macro. Creates an NBGL compatible glyph.
6234
#[cfg(any(target_os = "stax", target_os = "flex"))]
63-
{
64-
// Load glyph from 64x64 4bpp gif file with include_gif macro. Creates an NBGL compatible glyph.
65-
const FERRIS: NbglGlyph = NbglGlyph::from_include(include_gif!("crab_64x64.gif", NBGL));
66-
// Display the address confirmation screen.
67-
Ok(NbglAddressReview::new()
68-
.glyph(&FERRIS)
69-
.verify_str("Verify CRAB address")
70-
.show(&addr_hex))
71-
}
35+
const FERRIS: NbglGlyph = NbglGlyph::from_include(include_gif!("crab_64x64.gif", NBGL));
36+
#[cfg(any(target_os = "nanosplus", target_os = "nanox"))]
37+
const FERRIS: NbglGlyph = NbglGlyph::from_include(include_gif!("crab_16x16.gif", NBGL));
38+
39+
// Display the address confirmation screen.
40+
Ok(NbglAddressReview::new()
41+
.glyph(&FERRIS)
42+
.verify_str("Verify CRAB address")
43+
.show(&addr_hex))
7244
}

src/app_ui/menu.rs

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,64 +18,15 @@
1818
use include_gif::include_gif;
1919
use ledger_device_sdk::io::Comm;
2020

21-
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
22-
use ledger_device_sdk::ui::{
23-
bitmaps::{Glyph, BACK, CERTIFICATE, DASHBOARD_X},
24-
gadgets::{EventOrPageIndex, MultiPageMenu, Page},
25-
};
26-
27-
#[cfg(any(target_os = "stax", target_os = "flex"))]
2821
use crate::settings::Settings;
29-
#[cfg(any(target_os = "stax", target_os = "flex"))]
3022
use ledger_device_sdk::nbgl::{NbglGlyph, NbglHomeAndSettings};
3123

32-
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
33-
use crate::Instruction;
34-
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
35-
use ledger_device_sdk::io::Event;
36-
37-
// use ledger_device_sdk::nvm::*;
38-
39-
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
40-
fn ui_about_menu(comm: &mut Comm) -> Event<Instruction> {
41-
let pages = [
42-
&Page::from((["Rust Boilerplate", "(c) 2023 Ledger"], true)),
43-
&Page::from(("Back", &BACK)),
44-
];
45-
loop {
46-
match MultiPageMenu::new(comm, &pages).show() {
47-
EventOrPageIndex::Event(e) => return e,
48-
EventOrPageIndex::Index(1) => return ui_menu_main(comm),
49-
EventOrPageIndex::Index(_) => (),
50-
}
51-
}
52-
}
53-
54-
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
55-
pub fn ui_menu_main(comm: &mut Comm) -> Event<Instruction> {
56-
const APP_ICON: Glyph = Glyph::from_include(include_gif!("crab.gif"));
57-
let pages = [
58-
// The from trait allows to create different styles of pages
59-
// without having to use the new() function.
60-
&Page::from((["Boilerplate", "is ready"], &APP_ICON)),
61-
&Page::from((["Version", env!("CARGO_PKG_VERSION")], true)),
62-
&Page::from(("About", &CERTIFICATE)),
63-
&Page::from(("Quit", &DASHBOARD_X)),
64-
];
65-
loop {
66-
match MultiPageMenu::new(comm, &pages).show() {
67-
EventOrPageIndex::Event(e) => return e,
68-
EventOrPageIndex::Index(2) => return ui_about_menu(comm),
69-
EventOrPageIndex::Index(3) => ledger_device_sdk::exit_app(0),
70-
EventOrPageIndex::Index(_) => (),
71-
}
72-
}
73-
}
74-
75-
#[cfg(any(target_os = "stax", target_os = "flex"))]
7624
pub fn ui_menu_main(_: &mut Comm) -> NbglHomeAndSettings {
7725
// Load glyph from 64x64 4bpp gif file with include_gif macro. Creates an NBGL compatible glyph.
26+
#[cfg(any(target_os = "stax", target_os = "flex"))]
7827
const FERRIS: NbglGlyph = NbglGlyph::from_include(include_gif!("crab_64x64.gif", NBGL));
28+
#[cfg(any(target_os = "nanosplus", target_os = "nanox"))]
29+
const FERRIS: NbglGlyph = NbglGlyph::from_include(include_gif!("crab_16x16.gif", NBGL));
7930

8031
let settings_strings = [["Display Memo", "Allow display of transaction memo."]];
8132
let mut settings: Settings = Default::default();

src/app_ui/sign.rs

Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,8 @@
1717
use crate::handlers::sign_tx::Tx;
1818
use crate::AppSW;
1919

20-
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
21-
use ledger_device_sdk::ui::{
22-
bitmaps::{CROSSMARK, EYE, VALIDATE_14},
23-
gadgets::{Field, MultiFieldReview},
24-
};
25-
26-
#[cfg(any(target_os = "stax", target_os = "flex"))]
2720
use crate::settings::Settings;
28-
#[cfg(any(target_os = "stax", target_os = "flex"))]
2921
use include_gif::include_gif;
30-
#[cfg(any(target_os = "stax", target_os = "flex"))]
3122
use ledger_device_sdk::nbgl::{Field, NbglGlyph, NbglReview};
3223

3324
use alloc::format;
@@ -60,41 +51,28 @@ pub fn ui_display_tx(tx: &Tx) -> Result<bool, AppSW> {
6051
];
6152

6253
// Create transaction review
63-
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
64-
{
65-
let my_review = MultiFieldReview::new(
66-
&my_fields,
67-
&["Review ", "Transaction"],
68-
Some(&EYE),
69-
"Approve",
70-
Some(&VALIDATE_14),
71-
"Reject",
72-
Some(&CROSSMARK),
73-
);
74-
75-
Ok(my_review.show())
76-
}
7754

55+
// Load glyph from 64x64 4bpp gif file with include_gif macro. Creates an NBGL compatible glyph.
7856
#[cfg(any(target_os = "stax", target_os = "flex"))]
79-
{
80-
// Load glyph from 64x64 4bpp gif file with include_gif macro. Creates an NBGL compatible glyph.
81-
const FERRIS: NbglGlyph = NbglGlyph::from_include(include_gif!("crab_64x64.gif", NBGL));
82-
// Create NBGL review. Maximum number of fields and string buffer length can be customised
83-
// with constant generic parameters of NbglReview. Default values are 32 and 1024 respectively.
84-
let review: NbglReview = NbglReview::new()
85-
.titles(
86-
"Review transaction\nto send CRAB",
87-
"",
88-
"Sign transaction\nto send CRAB",
89-
)
90-
.glyph(&FERRIS);
57+
const FERRIS: NbglGlyph = NbglGlyph::from_include(include_gif!("crab_64x64.gif", NBGL));
58+
#[cfg(any(target_os = "nanosplus", target_os = "nanox"))]
59+
const FERRIS: NbglGlyph = NbglGlyph::from_include(include_gif!("crab_16x16.gif", NBGL));
60+
61+
// Create NBGL review. Maximum number of fields and string buffer length can be customised
62+
// with constant generic parameters of NbglReview. Default values are 32 and 1024 respectively.
63+
let review: NbglReview = NbglReview::new()
64+
.titles(
65+
"Review transaction\nto send CRAB",
66+
"",
67+
"Sign transaction\nto send CRAB",
68+
)
69+
.glyph(&FERRIS);
9170

92-
// If first setting switch is disabled do not display the transaction memo
93-
let settings: Settings = Default::default();
94-
if settings.get_element(0) == 0 {
95-
Ok(review.show(&my_fields[0..2]))
96-
} else {
97-
Ok(review.show(&my_fields))
98-
}
71+
// If first setting switch is disabled do not display the transaction memo
72+
let settings: Settings = Default::default();
73+
if settings.get_element(0) == 0 {
74+
Ok(review.show(&my_fields[0..2]))
75+
} else {
76+
Ok(review.show(&my_fields))
9977
}
10078
}

src/handlers/sign_tx.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ use alloc::vec::Vec;
2121
use ledger_device_sdk::ecc::{Secp256k1, SeedDerive};
2222
use ledger_device_sdk::hash::{sha3::Keccak256, HashInit};
2323
use ledger_device_sdk::io::Comm;
24-
25-
#[cfg(any(target_os = "stax", target_os = "flex"))]
2624
use ledger_device_sdk::nbgl::NbglHomeAndSettings;
2725

2826
use serde::Deserialize;
@@ -45,7 +43,6 @@ pub struct TxContext {
4543
raw_tx: Vec<u8>,
4644
path: Bip32Path,
4745
review_finished: bool,
48-
#[cfg(any(target_os = "stax", target_os = "flex"))]
4946
pub home: NbglHomeAndSettings,
5047
}
5148

@@ -57,7 +54,6 @@ impl TxContext {
5754
raw_tx: Vec::new(),
5855
path: Default::default(),
5956
review_finished: false,
60-
#[cfg(any(target_os = "stax", target_os = "flex"))]
6157
home: Default::default(),
6258
}
6359
}

src/main.rs

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,12 @@ use handlers::{
3939
sign_tx::{handler_sign_tx, TxContext},
4040
};
4141
use ledger_device_sdk::io::{ApduHeader, Comm, Reply, StatusWords};
42-
#[cfg(feature = "pending_review_screen")]
43-
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
44-
use ledger_device_sdk::ui::gadgets::display_pending_review;
45-
46-
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
47-
use ledger_device_sdk::io::Event;
4842

4943
ledger_device_sdk::set_panic!(ledger_device_sdk::exiting_panic);
5044

5145
// Required for using String, Vec, format!...
5246
extern crate alloc;
5347

54-
#[cfg(any(target_os = "stax", target_os = "flex"))]
5548
use ledger_device_sdk::nbgl::{init_comm, NbglReviewStatus, StatusType};
5649

5750
// P2 for last APDU to receive.
@@ -131,7 +124,6 @@ impl TryFrom<ApduHeader> for Instruction {
131124
}
132125
}
133126

134-
#[cfg(any(target_os = "stax", target_os = "flex"))]
135127
fn show_status_and_home_if_needed(ins: &Instruction, tx_ctx: &mut TxContext, status: &AppSW) {
136128
let (show_status, status_type) = match (ins, status) {
137129
(Instruction::GetPubkey { display: true }, AppSW::Deny | AppSW::Ok) => {
@@ -163,30 +155,15 @@ extern "C" fn sample_main() {
163155

164156
let mut tx_ctx = TxContext::new();
165157

166-
#[cfg(any(target_os = "stax", target_os = "flex"))]
167-
{
168-
// Initialize reference to Comm instance for NBGL
169-
// API calls.
170-
init_comm(&mut comm);
171-
tx_ctx.home = ui_menu_main(&mut comm);
172-
tx_ctx.home.show_and_return();
173-
}
174-
175-
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
176-
#[cfg(feature = "pending_review_screen")]
177-
display_pending_review(&mut comm);
158+
// Initialize reference to Comm instance for NBGL
159+
// API calls.
160+
init_comm(&mut comm);
161+
tx_ctx.home = ui_menu_main(&mut comm);
162+
tx_ctx.home.show_and_return();
178163

179164
loop {
180-
#[cfg(any(target_os = "stax", target_os = "flex"))]
181165
let ins: Instruction = comm.next_command();
182166

183-
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
184-
let ins = if let Event::Command(ins) = ui_menu_main(&mut comm) {
185-
ins
186-
} else {
187-
continue;
188-
};
189-
190167
let _status = match handle_apdu(&mut comm, &ins, &mut tx_ctx) {
191168
Ok(()) => {
192169
comm.reply_ok();
@@ -197,7 +174,6 @@ extern "C" fn sample_main() {
197174
sw
198175
}
199176
};
200-
#[cfg(any(target_os = "stax", target_os = "flex"))]
201177
show_status_and_home_if_needed(&ins, &mut tx_ctx, &_status);
202178
}
203179
}

tests/conftest.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
# 2. This fixture clears the pending review screen before each test
2121
# 3. The scope should be the same as the one configured by BACKEND_SCOPE in
2222
# ragger/conftest/configuration.py
23-
@pytest.fixture(scope="class", autouse=True)
24-
def clear_pending_review(firmware, navigator):
25-
# Press a button to clear the pending review
26-
if firmware.device.startswith("nano"):
27-
print("Clearing pending review")
28-
instructions = [
29-
NavInsID.BOTH_CLICK,
30-
]
31-
navigator.navigate(instructions,screen_change_before_first_instruction=False)
23+
# @pytest.fixture(scope="class", autouse=True)
24+
# def clear_pending_review(firmware, navigator):
25+
# # Press a button to clear the pending review
26+
# if firmware.device.startswith("nano"):
27+
# print("Clearing pending review")
28+
# instructions = [
29+
# NavInsID.BOTH_CLICK,
30+
# ]
31+
# navigator.navigate(instructions,screen_change_before_first_instruction=False)
-1.33 KB

0 commit comments

Comments
 (0)