Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
microengineer committed Feb 2, 2021
1 parent 829d41c commit da7c041
Show file tree
Hide file tree
Showing 74 changed files with 29,968 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "dev/sdk/nanos-secure-sdk"]
path = dev/sdk/nanos-secure-sdk
url = https://github.com/ledgerHQ/nanos-secure-sdk
[submodule "dev/sdk/nanox-secure-sdk"]
path = dev/sdk/nanox-secure-sdk
url = https://github.com/ledgerHQ/nanox-secure-sdk
186 changes: 186 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
#*******************************************************************************
# Ledger App
# (c) 2017 Ledger
#
# 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.
#*******************************************************************************

-include Makefile.env
ifeq ($(BOLOS_SDK),)
$(error Environment variable BOLOS_SDK is not set)
endif
include $(BOLOS_SDK)/Makefile.defines

APPNAME = "IOTA"
APPVERSION_MAJOR = 0
APPVERSION_MINOR = 6
APPVERSION_PATCH = 1
APPVERSION = $(APPVERSION_MAJOR).$(APPVERSION_MINOR).$(APPVERSION_PATCH)
APP_LOAD_PARAMS = --path "44'/4218'" --curve ed25519 --appFlags 0x240 $(COMMON_LOAD_PARAMS)

ifeq ($(TARGET_NAME),TARGET_BLUE)
ICONNAME = icons/blue_app_iota.gif
else ifeq ($(TARGET_NAME),TARGET_NANOX)
ICONNAME = icons/nanox_app_iota.gif
else ifeq ($(TARGET_NAME),TARGET_NANOS)
ICONNAME = icons/nanos_app_iota.gif
else
$(error unexpected target: $(TARGET_NAME))
endif


################
# Default rule #
################
all: default

############
# Platform #
############



DEFINES += $(DEFINES_LIB)

DEFINES += OS_IO_SEPROXYHAL
DEFINES += HAVE_BAGL HAVE_SPRINTF HAVE_SNPRINTF_FORMAT_U
DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=6 IO_HID_EP_LENGTH=64 HAVE_USB_APDU
DEFINES += LEDGER_MAJOR_VERSION=$(APPVERSION_MAJOR) LEDGER_MINOR_VERSION=$(APPVERSION_MINOR) LEDGER_PATCH_VERSION=$(APPVERSION_PATCH)

# U2F
DEFINES += HAVE_U2F HAVE_IO_U2F
DEFINES += U2F_PROXY_MAGIC=\"IOT\"
DEFINES += USB_SEGMENT_SIZE=64
DEFINES += BLE_SEGMENT_SIZE=32 #max MTU, min 20

# WebUSB
WEBUSB_URL = www.ledgerwallet.com
DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=$(shell echo -n $(WEBUSB_URL) | wc -c) WEBUSB_URL=$(shell echo -n $(WEBUSB_URL) | sed -e "s/./\\\'\0\\\',/g")

DEFINES += APPVERSION_MAJOR=$(APPVERSION_MAJOR)
DEFINES += APPVERSION_MINOR=$(APPVERSION_MINOR)
DEFINES += APPVERSION_PATCH=$(APPVERSION_PATCH)
DEFINES += APPVERSION=\"$(APPVERSION)\"


ifeq ($(TARGET_NAME),TARGET_NANOX)
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=300
DEFINES += HAVE_BLE BLE_COMMAND_TIMEOUT_MS=2000
DEFINES += HAVE_BLE_APDU # basic ledger apdu transport over BLE

DEFINES += HAVE_GLO096
DEFINES += HAVE_BAGL BAGL_WIDTH=128 BAGL_HEIGHT=64
DEFINES += HAVE_BAGL_ELLIPSIS # long label truncation feature
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_REGULAR_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_EXTRABOLD_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_LIGHT_16PX

else
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128
endif

#################
# sdk 1.6 supports ux_flow for the nano as well
DEFINES += HAVE_UX_FLOW

# if speculos simulator is selected enable debuging features
ifeq ($(SPECULOS), 1)
DEFINES += SPECULOS
DEBUG = 1
endif

ifeq ($(DEBUG),1)
DEFINES += APP_DEBUG
DEFINES += HAVE_BOLOS_APP_STACK_CANARY
# Development flags
APP_LOAD_PARAMS += --path "44'/01'"
DEFINES += HAVE_BOLOS_APP_STACK_CANARY

# we don't need printf
DEFINES += HAVE_PRINTF PRINTF=
# ifeq ($(TARGET_NAME),TARGET_NANOX)
# DEFINES += HAVE_PRINTF PRINTF=mcu_usb_printf
# else
# DEFINES += HAVE_PRINTF PRINTF=screen_printf
# endif
else
# Release flags
DEFINES += PRINTF\(...\)=
endif

