Skip to content

Commit

Permalink
Merge pull request #1 from Zondax/ft/keys_generation
Browse files Browse the repository at this point in the history
Keys generation
  • Loading branch information
ftheirs authored Mar 15, 2024
2 parents 100c49b + cc6a16b commit e8c705c
Show file tree
Hide file tree
Showing 83 changed files with 1,794 additions and 537 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Created by .ignore support plugin (hsz.mobi)
### C template
### C Ironfish
# Prerequisites
*.d

Expand Down Expand Up @@ -76,3 +76,5 @@ tests_zemu/yarn.lock
tests_tools/target
fuzz-*.log
/scan-build
app/rust/.cargo/registry
app/rust/.cargo/.package-cache*
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
[submodule "deps/stax-secure-sdk"]
path = deps/stax-secure-sdk
url = https://github.com/LedgerHQ/ledger-secure-sdk
[submodule "deps/blake2"]
path = deps/blake2
url = https://github.com/Zondax/BLAKE2.git
66 changes: 64 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
#* limitations under the License.
#********************************************************************************
cmake_minimum_required(VERSION 3.0)
project(ledger-template VERSION 0.0.0)
project(ledger-ironfish VERSION 0.0.0)
enable_testing()

cmake_policy(SET CMP0025 NEW)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)

option(ENABLE_FUZZING "Build with fuzzing instrumentation and build fuzz targets" OFF)
option(ENABLE_COVERAGE "Build with source code coverage instrumentation" OFF)
Expand Down Expand Up @@ -116,6 +116,11 @@ file(GLOB_RECURSE LIB_SRC
####
${CMAKE_CURRENT_SOURCE_DIR}/app/src/parser.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/parser_impl.c
####
${CMAKE_CURRENT_SOURCE_DIR}/app/src/crypto_helper.c
####
${CMAKE_CURRENT_SOURCE_DIR}/deps/blake2/ref/blake2b-ref.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/blake2s/blake2s-ref.c
)

add_library(app_lib STATIC ${LIB_SRC})
Expand All @@ -125,9 +130,63 @@ target_include_directories(app_lib PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/app/src
${CMAKE_CURRENT_SOURCE_DIR}/app/src/lib
${CMAKE_CURRENT_SOURCE_DIR}/app/src/common
###
${CMAKE_CURRENT_SOURCE_DIR}/app/rust/include
###
${CMAKE_CURRENT_SOURCE_DIR}/deps/blake2/ref

)

