From 2210005d6526b08231a301cc613c58c146c45d66 Mon Sep 17 00:00:00 2001 From: Alexis Grojean Date: Fri, 29 Mar 2024 15:11:23 +0100 Subject: [PATCH] Use new include_gif macro to generate NBGL glyphs. --- Cargo.toml | 1 + crab_64x64.gif | Bin 0 -> 721 bytes src/app_ui/address.rs | 5 ++-- src/app_ui/menu.rs | 53 +++++------------------------------------- src/app_ui/sign.rs | 23 ++++++++++++++---- 5 files changed, 28 insertions(+), 54 deletions(-) create mode 100644 crab_64x64.gif diff --git a/Cargo.toml b/Cargo.toml index dc82d37..a1e5489 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ numtoa = "0.2.4" [patch.crates-io] ledger_device_sdk = { path = 'ledger-device-rust-sdk/ledger_device_sdk' } ledger_secure_sdk_sys = { path = 'ledger-device-rust-sdk/ledger_secure_sdk_sys' } +include_gif = { path = 'ledger-device-rust-sdk/include_gif' } [profile.release] opt-level = 'z' diff --git a/crab_64x64.gif b/crab_64x64.gif new file mode 100644 index 0000000000000000000000000000000000000000..7271f2e3bf9e28be78dd2902d3aa36cdb6a9cf10 GIT binary patch literal 721 zcmV;?0xtbWNk%w1VL$*t0OJ4v|NsA)nVE=)h^nfpcXxLH00320Rc2;p?(XipySv@p z-OS9)5fKq0A|f+0Geks0A^s6Va%Ew3Wn>_CX>@2HM@dak04x9i002M$KmY&){t(DX ztGzhu&Ab0#D2`-lo@lDBZ0o*oEYEap-*}BE6Eg6UT~4zYEF{GN0^l1ADT>4rFsLpR z)qyk%TqJUdssfuWo26kTZAvw}-(?{4g-s}$@O*iJD1KdJdTs#$W`u==e=UK7g=K_~ zhgFA)D1CQmk0tE)@iMI^| zpzHhHyBV;!$_ZGapg@5GodobG*gzn;hY$k@aMB^5!~g^c8g%e5z=4JS1_?kMd6C>T z49XI!+~-jt0fPnhJvgx7fI)f^N1p3=vcdp|5lND>39~@MhX#rs)XDT=EeZ*Cmdx2y z0E40iAijjjplVe$6&3&$+LVBUn>qQX6AmsQJo^-hys%tETaYxMuOl% zUI}QqE3&*uiH8GBfhFOmzYCU0sYl|tP=aq`f>btjxIckP^U-rgkvkGCfq){g_%~k% z3i$V*GkthR*)#3T0fhkmJ!QcH4!&n0Z60cHi-t@%D1a0fB65dZ)? D)WkZY literal 0 HcmV?d00001 diff --git a/src/app_ui/address.rs b/src/app_ui/address.rs index 4a8371c..b44f489 100644 --- a/src/app_ui/address.rs +++ b/src/app_ui/address.rs @@ -56,13 +56,12 @@ pub fn ui_display_pk(addr: &[u8]) -> Result { "Reject", Some(&CROSSMARK), ); - + Ok(my_review.show()) } #[cfg(target_os = "stax")] { - Ok(NbglAddressConfirm.verify_address(addr_hex)) + Ok(NbglAddressConfirm::new().show(addr_hex)) } - } diff --git a/src/app_ui/menu.rs b/src/app_ui/menu.rs index 01f528e..8de2491 100644 --- a/src/app_ui/menu.rs +++ b/src/app_ui/menu.rs @@ -24,12 +24,10 @@ use ledger_device_sdk::ui::bitmaps::{Glyph, BACK, CERTIFICATE, DASHBOARD_X}; use ledger_device_sdk::ui::gadgets::{EventOrPageIndex, MultiPageMenu, Page}; #[cfg(target_os = "stax")] -use ledger_device_sdk::nbgl::NbglHome; - +use ledger_device_sdk::nbgl::{NbglGlyph, NbglHome}; use crate::Instruction; - #[cfg(not(target_os = "stax"))] fn ui_about_menu(comm: &mut Comm) -> Event { let pages = [ @@ -68,49 +66,10 @@ pub fn ui_menu_main(comm: &mut Comm) -> Event { #[cfg(target_os = "stax")] pub fn ui_menu_main(comm: &mut Comm) -> Event { + const FERRIS: NbglGlyph = NbglGlyph::from_include(include_gif!("crab_64x64.gif", NBGL)); NbglHome::new(comm) - .app_name("Boilerplate\0") - .info_contents(env!("CARGO_PKG_VERSION"), env!("CARGO_PKG_AUTHORS")) - .icon(&BTC_BMP) - .show() + .app_name("Boilerplate\0") + .info_contents(env!("CARGO_PKG_VERSION"), env!("CARGO_PKG_AUTHORS")) + .glyph(&FERRIS) + .show() } - -#[cfg(target_os = "stax")] -const BTC_BMP: [u8; 573] = [ - 0x40, 0x00, 0x40, 0x00, 0x21, 0x35, 0x02, 0x00, 0x33, 0x02, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x02, 0xff, 0xbd, 0x55, 0xb9, 0x4e, 0x23, 0x41, 0x10, 0x6d, 0x7b, 0x3c, 0x5c, 0x46, - 0x5e, 0x2f, 0x96, 0x20, 0xc3, 0x10, 0x5b, 0x82, 0xdd, 0x6c, 0x1d, 0x2d, 0x64, 0x10, 0x81, 0x88, - 0x10, 0x01, 0x87, 0x03, 0x02, 0x84, 0x38, 0x02, 0x62, 0x90, 0x58, 0x44, 0xb0, 0x01, 0xbb, 0xf0, - 0x01, 0x26, 0xd9, 0x68, 0x03, 0x10, 0x1f, 0x00, 0xa4, 0x44, 0xfc, 0x02, 0x26, 0x34, 0x88, 0xe1, - 0x32, 0x87, 0x8d, 0xa6, 0xe8, 0xee, 0xa9, 0x3e, 0xa6, 0xa7, 0x6d, 0x13, 0x51, 0xc1, 0xa8, 0x67, - 0x5e, 0x4f, 0xd7, 0xab, 0xaa, 0x57, 0xd5, 0x00, 0x9f, 0x67, 0x57, 0x5b, 0xfd, 0x84, 0x64, 0x46, - 0x4e, 0xec, 0xa8, 0xbf, 0x99, 0x26, 0x81, 0xe5, 0x3d, 0x0b, 0x5c, 0x9b, 0x23, 0xd2, 0xdc, 0xe8, - 0x06, 0x7f, 0x88, 0x90, 0x46, 0x1b, 0x56, 0x49, 0xc8, 0x5a, 0x0d, 0xf8, 0x92, 0x18, 0xd6, 0x1b, - 0x82, 0x5f, 0xd3, 0x26, 0x1e, 0x2b, 0xea, 0xf8, 0x0a, 0x89, 0x98, 0xee, 0xe1, 0x99, 0x58, 0x6c, - 0xbd, 0xe1, 0xef, 0xfa, 0x01, 0x2f, 0xc4, 0x6a, 0x92, 0x41, 0xc9, 0x8e, 0xcb, 0x10, 0xd2, 0x76, - 0x3c, 0xde, 0x88, 0x9d, 0xc6, 0xf0, 0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f, 0x50, 0xfb, 0xe1, 0xd9, 0x6f, 0xc0, 0xda, 0xaf, 0xef, 0x84, 0x74, 0x4d, 0x1e, - 0x7f, 0xe2, 0x95, 0x0c, 0xef, 0xe7, 0x7f, 0x81, 0xae, 0x00, 0x08, 0x00, 0x00, -]; \ No newline at end of file diff --git a/src/app_ui/sign.rs b/src/app_ui/sign.rs index c949cff..2df9ca6 100644 --- a/src/app_ui/sign.rs +++ b/src/app_ui/sign.rs @@ -18,13 +18,17 @@ use crate::handlers::sign_tx::Tx; use crate::utils::concatenate; use crate::AppSW; +use ledger_secure_sdk_sys::*; + #[cfg(not(target_os = "stax"))] use ledger_device_sdk::ui::bitmaps::{CROSSMARK, EYE, VALIDATE_14}; #[cfg(not(target_os = "stax"))] use ledger_device_sdk::ui::gadgets::{Field, MultiFieldReview}; #[cfg(target_os = "stax")] -use ledger_device_sdk::nbgl::{Field, NbglReview}; +use include_gif::include_gif; +#[cfg(target_os = "stax")] +use ledger_device_sdk::nbgl::{Field, NbglGlyph, NbglReview}; use numtoa::NumToA; @@ -82,13 +86,24 @@ pub fn ui_display_tx(tx: &Tx) -> Result { "Reject", Some(&CROSSMARK), ); - + Ok(my_review.show()) } #[cfg(target_os = "stax")] { - Ok(NbglReview.review_transaction(&my_fields)) - } + // This will copy the fields into the nbgl format, not ideal + // memory-wise... + let nbgl_fields: [nbgl_layoutTagValue_t; 3] = [ + my_fields[0].into(), + my_fields[1].into(), + my_fields[2].into(), + ]; + const FERRIS: NbglGlyph = NbglGlyph::from_include(include_gif!("crab_64x64.gif", NBGL)); + Ok(NbglReview::new() + .status_strings("TRANSACTION\nSIGNED\0", "Transaction\nRejected\0") + .glyph(&FERRIS) + .show(&nbgl_fields)) + } }