diff --git a/Cargo.lock b/Cargo.lock index 0edc8dc..8264dfb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1183,9 +1183,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" [[package]] name = "ledger_device_sdk" -version = "1.17.2" +version = "1.17.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3243f99eaf389a4fc68e103856432b022d46d747b7ff02bd26f984dba4390e5e" +checksum = "875d400a3d2607741f0eb107471611622fb99b75e612231c42b3b9e039fd96c9" dependencies = [ "const-zero", "include_gif", @@ -1988,7 +1988,7 @@ dependencies = [ [[package]] name = "starknet" -version = "2.1.0" +version = "2.1.1" dependencies = [ "hex", "include_gif", diff --git a/starknet/Cargo.toml b/starknet/Cargo.toml index a3f9d79..28ec164 100644 --- a/starknet/Cargo.toml +++ b/starknet/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "starknet" -version = "2.1.0" +version = "2.1.1" edition = "2021" authors = ["Ledger"] [dependencies] -ledger_device_sdk = "1.17.2" +ledger_device_sdk = "1.17.3" ledger_secure_sdk_sys = { version = "1.5.0", features = ["heap"]} include_gif = "1.2.0" hex = { version = "0.4", default-features = false, features = ["alloc"]} diff --git a/starknet/src/crypto.rs b/starknet/src/crypto.rs index a76d20c..90520b0 100644 --- a/starknet/src/crypto.rs +++ b/starknet/src/crypto.rs @@ -28,13 +28,7 @@ impl From for Reply { /// Helper function that signs with ECDSA in deterministic nonce pub fn sign_hash(ctx: &mut Ctx) -> Result<(), CryptoError> { - // ledger_device_sdk::testing::debug_print("Before shift: "); - // ledger_device_sdk::testing::debug_print(&ctx.hash.m_hash.to_hex_string()); - // ledger_device_sdk::testing::debug_print("\n"); poseidon::poseidon_shift(&mut ctx.hash.m_hash); - // ledger_device_sdk::testing::debug_print("After shift: "); - // ledger_device_sdk::testing::debug_print(&ctx.hash.m_hash.to_hex_string()); - // ledger_device_sdk::testing::debug_print("\n"); match Stark256::derive_from_path(ctx.bip32_path.as_ref()) .deterministic_sign(ctx.hash.m_hash.value.as_ref()) diff --git a/starknet/src/display.rs b/starknet/src/display.rs index 14b3804..f274fdf 100644 --- a/starknet/src/display.rs +++ b/starknet/src/display.rs @@ -3,9 +3,8 @@ use crate::{ erc20::{ERC20_TOKENS, TRANSFER}, types::FieldElement, }; -use alloc::format; use include_gif::include_gif; -use ledger_device_sdk::{io::Comm, testing}; +use ledger_device_sdk::io::Comm; use crate::context::{Ctx, Transaction}; @@ -26,7 +25,6 @@ use ledger_device_sdk::nbgl::{ pub fn show_tx(ctx: &mut Ctx) -> Option { match support_clear_sign(&ctx.tx) { Some(t) => { - testing::debug_print("Clear sign supported !!! \n"); let tx = &ctx.tx; let call = &tx.calls[0]; @@ -35,8 +33,6 @@ pub fn show_tx(ctx: &mut Ctx) -> Option { let to = call.calldata[0].to_hex_string(); let amount = call.calldata[1].to_dec_string(Some(ERC20_TOKENS[t].decimals)); - testing::debug_print("Compute fees \n"); - let max_fees_str = match tx.version { FieldElement::ONE => { let mut max_fees_str = tx.max_fee.to_dec_string(None); @@ -58,8 +54,6 @@ pub fn show_tx(ctx: &mut Ctx) -> Option { } }; - testing::debug_print("Compute fees OK \n"); - let my_fields = [ Field { name: "From", @@ -83,11 +77,6 @@ pub fn show_tx(ctx: &mut Ctx) -> Option { }, ]; - testing::debug_print(&format!( - "Token: {}\nTo: {}\nAmount: {}\n", - token, to, amount - )); - #[cfg(not(any(target_os = "stax", target_os = "flex")))] { let my_review = MultiFieldReview::new( @@ -115,10 +104,7 @@ pub fn show_tx(ctx: &mut Ctx) -> Option { Some(review.show(&my_fields)) } } - None => { - testing::debug_print("Clear sign not supported !!! \n"); - None - } + None => None, } } diff --git a/starknet/src/main.rs b/starknet/src/main.rs index 475dfbc..eea1c9f 100644 --- a/starknet/src/main.rs +++ b/starknet/src/main.rs @@ -34,7 +34,10 @@ extern "C" fn sample_main() { // or an APDU command if let io::Event::Command(ins) = display::main_ui(&mut comm) { match handle_apdu(&mut comm, &ins, &mut ctx) { - Ok(()) => comm.reply_ok(), + Ok(data) => { + comm.append(data.as_slice()); + comm.reply_ok() + } Err(sw) => comm.reply(sw), } } @@ -54,7 +57,10 @@ extern "C" fn sample_main() { // Wait for an APDU command let ins: Ins = comm.next_command(); match handle_apdu(&mut comm, &ins, &mut ctx) { - Ok(()) => comm.reply_ok(), + Ok(data) => { + comm.append(data.as_slice()); + comm.reply_ok() + } Err(sw) => comm.reply(sw), } } @@ -101,19 +107,22 @@ use ledger_device_sdk::io::Reply; const SIG_LENGTH: u8 = 0x41; -fn handle_apdu(comm: &mut io::Comm, ins: &Ins, ctx: &mut Ctx) -> Result<(), Reply> { +fn handle_apdu(comm: &mut io::Comm, ins: &Ins, ctx: &mut Ctx) -> Result, Reply> { if comm.rx == 0 { return Err(io::StatusWords::NothingReceived.into()); } let apdu_header = comm.get_apdu_metadata(); + let mut rdata: Vec = Vec::new(); + match ins { Ins::GetVersion => { let version_major = env!("CARGO_PKG_VERSION_MAJOR").parse::().unwrap(); let version_minor = env!("CARGO_PKG_VERSION_MINOR").parse::().unwrap(); let version_patch = env!("CARGO_PKG_VERSION_PATCH").parse::().unwrap(); - comm.append([version_major, version_minor, version_patch].as_slice()); + + rdata.extend_from_slice([version_major, version_minor, version_patch].as_slice()); } Ins::GetPubkey { display } => { ctx.reset(); @@ -138,7 +147,7 @@ fn handle_apdu(comm: &mut io::Comm, ins: &Ins, ctx: &mut Ctx) -> Result<(), Repl true => display::pkey_ui(key.as_ref(), ctx), }; if ret { - comm.append(key.as_ref()); + rdata.extend_from_slice(key.as_ref()); } else { return Err(io::StatusWords::UserCancelled.into()); } @@ -164,10 +173,10 @@ fn handle_apdu(comm: &mut io::Comm, ins: &Ins, ctx: &mut Ctx) -> Result<(), Repl match display::show_hash(ctx, false) { true => { crypto::sign_hash(ctx).unwrap(); - comm.append([0x41].as_slice()); - comm.append(ctx.hash.r.as_ref()); - comm.append(ctx.hash.s.as_ref()); - comm.append([ctx.hash.v].as_slice()); + rdata.extend_from_slice([0x41].as_slice()); + rdata.extend_from_slice(ctx.hash.r.as_ref()); + rdata.extend_from_slice(ctx.hash.s.as_ref()); + rdata.extend_from_slice([ctx.hash.v].as_slice()); } false => { return Err(io::StatusWords::UserCancelled.into()); @@ -213,13 +222,13 @@ fn handle_apdu(comm: &mut io::Comm, ins: &Ins, ctx: &mut Ctx) -> Result<(), Repl true => { display::show_pending(); ctx.hash.m_hash = crypto::tx_hash(&ctx.tx); - comm.append(ctx.hash.m_hash.value.as_ref()); + rdata.extend_from_slice(ctx.hash.m_hash.value.as_ref()); crypto::sign_hash(ctx).unwrap(); + rdata.extend_from_slice([SIG_LENGTH].as_slice()); + rdata.extend_from_slice(ctx.hash.r.as_ref()); + rdata.extend_from_slice(ctx.hash.s.as_ref()); + rdata.extend_from_slice([ctx.hash.v].as_slice()); display::show_status(true, ctx); - comm.append([SIG_LENGTH].as_slice()); - comm.append(ctx.hash.r.as_ref()); - comm.append(ctx.hash.s.as_ref()); - comm.append([ctx.hash.v].as_slice()); } false => { display::show_status(false, ctx); @@ -231,13 +240,13 @@ fn handle_apdu(comm: &mut io::Comm, ins: &Ins, ctx: &mut Ctx) -> Result<(), Repl ctx.hash.m_hash = crypto::tx_hash(&ctx.tx); match display::show_hash(ctx, true) { true => { - comm.append(ctx.hash.m_hash.value.as_ref()); + rdata.extend_from_slice(ctx.hash.m_hash.value.as_ref()); crypto::sign_hash(ctx).unwrap(); + rdata.extend_from_slice([SIG_LENGTH].as_slice()); + rdata.extend_from_slice(ctx.hash.r.as_ref()); + rdata.extend_from_slice(ctx.hash.s.as_ref()); + rdata.extend_from_slice([ctx.hash.v].as_slice()); display::show_status(true, ctx); - comm.append([SIG_LENGTH].as_slice()); - comm.append(ctx.hash.r.as_ref()); - comm.append(ctx.hash.s.as_ref()); - comm.append([ctx.hash.v].as_slice()); } false => { display::show_status(false, ctx); @@ -284,13 +293,13 @@ fn handle_apdu(comm: &mut io::Comm, ins: &Ins, ctx: &mut Ctx) -> Result<(), Repl true => { display::show_pending(); ctx.hash.m_hash = crypto::tx_hash(&ctx.tx); - comm.append(ctx.hash.m_hash.value.as_ref()); + rdata.extend_from_slice(ctx.hash.m_hash.value.as_ref()); crypto::sign_hash(ctx).unwrap(); + rdata.extend_from_slice([0x41].as_slice()); + rdata.extend_from_slice(ctx.hash.r.as_ref()); + rdata.extend_from_slice(ctx.hash.s.as_ref()); + rdata.extend_from_slice([ctx.hash.v].as_slice()); display::show_status(true, ctx); - comm.append([0x41].as_slice()); - comm.append(ctx.hash.r.as_ref()); - comm.append(ctx.hash.s.as_ref()); - comm.append([ctx.hash.v].as_slice()); } false => { display::show_status(false, ctx); @@ -302,13 +311,13 @@ fn handle_apdu(comm: &mut io::Comm, ins: &Ins, ctx: &mut Ctx) -> Result<(), Repl ctx.hash.m_hash = crypto::tx_hash(&ctx.tx); match display::show_hash(ctx, true) { true => { - comm.append(ctx.hash.m_hash.value.as_ref()); + rdata.extend_from_slice(ctx.hash.m_hash.value.as_ref()); crypto::sign_hash(ctx).unwrap(); + rdata.extend_from_slice([0x41].as_slice()); + rdata.extend_from_slice(ctx.hash.r.as_ref()); + rdata.extend_from_slice(ctx.hash.s.as_ref()); + rdata.extend_from_slice([ctx.hash.v].as_slice()); display::show_status(true, ctx); - comm.append([0x41].as_slice()); - comm.append(ctx.hash.r.as_ref()); - comm.append(ctx.hash.s.as_ref()); - comm.append([ctx.hash.v].as_slice()); } false => { display::show_status(false, ctx); @@ -375,5 +384,5 @@ fn handle_apdu(comm: &mut io::Comm, ins: &Ins, ctx: &mut Ctx) -> Result<(), Repl } } } - Ok(()) + Ok(rdata) } diff --git a/tests/snapshots/flex/test_app_mainmenu/00001.png b/tests/snapshots/flex/test_app_mainmenu/00001.png index ae54aa8..38aa871 100644 Binary files a/tests/snapshots/flex/test_app_mainmenu/00001.png and b/tests/snapshots/flex/test_app_mainmenu/00001.png differ diff --git a/tests/snapshots/nanosp/test_app_mainmenu/00001.png b/tests/snapshots/nanosp/test_app_mainmenu/00001.png index 0cf775b..72cca37 100644 Binary files a/tests/snapshots/nanosp/test_app_mainmenu/00001.png and b/tests/snapshots/nanosp/test_app_mainmenu/00001.png differ diff --git a/tests/snapshots/nanox/test_app_mainmenu/00001.png b/tests/snapshots/nanox/test_app_mainmenu/00001.png index 0cf775b..72cca37 100644 Binary files a/tests/snapshots/nanox/test_app_mainmenu/00001.png and b/tests/snapshots/nanox/test_app_mainmenu/00001.png differ diff --git a/tests/snapshots/stax/test_app_mainmenu/00001.png b/tests/snapshots/stax/test_app_mainmenu/00001.png index db69414..a4fe05f 100644 Binary files a/tests/snapshots/stax/test_app_mainmenu/00001.png and b/tests/snapshots/stax/test_app_mainmenu/00001.png differ