##############################################################
## Rust library for CPP tests
set(RUST_LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/app/rust")

# Determine the Rust target triple based on the host system
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
set(RUST_TARGET_TRIPLE "aarch64-unknown-linux-gnu")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
set(RUST_TARGET_TRIPLE "x86_64-unknown-linux-gnu")
else()
message(FATAL_ERROR "Unsupported processor: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
endif()
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "arm64")
set(RUST_TARGET_TRIPLE "aarch64-apple-darwin")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
set(RUST_TARGET_TRIPLE "x86_64-apple-darwin")
else()
message(FATAL_ERROR "Unsupported processor: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
endif()
else()
message(FATAL_ERROR "Unsupported host system: ${CMAKE_HOST_SYSTEM_NAME}")
endif()

# Use debug mode for debugging tests
set(RUST_TARGET_DIR "${RUST_LIB_DIR}/target/${RUST_TARGET_TRIPLE}/debug")

# Custom target for the Rust library
add_custom_target(RustLibClean
COMMAND cargo clean
WORKING_DIRECTORY ${RUST_LIB_DIR}
)
add_custom_target(RustLibBuild
COMMAND cargo build --target ${RUST_TARGET_TRIPLE} --features cpp_tests
WORKING_DIRECTORY ${RUST_LIB_DIR}
DEPENDS RustLibClean
)

# Assuming the Rust library outputs a file named librslib.a
set(RUST_LIB "${RUST_TARGET_DIR}/librslib.a")

# Ensure the Rust library is built before the C++ project
add_library(rslib STATIC IMPORTED)
set_property(TARGET rslib PROPERTY IMPORTED_LOCATION ${RUST_LIB})
add_dependencies(rslib RustLibBuild)

# Ensure your C++ targets depend on the Rust library being built first
# For example, for your app_lib static library:
add_dependencies(app_lib rslib)
##############################################################
# Tests
file(GLOB_RECURSE TESTS_SRC
Expand All @@ -141,11 +200,14 @@ target_include_directories(unittests PRIVATE
${CONAN_INCLUDE_DIRS_JSONCPP}
${CMAKE_CURRENT_SOURCE_DIR}/app/src
${CMAKE_CURRENT_SOURCE_DIR}/app/src/lib
###
${CMAKE_CURRENT_SOURCE_DIR}/deps/blake2/ref
)

target_link_libraries(unittests PRIVATE
gtest_main
app_lib
rslib
CONAN_PKG::fmt
CONAN_PKG::jsoncpp)

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# BOLOS_SDK IS DEFINED We use the plain Makefile for Ledger
# BOLOS_SDK NOT DEFINED We use a containerized build approach

TESTS_JS_PACKAGE = "@zondax/ledger-template"
TESTS_JS_PACKAGE = "@zondax/ledger-ironfish"
TESTS_JS_DIR = $(CURDIR)/js

ifeq ($(BOLOS_SDK),)
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Ledger Template app
# Ledger Ironfish app
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![GithubActions](https://github.com/Zondax/ledger-template/actions/workflows/main.yml/badge.svg)](https://github.com/Zondax/ledger-template/blob/main/.github/workflows/main.yaml)
[![GithubActions](https://github.com/Zondax/ledger-ironfish/actions/workflows/main.yml/badge.svg)](https://github.com/Zondax/ledger-ironfish/blob/main/.github/workflows/main.yaml)

---

Expand All @@ -11,9 +11,9 @@ _Please visit our website at [zondax.ch](https://www.zondax.ch)_

---

This project contains the Template app for Ledger Nano S Nano S+ and X.
This project contains the Ironfish app for Ledger Nano S Nano S+ and X.

- Ledger Nano S/S+/X Template app
- Ledger Nano S/S+/X Ironfish app
- Specs / Documentation
- C++ unit tests
- Zemu tests
Expand All @@ -32,7 +32,7 @@ Please:
*Once the app is approved by Ledger, it will be available in their app store (Ledger Live).
You can get builds generated by Github Actions from the release tab. THESE ARE UNVETTED DEVELOPMENT RELEASES*

Download a release from here (https://github.com/Zondax/ledger-template/releases). You only need `installer.sh`
Download a release from here (https://github.com/Zondax/ledger-ironfish/releases). You only need `installer.sh`

If the file is not executable, run
```sh
Expand Down
58 changes: 21 additions & 37 deletions app/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#*******************************************************************************
# Ledger App
# (c) 2018 - 2023 Zondax AG
# (c) 2018 - 2024 Zondax AG
# (c) 2017 Ledger
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -30,25 +30,18 @@ $(info ************ TARGET_NAME = [$(TARGET_NAME)])

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.app_testing

# #{TODO} --> Need for an special mode?
# DEFINES += REVIEW_SCREEN_ENABLED APP_BLIND_MODE_ENABLED

ifndef COIN
COIN=TODO
COIN=IRON
endif

include $(CURDIR)/Makefile.version

$(info COIN = [$(COIN)])

ifeq ($(COIN),TODO)
ifeq ($(COIN),IRON)
# Main app configuration
DEFINES += APP_STANDARD
ifneq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += SUBSTRATE_PARSER_FULL
endif
APPNAME = "Template"
APPPATH = "44'/283'"
APPNAME = "Ironfish"
APPPATH = "44'/133'"

else
define error_message
Expand All @@ -71,39 +64,30 @@ $(error ICONNAME is not set)
endif

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.platform
CFLAGS += -Wvla
# #{TODO} --> Need Rust?
# LDFLAGS += -z muldefs
# LDLIBS += -Lrust/target/thumbv6m-none-eabi/release -lrslib
# APP_SOURCE_PATH += $(CURDIR)/rust/include

# #{TODO} --> Need Rust?
# Add SDK BLAKE2b
DEFINES += HAVE_HASH HAVE_BLAKE2
INCLUDES_PATH += $(BOLOS_SDK)/lib_cxng/src


# Building Rust
LDFLAGS += -z muldefs
LDLIBS += -L$(MY_DIR)rust/target/$(RUST_TARGET)/release -lrslib

APP_SOURCE_PATH += $(CURDIR)/rust/include
APP_CUSTOM_LINK_DEPENDENCIES = rust
RUST_TARGET:=thumbv6m-none-eabi

.PHONY: rust
rust:
@echo "No rust code"

# Before linking, we need to be sure rust lib is there
bin/app.elf: rust
cd rust && RUSTC_BOOTSTRAP=1 CARGO_HOME="$(CURDIR)/rust/.cargo" cargo build --target $(RUST_TARGET) --release

.PHONY: rust_clean
rust_clean:
@echo "No rust code"
cd rust && CARGO_HOME="$(CURDIR)/rust/.cargo" cargo clean

clean: rust_clean

# .PHONY: rust
# rust:
# cd rust && CARGO_HOME="$(CURDIR)/rust/.cargo" cargo build --target thumbv6m-none-eabi --release

# # Before linking, we need to be sure rust lib is there
# bin/app.elf: rust

# .PHONY: rust_clean
# rust_clean:
# cd rust && CARGO_HOME="$(CURDIR)/rust/.cargo" cargo clean

# clean: rust_clean

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.side_loading

# Import generic rules from the SDK
Expand All @@ -113,7 +97,7 @@ include $(BOLOS_SDK)/Makefile.rules
dep/%.d: %.c Makefile

listvariants:
@echo VARIANTS COIN template
@echo VARIANTS COIN IRON

.PHONY: version
version:
Expand Down
13 changes: 13 additions & 0 deletions app/rust/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[build]

[target.'cfg(all(target_arch = "arm", target_os = "none"))']
rustflags = [
"--emit", "asm",
"-C", "relocation-model=ropi",
"-C", "link-arg=-nostartfiles",
"-C", "link-arg=-Tlink.ld",
"-C", "inline-threshold=0"
]
[unstable]
build-std=["core"]
build-std-features=["panic_immediate_abort"]
114 changes: 114 additions & 0 deletions app/rust/Cargo.lock

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

Loading

0 comments on commit e8c705c

Please sign in to comment.