##############
# Compiler #
##############
ifneq ($(BOLOS_ENV),)
$(info BOLOS_ENV=$(BOLOS_ENV))
CLANGPATH := $(BOLOS_ENV)/clang-arm-fropi/bin/
GCCPATH := $(BOLOS_ENV)/gcc-arm-none-eabi-5_3-2016q1/bin/
else
$(info BOLOS_ENV is not set: falling back to CLANGPATH and GCCPATH)
endif
ifeq ($(CLANGPATH),)
$(info CLANGPATH is not set: clang will be used from PATH)
endif
ifeq ($(GCCPATH),)
$(info GCCPATH is not set: arm-none-eabi-* will be used from PATH)
endif

CC := $(CLANGPATH)clang

ifeq ($(DEBUG),1)
CFLAGS += -O0 -g3
else
CFLAGS += -O2
endif

AS := $(GCCPATH)arm-none-eabi-gcc
AFLAGS +=

LD := $(GCCPATH)arm-none-eabi-gcc

ifeq ($(DEBUG),1)
LDFLAGS += -O0 -g3
else
LDFLAGS += -O2
endif

LDLIBS += -lm -lgcc -lc

# import rules to compile glyphs(/pone)
include $(BOLOS_SDK)/Makefile.glyphs

### variables processed by the common makefile.rules of the SDK to grab source files and include dirs
APP_SOURCE_PATH += src
SDK_SOURCE_PATH += lib_stusb lib_stusb_impl lib_u2f

ifeq ($(TARGET_NAME),TARGET_NANOX)
SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
SDK_SOURCE_PATH += lib_ux
endif

load: all
python3 -m ledgerblue.loadApp $(APP_LOAD_PARAMS)

delete:
python3 -m ledgerblue.deleteApp $(COMMON_DELETE_PARAMS)

# import generic rules from the sdk
include $(BOLOS_SDK)/Makefile.rules

#add dependency on custom makefile filename
dep/%.d: %.c Makefile



listvariants:
@echo VARIANTS COIN iota
172 changes: 171 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,171 @@
# ledger-iota-app
# IOTA Chrysalis App for Ledger Hardware Wallets

