Apply clang-format

This commit is contained in:
TamtamHero
2020-12-01 16:20:13 +01:00
parent 1421a74be5
commit 17bd07a346
80 changed files with 8859 additions and 5091 deletions

View File

@@ -1,76 +1,135 @@
#include "shared_context.h"
#define APP_FLAG_DATA_ALLOWED 0x01
#define APP_FLAG_DATA_ALLOWED 0x01
#define APP_FLAG_EXTERNAL_TOKEN_NEEDED 0x02
#define APP_FLAG_STARKWARE 0x04
#define APP_FLAG_STARKWARE_V2 0x08
#define APP_FLAG_STARKWARE 0x04
#define APP_FLAG_STARKWARE_V2 0x08
#define CLA 0xE0
#define INS_GET_PUBLIC_KEY 0x02
#define INS_SIGN 0x04
#define INS_GET_APP_CONFIGURATION 0x06
#define INS_SIGN_PERSONAL_MESSAGE 0x08
#define CLA 0xE0
#define INS_GET_PUBLIC_KEY 0x02
#define INS_SIGN 0x04
#define INS_GET_APP_CONFIGURATION 0x06
#define INS_SIGN_PERSONAL_MESSAGE 0x08
#define INS_PROVIDE_ERC20_TOKEN_INFORMATION 0x0A
#define INS_SIGN_EIP_712_MESSAGE 0x0C
#define INS_GET_ETH2_PUBLIC_KEY 0x0E
#define INS_SET_ETH2_WITHDRAWAL_INDEX 0x10
#define P1_CONFIRM 0x01
#define P1_NON_CONFIRM 0x00
#define P2_NO_CHAINCODE 0x00
#define P2_CHAINCODE 0x01
#define P1_FIRST 0x00
#define P1_MORE 0x80
#define INS_SIGN_EIP_712_MESSAGE 0x0C
#define INS_GET_ETH2_PUBLIC_KEY 0x0E
#define INS_SET_ETH2_WITHDRAWAL_INDEX 0x10
#define P1_CONFIRM 0x01
#define P1_NON_CONFIRM 0x00
#define P2_NO_CHAINCODE 0x00
#define P2_CHAINCODE 0x01
#define P1_FIRST 0x00
#define P1_MORE 0x80
#define COMMON_CLA 0xB0
#define COMMON_CLA 0xB0
#define COMMON_INS_GET_WALLET_ID 0x04
#ifdef HAVE_STARKWARE
#define STARKWARE_CLA 0xF0
#define STARKWARE_INS_GET_PUBLIC_KEY 0x02
#define STARKWARE_INS_SIGN_MESSAGE 0x04
#define STARKWARE_CLA 0xF0
#define STARKWARE_INS_GET_PUBLIC_KEY 0x02
#define STARKWARE_INS_SIGN_MESSAGE 0x04
#define STARKWARE_INS_PROVIDE_QUANTUM 0x08
#define STARKWARE_INS_UNSAFE_SIGN 0x0A
#define STARKWARE_INS_UNSAFE_SIGN 0x0A
#define P1_STARK_ORDER 0x01
#define P1_STARK_TRANSFER 0x02
#define P1_STARK_ORDER_V2 0x03
#define P1_STARK_TRANSFER_V2 0x04
#define P1_STARK_ORDER 0x01
#define P1_STARK_TRANSFER 0x02
#define P1_STARK_ORDER_V2 0x03
#define P1_STARK_TRANSFER_V2 0x04
#define P1_STARK_CONDITIONAL_TRANSFER 0x05
#define STARK_ORDER_TYPE 0
#define STARK_TRANSFER_TYPE 1
#define STARK_ORDER_TYPE 0
#define STARK_TRANSFER_TYPE 1
#define STARK_CONDITIONAL_TRANSFER_TYPE 2
#endif
#define OFFSET_CLA 0
#define OFFSET_INS 1
#define OFFSET_P1 2
#define OFFSET_P2 3
#define OFFSET_LC 4
#define OFFSET_CLA 0
#define OFFSET_INS 1
#define OFFSET_P1 2
#define OFFSET_P2 3
#define OFFSET_LC 4
#define OFFSET_CDATA 5
void handleGetPublicKey(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, unsigned int *flags, unsigned int *tx);
void handleProvideErc20TokenInformation(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, unsigned int *flags, unsigned int *tx);
void handleSign(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, unsigned int *flags, unsigned int *tx);
void handleGetAppConfiguration(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, unsigned int *flags, unsigned int *tx);
void handleSignPersonalMessage(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, unsigned int *flags, unsigned int *tx);
void handleSignEIP712Message(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, unsigned int *flags, unsigned int *tx);
void handleGetPublicKey(uint8_t p1,
uint8_t p2,
uint8_t *dataBuffer,
uint16_t dataLength,
unsigned int *flags,
unsigned int *tx);
void handleProvideErc20TokenInformation(uint8_t p1,
uint8_t p2,
uint8_t *dataBuffer,
uint16_t dataLength,
unsigned int *flags,
unsigned int *tx);
void handleSign(uint8_t p1,
uint8_t p2,
uint8_t *dataBuffer,
uint16_t dataLength,
unsigned int *flags,
unsigned int *tx);
void handleGetAppConfiguration(uint8_t p1,
uint8_t p2,
uint8_t *dataBuffer,
uint16_t dataLength,
unsigned int *flags,
unsigned int *tx);
void handleSignPersonalMessage(uint8_t p1,
uint8_t p2,
uint8_t *dataBuffer,
uint16_t dataLength,
unsigned int *flags,
unsigned int *tx);
void handleSignEIP712Message(uint8_t p1,
uint8_t p2,
uint8_t *dataBuffer,
uint16_t dataLength,
unsigned int *flags,
unsigned int *tx);
#ifdef HAVE_ETH2
void handleGetEth2PublicKey(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, unsigned int *flags, unsigned int *tx);
void handleSetEth2WinthdrawalIndex(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, unsigned int *flags, unsigned int *tx);
void handleGetEth2PublicKey(uint8_t p1,
uint8_t p2,
uint8_t *dataBuffer,
uint16_t dataLength,
unsigned int *flags,
unsigned int *tx);
void handleSetEth2WinthdrawalIndex(uint8_t p1,
uint8_t p2,
uint8_t *dataBuffer,
uint16_t dataLength,
unsigned int *flags,
unsigned int *tx);
#endif
#ifdef HAVE_STARKWARE
void handleStarkwareGetPublicKey(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, unsigned int *flags, unsigned int *tx);
void handleStarkwareSignMessage(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, unsigned int *flags, unsigned int *tx);
void handleStarkwareProvideQuantum(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, unsigned int *flags, unsigned int *tx);
void handleStarkwareUnsafeSign(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t dataLength, unsigned int *flags, unsigned int *tx);
void handleStarkwareGetPublicKey(uint8_t p1,
uint8_t p2,
uint8_t *dataBuffer,
uint16_t dataLength,
unsigned int *flags,
unsigned int *tx);
void handleStarkwareSignMessage(uint8_t p1,
uint8_t p2,
uint8_t *dataBuffer,
uint16_t dataLength,
unsigned int *flags,
unsigned int *tx);
void handleStarkwareProvideQuantum(uint8_t p1,
uint8_t p2,
uint8_t *dataBuffer,
uint16_t dataLength,
unsigned int *flags,
unsigned int *tx);
void handleStarkwareUnsafeSign(uint8_t p1,
uint8_t p2,
uint8_t *dataBuffer,
uint16_t dataLength,
unsigned int *flags,
unsigned int *tx);
#endif

View File

@@ -2,16 +2,16 @@
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
*
* Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
*
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
@@ -19,7 +19,7 @@
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
*
* @APPLE_LICENSE_HEADER_END@
*/
/* ====================================================================
@@ -172,41 +172,34 @@ int Base64decode(char *bufplain, const char *bufcoded)
#endif
static const char basis_64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char basis_64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int Base64encode_len(int len)
{
int Base64encode_len(int len) {
return ((len + 2) / 3 * 4) + 1;
}
int Base64encode(char *encoded, const char *string, int len)
{
int Base64encode(char *encoded, const char *string, int len) {
int i;
char *p;
p = encoded;
for (i = 0; i < len - 2; i += 3) {
*p++ = basis_64[(string[i] >> 2) & 0x3F];
*p++ = basis_64[((string[i] & 0x3) << 4) |
((int) (string[i + 1] & 0xF0) >> 4)];
*p++ = basis_64[((string[i + 1] & 0xF) << 2) |
((int) (string[i + 2] & 0xC0) >> 6)];
*p++ = basis_64[string[i + 2] & 0x3F];
*p++ = basis_64[(string[i] >> 2) & 0x3F];
*p++ = basis_64[((string[i] & 0x3) << 4) | ((int) (string[i + 1] & 0xF0) >> 4)];
*p++ = basis_64[((string[i + 1] & 0xF) << 2) | ((int) (string[i + 2] & 0xC0) >> 6)];
*p++ = basis_64[string[i + 2] & 0x3F];
}
if (i < len) {
*p++ = basis_64[(string[i] >> 2) & 0x3F];
if (i == (len - 1)) {
*p++ = basis_64[((string[i] & 0x3) << 4)];
*p++ = basis_64[(string[i] >> 2) & 0x3F];
if (i == (len - 1)) {
*p++ = basis_64[((string[i] & 0x3) << 4)];
*p++ = '=';
} else {
*p++ = basis_64[((string[i] & 0x3) << 4) | ((int) (string[i + 1] & 0xF0) >> 4)];
*p++ = basis_64[((string[i + 1] & 0xF) << 2)];
}
*p++ = '=';
}
else {
*p++ = basis_64[((string[i] & 0x3) << 4) |
((int) (string[i + 1] & 0xF0) >> 4)];
*p++ = basis_64[((string[i + 1] & 0xF) << 2)];
}
*p++ = '=';
}
*p++ = '\0';
return p - encoded;

View File

@@ -2,16 +2,16 @@
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
*
* Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
*
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
@@ -19,7 +19,7 @@
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
*
* @APPLE_LICENSE_HEADER_END@
*/
/* ====================================================================
@@ -79,8 +79,6 @@
*
*/
#ifndef _BASE64_H_
#define _BASE64_H_
@@ -89,7 +87,7 @@ extern "C" {
#endif
int Base64encode_len(int len);
int Base64encode(char * coded_dst, const char *plain_src,int len_plain_src);
int Base64encode(char *coded_dst, const char *plain_src, int len_plain_src);
#if 0
@@ -102,4 +100,4 @@ int Base64decode(char * plain_dst, const char *coded_src);
}
#endif
#endif //_BASE64_H_
#endif //_BASE64_H_

View File

@@ -1,19 +1,19 @@
/*******************************************************************************
* Ledger Ethereum App
* (c) 2016-2019 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.
********************************************************************************/
* Ledger Ethereum App
* (c) 2016-2019 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.
********************************************************************************/
#ifndef _CHAIN_CONFIG_H_
#define _CHAIN_CONFIG_H_
@@ -23,42 +23,42 @@
#include "os.h"
typedef enum chain_kind_e {
CHAIN_KIND_ETHEREUM,
CHAIN_KIND_ETHEREUM_CLASSIC,
CHAIN_KIND_EXPANSE,
CHAIN_KIND_POA,
CHAIN_KIND_RSK,
CHAIN_KIND_UBIQ,
CHAIN_KIND_WANCHAIN,
CHAIN_KIND_KUSD,
CHAIN_KIND_PIRL,
CHAIN_KIND_AKROMA,
CHAIN_KIND_MUSICOIN,
CHAIN_KIND_CALLISTO,
CHAIN_KIND_ETHERSOCIAL,
CHAIN_KIND_ELLAISM,
CHAIN_KIND_ETHER1,
CHAIN_KIND_ETHERGEM,
CHAIN_KIND_ATHEIOS,
CHAIN_KIND_GOCHAIN,
CHAIN_KIND_MIX,
CHAIN_KIND_REOSC,
CHAIN_KIND_HPB,
CHAIN_KIND_TOMOCHAIN,
CHAIN_KIND_TOBALABA,
CHAIN_KIND_DEXON,
CHAIN_KIND_VOLTA,
CHAIN_KIND_EWC,
CHAIN_KIND_ARTIS_SIGMA1,
CHAIN_KIND_ARTIS_TAU1,
CHAIN_KIND_WEBCHAIN,
CHAIN_KIND_THUNDERCORE
CHAIN_KIND_ETHEREUM,
CHAIN_KIND_ETHEREUM_CLASSIC,
CHAIN_KIND_EXPANSE,
CHAIN_KIND_POA,
CHAIN_KIND_RSK,
CHAIN_KIND_UBIQ,
CHAIN_KIND_WANCHAIN,
CHAIN_KIND_KUSD,
CHAIN_KIND_PIRL,
CHAIN_KIND_AKROMA,
CHAIN_KIND_MUSICOIN,
CHAIN_KIND_CALLISTO,
CHAIN_KIND_ETHERSOCIAL,
CHAIN_KIND_ELLAISM,
CHAIN_KIND_ETHER1,
CHAIN_KIND_ETHERGEM,
CHAIN_KIND_ATHEIOS,
CHAIN_KIND_GOCHAIN,
CHAIN_KIND_MIX,
CHAIN_KIND_REOSC,
CHAIN_KIND_HPB,
CHAIN_KIND_TOMOCHAIN,
CHAIN_KIND_TOBALABA,
CHAIN_KIND_DEXON,
CHAIN_KIND_VOLTA,
CHAIN_KIND_EWC,
CHAIN_KIND_ARTIS_SIGMA1,
CHAIN_KIND_ARTIS_TAU1,
CHAIN_KIND_WEBCHAIN,
CHAIN_KIND_THUNDERCORE
} chain_kind_t;
typedef struct chain_config_s {
char coinName[10]; // ticker
uint32_t chainId;
chain_kind_t kind;
char coinName[10]; // ticker
uint32_t chainId;
chain_kind_t kind;
} chain_config_t;
#endif /* _CHAIN_CONFIG_H_ */

View File

