Skip to content

Commit ca48f7f

Browse files
committed
Init
0 parents  commit ca48f7f

34 files changed

+7603
-0
lines changed

.gitignore

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Object files
5+
*.o
6+
*.ko
7+
*.obj
8+
*.elf
9+
*.sh
10+
11+
# Linker output
12+
*.ilk
13+
*.map
14+
*.exp
15+
16+
# Precompiled Headers
17+
*.gch
18+
*.pch
19+
20+
# Libraries
21+
*.lib
22+
*.a
23+
*.la
24+
*.lo
25+
glyphs.c
26+
glyphs.h
27+
28+
# Shared objects (inc. Windows DLLs)
29+
*.dll
30+
*.so
31+
*.so.*
32+
*.dylib
33+
34+
# Executables
35+
*.exe
36+
*.out
37+
*.app
38+
*.i*86
39+
*.x86_64
40+
*.hex
41+
42+
# Debug files
43+
*.dSYM/
44+
*.su
45+
*.idb
46+
*.pdb
47+
debug/
48+
49+
# Kernel Module Compile Results
50+
*.mod*
51+
*.cmd
52+
.tmp_versions/
53+
modules.order
54+
Module.symvers
55+
Mkfile.old
56+
dkms.conf
57+
58+
# Byte-compiled / optimized / DLL files
59+
__pycache__/
60+
*.py[cod]
61+
62+
#virtual env pip
63+
ledger/
64+
65+
# SDK
66+
/.env
67+
68+
# IDE
69+
/.vscode
70+
/.idea
71+
requirements.txt
72+
debug-tool

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM zondax/ledger-docker-bolos
2+
3+
ENV BOLOS_ENV=/opt/bolos
4+
ENV BOLOS_SDK=$BOLOS_ENV/nanos-secure-sdk
5+
#ENV BOLOS_SDK=$BOLOS_ENV/blue-secure-sdk
6+
7+
RUN git clone https://github.com/LedgerHQ/nanos-secure-sdk.git $BOLOS_ENV/nanos-secure-sdk
8+
RUN git clone https://github.com/ledgerhq/blue-secure-sdk $BOLOS_ENV/blue-secure-sdk
9+
RUN apt-get update && apt-get install -y \
10+
python3-pip
11+
12+
RUN cd /tmp \
13+
&& wget http://ftp.gnu.org/gnu/make/make-4.2.1.tar.bz2 \
14+
&& tar -jxf make-4.2.1.tar.bz2 \
15+
&& cd make-4.2.1 \
16+
&& ./configure --prefix=/usr \
17+
&& make \
18+
make install
19+
20+
21+
USER test

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Fernando Sobreira
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#*******************************************************************************
2+
# Ledger App
3+
# (c) 2018 Ledger
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#*******************************************************************************
17+
18+
ifeq ($(BOLOS_SDK),)
19+
$(error Environment variable BOLOS_SDK is not set)
20+
endif
21+
include $(BOLOS_SDK)/Makefile.defines
22+
23+
APPNAME = "MCashChain"
24+
APP_LOAD_PARAMS=--appFlags 0x240 --path "44'/2048" --curve secp256k1 $(COMMON_LOAD_PARAMS)
25+
26+
splitVersion=$(word $2, $(subst ., , $1))
27+
28+
APPVERSION = $(file < VERSION)
29+
30+
APPVERSION_M=$(call splitVersion, $(APPVERSION), 1)
31+
APPVERSION_N=$(call splitVersion, $(APPVERSION), 2)
32+
APPVERSION_P=$(call splitVersion, $(APPVERSION), 3)
33+
34+
#prepare hsm generation
35+
ifeq ($(TARGET_NAME), TARGET_NANOX)
36+
ICONNAME=nanox_app_mcash.gif
37+
else
38+
ICONNAME=nanos_app_mcash.gif
39+
endif
40+
41+
42+
################
43+
# Default rule #
44+
################
45+
all: default
46+
47+
############
48+
# Platform #
49+
############
50+
51+
DEFINES += OS_IO_SEPROXYHAL
52+
DEFINES += HAVE_BAGL HAVE_SPRINTF
53+
DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=6 IO_HID_EP_LENGTH=64 HAVE_USB_APDU
54+
DEFINES += LEDGER_MAJOR_VERSION=$(APPVERSION_M) LEDGER_MINOR_VERSION=$(APPVERSION_N) LEDGER_PATCH_VERSION=$(APPVERSION_P)
55+
56+
DEFINES += USB_SEGMENT_SIZE=64
57+
DEFINES += BLE_SEGMENT_SIZE=32 #max MTU, min 20
58+
DEFINES += UNUSED\(x\)=\(void\)x
59+
DEFINES += APPVERSION=\"$(APPVERSION)\"
60+
61+
ifeq ($(TARGET_NAME),TARGET_NANOX)
62+
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=300
63+
# BLE
64+
DEFINES += HAVE_BLE BLE_COMMAND_TIMEOUT_MS=2000
65+
DEFINES += HAVE_BLE_APDU # basic ledger apdu transport over BLE
66+
67+
DEFINES += HAVE_GLO096 HAVE_UX_FLOW
68+
DEFINES += HAVE_BAGL BAGL_WIDTH=128 BAGL_HEIGHT=64
69+
DEFINES += HAVE_BAGL_ELLIPSIS # long label truncation feature
70+
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_REGULAR_11PX
71+
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_EXTRABOLD_11PX
72+
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_LIGHT_16PX
73+
else
74+
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128
75+
endif
76+
77+
# Enabling debug PRINTF
78+
DEBUG = 1
79+
ifneq ($(DEBUG),0)
80+
81+
ifeq ($(TARGET_NAME),TARGET_NANOX)
82+
DEFINES += HAVE_PRINTF PRINTF=mcu_usb_printf
83+
else
84+
DEFINES += HAVE_PRINTF PRINTF=screen_printf
85+
endif
86+
else
87+
DEFINES += PRINTF\(...\)=
88+
endif
89+
90+
##############
91+
# Compiler #
92+
##############
93+
ifneq ($(BOLOS_ENV),)
94+
$(info BOLOS_ENV=$(BOLOS_ENV))
95+
CLANGPATH := $(BOLOS_ENV)/clang-arm-fropi/bin/
96+
GCCPATH := $(BOLOS_ENV)/gcc-arm-none-eabi-5_3-2016q1/bin/
97+
else
98+
$(info BOLOS_ENV is not set: falling back to CLANGPATH and GCCPATH)
99+
endif
100+
ifeq ($(CLANGPATH),)
101+
$(info CLANGPATH is not set: clang will be used from PATH)
102+
endif
103+
ifeq ($(GCCPATH),)
104+
$(info GCCPATH is not set: arm-none-eabi-* will be used from PATH)
105+
endif
106+
107+
CC := $(CLANGPATH)clang
108+
109+
#CFLAGS += -O0
110+
CFLAGS += -O3 -Os -Isrc/include
111+
112+
AS := $(GCCPATH)arm-none-eabi-gcc
113+
114+
LD := $(GCCPATH)arm-none-eabi-gcc
115+
LDFLAGS += -O3 -Os
116+
LDLIBS += -lm -lgcc -lc
117+
118+
# import rules to compile glyphs(/pone)
119+
include $(BOLOS_SDK)/Makefile.glyphs
120+
121+
### computed variables
122+
APP_SOURCE_PATH += src
123+
SDK_SOURCE_PATH += lib_u2f lib_stusb_impl lib_stusb
124+
ifeq ($(TARGET_NAME),TARGET_NANOX)
125+
SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
126+
SDK_SOURCE_PATH += lib_ux
127+
endif
128+
# U2F
129+
DEFINES += U2F_PROXY_MAGIC=\"MCASH\"
130+
DEFINES += HAVE_IO_U2F HAVE_U2F
131+
DEFINES += U2F_REQUEST_TIMEOUT=28000 # 28 seconds
132+
133+
load: all
134+
python -m ledgerblue.loadApp $(APP_LOAD_PARAMS)
135+
136+
delete:
137+
python -m ledgerblue.deleteApp $(COMMON_DELETE_PARAMS)
138+
139+
# import generic rules from the sdk
140+
include $(BOLOS_SDK)/Makefile.rules
141+
142+
#add dependency on custom makefile filename
143+
dep/%.d: %.c Makefile.genericwallet
144+
145+
listvariants:
146+
@echo VARIANTS COIN mcash

