Skip to content

Commit

Permalink
Merge pull request #13 from Conflux-Chain/blindSign
Browse files Browse the repository at this point in the history
add blind signing setting
  • Loading branch information
Pana authored Nov 27, 2024
2 parents 4c0067e + 1000ada commit d151d69
Show file tree
Hide file tree
Showing 34 changed files with 53 additions and 19 deletions.
49 changes: 43 additions & 6 deletions src/app_ui/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/

use include_gif::include_gif;
use ledger_device_sdk::io::Comm;

#[cfg(not(any(target_os = "stax", target_os = "flex")))]
use ledger_device_sdk::ui::{
bitmaps::{Glyph, BACK, CERTIFICATE, DASHBOARD_X},
bitmaps::{Glyph, BACK, CERTIFICATE, COGGLE, DASHBOARD_X},
gadgets::{EventOrPageIndex, MultiPageMenu, Page},
};

#[cfg(any(target_os = "stax", target_os = "flex"))]
use crate::settings::Settings;
#[cfg(any(target_os = "stax", target_os = "flex"))]
use ledger_device_sdk::nbgl::{NbglGlyph, NbglHomeAndSettings};
Expand All @@ -51,6 +49,40 @@ fn ui_about_menu(comm: &mut Comm) -> Event<Instruction> {
}
}

#[cfg(not(any(target_os = "stax", target_os = "flex")))]
fn ui_setting_menu(comm: &mut Comm) -> Event<Instruction> {
let blind_signing_index = 0;

let settings: Settings = Default::default();
let mut bs_enabled: bool = settings.get_element(blind_signing_index) != 0;
let mut bs_status = if bs_enabled { "Enabled" } else { "Disabled" };

loop {
let pages = [
&Page::from((["Blind Signing", bs_status], true)),
&Page::from(("Back", &BACK)),
];
match MultiPageMenu::new(comm, &pages).show() {
EventOrPageIndex::Event(e) => return e,
EventOrPageIndex::Index(0) => {
bs_enabled = !bs_enabled;
match bs_enabled {
true => {
settings.set_element(blind_signing_index, 1);
bs_status = "Enabled";
}
false => {
settings.set_element(blind_signing_index, 0);
bs_status = "Disabled";
}
}
}
EventOrPageIndex::Index(1) => return ui_menu_main(comm),
EventOrPageIndex::Index(_) => (),
}
}
}

#[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!("icons/cfx_16.gif"));
Expand All @@ -59,14 +91,16 @@ pub fn ui_menu_main(comm: &mut Comm) -> Event<Instruction> {
// without having to use the new() function.
&Page::from((["Conflux", "is ready"], &APP_ICON)),
&Page::from((["Version", env!("CARGO_PKG_VERSION")], true)),
&Page::from(("Settings", &COGGLE)),
&Page::from(("About", &CERTIFICATE)),
&Page::from(("Quit", &DASHBOARD_X)),
];
loop {
match MultiPageMenu::new(comm, &pages).show() {
EventOrPageIndex::Event(e) => return e,
EventOrPageIndex::Index(2) => return ui_about_menu(comm),
EventOrPageIndex::Index(3) => ledger_device_sdk::exit_app(0),
EventOrPageIndex::Index(2) => return ui_setting_menu(comm),
EventOrPageIndex::Index(3) => return ui_about_menu(comm),
EventOrPageIndex::Index(4) => ledger_device_sdk::exit_app(0),
EventOrPageIndex::Index(_) => (),
}
}
Expand All @@ -77,7 +111,10 @@ 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 CFX: NbglGlyph = NbglGlyph::from_include(include_gif!("icons/cfx_64.gif", NBGL));

let settings_strings = [["Display Data", "Allow display of transaction data."]];
let settings_strings = [
["Blind Signing", "Enable transaction blind signing."],
["Display Data", "Allow display of transaction data."],
];
let mut settings: Settings = Default::default();

// Display the home screen.
Expand Down
2 changes: 1 addition & 1 deletion src/app_ui/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub fn ui_display_tx(tx: &Transaction) -> Result<bool, AppSW> {

// If first setting switch is disabled do not display the transaction data
let settings: Settings = Default::default();
if settings.get_element(0) == 0 {
if settings.get_element(1) == 0 {
Ok(review.show(&my_fields[0..2]))
} else {
Ok(review.show(&my_fields))
Expand Down
20 changes: 8 additions & 12 deletions src/handlers/get_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,19 @@ use crate::AppSW;
use core::str::FromStr;
use ledger_device_sdk::io;

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

pub fn handler_get_version(comm: &mut io::Comm) -> Result<(), AppSW> {
if let Some((major, minor, patch)) = parse_version_string(env!("CARGO_PKG_VERSION")) {
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
let flags: u8 = 0b0000_0100;

#[cfg(any(target_os = "stax", target_os = "flex"))]
let mut flags: u8 = 0b0000_0100;
#[cfg(any(target_os = "stax", target_os = "flex"))]
{
let settings: Settings = Default::default();
if settings.get_element(0) == 1 {
// If the first byte is 1, then the user has enabled the "Display data" setting
flags |= crate::consts::APP_FLAG_DETAILED_DISPLAY_ENABLED;
}
let settings: Settings = Default::default();
if settings.get_element(0) == 1 {
// If the first byte is 1, then the user has enabled the "Blind signing" setting
flags |= crate::consts::APP_FLAG_BLIND_SIGNING_ENABLED;
}
if settings.get_element(1) == 1 {
// If the first byte is 1, then the user has enabled the "Display data" setting
flags |= crate::consts::APP_FLAG_DETAILED_DISPLAY_ENABLED;
}

comm.append(&[flags, major, minor, patch]);
Expand Down
Binary file modified tests/snapshots/flex/test_app_mainmenu/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/flex/test_sign_tx_1559_tx/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/flex/test_sign_tx_1gwei/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/flex/test_sign_tx_long_tx/00000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/flex/test_sign_tx_long_tx/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/flex/test_sign_tx_long_tx/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/flex/test_sign_tx_long_tx/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/flex/test_sign_tx_long_tx/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/flex/test_sign_tx_normal_tx/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/flex/test_sign_tx_short_tx/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/flex/test_sign_tx_very_big_value/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/flex/test_sign_tx_xgwei/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanosp/test_app_mainmenu/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanosp/test_app_mainmenu/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanosp/test_app_mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanox/test_app_mainmenu/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanox/test_app_mainmenu/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanox/test_app_mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_app_mainmenu/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_sign_tx_1559_tx/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_sign_tx_1gwei/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_sign_tx_long_tx/00000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_sign_tx_long_tx/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_sign_tx_long_tx/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_sign_tx_long_tx/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/stax/test_sign_tx_long_tx/00004.png
Binary file modified tests/snapshots/stax/test_sign_tx_normal_tx/00001.png
Binary file modified tests/snapshots/stax/test_sign_tx_short_tx/00001.png
Binary file modified tests/snapshots/stax/test_sign_tx_very_big_value/00001.png
Binary file modified tests/snapshots/stax/test_sign_tx_xgwei/00001.png
1 change: 1 addition & 0 deletions tests/test_app_mainmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def test_app_mainmenu(firmware, navigator, test_name):
# Navigate in the main menu
if firmware.device.startswith("nano"):
instructions = [
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK
Expand Down

0 comments on commit d151d69

Please sign in to comment.