@@ -5,248 +5,267 @@
#include "base64.h"
void eth_plugin_prepare_init(ethPluginInitContract_t *init, uint8_t *selector, uint32_t dataSize) {
memset((uint8_t*)init, 0, sizeof(ethPluginInitContract_t));
init->selector = selector;
init->dataSize = dataSize;
memset((uint8_t *) init, 0, sizeof(ethPluginInitContract_t));
init->selector = selector;
init->dataSize = dataSize;
}
void eth_plugin_prepare_provide_parameter(ethPluginProvideParameter_t *provideParameter, uint8_t *parameter, uint32_t parameterOffset) {
memset((uint8_t*)provideParameter, 0, sizeof(ethPluginProvideParameter_t));
provideParameter->parameter = parameter;
provideParameter->parameterOffset = parameterOffset;
void eth_plugin_prepare_provide_parameter(ethPluginProvideParameter_t *provideParameter,
uint8_t *parameter,
uint32_t parameterOffset) {
memset((uint8_t *) provideParameter, 0, sizeof(ethPluginProvideParameter_t));
provideParameter->parameter = parameter;
provideParameter->parameterOffset = parameterOffset;
}
void eth_plugin_prepare_finalize(ethPluginFinalize_t *finalize) {
memset((uint8_t*)finalize, 0, sizeof(ethPluginFinalize_t));
memset((uint8_t *) finalize, 0, sizeof(ethPluginFinalize_t));
}
void eth_plugin_prepare_provide_token(ethPluginProvideToken_t *provideToken, tokenDefinition_t *token1, tokenDefinition_t *token2) {
memset((uint8_t*)provideToken, 0, sizeof(ethPluginProvideToken_t));
provideToken->token1 = token1;
provideToken->token2 = token2;
void eth_plugin_prepare_provide_token(ethPluginProvideToken_t *provideToken,
tokenDefinition_t *token1,
tokenDefinition_t *token2) {
memset((uint8_t *) provideToken, 0, sizeof(ethPluginProvideToken_t));
provideToken->token1 = token1;
provideToken->token2 = token2;
}
void eth_plugin_prepare_query_contract_ID(ethQueryContractID_t *queryContractID, char *name, uint32_t nameLength, char *version, uint32_t versionLength) {
memset((uint8_t*)queryContractID, 0, sizeof(ethQueryContractID_t));
queryContractID->name = name;
queryContractID->nameLength = nameLength;
queryContractID->version = version;
queryContractID->versionLength = versionLength;
void eth_plugin_prepare_query_contract_ID(ethQueryContractID_t *queryContractID,
char *name,
uint32_t nameLength,
char *version,
uint32_t versionLength) {
memset((uint8_t *) queryContractID, 0, sizeof(ethQueryContractID_t));
queryContractID->name = name;
queryContractID->nameLength = nameLength;
queryContractID->version = version;
queryContractID->versionLength = versionLength;
}
void eth_plugin_prepare_query_contract_UI(ethQueryContractUI_t *queryContractUI, uint8_t screenIndex, char *title, uint32_t titleLength, char *msg, uint32_t msgLength) {
memset((uint8_t*)queryContractUI, 0, sizeof(ethQueryContractUI_t));
queryContractUI->screenIndex = screenIndex;
queryContractUI->title = title;
queryContractUI->titleLength = titleLength;
queryContractUI->msg = msg;
queryContractUI->msgLength = msgLength;
void eth_plugin_prepare_query_contract_UI(ethQueryContractUI_t *queryContractUI,
uint8_t screenIndex,
char *title,
uint32_t titleLength,
char *msg,
uint32_t msgLength) {
memset((uint8_t *) queryContractUI, 0, sizeof(ethQueryContractUI_t));
queryContractUI->screenIndex = screenIndex;
queryContractUI->title = title;
queryContractUI->titleLength = titleLength;
queryContractUI->msg = msg;
queryContractUI->msgLength = msgLength;
}
int eth_plugin_perform_init(uint8_t *contractAddress, ethPluginInitContract_t *init) {
uint8_t i;
const uint8_t **selectors;
dataContext.tokenContext.pluginAvailable = 0;
// Handle hardcoded plugin list
PRINTF("Selector %.*H\n", 4, init->selector);
for (i=0;; i++) {
uint8_t j;
selectors = PIC(INTERNAL_ETH_PLUGINS[i].selectors);
if (selectors == NULL) {
break;
}
for (j=0; ((j<INTERNAL_ETH_PLUGINS[i].num_selectors) && (contractAddress != NULL)); j++) {
if (memcmp(init->selector, PIC(selectors[j]), SELECTOR_SIZE) == 0) {
if ((INTERNAL_ETH_PLUGINS[i].availableCheck == NULL) ||
((PluginAvailableCheck)PIC(INTERNAL_ETH_PLUGINS[i].availableCheck))()) {
strcpy(dataContext.tokenContext.pluginName, INTERNAL_ETH_PLUGINS[i].alias);
dataContext.tokenContext.pluginAvailable = 1;
contractAddress = NULL;
break;
}
}
}
}
uint8_t i;
const uint8_t **selectors;
dataContext.tokenContext.pluginAvailable = 0;
// Handle hardcoded plugin list
PRINTF("Selector %.*H\n", 4, init->selector);
for (i = 0;; i++) {
uint8_t j;
selectors = PIC(INTERNAL_ETH_PLUGINS[i].selectors);
if (selectors == NULL) {
break;
}
for (j = 0; ((j < INTERNAL_ETH_PLUGINS[i].num_selectors) && (contractAddress != NULL));
j++) {
if (memcmp(init->selector, PIC(selectors[j]), SELECTOR_SIZE) == 0) {
if ((INTERNAL_ETH_PLUGINS[i].availableCheck == NULL) ||
((PluginAvailableCheck) PIC(INTERNAL_ETH_PLUGINS[i].availableCheck))()) {
strcpy(dataContext.tokenContext.pluginName, INTERNAL_ETH_PLUGINS[i].alias);
dataContext.tokenContext.pluginAvailable = 1;
contractAddress = NULL;
break;
}
}
}
}
// Do not handle a plugin if running in swap mode
if (called_from_swap && (contractAddress != NULL)) {
PRINTF("eth_plug_init aborted in swap mode\n");
return 0;
}
for (;;) {
PRINTF("eth_plugin_init\n");
if (contractAddress != NULL) {
PRINTF("Trying address %.*H\n", 20, contractAddress);
}
else {
PRINTF("Trying alias %s\n", dataContext.tokenContext.pluginName);
}
int status = eth_plugin_call(contractAddress, ETH_PLUGIN_INIT_CONTRACT, (void*)init);
if (!status) {
return 0;
}
if (status == ETH_PLUGIN_RESULT_OK) {
break;
}
if (status == ETH_PLUGIN_RESULT_OK_ALIAS) {
contractAddress = NULL;
}
}
PRINTF("eth_plugin_init ok %s\n", dataContext.tokenContext.pluginName);
dataContext.tokenContext.pluginAvailable = 1;
return 1;
// Do not handle a plugin if running in swap mode
if (called_from_swap && (contractAddress != NULL)) {
PRINTF("eth_plug_init aborted in swap mode\n");
return 0;
}
for (;;) {
PRINTF("eth_plugin_init\n");
if (contractAddress != NULL) {
PRINTF("Trying address %.*H\n", 20, contractAddress);
} else {
PRINTF("Trying alias %s\n", dataContext.tokenContext.pluginName);
}
int status = eth_plugin_call(contractAddress, ETH_PLUGIN_INIT_CONTRACT, (void *) init);
if (!status) {
return 0;
}
if (status == ETH_PLUGIN_RESULT_OK) {
break;
}
if (status == ETH_PLUGIN_RESULT_OK_ALIAS) {
contractAddress = NULL;
}
}
PRINTF("eth_plugin_init ok %s\n", dataContext.tokenContext.pluginName);
dataContext.tokenContext.pluginAvailable = 1;
return 1;
}
int eth_plugin_call(uint8_t *contractAddress, int method, void *parameter) {
ethPluginSharedRW_t pluginRW;
ethPluginSharedRO_t pluginRO;
char tmp[PLUGIN_ID_LENGTH];
char *alias;
uint8_t i;
uint8_t internalPlugin = 0;
ethPluginSharedRW_t pluginRW;
ethPluginSharedRO_t pluginRO;
char tmp[PLUGIN_ID_LENGTH];
char *alias;
uint8_t i;
uint8_t internalPlugin = 0;
pluginRW.sha3 = &global_sha3;
pluginRO.txContent = &tmpContent.txContent;
pluginRW.sha3 = &global_sha3;
pluginRO.txContent = &tmpContent.txContent;
if (contractAddress == NULL) {
if (!dataContext.tokenContext.pluginAvailable) {
PRINTF("Cached plugin call but no plugin available\n");
return 0;
}
alias = dataContext.tokenContext.pluginName;
}
else {
Base64encode(tmp, (char*)contractAddress, 20);
alias = tmp;
}
if (contractAddress == NULL) {
if (!dataContext.tokenContext.pluginAvailable) {
PRINTF("Cached plugin call but no plugin available\n");
return 0;
}
alias = dataContext.tokenContext.pluginName;
} else {
Base64encode(tmp, (char *) contractAddress, 20);
alias = tmp;
}
// Prepare the call
// Prepare the call
switch(method) {
case ETH_PLUGIN_INIT_CONTRACT:
((ethPluginInitContract_t*)parameter)->pluginSharedRW = &pluginRW;
((ethPluginInitContract_t*)parameter)->pluginSharedRO = &pluginRO;
((ethPluginInitContract_t*)parameter)->pluginContext = (uint8_t*)&dataContext.tokenContext.pluginContext;
((ethPluginInitContract_t*)parameter)->pluginContextLength = sizeof(dataContext.tokenContext.pluginContext);
((ethPluginInitContract_t*)parameter)->alias = dataContext.tokenContext.pluginName;
break;
case ETH_PLUGIN_PROVIDE_PARAMETER:
((ethPluginProvideParameter_t*)parameter)->pluginSharedRW = &pluginRW;
((ethPluginProvideParameter_t*)parameter)->pluginSharedRO = &pluginRO;
((ethPluginProvideParameter_t*)parameter)->pluginContext = (uint8_t*)&dataContext.tokenContext.pluginContext;
break;
case ETH_PLUGIN_FINALIZE:
((ethPluginFinalize_t*)parameter)->pluginSharedRW = &pluginRW;
((ethPluginFinalize_t*)parameter)->pluginSharedRO = &pluginRO;
((ethPluginFinalize_t*)parameter)->pluginContext = (uint8_t*)&dataContext.tokenContext.pluginContext;
break;
case ETH_PLUGIN_PROVIDE_TOKEN:
((ethPluginProvideToken_t*)parameter)->pluginSharedRW = &pluginRW;
((ethPluginProvideToken_t*)parameter)->pluginSharedRO = &pluginRO;
((ethPluginProvideToken_t*)parameter)->pluginContext = (uint8_t*)&dataContext.tokenContext.pluginContext;
break;
case ETH_PLUGIN_QUERY_CONTRACT_ID:
((ethQueryContractID_t*)parameter)->pluginSharedRW = &pluginRW;
((ethQueryContractID_t*)parameter)->pluginSharedRO = &pluginRO;
((ethQueryContractID_t*)parameter)->pluginContext = (uint8_t*)&dataContext.tokenContext.pluginContext;
break;
case ETH_PLUGIN_QUERY_CONTRACT_UI:
((ethQueryContractUI_t*)parameter)->pluginSharedRW = &pluginRW;
((ethQueryContractUI_t*)parameter)->pluginSharedRO = &pluginRO;
((ethQueryContractUI_t*)parameter)->pluginContext = (uint8_t*)&dataContext.tokenContext.pluginContext;
break;
default:
PRINTF("Unknown plugin method %d\n", method);
return 0;
}
switch (method) {
case ETH_PLUGIN_INIT_CONTRACT:
((ethPluginInitContract_t *) parameter)->pluginSharedRW = &pluginRW;
((ethPluginInitContract_t *) parameter)->pluginSharedRO = &pluginRO;
((ethPluginInitContract_t *) parameter)->pluginContext =
(uint8_t *) &dataContext.tokenContext.pluginContext;
((ethPluginInitContract_t *) parameter)->pluginContextLength =
sizeof(dataContext.tokenContext.pluginContext);
((ethPluginInitContract_t *) parameter)->alias = dataContext.tokenContext.pluginName;
break;
case ETH_PLUGIN_PROVIDE_PARAMETER:
((ethPluginProvideParameter_t *) parameter)->pluginSharedRW = &pluginRW;
((ethPluginProvideParameter_t *) parameter)->pluginSharedRO = &pluginRO;
((ethPluginProvideParameter_t *) parameter)->pluginContext =
(uint8_t *) &dataContext.tokenContext.pluginContext;
break;
case ETH_PLUGIN_FINALIZE:
((ethPluginFinalize_t *) parameter)->pluginSharedRW = &pluginRW;
((ethPluginFinalize_t *) parameter)->pluginSharedRO = &pluginRO;
((ethPluginFinalize_t *) parameter)->pluginContext =
(uint8_t *) &dataContext.tokenContext.pluginContext;
break;
case ETH_PLUGIN_PROVIDE_TOKEN:
((ethPluginProvideToken_t *) parameter)->pluginSharedRW = &pluginRW;
((ethPluginProvideToken_t *) parameter)->pluginSharedRO = &pluginRO;
((ethPluginProvideToken_t *) parameter)->pluginContext =
(uint8_t *) &dataContext.tokenContext.pluginContext;
break;
case ETH_PLUGIN_QUERY_CONTRACT_ID:
((ethQueryContractID_t *) parameter)->pluginSharedRW = &pluginRW;
((ethQueryContractID_t *) parameter)->pluginSharedRO = &pluginRO;
((ethQueryContractID_t *) parameter)->pluginContext =
(uint8_t *) &dataContext.tokenContext.pluginContext;
break;
case ETH_PLUGIN_QUERY_CONTRACT_UI:
((ethQueryContractUI_t *) parameter)->pluginSharedRW = &pluginRW;
((ethQueryContractUI_t *) parameter)->pluginSharedRO = &pluginRO;
((ethQueryContractUI_t *) parameter)->pluginContext =
(uint8_t *) &dataContext.tokenContext.pluginContext;
break;
default:
PRINTF("Unknown plugin method %d\n", method);
return 0;
}
// Perform the call
// Perform the call
for (i=0;; i++) {
if (INTERNAL_ETH_PLUGINS[i].alias[0] == 0) {
break;
}
if (strcmp(alias, INTERNAL_ETH_PLUGINS[i].alias) == 0) {
internalPlugin = 1;
((PluginCall)PIC(INTERNAL_ETH_PLUGINS[i].impl))(method, parameter);
break;
}
}
for (i = 0;; i++) {
if (INTERNAL_ETH_PLUGINS[i].alias[0] == 0) {
break;
}
if (strcmp(alias, INTERNAL_ETH_PLUGINS[i].alias) == 0) {
internalPlugin = 1;
((PluginCall) PIC(INTERNAL_ETH_PLUGINS[i].impl))(method, parameter);
break;
}
}
if (!internalPlugin) {
uint32_t params[3];
params[0] = (uint32_t)alias;
params[1] = method;
params[2] = (uint32_t)parameter;
BEGIN_TRY {
TRY {
os_lib_call(params);
}
CATCH_OTHER(e) {
PRINTF("Plugin call exception for %s\n", alias);
}
FINALLY {
}
}
END_TRY;
}
if (!internalPlugin) {
uint32_t params[3];
params[0] = (uint32_t) alias;
params[1] = method;
params[2] = (uint32_t) parameter;
BEGIN_TRY {
TRY {
os_lib_call(params);
}
CATCH_OTHER(e) {
PRINTF("Plugin call exception for %s\n", alias);
}
FINALLY {
}
}
END_TRY;
}
// Check the call result
// Check the call result
switch(method) {
case ETH_PLUGIN_INIT_CONTRACT:
switch (((ethPluginInitContract_t*)parameter)->result) {
case ETH_PLUGIN_RESULT_OK:
if (contractAddress != NULL) {
strcpy(dataContext.tokenContext.pluginName, alias);
}
break;
case ETH_PLUGIN_RESULT_OK_ALIAS:
break;
default:
return 0;
}
break;
case ETH_PLUGIN_PROVIDE_PARAMETER:
switch (((ethPluginProvideParameter_t*)parameter)->result) {
case ETH_PLUGIN_RESULT_OK:
case ETH_PLUGIN_RESULT_FALLBACK:
break;
default:
return 0;
}
break;
case ETH_PLUGIN_FINALIZE:
switch (((ethPluginFinalize_t*)parameter)->result) {
case ETH_PLUGIN_RESULT_OK:
case ETH_PLUGIN_RESULT_FALLBACK:
break;
default:
return 0;
}
break;
case ETH_PLUGIN_PROVIDE_TOKEN:
switch (((ethPluginProvideToken_t*)parameter)->result) {
case ETH_PLUGIN_RESULT_OK:
case ETH_PLUGIN_RESULT_FALLBACK:
break;
default:
return 0;
}
break;
case ETH_PLUGIN_QUERY_CONTRACT_ID:
if (((ethQueryContractID_t*)parameter)->result != ETH_PLUGIN_RESULT_OK) {
return 0;
}
break;
case ETH_PLUGIN_QUERY_CONTRACT_UI:
if (((ethQueryContractUI_t*)parameter)->result != ETH_PLUGIN_RESULT_OK) {
return 0;
}
break;
default:
return 0;
}
switch (method) {
case ETH_PLUGIN_INIT_CONTRACT:
switch (((ethPluginInitContract_t *) parameter)->result) {
case ETH_PLUGIN_RESULT_OK:
if (contractAddress != NULL) {
strcpy(dataContext.tokenContext.pluginName, alias);
}
break;
case ETH_PLUGIN_RESULT_OK_ALIAS:
break;
default:
return 0;
}
break;
case ETH_PLUGIN_PROVIDE_PARAMETER:
switch (((ethPluginProvideParameter_t *) parameter)->result) {
case ETH_PLUGIN_RESULT_OK:
case ETH_PLUGIN_RESULT_FALLBACK:
break;
default:
return 0;
}
break;
case ETH_PLUGIN_FINALIZE:
switch (((ethPluginFinalize_t *) parameter)->result) {
case ETH_PLUGIN_RESULT_OK:
case ETH_PLUGIN_RESULT_FALLBACK:
break;
default:
return 0;
}
break;
case ETH_PLUGIN_PROVIDE_TOKEN:
switch (((ethPluginProvideToken_t *) parameter)->result) {
case ETH_PLUGIN_RESULT_OK:
case ETH_PLUGIN_RESULT_FALLBACK:
break;
default:
return 0;
}
break;
case ETH_PLUGIN_QUERY_CONTRACT_ID:
if (((ethQueryContractID_t *) parameter)->result != ETH_PLUGIN_RESULT_OK) {
return 0;
}
break;
case ETH_PLUGIN_QUERY_CONTRACT_UI:
if (((ethQueryContractUI_t *) parameter)->result != ETH_PLUGIN_RESULT_OK) {
return 0;
}
break;
default:
return 0;
}
return 1;
return 1;
}

View File

@@ -3,11 +3,24 @@
#include "eth_plugin_interface.h"
void eth_plugin_prepare_init(ethPluginInitContract_t *init, uint8_t *selector, uint32_t dataSize);
void eth_plugin_prepare_provide_parameter(ethPluginProvideParameter_t *provideParameter, uint8_t *parameter, uint32_t parameterOffset);
void eth_plugin_prepare_provide_parameter(ethPluginProvideParameter_t *provideParameter,
uint8_t *parameter,
uint32_t parameterOffset);
void eth_plugin_prepare_finalize(ethPluginFinalize_t *finalize);
void eth_plugin_prepare_provide_token(ethPluginProvideToken_t *provideToken, tokenDefinition_t *token1, tokenDefinition_t *token2);
void eth_plugin_prepare_query_contract_ID(ethQueryContractID_t *queryContractID, char *name, uint32_t nameLength, char *version, uint32_t versionLength);
void eth_plugin_prepare_query_contract_UI(ethQueryContractUI_t *queryContractUI, uint8_t screenIndex, char *title, uint32_t titleLength, char *msg, uint32_t msgLength);
void eth_plugin_prepare_provide_token(ethPluginProvideToken_t *provideToken,
tokenDefinition_t *token1,
tokenDefinition_t *token2);
void eth_plugin_prepare_query_contract_ID(ethQueryContractID_t *queryContractID,
char *name,
uint32_t nameLength,
char *version,
uint32_t versionLength);
void eth_plugin_prepare_query_contract_UI(ethQueryContractUI_t *queryContractUI,
uint8_t screenIndex,
char *title,
uint32_t titleLength,
char *msg,
uint32_t msgLength);
int eth_plugin_perform_init(uint8_t *contractAddress, ethPluginInitContract_t *init);
// NULL for cached address, or base contract address
@@ -17,4 +30,3 @@ int compound_plugin_call(uint8_t *contractAddress, int method, void *parameter);
void plugin_ui_start(void);
#endif

View File

@@ -11,123 +11,116 @@
typedef enum {
ETH_PLUGIN_INIT_CONTRACT = 0x0101,
ETH_PLUGIN_PROVIDE_PARAMETER = 0x0102,
ETH_PLUGIN_FINALIZE = 0x0103,
ETH_PLUGIN_PROVIDE_TOKEN = 0x0104,
ETH_PLUGIN_QUERY_CONTRACT_ID = 0x0105,
ETH_PLUGIN_QUERY_CONTRACT_UI = 0x0106
ETH_PLUGIN_INIT_CONTRACT = 0x0101,
ETH_PLUGIN_PROVIDE_PARAMETER = 0x0102,
ETH_PLUGIN_FINALIZE = 0x0103,
ETH_PLUGIN_PROVIDE_TOKEN = 0x0104,
ETH_PLUGIN_QUERY_CONTRACT_ID = 0x0105,
ETH_PLUGIN_QUERY_CONTRACT_UI = 0x0106
} eth_plugin_msg_t;
typedef enum {
ETH_PLUGIN_RESULT_ERROR = 0x00,
ETH_PLUGIN_RESULT_OK = 0x01,
ETH_PLUGIN_RESULT_OK_ALIAS = 0x02,
ETH_PLUGIN_RESULT_FALLBACK = 0x03
ETH_PLUGIN_RESULT_ERROR = 0x00,
ETH_PLUGIN_RESULT_OK = 0x01,
ETH_PLUGIN_RESULT_OK_ALIAS = 0x02,
ETH_PLUGIN_RESULT_FALLBACK = 0x03
} eth_plugin_result_t;
typedef enum {
ETH_UI_TYPE_AMOUNT_ADDRESS = 0x01,
ETH_UI_TYPE_GENERIC = 0x02
ETH_UI_TYPE_AMOUNT_ADDRESS = 0x01,
ETH_UI_TYPE_GENERIC = 0x02
} eth_ui_type_t;
typedef void (*PluginCall)(int, void*);
typedef void (*PluginCall)(int, void *);
// Shared objects, read-write
typedef struct ethPluginSharedRW_t {
cx_sha3_t *sha3;
cx_sha3_t *sha3;
} ethPluginSharedRW_t;
// Shared objects, read-only
typedef struct ethPluginSharedRO_t {
txContent_t *txContent;
txContent_t *txContent;
} ethPluginSharedRO_t;
// Init Contract
typedef struct ethPluginInitContract_t {
// in
// in
ethPluginSharedRW_t *pluginSharedRW;
ethPluginSharedRO_t *pluginSharedRO;
uint8_t *pluginContext;
uint32_t pluginContextLength;
uint8_t *selector; // 4 bytes selector
uint32_t dataSize;
ethPluginSharedRW_t *pluginSharedRW;
ethPluginSharedRO_t *pluginSharedRO;
uint8_t *pluginContext;
uint32_t pluginContextLength;
uint8_t *selector; // 4 bytes selector
uint32_t dataSize;
char *alias; // 29 bytes alias if ETH_PLUGIN_RESULT_OK_ALIAS set
char *alias; // 29 bytes alias if ETH_PLUGIN_RESULT_OK_ALIAS set
uint8_t result;
uint8_t result;
} ethPluginInitContract_t;
// Provide parameter
typedef struct ethPluginProvideParameter_t {
ethPluginSharedRW_t *pluginSharedRW;
ethPluginSharedRO_t *pluginSharedRO;
uint8_t *pluginContext;
uint8_t *parameter; // 32 bytes parameter
uint32_t parameterOffset;
ethPluginSharedRW_t *pluginSharedRW;
ethPluginSharedRO_t *pluginSharedRO;
uint8_t *pluginContext;
uint8_t *parameter; // 32 bytes parameter
uint32_t parameterOffset;
uint8_t result;
uint8_t result;
} ethPluginProvideParameter_t;
// Finalize
typedef struct ethPluginFinalize_t {
ethPluginSharedRW_t *pluginSharedRW;
ethPluginSharedRO_t *pluginSharedRO;
uint8_t *pluginContext;
ethPluginSharedRW_t *pluginSharedRW;
ethPluginSharedRO_t *pluginSharedRO;
uint8_t *pluginContext;
uint8_t *tokenLookup1; // set by the plugin if a token should be looked up
uint8_t *tokenLookup2;
uint8_t *tokenLookup1; // set by the plugin if a token should be looked up
uint8_t *tokenLookup2;
uint8_t *amount; // set an uint256 pointer if uiType is UI_AMOUNT_ADDRESS
uint8_t *address; // set to a 20 bytes address pointer if uiType is UI_AMOUNT_ADDRESS
uint8_t *amount; // set an uint256 pointer if uiType is UI_AMOUNT_ADDRESS
uint8_t *address; // set to a 20 bytes address pointer if uiType is UI_AMOUNT_ADDRESS
uint8_t uiType;
uint8_t numScreens; // ignored if uiType is UI_AMOUNT_ADDRESS
uint8_t result;
uint8_t uiType;
uint8_t numScreens; // ignored if uiType is UI_AMOUNT_ADDRESS
uint8_t result;
} ethPluginFinalize_t;
// If uiType is UI_AMOUNT_ADDRESS, the amount and address provided by the plugin will be used
// If tokenLookup1 is set, the amount is provided for this token
// if uiType is UI_TYPE_GENERIC, the ETH application provides tokens if requested then prompts
// if uiType is UI_TYPE_GENERIC, the ETH application provides tokens if requested then prompts
// for each UI field
// The first field is forced by the ETH app to be the name + version of the plugin handling the request
// The last field is the fee amount
// The first field is forced by the ETH app to be the name + version of the plugin handling the
// request The last field is the fee amount
// Provide token
// Provide token
typedef struct ethPluginProvideToken_t {
ethPluginSharedRW_t *pluginSharedRW;
ethPluginSharedRO_t *pluginSharedRO;
uint8_t *pluginContext;
ethPluginSharedRW_t *pluginSharedRW;
ethPluginSharedRO_t *pluginSharedRO;
uint8_t *pluginContext;
tokenDefinition_t *token1; // set by the ETH application, to be saved by the plugin
tokenDefinition_t *token2;
tokenDefinition_t *token1; // set by the ETH application, to be saved by the plugin
tokenDefinition_t *token2;
uint8_t result;
uint8_t result;
} ethPluginProvideToken_t;
@@ -136,36 +129,33 @@ typedef struct ethPluginProvideToken_t {
// This is always called on the non aliased contract
typedef struct ethQueryContractID_t {
ethPluginSharedRW_t *pluginSharedRW;
ethPluginSharedRO_t *pluginSharedRO;
uint8_t *pluginContext;
ethPluginSharedRW_t *pluginSharedRW;
ethPluginSharedRO_t *pluginSharedRO;
uint8_t *pluginContext;
char *name;
uint32_t nameLength;
char *version;
uint32_t versionLength;
char *name;
uint32_t nameLength;
char *version;
uint32_t versionLength;
uint8_t result;
uint8_t result;
} ethQueryContractID_t;
// Query Contract UI
typedef struct ethQueryContractUI_t {
ethPluginSharedRW_t *pluginSharedRW;
ethPluginSharedRO_t *pluginSharedRO;
uint8_t *pluginContext;
uint8_t screenIndex;
char *title;
uint32_t titleLength;
char *msg;
uint32_t msgLength;
ethPluginSharedRW_t *pluginSharedRW;
ethPluginSharedRO_t *pluginSharedRO;
uint8_t *pluginContext;
uint8_t screenIndex;
char *title;
uint32_t titleLength;
char *msg;
uint32_t msgLength;
uint8_t result;
uint8_t result;
} ethQueryContractUI_t;
#endif

View File

@@ -3,138 +3,118 @@
bool erc20_plugin_available_check(void);
bool erc721_plugin_available_check(void);
void erc20_plugin_call(int message, void *parameters);
void erc721_plugin_call(int message, void *parameters);
void compound_plugin_call(int message, void *parameters);
void erc20_plugin_call(int message, void* parameters);
void erc721_plugin_call(int message, void* parameters);
void compound_plugin_call(int message, void* parameters);
#ifdef HAVE_STARKWARE
void starkware_plugin_call(int message, void *parameters);
void starkware_plugin_call(int message, void* parameters);
#endif
#ifdef HAVE_ETH2
void eth2_plugin_call(int message, void *parameters);
void eth2_plugin_call(int message, void* parameters);
#endif
static const uint8_t const ERC20_TRANSFER_SELECTOR[SELECTOR_SIZE] = { 0xa9, 0x05, 0x9c, 0xbb };
static const uint8_t const ERC20_APPROVE_SELECTOR[SELECTOR_SIZE] = { 0x09, 0x5e, 0xa7, 0xb3 };
static const uint8_t const ERC20_TRANSFER_SELECTOR[SELECTOR_SIZE] = {0xa9, 0x05, 0x9c, 0xbb};
static const uint8_t const ERC20_APPROVE_SELECTOR[SELECTOR_SIZE] = {0x09, 0x5e, 0xa7, 0xb3};
const uint8_t* const ERC20_SELECTORS[NUM_ERC20_SELECTORS] = {
ERC20_TRANSFER_SELECTOR, ERC20_APPROVE_SELECTOR
};
const uint8_t* const ERC20_SELECTORS[NUM_ERC20_SELECTORS] = {ERC20_TRANSFER_SELECTOR,
ERC20_APPROVE_SELECTOR};
static const uint8_t const ERC721_APPROVE_SELECTOR[SELECTOR_SIZE] = {0x09, 0x5e, 0xa7, 0xb3};
static const uint8_t const ERC721_APPROVE_SELECTOR[SELECTOR_SIZE] = { 0x09, 0x5e, 0xa7, 0xb3 };
const uint8_t* const ERC721_SELECTORS[NUM_ERC721_SELECTORS] = {ERC721_APPROVE_SELECTOR};
const uint8_t* const ERC721_SELECTORS[NUM_ERC721_SELECTORS] = {
ERC721_APPROVE_SELECTOR
};
static const uint8_t const COMPOUND_REDEEM_UNDERLYING_SELECTOR[SELECTOR_SIZE] = { 0x85, 0x2a, 0x12, 0xe3 };
static const uint8_t const COMPOUND_REDEEM_SELECTOR[SELECTOR_SIZE] = { 0xdb, 0x00, 0x6a, 0x75 };
static const uint8_t const COMPOUND_MINT_SELECTOR[SELECTOR_SIZE] = { 0xa0, 0x71, 0x2d, 0x68 };
static const uint8_t const CETH_MINT_SELECTOR[SELECTOR_SIZE] = { 0x12, 0x49, 0xc5, 0x8b };
static const uint8_t const COMPOUND_REDEEM_UNDERLYING_SELECTOR[SELECTOR_SIZE] = {0x85,
0x2a,
0x12,
0xe3};
static const uint8_t const COMPOUND_REDEEM_SELECTOR[SELECTOR_SIZE] = {0xdb, 0x00, 0x6a, 0x75};
static const uint8_t const COMPOUND_MINT_SELECTOR[SELECTOR_SIZE] = {0xa0, 0x71, 0x2d, 0x68};
static const uint8_t const CETH_MINT_SELECTOR[SELECTOR_SIZE] = {0x12, 0x49, 0xc5, 0x8b};
const uint8_t* const COMPOUND_SELECTORS[NUM_COMPOUND_SELECTORS] = {
COMPOUND_REDEEM_UNDERLYING_SELECTOR, COMPOUND_REDEEM_SELECTOR,
COMPOUND_MINT_SELECTOR, CETH_MINT_SELECTOR
};
COMPOUND_REDEEM_UNDERLYING_SELECTOR,
COMPOUND_REDEEM_SELECTOR,
COMPOUND_MINT_SELECTOR,
CETH_MINT_SELECTOR};
#ifdef HAVE_ETH2
static const uint8_t const ETH2_DEPOSIT_SELECTOR[SELECTOR_SIZE] = { 0x22, 0x89, 0x51, 0x18 };
static const uint8_t const ETH2_DEPOSIT_SELECTOR[SELECTOR_SIZE] = {0x22, 0x89, 0x51, 0x18};
const uint8_t* const ETH2_SELECTORS[NUM_ETH2_SELECTORS] = {
ETH2_DEPOSIT_SELECTOR
};
const uint8_t* const ETH2_SELECTORS[NUM_ETH2_SELECTORS] = {ETH2_DEPOSIT_SELECTOR};
#endif
#ifdef HAVE_STARKWARE
static const uint8_t const STARKWARE_REGISTER_ID[SELECTOR_SIZE] = { 0xdd, 0x24, 0x14, 0xd4 };
static const uint8_t const STARKWARE_DEPOSIT_TOKEN_ID[SELECTOR_SIZE] = { 0x25, 0x05, 0xc3, 0xd9 };
static const uint8_t const STARKWARE_DEPOSIT_ETH_ID[SELECTOR_SIZE] = { 0x00, 0xae, 0xef, 0x8a };
static const uint8_t const STARKWARE_DEPOSIT_CANCEL_ID[SELECTOR_SIZE] = { 0x7d, 0xf7, 0xdc, 0x04 };
static const uint8_t const STARKWARE_DEPOSIT_RECLAIM_ID[SELECTOR_SIZE] = { 0xae, 0x87, 0x38, 0x16 };
static const uint8_t const STARKWARE_WITHDRAW_ID[SELECTOR_SIZE] = { 0x44, 0x1a, 0x3e, 0x70 };
static const uint8_t const STARKWARE_FULL_WITHDRAWAL_ID[SELECTOR_SIZE] = { 0xa9, 0x33, 0x10, 0xc4 };
static const uint8_t const STARKWARE_FREEZE_ID[SELECTOR_SIZE] = { 0x93, 0xc1, 0xe4, 0x66 };
static const uint8_t const STARKWARE_ESCAPE_ID[SELECTOR_SIZE] = { 0x9e, 0x3a, 0xda, 0xc4 };
static const uint8_t const STARKWARE_VERIFY_ESCAPE_ID[SELECTOR_SIZE] = { 0x2d, 0xd5, 0x30, 0x06 };
static const uint8_t const STARKWARE_WITHDRAW_TO_ID[SELECTOR_SIZE] = { 0x14, 0xcd, 0x70, 0xe4 };
static const uint8_t const STARKWARE_DEPOSIT_NFT_ID[SELECTOR_SIZE] = { 0xae, 0x1c, 0xdd, 0xe6 };
static const uint8_t const STARKWARE_DEPOSIT_NFT_RECLAIM_ID[SELECTOR_SIZE] = { 0xfc, 0xb0, 0x58, 0x22 };
static const uint8_t const STARKWARE_WITHDRAW_AND_MINT_ID[SELECTOR_SIZE] = { 0xd9, 0x14, 0x43, 0xb7 };
static const uint8_t const STARKWARE_WITHDRAW_NFT_ID[SELECTOR_SIZE] = { 0x01, 0x9b, 0x41, 0x7a };
static const uint8_t const STARKWARE_WITHDRAW_NFT_TO_ID[SELECTOR_SIZE] = { 0xeb, 0xef, 0x0f, 0xd0 };
static const uint8_t const STARKWARE_REGISTER_ID[SELECTOR_SIZE] = {0xdd, 0x24, 0x14, 0xd4};
static const uint8_t const STARKWARE_DEPOSIT_TOKEN_ID[SELECTOR_SIZE] = {0x25, 0x05, 0xc3, 0xd9};
static const uint8_t const STARKWARE_DEPOSIT_ETH_ID[SELECTOR_SIZE] = {0x00, 0xae, 0xef, 0x8a};
static const uint8_t const STARKWARE_DEPOSIT_CANCEL_ID[SELECTOR_SIZE] = {0x7d, 0xf7, 0xdc, 0x04};
static const uint8_t const STARKWARE_DEPOSIT_RECLAIM_ID[SELECTOR_SIZE] = {0xae, 0x87, 0x38, 0x16};
static const uint8_t const STARKWARE_WITHDRAW_ID[SELECTOR_SIZE] = {0x44, 0x1a, 0x3e, 0x70};
static const uint8_t const STARKWARE_FULL_WITHDRAWAL_ID[SELECTOR_SIZE] = {0xa9, 0x33, 0x10, 0xc4};
static const uint8_t const STARKWARE_FREEZE_ID[SELECTOR_SIZE] = {0x93, 0xc1, 0xe4, 0x66};
static const uint8_t const STARKWARE_ESCAPE_ID[SELECTOR_SIZE] = {0x9e, 0x3a, 0xda, 0xc4};
static const uint8_t const STARKWARE_VERIFY_ESCAPE_ID[SELECTOR_SIZE] = {0x2d, 0xd5, 0x30, 0x06};
static const uint8_t const STARKWARE_WITHDRAW_TO_ID[SELECTOR_SIZE] = {0x14, 0xcd, 0x70, 0xe4};
static const uint8_t const STARKWARE_DEPOSIT_NFT_ID[SELECTOR_SIZE] = {0xae, 0x1c, 0xdd, 0xe6};
static const uint8_t const STARKWARE_DEPOSIT_NFT_RECLAIM_ID[SELECTOR_SIZE] = {0xfc,
0xb0,
0x58,
0x22};
static const uint8_t const STARKWARE_WITHDRAW_AND_MINT_ID[SELECTOR_SIZE] = {0xd9, 0x14, 0x43, 0xb7};
static const uint8_t const STARKWARE_WITHDRAW_NFT_ID[SELECTOR_SIZE] = {0x01, 0x9b, 0x41, 0x7a};
static const uint8_t const STARKWARE_WITHDRAW_NFT_TO_ID[SELECTOR_SIZE] = {0xeb, 0xef, 0x0f, 0xd0};
const uint8_t* const STARKWARE_SELECTORS[NUM_STARKWARE_SELECTORS] = {
STARKWARE_REGISTER_ID, STARKWARE_DEPOSIT_TOKEN_ID, STARKWARE_DEPOSIT_ETH_ID,
STARKWARE_DEPOSIT_CANCEL_ID, STARKWARE_DEPOSIT_RECLAIM_ID, STARKWARE_WITHDRAW_ID,
STARKWARE_FULL_WITHDRAWAL_ID, STARKWARE_FREEZE_ID, STARKWARE_ESCAPE_ID,
STARKWARE_VERIFY_ESCAPE_ID, STARKWARE_WITHDRAW_TO_ID, STARKWARE_DEPOSIT_NFT_ID,
STARKWARE_DEPOSIT_NFT_RECLAIM_ID, STARKWARE_WITHDRAW_AND_MINT_ID, STARKWARE_WITHDRAW_NFT_ID,
STARKWARE_WITHDRAW_NFT_TO_ID
};
STARKWARE_REGISTER_ID,
STARKWARE_DEPOSIT_TOKEN_ID,
STARKWARE_DEPOSIT_ETH_ID,
STARKWARE_DEPOSIT_CANCEL_ID,
STARKWARE_DEPOSIT_RECLAIM_ID,
STARKWARE_WITHDRAW_ID,
STARKWARE_FULL_WITHDRAWAL_ID,
STARKWARE_FREEZE_ID,
STARKWARE_ESCAPE_ID,
STARKWARE_VERIFY_ESCAPE_ID,
STARKWARE_WITHDRAW_TO_ID,
STARKWARE_DEPOSIT_NFT_ID,
STARKWARE_DEPOSIT_NFT_RECLAIM_ID,
STARKWARE_WITHDRAW_AND_MINT_ID,
STARKWARE_WITHDRAW_NFT_ID,
STARKWARE_WITHDRAW_NFT_TO_ID};
#endif
// All internal alias names start with 'minus'
const internalEthPlugin_t const INTERNAL_ETH_PLUGINS[] = {
{
erc20_plugin_available_check,
ERC20_SELECTORS,
NUM_ERC20_SELECTORS,
"-erc20",
erc20_plugin_call
},
const internalEthPlugin_t const INTERNAL_ETH_PLUGINS[] = {
{erc20_plugin_available_check,
ERC20_SELECTORS,
NUM_ERC20_SELECTORS,
"-erc20",
erc20_plugin_call},
{
erc721_plugin_available_check,
ERC721_SELECTORS,
NUM_ERC721_SELECTORS,
"-er721",
erc721_plugin_call
},
{erc721_plugin_available_check,
ERC721_SELECTORS,
NUM_ERC721_SELECTORS,
"-er721",
erc721_plugin_call},
{
NULL,
COMPOUND_SELECTORS,
NUM_COMPOUND_SELECTORS,
"-cmpd",
compound_plugin_call
},
{NULL, COMPOUND_SELECTORS, NUM_COMPOUND_SELECTORS, "-cmpd", compound_plugin_call},
#ifdef HAVE_ETH2
{
NULL,
ETH2_SELECTORS,
NUM_ETH2_SELECTORS,
"-eth2",
eth2_plugin_call
},
{NULL, ETH2_SELECTORS, NUM_ETH2_SELECTORS, "-eth2", eth2_plugin_call},
#endif
#endif
#ifdef HAVE_STARKWARE
{
NULL,
STARKWARE_SELECTORS,
10,
"-strk",
starkware_plugin_call
},
{NULL, STARKWARE_SELECTORS, 10, "-strk", starkware_plugin_call},
#endif
#endif
{
NULL,
NULL,
0,
"",
NULL
}
};
{NULL, NULL, 0, "", NULL}};

View File

@@ -7,11 +7,11 @@
typedef bool (*PluginAvailableCheck)(void);
typedef struct internalEthPlugin_t {
PluginAvailableCheck availableCheck;
const uint8_t **selectors;
uint8_t num_selectors;
char alias[7];
PluginCall impl;
PluginAvailableCheck availableCheck;
const uint8_t** selectors;
uint8_t num_selectors;
char alias[7];
PluginCall impl;
} internalEthPlugin_t;
#define NUM_ERC20_SELECTORS 2

View File

@@ -7,86 +7,94 @@
typedef enum {
PLUGIN_UI_INSIDE = 0,
PLUGIN_UI_OUTSIDE
PLUGIN_UI_INSIDE = 0,
PLUGIN_UI_OUTSIDE
} plugin_ui_state_t;
void computeFees(char *displayBuffer, uint32_t displayBufferSize);
void plugin_ui_get_id() {
ethQueryContractID_t pluginQueryContractID;
eth_plugin_prepare_query_contract_ID(&pluginQueryContractID, strings.tmp.tmp, sizeof(strings.tmp.tmp), strings.tmp.tmp2, sizeof(strings.tmp.tmp2));
// Query the original contract for ID if it's not an internal alias
if (!eth_plugin_call(
(dataContext.tokenContext.pluginName[0] == '-' ? NULL : tmpContent.txContent.destination),
ETH_PLUGIN_QUERY_CONTRACT_ID, (void*)&pluginQueryContractID)) {
PRINTF("Plugin query contract ID call failed\n");
io_seproxyhal_touch_tx_cancel(NULL);
}
ethQueryContractID_t pluginQueryContractID;
eth_plugin_prepare_query_contract_ID(&pluginQueryContractID,
strings.tmp.tmp,
sizeof(strings.tmp.tmp),
strings.tmp.tmp2,
sizeof(strings.tmp.tmp2));
// Query the original contract for ID if it's not an internal alias
if (!eth_plugin_call(
(dataContext.tokenContext.pluginName[0] == '-' ? NULL
: tmpContent.txContent.destination),
ETH_PLUGIN_QUERY_CONTRACT_ID,
(void *) &pluginQueryContractID)) {
PRINTF("Plugin query contract ID call failed\n");
io_seproxyhal_touch_tx_cancel(NULL);
}
}
void plugin_ui_get_item() {
ethQueryContractUI_t pluginQueryContractUI;
eth_plugin_prepare_query_contract_UI(&pluginQueryContractUI, dataContext.tokenContext.pluginUiCurrentItem, strings.tmp.tmp, sizeof(strings.tmp.tmp), strings.tmp.tmp2, sizeof(strings.tmp.tmp2));
if (!eth_plugin_call(NULL, ETH_PLUGIN_QUERY_CONTRACT_UI, (void*)&pluginQueryContractUI)) {
PRINTF("Plugin query contract UI call failed\n");
io_seproxyhal_touch_tx_cancel(NULL);
}
ethQueryContractUI_t pluginQueryContractUI;
eth_plugin_prepare_query_contract_UI(&pluginQueryContractUI,
dataContext.tokenContext.pluginUiCurrentItem,
strings.tmp.tmp,
sizeof(strings.tmp.tmp),
strings.tmp.tmp2,
sizeof(strings.tmp.tmp2));
if (!eth_plugin_call(NULL, ETH_PLUGIN_QUERY_CONTRACT_UI, (void *) &pluginQueryContractUI)) {
PRINTF("Plugin query contract UI call failed\n");
io_seproxyhal_touch_tx_cancel(NULL);
}
}
void display_next_plugin_item(bool entering) {
if (entering) {
if (dataContext.tokenContext.pluginUiState == PLUGIN_UI_OUTSIDE) {
dataContext.tokenContext.pluginUiState = PLUGIN_UI_INSIDE;
dataContext.tokenContext.pluginUiCurrentItem = 0;
plugin_ui_get_item();
ux_flow_next();
if (entering) {
if (dataContext.tokenContext.pluginUiState == PLUGIN_UI_OUTSIDE) {
dataContext.tokenContext.pluginUiState = PLUGIN_UI_INSIDE;
dataContext.tokenContext.pluginUiCurrentItem = 0;
plugin_ui_get_item();
ux_flow_next();
} else {
if (dataContext.tokenContext.pluginUiCurrentItem > 0) {
dataContext.tokenContext.pluginUiCurrentItem--;
plugin_ui_get_item();
ux_flow_next();
} else {
dataContext.tokenContext.pluginUiState = PLUGIN_UI_OUTSIDE;
dataContext.tokenContext.pluginUiCurrentItem = 0;
ux_flow_prev();
}
}
} else {
if (dataContext.tokenContext.pluginUiState == PLUGIN_UI_OUTSIDE) {
dataContext.tokenContext.pluginUiState = PLUGIN_UI_INSIDE;
plugin_ui_get_item();
ux_flow_prev();
} else {
if (dataContext.tokenContext.pluginUiCurrentItem <
dataContext.tokenContext.pluginUiMaxItems - 1) {
dataContext.tokenContext.pluginUiCurrentItem++;
plugin_ui_get_item();
ux_flow_prev();
// Reset multi page layout to the first page
G_ux.layout_paging.current = 0;
#ifdef TARGET_NANOS
ux_layout_paging_redisplay(G_ux.stack_count - 1);
#else
ux_layout_bnnn_paging_redisplay(0);
#endif
} else {
dataContext.tokenContext.pluginUiState = PLUGIN_UI_OUTSIDE;
ux_flow_next();
}
}
}
else {
if (dataContext.tokenContext.pluginUiCurrentItem > 0) {
dataContext.tokenContext.pluginUiCurrentItem--;
plugin_ui_get_item();
ux_flow_next();
}
else {
dataContext.tokenContext.pluginUiState = PLUGIN_UI_OUTSIDE;
dataContext.tokenContext.pluginUiCurrentItem = 0;
ux_flow_prev();
}
}
}
else {
if (dataContext.tokenContext.pluginUiState == PLUGIN_UI_OUTSIDE) {
dataContext.tokenContext.pluginUiState = PLUGIN_UI_INSIDE;
plugin_ui_get_item();
ux_flow_prev();
}
else {
if (dataContext.tokenContext.pluginUiCurrentItem < dataContext.tokenContext.pluginUiMaxItems - 1) {
dataContext.tokenContext.pluginUiCurrentItem++;
plugin_ui_get_item();
ux_flow_prev();
// Reset multi page layout to the first page
G_ux.layout_paging.current = 0;
#ifdef TARGET_NANOS
ux_layout_paging_redisplay(G_ux.stack_count-1);
#else
ux_layout_bnnn_paging_redisplay(0);
#endif
}
else {
dataContext.tokenContext.pluginUiState = PLUGIN_UI_OUTSIDE;
ux_flow_next();
}
}
}
}
void plugin_ui_compute_fees() {
computeFees(strings.common.maxFee, sizeof(strings.common.maxFee));
computeFees(strings.common.maxFee, sizeof(strings.common.maxFee));
}
// clang-format off
UX_FLOW_DEF_NOCB(
ux_plugin_approval_intro_step,
pnn,
@@ -155,21 +163,20 @@ UX_FLOW_DEF_VALID(
&C_icon_crossmark,
"Reject",
});
// clang-format on
UX_FLOW(
ux_plugin_approval_flow,
&ux_plugin_approval_intro_step,
&ux_plugin_approval_id_step,
&ux_plugin_approval_before_step,
&ux_plugin_approval_display_step,
&ux_plugin_approval_after_step,
&ux_plugin_approval_fees_step,
&ux_plugin_approval_ok_step,
&ux_plugin_approval_cancel_step
);
UX_FLOW(ux_plugin_approval_flow,
&ux_plugin_approval_intro_step,
&ux_plugin_approval_id_step,
&ux_plugin_approval_before_step,
&ux_plugin_approval_display_step,
&ux_plugin_approval_after_step,
&ux_plugin_approval_fees_step,
&ux_plugin_approval_ok_step,
&ux_plugin_approval_cancel_step);
void plugin_ui_start() {
dataContext.tokenContext.pluginUiState = PLUGIN_UI_OUTSIDE;
dataContext.tokenContext.pluginUiCurrentItem = 0;
ux_flow_init(0, ux_plugin_approval_flow, NULL);
dataContext.tokenContext.pluginUiState = PLUGIN_UI_OUTSIDE;
dataContext.tokenContext.pluginUiCurrentItem = 0;
ux_flow_init(0, ux_plugin_approval_flow, NULL);
}

View File

@@ -7,8 +7,8 @@
#define ZERO(x) memset(x, 0, sizeof(x))
void handle_check_address(check_address_parameters_t* params, chain_config_t* chain_config) {
PRINTF("Params on the address %d\n",(unsigned int)params);
PRINTF("Address to check %s\n",params->address_to_check);
PRINTF("Params on the address %d\n", (unsigned int) params);
PRINTF("Address to check %s\n", params->address_to_check);
PRINTF("Inside handle_check_address\n");
params->result = 0;
if (params->address_to_check == 0) {
@@ -17,27 +17,23 @@ void handle_check_address(check_address_parameters_t* params, chain_config_t* ch
}
uint8_t i;
uint8_t *bip32_path_ptr = params->address_parameters;
uint8_t* bip32_path_ptr = params->address_parameters;
uint8_t bip32PathLength = *(bip32_path_ptr++);
cx_sha3_t local_sha3;
// Common memory is used for locals that are not used concurrently
union group1
{
union group1 {
uint32_t bip32Path[MAX_BIP32_PATH];
cx_ecfp_private_key_t privateKey;
char address[51];
} locals_union1;
union group2
{
union group2 {
uint8_t privateKeyData[32];
cx_ecfp_public_key_t publicKey;
} locals_union2;
if ((bip32PathLength < 0x01) ||
(bip32PathLength > MAX_BIP32_PATH) ||
(bip32PathLength*4 != params->address_parameters_length - 1)) {
if ((bip32PathLength < 0x01) || (bip32PathLength > MAX_BIP32_PATH) ||
(bip32PathLength * 4 != params->address_parameters_length - 1)) {
PRINTF("Invalid path\n");
return;
}
@@ -45,22 +41,34 @@ void handle_check_address(check_address_parameters_t* params, chain_config_t* ch
locals_union1.bip32Path[i] = U4BE(bip32_path_ptr, 0);
bip32_path_ptr += 4;
}
os_perso_derive_node_bip32(CX_CURVE_256K1, locals_union1.bip32Path, bip32PathLength, locals_union2.privateKeyData, NULL);
os_perso_derive_node_bip32(CX_CURVE_256K1,
locals_union1.bip32Path,
bip32PathLength,
locals_union2.privateKeyData,
NULL);
ZERO(&locals_union1);
cx_ecfp_init_private_key(CX_CURVE_256K1, locals_union2.privateKeyData, 32, &locals_union1.privateKey);
cx_ecfp_init_private_key(CX_CURVE_256K1,
locals_union2.privateKeyData,
32,
&locals_union1.privateKey);
ZERO(&locals_union2);
cx_ecfp_generate_pair(CX_CURVE_256K1, &locals_union2.publicKey, &locals_union1.privateKey, 1);
ZERO(&locals_union1);
getEthAddressStringFromKey(&locals_union2.publicKey, (uint8_t*)locals_union1.address, &local_sha3, chain_config);
getEthAddressStringFromKey(&locals_union2.publicKey,
(uint8_t*) locals_union1.address,
&local_sha3,
chain_config);
ZERO(&locals_union2);
uint8_t offset_0x = 0;
if(memcmp(params->address_to_check, "0x", 2) == 0){
if (memcmp(params->address_to_check, "0x", 2) == 0) {
offset_0x = 2;
}
if ((strlen(locals_union1.address) != strlen(params->address_to_check + offset_0x)) ||
memcmp(locals_union1.address, params->address_to_check + offset_0x, strlen(locals_union1.address)) != 0) {
memcmp(locals_union1.address,
params->address_to_check + offset_0x,
strlen(locals_union1.address)) != 0) {
PRINTF("Addresses doesn't match\n");
return;
}

View File

@@ -4,6 +4,7 @@
#include "swap_lib_calls.h"
#include "chainConfig.h"
void handle_check_address(check_address_parameters_t* check_address_params, chain_config_t* chain_config);
void handle_check_address(check_address_parameters_t* check_address_params,
chain_config_t* chain_config);
#endif // _HANDLE_CHECK_ADDRESS_H_
#endif // _HANDLE_CHECK_ADDRESS_H_

View File

@@ -6,8 +6,8 @@
#include "string.h"
#include <stdint.h>
void handle_get_printable_amount( get_printable_amount_parameters_t* params, chain_config_t *config) {
void handle_get_printable_amount(get_printable_amount_parameters_t* params,
chain_config_t* config) {
uint8_t decimals;
char ticker[MAX_TICKER_LEN];
memset(params->printable_amount, 0, sizeof(params->printable_amount));
@@ -15,19 +15,27 @@ void handle_get_printable_amount( get_printable_amount_parameters_t* params, cha
PRINTF("Amount is too big, 32 bytes max but buffer has %u bytes", params->amount_length);
os_lib_end();
}
if(!parse_swap_config(params->coin_configuration, params->coin_configuration_length, ticker, &decimals)){
if (!parse_swap_config(params->coin_configuration,
params->coin_configuration_length,
ticker,
&decimals)) {
PRINTF("Error while parsing config\n");
os_lib_end();
}
// If the amount is a fee, its value is nominated in ETH even if we're doing an ERC20 swap
if(params->is_fee){
if (params->is_fee) {
uint8_t ticker_len = strnlen(config->coinName, sizeof(config->coinName));
memcpy(ticker, config->coinName, ticker_len);
ticker[ticker_len] = ' ';
ticker[ticker_len+1] = '\0';
ticker[ticker_len + 1] = '\0';
decimals = WEI_TO_ETHER;
}
amountToString(params->amount, params->amount_length, decimals, ticker, params->printable_amount, sizeof(params->printable_amount));
amountToString(params->amount,
params->amount_length,
decimals,
ticker,
params->printable_amount,
sizeof(params->printable_amount));
}

View File

@@ -4,6 +4,7 @@
#include "swap_lib_calls.h"
#include "chainConfig.h"
void handle_get_printable_amount(get_printable_amount_parameters_t* get_printable_amount_params, chain_config_t *config);
void handle_get_printable_amount(get_printable_amount_parameters_t* get_printable_amount_params,
chain_config_t* config);
#endif // _HANDLE_GET_PRINTABLE_AMOUNT_H_
#endif // _HANDLE_GET_PRINTABLE_AMOUNT_H_

View File

@@ -4,13 +4,15 @@
#include "shared_context.h"
#include "utils.h"
void copy_transaction_parameters(create_transaction_parameters_t* sign_transaction_params, chain_config_t *config) {
void copy_transaction_parameters(create_transaction_parameters_t* sign_transaction_params,
chain_config_t* config) {
// first copy parameters to stack, and then to global data.
// We need this "trick" as the input data position can overlap with app-ethereum globals
txStringProperties_t stack_data;
memset(&stack_data, 0, sizeof(stack_data));
strncpy(stack_data.fullAddress, sign_transaction_params->destination_address, sizeof(stack_data.fullAddress));
strncpy(stack_data.fullAddress,
sign_transaction_params->destination_address,
sizeof(stack_data.fullAddress));
if ((stack_data.fullAddress[sizeof(stack_data.fullAddress) - 1] != '\0') ||
(sign_transaction_params->amount_length > 32) ||
(sign_transaction_params->fee_amount_length > 8)) {
@@ -19,21 +21,35 @@ void copy_transaction_parameters(create_transaction_parameters_t* sign_transacti
uint8_t decimals;
char ticker[MAX_TICKER_LEN];
if(!parse_swap_config(sign_transaction_params->coin_configuration, sign_transaction_params->coin_configuration_length, ticker, &decimals)){
if (!parse_swap_config(sign_transaction_params->coin_configuration,
sign_transaction_params->coin_configuration_length,
ticker,
&decimals)) {
PRINTF("Error while parsing config\n");
os_lib_end();
}
amountToString(sign_transaction_params->amount, sign_transaction_params->amount_length, decimals, ticker, stack_data.fullAmount, sizeof(stack_data.fullAmount));
amountToString(sign_transaction_params->amount,
sign_transaction_params->amount_length,
decimals,
ticker,
stack_data.fullAmount,
sizeof(stack_data.fullAmount));
// If the amount is a fee, its value is nominated in ETH even if we're doing an ERC20 swap
strcpy(ticker, config->coinName);
decimals = WEI_TO_ETHER;
amountToString(sign_transaction_params->fee_amount, sign_transaction_params->fee_amount_length, decimals, ticker, stack_data.maxFee, sizeof(stack_data.maxFee));
amountToString(sign_transaction_params->fee_amount,
sign_transaction_params->fee_amount_length,
decimals,
ticker,
stack_data.maxFee,
sizeof(stack_data.maxFee));
memcpy(&strings.common, &stack_data, sizeof(stack_data));
}
void handle_swap_sign_transaction(create_transaction_parameters_t* sign_transaction_params, chain_config_t *config) {
void handle_swap_sign_transaction(create_transaction_parameters_t* sign_transaction_params,
chain_config_t* config) {
copy_transaction_parameters(sign_transaction_params, config);
chainConfig = config;
reset_app_context();
@@ -41,25 +57,25 @@ void handle_swap_sign_transaction(create_transaction_parameters_t* sign_transact
io_seproxyhal_init();
if (N_storage.initialized != 0x01) {
internalStorage_t storage;
storage.dataAllowed = 0x00;
storage.contractDetails = 0x00;
storage.initialized = 0x01;
nvm_write((void*)&N_storage, (void*)&storage, sizeof(internalStorage_t));
internalStorage_t storage;
storage.dataAllowed = 0x00;
storage.contractDetails = 0x00;
storage.initialized = 0x01;
nvm_write((void*) &N_storage, (void*) &storage, sizeof(internalStorage_t));
}
UX_INIT();
USB_power(0);
USB_power(1);
//ui_idle();
// ui_idle();
PRINTF("USB power ON/OFF\n");
#ifdef TARGET_NANOX
// grab the current plane mode setting
G_io_app.plane_mode = os_setting_get(OS_SETTING_PLANEMODE, NULL, 0);
#endif // TARGET_NANOX
#endif // TARGET_NANOX
#ifdef HAVE_BLE
BLE_power(0, NULL);
BLE_power(1, "Nano X");
#endif // HAVE_BLE
#endif // HAVE_BLE
app_main();
}

View File

@@ -4,6 +4,7 @@
#include "swap_lib_calls.h"
#include "chainConfig.h"
void handle_swap_sign_transaction(create_transaction_parameters_t* get_printable_amount_params, chain_config_t *config);
void handle_swap_sign_transaction(create_transaction_parameters_t* get_printable_amount_params,
chain_config_t* config);
#endif // _HANDLE_SWAP_SIGN_TRANSACTION_H_
#endif // _HANDLE_SWAP_SIGN_TRANSACTION_H_

View File

@@ -1,19 +1,19 @@
/*******************************************************************************
* Ledger Ethereum App
* (c) 2016-2019 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.
********************************************************************************/
* Ledger Ethereum App
* (c) 2016-2019 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 "shared_context.h"
#include "apdu_constants.h"
@@ -67,23 +67,23 @@ const internalStorage_t N_storage_real;
chain_config_t *chainConfig;
void reset_app_context() {
//PRINTF("!!RESET_APP_CONTEXT\n");
appState = APP_STATE_IDLE;
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_TOKEN);
called_from_swap = false;
// PRINTF("!!RESET_APP_CONTEXT\n");
appState = APP_STATE_IDLE;
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_TOKEN);
called_from_swap = false;
#ifdef HAVE_STARKWARE
quantumSet = false;
quantumSet = false;
#endif
#ifdef HAVE_ETH2
eth2WithdrawalIndex = 0;
eth2WithdrawalIndex = 0;
#endif
memset((uint8_t*)&txContext, 0, sizeof(txContext));
memset((uint8_t*)&tmpContent, 0, sizeof(tmpContent));
memset((uint8_t *) &txContext, 0, sizeof(txContext));
memset((uint8_t *) &tmpContent, 0, sizeof(tmpContent));
}
void ui_idle(void) {
// reserve a display stack slot if none yet
if(G_ux.stack_count == 0) {
if (G_ux.stack_count == 0) {
ux_stack_push();
}
ux_flow_init(0, ux_idle_flow, NULL);
@@ -92,24 +92,24 @@ void ui_idle(void) {
unsigned int io_seproxyhal_touch_exit(const bagl_element_t *e) {
// Go back to the dashboard
os_sched_exit(0);
return 0; // do not redraw the widget
return 0; // do not redraw the widget
}
#if defined(TARGET_NANOS)
unsigned int ui_address_nanos_button(unsigned int button_mask, unsigned int button_mask_counter) {
switch(button_mask) {
case BUTTON_EVT_RELEASED|BUTTON_LEFT: // CANCEL
io_seproxyhal_touch_address_cancel(NULL);
switch (button_mask) {
case BUTTON_EVT_RELEASED | BUTTON_LEFT: // CANCEL
io_seproxyhal_touch_address_cancel(NULL);
break;
case BUTTON_EVT_RELEASED|BUTTON_RIGHT: { // OK
io_seproxyhal_touch_address_ok(NULL);
break;
case BUTTON_EVT_RELEASED | BUTTON_RIGHT: { // OK
io_seproxyhal_touch_address_ok(NULL);
break;
}
}
return 0;
}
#endif // #if defined(TARGET_NANOS)
#endif // #if defined(TARGET_NANOS)
void io_seproxyhal_send_status(uint32_t sw) {
G_io_apdu_buffer[0] = ((sw >> 8) & 0xff);
@@ -117,60 +117,59 @@ void io_seproxyhal_send_status(uint32_t sw) {
io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2);
}
void format_signature_out(const uint8_t* signature) {
memset(G_io_apdu_buffer + 1, 0x00, 64);
uint8_t offset = 1;
uint8_t xoffset = 4; //point to r value
//copy r
uint8_t xlength = signature[xoffset-1];
if (xlength == 33) {
xlength = 32;
xoffset ++;
}
memmove(G_io_apdu_buffer+offset+32-xlength, signature+xoffset, xlength);
offset += 32;
xoffset += xlength +2; //move over rvalue and TagLEn
//copy s value
xlength = signature[xoffset-1];
if (xlength == 33) {
xlength = 32;
xoffset ++;
}
memmove(G_io_apdu_buffer+offset+32-xlength, signature+xoffset, xlength);
void format_signature_out(const uint8_t *signature) {
memset(G_io_apdu_buffer + 1, 0x00, 64);
uint8_t offset = 1;
uint8_t xoffset = 4; // point to r value
// copy r
uint8_t xlength = signature[xoffset - 1];
if (xlength == 33) {
xlength = 32;
xoffset++;
}
memmove(G_io_apdu_buffer + offset + 32 - xlength, signature + xoffset, xlength);
offset += 32;
xoffset += xlength + 2; // move over rvalue and TagLEn
// copy s value
xlength = signature[xoffset - 1];
if (xlength == 33) {
xlength = 32;
xoffset++;
}
memmove(G_io_apdu_buffer + offset + 32 - xlength, signature + xoffset, xlength);
}
unsigned short io_exchange_al(unsigned char channel, unsigned short tx_len) {
switch (channel & ~(IO_FLAGS)) {
case CHANNEL_KEYBOARD:
break;
case CHANNEL_KEYBOARD:
break;
// multiplexed io exchange over a SPI channel and TLV encapsulated protocol
case CHANNEL_SPI:
if (tx_len) {
io_seproxyhal_spi_send(G_io_apdu_buffer, tx_len);
// multiplexed io exchange over a SPI channel and TLV encapsulated protocol
case CHANNEL_SPI:
if (tx_len) {
io_seproxyhal_spi_send(G_io_apdu_buffer, tx_len);
if (channel & IO_RESET_AFTER_REPLIED) {
reset();
if (channel & IO_RESET_AFTER_REPLIED) {
reset();
}
return 0; // nothing received from the master so far (it's a tx
// transaction)
} else {
return io_seproxyhal_spi_recv(G_io_apdu_buffer, sizeof(G_io_apdu_buffer), 0);
}
return 0; // nothing received from the master so far (it's a tx
// transaction)
} else {
return io_seproxyhal_spi_recv(G_io_apdu_buffer,
sizeof(G_io_apdu_buffer), 0);
}
default:
THROW(INVALID_PARAMETER);
default:
THROW(INVALID_PARAMETER);
}
return 0;
}
tokenDefinition_t* getKnownToken(uint8_t *contractAddress) {
tokenDefinition_t *getKnownToken(uint8_t *contractAddress) {
tokenDefinition_t *currentToken = NULL;
#ifdef HAVE_TOKENS_LIST
uint32_t numTokens = 0;
uint32_t i;
switch(chainConfig->kind) {
switch (chainConfig->kind) {
case CHAIN_KIND_AKROMA:
numTokens = NUM_TOKENS_AKROMA;
break;
@@ -262,97 +261,97 @@ tokenDefinition_t* getKnownToken(uint8_t *contractAddress) {
numTokens = NUM_TOKENS_THUNDERCORE;
break;
}
for (i=0; i<numTokens; i++) {
switch(chainConfig->kind) {
for (i = 0; i < numTokens; i++) {
switch (chainConfig->kind) {
case CHAIN_KIND_AKROMA:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_AKROMA[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_AKROMA[i]);
break;
case CHAIN_KIND_ETHEREUM:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_ETHEREUM[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_ETHEREUM[i]);
break;
case CHAIN_KIND_ETHEREUM_CLASSIC:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_ETHEREUM_CLASSIC[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_ETHEREUM_CLASSIC[i]);
break;
case CHAIN_KIND_PIRL:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_PIRL[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_PIRL[i]);
break;
case CHAIN_KIND_POA:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_POA[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_POA[i]);
break;
case CHAIN_KIND_ARTIS_SIGMA1:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_ARTIS_SIGMA1[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_ARTIS_SIGMA1[i]);
break;
case CHAIN_KIND_ARTIS_TAU1:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_ARTIS_TAU1[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_ARTIS_TAU1[i]);
break;
case CHAIN_KIND_RSK:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_RSK[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_RSK[i]);
break;
case CHAIN_KIND_EXPANSE:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_EXPANSE[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_EXPANSE[i]);
break;
case CHAIN_KIND_UBIQ:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_UBIQ[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_UBIQ[i]);
break;
case CHAIN_KIND_WANCHAIN:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_WANCHAIN[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_WANCHAIN[i]);
break;
case CHAIN_KIND_KUSD:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_KUSD[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_KUSD[i]);
break;
case CHAIN_KIND_MUSICOIN:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_MUSICOIN[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_MUSICOIN[i]);
break;
case CHAIN_KIND_CALLISTO:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_CALLISTO[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_CALLISTO[i]);
break;
case CHAIN_KIND_ETHERSOCIAL:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_ETHERSOCIAL[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_ETHERSOCIAL[i]);
break;
case CHAIN_KIND_ELLAISM:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_ELLAISM[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_ELLAISM[i]);
break;
case CHAIN_KIND_ETHER1:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_ETHER1[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_ETHER1[i]);
break;
case CHAIN_KIND_ETHERGEM:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_ETHERGEM[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_ETHERGEM[i]);
break;
case CHAIN_KIND_ATHEIOS:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_ATHEIOS[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_ATHEIOS[i]);
break;
case CHAIN_KIND_GOCHAIN:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_GOCHAIN[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_GOCHAIN[i]);
break;
case CHAIN_KIND_MIX:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_MIX[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_MIX[i]);
break;
case CHAIN_KIND_REOSC:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_REOSC[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_REOSC[i]);
break;
case CHAIN_KIND_HPB:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_HPB[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_HPB[i]);
break;
case CHAIN_KIND_TOMOCHAIN:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_TOMOCHAIN[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_TOMOCHAIN[i]);
break;
case CHAIN_KIND_TOBALABA:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_TOBALABA[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_TOBALABA[i]);
break;
case CHAIN_KIND_DEXON:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_DEXON[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_DEXON[i]);
break;
case CHAIN_KIND_VOLTA:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_VOLTA[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_VOLTA[i]);
break;
case CHAIN_KIND_EWC:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_EWC[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_EWC[i]);
break;
case CHAIN_KIND_WEBCHAIN:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_WEBCHAIN[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_WEBCHAIN[i]);
break;
case CHAIN_KIND_THUNDERCORE:
currentToken = (tokenDefinition_t *)PIC(&TOKENS_THUNDERCORE[i]);
currentToken = (tokenDefinition_t *) PIC(&TOKENS_THUNDERCORE[i]);
break
}
if (memcmp(currentToken->address, tmpContent.txContent.destination, 20) == 0) {
@@ -360,91 +359,151 @@ tokenDefinition_t* getKnownToken(uint8_t *contractAddress) {
}
}
#endif
for(size_t i=0; i<MAX_TOKEN; i++){
currentToken = &tmpCtx.transactionContext.tokens[i];
if (tmpCtx.transactionContext.tokenSet[i] && (memcmp(currentToken->address, contractAddress, 20) == 0)) {
PRINTF("Token found at index %d\n", i);
return currentToken;
}
for (size_t i = 0; i < MAX_TOKEN; i++) {
currentToken = &tmpCtx.transactionContext.tokens[i];
if (tmpCtx.transactionContext.tokenSet[i] &&
(memcmp(currentToken->address, contractAddress, 20) == 0)) {
PRINTF("Token found at index %d\n", i);
return currentToken;
}
}
return NULL;
}
void handleApdu(unsigned int *flags, unsigned int *tx) {
unsigned short sw = 0;
BEGIN_TRY {
TRY {
unsigned short sw = 0;
BEGIN_TRY {
TRY {
#ifdef HAVE_STARKWARE
if (G_io_apdu_buffer[OFFSET_CLA] == STARKWARE_CLA) {
switch(G_io_apdu_buffer[OFFSET_INS]) {
case STARKWARE_INS_GET_PUBLIC_KEY:
handleStarkwareGetPublicKey(G_io_apdu_buffer[OFFSET_P1], G_io_apdu_buffer[OFFSET_P2], G_io_apdu_buffer + OFFSET_CDATA, G_io_apdu_buffer[OFFSET_LC], flags, tx);
break;
case STARKWARE_INS_SIGN_MESSAGE:
handleStarkwareSignMessage(G_io_apdu_buffer[OFFSET_P1], G_io_apdu_buffer[OFFSET_P2], G_io_apdu_buffer + OFFSET_CDATA, G_io_apdu_buffer[OFFSET_LC], flags, tx);
break;
case STARKWARE_INS_PROVIDE_QUANTUM:
handleStarkwareProvideQuantum(G_io_apdu_buffer[OFFSET_P1], G_io_apdu_buffer[OFFSET_P2], G_io_apdu_buffer + OFFSET_CDATA, G_io_apdu_buffer[OFFSET_LC], flags, tx);
break;
case STARKWARE_INS_UNSAFE_SIGN:
handleStarkwareUnsafeSign(G_io_apdu_buffer[OFFSET_P1], G_io_apdu_buffer[OFFSET_P2], G_io_apdu_buffer + OFFSET_CDATA, G_io_apdu_buffer[OFFSET_LC], flags, tx);
break;
default:
THROW(0x6D00);
break;
}
CLOSE_TRY;
return;
}
if (G_io_apdu_buffer[OFFSET_CLA] == STARKWARE_CLA) {
switch (G_io_apdu_buffer[OFFSET_INS]) {
case STARKWARE_INS_GET_PUBLIC_KEY:
handleStarkwareGetPublicKey(G_io_apdu_buffer[OFFSET_P1],
G_io_apdu_buffer[OFFSET_P2],
G_io_apdu_buffer + OFFSET_CDATA,
G_io_apdu_buffer[OFFSET_LC],
flags,
tx);
break;
case STARKWARE_INS_SIGN_MESSAGE:
handleStarkwareSignMessage(G_io_apdu_buffer[OFFSET_P1],
G_io_apdu_buffer[OFFSET_P2],
G_io_apdu_buffer + OFFSET_CDATA,
G_io_apdu_buffer[OFFSET_LC],
flags,
tx);
break;
case STARKWARE_INS_PROVIDE_QUANTUM:
handleStarkwareProvideQuantum(G_io_apdu_buffer[OFFSET_P1],
G_io_apdu_buffer[OFFSET_P2],
G_io_apdu_buffer + OFFSET_CDATA,
G_io_apdu_buffer[OFFSET_LC],
flags,
tx);
break;
case STARKWARE_INS_UNSAFE_SIGN:
handleStarkwareUnsafeSign(G_io_apdu_buffer[OFFSET_P1],
G_io_apdu_buffer[OFFSET_P2],
G_io_apdu_buffer + OFFSET_CDATA,
G_io_apdu_buffer[OFFSET_LC],
flags,
tx);
break;
default:
THROW(0x6D00);
break;
}
CLOSE_TRY;
return;
}
#endif
if (G_io_apdu_buffer[OFFSET_CLA] != CLA) {
THROW(0x6E00);
}
if (G_io_apdu_buffer[OFFSET_CLA] != CLA) {
THROW(0x6E00);
}
switch (G_io_apdu_buffer[OFFSET_INS]) {
case INS_GET_PUBLIC_KEY:
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_TOKEN);
handleGetPublicKey(G_io_apdu_buffer[OFFSET_P1], G_io_apdu_buffer[OFFSET_P2], G_io_apdu_buffer + OFFSET_CDATA, G_io_apdu_buffer[OFFSET_LC], flags, tx);
break;
switch (G_io_apdu_buffer[OFFSET_INS]) {
case INS_GET_PUBLIC_KEY:
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_TOKEN);
handleGetPublicKey(G_io_apdu_buffer[OFFSET_P1],
G_io_apdu_buffer[OFFSET_P2],
G_io_apdu_buffer + OFFSET_CDATA,
G_io_apdu_buffer[OFFSET_LC],
flags,
tx);
break;
case INS_PROVIDE_ERC20_TOKEN_INFORMATION:
handleProvideErc20TokenInformation(G_io_apdu_buffer[OFFSET_P1], G_io_apdu_buffer[OFFSET_P2], G_io_apdu_buffer + OFFSET_CDATA, G_io_apdu_buffer[OFFSET_LC], flags, tx);
break;
case INS_PROVIDE_ERC20_TOKEN_INFORMATION:
handleProvideErc20TokenInformation(G_io_apdu_buffer[OFFSET_P1],
G_io_apdu_buffer[OFFSET_P2],
G_io_apdu_buffer + OFFSET_CDATA,
G_io_apdu_buffer[OFFSET_LC],
flags,
tx);
break;
case INS_SIGN:
handleSign(G_io_apdu_buffer[OFFSET_P1], G_io_apdu_buffer[OFFSET_P2], G_io_apdu_buffer + OFFSET_CDATA, G_io_apdu_buffer[OFFSET_LC], flags, tx);
break;
case INS_SIGN:
handleSign(G_io_apdu_buffer[OFFSET_P1],
G_io_apdu_buffer[OFFSET_P2],
G_io_apdu_buffer + OFFSET_CDATA,
G_io_apdu_buffer[OFFSET_LC],
flags,
tx);
break;
case INS_GET_APP_CONFIGURATION:
handleGetAppConfiguration(G_io_apdu_buffer[OFFSET_P1], G_io_apdu_buffer[OFFSET_P2], G_io_apdu_buffer + OFFSET_CDATA, G_io_apdu_buffer[OFFSET_LC], flags, tx);
break;
case INS_GET_APP_CONFIGURATION:
handleGetAppConfiguration(G_io_apdu_buffer[OFFSET_P1],
G_io_apdu_buffer[OFFSET_P2],
G_io_apdu_buffer + OFFSET_CDATA,
G_io_apdu_buffer[OFFSET_LC],
flags,
tx);
break;
case INS_SIGN_PERSONAL_MESSAGE:
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_TOKEN);
handleSignPersonalMessage(G_io_apdu_buffer[OFFSET_P1], G_io_apdu_buffer[OFFSET_P2], G_io_apdu_buffer + OFFSET_CDATA, G_io_apdu_buffer[OFFSET_LC], flags, tx);
break;
case INS_SIGN_PERSONAL_MESSAGE:
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_TOKEN);
handleSignPersonalMessage(G_io_apdu_buffer[OFFSET_P1],
G_io_apdu_buffer[OFFSET_P2],
G_io_apdu_buffer + OFFSET_CDATA,
G_io_apdu_buffer[OFFSET_LC],
flags,
tx);
break;
case INS_SIGN_EIP_712_MESSAGE:
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_TOKEN);
handleSignEIP712Message(G_io_apdu_buffer[OFFSET_P1], G_io_apdu_buffer[OFFSET_P2], G_io_apdu_buffer + OFFSET_CDATA, G_io_apdu_buffer[OFFSET_LC], flags, tx);
break;
case INS_SIGN_EIP_712_MESSAGE:
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_TOKEN);
handleSignEIP712Message(G_io_apdu_buffer[OFFSET_P1],
G_io_apdu_buffer[OFFSET_P2],
G_io_apdu_buffer + OFFSET_CDATA,
G_io_apdu_buffer[OFFSET_LC],
flags,
tx);
break;
#ifdef HAVE_ETH2
case INS_GET_ETH2_PUBLIC_KEY:
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_TOKEN);
handleGetEth2PublicKey(G_io_apdu_buffer[OFFSET_P1], G_io_apdu_buffer[OFFSET_P2], G_io_apdu_buffer + OFFSET_CDATA, G_io_apdu_buffer[OFFSET_LC], flags, tx);
break;
case INS_GET_ETH2_PUBLIC_KEY:
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_TOKEN);
handleGetEth2PublicKey(G_io_apdu_buffer[OFFSET_P1],
G_io_apdu_buffer[OFFSET_P2],
G_io_apdu_buffer + OFFSET_CDATA,
G_io_apdu_buffer[OFFSET_LC],
flags,
tx);
break;
case INS_SET_ETH2_WITHDRAWAL_INDEX:
handleSetEth2WithdrawalIndex(G_io_apdu_buffer[OFFSET_P1], G_io_apdu_buffer[OFFSET_P2], G_io_apdu_buffer + OFFSET_CDATA, G_io_apdu_buffer[OFFSET_LC], flags, tx);
break;
case INS_SET_ETH2_WITHDRAWAL_INDEX:
handleSetEth2WithdrawalIndex(G_io_apdu_buffer[OFFSET_P1],
G_io_apdu_buffer[OFFSET_P2],
G_io_apdu_buffer + OFFSET_CDATA,
G_io_apdu_buffer[OFFSET_LC],
flags,
tx);
break;
#endif
@@ -453,40 +512,40 @@ void handleApdu(unsigned int *flags, unsigned int *tx) {
goto return_to_dashboard;
#endif
default:
THROW(0x6D00);
break;
}
}
CATCH(EXCEPTION_IO_RESET) {
THROW(EXCEPTION_IO_RESET);
}
CATCH_OTHER(e) {
switch (e & 0xF000) {
case 0x6000:
// Wipe the transaction context and report the exception
sw = e;
reset_app_context();
break;
case 0x9000:
// All is well
sw = e;
break;
default:
// Internal error
sw = 0x6800 | (e & 0x7FF);
reset_app_context();
break;
default:
THROW(0x6D00);
break;
}
}
// Unexpected exception => report
G_io_apdu_buffer[*tx] = sw >> 8;
G_io_apdu_buffer[*tx + 1] = sw;
*tx += 2;
}
FINALLY {
}
}
END_TRY;
CATCH(EXCEPTION_IO_RESET) {
THROW(EXCEPTION_IO_RESET);
}
CATCH_OTHER(e) {
switch (e & 0xF000) {
case 0x6000:
// Wipe the transaction context and report the exception
sw = e;
reset_app_context();
break;
case 0x9000:
// All is well
sw = e;
break;
default:
// Internal error
sw = 0x6800 | (e & 0x7FF);
reset_app_context();
break;
}
// Unexpected exception => report
G_io_apdu_buffer[*tx] = sw >> 8;
G_io_apdu_buffer[*tx + 1] = sw;
*tx += 2;
}
FINALLY {
}
}
END_TRY;
}
void app_main(void) {
@@ -506,8 +565,8 @@ void app_main(void) {
BEGIN_TRY {
TRY {
rx = tx;
tx = 0; // ensure no race in catch_other if io_exchange throws
// an error
tx = 0; // ensure no race in catch_other if io_exchange throws
// an error
rx = io_exchange(CHANNEL_APDU | flags, rx);
flags = 0;
@@ -525,20 +584,20 @@ void app_main(void) {
}
CATCH_OTHER(e) {
switch (e & 0xF000) {
case 0x6000:
// Wipe the transaction context and report the exception
sw = e;
reset_app_context();
break;
case 0x9000:
// All is well
sw = e;
break;
default:
// Internal error
sw = 0x6800 | (e & 0x7FF);
reset_app_context();
break;
case 0x6000:
// Wipe the transaction context and report the exception
sw = e;
reset_app_context();
break;
case 0x9000:
// All is well
sw = e;
break;
default:
// Internal error
sw = 0x6800 | (e & 0x7FF);
reset_app_context();
break;
}
if (e != 0x9000) {
flags &= ~IO_ASYNCH_REPLY;
@@ -554,13 +613,13 @@ void app_main(void) {
END_TRY;
}
//return_to_dashboard:
// return_to_dashboard:
return;
}
// override point, but nothing more to do
void io_seproxyhal_display(const bagl_element_t *element) {
io_seproxyhal_display_default((bagl_element_t *)element);
io_seproxyhal_display_default((bagl_element_t *) element);
}
unsigned char io_event(unsigned char channel) {
@@ -569,26 +628,28 @@ unsigned char io_event(unsigned char channel) {
// can't have more than one tag in the reply, not supported yet.
switch (G_io_seproxyhal_spi_buffer[0]) {
case SEPROXYHAL_TAG_FINGER_EVENT:
UX_FINGER_EVENT(G_io_seproxyhal_spi_buffer);
break;
case SEPROXYHAL_TAG_FINGER_EVENT:
UX_FINGER_EVENT(G_io_seproxyhal_spi_buffer);
break;
case SEPROXYHAL_TAG_BUTTON_PUSH_EVENT:
UX_BUTTON_PUSH_EVENT(G_io_seproxyhal_spi_buffer);
break;
case SEPROXYHAL_TAG_BUTTON_PUSH_EVENT:
UX_BUTTON_PUSH_EVENT(G_io_seproxyhal_spi_buffer);
break;
case SEPROXYHAL_TAG_STATUS_EVENT:
if (G_io_apdu_media == IO_APDU_MEDIA_USB_HID && !(U4BE(G_io_seproxyhal_spi_buffer, 3) & SEPROXYHAL_TAG_STATUS_EVENT_FLAG_USB_POWERED)) {
THROW(EXCEPTION_IO_RESET);
}
// no break is intentional
default:
UX_DEFAULT_EVENT();
break;
case SEPROXYHAL_TAG_STATUS_EVENT:
if (G_io_apdu_media == IO_APDU_MEDIA_USB_HID &&
!(U4BE(G_io_seproxyhal_spi_buffer, 3) &
SEPROXYHAL_TAG_STATUS_EVENT_FLAG_USB_POWERED)) {
THROW(EXCEPTION_IO_RESET);
}
// no break is intentional
default:
UX_DEFAULT_EVENT();
break;
case SEPROXYHAL_TAG_DISPLAY_PROCESSED_EVENT:
UX_DISPLAYED_EVENT({});
break;
case SEPROXYHAL_TAG_DISPLAY_PROCESSED_EVENT:
UX_DISPLAYED_EVENT({});
break;
#if 0
case SEPROXYHAL_TAG_TICKER_EVENT:
@@ -609,21 +670,17 @@ unsigned char io_event(unsigned char channel) {
}
void app_exit() {
BEGIN_TRY_L(exit) {
TRY_L(exit) {
os_sched_exit(-1);
}
FINALLY_L(exit) {
}
}
END_TRY_L(exit);
}
void coin_main_with_config(chain_config_t *config) {
chainConfig = config;
reset_app_context();
tmpCtx.transactionContext.currentTokenIndex = 0;
@@ -638,14 +695,14 @@ void coin_main_with_config(chain_config_t *config) {
#ifdef TARGET_NANOX
// grab the current plane mode setting
G_io_app.plane_mode = os_setting_get(OS_SETTING_PLANEMODE, NULL, 0);
#endif // TARGET_NANOX
#endif // TARGET_NANOX
if (N_storage.initialized != 0x01) {
internalStorage_t storage;
storage.dataAllowed = 0x00;
storage.contractDetails = 0x00;
storage.initialized = 0x01;
nvm_write((void*)&N_storage, (void*)&storage, sizeof(internalStorage_t));
nvm_write((void *) &N_storage, (void *) &storage, sizeof(internalStorage_t));
}
USB_power(0);
@@ -656,7 +713,7 @@ void coin_main_with_config(chain_config_t *config) {
#ifdef HAVE_BLE
BLE_power(0, NULL);
BLE_power(1, "Nano X");
#endif // HAVE_BLE
#endif // HAVE_BLE
app_main();
}
@@ -690,30 +747,37 @@ void coin_main() {
coin_main_with_config(&coin_config);
}
void library_main_with_config(chain_config_t *config, unsigned int command, unsigned int* call_parameters) {
void library_main_with_config(chain_config_t *config,
unsigned int command,
unsigned int *call_parameters) {
BEGIN_TRY {
TRY {
check_api_level(CX_COMPAT_APILEVEL);
PRINTF("Inside a library \n");
switch (command) {
case CHECK_ADDRESS:
handle_check_address((check_address_parameters_t*)call_parameters, config);
break;
handle_check_address((check_address_parameters_t *) call_parameters, config);
break;
case SIGN_TRANSACTION:
handle_swap_sign_transaction((create_transaction_parameters_t*)call_parameters, config);
break;
handle_swap_sign_transaction(
(create_transaction_parameters_t *) call_parameters,
config);
break;
case GET_PRINTABLE_AMOUNT:
handle_get_printable_amount((get_printable_amount_parameters_t*)call_parameters, config);
break;
handle_get_printable_amount(
(get_printable_amount_parameters_t *) call_parameters,
config);
break;
}
os_lib_end();
}
FINALLY {}
FINALLY {
}
}
END_TRY;
}
void library_main(unsigned int call_id, unsigned int* call_parameters) {
void library_main(unsigned int call_id, unsigned int *call_parameters) {
chain_config_t coin_config;
init_coin_config(&coin_config);
library_main_with_config(&coin_config, call_id, call_parameters);
@@ -736,22 +800,22 @@ __attribute__((section(".boot"))) int main(int arg0) {
libcall_params[4] = 0;
if (arg0) {
// call as a library
libcall_params[2] = ((unsigned int *)arg0)[1];
libcall_params[4] = ((unsigned int *)arg0)[3]; // library arguments
libcall_params[2] = ((unsigned int *) arg0)[1];
libcall_params[4] = ((unsigned int *) arg0)[3]; // library arguments
os_lib_call(&libcall_params);
((unsigned int *)arg0)[0] = libcall_params[1];
((unsigned int *) arg0)[0] = libcall_params[1];
os_lib_end();
}
else {
} else {
// launch coin application
libcall_params[1] = 0x100; // use the Init call, as we won't exit
libcall_params[1] = 0x100; // use the Init call, as we won't exit
os_lib_call(&libcall_params);
}
}
FINALLY {}
FINALLY {
}
}
END_TRY;
// no return
// no return
#else
// exit critical section
__asm volatile("cpsie i");
@@ -765,12 +829,12 @@ __attribute__((section(".boot"))) int main(int arg0) {
return 0;
}
if (((unsigned int *)arg0)[0] != 0x100) {
if (((unsigned int *) arg0)[0] != 0x100) {
app_exit();
return 0;
}
unsigned int command = ((unsigned int *)arg0)[1];
chain_config_t * chain_config = ((unsigned int *)arg0)[2];
unsigned int command = ((unsigned int *) arg0)[1];
chain_config_t *chain_config = ((unsigned int *) arg0)[2];
switch (command) {
case RUN_APPLICATION:
// coin application launched from dashboard
@@ -778,25 +842,18 @@ __attribute__((section(".boot"))) int main(int arg0) {
app_exit();
else
coin_main_with_config(chain_config);
break;
break;
default:
if (chain_config == NULL)
// Called as standalone eth library
library_main(command, ((unsigned int *)arg0)[3]);// called as bitcoin library
library_main(command, ((unsigned int *) arg0)[3]); // called as bitcoin library
else
// Called as a library from an altcoin
library_main_with_config(chain_config, command, ((unsigned int *)arg0)[3]);// called as coin library
break;
library_main_with_config(chain_config,
command,
((unsigned int *) arg0)[3]); // called as coin library
break;
}
#endif
return 0;
}

View File

@@ -3,12 +3,12 @@
#include "poorstream.h"
void poorstream_init(poorstream_t *stream, uint8_t *buffer) {
memset((void*)stream, 0, sizeof(poorstream_t));
stream->pointer = buffer;
memset((void *) stream, 0, sizeof(poorstream_t));
stream->pointer = buffer;
}
void poorstream_flush(poorstream_t *stream) {
//PRINTF("Flush\n");
// PRINTF("Flush\n");
*(stream->pointer + 0) = (stream->accumulator >> 56);
*(stream->pointer + 1) = (stream->accumulator >> 48);
*(stream->pointer + 2) = (stream->accumulator >> 40);
@@ -23,12 +23,12 @@ void poorstream_write_bits(poorstream_t *stream, uint64_t bits, uint32_t num_bit
stream->offset += num_bits;
if (stream->offset < 64) {
stream->accumulator |= (bits << (64 - stream->offset));
//PRINTF("ACC |= << %d\n", (64 - stream->offset));
// PRINTF("ACC |= << %d\n", (64 - stream->offset));
} else {
stream->offset -= 64;
stream->mask = ((1 << (num_bits - stream->offset)) - 1);
//PRINTF("Mask %lx\n", stream->mask);
//PRINTF("Offset %d\n", stream->offset);
// PRINTF("Mask %lx\n", stream->mask);
// PRINTF("Offset %d\n", stream->offset);
stream->accumulator |= ((bits >> stream->offset) & stream->mask);
poorstream_flush(stream);
stream->accumulator = 0;

View File

@@ -8,10 +8,10 @@
#include "os.h"
typedef struct poorstream_t {
uint8_t *pointer;
uint32_t offset;
uint64_t mask;
uint64_t accumulator;
uint8_t *pointer;
uint32_t offset;
uint64_t mask;
uint64_t accumulator;
} poorstream_t;
void poorstream_init(poorstream_t *stream, uint8_t *buffer);

View File

@@ -22,24 +22,24 @@
#define WEI_TO_ETHER 18
#define N_storage (*(volatile internalStorage_t*) PIC(&N_storage_real))
#define N_storage (*(volatile internalStorage_t *) PIC(&N_storage_real))
typedef struct internalStorage_t {
unsigned char dataAllowed;
unsigned char contractDetails;
uint8_t initialized;
unsigned char dataAllowed;
unsigned char contractDetails;
uint8_t initialized;
} internalStorage_t;
#ifdef HAVE_STARKWARE
typedef enum starkQuantumType_e {
STARK_QUANTUM_LEGACY = 0x00,
STARK_QUANTUM_ETH,
STARK_QUANTUM_ERC20,
STARK_QUANTUM_ERC721,
STARK_QUANTUM_MINTABLE_ERC20,
STARK_QUANTUM_MINTABLE_ERC721
STARK_QUANTUM_LEGACY = 0x00,
STARK_QUANTUM_ETH,
STARK_QUANTUM_ERC20,
STARK_QUANTUM_ERC721,
STARK_QUANTUM_MINTABLE_ERC20,
STARK_QUANTUM_MINTABLE_ERC721
} starkQuantumType_e;
@@ -47,11 +47,11 @@ typedef enum starkQuantumType_e {
typedef struct tokenContext_t {
char pluginName[PLUGIN_ID_LENGTH];
uint8_t pluginAvailable;
uint8_t pluginAvailable;
uint8_t data[32];
uint8_t fieldIndex;
uint8_t fieldOffset;
uint8_t fieldOffset;
uint8_t pluginUiMaxItems;
uint8_t pluginUiCurrentItem;
@@ -98,7 +98,6 @@ typedef struct messageSigningContext712_t {
uint8_t messageHash[32];
} messageSigningContext712_t;
typedef union {
publicKeyContext_t publicKeyContext;
transactionContext_t transactionContext;
@@ -107,22 +106,22 @@ typedef union {
} tmpCtx_t;
typedef union {
txContent_t txContent;
cx_sha256_t sha2;
char tmp[100];
txContent_t txContent;
cx_sha256_t sha2;
char tmp[100];
} tmpContent_t;
#ifdef HAVE_STARKWARE
typedef struct starkContext_t {
uint8_t w1[32];
uint8_t w2[32];
uint8_t w3[32];
uint8_t w4[32];
uint8_t conditional;
uint8_t transferDestination[32];
uint8_t fact[32];
uint8_t conditionAddress[20];
uint8_t w1[32];
uint8_t w2[32];
uint8_t w3[32];
uint8_t w4[32];
uint8_t conditional;
uint8_t transferDestination[32];
uint8_t fact[32];
uint8_t conditionAddress[20];
} starkContext_t;
#endif
@@ -134,27 +133,23 @@ typedef union {
#endif
} dataContext_t;
typedef enum {
APP_STATE_IDLE,
APP_STATE_SIGNING_TX,
APP_STATE_SIGNING_MESSAGE
} app_state_t;
typedef enum { APP_STATE_IDLE, APP_STATE_SIGNING_TX, APP_STATE_SIGNING_MESSAGE } app_state_t;
typedef enum {
CONTRACT_NONE,
CONTRACT_ERC20,
CONTRACT_ALLOWANCE,
CONTRACT_NONE,
CONTRACT_ERC20,
CONTRACT_ALLOWANCE,
#ifdef HAVE_STARKWARE
CONTRACT_STARKWARE_REGISTER,
CONTRACT_STARKWARE_DEPOSIT_TOKEN,
CONTRACT_STARKWARE_DEPOSIT_ETH,
CONTRACT_STARKWARE_WITHDRAW,
CONTRACT_STARKWARE_DEPOSIT_CANCEL,
CONTRACT_STARKWARE_DEPOSIT_RECLAIM,
CONTRACT_STARKWARE_FULL_WITHDRAWAL,
CONTRACT_STARKWARE_FREEZE,
CONTRACT_STARKWARE_ESCAPE,
CONTRACT_STARKWARE_VERIFY_ESCAPE
CONTRACT_STARKWARE_REGISTER,
CONTRACT_STARKWARE_DEPOSIT_TOKEN,
CONTRACT_STARKWARE_DEPOSIT_ETH,
CONTRACT_STARKWARE_WITHDRAW,
CONTRACT_STARKWARE_DEPOSIT_CANCEL,
CONTRACT_STARKWARE_DEPOSIT_RECLAIM,
CONTRACT_STARKWARE_FULL_WITHDRAWAL,
CONTRACT_STARKWARE_FREEZE,
CONTRACT_STARKWARE_ESCAPE,
CONTRACT_STARKWARE_VERIFY_ESCAPE
#endif
} contract_call_t;
@@ -196,5 +191,4 @@ extern uint32_t eth2WithdrawalIndex;
void reset_app_context(void);
#endif // __SHARED_CONTEXT_H__
#endif // __SHARED_CONTEXT_H__

View File

@@ -5,18 +5,17 @@
#include "ui_callbacks.h"
#include "utils.h"
static unsigned char const C_cx_Stark256_n[] = {
//n: 0x0800000000000010ffffffffffffffffb781126dcae7b2321e66a241adc64d2f
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xb7, 0x81, 0x12, 0x6d, 0xca, 0xe7, 0xb2, 0x32, 0x1e, 0x66, 0xa2, 0x41, 0xad, 0xc6, 0x4d, 0x2f};
// C_cx_secp256k1_n - (C_cx_secp256k1_n % C_cx_Stark256_n)
static unsigned char const STARK_DERIVE_BIAS[] = {
0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x0e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7,
0x38, 0xa1, 0x3b, 0x4b, 0x92, 0x0e, 0x94, 0x11, 0xae, 0x6d, 0xa5, 0xf4, 0x0b, 0x03, 0x58, 0xb1
};
static unsigned char const C_cx_Stark256_n[] = {
// n: 0x0800000000000010ffffffffffffffffb781126dcae7b2321e66a241adc64d2f
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xb7, 0x81, 0x12, 0x6d, 0xca, 0xe7, 0xb2, 0x32, 0x1e, 0x66, 0xa2, 0x41, 0xad, 0xc6, 0x4d, 0x2f};
void starkDerivePrivateKey(uint32_t *bip32Path, uint32_t bip32PathLength, uint8_t *privateKeyData) {
// C_cx_secp256k1_n - (C_cx_secp256k1_n % C_cx_Stark256_n)
static unsigned char const STARK_DERIVE_BIAS[] = {
0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x0e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7,
0x38, 0xa1, 0x3b, 0x4b, 0x92, 0x0e, 0x94, 0x11, 0xae, 0x6d, 0xa5, 0xf4, 0x0b, 0x03, 0x58, 0xb1};
void starkDerivePrivateKey(uint32_t *bip32Path, uint32_t bip32PathLength, uint8_t *privateKeyData) {
#if 0
// Sanity check
if (bip32Path[0] != STARK_BIP32_PATH_0) {
@@ -29,59 +28,62 @@ void starkDerivePrivateKey(uint32_t *bip32Path, uint32_t bip32PathLength, uint8_
cx_math_modm(privateKeyData, 32, C_cx_Stark256_n, 32);
PRINTF("Private key after processing %.*H\n", 32, privateKeyData);
#else
uint8_t tmp[33];
uint8_t index = 0;
// Sanity check
if ((bip32PathLength < 2) || (bip32Path[0] != STARK_BIP32_PATH_0) || (bip32Path[1] != STARK_BIP32_PATH_1)) {
PRINTF("Invalid Stark derivation path %d %d\n", bip32Path[0], bip32Path[1]);
THROW(0x6a80);
}
os_perso_derive_node_bip32(CX_CURVE_256K1, bip32Path, bip32PathLength, tmp, NULL);
PRINTF("Private key before processing %.*H\n", 32, tmp);
for(;;) {
tmp[32] = index;
cx_hash_sha256(tmp, 33, privateKeyData, 32);
PRINTF("Key hash %.*H\n", 32, privateKeyData);
if (cx_math_cmp(privateKeyData, STARK_DERIVE_BIAS, 32) < 0) {
cx_math_modm(privateKeyData, 32, C_cx_Stark256_n, 32);
break;
uint8_t tmp[33];
uint8_t index = 0;
// Sanity check
if ((bip32PathLength < 2) || (bip32Path[0] != STARK_BIP32_PATH_0) ||
(bip32Path[1] != STARK_BIP32_PATH_1)) {
PRINTF("Invalid Stark derivation path %d %d\n", bip32Path[0], bip32Path[1]);
THROW(0x6a80);
}
index++;
}
PRINTF("Key result %.*H\n", 32, privateKeyData);
os_perso_derive_node_bip32(CX_CURVE_256K1, bip32Path, bip32PathLength, tmp, NULL);
PRINTF("Private key before processing %.*H\n", 32, tmp);
for (;;) {
tmp[32] = index;
cx_hash_sha256(tmp, 33, privateKeyData, 32);
PRINTF("Key hash %.*H\n", 32, privateKeyData);
if (cx_math_cmp(privateKeyData, STARK_DERIVE_BIAS, 32) < 0) {
cx_math_modm(privateKeyData, 32, C_cx_Stark256_n, 32);
break;
}
index++;
}
PRINTF("Key result %.*H\n", 32, privateKeyData);
#endif
#endif
}
void stark_get_amount_string(uint8_t *contractAddress, uint8_t *quantum256, uint8_t *amount64, char *tmp100, char *target100) {
uint256_t amountPre, quantum, amount;
uint8_t decimals;
char *ticker = (char*)PIC(chainConfig->coinName);
void stark_get_amount_string(uint8_t *contractAddress,
uint8_t *quantum256,
uint8_t *amount64,
char *tmp100,
char *target100) {
uint256_t amountPre, quantum, amount;
uint8_t decimals;
char *ticker = (char *) PIC(chainConfig->coinName);
PRINTF("stark_get_amount_string %.*H\n", 20, contractAddress);
PRINTF("stark_get_amount_string %.*H\n", 20, contractAddress);
if (allzeroes(contractAddress, 20)) {
decimals = WEI_TO_ETHER;
PRINTF("stark_get_amount_string - ETH\n");
}
else {
tokenDefinition_t *token = getKnownToken(contractAddress);
if (token == NULL) { // caught earlier
THROW(0x6A80);
if (allzeroes(contractAddress, 20)) {
decimals = WEI_TO_ETHER;
PRINTF("stark_get_amount_string - ETH\n");
} else {
tokenDefinition_t *token = getKnownToken(contractAddress);
if (token == NULL) { // caught earlier
THROW(0x6A80);
}
decimals = token->decimals;
ticker = (char *) token->ticker;
PRINTF("stark_get_amount_string - decimals %d ticker %s\n", decimals, ticker);
}
decimals = token->decimals;
ticker = (char*)token->ticker;
PRINTF("stark_get_amount_string - decimals %d ticker %s\n", decimals, ticker);
}
convertUint256BE(amount64, 8, &amountPre);
readu256BE(quantum256, &quantum);
mul256(&amountPre, &quantum, &amount);
tostring256(&amount, 10, tmp100, 100);
PRINTF("stark_get_amount_string - mul256 %s\n", tmp100);
strcpy(target100, ticker);
adjustDecimals(tmp100, strlen(tmp100), target100 + strlen(ticker), 100, decimals);
PRINTF("get_amount_string %s\n", target100);
convertUint256BE(amount64, 8, &amountPre);
readu256BE(quantum256, &quantum);
mul256(&amountPre, &quantum, &amount);
tostring256(&amount, 10, tmp100, 100);
PRINTF("stark_get_amount_string - mul256 %s\n", tmp100);
strcpy(target100, ticker);
adjustDecimals(tmp100, strlen(tmp100), target100 + strlen(ticker), 100, decimals);
PRINTF("get_amount_string %s\n", target100);
}
#endif // HAVE_STARK
#endif // HAVE_STARK

View File

@@ -8,14 +8,14 @@
#include "os.h"
#include "cx.h"
/* EC points */
#define FIELD_ELEMENT_SIZE (32)
#define EC_POINT_SIZE (2 * FIELD_ELEMENT_SIZE + 1)
#define EC_POINT_SIZE (2 * FIELD_ELEMENT_SIZE + 1)
typedef unsigned char FieldElement[FIELD_ELEMENT_SIZE];
typedef unsigned char ECPoint[EC_POINT_SIZE];
void pedersen(FieldElement res, /* out */
FieldElement a, FieldElement b);
FieldElement a,
FieldElement b);
#endif
#endif

View File

@@ -8,16 +8,14 @@
#define SIGNATURE_MAX_LEN (72)
static const ECPoint PEDERSEN_SHIFT[] = { {
static const ECPoint PEDERSEN_SHIFT[] = {{
0x04,
0x04, 0x9e, 0xe3, 0xeb, 0xa8, 0xc1, 0x60, 0x07, 0x00, 0xee, 0x1b,
0x87, 0xeb, 0x59, 0x9f, 0x16, 0x71, 0x6b, 0x0b, 0x10, 0x22, 0x94,
0x77, 0x33, 0x55, 0x1f, 0xde, 0x40, 0x50, 0xca, 0x68, 0x04,
0x04, 0x9e, 0xe3, 0xeb, 0xa8, 0xc1, 0x60, 0x07, 0x00, 0xee, 0x1b, 0x87, 0xeb, 0x59, 0x9f, 0x16,
0x71, 0x6b, 0x0b, 0x10, 0x22, 0x94, 0x77, 0x33, 0x55, 0x1f, 0xde, 0x40, 0x50, 0xca, 0x68, 0x04,
0x03, 0xca, 0x0c, 0xfe, 0x4b, 0x3b, 0xc6, 0xdd, 0xf3, 0x46, 0xd4,
0x9d, 0x06, 0xea, 0x0e, 0xd3, 0x4e, 0x62, 0x10, 0x62, 0xc0, 0xe0,
0x56, 0xc1, 0xd0, 0x40, 0x5d, 0x26, 0x6e, 0x10, 0x26, 0x8a,
0x03, 0xca, 0x0c, 0xfe, 0x4b, 0x3b, 0xc6, 0xdd, 0xf3, 0x46, 0xd4, 0x9d, 0x06, 0xea, 0x0e, 0xd3,
0x4e, 0x62, 0x10, 0x62, 0xc0, 0xe0, 0x56, 0xc1, 0xd0, 0x40, 0x5d, 0x26, 0x6e, 0x10, 0x26, 0x8a,
}};
static const ECPoint PEDERSEN_POINTS[4] = {
@@ -78,15 +76,16 @@ void accum_ec_mul(ECPoint *hash, uint8_t *buf, int len, int pedersen_idx) {
}
void pedersen(FieldElement res, /* out */
FieldElement a, FieldElement b) {
FieldElement a,
FieldElement b) {
ECPoint hash;
memcpy(hash, PEDERSEN_SHIFT, sizeof(hash));
accum_ec_mul(&hash, a, 1, 1);
accum_ec_mul(&hash, a+1, FIELD_ELEMENT_SIZE-1, 0);
accum_ec_mul(&hash, a + 1, FIELD_ELEMENT_SIZE - 1, 0);
accum_ec_mul(&hash, b, 1, 3);
accum_ec_mul(&hash, b+1, FIELD_ELEMENT_SIZE-1, 2);
accum_ec_mul(&hash, b + 1, FIELD_ELEMENT_SIZE - 1, 2);
memcpy(res, hash + 1, FIELD_ELEMENT_SIZE);
}
@@ -116,31 +115,43 @@ int stark_sign(uint8_t *signature, /* out */
PRINTF("Pedersen hash 2 %.*H\n", 32, hash);
cx_ecfp_init_private_key(CX_CURVE_Stark256, privateKeyData, 32, &privateKey);
io_seproxyhal_io_heartbeat();
int signatureLength = cx_ecdsa_sign(&privateKey, CX_RND_RFC6979 | CX_LAST, CX_SHA256,
hash, sizeof(hash), signature, SIGNATURE_MAX_LEN, &info);
int signatureLength = cx_ecdsa_sign(&privateKey,
CX_RND_RFC6979 | CX_LAST,
CX_SHA256,
hash,
sizeof(hash),
signature,
SIGNATURE_MAX_LEN,
&info);
PRINTF("Stark signature %.*H\n", signatureLength, signature);
return signatureLength;
}
// ERC20Token(address)
static const uint8_t ERC20_SELECTOR[] = { 0xf4, 0x72, 0x61, 0xb0 };
static const uint8_t ERC20_SELECTOR[] = {0xf4, 0x72, 0x61, 0xb0};
// ETH()
static const uint8_t ETH_SELECTOR[] = { 0x83, 0x22, 0xff, 0xf2 };
static const uint8_t ETH_SELECTOR[] = {0x83, 0x22, 0xff, 0xf2};
// ERC721Token(address, uint256)
static const uint8_t ERC721_SELECTOR[] = { 0x02, 0x57, 0x17, 0x92 };
static const uint8_t ERC721_SELECTOR[] = {0x02, 0x57, 0x17, 0x92};
// MintableERC20Token(address)
static const uint8_t MINTABLE_ERC20_SELECTOR[] = { 0x68, 0x64, 0x6e, 0x2d };
static const uint8_t MINTABLE_ERC20_SELECTOR[] = {0x68, 0x64, 0x6e, 0x2d};
// MintableERC721Token(address,uint256)
static const uint8_t MINTABLE_ERC721_SELECTOR[] = { 0xb8, 0xb8, 0x66, 0x72 };
static const char NFT_ASSET_ID_PREFIX[] = { 'N', 'F', 'T', ':', 0 };
static const char MINTABLE_ASSET_ID_PREFIX[] = { 'M', 'I', 'N', 'T', 'A', 'B', 'L', 'E', ':', 0 };
static const uint8_t MINTABLE_ERC721_SELECTOR[] = {0xb8, 0xb8, 0x66, 0x72};
static const char NFT_ASSET_ID_PREFIX[] = {'N', 'F', 'T', ':', 0};
static const char MINTABLE_ASSET_ID_PREFIX[] = {'M', 'I', 'N', 'T', 'A', 'B', 'L', 'E', ':', 0};
void compute_token_id(cx_sha3_t *sha3, uint8_t *contractAddress, uint8_t quantumType, uint8_t *quantum, uint8_t *mintingBlob, bool assetTypeOnly, uint8_t *output) {
void compute_token_id(cx_sha3_t *sha3,
uint8_t *contractAddress,
uint8_t quantumType,
uint8_t *quantum,
uint8_t *mintingBlob,
bool assetTypeOnly,
uint8_t *output) {
uint8_t tmp[36];
cx_keccak_init(sha3, 256);
if ((contractAddress != NULL) && (!allzeroes(contractAddress, 20))) {
const uint8_t *selector = NULL;
switch(quantumType) {
switch (quantumType) {
case STARK_QUANTUM_ERC20:
case STARK_QUANTUM_LEGACY:
selector = ERC20_SELECTOR;
@@ -162,29 +173,27 @@ void compute_token_id(cx_sha3_t *sha3, uint8_t *contractAddress, uint8_t quantum
memset(tmp, 0, sizeof(tmp));
memmove(tmp, selector, 4);
memmove(tmp + 16, contractAddress, 20);
cx_hash((cx_hash_t*)sha3, 0, tmp, sizeof(tmp), NULL, 0);
}
else {
cx_hash((cx_hash_t *) sha3, 0, tmp, sizeof(tmp), NULL, 0);
} else {
PRINTF("compute_token_id for ETH\n");
cx_hash((cx_hash_t*)sha3, 0, ETH_SELECTOR, sizeof(ETH_SELECTOR), NULL, 0);
cx_hash((cx_hash_t *) sha3, 0, ETH_SELECTOR, sizeof(ETH_SELECTOR), NULL, 0);
}
if ((quantumType == STARK_QUANTUM_ERC721) || (quantumType == STARK_QUANTUM_MINTABLE_ERC721)) {
if ((quantumType == STARK_QUANTUM_ERC721) || (quantumType == STARK_QUANTUM_MINTABLE_ERC721)) {
memset(tmp, 0, 32);
tmp[31] = 1;
PRINTF("compute_token_id quantum %.*H\n", 32, tmp);
cx_hash((cx_hash_t*)sha3, CX_LAST, tmp, 32, output, 32);
}
else {
cx_hash((cx_hash_t *) sha3, CX_LAST, tmp, 32, output, 32);
} else {
PRINTF("compute_token_id quantum %.*H\n", 32, quantum);
cx_hash((cx_hash_t*)sha3, CX_LAST, quantum, 32, output, 32);
cx_hash((cx_hash_t *) sha3, CX_LAST, quantum, 32, output, 32);
}
if (!assetTypeOnly && ((quantumType != STARK_QUANTUM_LEGACY) &&
(quantumType != STARK_QUANTUM_ETH) &&
(quantumType != STARK_QUANTUM_ERC20))) {
if (!assetTypeOnly &&
((quantumType != STARK_QUANTUM_LEGACY) && (quantumType != STARK_QUANTUM_ETH) &&
(quantumType != STARK_QUANTUM_ERC20))) {
const char *prefix = NULL;
output[0] &= 0x03;
cx_keccak_init(sha3, 256);
switch(quantumType) {
switch (quantumType) {
case STARK_QUANTUM_ERC721:
prefix = NFT_ASSET_ID_PREFIX;
break;
@@ -196,18 +205,18 @@ void compute_token_id(cx_sha3_t *sha3, uint8_t *contractAddress, uint8_t quantum
PRINTF("Unsupported non default quantum type %d\n", quantumType);
return;
}
cx_hash((cx_hash_t*)sha3, 0, (const uint8_t*)prefix, strlen(prefix), NULL, 0);
cx_hash((cx_hash_t*)sha3, 0, output, 32, NULL, 0);
cx_hash((cx_hash_t*)sha3, CX_LAST, mintingBlob, 32, output, 32);
cx_hash((cx_hash_t *) sha3, 0, (const uint8_t *) prefix, strlen(prefix), NULL, 0);
cx_hash((cx_hash_t *) sha3, 0, output, 32, NULL, 0);
cx_hash((cx_hash_t *) sha3, CX_LAST, mintingBlob, 32, output, 32);
}
if (!assetTypeOnly && ((quantumType == STARK_QUANTUM_MINTABLE_ERC20) || (quantumType == STARK_QUANTUM_MINTABLE_ERC721))) {
if (!assetTypeOnly && ((quantumType == STARK_QUANTUM_MINTABLE_ERC20) ||
(quantumType == STARK_QUANTUM_MINTABLE_ERC721))) {
output[0] = 0x04;
output[1] = 0x00;
}
else {
} else {
output[0] &= 0x03;
}
PRINTF("compute_token_id computed token %.*H\n", 32, output);
}
#endif // HAVE_STARK
#endif // HAVE_STARK

View File

@@ -9,11 +9,21 @@
#include "cx.h"
#include "stark_crypto.h"
void compute_token_id(cx_sha3_t *sha3, uint8_t *contractAddress, uint8_t quantumType, uint8_t *quantum, uint8_t *mintingBlob, bool assetTypeOnly, uint8_t *output);
void compute_token_id(cx_sha3_t *sha3,
uint8_t *contractAddress,
uint8_t quantumType,
uint8_t *quantum,
uint8_t *mintingBlob,
bool assetTypeOnly,
uint8_t *output);
void starkDerivePrivateKey(uint32_t *bip32Path, uint32_t bip32PathLength, uint8_t *privateKeyData);
void stark_get_amount_string(uint8_t *contractAddress, uint8_t *quantum256, uint8_t *amount64, char *tmp100, char *target100);
void stark_get_amount_string(uint8_t *contractAddress,
uint8_t *quantum256,
uint8_t *amount64,
char *tmp100,
char *target100);
int stark_sign(uint8_t *signature, /* out */
uint8_t *privateKeyData,
@@ -23,4 +33,3 @@ int stark_sign(uint8_t *signature, /* out */
FieldElement condition);
#endif

View File

@@ -20,8 +20,8 @@ typedef struct check_address_parameters_s {
// fields and serialization format depends on spesific coin app
unsigned char* address_parameters;
unsigned char address_parameters_length;
char *address_to_check;
char *extra_id_to_check;
char* address_to_check;
char* extra_id_to_check;
// OUT
int result;
} check_address_parameters_t;
@@ -45,8 +45,8 @@ typedef struct create_transaction_parameters_s {
unsigned char amount_length;
unsigned char* fee_amount;
unsigned char fee_amount_length;
char *destination_address;
char *destination_address_extra_id;
char* destination_address;
char* destination_address_extra_id;
} create_transaction_parameters_t;
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,26 +1,26 @@
/*******************************************************************************
* Ledger Ethereum App
* (c) 2016-2019 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.
********************************************************************************/
* Ledger Ethereum App
* (c) 2016-2019 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.
********************************************************************************/
#ifndef _TOKENS_H_
#define _TOKENS_H_
#include <stdint.h>
#define MAX_TICKER_LEN 12 // 10 characters + ' ' + '\0'
#define MAX_TICKER_LEN 12 // 10 characters + ' ' + '\0'
typedef struct tokenDefinition_t {
#ifdef HAVE_CONTRACT_NAME_IN_DESCRIPTOR
@@ -33,7 +33,7 @@ typedef struct tokenDefinition_t {
#ifdef HAVE_TOKENS_EXTRA_LIST
#define NUM_TOKENS_EXTRA 4
#define NUM_TOKENS_EXTRA 4
extern tokenDefinition_t const TOKENS_EXTRA[NUM_TOKENS_EXTRA];
@@ -41,36 +41,36 @@ extern tokenDefinition_t const TOKENS_EXTRA[NUM_TOKENS_EXTRA];
#ifdef HAVE_TOKENS_LIST
#define NUM_TOKENS_AKROMA 0
#define NUM_TOKENS_ELLAISM 1
#define NUM_TOKENS_ETHEREUM 1102
#define NUM_TOKENS_AKROMA 0
#define NUM_TOKENS_ELLAISM 1
#define NUM_TOKENS_ETHEREUM 1102
#define NUM_TOKENS_ETHEREUM_CLASSIC 4
#define NUM_TOKENS_ETHERSOCIAL 0
#define NUM_TOKENS_ETHER1 0
#define NUM_TOKENS_PIRL 0
#define NUM_TOKENS_POA 0
#define NUM_TOKENS_RSK 0
#define NUM_TOKENS_UBIQ 6
#define NUM_TOKENS_EXPANSE 0
#define NUM_TOKENS_WANCHAIN 0
#define NUM_TOKENS_KUSD 0
#define NUM_TOKENS_MUSICOIN 0
#define NUM_TOKENS_CALLISTO 0
#define NUM_TOKENS_ETHERGEM 0
#define NUM_TOKENS_ATHEIOS 0
#define NUM_TOKENS_GOCHAIN 0
#define NUM_TOKENS_MIX 0
#define NUM_TOKENS_REOSC 0
#define NUM_TOKENS_HPB 0
#define NUM_TOKENS_TOMOCHAIN 0
#define NUM_TOKENS_TOBALABA 0
#define NUM_TOKENS_DEXON 0
#define NUM_TOKENS_VOLTA 0
#define NUM_TOKENS_EWC 0
#define NUM_TOKENS_ARTIS_SIGMA1 0
#define NUM_TOKENS_ARTIS_TAU1 0
#define NUM_TOKENS_WEBCHAIN 0
#define NUM_TOKENS_THUNDERCORE 0
#define NUM_TOKENS_ETHERSOCIAL 0
#define NUM_TOKENS_ETHER1 0
#define NUM_TOKENS_PIRL 0
#define NUM_TOKENS_POA 0
#define NUM_TOKENS_RSK 0
#define NUM_TOKENS_UBIQ 6
#define NUM_TOKENS_EXPANSE 0
#define NUM_TOKENS_WANCHAIN 0
#define NUM_TOKENS_KUSD 0
#define NUM_TOKENS_MUSICOIN 0
#define NUM_TOKENS_CALLISTO 0
#define NUM_TOKENS_ETHERGEM 0
#define NUM_TOKENS_ATHEIOS 0
#define NUM_TOKENS_GOCHAIN 0
#define NUM_TOKENS_MIX 0
#define NUM_TOKENS_REOSC 0
#define NUM_TOKENS_HPB 0
#define NUM_TOKENS_TOMOCHAIN 0
#define NUM_TOKENS_TOBALABA 0
#define NUM_TOKENS_DEXON 0
#define NUM_TOKENS_VOLTA 0
#define NUM_TOKENS_EWC 0
#define NUM_TOKENS_ARTIS_SIGMA1 0
#define NUM_TOKENS_ARTIS_TAU1 0
#define NUM_TOKENS_WEBCHAIN 0
#define NUM_TOKENS_THUNDERCORE 0
extern tokenDefinition_t const TOKENS_AKROMA[NUM_TOKENS_AKROMA];
extern tokenDefinition_t const TOKENS_ELLAISM[NUM_TOKENS_ELLAISM];

View File

@@ -17,7 +17,6 @@ unsigned int io_seproxyhal_touch_eth2_address_ok(const bagl_element_t *e);
void ui_idle(void);
void io_seproxyhal_send_status(uint32_t sw);
void format_signature_out(const uint8_t* signature);
void format_signature_out(const uint8_t *signature);
void finalizeParsing(bool direct);
tokenDefinition_t* getKnownToken(uint8_t *contractAddress);
tokenDefinition_t *getKnownToken(uint8_t *contractAddress);

View File

@@ -6,6 +6,7 @@ void switch_settings_contract_data(void);
void switch_settings_display_data(void);
//////////////////////////////////////////////////////////////////////
// clang-format off
UX_STEP_NOCB(
ux_idle_flow_1_step,
nn, //pnn,
@@ -37,16 +38,18 @@ UX_STEP_CB(
&C_icon_dashboard_x,
"Quit",
});
// clang-format on
UX_FLOW(ux_idle_flow,
&ux_idle_flow_1_step,
&ux_idle_flow_2_step,
&ux_idle_flow_3_step,
&ux_idle_flow_4_step,
FLOW_LOOP
);
&ux_idle_flow_1_step,
&ux_idle_flow_2_step,
&ux_idle_flow_3_step,
&ux_idle_flow_4_step,
FLOW_LOOP);
#if defined(TARGET_NANOS)
// clang-format off
UX_STEP_CB(
ux_settings_flow_1_step,
bnnn_paging,
@@ -99,28 +102,28 @@ UX_STEP_CB(
&C_icon_back_x,
"Back",
});
// clang-format on
UX_FLOW(ux_settings_flow,
&ux_settings_flow_1_step,
&ux_settings_flow_2_step,
&ux_settings_flow_3_step
);
&ux_settings_flow_1_step,
&ux_settings_flow_2_step,
&ux_settings_flow_3_step);
void display_settings() {
strcpy(strings.common.fullAddress, (N_storage.dataAllowed ? "Allowed" : "NOT Allowed"));
strcpy(strings.common.fullAddress + 20, (N_storage.contractDetails ? "Displayed" : "NOT Displayed"));
ux_flow_init(0, ux_settings_flow, NULL);
strcpy(strings.common.fullAddress, (N_storage.dataAllowed ? "Allowed" : "NOT Allowed"));
strcpy(strings.common.fullAddress + 20,
(N_storage.contractDetails ? "Displayed" : "NOT Displayed"));
ux_flow_init(0, ux_settings_flow, NULL);
}
void switch_settings_contract_data() {
uint8_t value = (N_storage.dataAllowed ? 0 : 1);
nvm_write((void*)&N_storage.dataAllowed, (void*)&value, sizeof(uint8_t));
display_settings();
uint8_t value = (N_storage.dataAllowed ? 0 : 1);
nvm_write((void*) &N_storage.dataAllowed, (void*) &value, sizeof(uint8_t));
display_settings();
}
void switch_settings_display_data() {
uint8_t value = (N_storage.contractDetails ? 0 : 1);
nvm_write((void*)&N_storage.contractDetails, (void*)&value, sizeof(uint8_t));
display_settings();
uint8_t value = (N_storage.contractDetails ? 0 : 1);
nvm_write((void*) &N_storage.contractDetails, (void*) &value, sizeof(uint8_t));
display_settings();
}

View File

@@ -2,55 +2,54 @@
#include "os_io_seproxyhal.h"
extern const ux_flow_step_t * const ux_idle_flow [];
extern const ux_flow_step_t* const ux_idle_flow[];
extern const ux_flow_step_t * const ux_settings_flow [];
extern const ux_flow_step_t* const ux_settings_flow[];
extern const ux_flow_step_t * const ux_display_public_flow [];
extern const ux_flow_step_t* const ux_display_public_flow[];
extern const ux_flow_step_t * const ux_confirm_selector_flow [];
extern const ux_flow_step_t* const ux_confirm_selector_flow[];
extern const ux_flow_step_t * const ux_confirm_parameter_flow [];
extern const ux_flow_step_t* const ux_confirm_parameter_flow[];
extern const ux_flow_step_t * const ux_approval_tx_flow [];
extern const ux_flow_step_t* const ux_approval_tx_flow[];
extern const ux_flow_step_t * const ux_approval_tx_data_warning_flow [];
extern const ux_flow_step_t* const ux_approval_tx_data_warning_flow[];
extern const ux_flow_step_t * const ux_approval_allowance_flow [];
extern const ux_flow_step_t* const ux_approval_allowance_flow[];
extern const ux_flow_step_t * const ux_sign_flow [];
extern const ux_flow_step_t* const ux_sign_flow[];
extern const ux_flow_step_t * const ux_sign_712_v0_flow [];
extern const ux_flow_step_t* const ux_sign_712_v0_flow[];
extern const ux_flow_step_t * const ux_display_public_eth2_flow [];
extern const ux_flow_step_t* const ux_display_public_eth2_flow[];
#ifdef HAVE_STARKWARE
extern const ux_flow_step_t * const ux_display_stark_public_flow [];
extern const ux_flow_step_t* const ux_display_stark_public_flow[];
extern const ux_flow_step_t * const ux_stark_limit_order_flow [];
extern const ux_flow_step_t* const ux_stark_limit_order_flow[];
extern const ux_flow_step_t * const ux_stark_transfer_flow [];
extern const ux_flow_step_t* const ux_stark_transfer_flow[];
extern const ux_flow_step_t * const ux_stark_self_transfer_flow [];
extern const ux_flow_step_t* const ux_stark_self_transfer_flow[];
extern const ux_flow_step_t * const ux_stark_transfer_conditional_flow [];
extern const ux_flow_step_t* const ux_stark_transfer_conditional_flow[];
extern const ux_flow_step_t * const ux_stark_self_transfer_conditional_flow [];
extern const ux_flow_step_t* const ux_stark_self_transfer_conditional_flow[];
extern const ux_flow_step_t * const ux_approval_starkware_register_flow [];
extern const ux_flow_step_t* const ux_approval_starkware_register_flow[];
extern const ux_flow_step_t * const ux_approval_starkware_deposit_flow [];
extern const ux_flow_step_t* const ux_approval_starkware_deposit_flow[];
extern const ux_flow_step_t * const ux_approval_starkware_withdraw_flow [];
extern const ux_flow_step_t* const ux_approval_starkware_withdraw_flow[];
extern const ux_flow_step_t * const ux_approval_starkware_verify_vault_id_flow [];
extern const ux_flow_step_t* const ux_approval_starkware_verify_vault_id_flow[];
extern const ux_flow_step_t * const ux_approval_starkware_escape_flow [];
extern const ux_flow_step_t* const ux_approval_starkware_escape_flow[];
extern const ux_flow_step_t * const ux_approval_starkware_verify_escape_flow [];
extern const ux_flow_step_t* const ux_approval_starkware_verify_escape_flow[];
extern const ux_flow_step_t * const ux_stark_unsafe_sign_flow [];
extern const ux_flow_step_t* const ux_stark_unsafe_sign_flow[];
#endif

View File

@@ -1,19 +1,19 @@
/*******************************************************************************
* Ledger Ethereum App
* (c) 2016-2019 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.
********************************************************************************/
* Ledger Ethereum App
* (c) 2016-2019 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 <stdint.h>
#include <string.h>
@@ -23,16 +23,16 @@
#include "uint256.h"
#include "tokens.h"
static const unsigned char hex_digits[] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
static const unsigned char hex_digits[] =
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
void array_hexstr(char *strbuf, const void *bin, unsigned int len) {
while (len--) {
*strbuf++ = hex_digits[((*((char *)bin)) >> 4) & 0xF];
*strbuf++ = hex_digits[(*((char *)bin)) & 0xF];
bin = (const void *)((unsigned int)bin + 1);
*strbuf++ = hex_digits[((*((char *) bin)) >> 4) & 0xF];
*strbuf++ = hex_digits[(*((char *) bin)) & 0xF];
bin = (const void *) ((unsigned int) bin + 1);
}
*strbuf = 0; // EOS
*strbuf = 0; // EOS
}
void convertUint256BE(uint8_t *data, uint32_t length, uint256_t *target) {
@@ -45,7 +45,7 @@ void convertUint256BE(uint8_t *data, uint32_t length, uint256_t *target) {
int local_strchr(char *string, char ch) {
unsigned int length = strlen(string);
unsigned int i;
for (i=0; i<length; i++) {
for (i = 0; i < length; i++) {
if (string[i] == ch) {
return i;
}
@@ -56,30 +56,27 @@ int local_strchr(char *string, char ch) {
uint32_t getV(txContent_t *txContent) {
uint32_t v = 0;
if (txContent->vLength == 1) {
v = txContent->v[0];
}
else
if (txContent->vLength == 2) {
v = (txContent->v[0] << 8) | txContent->v[1];
}
else
if (txContent->vLength == 3) {
v = (txContent->v[0] << 16) | (txContent->v[1] << 8) | txContent->v[2];
}
else
if (txContent->vLength == 4) {
v = (txContent->v[0] << 24) | (txContent->v[1] << 16) |
(txContent->v[2] << 8) | txContent->v[3];
}
else
if (txContent->vLength != 0) {
v = txContent->v[0];
} else if (txContent->vLength == 2) {
v = (txContent->v[0] << 8) | txContent->v[1];
} else if (txContent->vLength == 3) {
v = (txContent->v[0] << 16) | (txContent->v[1] << 8) | txContent->v[2];
} else if (txContent->vLength == 4) {
v = (txContent->v[0] << 24) | (txContent->v[1] << 16) | (txContent->v[2] << 8) |
txContent->v[3];
} else if (txContent->vLength != 0) {
PRINTF("Unexpected v format\n");
THROW(EXCEPTION);
}
return v;
}
void amountToString(uint8_t* amount, uint8_t amount_size, uint8_t decimals, char* ticker, char* out_buffer, uint8_t out_buffer_size){
void amountToString(uint8_t *amount,
uint8_t amount_size,
uint8_t decimals,
char *ticker,
char *out_buffer,
uint8_t out_buffer_size) {
uint256_t amount_256;
char tmp_buffer[100];
convertUint256BE(amount, amount_size, &amount_256);
@@ -90,25 +87,29 @@ void amountToString(uint8_t* amount, uint8_t amount_size, uint8_t decimals, char
memcpy(out_buffer, ticker, MIN(out_buffer_size, ticker_len));
adjustDecimals(tmp_buffer, amount_len, out_buffer + ticker_len, out_buffer_size - ticker_len -1, decimals);
out_buffer[out_buffer_size-1] = '\0';
adjustDecimals(tmp_buffer,
amount_len,
out_buffer + ticker_len,
out_buffer_size - ticker_len - 1,
decimals);
out_buffer[out_buffer_size - 1] = '\0';
}
bool parse_swap_config(uint8_t* config, uint8_t config_len, char* ticker, uint8_t* decimals){
bool parse_swap_config(uint8_t *config, uint8_t config_len, char *ticker, uint8_t *decimals) {
uint8_t ticker_len, offset = 0;
if (config_len == 0){
if (config_len == 0) {
return false;
}
ticker_len = config[offset++];
if(ticker_len == 0 || ticker_len > MAX_TICKER_LEN - 2 || config_len - offset < ticker_len){
if (ticker_len == 0 || ticker_len > MAX_TICKER_LEN - 2 || config_len - offset < ticker_len) {
return false;
}
memcpy(ticker, config+offset, ticker_len);
memcpy(ticker, config + offset, ticker_len);
offset += ticker_len;
ticker[ticker_len] = ' ';
ticker[ticker_len+1] = '\0';
ticker[ticker_len + 1] = '\0';
if(config_len - offset < 1){
if (config_len - offset < 1) {
return false;
}
*decimals = config[offset];

View File

@@ -1,19 +1,19 @@
/*******************************************************************************
* Ledger Ethereum App
* (c) 2016-2019 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.
********************************************************************************/
* Ledger Ethereum App
* (c) 2016-2019 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.
********************************************************************************/
#ifndef _UTILS_H_
#define _UTILS_H_
@@ -22,15 +22,20 @@
#include "uint256.h"
void array_hexstr(char *strbuf, const void *bin, unsigned int len);
void array_hexstr(char* strbuf, const void* bin, unsigned int len);
void convertUint256BE(uint8_t *data, uint32_t length, uint256_t *target);
void convertUint256BE(uint8_t* data, uint32_t length, uint256_t* target);
int local_strchr(char *string, char ch);
int local_strchr(char* string, char ch);
uint32_t getV(txContent_t *txContent);
uint32_t getV(txContent_t* txContent);
void amountToString(uint8_t* amount, uint8_t amount_len, uint8_t decimals, char* ticker, char* out_buffer, uint8_t out_buffer_size);
void amountToString(uint8_t* amount,
uint8_t amount_len,
uint8_t decimals,
char* ticker,
char* out_buffer,
uint8_t out_buffer_size);
bool parse_swap_config(uint8_t* config, uint8_t config_len, char* ticker, uint8_t* decimals);