Skip to content

Commit

Permalink
stax tmp 1
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyProgrammist committed Jun 26, 2024
1 parent f8a075f commit e64256c
Show file tree
Hide file tree
Showing 30 changed files with 463 additions and 106 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ledgerDevTools.appSettings": {
"selectedDevice": "Stax",
"selectedUseCase": "release"
}
}
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ icon = "icons/app_near_14px.gif"
[package.metadata.ledger.nanosplus]
icon = "icons/app_near_14px.gif"

[package.metadata.ledger.stax]
icon = "icons/app_near_14px.gif"

[features]
default = []
speculos = ["ledger_device_sdk/speculos"]
6 changes: 6 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ run_speculos_nanox:
-v "$(realpath ./):/app" -it --name \
app-near-container ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:latest \
bash -c '/usr/bin/python3 -m speculos --model nanox --api-port 5000 --apdu-port 5001 --display headless /app/target/nanox/release/app-near-rust'

run_speculos_stax:
docker run --rm -p 5000:5000 -p 5001:5001 -v '/dev/bus/usb:/dev/bus/usb' \
-v "$(realpath ./):/app" -it --name \
app-near-container ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:latest \
bash -c '/usr/bin/python3 -m speculos --model stax --api-port 5000 --apdu-port 5001 --display headless /app/target/stax/release/app-near-rust'
18 changes: 18 additions & 0 deletions app_stax.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"apiLevel": "15",
"binary": "target/stax/release/app.hex",
"dataSize": 6144,
"derivationPath": {
"curves": [
"ed25519"
],
"paths": [
"44'/397'"
]
},
"flags": "0x200",
"icon": "icons/app_near_14px.gif",
"name": "NEAR",
"targetId": "0x33200004",
"version": "2.0.0"
}
2 changes: 1 addition & 1 deletion ledger_app.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[app]
build_directory = "./"
sdk = "Rust"
devices = ["nanos", "nanox", "nanos+"]
devices = ["nanos", "nanox", "nanos+", "stax"]

[tests]
pytest_directory = "./tests/"
1 change: 1 addition & 0 deletions local_test_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function build_all() {
cargo ledger build nanos
cargo ledger build nanosplus
cargo ledger build nanox
cargo ledger build stax
exit
EOF
}
Expand Down
86 changes: 66 additions & 20 deletions src/app_ui/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@
use crate::utils::crypto;
use crate::AppSW;
use fmt_buffer::Buffer;
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
use ledger_device_sdk::ui::bitmaps::{CROSSMARK, EYE, VALIDATE_14};
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
use ledger_device_sdk::ui::gadgets::{Field, MultiFieldReview};
#[cfg(any(target_os = "stax", target_os = "flex"))]
use include_gif::include_gif;
#[cfg(any(target_os = "stax", target_os = "flex"))]
use ledger_device_sdk::nbgl::{Field, NbglGlyph, NbglReview};


pub fn ui_display_pk_base58(public_key: &crypto::PublicKeyBe) -> Result<bool, AppSW> {
let mut out_buf = Buffer::<60>::new();
Expand All @@ -30,17 +37,37 @@ pub fn ui_display_pk_base58(public_key: &crypto::PublicKeyBe) -> Result<bool, Ap
value: out_buf.as_str(),
}];

let my_review = MultiFieldReview::new(
&my_field,
&["Confirm Address"],
Some(&EYE),
"Approve",
Some(&VALIDATE_14),
"Reject",
Some(&CROSSMARK),
);
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
{
let my_review = MultiFieldReview::new(
&my_field,
&["Confirm Address"],
Some(&EYE),
"Approve",
Some(&VALIDATE_14),
"Reject",
Some(&CROSSMARK),
);
Ok(my_review.show())
}

#[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!("icons/app_near_14px.gif", 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 mut review: NbglReview = NbglReview::new()
.titles(
"Review transaction\nto send CRAB",
"",
"Sign transaction\nto send CRAB",
)
.glyph(&FERRIS);

Ok(my_review.show())

Ok(review.show(&my_field))
}
}

pub fn ui_display_hex(public_key: &crypto::PublicKeyBe) -> Result<bool, AppSW> {
Expand All @@ -51,15 +78,34 @@ pub fn ui_display_hex(public_key: &crypto::PublicKeyBe) -> Result<bool, AppSW> {
value: public_key.display_str_hex(&mut out_buf),
}];

