Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico Ginosa committed May 3, 2020
0 parents commit fb29a02
Show file tree
Hide file tree
Showing 336 changed files with 104,947 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# top-most EditorConfig file
root = true

[*]
charset = utf-8
trim_trailing_whitespace = true
end_of_line = lf
insert_final_newline = true

[*.{c,h,cpp,hpp}]
indent_style = space
indent_size = 4

[*.{yml,sh}]
indent_style = space
indent_size = 2
97 changes: 97 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Created by .ignore support plugin (hsz.mobi)
### C template
# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

\cmake-build-debug
\.idea/
/tmp/
/deps/nano2-sdk/

# Created by cmake
googletest-download/
googletest-src/
googletest-build/
CMakeFiles/
CMakeCache.txt
unittests
*.cmake
Testing/
cmake-build-fuzz/

# Others
/cmake-build-debug/
/cmake-build-fuzz/
\.idea
/app/bin/
/app/debug/
/app/obj/

\deps/*
!\deps/nanos-secure-sdk
\deps/nano2-sdk
!\deps/ledger-zxlib
!\deps/tinycbor
!\deps/tinycbor-ledger

# Python
.envs

# MacOS
.DS_Store

# Vscode
.vscode
.DS_Store
.idea
__pycache__
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "deps/nanos-secure-sdk"]
path = deps/nanos-secure-sdk
url = https://github.com/LedgerHQ/nanos-secure-sdk.git
97 changes: 97 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#*******************************************************************************
#* (c) 2018 ZondaX GmbH
#*
#* Licensed under the Apache License, Version 2.0 (the "License");
#* you may not use this file except in compliance with the License.
#* You may obtain a copy of the License at
#*
#* http://www.apache.org/licenses/LICENSE-2.0
#*
#* Unless required by applicable law or agreed to in writing, software
#* distributed under the License is distributed on an "AS IS" BASIS,
#* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#* See the License for the specific language governing permissions and
#* limitations under the License.
#********************************************************************************
cmake_minimum_required(VERSION 3.0)
project(ledger-idena VERSION 0.0.0)
enable_testing()

cmake_policy(SET CMP0025 NEW)
set(CMAKE_CXX_STANDARD 11)

include(cmake/conan/CMakeLists.txt)
add_subdirectory(cmake/gtest)

string(APPEND CMAKE_CXX_FLAGS " -fsanitize=address -fno-omit-frame-pointer")
string(APPEND CMAKE_LINKER_FLAGS " -fsanitize=address -fno-omit-frame-pointer")

##############################################################
##############################################################
# static libs
file(GLOB_RECURSE TINYCBOR_SRC
${CMAKE_CURRENT_SOURCE_DIR}/deps/tinycbor/src/cborparser.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/tinycbor/src/cborvalidation.c
)

file(GLOB_RECURSE LIB_SRC
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/src/hexutils.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/src/bignum.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/src/zxmacros.c
#########
${CMAKE_CURRENT_SOURCE_DIR}/app/src/parser.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/parser_impl.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/src/bech32.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/src/segwit_addr.c
)

add_library(app_lib STATIC
${LIB_SRC}
${TINYCBOR_SRC}
)

target_include_directories(app_lib PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/include
${CMAKE_CURRENT_SOURCE_DIR}/deps/tinycbor/src
${CMAKE_CURRENT_SOURCE_DIR}/app/src
${CMAKE_CURRENT_SOURCE_DIR}/app/src/lib
${CMAKE_CURRENT_SOURCE_DIR}/app/src/common
)

##############################################################
##############################################################
# Tests
file(GLOB_RECURSE TESTS_SRC
${CMAKE_CURRENT_SOURCE_DIR}/tests/*.cpp)

add_executable(unittests ${TESTS_SRC})
target_include_directories(unittests PUBLIC
${gtest_SOURCE_DIR}/include
${gmock_SOURCE_DIR}/include
${CONAN_INCLUDE_DIRS_FMT}
${CONAN_INCLUDE_DIRS_JSONCPP}
${CMAKE_CURRENT_SOURCE_DIR}/deps/tinycbor/src
)

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

add_test(unittests ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittests)
set_tests_properties(unittests PROPERTIES WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests)

###############################################################
# Force tests to depend from app compiling
###############################################################

#set(DISABLE_DOCKER_BUILDS OFF CACHE BOOL "Disables Docker Builds")
#
#if (NOT DISABLE_DOCKER_BUILDS)
# add_custom_target(ledger_app
# COMMAND make build
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
# )
# add_dependencies(unittests ledger_app)
#endif()
125 changes: 125 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Ledger Idena app
This repository contains:

- Ledger Nano S/X Idena app
- Specs / Documentation
- C++ unit tests

## Installing

# Building

At the moment, the only option is to build the app on your own. **Please only use a TEST DEVICE!**

Once the app is ready and we reach v1.0.0, it will be submitted to Ledger so it is published in the app Catalog.

## Dependencies

### Ledger Nano S

- This project requires Ledger firmware 1.6

- The current repository keeps track of Ledger's SDK but it is possible to override it by changing the git submodule.

### Docker CE

- Please install docker CE. The instructions can be found here: https://docs.docker.com/install/

### Ubuntu Dependencies
- Install the following packages:
```
sudo apt update && apt-get -y install build-essential git wget cmake \
libssl-dev libgmp-dev autoconf libtool
```

### Python Dependencies
- virtualenv must use python3
```
virtualenv .envs/ledger -p python3
source .envs/ledger/bin/activate
pip install -r requirements.txt
```

### Prepare your development device

**Please do not use a Ledger device with funds for development purposes.**

**Have a second device that is used ONLY for development and testing**

There are a few additional steps that increase reproducibility and simplify development:

**1 - Ensure your device works in your OS**
- In Linux hosts it might be necessary to adjust udev rules, etc. Refer to Ledger documentation: https://support.ledger.com/hc/en-us/articles/115005165269-Fix-connection-issues
- In MaxOS Ledger Live app must be closed

**2 - Set a test mnemonic**

All our tests expect the device to be configured with a known test mnemonic.

- Plug your device while pressing the right button

- Your device will show "Recovery" in the screen

- Double click

- Run `make dev_init`. This will take about 2 minutes. The device will be initialized to:

```
PIN: 5555
Mnemonic: equip will roof matter pink blind book anxiety banner elbow sun young
Private key index 0: dfa1be0964f736f1534e135428d5704ee2505dfae0a4075a694018d9aa7518c9
```

**3 - Add a development certificate**

- Plug your device while pressing the right button

- Your device will show "Recovery" in the screen

- Click both buttons at the same time

- Enter your pin if necessary

- Run `make dev_ca`. The device will receive a development certificate to avoid constant manual confirmations.


# Building the Ledger App

The Makefile will build the firmware in a docker container and leave the binary in the correct directory.

- Build

The following command will build the app firmware inside a container and load to your device:
```
source .envs/ledger/bin/activate
make # Builds the app
```

- Upload to a device
The following command will upload the application to the ledger. _Warning: The application will be deleted before uploading._
```
source .envs/ledger/bin/activate
make load # Builds and loads the app to the device
```

# Development (EMU)

## Run emulated app

### MacOS Dependencies
- Install [xQuartz](https://www.xquartz.org/)

### First time EMU execution
```
source .envs/ledger/bin/activate
open -a XQuartz
xhost + $(hostname)
export DISPLAY=docker.for.mac.localhost:0
make env
```

### EMU execution
```
source ledger/bin/activate
make env
```
Loading

0 comments on commit fb29a02

Please sign in to comment.