Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions src/app_ui/eip712.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unused_assignments)]
use crate::{
app_ui::CFX_ICON,
eip712::{Eip712Context, CIP23_DOMAIN_TYPE_NAME, EIP712_DOMAIN_TYPE_NAME},
Expand Down Expand Up @@ -43,30 +42,35 @@ pub fn ui_display_712_message(ctx: &Eip712Context) -> Result<bool, AppSW> {
});
}

let mut chain_id_str = Default::default();
if let Some(chain_id) = ctx.eip712_domain.chain_id.as_ref() {
chain_id_str = format!("{}", chain_id);
let chain_id_str = ctx
.eip712_domain
.chain_id
.as_ref()
.map(|c| format!("{}", c));
if let Some(s) = chain_id_str.as_ref() {
my_fields.push(Field {
name: "ChainId",
value: chain_id_str.as_str(),
value: s.as_str(),
});
}

let mut contract_addr_str = Default::default();
if let Some(contract) = ctx.eip712_domain.verifying_contract.as_ref() {
contract_addr_str = format!("{}", contract);
let contract_addr_str = ctx
.eip712_domain
.verifying_contract
.as_ref()
.map(|c| format!("{}", c));
if let Some(s) = contract_addr_str.as_ref() {
my_fields.push(Field {
name: "Verifying Contract",
value: contract_addr_str.as_str(),
value: s.as_str(),
});
}

let mut salt_str = Default::default();
if let Some(salt) = ctx.eip712_domain.salt.as_ref() {
salt_str = format!("{}", salt);
let salt_str = ctx.eip712_domain.salt.as_ref().map(|s| format!("{}", s));
if let Some(s) = salt_str.as_ref() {
my_fields.push(Field {
name: "Salt",
value: salt_str.as_str(),
value: s.as_str(),
});
}

Expand Down
1 change: 0 additions & 1 deletion src/app_ui/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use ledger_device_sdk::nbgl::{Field, NbglChoice, NbglReview, PageIndex};
/// # Arguments
///
/// * `tx` - Transaction to be displayed for validation
#[allow(unused_variables)]
pub fn ui_display_tx(tx: &Transaction, ctx: &mut Context) -> Result<bool, AppSW> {
let fully_decoded = tx.fully_decoded();

Expand Down
45 changes: 2 additions & 43 deletions src/eip712/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ use alloc::{
vec::Vec,
};
use alloy_primitives::B256;
use ledger_rust_eip712::{eip712::eip712_signing_hash, parser, Eip712Domain, TypedData};
use ledger_rust_eip712::{eip712::eip712_signing_hash, Eip712Domain};
pub use ledger_rust_eip712::{types, utils, CIP23_DOMAIN_TYPE_NAME, EIP712_DOMAIN_TYPE_NAME};
use types::{
build_resolver_from_struct_defs, Eip712FieldDefinition, Eip712FieldValue,
Eip712StructDefinitions, Eip712StructImplementation,
Eip712FieldDefinition, Eip712FieldValue, Eip712StructDefinitions, Eip712StructImplementation,
};

pub struct Eip712Context {
Expand Down Expand Up @@ -106,46 +105,6 @@ impl Eip712Context {
|| self.eip712_domain.salt.is_some()
}

#[allow(unused)]
pub fn eip712_signing_hash(&mut self) -> Result<B256, &str> {
if !self.is_eip712_domain_set_up() {
return Err("no domain data");
}
if self.current_root_struct.is_none() {
return Err("no primary type");
}
let primary_type = self.current_root_struct.take().unwrap();

let resolver = build_resolver_from_struct_defs(&self.struct_definitions)?;

let type_schema = parser::build_schema(&self.struct_definitions, &primary_type)
.map_err(|_| "build schema failed")?;

// clear struct definitions to save memory
self.struct_definitions.clear();

let field_values: Vec<_> = self.current_struct_field_values.drain(..).collect();
let mut data_iter = field_values.into_iter().map(|v| v.value);

let value =
parser::build_value(&type_schema, &mut data_iter).map_err(|_| "invalid data")?;

let typed_data = TypedData {
domain: self.eip712_domain.clone(),
resolver,
primary_type,
message: value,
};

// clear domain to save memory
self.eip712_domain = Default::default();

typed_data
.eip712_signing_hash()
.map_err(|_| "signing hash compute failed")
}

//
pub fn custom_eip712_signing_hash(&mut self) -> Result<B256, &str> {
if !self.is_eip712_domain_set_up() {
return Err("no domain data");
Expand Down
1 change: 0 additions & 1 deletion src/handlers/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ impl Context {
}
}
// Get review status
#[allow(dead_code)]
pub fn finished(&self) -> bool {
self.review_finished
}
Expand Down
35 changes: 1 addition & 34 deletions src/ins_consts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(unused)]
pub const CLA: u8 = 0xe0;

pub mod ins {
Expand All @@ -13,7 +12,7 @@ pub mod ins {
/// GET APP NAME
pub const GET_APP_NAME: u8 = 0x05;
// GET APP CONFIGURATION
pub const GET_APP_CONFIGURATION: u8 = 0x06;
// pub const GET_APP_CONFIGURATION: u8 = 0x06;
/// SIGN PERSONAL MESSAGE
pub const SIGN_ETH_PERSONAL_MESSAGE: u8 = 0x07;
/// SIGN EIP 712
Expand All @@ -22,8 +21,6 @@ pub mod ins {
pub const EIP712_SEND_STRUCT_DEFINITION: u8 = 0x0B;
/// EIP712 SEND STRUCT IMPLEMENTATION
pub const EIP712_SEND_STRUCT_IMPLEMENTATION: u8 = 0x0C;
/// EIP712 FILTERING
pub const EIP712_FILTERING: u8 = 0x0D;
}

pub mod p1_sign_tx {
Expand Down Expand Up @@ -80,33 +77,3 @@ pub mod p2_eip712_struct_impl {
/// Struct field
pub const STRUCT_FIELD: u8 = 0xFF;
}

/// P1 parameter constants for EIP712 FILTERING
#[allow(unused)]
pub mod p1_eip712_filtering {
/// Standard
pub const STANDARD: u8 = 0x00;
/// Discarded
pub const DISCARDED: u8 = 0x01;
}

/// P2 parameter constants for EIP712 FILTERING
#[allow(unused)]
pub mod p2_eip712_filtering {
/// Activation
pub const ACTIVATION: u8 = 0x00;
/// Discarded filter path
pub const DISCARDED_FILTER_PATH: u8 = 0x01;
/// Message info
pub const MESSAGE_INFO: u8 = 0x0F;
/// Trusted name
pub const TRUSTED_NAME: u8 = 0xFB;
/// Date/time
pub const DATE_TIME: u8 = 0xFC;
/// Amount-join token
pub const AMOUNT_JOIN_TOKEN: u8 = 0xFD;
/// Amount-join value
pub const AMOUNT_JOIN_VALUE: u8 = 0xFE;
/// Raw field
pub const RAW_FIELD: u8 = 0xFF;
}
10 changes: 0 additions & 10 deletions src/types/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@ impl Address {
pub fn is_user_address(&self) -> bool {
self.address_type() == 0x10
}

#[allow(unused)]
pub fn is_contract_address(&self) -> bool {
self.address_type() == 0x80
}

#[allow(unused)]
pub fn is_builtin_address(&self) -> bool {
self.address_type() == 0x00
}
}

impl Decodable for Address {
Expand Down
2 changes: 1 addition & 1 deletion src/types/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub const TX_RLP_PREFIX_2930: [u8; 4] = [0x63, 0x66, 0x78, 0x01]; // "cfx" + 1
pub const TX_RLP_PREFIX_1559: [u8; 4] = [0x63, 0x66, 0x78, 0x02]; // "cfx" + 2
pub const ONE_CFX_IN_DRIP: u64 = 1_000_000_000_000_000_000;

#[allow(dead_code)]
#[allow(unused)]
#[derive(Debug, Default, Clone)]
pub struct Transaction {
pub to: Address,
Expand Down
Loading