Skip to content

Commit 21ccfdb

Browse files
committed
Add support for ledger nanos
1 parent 7d5fea9 commit 21ccfdb

15 files changed

+90
-15
lines changed

.github/workflows/build_and_function_tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
node-version: 16
3232
- run: make release
3333
- run: make set-github-action
34+
- run: make run-github-ci device=nanos path=nanos
3435
- run: make run-github-ci device=nanosp path=nanosplus
3536
- run: make run-github-ci device=nanox path=nanox
3637
- run: make run-github-ci device=stax path=stax

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ ledger_app_builder = ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:$(ve
33
ledger_app_dev_tools = ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:$(version)
44

55
release:
6+
@make _release device=nanos
67
@make _release device=nanox
78
@make _release device=nanosplus
89
@make _release device=stax
@@ -26,7 +27,7 @@ check:
2627
echo 'Cargo fmt' && \
2728
cargo fmt --all -- --check && \
2829
echo 'Cargo clippy' && \
29-
cargo +nightly-2023-11-10 clippy --target=nanox && \
30+
cargo +nightly-2023-11-10 clippy --target=nanos && \
3031
cargo +nightly-2023-11-10 clippy --target=stax && \
3132
cargo install cargo-audit && cargo audit && \
3233
cargo install --locked cargo-deny && cargo +nightly-2023-11-10 deny check \
@@ -38,7 +39,10 @@ _run-speculos:
3839
speculos -m $(device) /app/app/target/$(path)/release/alephium
3940

4041
run-speculos:
41-
@make run-speculos-nanosplus
42+
@make run-speculos-nanos
43+
44+
run-speculos-nanos:
45+
@make _run-speculos device=nanos path=nanos
4246

4347
run-speculos-nanosplus:
4448
@make _run-speculos device=nanosp path=nanosplus
@@ -69,5 +73,8 @@ run-github-ci:
6973

7074
.PHONY: release clean
7175

76+
install_nanos:
77+
ledgerctl install -f nanos.json
78+
7279
install_nanosplus:
7380
ledgerctl install -f nanosplus.json

app/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ curve = ["secp256k1"]
2929
flags = "0"
3030
path = ["44'/1234'"]
3131

32+
[package.metadata.ledger.nanos]
33+
icon = "alph_16x16.gif"
34+
3235
[package.metadata.ledger.nanox]
3336
icon = "alph_14x14.gif"
3437

app/alph_16x16.gif

89 Bytes
Loading

app/src/nvm/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
#[cfg(target_os = "nanos")]
2+
use crate::nvm::nvm_data::NVMData;
3+
#[cfg(not(target_os = "nanos"))]
14
use ledger_device_sdk::NVMData;
25
use ledger_secure_sdk_sys::nvm_write;
36

47
use crate::error_code::ErrorCode;
58

9+
#[cfg(target_os = "nanos")]
10+
pub mod nvm_data;
611
pub mod swapping_buffer;
712

813
pub const NVM_DATA_SIZE: usize = 2048;

app/src/nvm/nvm_data.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pub struct NVMData<T> {
2+
data: T,
3+
}
4+
5+
impl<T> NVMData<T> {
6+
pub const fn new(data: T) -> NVMData<T> {
7+
NVMData { data }
8+
}
9+
10+
pub fn get_mut(&mut self) -> &mut T {
11+
ledger_secure_sdk_sys::pic_rs_mut(&mut self.data)
12+
}
13+
14+
pub fn get_ref(&self) -> &T {
15+
ledger_secure_sdk_sys::pic_rs(&self.data)
16+
}
17+
}

app/src/nvm/swapping_buffer.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// This code is inspired by code from zondax: https://github.com/Zondax/ledger-rust/blob/main/bolos/src/swapping_buffer.rs
22
use utils::buffer::Writable;
33

4+
#[cfg(target_os = "nanos")]
5+
use crate::nvm::nvm_data::NVMData;
46
use crate::{
57
error_code::ErrorCode,
68
nvm::{write_from, NVM},
79
};
10+
#[cfg(not(target_os = "nanos"))]
811
use ledger_device_sdk::NVMData;
912

1013
pub const RAM_SIZE: usize = 512;

app/src/sign_tx_context.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
#[cfg(target_os = "nanos")]
2+
use crate::nvm::nvm_data::NVMData;
13
use ledger_device_sdk::io::ApduHeader;
4+
#[cfg(not(target_os = "nanos"))]
25
use ledger_device_sdk::NVMData;
36
use utils::{
47
buffer::Buffer, decode::StreamingDecoder, deserialize_path, types::UnsignedTx, PATH_LENGTH,

app/src/ui/bagl/home.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const UI_PAGE_NUM: u8 = 4;
1515

1616
fn show_ui_welcome() {
1717
const APP_ICON: Glyph = Glyph::from_include(include_gif!("alph_14x14.gif"));
18-
gadgets::Page::from((["Alephium", "is ready"], &APP_ICON)).place();
18+
gadgets::Page::from((["Alephium ", "is ready"], &APP_ICON)).place();
1919
}
2020

2121
fn show_ui_blind_signing() {

app/src/ui/bagl/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn sign_hash_ui(path: &[u32], message: &[u8]) -> Result<([u8; 72], u32, u32)
1010
let hex: [u8; 64] = utils::to_hex(message).ok_or(ErrorCode::BadLen)?;
1111
let hex_str = from_utf8(&hex).map_err(|_| ErrorCode::InternalError)?;
1212

13-
let review_messages = ["Review", "Hash"];
13+
let review_messages = ["Review ", "Hash "];
1414
let fields = [Field {
1515
name: "Hash",
1616
value: hex_str,
@@ -32,7 +32,7 @@ pub fn sign_hash_ui(path: &[u32], message: &[u8]) -> Result<([u8; 72], u32, u32)
3232
}
3333

3434
pub fn review_address(address: &str) -> Result<(), ErrorCode> {
35-
let review_messages = ["Review", "Address"];
35+
let review_messages = ["Review ", "Address "];
3636
let fields = [Field {
3737
name: "Address",
3838
value: address,

0 commit comments

Comments
 (0)