Skip to content

Commit

Permalink
Revert "Ase new SDK API for chaincode and hash functions + add traces"
Browse files Browse the repository at this point in the history
This reverts commit f39d96b.
  • Loading branch information
yogh333 committed Feb 13, 2024
1 parent f39d96b commit 20e0f4f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 50 deletions.
18 changes: 7 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["yhql", "agrojean-ledger"]
edition = "2021"

[dependencies]
ledger_device_sdk = "1.5.1"
ledger_device_sdk = "1.5.0"
ledger_secure_sdk_sys = "1.2.0"
include_gif = "1.0.1"
serde = {version="1.0.192", default_features = false, features = ["derive"]}
Expand Down Expand Up @@ -35,7 +35,3 @@ icon = "crab_14x14.gif"

[package.metadata.ledger.nanosplus]
icon = "crab_14x14.gif"

[patch.crates-io]
ledger_device_sdk = {path = "../ledger-device-rust-sdk/ledger_device_sdk"}
ledger_secure_sdk_sys = {path = "../ledger-device-rust-sdk/ledger_secure_sdk_sys"}
39 changes: 7 additions & 32 deletions src/handlers/get_public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use crate::app_ui::address::ui_display_pk;
use crate::utils::Bip32Path;
use crate::AppSW;
use ledger_device_sdk::ecc::{Secp256k1, SeedDerive};
use ledger_device_sdk::hash::{HashId, Hasher};
use ledger_device_sdk::io::Comm;
use ledger_secure_sdk_sys::{
cx_hash_no_throw, cx_hash_t, cx_keccak_init_no_throw, cx_sha3_t, CX_LAST, CX_OK,
Expand All @@ -29,34 +28,12 @@ pub fn handler_get_public_key(comm: &mut Comm, display: bool) -> Result<(), AppS
let data = comm.get_data().map_err(|_| AppSW::WrongApduLength)?;
let path: Bip32Path = data.try_into()?;

{
let test_hash: &[u8; 29] = b"Not your keys, not your coins";

let mut keccak = Hasher::new(HashId::KECCAK_256, 32).unwrap();

let mut output: [u8; 32] = [0u8; 32];

let size = keccak.get_size().unwrap();
if size == 32 {
ledger_device_sdk::testing::debug_print("Size match \n");
} else {
ledger_device_sdk::testing::debug_print("Size mismatch \n");
}

ledger_device_sdk::testing::debug_print("Calling hash\n");

let _res = keccak.hash(test_hash, &mut output);

//let _ = keccak.hash_update(test_hash);
//let _ = keccak.hash_final(&mut output);
}

let (k, _cc) = Secp256k1::derive_from_path(path.as_ref());
let pk = k.public_key().map_err(|_| AppSW::KeyDeriveFail)?;
let pk = Secp256k1::derive_from_path(path.as_ref())
.public_key()
.map_err(|_| AppSW::KeyDeriveFail)?;

// Display address on device if requested
if display {
//let mut keccak256 = Hasher::new(HashId::KECCAK_256, 32).unwrap();
let mut keccak256: cx_sha3_t = Default::default();
let mut address: [u8; 32] = [0u8; 32];

Expand All @@ -65,12 +42,13 @@ pub fn handler_get_public_key(comm: &mut Comm, display: bool) -> Result<(), AppS
return Err(AppSW::AddrDisplayFail);
}

let pk_ptr = pk.as_ref();
let mut pk_mut = pk.pubkey;
let pk_ptr = pk_mut.as_mut_ptr().offset(1);
if cx_hash_no_throw(
&mut keccak256.header as *mut cx_hash_t,
CX_LAST,
pk_ptr[1..].as_ptr(),
pk_ptr[1..].len(),
pk_ptr,
64_usize,
address.as_mut_ptr(),
address.len(),
) != CX_OK
Expand All @@ -79,9 +57,6 @@ pub fn handler_get_public_key(comm: &mut Comm, display: bool) -> Result<(), AppS
}
}

//let pk_ptr = pk.as_ref();
//let _ = keccak256.hash(&(pk_ptr[1..]), &mut address);

if !ui_display_pk(&address)? {
return Err(AppSW::Deny);
}
Expand Down
3 changes: 1 addition & 2 deletions src/handlers/sign_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ fn compute_signature_and_append(comm: &mut Comm, ctx: &mut TxContext) -> Result<
}
}

let (k, _cc) = Secp256k1::derive_from_path(ctx.path.as_ref());
let (sig, siglen, parity) = k
let (sig, siglen, parity) = Secp256k1::derive_from_path(ctx.path.as_ref())
.deterministic_sign(&message_hash)
.map_err(|_| AppSW::TxSignFail)?;
comm.append(&[siglen as u8]);
Expand Down

0 comments on commit 20e0f4f

Please sign in to comment.