Skip to content
Closed
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

members = [
"utils",
# "app"
]

exclude = [ "app" ]
14 changes: 12 additions & 2 deletions app/Cargo.lock

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

2 changes: 1 addition & 1 deletion app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["alephium devs"]
edition = "2021"

[dependencies]
nanos_sdk = { git = "https://github.com/LedgerHQ/ledger-nanos-sdk.git" }
nanos_sdk = { git = "https://github.com/LedgerHQ/ledger-nanos-sdk.git", rev = "4d9bfc6183d94cee6edb239c39286be3825cc179" }
nanos_ui = { git = "https://github.com/LedgerHQ/ledger-nanos-ui.git", rev = "c7fe3dff2417f9a118ad176d578c5c1ee07e83cd" }
utils= { path = "../utils" }

Expand Down
2 changes: 1 addition & 1 deletion app/src/app_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::ptr::null;
#[cfg(feature = "debug")]
pub mod print {

use nanos_sdk::debug_print;
use nanos_sdk::testing::debug_print;

pub fn println(s: &str) {
debug_print(s);
Expand Down
28 changes: 17 additions & 11 deletions app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![no_main]

use nanos_sdk::buttons::ButtonEvent;
use nanos_sdk::ecc::SeedDerive;
use nanos_ui::layout;
use nanos_ui::layout::Draw;
use nanos_ui::layout::StringPlace;
Expand Down Expand Up @@ -34,7 +35,7 @@ fn sign_ui(path: &[u32], message: &[u8]) -> Result<Option<([u8; 72], u32)>, Sysc
}

if ui::Validator::new("Sign ?").ask() {
let signature = Secp256k1::from_bip32(path)
let signature = Secp256k1::derive_from_path(path)
.deterministic_sign(message)
.map_err(|_| SyscallError::Unspecified)?;
ui::SingleMessage::new("Signing...").show();
Expand Down Expand Up @@ -150,13 +151,14 @@ enum Ins {
SignHash,
}

impl From<u8> for Ins {
fn from(ins: u8) -> Ins {
match ins {
0 => Ins::GetVersion,
1 => Ins::GetPubKey,
2 => Ins::SignHash,
_ => panic!(),
impl TryFrom<io::ApduHeader> for Ins {
type Error = ();
fn try_from(header: io::ApduHeader) -> Result<Self, Self::Error> {
match header.ins {
0 => Ok(Ins::GetVersion),
1 => Ok(Ins::GetPubKey),
2 => Ok(Ins::SignHash),
_ => Err(()),
}
}
}
Expand All @@ -169,6 +171,10 @@ fn handle_apdu(comm: &mut io::Comm, ins: Ins) -> Result<bool, Reply> {
}

let mut path: [u32; 5] = [0; 5];
let apdu_header = comm.get_apdu_metadata();
if apdu_header.cla != 0x80 {
return Err(io::StatusWords::BadCla.into());
}

match ins {
Ins::GetVersion => {
Expand All @@ -186,8 +192,8 @@ fn handle_apdu(comm: &mut io::Comm, ins: Ins) -> Result<bool, Reply> {
}
println_slice::<40>(raw_path);

let p1 = comm.get_p1();
let p2 = comm.get_p2();
let p1 = apdu_header.p1;
let p2 = apdu_header.p2;

let (pk, hd_index) = if p1 == 0 {
(derive_pub_key(& mut path)?, path[path.len() - 1])
Expand Down Expand Up @@ -226,7 +232,7 @@ fn handle_apdu(comm: &mut io::Comm, ins: Ins) -> Result<bool, Reply> {
}

fn derive_pub_key(path: &[u32]) -> Result<ECPublicKey<65, 'W'>, Reply> {
let pk = Secp256k1::from_bip32(path)
let pk = Secp256k1::derive_from_path(path)
.public_key()
.map_err(|x| Reply(0x6eu16 | (x as u16 & 0xff)))?;
return Ok(pk);
Expand Down