README.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Clone this repository
2+
```bash
3+
git clone https://github.com/fbsobreira/mcash-ledger.git
4+
cd mcash-ledger
5+
```
6+
7+
8+
# Compiling from source
9+
10+
## Docker toolchain image
11+
In order to make compiling as eas as possible you can make use of a docker image containing all the necessary compilers and the [nanos-secure-sdk](https://github.com/LedgerHQ/nanos-secure-sdk).
12+
13+
Make sure you have [Docker](https://www.docker.com/community-edition) installed.
14+
15+
### Step 1 - Build the image:
16+
> make sure to select the appropriate $BOLOS_SDK in Dockerfile
17+
```bash
18+
docker build -t ledger-chain:latest .
19+
```
20+
The `.` at the end is **important!**
21+
22+
23+
### Step 2 - Use Docker image
24+
```bash
25+
docker run --rm -v "$(pwd)":/mcash-ledger -w /mcash-ledger ledger-chain make
26+
```
27+
28+
## Using your own toolchain
29+
```bash
30+
make
31+
```
32+
33+
34+
# Load app onto Ledger Nano S
35+
36+
Before attempting to load the hex file, make sure your Ledger Nano S
37+
is connected and the firware is updated to the [latest version](https://support.ledgerwallet.com/hc/en-us/articles/360002731113-Update-the-firmware).
38+
39+
Enter your PIN and **make sure you're seeing the Dashboard app**.
40+
41+
## Using Docker image
42+
### Step 1 - Install virtualenv
43+
```bash
44+
[sudo] pip install -U setuptools
45+
[sudo] pip install virtualenv
46+
```
47+
48+
### Step 2 - Create new virtualenv
49+
#### linux dependencies for ledgerblue module
50+
> libudev1 libudev-dev libusb-1.0-0-dev
51+
52+
```bash
53+
virtualenv -p python3 ledger
54+
source ledger/bin/activate
55+
pip install ledgerblue
56+
or pip install git+https://github.com/LedgerHQ/blue-loader-python.git
57+
```
58+
59+
If you run into errors here, make sure you have the required dependencies installed. See [Ledger - Loader Python](https://github.com/LedgerHQ/blue-loader-python).
60+
61+
### Step 3 - Load HEX file
62+
```bash
63+
python -m ledgerblue.loadApp \
64+
--targetId 0x31100004 \
65+
--fileName bin/app.hex \
66+
--icon `docker run --rm -v "$(pwd)":/mcash_ledger -w /mcash_ledger ledger-chain sh -c 'python $BOLOS_SDK/icon.py nanos_app_mcash.gif hexbitmaponly'` \
67+
--curve secp256k1 \
68+
--path "44'/2048" \
69+
--apdu \
70+
--appName "MCashChain" \
71+
--appVersion `cat ./VERSION` \
72+
--appFlags 0x40 \
73+
--delete \
74+
--dataSize `cat debug/app.map | grep _nvram_data_size | tr -s ' ' | cut -f2 -d' '` \
75+
--tlv
76+
```
77+
78+
### Step 4 - Leave virtualenv
79+
To get out of your Python virtualenv again after everything is done.
80+
```bash
81+
deactivate
82+
```
83+
84+
## Using your own toolchain
85+
86+
```bash
87+
make load
88+
```
89+
90+
### Step 1 - Install virtualenv
91+
See step 1 above.
92+
93+
### Step 2 - Create new virtualenv
94+
See step 2 above.
95+
96+
### Step 3 - Load HEX file
97+
```bash
98+
python -m ledgerblue.loadApp \
99+
--targetId 0x31100003 \
100+
--fileName NAME_OF_PRECOMPILED_HEX_HERE.hex \
101+
--icon 0100000000ffffff0000000000fc000c0f3814c822103f101120092005400340018001800000000000 \
102+
--curve secp256k1 \
103+
--path "44'/2048" \
104+
--apdu \
105+
--appName "Mcash Chain" \
106+
--appVersion "VERSION_NUMBER" \
107+
--appFlags 0x40 \
108+
--delete \
109+
--dataSize DATA_SIZE_OF_PRECOMPILED_HEX \
110+
--tlv
111+
```
112+
Replace `NAME_OF_PRECOMPILED_HEX_HERE.hex` with the location and name of the pre-compiled HEX file.
113+
114+
Replace `VERSION_NUMBER` with the version number of the pre-compiled HEX file.
115+
116+
Replace `DATA_SIZE_OF_PRECOMPILED_HEX` with the data size of the pre-compiled HEX file.
117+
118+
### Step 4 - Leave virtualenv
119+
See step 4 above.
120+
121+
# Links
122+
========
123+
124+
### [Mcashscan Integration](https://mcashscan.io)

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.1

glyphs/badge_mcash.gif

1.62 KB
Loading

glyphs/badge_transaction.gif

339 Bytes
Loading

glyphs/icon.gif

68 Bytes
Loading

glyphs/icon_back.gif

74 Bytes
Loading

0 commit comments

Comments
 (0)