-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from coderofstuff/convert-standard-app
Convert standard app
- Loading branch information
Showing
171 changed files
with
372 additions
and
1,669 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,112 +1,116 @@ | ||
# **************************************************************************** | ||
# Ledger App Boilerplate | ||
# (c) 2023 Ledger SAS. | ||
# | ||
# 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. | ||
# **************************************************************************** | ||
|
||
ifeq ($(BOLOS_SDK),) | ||
$(error Environment variable BOLOS_SDK is not set) | ||
endif | ||
|
||
include $(BOLOS_SDK)/Makefile.defines | ||
|
||
APP_LOAD_PARAMS = --curve secp256k1 | ||
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_STAX)) | ||
APP_LOAD_PARAMS += --appFlags 0x200 # APPLICATION_FLAG_BOLOS_SETTINGS | ||
else | ||
APP_LOAD_PARAMS += --appFlags 0x000 | ||
endif | ||
APP_LOAD_PARAMS += --path "44'/111111'" | ||
APP_LOAD_PARAMS += $(COMMON_LOAD_PARAMS) | ||
######################################## | ||
# Mandatory configuration # | ||
######################################## | ||
# Application name | ||
APPNAME = "Kaspa" | ||
|
||
APPNAME = "Kaspa" | ||
# Application version | ||
APPVERSION_M = 1 | ||
APPVERSION_N = 0 | ||
APPVERSION_P = 0 | ||
APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)" | ||
APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)" | ||
|
||
ifeq ($(TARGET_NAME),TARGET_NANOS) | ||
DEFINES += MAX_INPUT_COUNT=15 | ||
ICONNAME=icons/nanos_kaspa_logo.gif | ||
else ifeq ($(TARGET_NAME),TARGET_STAX) | ||
DEFINES += MAX_INPUT_COUNT=128 | ||
ICONNAME=icons/stax_kaspa_logo_32px.gif | ||
else | ||
DEFINES += MAX_INPUT_COUNT=128 | ||
ICONNAME=icons/nanox_kaspa_logo.gif | ||
endif | ||
|
||
DEFINES += $(DEFINES_LIB) | ||
DEFINES += APPNAME=\"$(APPNAME)\" | ||
DEFINES += APPVERSION=\"$(APPVERSION)\" | ||
DEFINES += MAJOR_VERSION=$(APPVERSION_M) MINOR_VERSION=$(APPVERSION_N) PATCH_VERSION=$(APPVERSION_P) | ||
DEFINES += OS_IO_SEPROXYHAL | ||
DEFINES += 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 += USB_SEGMENT_SIZE=64 | ||
DEFINES += BLE_SEGMENT_SIZE=32 | ||
DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=0 WEBUSB_URL="" | ||
DEFINES += UNUSED\(x\)=\(void\)x | ||
|
||
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_STAX)) | ||
DEFINES += HAVE_BLE BLE_COMMAND_TIMEOUT_MS=2000 HAVE_BLE_APDU | ||
endif | ||
|
||
ifeq ($(TARGET_NAME),TARGET_NANOS) | ||
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128 | ||
else | ||
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=300 | ||
endif | ||
|
||
ifeq ($(TARGET_NAME),TARGET_STAX) | ||
DEFINES += NBGL_QRCODE | ||
else | ||
DEFINES += HAVE_BAGL HAVE_UX_FLOW | ||
ifneq ($(TARGET_NAME),TARGET_NANOS) | ||
DEFINES += HAVE_GLO096 | ||
DEFINES += 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 | ||
endif | ||
endif | ||
|
||
DEBUG ?= 0 | ||
ifneq ($(DEBUG),0) | ||
DEFINES += HAVE_DEBUG_APDU | ||
DEFINES += HAVE_PRINTF | ||
ifeq ($(TARGET_NAME),TARGET_NANOS) | ||
DEFINES += PRINTF=screen_printf | ||
else | ||
DEFINES += PRINTF=mcu_usb_printf | ||
endif | ||
else | ||
DEFINES += PRINTF\(...\)= | ||
endif | ||
|
||
CC := $(CLANGPATH)clang | ||
AS := $(GCCPATH)arm-none-eabi-gcc | ||
LD := $(GCCPATH)arm-none-eabi-gcc | ||
LDLIBS += -lm -lgcc -lc | ||
|
||
include $(BOLOS_SDK)/Makefile.glyphs | ||
|
||
# Application source files | ||
APP_SOURCE_PATH += src | ||
SDK_SOURCE_PATH += lib_stusb lib_stusb_impl | ||
|
||
ifneq ($(TARGET_NAME),TARGET_STAX) | ||
SDK_SOURCE_PATH += lib_ux | ||
endif | ||
|
||
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_STAX)) | ||
SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl | ||
endif | ||
|
||
load: all | ||
python3 -m ledgerblue.loadApp $(APP_LOAD_PARAMS) | ||
|
||
load-offline: all | ||
python3 -m ledgerblue.loadApp $(APP_LOAD_PARAMS) --offline | ||
|
||
delete: | ||
python3 -m ledgerblue.deleteApp $(COMMON_DELETE_PARAMS) | ||
|
||
include $(BOLOS_SDK)/Makefile.rules | ||
|
||
listvariants: | ||
@echo VARIANTS COIN KAS | ||
# Application icons following guidelines: | ||
# https://developers.ledger.com/docs/embedded-app/design-requirements/#device-icon | ||
ICON_NANOS = icons/nanos_kaspa_logo.gif | ||
ICON_NANOX = icons/nanox_kaspa_logo.gif | ||
ICON_NANOSP = icons/nanox_kaspa_logo.gif | ||
ICON_STAX = icons/stax_kaspa_logo_32px.gif | ||
|
||
# Application allowed derivation curves. | ||
# Possibles curves are: secp256k1, secp256r1, ed25519 and bls12381g1 | ||
# If your app needs it, you can specify multiple curves by using: | ||
# `CURVE_APP_LOAD_PARAMS = <curve1> <curve2>` | ||
CURVE_APP_LOAD_PARAMS = secp256k1 | ||
|
||
# Application allowed derivation paths. | ||
# You should request a specific path for your app. | ||
# This serve as an isolation mechanism. | ||
# Most application will have to request a path according to the BIP-0044 | ||
# and SLIP-0044 standards. | ||
# If your app needs it, you can specify multiple path by using: | ||
# `PATH_APP_LOAD_PARAMS = "44'/1'" "45'/1'"` | ||
PATH_APP_LOAD_PARAMS = "44'/111111'" # purpose=coin(44) / coin_type=Testnet(1) | ||
|
||
# Setting to allow building variant applications | ||
# - <VARIANT_PARAM> is the name of the parameter which should be set | ||
# to specify the variant that should be build. | ||
# - <VARIANT_VALUES> a list of variant that can be build using this app code. | ||
# * It must at least contains one value. | ||
# * Values can be the app ticker or anything else but should be unique. | ||
VARIANT_PARAM = COIN | ||
VARIANT_VALUES = KAS | ||
|
||
# Enabling DEBUG flag will enable PRINTF and disable optimizations | ||
#DEBUG = 1 | ||
|
||
######################################## | ||
# Application custom permissions # | ||
######################################## | ||
# See SDK `include/appflags.h` for the purpose of each permission | ||
#HAVE_APPLICATION_FLAG_DERIVE_MASTER = 1 | ||
#HAVE_APPLICATION_FLAG_GLOBAL_PIN = 1 | ||
#HAVE_APPLICATION_FLAG_BOLOS_SETTINGS = 1 | ||
#HAVE_APPLICATION_FLAG_LIBRARY = 1 | ||
|
||
######################################## | ||
# Application communication interfaces # | ||
######################################## | ||
ENABLE_BLUETOOTH = 1 | ||
#ENABLE_NFC = 1 | ||
|
||
######################################## | ||
# NBGL custom features # | ||
######################################## | ||
ENABLE_NBGL_QRCODE = 1 | ||
#ENABLE_NBGL_KEYBOARD = 1 | ||
#ENABLE_NBGL_KEYPAD = 1 | ||
|
||
######################################## | ||
# Features disablers # | ||
######################################## | ||
# These advanced settings allow to disable some feature that are by | ||
# default enabled in the SDK `Makefile.standard_app`. | ||
#DISABLE_STANDARD_APP_FILES = 1 | ||
#DISABLE_DEFAULT_IO_SEPROXY_BUFFER_SIZE = 1 # To allow custom size declaration | ||
#DISABLE_STANDARD_APP_DEFINES = 1 # Will set all the following disablers | ||
#DISABLE_STANDARD_SNPRINTF = 1 | ||
#DISABLE_STANDARD_USB = 1 | ||
#DISABLE_STANDARD_WEBUSB = 1 | ||
#DISABLE_STANDARD_BAGL_UX_FLOW = 1 | ||
|
||
include $(BOLOS_SDK)/Makefile.standard_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/***************************************************************************** | ||
* MIT License | ||
* | ||
* Copyright (c) 2023 coderofstuff | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*****************************************************************************/ | ||
#include <stdint.h> // uint*_t | ||
#include <string.h> // memset, explicit_bzero | ||
|
||
#include "os.h" | ||
#include "ux.h" | ||
|
||
#include "types.h" | ||
#include "globals.h" | ||
#include "io.h" | ||
#include "sw.h" | ||
#include "ui/menu.h" | ||
#include "apdu/parser.h" | ||
#include "apdu/dispatcher.h" | ||
|
||
global_ctx_t G_context; | ||
|
||
/** | ||
* Handle APDU command received and send back APDU response using handlers. | ||
*/ | ||
void app_main() { | ||
// Length of APDU command received in G_io_apdu_buffer | ||
int input_len = 0; | ||
// Structured APDU command | ||
command_t cmd; | ||
|
||
io_init(); | ||
|
||
ui_menu_main(); | ||
|
||
// Reset context | ||
explicit_bzero(&G_context, sizeof(G_context)); | ||
|
||
for (;;) { | ||
// Receive command bytes in G_io_apdu_buffer | ||
if ((input_len = io_recv_command()) < 0) { | ||
PRINTF("=> io_recv_command failure\n"); | ||
return; | ||
} | ||
|
||
// Parse APDU command from G_io_apdu_buffer | ||
if (!apdu_parser(&cmd, G_io_apdu_buffer, input_len)) { | ||
PRINTF("=> /!\\ BAD LENGTH: %.*H\n", input_len, G_io_apdu_buffer); | ||
io_send_sw(SW_WRONG_DATA_LENGTH); | ||
continue; | ||
} | ||
|
||
PRINTF("=> CLA=%02X | INS=%02X | P1=%02X | P2=%02X | Lc=%02X | CData=%.*H\n", | ||
cmd.cla, | ||
cmd.ins, | ||
cmd.p1, | ||
cmd.p2, | ||
cmd.lc, | ||
cmd.lc, | ||
cmd.data); | ||
|
||
// Dispatch structured APDU command to handler | ||
if (apdu_dispatcher(&cmd) < 0) { | ||
PRINTF("=> apdu_dispatcher failure\n"); | ||
return; | ||
} | ||
} | ||
} |
Oops, something went wrong.