diff --git a/rust-app/Cargo.lock b/rust-app/Cargo.lock index 4f97510..4e08760 100644 --- a/rust-app/Cargo.lock +++ b/rust-app/Cargo.lock @@ -31,8 +31,8 @@ dependencies = [ [[package]] name = "alamgu-async-block" -version = "0.1.1" -source = "git+https://github.com/alamgu/alamgu-async-block#a420f4f1f4bde0748ebe65aa43bd11d3e8d92661" +version = "0.1.2" +source = "git+https://github.com/alamgu/alamgu-async-block#bd8c9abe1cd8f3a952e1b95b4adec4039874df10" dependencies = [ "arrayvec", "ledger-log", @@ -256,8 +256,8 @@ dependencies = [ [[package]] name = "ledger-parser-combinators" -version = "0.1.1" -source = "git+https://github.com/alamgu/ledger-parser-combinators?branch=async-split-take-2#f2eda29c67c0da3f415aca1457dc6b5e9c594748" +version = "0.1.2" +source = "git+https://github.com/alamgu/ledger-parser-combinators?branch=async-split-take-2#90662ff6e74ddb280fae3a145815bec12ad38120" dependencies = [ "arrayvec", "bstringify", diff --git a/rust-app/src/implementation.rs b/rust-app/src/implementation.rs index 9154cc3..70c3429 100644 --- a/rust-app/src/implementation.rs +++ b/rust-app/src/implementation.rs @@ -8,7 +8,7 @@ use core::fmt::Write; use ledger_crypto_helpers::common::{try_option, Address, HexSlice}; use ledger_crypto_helpers::eddsa::{ed25519_public_key_bytes, eddsa_sign, with_public_keys}; use ledger_crypto_helpers::hasher::{Blake2b, Hasher, HexHash}; -use ledger_device_sdk::io::SyscallError; +use ledger_device_sdk::io::{StatusWords, SyscallError}; use ledger_log::trace; use ledger_parser_combinators::async_parser::*; use ledger_parser_combinators::bcs::async_parser::*; @@ -57,13 +57,13 @@ pub const BIP32_PREFIX: [u32; 5] = pub async fn get_address_apdu(io: HostIO, prompt: bool) { let input = match io.get_params::<1>() { Some(v) => v, - None => reject().await, + None => reject(SyscallError::InvalidParameter as u16).await, }; let path = BIP_PATH_PARSER.parse(&mut input[0].clone()).await; if !path.starts_with(&BIP32_PREFIX[0..2]) { - reject::<()>().await; + reject::<()>(SyscallError::InvalidParameter as u16).await; } let mut rv = ArrayVec::::new(); @@ -90,7 +90,7 @@ pub async fn get_address_apdu(io: HostIO, prompt: bool) { }) .is_err() { - reject::<()>().await; + reject::<()>(StatusWords::UserCancelled as u16).await; } io.result_final(&rv).await; @@ -161,13 +161,25 @@ impl AsyncParser for DefaultInterp { ) .await; } - _ => reject_on(core::file!(), core::line!()).await, + _ => { + reject_on( + core::file!(), + core::line!(), + SyscallError::NotSupported as u16, + ) + .await + } } CallArg::ObjectArg } _ => { trace!("CallArgSchema: Unknown enum: {}", enum_variant); - reject_on(core::file!(), core::line!()).await + reject_on( + core::file!(), + core::line!(), + SyscallError::NotSupported as u16, + ) + .await } } } @@ -223,7 +235,12 @@ impl AsyncParser for DefaultInterp { } _ => { trace!("CommandSchema: Unknown enum: {}", enum_variant); - reject_on(core::file!(), core::line!()).await + reject_on( + core::file!(), + core::line!(), + SyscallError::NotSupported as u16, + ) + .await } } } @@ -275,7 +292,14 @@ impl AsyncParser for DefaultInterp { .await, ) } - _ => reject_on(core::file!(), core::line!()).await, + _ => { + reject_on( + core::file!(), + core::line!(), + SyscallError::NotSupported as u16, + ) + .await + } } } } @@ -316,13 +340,27 @@ impl AsyncParser reject_on(core::file!(), core::line!()).await, + _ => { + reject_on( + core::file!(), + core::line!(), + SyscallError::NotSupported as u16, + ) + .await + } }, CallArg::Amount(amt) => { #[allow(clippy::single_match)] match amounts.try_push((amt, i)) { - Err(_) => reject_on(core::file!(), core::line!()).await, + Err(_) => { + reject_on( + core::file!(), + core::line!(), + SyscallError::NotSupported as u16, + ) + .await + } _ => {} } } @@ -332,7 +370,12 @@ impl AsyncParser(core::file!(), core::line!()).await; + reject_on::<()>( + core::file!(), + core::line!(), + SyscallError::NotSupported as u16, + ) + .await; } let mut verified_recipient = false; @@ -352,23 +395,47 @@ impl AsyncParser { if verified_recipient { // Reject more than one TransferObject(s) - reject_on::<()>(core::file!(), core::line!()).await; + reject_on::<()>( + core::file!(), + core::line!(), + SyscallError::NotSupported as u16, + ) + .await; } match recipient_input { Argument::Input(inp_index) => { if Some(inp_index as u32) != recipient_index { trace!("TransferObject recipient mismatch"); - reject_on::<()>(core::file!(), core::line!()).await; + reject_on::<()>( + core::file!(), + core::line!(), + SyscallError::NotSupported as u16, + ) + .await; } verified_recipient = true; } - _ => reject_on(core::file!(), core::line!()).await, + _ => { + reject_on( + core::file!(), + core::line!(), + SyscallError::NotSupported as u16, + ) + .await + } } } Command::SplitCoins(coin, input_indices) => { match coin { Argument::GasCoin => {} - _ => reject_on(core::file!(), core::line!()).await, + _ => { + reject_on( + core::file!(), + core::line!(), + SyscallError::NotSupported as u16, + ) + .await + } } for arg in &input_indices { match arg { @@ -378,14 +445,25 @@ impl AsyncParser total_amount = t, None => { - reject_on(core::file!(), core::line!()) - .await + reject_on( + core::file!(), + core::line!(), + SyscallError::InvalidParameter as u16, + ) + .await } } } } } - _ => reject_on(core::file!(), core::line!()).await, + _ => { + reject_on( + core::file!(), + core::line!(), + SyscallError::NotSupported as u16, + ) + .await + } } } } @@ -394,7 +472,12 @@ impl AsyncParser(core::file!(), core::line!()).await; + reject_on::<()>( + core::file!(), + core::line!(), + SyscallError::NotSupported as u16, + ) + .await; } if PROMPT @@ -415,7 +498,7 @@ impl AsyncParser().await; + reject::<()>(StatusWords::UserCancelled as u16).await; } } } @@ -444,7 +527,12 @@ impl AsyncParser { trace!("TransactionKind: {}", enum_variant); - reject_on(core::file!(), core::line!()).await + reject_on( + core::file!(), + core::line!(), + SyscallError::NotSupported as u16, + ) + .await } } } @@ -492,7 +580,14 @@ impl AsyncParser for DefaultInt trace!("TransactionExpiration: Epoch"); >::parse(&DefaultInterp, input).await; } - _ => reject_on(core::file!(), core::line!()).await, + _ => { + reject_on( + core::file!(), + core::line!(), + SyscallError::NotSupported as u16, + ) + .await + } } } } @@ -568,7 +663,14 @@ impl AsyncParser().parse(input).await; } - _ => reject_on(core::file!(), core::line!()).await, + _ => { + reject_on( + core::file!(), + core::line!(), + SyscallError::NotSupported as u16, + ) + .await + } } } } @@ -582,7 +684,7 @@ const fn tx_parser( pub async fn sign_apdu(io: HostIO, settings: Settings) { let mut input = match io.get_params::<2>() { Some(v) => v, - None => reject().await, + None => reject(SyscallError::InvalidParameter as u16).await, }; // Read length, and move input[0] by one byte @@ -601,14 +703,14 @@ pub async fn sign_apdu(io: HostIO, settings: Settings) { if known_txn { if scroller("Transfer", |w| Ok(write!(w, "SUI")?)).is_none() { - reject::<()>().await; + reject::<()>(StatusWords::UserCancelled as u16).await; }; { let mut bs = input[1].clone(); NoinlineFut(async move { let path = BIP_PATH_PARSER.parse(&mut bs).await; if !path.starts_with(&BIP32_PREFIX[0..2]) { - reject::<()>().await; + reject::<()>(SyscallError::InvalidParameter as u16).await; } if with_public_keys(&path, true, |_, address: &SuiPubKeyAddress| { try_option(|| -> Option<()> { @@ -619,7 +721,7 @@ pub async fn sign_apdu(io: HostIO, settings: Settings) { .ok() .is_none() { - reject::<()>().await; + reject::<()>(StatusWords::UserCancelled as u16).await; } }) .await @@ -635,7 +737,7 @@ pub async fn sign_apdu(io: HostIO, settings: Settings) { }; if final_accept_prompt(&["Sign Transaction?"]).is_none() { - reject::<()>().await; + reject::<()>(StatusWords::UserCancelled as u16).await; }; } else if settings.get() == 0 { scroller("WARNING", |w| { @@ -644,9 +746,9 @@ pub async fn sign_apdu(io: HostIO, settings: Settings) { "Transaction not recognized, enable blind signing to sign unknown transactions" )?) }); - reject::<()>().await; + reject::<()>(SyscallError::NotSupported as u16).await; } else if scroller("WARNING", |w| Ok(write!(w, "Transaction not recognized")?)).is_none() { - reject::<()>().await; + reject::<()>(StatusWords::UserCancelled as u16).await; } // By the time we get here, we've approved and just need to do the signature. @@ -668,20 +770,20 @@ pub async fn sign_apdu(io: HostIO, settings: Settings) { let hash: HexHash<32> = hasher.finalize(); if !known_txn { if scroller("Transaction Hash", |w| Ok(write!(w, "0x{hash}")?)).is_none() { - reject::<()>().await; + reject::<()>(StatusWords::UserCancelled as u16).await; }; if final_accept_prompt(&["Blind Sign Transaction?"]).is_none() { - reject::<()>().await; + reject::<()>(StatusWords::UserCancelled as u16).await; }; } let path = BIP_PATH_PARSER.parse(&mut input[1].clone()).await; if !path.starts_with(&BIP32_PREFIX[0..2]) { - reject::<()>().await; + reject::<()>(SyscallError::InvalidParameter as u16).await; } if let Some(sig) = { eddsa_sign(&path, true, &hash.0).ok() } { io.result_final(&sig.0[0..]).await; } else { - reject::<()>().await; + reject::<()>(SyscallError::Unspecified as u16).await; } }) .await