Skip to content

Commit

Permalink
Use blind signing dedicated API
Browse files Browse the repository at this point in the history
  • Loading branch information
yogh333 committed Sep 18, 2024
1 parent 76916f0 commit ea9ec8f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
6 changes: 1 addition & 5 deletions ledger_device_sdk/src/nbgl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use alloc::ffi::CString;
use alloc::vec::Vec;
use core::ffi::{c_char, c_int};
use core::mem::transmute;
use include_gif::include_gif;
use ledger_secure_sdk_sys::*;

#[no_mangle]
Expand Down Expand Up @@ -210,15 +209,12 @@ trait ToMessage {
}

impl TransactionType {
pub fn to_c_type(&self, blind: bool, skippable: bool) -> nbgl_operationType_t {
fn to_c_type(&self, skippable: bool) -> nbgl_operationType_t {
let mut tx_type = match self {
TransactionType::Transaction => TYPE_TRANSACTION.into(),
TransactionType::Message => TYPE_MESSAGE.into(),
TransactionType::Operation => TYPE_OPERATION.into(),
};
if blind {
tx_type |= BLIND_OPERATION;
}
if skippable {
tx_type |= SKIPPABLE_OPERATION;
}
Expand Down
34 changes: 25 additions & 9 deletions ledger_device_sdk/src/nbgl/nbgl_review.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,31 @@ impl<'a> NbglReview<'a> {

// Show the review on the device.
self.ux_sync_init();
nbgl_useCaseReview(
self.tx_type.to_c_type(self.blind, false),
&tag_value_list as *const nbgl_contentTagValueList_t,
&icon as *const nbgl_icon_details_t,
self.title.as_ptr() as *const c_char,
self.subtitle.as_ptr() as *const c_char,
self.finish_title.as_ptr() as *const c_char,
Some(choice_callback),
);
match self.blind {
true => {
nbgl_useCaseReviewBlindSigning(
self.tx_type.to_c_type(false),
&tag_value_list as *const nbgl_contentTagValueList_t,
&icon as *const nbgl_icon_details_t,
self.title.as_ptr() as *const c_char,
self.subtitle.as_ptr() as *const c_char,
self.finish_title.as_ptr() as *const c_char,
core::ptr::null(),
Some(choice_callback),
);
}
false => {
nbgl_useCaseReview(
self.tx_type.to_c_type(false),
&tag_value_list as *const nbgl_contentTagValueList_t,
&icon as *const nbgl_icon_details_t,
self.title.as_ptr() as *const c_char,
self.subtitle.as_ptr() as *const c_char,
self.finish_title.as_ptr() as *const c_char,
Some(choice_callback),
);
}
}
let sync_ret = self.ux_sync_wait(false);

// Return true if the user approved the transaction, false otherwise.
Expand Down
27 changes: 20 additions & 7 deletions ledger_device_sdk/src/nbgl/nbgl_streaming_review.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,26 @@ impl NbglStreamingReview {
let subtitle = CString::new(subtitle).unwrap();

self.ux_sync_init();
nbgl_useCaseReviewStreamingStart(
self.tx_type.to_c_type(self.blind, false),
&self.icon as *const nbgl_icon_details_t,
title.as_ptr() as *const c_char,
subtitle.as_ptr() as *const c_char,
Some(choice_callback),
);
match self.blind {
true => {
nbgl_useCaseReviewStreamingBlindSigningStart(
self.tx_type.to_c_type(false),
&self.icon as *const nbgl_icon_details_t,
title.as_ptr() as *const c_char,
subtitle.as_ptr() as *const c_char,
Some(choice_callback),
);
}
false => {
nbgl_useCaseReviewStreamingStart(
self.tx_type.to_c_type(false),
&self.icon as *const nbgl_icon_details_t,
title.as_ptr() as *const c_char,
subtitle.as_ptr() as *const c_char,
Some(choice_callback),
);
}
}
let sync_ret = self.ux_sync_wait(false);

// Return true if the user approved the transaction, false otherwise.
Expand Down

0 comments on commit ea9ec8f

Please sign in to comment.