let my_review = MultiFieldReview::new(
&my_field,
&["Confirm Address"],
Some(&EYE),
"Approve",
Some(&VALIDATE_14),
"Reject",
Some(&CROSSMARK),
);
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
{
let my_review = MultiFieldReview::new(
&my_field,
&["Confirm Address"],
Some(&EYE),
"Approve",
Some(&VALIDATE_14),
"Reject",
Some(&CROSSMARK),
);
Ok(my_review.show())
}

#[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!("icons/app_near_14px.gif", 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 mut review: NbglReview = NbglReview::new()
.titles(
"Review transaction\nto send CRAB",
"",
"Sign transaction\nto send CRAB",
)
.glyph(&FERRIS);

Ok(my_review.show())
Ok(review.show(&my_field))
}
}
3 changes: 3 additions & 0 deletions src/app_ui/fields_writer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use core::panic;

#[cfg(not(any(target_os = "stax", target_os = "flex")))]
use ledger_device_sdk::ui::gadgets::Field;
#[cfg(any(target_os = "stax", target_os = "flex"))]
use ledger_device_sdk::nbgl::Field;

use crate::utils::types::elipsis_fields::ElipsisFields;

Expand Down
29 changes: 29 additions & 0 deletions src/app_ui/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@

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

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((["NEAR", "(c) 2024 Ledger"], true)),
Expand All @@ -36,13 +43,16 @@ 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> {
#[cfg(target_os = "nanos")]
const APP_ICON: Glyph = Glyph::from_include(include_gif!("icons/app_near_16px.gif"));
#[cfg(target_os = "nanosplus")]
const APP_ICON: Glyph = Glyph::from_include(include_gif!("icons/app_near_14px.gif"));
#[cfg(target_os = "nanox")]
const APP_ICON: Glyph = Glyph::from_include(include_gif!("icons/app_near_14px.gif"));
#[cfg(target_os = "stax")]
const APP_ICON: Glyph = Glyph::from_include(include_gif!("icons/app_near_14px.gif"));
let pages = [
// The from trait allows to create different styles of pages
// without having to use the new() function.
Expand All @@ -60,3 +70,22 @@ 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) -> Event<Instruction> {
// Load glyph from 64x64 4bpp gif file with include_gif macro. Creates an NBGL compatible glyph.
const FERRIS: NbglGlyph = NbglGlyph::from_include(include_gif!("icons/app_near_14px.gif", NBGL));

let settings_strings = [["Display Memo", "Allow display of transaction memo."]];
let mut settings: Settings = Default::default();
// Display the home screen.
NbglHomeAndSettings::new()
.glyph(&FERRIS)
.settings(settings.get_mut_ref(), &settings_strings)
.infos(
"Boilerplate",
env!("CARGO_PKG_VERSION"),
env!("CARGO_PKG_AUTHORS"),
)
.show()
}
4 changes: 4 additions & 0 deletions src/app_ui/sign/common/action/add_key_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ use crate::{
utils::types::elipsis_fields::ElipsisFields,
};

#[cfg(not(any(target_os = "stax", target_os = "flex")))]
use ledger_device_sdk::ui::gadgets::Field;
#[cfg(any(target_os = "stax", target_os = "flex"))]
use ledger_device_sdk::nbgl::Field;

use numtoa::NumToA;

pub struct FieldsContext {
Expand Down
3 changes: 3 additions & 0 deletions src/app_ui/sign/common/action/create_account.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::{parsing, utils::types::elipsis_fields::ElipsisFields};
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
use ledger_device_sdk::ui::gadgets::Field;
#[cfg(any(target_os = "stax", target_os = "flex"))]
use ledger_device_sdk::nbgl::Field;

use crate::app_ui::fields_writer::FieldsWriter;

Expand Down
3 changes: 3 additions & 0 deletions src/app_ui/sign/common/action/delete_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use crate::{
parsing,
utils::types::elipsis_fields::{ElipsisFields, EllipsisBuffer},
};
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
use ledger_device_sdk::ui::gadgets::Field;
#[cfg(any(target_os = "stax", target_os = "flex"))]
use ledger_device_sdk::nbgl::Field;

use crate::app_ui::fields_writer::FieldsWriter;

Expand Down
3 changes: 3 additions & 0 deletions src/app_ui/sign/common/action/delete_key.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
use ledger_device_sdk::ui::gadgets::Field;
#[cfg(any(target_os = "stax", target_os = "flex"))]
use ledger_device_sdk::nbgl::Field;

use crate::{
app_ui::fields_writer::FieldsWriter, parsing, sign_ui::common::tx_public_key_context,
Expand Down
3 changes: 3 additions & 0 deletions src/app_ui/sign/common/action/deploy_contract.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::{parsing, utils::types::elipsis_fields::ElipsisFields};
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
use ledger_device_sdk::ui::gadgets::Field;
#[cfg(any(target_os = "stax", target_os = "flex"))]
use ledger_device_sdk::nbgl::Field;

use crate::app_ui::fields_writer::FieldsWriter;

Expand Down
4 changes: 4 additions & 0 deletions src/app_ui/sign/common/action/function_call_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ use crate::{
parsing,
utils::types::elipsis_fields::{ElipsisFields, EllipsisBuffer},
};
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
use ledger_device_sdk::ui::gadgets::Field;
#[cfg(any(target_os = "stax", target_os = "flex"))]
use ledger_device_sdk::nbgl::Field;

use near_gas::GasBuffer;
use near_token::TokenBuffer;

Expand Down
4 changes: 4 additions & 0 deletions src/app_ui/sign/common/action/function_call_permission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ use crate::{
parsing,
utils::types::elipsis_fields::{ElipsisFields, EllipsisBuffer},
};
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
use ledger_device_sdk::ui::gadgets::Field;
#[cfg(any(target_os = "stax", target_os = "flex"))]
use ledger_device_sdk::nbgl::Field;

use near_token::TokenBuffer;
use numtoa::NumToA;

Expand Down
48 changes: 38 additions & 10 deletions src/app_ui/sign/common/action/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ use crate::app_ui::aliases::{FnCallCappedString, FnCallHexDisplay, U32Buffer};
use crate::{app_ui::fields_writer::FieldsWriter, handlers::common::action::ActionParams, parsing};
use fmt_buffer::Buffer;

#[cfg(not(any(target_os = "stax", target_os = "flex")))]
use ledger_device_sdk::ui::{
bitmaps::{CROSSMARK, EYE, VALIDATE_14},
gadgets::MultiFieldReview,
};
#[cfg(any(target_os = "stax", target_os = "flex"))]
use ledger_device_sdk::nbgl::{NbglReview, NbglGlyph};

#[cfg(any(target_os = "stax", target_os = "flex"))]
use include_gif::include_gif;
use numtoa::NumToA;

use super::tx_public_key_context;
Expand Down Expand Up @@ -177,17 +183,39 @@ pub fn ui_display_common<const N: usize>(
} else {
"Sign"
};
let my_review = MultiFieldReview::new(
writer.get_fields(),
&binding,
Some(&EYE),
if is_last { last_msg } else { next_msg },
Some(&VALIDATE_14),
"Reject",
Some(&CROSSMARK),
);

my_review.show()
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
{
let my_review = MultiFieldReview::new(
writer.get_fields(),
&binding,
Some(&EYE),
if is_last { last_msg } else { next_msg },
Some(&VALIDATE_14),
"Reject",
Some(&CROSSMARK),
);

my_review.show()
}


#[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!("icons/app_near_14px.gif", 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 mut review: NbglReview = NbglReview::new()
.titles(
"Review transaction\nto send CRAB",
"",
"Sign transaction\nto send CRAB",
)
.glyph(&FERRIS);

review.show(writer.get_fields())
}
}

/// a buffer, large enough to fit description string and
Expand Down
4 changes: 4 additions & 0 deletions src/app_ui/sign/common/action/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ use crate::{
sign_ui::common::tx_public_key_context,
utils::types::elipsis_fields::ElipsisFields,
};
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
use ledger_device_sdk::ui::gadgets::Field;
#[cfg(any(target_os = "stax", target_os = "flex"))]
use ledger_device_sdk::nbgl::Field;

use near_token::TokenBuffer;

use crate::app_ui::fields_writer::FieldsWriter;
Expand Down
Loading

0 comments on commit e64256c

Please sign in to comment.