-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add transaction signing APDU handling and display.
- Loading branch information
1 parent
3b35d0d
commit cb572c8
Showing
7 changed files
with
444 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/***************************************************************************** | ||
* Ledger App Boilerplate Rust. | ||
* (c) 2023 Ledger SAS. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*****************************************************************************/ | ||
|
||
use crate::handlers::sign_tx::Tx; | ||
use crate::utils::{concatenate, to_hex_all_caps}; | ||
use crate::SW_TX_DISPLAY_FAIL; | ||
use core::str::from_utf8; | ||
use nanos_sdk::io::Reply; | ||
use nanos_ui::bitmaps::{CROSSMARK, EYE, VALIDATE_14}; | ||
use nanos_ui::ui::{Field, MultiFieldReview}; | ||
use numtoa::NumToA; | ||
// use nanos_sdk::testing; | ||
|
||
pub fn ui_display_tx(tx: &Tx) -> Result<bool, Reply> { | ||
// Format amount value | ||
let mut amount_buf = [0u8; 20]; | ||
let mut amount_with_denom_buf = [0u8; 25]; | ||
concatenate( | ||
&["CRAB", " ", tx.value.numtoa_str(10, &mut amount_buf)], | ||
&mut amount_with_denom_buf, | ||
); | ||
let amount_str_with_denom = from_utf8(&amount_with_denom_buf) | ||
.map_err(|_| Reply(SW_TX_DISPLAY_FAIL))? | ||
.trim_matches(char::from(0)); | ||
|
||
// Format destination address | ||
let hex_addr_buf = to_hex_all_caps(&tx.to).map_err(|_| Reply(SW_TX_DISPLAY_FAIL))?; | ||
let hex_addr_str = from_utf8(&hex_addr_buf).map_err(|_| Reply(SW_TX_DISPLAY_FAIL))?; | ||
let mut addr_with_prefix_buf = [0u8; 42]; | ||
concatenate(&["0x", hex_addr_str], &mut addr_with_prefix_buf); | ||
let hex_addr_str_with_prefix = | ||
from_utf8(&addr_with_prefix_buf).map_err(|_| Reply(SW_TX_DISPLAY_FAIL))?; | ||
|
||
// Format memo | ||
let memo_str = from_utf8(&tx.memo[..tx.memo_len]).map_err(|_| Reply(SW_TX_DISPLAY_FAIL))?; | ||
|
||
// Define transaction review fields | ||
let my_fields = [ | ||
Field { | ||
name: "Amount", | ||
value: amount_str_with_denom, | ||
}, | ||
Field { | ||
name: "Destination", | ||
value: hex_addr_str_with_prefix, | ||
}, | ||
Field { | ||
name: "Memo", | ||
value: memo_str, | ||
}, | ||
]; | ||
|
||
// Create transaction review | ||
let my_review = MultiFieldReview::new( | ||
&my_fields, | ||
&["Review ", "Transaction"], | ||
Some(&EYE), | ||
"Approve", | ||
Some(&VALIDATE_14), | ||
"Reject", | ||
Some(&CROSSMARK), | ||
); | ||
|
||
Ok(my_review.show()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.