[![license](https://img.shields.io/github/license/IOTA-Ledger/blue-app-iota.svg)](https://github.com/IOTA-Ledger/blue-app-iota/blob/master/LICENSE)


***It is strongly recommended to take a few minutes to read this document to make sure you fully understand how IOTA and the Ledger Hardware Wallet works, and how they interact together.***

## Table of contents

- [IOTA Chrysalis App for Ledger Hardware Wallets](#iota-chrysalis-app-for-ledger-hardware-wallets)
- [Table of contents](#table-of-contents)
- [Introduction](#introduction)
- [Terminology](#terminology)
- [Address Reuse](#address-reuse)
- [IOTA Message](#iota-message)
- [Parts of an IOTA Message](#parts-of-an-iota-message)
- [How Ledger Hardware Wallets Work](#how-ledger-hardware-wallets-work)
- [IOTA Specific Considerations for Ledger Hardware Wallets](#iota-specific-considerations-for-ledger-hardware-wallets)
- [IOTA User-Facing App Functions](#iota-user-facing-app-functions)
- [Functions](#functions)
- [Display](#display)
- [IOTA Security Concerns Relating to Ledger Hardware Wallets](#iota-security-concerns-relating-to-ledger-hardware-wallets)
- [Limitations of Ledger Hardware Wallets](#limitations-of-ledger-hardware-wallets)
- [FAQ](#faq)
- [I lost my ledger, what should I do now?](#i-lost-my-ledger-what-should-i-do-now)
- [Development](#development)
- [Preparing development environment](#preparing-development-environment)
- [Compile and load the IOTA Ledger app](#compile-and-load-the-iota-ledger-app)
- [Specification](#specification)

---

## Introduction

IOTA is an unique cryptocurrency with specific design considerations that must be taken into account. This document will attempt to go over how the Ledger hardware wallet functions, and how to stay safe when using a Ledger to store IOTA.

### Terminology

*Seed:* A single secret key from that all private keys are derived (aka "*24 words*", [BIP39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki)).

*Private Key:* Private keys are derived from the seed ([BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) with ED25519 curve, [BIP44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki]). The private key is used to generate a public key. It is also used to prove you own said public key by means of creating a signature for a specific transaction.

*Public Key:* The public part of a private/public key pair.

*Address:* A hashed representation of the public key that is used to send coins to.

*Input:* The unspent transaction output (UTXO) from which coins are transfered.

*Output:* The address to which coins are transfered.

*Change/Remainder:* After sending funds to a 3rd party, all remaining funds on the account must be transferred to a new address - this is called the change or remainder address.

### Address Reuse

IOTA Chrysalis switched from quantum resistance signatures (Winternitz One-Time) to ED25519 signatures and from an account based model to an UTXO model. For this reason, address reuse no longer is problematic and IOTA is as secure as *other major crypto currencies*.

### IOTA Message

A message mainly is just a group of inputs and outputs. So if Bob has 10Mi, and wants to send Alice 3Mi, the message could look like this:

**input:** Bob -10Mi

**output:** Alice +3Mi

**output:** Bob +7Mi (change output / remainder)

This example highlights how IOTA handles messages. First it takes an input of 10Mi from Bob's address. It sends 3 of it to Alice, and it puts the remaining 7Mi on a new address belonging to Bob's seed.

All inputs require the private key to generate signatures which prove that you are the owner of the funds.

Because messages are *atomic units*, the network will never accept Bob's input of -10Mi without also accepting sending 3 to Alice, and 7 to a new address owned by Bob (in this example).

### Parts of an IOTA Message

An IOTA message is broken up into 2 halves. The first half is generating a message and creating signatures for it.

The second half is selecting 2 other messages to confirm, and performing the proof of work.

The Ledger is **only** responsible for generating signatures for a specific message. After that the host machine (or anybody else for that matter), can take the signatures and broadcast it to the network (however the signatures are only valid for the specific message).

## How Ledger Hardware Wallets Work

The Ledger Hardware Wallet works by deterministically generating IOTA keys based on your 24 word mnemonic (created when setting up the device).

Instead of storing the seed on your computer (which could be stolen by an attacker), the seed is stored on the Ledger device, and is never broadcast to the host machine it is connected to.

Instead, the host machine must ask the Ledger to provide the information (such as public keys or signatures). When creating messages, the host will generate an unsigned message and then send it to the Ledger device to be signed. The Ledger will then use the private keys associated with the inputs to generate unique signatures, and will then transfer **only the signatures** back to the host machine.

The host can then use these signatures (which are only valid for that specific message) to broadcast the message to the network. However as you can see, neither the seed, nor any of the private keys ever leave the device.

See [Ledger's documentation](http://ledger.readthedocs.io) to get more info about the inner workings of the Ledger Hardware Wallets.

## IOTA Specific Considerations for Ledger Hardware Wallets

### IOTA User-Facing App Functions

#### Functions

- *Display Address:* The wallet can ask the Ledger to display the address for a specific index on the seed. It **only** accepts the index, and subsequently generates the address itself and thus verifies that the address belongs to the Ledger.

*Note: Only the remainder address (shown as "Remainder") will be verified to belong to the Ledger. Outputs shown as "Send To" are not.*

- *Sign Transaction:* The wallet will generate a message for the user to approve before the Ledger signs it. **Ensure all amounts and addresses are correct before signing**. These signatures are then sent back to the host machine.

#### Display

**TODO**


### IOTA Security Concerns Relating to Ledger Hardware Wallets

All warnings on the Ledger are there for a reason, **MAKE SURE TO READ THEM** and refer to this document if there is any confusion.

- **Don't rush through signing a message.**
Before a message is signed, all outputs of a message are shown on the display. The user can scroll through the individual outputs and finally choose whether to sign the message ("Accept") or not ("Reject").

Outputs that go to 3rd party addresses are shown on the display with "Send To". The address to which the rest is sent is shown as "Remainder".

The Remainder also shows the BIP32 path in addition to the amount. This address is calculated on the ledger and ensures that the rest of the IOTAs are sent to an address owned by the Leder Nano.

If the input amount perfectly matches the output amount, there will be no remainder. **If there is no remainder, double check that you are sending the proper amount to the proper address because there is no remainder being sent back to your seed.**

### Limitations of Ledger Hardware Wallets

Due to the memory limitations of the Ledger Nano S/X, the messages have certain restrictions. The Ledger Nano S can only accept messages with about 17 inputs/outputs (e.g. 4 inputs, 13 outputs). The Ledger Nano X can accept messages with about 180 inputs/outputs.

## FAQ

#### I lost my ledger, what should I do now?

Hopefully you wrote down your 24 recovery words and your optional passphrase in a safe place. If not, all your funds are lost.

If you did, the best solution is to buy a new Ledger and enter your 24 recovery words and your optional passphrase in the new device.<br>
After installation of the IOTA Ledger app, all your funds are restored. Take care to reinitialize your seed index correctly.

## Development

You either can

- run the app in a Ledger Nano S/X simulator or
- load the app on your read Ledger Nano S

In both cases, you find instructions here: [Ledger-IOTA-App-Docker Repository](https://gitlab.com/ledger-iota-chrysalis/ledger-iota-app-docker)

### Preparing development environment

For active development it might be easier to install the development environment locally instead of using Docker:

- Clone this repo
- Ensure that all git submodules are initialized
```
git submodule update --init --recursive
```
- Set up your development environment according to [Ledger Documentation - Getting Started](https://ledger.readthedocs.io/en/latest/userspace/getting_started.html).
### Compile and load the IOTA Ledger app
After the development environment has been installed, the app can be build and installed in the following way:
- Connect your Ledger to the PC and unlock it
- To load the app, be sure that the dashboard is opened in the Ledger
- Run the following commands to compile the app from source and load it
```
make load
```
- Accept all the messages on the Ledger
## Specification
See: [APDU API Specification](docs/specification_chrysalis.md)
1 change: 1 addition & 0 deletions dev/sdk/nanos-secure-sdk
Submodule nanos-secure-sdk added at 1bc941
1 change: 1 addition & 0 deletions dev/sdk/nanox-secure-sdk
Submodule nanox-secure-sdk added at abe9a1
Binary file added docs/apdu_request.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit da7c041

Please sign in to comment.