From 0ab933532a5c262fec05b317ddeb3a022320c4d2 Mon Sep 17 00:00:00 2001 From: Sarah GLINER Date: Thu, 28 Mar 2024 10:06:27 +0100 Subject: [PATCH] Update --- Makefile | 417 +++++++++++++++++- lib-app-bitcoin/Makefile | 3 +- .../handler/hash_input_finalize_full.c | 7 +- lib-app-bitcoin/handler/hash_sign.c | 2 +- lib-app-bitcoin/ui/main_ui.c | 9 +- 5 files changed, 431 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index fd39c5a8..5680ce57 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ APPVERSION_M = 2 APPVERSION_N = 3 APPVERSION_P = 0 -VARIANT_VALUES = bitcoin_testnet_legacy bitcoin_legacy +VARIANT_VALUES = bitcoin_testnet_legacy bitcoin_legacy bitcoin_cash bitcoin_gold litecoin dogecoin dash horizen komodo stratis peercoin pivx viacoin vertcoin stealth digibyte bitcoin_private firo gamecredits zclassic xsn nix lbry ravencoin hydra hydra_testnet xrhodium # Application source files # There is no additional sources for bitcoin @@ -68,6 +68,421 @@ COIN_NATIVE_SEGWIT_PREFIX=\"bc\" COIN_KIND=COIN_KIND_BITCOIN COIN_FLAGS=FLAG_SEGWIT_CHANGE_SUPPORT APPNAME ="Bitcoin Legacy" + +else ifeq ($(COIN),bitcoin_cash) +# Bitcoin cash +# Initial fork from Bitcoin, public key access is authorized. Signature is different thanks to the forkId +BIP44_COIN_TYPE=145 +BIP44_COIN_TYPE_2=0 +COIN_P2PKH_VERSION=0 +COIN_P2SH_VERSION=5 +COIN_FAMILY=1 +COIN_COINID=\"Bitcoin\" +COIN_COINID_HEADER=\"BITCOINCASH\" +COIN_COINID_NAME=\"BitcoinCash\" +COIN_COINID_SHORT=\"BCH\" +COIN_KIND=COIN_KIND_BITCOIN_CASH +COIN_FORKID=0 +APPNAME ="Bitcoin Cash" + +else ifeq ($(COIN),bitcoin_gold) +# Bitcoin Gold +# Initial fork from Bitcoin, public key access is authorized. Signature is different thanks to the forkId +BIP44_COIN_TYPE=156 +BIP44_COIN_TYPE_2=0 +COIN_P2PKH_VERSION=38 +COIN_P2SH_VERSION=23 +COIN_FAMILY=1 +COIN_COINID=\"Bitcoin\\x20Gold\" +COIN_COINID_HEADER=\"BITCOINGOLD\" +COIN_COINID_NAME=\"BitcoinGold\" +COIN_COINID_SHORT=\"BTG\" +COIN_KIND=COIN_KIND_BITCOIN_GOLD +COIN_FLAGS=FLAG_SEGWIT_CHANGE_SUPPORT +COIN_FORKID=79 +APPNAME ="Bitcoin Gold" + +else ifeq ($(COIN),litecoin) +# Litecoin +BIP44_COIN_TYPE=2 +BIP44_COIN_TYPE_2=2 +COIN_P2PKH_VERSION=48 +COIN_P2SH_VERSION=50 +COIN_FAMILY=1 +COIN_COINID=\"Litecoin\" +COIN_COINID_HEADER=\"LITECOIN\" +COIN_COINID_NAME=\"Litecoin\" +COIN_COINID_SHORT=\"LTC\" +COIN_NATIVE_SEGWIT_PREFIX=\"ltc\" +COIN_KIND=COIN_KIND_LITECOIN +COIN_FLAGS=FLAG_SEGWIT_CHANGE_SUPPORT +APPNAME ="Litecoin" + +else ifeq ($(COIN),dogecoin) +# Doge +BIP44_COIN_TYPE=3 +BIP44_COIN_TYPE_2=3 +COIN_P2PKH_VERSION=30 +COIN_P2SH_VERSION=22 +COIN_FAMILY=1 +COIN_COINID=\"Dogecoin\" +COIN_COINID_HEADER=\"DOGECOIN\" +COIN_COINID_NAME=\"Dogecoin\" +COIN_COINID_SHORT=\"DOGE\" +COIN_KIND=COIN_KIND_DOGE +APPNAME ="Dogecoin" + +else ifeq ($(COIN),dash) +# Dash +BIP44_COIN_TYPE=5 +BIP44_COIN_TYPE_2=5 +COIN_P2PKH_VERSION=76 +COIN_P2SH_VERSION=16 +COIN_FAMILY=1 +COIN_COINID=\"DarkCoin\" +COIN_COINID_HEADER=\"DASH\" +COIN_COINID_NAME=\"Dash\" +COIN_COINID_SHORT=\"DASH\" +COIN_KIND=COIN_KIND_DASH +APPNAME ="Dash" + +else ifeq ($(COIN),zcash) +# Zcash (deprecated, code before the NU5 hard fork) +$(error the zcash variant is deprecated and no longer functional since the NU5 hard fork) +BIP44_COIN_TYPE=133 +BIP44_COIN_TYPE_2=133 +COIN_P2PKH_VERSION=7352 +COIN_P2SH_VERSION=7357 +COIN_FAMILY=1 +COIN_COINID=\"Zcash\" +COIN_COINID_HEADER=\"ZCASH\" +COIN_COINID_NAME=\"Zcash\" +COIN_COINID_SHORT=\"ZEC\" +COIN_KIND=COIN_KIND_ZCASH +# Switch to Canopy over Heartwood +BRANCH_ID=0xE9FF75A6 +APPNAME ="Zcash" + +else ifeq ($(COIN),horizen) +# Horizen +BIP44_COIN_TYPE=121 +BIP44_COIN_TYPE_2=121 +COIN_P2PKH_VERSION=8329 +COIN_P2SH_VERSION=8342 +COIN_FAMILY=4 +COIN_COINID=\"Horizen\" +COIN_COINID_HEADER=\"HORIZEN\" +COIN_COINID_NAME=\"Horizen\" +COIN_COINID_SHORT=\"ZEN\" +COIN_KIND=COIN_KIND_HORIZEN +APPNAME ="Horizen" + +else ifeq ($(COIN),komodo) +# Komodo +BIP44_COIN_TYPE=141 +BIP44_COIN_TYPE_2=141 +COIN_P2PKH_VERSION=60 +COIN_P2SH_VERSION=85 +COIN_FAMILY=1 +COIN_COINID=\"Komodo\" +COIN_COINID_HEADER=\"KOMODO\" +COIN_COINID_NAME=\"Komodo\" +COIN_COINID_SHORT=\"KMD\" +COIN_KIND=COIN_KIND_KOMODO +APPNAME ="Komodo" + +else ifeq ($(COIN),stratis) +# Stratis +BIP44_COIN_TYPE=105105 +BIP44_COIN_TYPE_2=105105 +COIN_P2PKH_VERSION=75 +COIN_P2SH_VERSION=140 +COIN_FAMILY=2 +COIN_COINID=\"Stratis\" +COIN_COINID_HEADER=\"STRATIS\" +COIN_COINID_NAME=\"Stratis\" +COIN_COINID_SHORT=\"STRAX\" +COIN_KIND=COIN_KIND_STRATIS +COIN_FLAGS=FLAG_PEERCOIN_SUPPORT +APPNAME ="Stratis" + +else ifeq ($(COIN),xrhodium) +#Xrhodium +BIP44_COIN_TYPE=10291 +BIP44_COIN_TYPE_2=10291 +COIN_P2PKH_VERSION=61 +COIN_P2SH_VERSION=123 +COIN_FAMILY=1 +COIN_COINID=\"xrhodium\" +COIN_COINID_HEADER=\"XRHODIUM\" +COIN_COINID_NAME=\"xRhodium\" +COIN_COINID_SHORT=\"XRC\" +COIN_KIND=COIN_KIND_XRHODIUM +APPNAME ="xRhodium" + +else ifeq ($(COIN),peercoin) +# Peercoin +BIP44_COIN_TYPE=6 +BIP44_COIN_TYPE_2=6 +COIN_P2PKH_VERSION=55 +COIN_P2SH_VERSION=117 +COIN_FAMILY=2 +COIN_COINID=\"PPCoin\" +COIN_COINID_HEADER=\"PEERCOIN\" +COIN_COINID_NAME=\"Peercoin\" +COIN_COINID_SHORT=\"PPC\" +COIN_KIND=COIN_KIND_PEERCOIN +COIN_FLAGS=FLAG_PEERCOIN_UNITS\|FLAG_PEERCOIN_SUPPORT +APPNAME ="Peercoin" + +else ifeq ($(COIN),pivx) +# PivX +# 77 was used in the Chrome apps +BIP44_COIN_TYPE=119 +BIP44_COIN_TYPE_2=77 +COIN_P2PKH_VERSION=30 +COIN_P2SH_VERSION=13 +COIN_FAMILY=1 +COIN_COINID=\"DarkNet\" +COIN_COINID_HEADER=\"PIVX\" +COIN_COINID_NAME=\"PivX\" +COIN_COINID_SHORT=\"PIVX\" +COIN_KIND=COIN_KIND_PIVX +APPNAME ="PivX" + +else ifeq ($(COIN),stealth) +# Stealth +BIP44_COIN_TYPE=125 +BIP44_COIN_TYPE_2=125 +COIN_P2PKH_VERSION=62 +COIN_P2SH_VERSION=85 +COIN_FAMILY=4 +COIN_COINID=\"Stealth\" +COIN_COINID_HEADER=\"STEALTH\" +COIN_COINID_NAME=\"Stealth\" +COIN_COINID_SHORT=\"XST\" +COIN_KIND=COIN_KIND_STEALTH +COIN_FLAGS=FLAG_PEERCOIN_UNITS\|FLAG_PEERCOIN_SUPPORT +APPNAME ="Stealth" + +else ifeq ($(COIN),viacoin) +# Viacoin +BIP44_COIN_TYPE=14 +BIP44_COIN_TYPE_2=14 +COIN_P2PKH_VERSION=71 +COIN_P2SH_VERSION=33 +COIN_FAMILY=1 +COIN_COINID=\"Viacoin\" +COIN_COINID_HEADER=\"VIACOIN\" +COIN_COINID_NAME=\"Viacoin\" +COIN_COINID_SHORT=\"VIA\" +COIN_KIND=COIN_KIND_VIACOIN +COIN_FLAGS=FLAG_SEGWIT_CHANGE_SUPPORT +APPNAME ="Viacoin" + +else ifeq ($(COIN),vertcoin) +# Vertcoin +# 128 was used in the Chrome apps +BIP44_COIN_TYPE=28 +BIP44_COIN_TYPE_2=128 +COIN_P2PKH_VERSION=71 +COIN_P2SH_VERSION=5 +COIN_FAMILY=1 +COIN_COINID=\"Vertcoin\" +COIN_COINID_HEADER=\"VERTCOIN\" +COIN_COINID_NAME=\"Vertcoin\" +COIN_COINID_SHORT=\"VTC\" +COIN_NATIVE_SEGWIT_PREFIX=\"vtc\" +COIN_KIND=COIN_KIND_VERTCOIN +COIN_FLAGS=FLAG_SEGWIT_CHANGE_SUPPORT +APPNAME ="Vertcoin" + +else ifeq ($(COIN),digibyte) +BIP44_COIN_TYPE=20 +BIP44_COIN_TYPE_2=20 +COIN_P2PKH_VERSION=30 +COIN_P2SH_VERSION=63 +COIN_FAMILY=1 +COIN_COINID=\"DigiByte\" +COIN_COINID_HEADER=\"DIGIBYTE\" +COIN_COINID_NAME=\"DigiByte\" +COIN_COINID_SHORT=\"DGB\" +COIN_NATIVE_SEGWIT_PREFIX=\"dgb\" +COIN_KIND=COIN_KIND_DIGIBYTE +COIN_FLAGS=FLAG_SEGWIT_CHANGE_SUPPORT +APPNAME ="Digibyte" + +else ifeq ($(COIN),qtum) +$(error the qtum variant is deprecated and has been moved to its dedicated repo +else ifeq ($(COIN),firo) +BIP44_COIN_TYPE=136 +BIP44_COIN_TYPE_2=136 +COIN_P2PKH_VERSION=82 +COIN_P2SH_VERSION=7 +COIN_FAMILY=1 +COIN_COINID=\"Zcoin\" +COIN_COINID_HEADER=\"FIRO\" +COIN_COINID_NAME=\"Firo\" +COIN_COINID_SHORT=\"FIRO\" +COIN_KIND=COIN_KIND_FIRO +APPNAME ="Firo" + +else ifeq ($(COIN),bitcoin_private) +# Bitcoin Private +# Initial fork from Bitcoin, public key access is authorized. Signature is different thanks to the forkId +# Note : might need a third lock on ZClassic +BIP44_COIN_TYPE=183 +BIP44_COIN_TYPE_2=0 +COIN_P2PKH_VERSION=4901 +COIN_P2SH_VERSION=5039 +COIN_FAMILY=1 +COIN_COINID=\"BPrivate\" +COIN_COINID_HEADER=\"BITCOINPRIVATE\" +COIN_COINID_NAME=\"BPrivate\" +COIN_COINID_SHORT=\"BTCP\" +COIN_KIND=COIN_KIND_BITCOIN_PRIVATE +COIN_FORKID=42 +APPNAME ="Bitcoin Private" + +else ifeq ($(COIN),gamecredits) +# GameCredits +BIP44_COIN_TYPE=101 +BIP44_COIN_TYPE_2=101 +COIN_P2PKH_VERSION=38 +COIN_P2SH_VERSION=62 +COIN_FAMILY=1 +COIN_COINID=\"GameCredits\" +COIN_COINID_HEADER=\"GAMECREDITS\" +COIN_COINID_NAME=\"GameCredits\" +COIN_COINID_SHORT=\"GAME\" +COIN_KIND=COIN_KIND_GAMECREDITS +COIN_FLAGS=FLAG_SEGWIT_CHANGE_SUPPORT +APPNAME ="GameCredits" + +else ifeq ($(COIN),zclassic) +# ZClassic +BIP44_COIN_TYPE=147 +BIP44_COIN_TYPE_2=147 +COIN_P2PKH_VERSION=7352 +COIN_P2SH_VERSION=7357 +COIN_FAMILY=1 +COIN_COINID=\"ZClassic\" +COIN_COINID_HEADER=\"ZCLASSIC\" +COIN_COINID_NAME=\"ZClassic\" +COIN_COINID_SHORT=\"ZCL\" +COIN_KIND=COIN_KIND_ZCLASSIC +APPNAME ="ZClassic" + +else ifeq ($(COIN),xsn) +# XSN mainnet +BIP44_COIN_TYPE=384 +BIP44_COIN_TYPE_2=384 +COIN_P2PKH_VERSION=76 +COIN_P2SH_VERSION=16 +COIN_FAMILY=1 +COIN_COINID=\"XSN\" +COIN_COINID_HEADER=\"XSN\" +COIN_COINID_NAME=\"XSN\" +COIN_COINID_SHORT=\"XSN\" +COIN_NATIVE_SEGWIT_PREFIX=\"xc\" +COIN_KIND=COIN_KIND_XSN +COIN_FLAGS=FLAG_SEGWIT_CHANGE_SUPPORT +APPNAME ="XSN" + +else ifeq ($(COIN),nix) +# NIX +BIP44_COIN_TYPE=400 +BIP44_COIN_TYPE_2=400 +COIN_P2PKH_VERSION=38 +COIN_P2SH_VERSION=53 +COIN_FAMILY=1 +COIN_COINID=\"NIX\" +COIN_COINID_HEADER=\"NIX\" +COIN_COINID_NAME=\"NIX\" +COIN_COINID_SHORT=\"NIX\" +COIN_NATIVE_SEGWIT_PREFIX=\"nix\" +COIN_KIND=COIN_KIND_NIX +COIN_FLAGS=FLAG_SEGWIT_CHANGE_SUPPORT +APPNAME ="NIX" + +else ifeq ($(COIN),lbry) +# LBRY +BIP44_COIN_TYPE=140 +BIP44_COIN_TYPE_2=140 +COIN_P2PKH_VERSION=85 +COIN_P2SH_VERSION=122 +COIN_FAMILY=1 +COIN_COINID=\"LBRY\" +COIN_COINID_HEADER=\"LBRY\" +COIN_COINID_NAME=\"LBRY\" +COIN_COINID_SHORT=\"LBC\" +COIN_KIND=COIN_KIND_LBRY +APPNAME ="LBRY" + +else ifeq ($(COIN),resistance) +# Resistance +BIP44_COIN_TYPE=356 +BIP44_COIN_TYPE_2=356 +COIN_P2PKH_VERSION=7063 +COIN_P2SH_VERSION=7068 +COIN_FAMILY=1 +COIN_COINID=\"Res\" +COIN_COINID_HEADER=\"RES\" +COIN_COINID_NAME=\"Res\" +COIN_COINID_SHORT=\"RES\" +COIN_KIND=COIN_KIND_RESISTANCE +APPNAME ="Resistance" + +else ifeq ($(COIN),ravencoin) +# Ravencoin +BIP44_COIN_TYPE=175 +BIP44_COIN_TYPE_2=175 +COIN_P2PKH_VERSION=60 +COIN_P2SH_VERSION=122 +COIN_FAMILY=1 +COIN_COINID=\"Ravencoin\" +COIN_COINID_HEADER=\"RAVENCOIN\" +COIN_COINID_NAME=\"Ravencoin\" +COIN_COINID_SHORT=\"RVN\" +COIN_KIND=COIN_KIND_RAVENCOIN +APPNAME ="Ravencoin" + +else ifeq ($(COIN),hydra_testnet) +# Hydra testnet +BIP44_COIN_TYPE=0 +BIP44_COIN_TYPE_2=0 +COIN_P2PKH_VERSION=66 +COIN_P2SH_VERSION=128 +COIN_FAMILY=3 +COIN_COINID=\"Hydra\" +COIN_COINID_HEADER=\"HYDRA\" +COIN_COINID_NAME=\"HYDRA\" +COIN_COINID_SHORT=\"HYDRA\" +COIN_NATIVE_SEGWIT_PREFIX=\"hc\" +COIN_KIND=COIN_KIND_HYDRA +COIN_FLAGS=FLAG_SEGWIT_CHANGE_SUPPORT +APPNAME ="Hydra Test" +APP_LOAD_PARAMS += --path "44'/609'" + +else ifeq ($(COIN),hydra) +# Hydra mainnet +BIP44_COIN_TYPE=0 +BIP44_COIN_TYPE_2=0 +COIN_P2PKH_VERSION=40 +COIN_P2SH_VERSION=63 +COIN_FAMILY=3 +COIN_COINID=\"Hydra\" +COIN_COINID_HEADER=\"HYDRA\" +COIN_COINID_NAME=\"HYDRA\" +COIN_COINID_SHORT=\"HYDRA\" +COIN_NATIVE_SEGWIT_PREFIX=\"hc\" +COIN_KIND=COIN_KIND_HYDRA +COIN_FLAGS=FLAG_SEGWIT_CHANGE_SUPPORT +APPNAME ="Hydra" +APP_LOAD_PARAMS += --path "44'/609'" + +else ifeq ($(filter clean,$(MAKECMDGOALS)),) +$(error Unsupported COIN - use bitcoin_testnet, bitcoin, bitcoin_cash, bitcoin_gold, litecoin, dogecoin, dash, zcash, horizen, komodo, stratis, peercoin, pivx, viacoin, vertcoin, stealth, digibyte, bitcoin_private, firo, gamecredits, zclassic, xsn, nix, lbry, resistance, ravencoin, hydra, hydra_testnet, xrhodium) endif include lib-app-bitcoin/Makefile diff --git a/lib-app-bitcoin/Makefile b/lib-app-bitcoin/Makefile index 9585aec1..b19b0cc3 100644 --- a/lib-app-bitcoin/Makefile +++ b/lib-app-bitcoin/Makefile @@ -115,7 +115,8 @@ $(error COIN_KIND must be defined) endif ifndef COIN_FLAGS -$(error COIN_FLAGS must be defined) +$(info COIN_FLAGS automatically set to 0) +COIN_FLAGS=0 endif ifndef COIN_FORKID diff --git a/lib-app-bitcoin/handler/hash_input_finalize_full.c b/lib-app-bitcoin/handler/hash_input_finalize_full.c index 41815b2c..a1ed5acd 100644 --- a/lib-app-bitcoin/handler/hash_input_finalize_full.c +++ b/lib-app-bitcoin/handler/hash_input_finalize_full.c @@ -536,7 +536,7 @@ unsigned short handler_hash_input_finalize_full(buffer_t* buffer, uint8_t p1, ui if (is_async) { // if the UI reject the processing of the request, then reply // immediately - bool status; + int status; if(context_D.outputParsingState == BIP44_CHANGE_PATH_VALIDATION) { context_D.outputParsingState = OUTPUT_PARSING_NUMBER_OUTPUTS; return 0; @@ -547,7 +547,7 @@ unsigned short handler_hash_input_finalize_full(buffer_t* buffer, uint8_t p1, ui else { status = confirm_single_output(); } - if (!status) { + if (status == 0) { ui_transaction_error(); context_D.transactionContext.transactionState = TRANSACTION_NONE; @@ -555,6 +555,9 @@ unsigned short handler_hash_input_finalize_full(buffer_t* buffer, uint8_t p1, ui sw = SW_INCORRECT_DATA; return io_send_sw(sw); } + else if (status == 2) { + return io_send_response_pointer(G_io_apdu_buffer, context_D.outLength, SW_OK); + } return 0; } return io_send_response_pointer(G_io_apdu_buffer, context_D.outLength, sw); diff --git a/lib-app-bitcoin/handler/hash_sign.c b/lib-app-bitcoin/handler/hash_sign.c index bf450ce5..bd505aa7 100644 --- a/lib-app-bitcoin/handler/hash_sign.c +++ b/lib-app-bitcoin/handler/hash_sign.c @@ -102,7 +102,7 @@ WEAK unsigned short handler_hash_sign(buffer_t* buffer, uint8_t p1, uint8_t p2) context_D.transactionSummary.sighashType = sighashType; // if bitcoin cash OR forkid is set, then use the fork id - if (COIN_KIND == COIN_KIND_BITCOIN_CASH || + if ((COIN_KIND == COIN_KIND_BITCOIN_CASH) || (COIN_FORKID)) { #define SIGHASH_FORKID 0x40 if (sighashType != (SIGHASH_ALL | SIGHASH_FORKID)) { diff --git a/lib-app-bitcoin/ui/main_ui.c b/lib-app-bitcoin/ui/main_ui.c index 009fdd13..850e6016 100644 --- a/lib-app-bitcoin/ui/main_ui.c +++ b/lib-app-bitcoin/ui/main_ui.c @@ -230,7 +230,10 @@ unsigned int silent_confirm_single_output() { unsigned int confirm_single_output(void) { if (G_called_from_swap) { - return silent_confirm_single_output(); + if (silent_confirm_single_output()) { + return 2; + } + return 0; } prepare_single_output(); @@ -240,7 +243,9 @@ unsigned int confirm_single_output(void) { unsigned int finalize_tx(void) { if (G_called_from_swap) { - return check_fee_swap(); + if (check_fee_swap()) { + return 2; + } } if (!prepare_fees()) {