Merge pull request #520 from LedgerHQ/fbe/redo_file_architecture_clean
Fbe/redo file architecture clean
This commit is contained in:
2
.github/workflows/sdk-generation.yml
vendored
2
.github/workflows/sdk-generation.yml
vendored
@@ -26,7 +26,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Build new SDK
|
||||
run: python tools/build_sdk.py
|
||||
run: ./tools/build_sdk.sh
|
||||
|
||||
- name: Extract branch name
|
||||
shell: bash
|
||||
|
||||
2
Makefile
2
Makefile
@@ -277,7 +277,7 @@ ifeq ($(CHAIN),ethereum)
|
||||
endif
|
||||
|
||||
# rebuild SDK
|
||||
$(shell python3 tools/build_sdk.py)
|
||||
$(shell ./tools/build_sdk.sh)
|
||||
|
||||
# check if a difference is noticed (fail if it happens in CI build)
|
||||
ifneq ($(shell git status | grep 'ethereum-plugin-sdk'),)
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "ethUstream.h"
|
||||
#include "ethUtils.h"
|
||||
#include "utils.h"
|
||||
#include "rlp_utils.h"
|
||||
#include "common_utils.h"
|
||||
|
||||
#define MAX_INT256 32
|
||||
#define MAX_ADDRESS 20
|
||||
@@ -15,14 +15,15 @@
|
||||
* limitations under the License.
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef _ETHUSTREAM_H_
|
||||
#define _ETHUSTREAM_H_
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "os.h"
|
||||
#include "cx.h"
|
||||
#include "common_utils.h"
|
||||
#include "tx_content.h"
|
||||
|
||||
struct txContext_t;
|
||||
|
||||
@@ -35,10 +36,7 @@ typedef enum customStatus_e {
|
||||
|
||||
typedef customStatus_e (*ustreamProcess_t)(struct txContext_t *context);
|
||||
|
||||
#define TX_FLAG_TYPE 0x01
|
||||
#define ADDRESS_LENGTH 20
|
||||
#define INT128_LENGTH 16
|
||||
#define INT256_LENGTH 32
|
||||
#define TX_FLAG_TYPE 0x01
|
||||
|
||||
// First variant of every Tx enum.
|
||||
#define RLP_NONE 0
|
||||
@@ -114,24 +112,6 @@ typedef enum parserStatus_e {
|
||||
USTREAM_CONTINUE // Used internally to signify we can keep on parsing
|
||||
} parserStatus_e;
|
||||
|
||||
typedef struct txInt256_t {
|
||||
uint8_t value[INT256_LENGTH];
|
||||
uint8_t length;
|
||||
} txInt256_t;
|
||||
|
||||
typedef struct txContent_t {
|
||||
txInt256_t gasprice; // Used as MaxFeePerGas when dealing with EIP1559 transactions.
|
||||
txInt256_t startgas; // Also known as `gasLimit`.
|
||||
txInt256_t value;
|
||||
txInt256_t nonce;
|
||||
txInt256_t chainID;
|
||||
uint8_t destination[ADDRESS_LENGTH];
|
||||
uint8_t destinationLength;
|
||||
uint8_t v[8];
|
||||
uint8_t vLength;
|
||||
bool dataPresent;
|
||||
} txContent_t;
|
||||
|
||||
typedef struct txContext_t {
|
||||
uint8_t currentField;
|
||||
cx_sha3_t *sha3;
|
||||
@@ -164,5 +144,3 @@ parserStatus_e processTx(txContext_t *context,
|
||||
parserStatus_e continueTx(txContext_t *context);
|
||||
void copyTxData(txContext_t *context, uint8_t *out, uint32_t length);
|
||||
uint8_t readTxByte(txContext_t *context);
|
||||
|
||||
#endif // _ETHUSTREAM_H_
|
||||
@@ -1,9 +1,9 @@
|
||||
#include <string.h>
|
||||
#include "eth_plugin_handler.h"
|
||||
#include "eth_plugin_internal.h"
|
||||
#include "plugin_utils.h"
|
||||
#include "shared_context.h"
|
||||
#include "network.h"
|
||||
#include "ethUtils.h"
|
||||
|
||||
void eth_plugin_prepare_init(ethPluginInitContract_t *init,
|
||||
const uint8_t *selector,
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#define NO_EXTRA_INFO(ctx, idx) \
|
||||
(allzeroes(&(ctx.transactionContext.extraInfo[idx]), sizeof(extraInfo_t)))
|
||||
|
||||
#define NO_NFT_METADATA (NO_EXTRA_INFO(tmpCtx, 1))
|
||||
|
||||
void eth_plugin_prepare_init(ethPluginInitContract_t *init,
|
||||
const uint8_t *selector,
|
||||
uint32_t dataSize);
|
||||
|
||||
@@ -1,39 +1,11 @@
|
||||
#include <string.h>
|
||||
#include "eth_plugin_internal.h"
|
||||
#include "ethUtils.h" // allzeroes
|
||||
#include "plugin_utils.h"
|
||||
|
||||
bool erc20_plugin_available_check(void);
|
||||
|
||||
void erc20_plugin_call(int message, void* parameters);
|
||||
|
||||
void copy_address(uint8_t* dst, const uint8_t* parameter, uint8_t dst_size) {
|
||||
uint8_t copy_size = MIN(dst_size, ADDRESS_LENGTH);
|
||||
memmove(dst, parameter + PARAMETER_LENGTH - copy_size, copy_size);
|
||||
}
|
||||
|
||||
void copy_parameter(uint8_t* dst, const uint8_t* parameter, uint8_t dst_size) {
|
||||
uint8_t copy_size = MIN(dst_size, PARAMETER_LENGTH);
|
||||
memmove(dst, parameter, copy_size);
|
||||
}
|
||||
|
||||
bool U2BE_from_parameter(const uint8_t* parameter, uint16_t* value) {
|
||||
if (allzeroes(parameter, PARAMETER_LENGTH - sizeof(uint16_t))) {
|
||||
*value = U2BE(parameter, PARAMETER_LENGTH - sizeof(uint16_t));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool U4BE_from_parameter(const uint8_t* parameter, uint32_t* value) {
|
||||
if (allzeroes(parameter, PARAMETER_LENGTH - sizeof(uint32_t))) {
|
||||
*value = U4BE(parameter, PARAMETER_LENGTH - sizeof(uint32_t));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef HAVE_STARKWARE
|
||||
void starkware_plugin_call(int message, void* parameters);
|
||||
#endif
|
||||
|
||||
@@ -1,25 +1,13 @@
|
||||
#ifndef _ETH_PLUGIN_INTERNAL_H_
|
||||
#define _ETH_PLUGIN_INTERNAL_H_
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "shared_context.h"
|
||||
#include "eth_plugin_interface.h"
|
||||
|
||||
#define SELECTOR_SIZE 4
|
||||
#define PARAMETER_LENGTH 32
|
||||
|
||||
void copy_address(uint8_t* dst, const uint8_t* parameter, uint8_t dst_size);
|
||||
|
||||
void copy_parameter(uint8_t* dst, const uint8_t* parameter, uint8_t dst_size);
|
||||
|
||||
void erc721_plugin_call(int message, void* parameters);
|
||||
void erc1155_plugin_call(int message, void* parameters);
|
||||
|
||||
// Get the value from the beginning of the parameter (right to left) and check if the rest of it is
|
||||
// zero
|
||||
bool U2BE_from_parameter(const uint8_t* parameter, uint16_t* value);
|
||||
bool U4BE_from_parameter(const uint8_t* parameter, uint32_t* value);
|
||||
|
||||
typedef bool (*PluginAvailableCheck)(void);
|
||||
typedef void (*PluginCall)(int, void*);
|
||||
|
||||
@@ -49,5 +37,3 @@ extern const uint8_t* const STARKWARE_SELECTORS[NUM_STARKWARE_SELECTORS];
|
||||
#endif
|
||||
|
||||
extern internalEthPlugin_t const INTERNAL_ETH_PLUGINS[];
|
||||
|
||||
#endif // _ETH_PLUGIN_INTERNAL_H_
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
#ifdef HAVE_TOKENS_EXTRA_LIST
|
||||
|
||||
#include "tokens.h"
|
||||
#include "extra_tokens.h"
|
||||
|
||||
const tokenDefinition_t TOKENS_EXTRA[NUM_TOKENS_EXTRA] = {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*****************************************************************************
|
||||
* Ledger Plugin SDK
|
||||
* (c) 2023 Ledger SAS
|
||||
/*******************************************************************************
|
||||
* 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.
|
||||
@@ -13,16 +13,14 @@
|
||||
* 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 "plugin_utils.h"
|
||||
#pragma once
|
||||
|
||||
bool find_selector(uint32_t selector, const uint32_t *array, size_t size, size_t *idx) {
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
if (selector == array[i]) {
|
||||
if (idx != NULL) *idx = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#ifdef HAVE_TOKENS_EXTRA_LIST
|
||||
|
||||
#define NUM_TOKENS_EXTRA 8
|
||||
|
||||
extern tokenDefinition_t const TOKENS_EXTRA[NUM_TOKENS_EXTRA];
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "handle_check_address.h"
|
||||
#include "os.h"
|
||||
#include "shared_context.h"
|
||||
#include "ethUtils.h"
|
||||
#include "string.h"
|
||||
|
||||
#define ZERO(x) explicit_bzero(&x, sizeof(x))
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#include "handle_get_printable_amount.h"
|
||||
#include "shared_context.h"
|
||||
#include "ethUtils.h"
|
||||
#include "utils.h"
|
||||
#include "uint256.h"
|
||||
#include "string.h"
|
||||
#include <stdint.h>
|
||||
#include <os.h>
|
||||
|
||||
#include "swap_utils.h"
|
||||
#include "handle_get_printable_amount.h"
|
||||
#include "shared_context.h"
|
||||
#include "common_utils.h"
|
||||
#include "uint256.h"
|
||||
#include "string.h"
|
||||
|
||||
void handle_get_printable_amount(get_printable_amount_parameters_t* params,
|
||||
chain_config_t* config) {
|
||||
uint8_t decimals;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#include "os_io_seproxyhal.h"
|
||||
#include "os.h"
|
||||
#include "ux.h"
|
||||
#include "swap_utils.h"
|
||||
#include "handle_swap_sign_transaction.h"
|
||||
#include "shared_context.h"
|
||||
#include "utils.h"
|
||||
#include "common_utils.h"
|
||||
#ifdef HAVE_NBGL
|
||||
#include "nbgl_use_case.h"
|
||||
#endif // HAVE_NBGL
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "os_io_seproxyhal.h"
|
||||
|
||||
#include "glyphs.h"
|
||||
#include "utils.h"
|
||||
#include "common_utils.h"
|
||||
|
||||
#include "swap_lib_calls.h"
|
||||
#include "handle_swap_sign_transaction.h"
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "os_utils.h"
|
||||
#include "os_pic.h"
|
||||
#include "network.h"
|
||||
#include "shared_context.h"
|
||||
#include "common_utils.h"
|
||||
|
||||
typedef struct network_info_s {
|
||||
const char *name;
|
||||
@@ -113,3 +115,32 @@ const char *get_network_ticker_from_chain_id(const uint64_t *chain_id) {
|
||||
bool chain_is_ethereum_compatible(const uint64_t *chain_id) {
|
||||
return get_network_from_chain_id(chain_id) != NULL;
|
||||
}
|
||||
|
||||
// Returns the chain ID. Defaults to 0 if txType was not found (For TX).
|
||||
uint64_t get_tx_chain_id(void) {
|
||||
uint64_t chain_id = 0;
|
||||
|
||||
switch (txContext.txType) {
|
||||
case LEGACY:
|
||||
chain_id = u64_from_BE(txContext.content->v, txContext.content->vLength);
|
||||
break;
|
||||
case EIP2930:
|
||||
case EIP1559:
|
||||
chain_id = u64_from_BE(tmpContent.txContent.chainID.value,
|
||||
tmpContent.txContent.chainID.length);
|
||||
break;
|
||||
default:
|
||||
PRINTF("Txtype `%d` not supported while generating chainID\n", txContext.txType);
|
||||
break;
|
||||
}
|
||||
return chain_id;
|
||||
}
|
||||
|
||||
const char *get_displayable_ticker(const uint64_t *chain_id) {
|
||||
const char *ticker = get_network_ticker_from_chain_id(chain_id);
|
||||
|
||||
if (ticker == NULL) {
|
||||
ticker = chainConfig->coinName;
|
||||
}
|
||||
return ticker;
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef _NETWORK_H_
|
||||
#define _NETWORK_H_
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
@@ -9,4 +8,6 @@ const char *get_network_ticker_from_chain_id(const uint64_t *chain_id);
|
||||
|
||||
bool chain_is_ethereum_compatible(const uint64_t *chain_id);
|
||||
|
||||
#endif // _NETWORK_H_
|
||||
uint64_t get_tx_chain_id(void);
|
||||
|
||||
const char *get_displayable_ticker(const uint64_t *chain_id);
|
||||
14
src/nft.h
14
src/nft.h
@@ -1,14 +0,0 @@
|
||||
#ifndef _NFT_H_
|
||||
#define _NFT_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define COLLECTION_NAME_MAX_LEN 70
|
||||
#define NO_NFT_METADATA (NO_EXTRA_INFO(tmpCtx, 1))
|
||||
|
||||
typedef struct nftInfo_t {
|
||||
uint8_t contractAddress[ADDRESS_LENGTH]; // must be first item
|
||||
char collectionName[COLLECTION_NAME_MAX_LEN + 1];
|
||||
} nftInfo_t;
|
||||
|
||||
#endif // _NFT_H_
|
||||
103
src/public_keys.h
Normal file
103
src/public_keys.h
Normal file
@@ -0,0 +1,103 @@
|
||||
/*******************************************************************************
|
||||
* 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.
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
static const uint8_t LEDGER_SIGNATURE_PUBLIC_KEY[] = {
|
||||
#if defined(HAVE_CAL_TEST_KEY)
|
||||
0x04, 0x4c, 0xca, 0x8f, 0xad, 0x49, 0x6a, 0xa5, 0x04, 0x0a, 0x00, 0xa7, 0xeb, 0x2f,
|
||||
0x5c, 0xc3, 0xb8, 0x53, 0x76, 0xd8, 0x8b, 0xa1, 0x47, 0xa7, 0xd7, 0x05, 0x4a, 0x99,
|
||||
0xc6, 0x40, 0x56, 0x18, 0x87, 0xfe, 0x17, 0xa0, 0x96, 0xe3, 0x6c, 0x3b, 0x52, 0x3b,
|
||||
0x24, 0x4f, 0x3e, 0x2f, 0xf7, 0xf8, 0x40, 0xae, 0x26, 0xc4, 0xe7, 0x7a, 0xd3, 0xbc,
|
||||
0x73, 0x9a, 0xf5, 0xde, 0x6f, 0x2d, 0x77, 0xa7, 0xb6
|
||||
#elif defined(HAVE_CAL_STAGING_KEY)
|
||||
// staging key 2019-01-11 03:07PM (erc20signer)
|
||||
0x04, 0x20, 0xda, 0x62, 0x00, 0x3c, 0x0c, 0xe0, 0x97, 0xe3, 0x36, 0x44, 0xa1, 0x0f,
|
||||
0xe4, 0xc3, 0x04, 0x54, 0x06, 0x9a, 0x44, 0x54, 0xf0, 0xfa, 0x9d, 0x4e, 0x84, 0xf4,
|
||||
0x50, 0x91, 0x42, 0x9b, 0x52, 0x20, 0xaf, 0x9e, 0x35, 0xc0, 0xb2, 0xd9, 0x28, 0x93,
|
||||
0x80, 0x13, 0x73, 0x07, 0xde, 0x4d, 0xd1, 0xd4, 0x18, 0x42, 0x8c, 0xf2, 0x1a, 0x93,
|
||||
0xb3, 0x35, 0x61, 0xbb, 0x09, 0xd8, 0x8f, 0xe5, 0x79
|
||||
#else
|
||||
// production key 2019-01-11 03:07PM (erc20signer)
|
||||
0x04, 0x5e, 0x6c, 0x10, 0x20, 0xc1, 0x4d, 0xc4, 0x64, 0x42, 0xfe, 0x89, 0xf9, 0x7c,
|
||||
0x0b, 0x68, 0xcd, 0xb1, 0x59, 0x76, 0xdc, 0x24, 0xf2, 0x4c, 0x31, 0x6e, 0x7b, 0x30,
|
||||
0xfe, 0x4e, 0x8c, 0xc7, 0x6b, 0x14, 0x89, 0x15, 0x0c, 0x21, 0x51, 0x4e, 0xbf, 0x44,
|
||||
0x0f, 0xf5, 0xde, 0xa5, 0x39, 0x3d, 0x83, 0xde, 0x53, 0x58, 0xcd, 0x09, 0x8f, 0xce,
|
||||
0x8f, 0xd0, 0xf8, 0x1d, 0xaa, 0x94, 0x97, 0x91, 0x83
|
||||
#endif
|
||||
};
|
||||
|
||||
static const uint8_t LEDGER_NFT_METADATA_PUBLIC_KEY[] = {
|
||||
#if defined(HAVE_NFT_TEST_KEY)
|
||||
0x04, 0x3c, 0xfb, 0x5f, 0xb3, 0x19, 0x05, 0xf4, 0xbd, 0x39, 0xd9, 0xd5, 0x35, 0xa4,
|
||||
0x0c, 0x26, 0xaa, 0xb5, 0x1c, 0x5d, 0x7d, 0x32, 0x19, 0xb2, 0x8a, 0xc9, 0x42, 0xb9,
|
||||
0x80, 0xfb, 0x20, 0x6c, 0xfb, 0x30, 0xb5, 0x1c, 0xc2, 0xde, 0x21, 0x19, 0xac, 0x03,
|
||||
0x8e, 0xbb, 0x0d, 0x7d, 0xd6, 0x54, 0x17, 0x70, 0x20, 0x4a, 0x3c, 0xed, 0x3a, 0x79,
|
||||
0xe2, 0x8b, 0x32, 0xfb, 0xb6, 0x72, 0x64, 0x68, 0xc0
|
||||
#elif defined(HAVE_NFT_STAGING_KEY)
|
||||
0x04, 0xf5, 0x70, 0x0c, 0xa1, 0xe8, 0x74, 0x24, 0xc7, 0xc7, 0xd1, 0x19, 0xe7, 0xe3,
|
||||
0xc1, 0x89, 0xb1, 0x62, 0x50, 0x94, 0xdb, 0x6e, 0xa0, 0x40, 0x87, 0xc8, 0x30, 0x00,
|
||||
0x7d, 0x0b, 0x46, 0x9a, 0x53, 0x11, 0xee, 0x6a, 0x1a, 0xcd, 0x1d, 0xa5, 0xaa, 0xb0,
|
||||
0xf5, 0xc6, 0xdf, 0x13, 0x15, 0x8d, 0x28, 0xcc, 0x12, 0xd1, 0xdd, 0xa6, 0xec, 0xe9,
|
||||
0x46, 0xb8, 0x9d, 0x5c, 0x05, 0x49, 0x92, 0x59, 0xc4
|
||||
#else // production key
|
||||
0x04, 0x98, 0x8d, 0xa6, 0xb2, 0x46, 0xf2, 0x8e, 0x77, 0xc1, 0xba, 0xb6, 0x75, 0xcb,
|
||||
0x2a, 0x27, 0x44, 0xf7, 0xf5, 0xce, 0xc5, 0x6a, 0xe6, 0xe0, 0x32, 0x23, 0x33, 0x7b,
|
||||
0x57, 0x94, 0xcd, 0x6a, 0xe0, 0x7d, 0x48, 0xb3, 0x0d, 0xb9, 0xcc, 0xb4, 0x0f, 0x5a,
|
||||
0x02, 0xa1, 0x1a, 0x3a, 0xb9, 0x9d, 0x5f, 0x59, 0x5a, 0x3d, 0x50, 0xa0, 0xe1, 0x30,
|
||||
0x23, 0xfd, 0x0d, 0x95, 0x87, 0x92, 0xd7, 0x97, 0x01
|
||||
#endif
|
||||
};
|
||||
|
||||
static const uint8_t DOMAIN_NAME_PUB_KEY[] = {
|
||||
#ifdef HAVE_DOMAIN_NAME_TEST_KEY
|
||||
0x04, 0xb9, 0x1f, 0xbe, 0xc1, 0x73, 0xe3, 0xba, 0x4a, 0x71, 0x4e, 0x01, 0x4e, 0xbc,
|
||||
0x82, 0x7b, 0x6f, 0x89, 0x9a, 0x9f, 0xa7, 0xf4, 0xac, 0x76, 0x9c, 0xde, 0x28, 0x43,
|
||||
0x17, 0xa0, 0x0f, 0x4f, 0x65, 0x0f, 0x09, 0xf0, 0x9a, 0xa4, 0xff, 0x5a, 0x31, 0x76,
|
||||
0x02, 0x55, 0xfe, 0x5d, 0xfc, 0x81, 0x13, 0x29, 0xb3, 0xb5, 0x0b, 0xe9, 0x91, 0x94,
|
||||
0xfc, 0xa1, 0x16, 0x19, 0xe6, 0x5f, 0x2e, 0xdf, 0xea
|
||||
#else
|
||||
0x04, 0x6a, 0x94, 0xe7, 0xa4, 0x2c, 0xd0, 0xc3, 0x3f, 0xdf, 0x44, 0x0c, 0x8e, 0x2a,
|
||||
0xb2, 0x54, 0x2c, 0xef, 0xbe, 0x5d, 0xb7, 0xaa, 0x0b, 0x93, 0xa9, 0xfc, 0x81, 0x4b,
|
||||
0x9a, 0xcf, 0xa7, 0x5e, 0xb4, 0xe5, 0x3d, 0x6f, 0x00, 0x25, 0x94, 0xbd, 0xb6, 0x05,
|
||||
0xd9, 0xb5, 0xbd, 0xa9, 0xfa, 0x4b, 0x4b, 0xf3, 0xa5, 0x49, 0x6f, 0xd3, 0x16, 0x4b,
|
||||
0xae, 0xf5, 0xaf, 0xcf, 0x90, 0xe8, 0x40, 0x88, 0x71
|
||||
#endif
|
||||
};
|
||||
|
||||
// Only used for signing NFT plugins (ERC721 and ERC1155)
|
||||
static const uint8_t LEDGER_NFT_SELECTOR_PUBLIC_KEY[] = {
|
||||
#if defined(HAVE_SET_PLUGIN_TEST_KEY)
|
||||
0x04, 0xc0, 0x55, 0xbc, 0x4e, 0xcf, 0x05, 0x5e, 0x2d, 0x85, 0x08, 0x5d, 0x35, 0x12,
|
||||
0x7a, 0x3d, 0xe6, 0x70, 0x5c, 0x7f, 0x88, 0x50, 0x55, 0xcd, 0x70, 0x71, 0xe8, 0x76,
|
||||
0x71, 0xbf, 0x19, 0x1f, 0xe3, 0x3c, 0xc8, 0xf0, 0x1a, 0xbc, 0x2f, 0x28, 0x7c, 0x81,
|
||||
0x9a, 0x14, 0x8a, 0xbe, 0x1b, 0x58, 0x1d, 0xf1, 0xb4, 0x94, 0x0a, 0xf5, 0xd4, 0xdc,
|
||||
0x3a, 0x4e, 0x6b, 0x60, 0x19, 0x17, 0x71, 0x2b, 0x37
|
||||
#elif defined(HAVE_NFT_STAGING_KEY)
|
||||
0x04, 0xf5, 0x70, 0x0c, 0xa1, 0xe8, 0x74, 0x24, 0xc7, 0xc7, 0xd1, 0x19, 0xe7, 0xe3,
|
||||
0xc1, 0x89, 0xb1, 0x62, 0x50, 0x94, 0xdb, 0x6e, 0xa0, 0x40, 0x87, 0xc8, 0x30, 0x00,
|
||||
0x7d, 0x0b, 0x46, 0x9a, 0x53, 0x11, 0xee, 0x6a, 0x1a, 0xcd, 0x1d, 0xa5, 0xaa, 0xb0,
|
||||
0xf5, 0xc6, 0xdf, 0x13, 0x15, 0x8d, 0x28, 0xcc, 0x12, 0xd1, 0xdd, 0xa6, 0xec, 0xe9,
|
||||
0x46, 0xb8, 0x9d, 0x5c, 0x05, 0x49, 0x92, 0x59, 0xc4
|
||||
#else
|
||||
0x04, 0xd8, 0x62, 0x6e, 0x01, 0x9e, 0x55, 0x3e, 0x19, 0x69, 0x56, 0xf1, 0x17, 0x4d,
|
||||
0xcd, 0xb8, 0x9a, 0x1c, 0xda, 0xc4, 0x93, 0x90, 0x08, 0xbc, 0x79, 0x77, 0x33, 0x6d,
|
||||
0x78, 0x24, 0xee, 0xe3, 0xa2, 0x62, 0x24, 0x1a, 0x62, 0x73, 0x52, 0x3b, 0x09, 0xb8,
|
||||
0xd0, 0xce, 0x0d, 0x39, 0xe8, 0x60, 0xc9, 0x4d, 0x02, 0x53, 0x58, 0xdb, 0xdc, 0x25,
|
||||
0x92, 0xc7, 0xc6, 0x48, 0x0d, 0x39, 0xce, 0xbb, 0xa3
|
||||
#endif
|
||||
};
|
||||
113
src/rlp_utils.c
Normal file
113
src/rlp_utils.c
Normal file
@@ -0,0 +1,113 @@
|
||||
/*******************************************************************************
|
||||
* 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.
|
||||
********************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief Utilities for an Ethereum Hardware Wallet logic
|
||||
* @file ethUtils.h
|
||||
* @author Ledger Firmware Team <hello@ledger.fr>
|
||||
* @version 1.0
|
||||
* @date 8th of March 2016
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "rlp_utils.h"
|
||||
|
||||
bool rlpCanDecode(uint8_t *buffer, uint32_t bufferLength, bool *valid) {
|
||||
if (*buffer <= 0x7f) {
|
||||
} else if (*buffer <= 0xb7) {
|
||||
} else if (*buffer <= 0xbf) {
|
||||
if (bufferLength < (1 + (*buffer - 0xb7))) {
|
||||
return false;
|
||||
}
|
||||
if (*buffer > 0xbb) {
|
||||
*valid = false; // arbitrary 32 bits length limitation
|
||||
return true;
|
||||
}
|
||||
} else if (*buffer <= 0xf7) {
|
||||
} else {
|
||||
if (bufferLength < (1 + (*buffer - 0xf7))) {
|
||||
return false;
|
||||
}
|
||||
if (*buffer > 0xfb) {
|
||||
*valid = false; // arbitrary 32 bits length limitation
|
||||
return true;
|
||||
}
|
||||
}
|
||||
*valid = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool rlpDecodeLength(uint8_t *buffer, uint32_t *fieldLength, uint32_t *offset, bool *list) {
|
||||
if (*buffer <= 0x7f) {
|
||||
*offset = 0;
|
||||
*fieldLength = 1;
|
||||
*list = false;
|
||||
} else if (*buffer <= 0xb7) {
|
||||
*offset = 1;
|
||||
*fieldLength = *buffer - 0x80;
|
||||
*list = false;
|
||||
} else if (*buffer <= 0xbf) {
|
||||
*offset = 1 + (*buffer - 0xb7);
|
||||
*list = false;
|
||||
switch (*buffer) {
|
||||
case 0xb8:
|
||||
*fieldLength = *(buffer + 1);
|
||||
break;
|
||||
case 0xb9:
|
||||
*fieldLength = (*(buffer + 1) << 8) + *(buffer + 2);
|
||||
break;
|
||||
case 0xba:
|
||||
*fieldLength = (*(buffer + 1) << 16) + (*(buffer + 2) << 8) + *(buffer + 3);
|
||||
break;
|
||||
case 0xbb:
|
||||
*fieldLength = (*(buffer + 1) << 24) + (*(buffer + 2) << 16) +
|
||||
(*(buffer + 3) << 8) + *(buffer + 4);
|
||||
break;
|
||||
default:
|
||||
return false; // arbitrary 32 bits length limitation
|
||||
}
|
||||
} else if (*buffer <= 0xf7) {
|
||||
*offset = 1;
|
||||
*fieldLength = *buffer - 0xc0;
|
||||
*list = true;
|
||||
} else {
|
||||
*offset = 1 + (*buffer - 0xf7);
|
||||
*list = true;
|
||||
switch (*buffer) {
|
||||
case 0xf8:
|
||||
*fieldLength = *(buffer + 1);
|
||||
break;
|
||||
case 0xf9:
|
||||
*fieldLength = (*(buffer + 1) << 8) + *(buffer + 2);
|
||||
break;
|
||||
case 0xfa:
|
||||
*fieldLength = (*(buffer + 1) << 16) + (*(buffer + 2) << 8) + *(buffer + 3);
|
||||
break;
|
||||
case 0xfb:
|
||||
*fieldLength = (*(buffer + 1) << 24) + (*(buffer + 2) << 16) +
|
||||
(*(buffer + 3) << 8) + *(buffer + 4);
|
||||
break;
|
||||
default:
|
||||
return false; // arbitrary 32 bits length limitation
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
37
src/rlp_utils.h
Normal file
37
src/rlp_utils.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*******************************************************************************
|
||||
* 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.
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief Decode an RLP encoded field - see
|
||||
* https://github.com/ethereum/wiki/wiki/RLP
|
||||
* @param [in] buffer buffer containing the RLP encoded field to decode
|
||||
* @param [out] fieldLength length of the RLP encoded field
|
||||
* @param [out] offset offset to the beginning of the RLP encoded field from the
|
||||
* buffer
|
||||
* @param [out] list true if the field encodes a list, false if it encodes a
|
||||
* string
|
||||
* @return true if the RLP header is consistent
|
||||
*/
|
||||
bool rlpDecodeLength(uint8_t *buffer, uint32_t *fieldLength, uint32_t *offset, bool *list);
|
||||
|
||||
bool rlpCanDecode(uint8_t *buffer, uint32_t bufferLength, bool *valid);
|
||||
@@ -3,18 +3,19 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "os.h"
|
||||
#include "cx.h"
|
||||
#include "ethUstream.h"
|
||||
#include "tokens.h"
|
||||
#include "tx_content.h"
|
||||
#include "chainConfig.h"
|
||||
#include "nft.h"
|
||||
#include "asset_info.h"
|
||||
#ifdef HAVE_NBGL
|
||||
#include "nbgl_types.h"
|
||||
#endif
|
||||
|
||||
#define MAX_BIP32_PATH 10
|
||||
|
||||
#define WEI_TO_ETHER 18
|
||||
|
||||
#define SELECTOR_LENGTH 4
|
||||
|
||||
#define PLUGIN_ID_LENGTH 30
|
||||
@@ -95,11 +96,6 @@ typedef struct publicKeyContext_t {
|
||||
bool getChaincode;
|
||||
} publicKeyContext_t;
|
||||
|
||||
typedef union extraInfo_t {
|
||||
tokenDefinition_t token;
|
||||
nftInfo_t nft;
|
||||
} extraInfo_t;
|
||||
|
||||
typedef struct transactionContext_t {
|
||||
bip32_path_t bip32;
|
||||
uint8_t hash[INT256_LENGTH];
|
||||
@@ -226,16 +222,6 @@ typedef enum {
|
||||
|
||||
extern pluginType_t pluginType;
|
||||
|
||||
typedef enum { CALLER_TYPE_CLONE, CALLER_TYPE_PLUGIN } e_caller_type;
|
||||
|
||||
typedef struct caller_app_t {
|
||||
const char *name;
|
||||
#ifdef HAVE_NBGL
|
||||
const nbgl_icon_details_t *icon;
|
||||
#endif
|
||||
char type; // does not have to be set by the caller app
|
||||
} caller_app_t;
|
||||
|
||||
extern uint8_t appState;
|
||||
#ifdef HAVE_STARKWARE
|
||||
extern bool quantumSet;
|
||||
@@ -244,8 +230,6 @@ extern bool quantumSet;
|
||||
extern uint32_t eth2WithdrawalIndex;
|
||||
#endif
|
||||
|
||||
extern caller_app_t *caller_app;
|
||||
|
||||
void reset_app_context(void);
|
||||
const uint8_t *parseBip32(const uint8_t *dataBuffer, uint8_t *dataLength, bip32_path_t *bip32);
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
#include "shared_context.h"
|
||||
#include "stark_utils.h"
|
||||
#include "utils.h"
|
||||
#include "ethUtils.h"
|
||||
#include "uint256.h"
|
||||
#include "common_utils.h"
|
||||
|
||||
extraInfo_t *getKnownToken(uint8_t *contractAddress);
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "stark_crypto.h"
|
||||
#include "shared_context.h"
|
||||
#include "ethUtils.h"
|
||||
#include "uint256.h"
|
||||
#include "uint_common.h"
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "chainConfig.h"
|
||||
#include "shared_context.h"
|
||||
#include "stdint.h"
|
||||
#include "caller_api.h"
|
||||
|
||||
#define RUN_APPLICATION 1
|
||||
|
||||
|
||||
43
src/swap_utils.c
Normal file
43
src/swap_utils.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/*******************************************************************************
|
||||
* 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>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "asset_info.h"
|
||||
#include "swap_utils.h"
|
||||
|
||||
bool parse_swap_config(const uint8_t *config, uint8_t config_len, char *ticker, uint8_t *decimals) {
|
||||
uint8_t ticker_len, offset = 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) {
|
||||
return false;
|
||||
}
|
||||
memcpy(ticker, config + offset, ticker_len);
|
||||
offset += ticker_len;
|
||||
ticker[ticker_len] = '\0';
|
||||
|
||||
if (config_len - offset < 1) {
|
||||
return false;
|
||||
}
|
||||
*decimals = config[offset];
|
||||
return true;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*****************************************************************************
|
||||
* Ledger Plugin SDK
|
||||
* (c) 2023 Ledger SAS
|
||||
/*******************************************************************************
|
||||
* 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.
|
||||
@@ -13,15 +13,10 @@
|
||||
* 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_
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
bool find_selector(uint32_t selector, const uint32_t *array, size_t size, size_t *idx);
|
||||
|
||||
#endif // UTILS_H_
|
||||
bool parse_swap_config(const uint8_t* config, uint8_t config_len, char* ticker, uint8_t* decimals);
|
||||
68
src/tokens.h
68
src/tokens.h
@@ -1,68 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* 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>
|
||||
#include "ethUstream.h"
|
||||
|
||||
#define MAX_TICKER_LEN 11 // 10 characters + '\0'
|
||||
#define MAX_ITEMS 2
|
||||
|
||||
typedef struct tokenDefinition_t {
|
||||
uint8_t address[ADDRESS_LENGTH]; // must be first item
|
||||
#ifdef HAVE_CONTRACT_NAME_IN_DESCRIPTOR
|
||||
uint8_t contractName[ADDRESS_LENGTH];
|
||||
#endif
|
||||
char ticker[MAX_TICKER_LEN];
|
||||
uint8_t decimals;
|
||||
} tokenDefinition_t;
|
||||
|
||||
#ifdef HAVE_TOKENS_EXTRA_LIST
|
||||
|
||||
#define NUM_TOKENS_EXTRA 8
|
||||
|
||||
extern tokenDefinition_t const TOKENS_EXTRA[NUM_TOKENS_EXTRA];
|
||||
|
||||
#endif
|
||||
|
||||
static const uint8_t LEDGER_SIGNATURE_PUBLIC_KEY[] = {
|
||||
#if defined(HAVE_CAL_TEST_KEY)
|
||||
0x04, 0x4c, 0xca, 0x8f, 0xad, 0x49, 0x6a, 0xa5, 0x04, 0x0a, 0x00, 0xa7, 0xeb, 0x2f,
|
||||
0x5c, 0xc3, 0xb8, 0x53, 0x76, 0xd8, 0x8b, 0xa1, 0x47, 0xa7, 0xd7, 0x05, 0x4a, 0x99,
|
||||
0xc6, 0x40, 0x56, 0x18, 0x87, 0xfe, 0x17, 0xa0, 0x96, 0xe3, 0x6c, 0x3b, 0x52, 0x3b,
|
||||
0x24, 0x4f, 0x3e, 0x2f, 0xf7, 0xf8, 0x40, 0xae, 0x26, 0xc4, 0xe7, 0x7a, 0xd3, 0xbc,
|
||||
0x73, 0x9a, 0xf5, 0xde, 0x6f, 0x2d, 0x77, 0xa7, 0xb6
|
||||
#elif defined(HAVE_CAL_STAGING_KEY)
|
||||
// staging key 2019-01-11 03:07PM (erc20signer)
|
||||
0x04, 0x20, 0xda, 0x62, 0x00, 0x3c, 0x0c, 0xe0, 0x97, 0xe3, 0x36, 0x44, 0xa1, 0x0f,
|
||||
0xe4, 0xc3, 0x04, 0x54, 0x06, 0x9a, 0x44, 0x54, 0xf0, 0xfa, 0x9d, 0x4e, 0x84, 0xf4,
|
||||
0x50, 0x91, 0x42, 0x9b, 0x52, 0x20, 0xaf, 0x9e, 0x35, 0xc0, 0xb2, 0xd9, 0x28, 0x93,
|
||||
0x80, 0x13, 0x73, 0x07, 0xde, 0x4d, 0xd1, 0xd4, 0x18, 0x42, 0x8c, 0xf2, 0x1a, 0x93,
|
||||
0xb3, 0x35, 0x61, 0xbb, 0x09, 0xd8, 0x8f, 0xe5, 0x79
|
||||
#else
|
||||
// production key 2019-01-11 03:07PM (erc20signer)
|
||||
0x04, 0x5e, 0x6c, 0x10, 0x20, 0xc1, 0x4d, 0xc4, 0x64, 0x42, 0xfe, 0x89, 0xf9, 0x7c,
|
||||
0x0b, 0x68, 0xcd, 0xb1, 0x59, 0x76, 0xdc, 0x24, 0xf2, 0x4c, 0x31, 0x6e, 0x7b, 0x30,
|
||||
0xfe, 0x4e, 0x8c, 0xc7, 0x6b, 0x14, 0x89, 0x15, 0x0c, 0x21, 0x51, 0x4e, 0xbf, 0x44,
|
||||
0x0f, 0xf5, 0xde, 0xa5, 0x39, 0x3d, 0x83, 0xde, 0x53, 0x58, 0xcd, 0x09, 0x8f, 0xce,
|
||||
0x8f, 0xd0, 0xf8, 0x1d, 0xaa, 0x94, 0x97, 0x91, 0x83
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // _TOKENS_H_
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <string.h>
|
||||
#include "uint128.h"
|
||||
#include "uint_common.h"
|
||||
#include "ethUtils.h" // HEXDIGITS
|
||||
#include "common_utils.h" // HEXDIGITS
|
||||
|
||||
void readu128BE(const uint8_t *const buffer, uint128_t *const target) {
|
||||
UPPER_P(target) = readUint64BE(buffer);
|
||||
@@ -290,3 +290,21 @@ bool tostring128_signed(const uint128_t *const number,
|
||||
}
|
||||
return tostring128(number, base, out, out_length); // positive value
|
||||
}
|
||||
|
||||
void convertUint64BEto128(const uint8_t *const data, uint32_t length, uint128_t *const target) {
|
||||
uint8_t tmp[INT128_LENGTH];
|
||||
int64_t value;
|
||||
|
||||
value = u64_from_BE(data, length);
|
||||
memset(tmp, ((value < 0) ? 0xff : 0), sizeof(tmp) - length);
|
||||
memmove(tmp + sizeof(tmp) - length, data, length);
|
||||
readu128BE(tmp, target);
|
||||
}
|
||||
|
||||
void convertUint128BE(const uint8_t *const data, uint32_t length, uint128_t *const target) {
|
||||
uint8_t tmp[INT128_LENGTH];
|
||||
|
||||
memset(tmp, 0, sizeof(tmp) - length);
|
||||
memmove(tmp + sizeof(tmp) - length, data, length);
|
||||
readu128BE(tmp, target);
|
||||
}
|
||||
@@ -56,5 +56,7 @@ bool tostring128_signed(const uint128_t *const number,
|
||||
uint32_t base,
|
||||
char *const out,
|
||||
uint32_t out_length);
|
||||
void convertUint64BEto128(const uint8_t *const data, uint32_t length, uint128_t *const target);
|
||||
void convertUint128BE(const uint8_t *const data, uint32_t length, uint128_t *const target);
|
||||
|
||||
#endif // _UINT128_H_
|
||||
@@ -21,8 +21,7 @@
|
||||
#include <string.h>
|
||||
#include "uint256.h"
|
||||
#include "uint_common.h"
|
||||
#include "ethUstream.h" // INT256_LENGTH
|
||||
#include "ethUtils.h" // HEXDIGITS
|
||||
#include "common_utils.h" // INT256_LENGTH
|
||||
|
||||
void readu256BE(const uint8_t *const buffer, uint256_t *const target) {
|
||||
readu128BE(buffer, &UPPER_P(target));
|
||||
@@ -290,3 +289,11 @@ bool tostring256_signed(const uint256_t *const number,
|
||||
}
|
||||
return tostring256(number, base, out, out_length); // positive value
|
||||
}
|
||||
|
||||
void convertUint256BE(const uint8_t *const data, uint32_t length, uint256_t *const target) {
|
||||
uint8_t tmp[INT256_LENGTH];
|
||||
|
||||
memset(tmp, 0, sizeof(tmp) - length);
|
||||
memmove(tmp + sizeof(tmp) - length, data, length);
|
||||
readu256BE(tmp, target);
|
||||
}
|
||||
@@ -57,5 +57,6 @@ bool tostring256_signed(const uint256_t *const number,
|
||||
uint32_t base,
|
||||
char *const out,
|
||||
uint32_t out_length);
|
||||
void convertUint256BE(const uint8_t *const data, uint32_t length, uint256_t *const target);
|
||||
|
||||
#endif // _UINT256_H_
|
||||
169
src/utils.c
169
src/utils.c
@@ -1,169 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* 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>
|
||||
|
||||
#include "ethUstream.h"
|
||||
#include "ethUtils.h"
|
||||
#include "uint128.h"
|
||||
#include "uint256.h"
|
||||
#include "tokens.h"
|
||||
#include "utils.h"
|
||||
|
||||
void array_hexstr(char *strbuf, const void *bin, unsigned int len) {
|
||||
while (len--) {
|
||||
*strbuf++ = HEXDIGITS[((*((char *) bin)) >> 4) & 0xF];
|
||||
*strbuf++ = HEXDIGITS[(*((char *) bin)) & 0xF];
|
||||
bin = (const void *) ((unsigned int) bin + 1);
|
||||
}
|
||||
*strbuf = 0; // EOS
|
||||
}
|
||||
|
||||
void convertUint64BEto128(const uint8_t *const data, uint32_t length, uint128_t *const target) {
|
||||
uint8_t tmp[INT128_LENGTH];
|
||||
int64_t value;
|
||||
|
||||
value = u64_from_BE(data, length);
|
||||
memset(tmp, ((value < 0) ? 0xff : 0), sizeof(tmp) - length);
|
||||
memmove(tmp + sizeof(tmp) - length, data, length);
|
||||
readu128BE(tmp, target);
|
||||
}
|
||||
|
||||
void convertUint128BE(const uint8_t *const data, uint32_t length, uint128_t *const target) {
|
||||
uint8_t tmp[INT128_LENGTH];
|
||||
|
||||
memset(tmp, 0, sizeof(tmp) - length);
|
||||
memmove(tmp + sizeof(tmp) - length, data, length);
|
||||
readu128BE(tmp, target);
|
||||
}
|
||||
|
||||
void convertUint256BE(const uint8_t *const data, uint32_t length, uint256_t *const target) {
|
||||
uint8_t tmp[INT256_LENGTH];
|
||||
|
||||
memset(tmp, 0, sizeof(tmp) - length);
|
||||
memmove(tmp + sizeof(tmp) - length, data, length);
|
||||
readu256BE(tmp, target);
|
||||
}
|
||||
|
||||
uint64_t u64_from_BE(const uint8_t *in, uint8_t size) {
|
||||
uint8_t i = 0;
|
||||
uint64_t res = 0;
|
||||
|
||||
while (i < size && i < sizeof(res)) {
|
||||
res <<= 8;
|
||||
res |= in[i];
|
||||
i++;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool uint256_to_decimal(const uint8_t *value, size_t value_len, char *out, size_t out_len) {
|
||||
if (value_len > INT256_LENGTH) {
|
||||
// value len is bigger than INT256_LENGTH ?!
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16_t n[16] = {0};
|
||||
// Copy and right-align the number
|
||||
memcpy((uint8_t *) n + INT256_LENGTH - value_len, value, value_len);
|
||||
|
||||
// Special case when value is 0
|
||||
if (allzeroes(n, INT256_LENGTH)) {
|
||||
if (out_len < 2) {
|
||||
// Not enough space to hold "0" and \0.
|
||||
return false;
|
||||
}
|
||||
strlcpy(out, "0", out_len);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint16_t *p = n;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
n[i] = __builtin_bswap16(*p++);
|
||||
}
|
||||
int pos = out_len;
|
||||
while (!allzeroes(n, sizeof(n))) {
|
||||
if (pos == 0) {
|
||||
return false;
|
||||
}
|
||||
pos -= 1;
|
||||
unsigned int carry = 0;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
int rem = ((carry << 16) | n[i]) % 10;
|
||||
n[i] = ((carry << 16) | n[i]) / 10;
|
||||
carry = rem;
|
||||
}
|
||||
out[pos] = '0' + carry;
|
||||
}
|
||||
memmove(out, out + pos, out_len - pos);
|
||||
out[out_len - pos] = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool amountToString(const uint8_t *amount,
|
||||
uint8_t amount_size,
|
||||
uint8_t decimals,
|
||||
const char *ticker,
|
||||
char *out_buffer,
|
||||
size_t out_buffer_size) {
|
||||
char tmp_buffer[100] = {0};
|
||||
|
||||
if (uint256_to_decimal(amount, amount_size, tmp_buffer, sizeof(tmp_buffer)) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t amount_len = strnlen(tmp_buffer, sizeof(tmp_buffer));
|
||||
uint8_t ticker_len = strnlen(ticker, MAX_TICKER_LEN);
|
||||
|
||||
memcpy(out_buffer, ticker, MIN(out_buffer_size, ticker_len));
|
||||
if (ticker_len > 0) {
|
||||
out_buffer[ticker_len++] = ' ';
|
||||
}
|
||||
|
||||
if (adjustDecimals(tmp_buffer,
|
||||
amount_len,
|
||||
out_buffer + ticker_len,
|
||||
out_buffer_size - ticker_len - 1,
|
||||
decimals) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
out_buffer[out_buffer_size - 1] = '\0';
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parse_swap_config(const uint8_t *config, uint8_t config_len, char *ticker, uint8_t *decimals) {
|
||||
uint8_t ticker_len, offset = 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) {
|
||||
return false;
|
||||
}
|
||||
memcpy(ticker, config + offset, ticker_len);
|
||||
offset += ticker_len;
|
||||
ticker[ticker_len] = '\0';
|
||||
|
||||
if (config_len - offset < 1) {
|
||||
return false;
|
||||
}
|
||||
*decimals = config[offset];
|
||||
return true;
|
||||
}
|
||||
46
src/utils.h
46
src/utils.h
@@ -1,46 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* 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_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "uint256.h"
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
||||
void array_hexstr(char* strbuf, const void* bin, unsigned int len);
|
||||
|
||||
void convertUint128BE(const uint8_t* const data, uint32_t length, uint128_t* const target);
|
||||
void convertUint256BE(const uint8_t* const data, uint32_t length, uint256_t* const target);
|
||||
void convertUint64BEto128(const uint8_t* const data, uint32_t length, uint128_t* const target);
|
||||
|
||||
uint64_t u64_from_BE(const uint8_t* in, uint8_t size);
|
||||
|
||||
bool uint256_to_decimal(const uint8_t* value, size_t value_len, char* out, size_t out_len);
|
||||
|
||||
bool amountToString(const uint8_t* amount,
|
||||
uint8_t amount_len,
|
||||
uint8_t decimals,
|
||||
const char* ticker,
|
||||
char* out_buffer,
|
||||
size_t out_buffer_size);
|
||||
|
||||
bool parse_swap_config(const uint8_t* config, uint8_t config_len, char* ticker, uint8_t* decimals);
|
||||
|
||||
#endif // _UTILS_H_
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "shared_context.h"
|
||||
#include "ui_callbacks.h"
|
||||
#include "common_ui.h"
|
||||
#include "utils.h"
|
||||
#include "common_utils.h"
|
||||
|
||||
#define ENABLED_STR "Enabled"
|
||||
#define DISABLED_STR "Disabled"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "shared_context.h"
|
||||
#include "ui_callbacks.h"
|
||||
#include "common_712.h"
|
||||
#include "ethUtils.h"
|
||||
|
||||
void prepare_domain_hash_v0() {
|
||||
snprintf(strings.tmp.tmp,
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#include "shared_context.h"
|
||||
#include "ui_callbacks.h"
|
||||
#include "chainConfig.h"
|
||||
#include "utils.h"
|
||||
#include "common_utils.h"
|
||||
#include "feature_signTx.h"
|
||||
#include "network.h"
|
||||
#include "eth_plugin_handler.h"
|
||||
#include "ui_plugin.h"
|
||||
#include "common_ui.h"
|
||||
#include "ethUtils.h"
|
||||
#include "plugins.h"
|
||||
#include "domain_name.h"
|
||||
#include "ui_domain_name.h"
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "shared_context.h"
|
||||
#include "ui_callbacks.h"
|
||||
#include "ethUtils.h"
|
||||
#include "starkDisplayUtils.h"
|
||||
#include "apdu_constants.h"
|
||||
|
||||
|
||||
51
src_common/asset_info.h
Normal file
51
src_common/asset_info.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*******************************************************************************
|
||||
* 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.
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "common_utils.h"
|
||||
|
||||
// NFT
|
||||
|
||||
#define COLLECTION_NAME_MAX_LEN 70
|
||||
|
||||
typedef struct nftInfo_t {
|
||||
uint8_t contractAddress[ADDRESS_LENGTH]; // must be first item
|
||||
char collectionName[COLLECTION_NAME_MAX_LEN + 1];
|
||||
} nftInfo_t;
|
||||
|
||||
// TOKENS
|
||||
|
||||
#define MAX_TICKER_LEN 11 // 10 characters + '\0'
|
||||
#define MAX_ITEMS 2
|
||||
|
||||
typedef struct tokenDefinition_t {
|
||||
uint8_t address[ADDRESS_LENGTH]; // must be first item
|
||||
#ifdef HAVE_CONTRACT_NAME_IN_DESCRIPTOR
|
||||
uint8_t contractName[ADDRESS_LENGTH];
|
||||
#endif
|
||||
char ticker[MAX_TICKER_LEN];
|
||||
uint8_t decimals;
|
||||
} tokenDefinition_t;
|
||||
|
||||
// UNION
|
||||
|
||||
typedef union extraInfo_t {
|
||||
tokenDefinition_t token;
|
||||
nftInfo_t nft;
|
||||
} extraInfo_t;
|
||||
34
src_common/caller_api.h
Normal file
34
src_common/caller_api.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*******************************************************************************
|
||||
* 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.
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef HAVE_NBGL
|
||||
#include "ux.h"
|
||||
#endif
|
||||
|
||||
typedef enum { CALLER_TYPE_CLONE, CALLER_TYPE_PLUGIN } e_caller_type;
|
||||
|
||||
typedef struct caller_app_t {
|
||||
const char *name;
|
||||
#ifdef HAVE_NBGL
|
||||
const nbgl_icon_details_t *icon;
|
||||
#endif
|
||||
char type; // does not have to be set by the caller app
|
||||
} caller_app_t;
|
||||
|
||||
extern caller_app_t *caller_app;
|
||||
@@ -15,105 +15,202 @@
|
||||
* limitations under the License.
|
||||
********************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief Utilities for an Ethereum Hardware Wallet logic
|
||||
* @file ethUtils.h
|
||||
* @author Ledger Firmware Team <hello@ledger.fr>
|
||||
* @version 1.0
|
||||
* @date 8th of March 2016
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "shared_context.h"
|
||||
#include "utils.h"
|
||||
#include "ethUtils.h"
|
||||
#include "chainConfig.h"
|
||||
#include "ethUstream.h"
|
||||
#include "network.h"
|
||||
#include "asset_info.h"
|
||||
#include "common_utils.h"
|
||||
|
||||
bool rlpCanDecode(uint8_t *buffer, uint32_t bufferLength, bool *valid) {
|
||||
if (*buffer <= 0x7f) {
|
||||
} else if (*buffer <= 0xb7) {
|
||||
} else if (*buffer <= 0xbf) {
|
||||
if (bufferLength < (1 + (*buffer - 0xb7))) {
|
||||
return false;
|
||||
}
|
||||
if (*buffer > 0xbb) {
|
||||
*valid = false; // arbitrary 32 bits length limitation
|
||||
return true;
|
||||
}
|
||||
} else if (*buffer <= 0xf7) {
|
||||
} else {
|
||||
if (bufferLength < (1 + (*buffer - 0xf7))) {
|
||||
return false;
|
||||
}
|
||||
if (*buffer > 0xfb) {
|
||||
*valid = false; // arbitrary 32 bits length limitation
|
||||
return true;
|
||||
}
|
||||
void array_hexstr(char *strbuf, const void *bin, unsigned int len) {
|
||||
while (len--) {
|
||||
*strbuf++ = HEXDIGITS[((*((char *) bin)) >> 4) & 0xF];
|
||||
*strbuf++ = HEXDIGITS[(*((char *) bin)) & 0xF];
|
||||
bin = (const void *) ((unsigned int) bin + 1);
|
||||
}
|
||||
*strbuf = 0; // EOS
|
||||
}
|
||||
|
||||
uint64_t u64_from_BE(const uint8_t *in, uint8_t size) {
|
||||
uint8_t i = 0;
|
||||
uint64_t res = 0;
|
||||
|
||||
while (i < size && i < sizeof(res)) {
|
||||
res <<= 8;
|
||||
res |= in[i];
|
||||
i++;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool u64_to_string(uint64_t src, char *dst, uint8_t dst_size) {
|
||||
// Copy the numbers in ASCII format.
|
||||
uint8_t i = 0;
|
||||
do {
|
||||
// Checking `i + 1` to make sure we have enough space for '\0'.
|
||||
if (i + 1 >= dst_size) {
|
||||
return false;
|
||||
}
|
||||
dst[i] = src % 10 + '0';
|
||||
src /= 10;
|
||||
i++;
|
||||
} while (src);
|
||||
|
||||
// Null terminate string
|
||||
dst[i] = '\0';
|
||||
|
||||
// Revert the string
|
||||
i--;
|
||||
uint8_t j = 0;
|
||||
while (j < i) {
|
||||
char tmp = dst[i];
|
||||
dst[i] = dst[j];
|
||||
dst[j] = tmp;
|
||||
i--;
|
||||
j++;
|
||||
}
|
||||
*valid = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool rlpDecodeLength(uint8_t *buffer, uint32_t *fieldLength, uint32_t *offset, bool *list) {
|
||||
if (*buffer <= 0x7f) {
|
||||
*offset = 0;
|
||||
*fieldLength = 1;
|
||||
*list = false;
|
||||
} else if (*buffer <= 0xb7) {
|
||||
*offset = 1;
|
||||
*fieldLength = *buffer - 0x80;
|
||||
*list = false;
|
||||
} else if (*buffer <= 0xbf) {
|
||||
*offset = 1 + (*buffer - 0xb7);
|
||||
*list = false;
|
||||
switch (*buffer) {
|
||||
case 0xb8:
|
||||
*fieldLength = *(buffer + 1);
|
||||
break;
|
||||
case 0xb9:
|
||||
*fieldLength = (*(buffer + 1) << 8) + *(buffer + 2);
|
||||
break;
|
||||
case 0xba:
|
||||
*fieldLength = (*(buffer + 1) << 16) + (*(buffer + 2) << 8) + *(buffer + 3);
|
||||
break;
|
||||
case 0xbb:
|
||||
*fieldLength = (*(buffer + 1) << 24) + (*(buffer + 2) << 16) +
|
||||
(*(buffer + 3) << 8) + *(buffer + 4);
|
||||
break;
|
||||
default:
|
||||
return false; // arbitrary 32 bits length limitation
|
||||
}
|
||||
} else if (*buffer <= 0xf7) {
|
||||
*offset = 1;
|
||||
*fieldLength = *buffer - 0xc0;
|
||||
*list = true;
|
||||
} else {
|
||||
*offset = 1 + (*buffer - 0xf7);
|
||||
*list = true;
|
||||
switch (*buffer) {
|
||||
case 0xf8:
|
||||
*fieldLength = *(buffer + 1);
|
||||
break;
|
||||
case 0xf9:
|
||||
*fieldLength = (*(buffer + 1) << 8) + *(buffer + 2);
|
||||
break;
|
||||
case 0xfa:
|
||||
*fieldLength = (*(buffer + 1) << 16) + (*(buffer + 2) << 8) + *(buffer + 3);
|
||||
break;
|
||||
case 0xfb:
|
||||
*fieldLength = (*(buffer + 1) << 24) + (*(buffer + 2) << 16) +
|
||||
(*(buffer + 3) << 8) + *(buffer + 4);
|
||||
break;
|
||||
default:
|
||||
return false; // arbitrary 32 bits length limitation
|
||||
}
|
||||
bool uint256_to_decimal(const uint8_t *value, size_t value_len, char *out, size_t out_len) {
|
||||
if (value_len > INT256_LENGTH) {
|
||||
// value len is bigger than INT256_LENGTH ?!
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16_t n[16] = {0};
|
||||
// Copy and right-align the number
|
||||
memcpy((uint8_t *) n + INT256_LENGTH - value_len, value, value_len);
|
||||
|
||||
// Special case when value is 0
|
||||
if (allzeroes(n, INT256_LENGTH)) {
|
||||
if (out_len < 2) {
|
||||
// Not enough space to hold "0" and \0.
|
||||
return false;
|
||||
}
|
||||
strlcpy(out, "0", out_len);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint16_t *p = n;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
n[i] = __builtin_bswap16(*p++);
|
||||
}
|
||||
int pos = out_len;
|
||||
while (!allzeroes(n, sizeof(n))) {
|
||||
if (pos == 0) {
|
||||
return false;
|
||||
}
|
||||
pos -= 1;
|
||||
unsigned int carry = 0;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
int rem = ((carry << 16) | n[i]) % 10;
|
||||
n[i] = ((carry << 16) | n[i]) / 10;
|
||||
carry = rem;
|
||||
}
|
||||
out[pos] = '0' + carry;
|
||||
}
|
||||
memmove(out, out + pos, out_len - pos);
|
||||
out[out_len - pos] = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool adjustDecimals(const char *src,
|
||||
size_t srcLength,
|
||||
char *target,
|
||||
size_t targetLength,
|
||||
uint8_t decimals) {
|
||||
uint32_t startOffset;
|
||||
uint32_t lastZeroOffset = 0;
|
||||
uint32_t offset = 0;
|
||||
if ((srcLength == 1) && (*src == '0')) {
|
||||
if (targetLength < 2) {
|
||||
return false;
|
||||
}
|
||||
target[0] = '0';
|
||||
target[1] = '\0';
|
||||
return true;
|
||||
}
|
||||
if (srcLength <= decimals) {
|
||||
uint32_t delta = decimals - srcLength;
|
||||
if (targetLength < srcLength + 1 + 2 + delta) {
|
||||
return false;
|
||||
}
|
||||
target[offset++] = '0';
|
||||
target[offset++] = '.';
|
||||
for (uint32_t i = 0; i < delta; i++) {
|
||||
target[offset++] = '0';
|
||||
}
|
||||
startOffset = offset;
|
||||
for (uint32_t i = 0; i < srcLength; i++) {
|
||||
target[offset++] = src[i];
|
||||
}
|
||||
target[offset] = '\0';
|
||||
} else {
|
||||
uint32_t sourceOffset = 0;
|
||||
uint32_t delta = srcLength - decimals;
|
||||
if (targetLength < srcLength + 1 + 1) {
|
||||
return false;
|
||||
}
|
||||
while (offset < delta) {
|
||||
target[offset++] = src[sourceOffset++];
|
||||
}
|
||||
if (decimals != 0) {
|
||||
target[offset++] = '.';
|
||||
}
|
||||
startOffset = offset;
|
||||
while (sourceOffset < srcLength) {
|
||||
target[offset++] = src[sourceOffset++];
|
||||
}
|
||||
target[offset] = '\0';
|
||||
}
|
||||
for (uint32_t i = startOffset; i < offset; i++) {
|
||||
if (target[i] == '0') {
|
||||
if (lastZeroOffset == 0) {
|
||||
lastZeroOffset = i;
|
||||
}
|
||||
} else {
|
||||
lastZeroOffset = 0;
|
||||
}
|
||||
}
|
||||
if (lastZeroOffset != 0) {
|
||||
target[lastZeroOffset] = '\0';
|
||||
if (target[lastZeroOffset - 1] == '.') {
|
||||
target[lastZeroOffset - 1] = '\0';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool amountToString(const uint8_t *amount,
|
||||
uint8_t amount_size,
|
||||
uint8_t decimals,
|
||||
const char *ticker,
|
||||
char *out_buffer,
|
||||
size_t out_buffer_size) {
|
||||
char tmp_buffer[100] = {0};
|
||||
|
||||
if (uint256_to_decimal(amount, amount_size, tmp_buffer, sizeof(tmp_buffer)) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t amount_len = strnlen(tmp_buffer, sizeof(tmp_buffer));
|
||||
uint8_t ticker_len = strnlen(ticker, MAX_TICKER_LEN);
|
||||
|
||||
memcpy(out_buffer, ticker, MIN(out_buffer_size, ticker_len));
|
||||
if (ticker_len > 0) {
|
||||
out_buffer[ticker_len++] = ' ';
|
||||
}
|
||||
|
||||
if (adjustDecimals(tmp_buffer,
|
||||
amount_len,
|
||||
out_buffer + ticker_len,
|
||||
out_buffer_size - ticker_len - 1,
|
||||
decimals) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
out_buffer[out_buffer_size - 1] = '\0';
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -163,35 +260,6 @@ bool getEthAddressStringFromKey(cx_ecfp_public_key_t *publicKey,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool u64_to_string(uint64_t src, char *dst, uint8_t dst_size) {
|
||||
// Copy the numbers in ASCII format.
|
||||
uint8_t i = 0;
|
||||
do {
|
||||
// Checking `i + 1` to make sure we have enough space for '\0'.
|
||||
if (i + 1 >= dst_size) {
|
||||
return false;
|
||||
}
|
||||
dst[i] = src % 10 + '0';
|
||||
src /= 10;
|
||||
i++;
|
||||
} while (src);
|
||||
|
||||
// Null terminate string
|
||||
dst[i] = '\0';
|
||||
|
||||
// Revert the string
|
||||
i--;
|
||||
uint8_t j = 0;
|
||||
while (j < i) {
|
||||
char tmp = dst[i];
|
||||
dst[i] = dst[j];
|
||||
dst[j] = tmp;
|
||||
i--;
|
||||
j++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool getEthAddressStringFromBinary(uint8_t *address,
|
||||
char *out,
|
||||
cx_sha3_t *sha3Context,
|
||||
@@ -281,99 +349,3 @@ bool getEthDisplayableAddress(uint8_t *in,
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool adjustDecimals(const char *src,
|
||||
size_t srcLength,
|
||||
char *target,
|
||||
size_t targetLength,
|
||||
uint8_t decimals) {
|
||||
uint32_t startOffset;
|
||||
uint32_t lastZeroOffset = 0;
|
||||
uint32_t offset = 0;
|
||||
if ((srcLength == 1) && (*src == '0')) {
|
||||
if (targetLength < 2) {
|
||||
return false;
|
||||
}
|
||||
target[0] = '0';
|
||||
target[1] = '\0';
|
||||
return true;
|
||||
}
|
||||
if (srcLength <= decimals) {
|
||||
uint32_t delta = decimals - srcLength;
|
||||
if (targetLength < srcLength + 1 + 2 + delta) {
|
||||
return false;
|
||||
}
|
||||
target[offset++] = '0';
|
||||
target[offset++] = '.';
|
||||
for (uint32_t i = 0; i < delta; i++) {
|
||||
target[offset++] = '0';
|
||||
}
|
||||
startOffset = offset;
|
||||
for (uint32_t i = 0; i < srcLength; i++) {
|
||||
target[offset++] = src[i];
|
||||
}
|
||||
target[offset] = '\0';
|
||||
} else {
|
||||
uint32_t sourceOffset = 0;
|
||||
uint32_t delta = srcLength - decimals;
|
||||
if (targetLength < srcLength + 1 + 1) {
|
||||
return false;
|
||||
}
|
||||
while (offset < delta) {
|
||||
target[offset++] = src[sourceOffset++];
|
||||
}
|
||||
if (decimals != 0) {
|
||||
target[offset++] = '.';
|
||||
}
|
||||
startOffset = offset;
|
||||
while (sourceOffset < srcLength) {
|
||||
target[offset++] = src[sourceOffset++];
|
||||
}
|
||||
target[offset] = '\0';
|
||||
}
|
||||
for (uint32_t i = startOffset; i < offset; i++) {
|
||||
if (target[i] == '0') {
|
||||
if (lastZeroOffset == 0) {
|
||||
lastZeroOffset = i;
|
||||
}
|
||||
} else {
|
||||
lastZeroOffset = 0;
|
||||
}
|
||||
}
|
||||
if (lastZeroOffset != 0) {
|
||||
target[lastZeroOffset] = '\0';
|
||||
if (target[lastZeroOffset - 1] == '.') {
|
||||
target[lastZeroOffset - 1] = '\0';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Returns the chain ID. Defaults to 0 if txType was not found (For TX).
|
||||
uint64_t get_tx_chain_id(void) {
|
||||
uint64_t chain_id = 0;
|
||||
|
||||
switch (txContext.txType) {
|
||||
case LEGACY:
|
||||
chain_id = u64_from_BE(txContext.content->v, txContext.content->vLength);
|
||||
break;
|
||||
case EIP2930:
|
||||
case EIP1559:
|
||||
chain_id = u64_from_BE(tmpContent.txContent.chainID.value,
|
||||
tmpContent.txContent.chainID.length);
|
||||
break;
|
||||
default:
|
||||
PRINTF("Txtype `%d` not supported while generating chainID\n", txContext.txType);
|
||||
break;
|
||||
}
|
||||
return chain_id;
|
||||
}
|
||||
|
||||
const char *get_displayable_ticker(const uint64_t *chain_id) {
|
||||
const char *ticker = get_network_ticker_from_chain_id(chain_id);
|
||||
|
||||
if (ticker == NULL) {
|
||||
ticker = chainConfig->coinName;
|
||||
}
|
||||
return ticker;
|
||||
}
|
||||
@@ -15,30 +15,46 @@
|
||||
* limitations under the License.
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef _ETHUTILS_H_
|
||||
#define _ETHUTILS_H_
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "os.h"
|
||||
#include "cx.h"
|
||||
#include "chainConfig.h"
|
||||
|
||||
#define WEI_TO_ETHER 18
|
||||
|
||||
#define ADDRESS_LENGTH 20
|
||||
#define INT128_LENGTH 16
|
||||
#define INT256_LENGTH 32
|
||||
|
||||
#define KECCAK256_HASH_BYTESIZE 32
|
||||
|
||||
/**
|
||||
* @brief Decode an RLP encoded field - see
|
||||
* https://github.com/ethereum/wiki/wiki/RLP
|
||||
* @param [in] buffer buffer containing the RLP encoded field to decode
|
||||
* @param [out] fieldLength length of the RLP encoded field
|
||||
* @param [out] offset offset to the beginning of the RLP encoded field from the
|
||||
* buffer
|
||||
* @param [out] list true if the field encodes a list, false if it encodes a
|
||||
* string
|
||||
* @return true if the RLP header is consistent
|
||||
*/
|
||||
bool rlpDecodeLength(uint8_t *buffer, uint32_t *fieldLength, uint32_t *offset, bool *list);
|
||||
static const char HEXDIGITS[] = "0123456789abcdef";
|
||||
|
||||
bool rlpCanDecode(uint8_t *buffer, uint32_t bufferLength, bool *valid);
|
||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
||||
void array_hexstr(char *strbuf, const void *bin, unsigned int len);
|
||||
|
||||
uint64_t u64_from_BE(const uint8_t *in, uint8_t size);
|
||||
|
||||
bool u64_to_string(uint64_t src, char *dst, uint8_t dst_size);
|
||||
|
||||
bool uint256_to_decimal(const uint8_t *value, size_t value_len, char *out, size_t out_len);
|
||||
|
||||
bool amountToString(const uint8_t *amount,
|
||||
uint8_t amount_len,
|
||||
uint8_t decimals,
|
||||
const char *ticker,
|
||||
char *out_buffer,
|
||||
size_t out_buffer_size);
|
||||
|
||||
bool adjustDecimals(const char *src,
|
||||
size_t srcLength,
|
||||
char *target,
|
||||
size_t targetLength,
|
||||
uint8_t decimals);
|
||||
|
||||
bool getEthAddressFromKey(cx_ecfp_public_key_t *publicKey, uint8_t *out, cx_sha3_t *sha3Context);
|
||||
|
||||
@@ -47,8 +63,6 @@ bool getEthAddressStringFromKey(cx_ecfp_public_key_t *publicKey,
|
||||
cx_sha3_t *sha3Context,
|
||||
uint64_t chainId);
|
||||
|
||||
bool u64_to_string(uint64_t src, char *dst, uint8_t dst_size);
|
||||
|
||||
bool getEthAddressStringFromBinary(uint8_t *address,
|
||||
char *out,
|
||||
cx_sha3_t *sha3Context,
|
||||
@@ -60,12 +74,6 @@ bool getEthDisplayableAddress(uint8_t *in,
|
||||
cx_sha3_t *sha3,
|
||||
uint64_t chainId);
|
||||
|
||||
bool adjustDecimals(const char *src,
|
||||
size_t srcLength,
|
||||
char *target,
|
||||
size_t targetLength,
|
||||
uint8_t decimals);
|
||||
|
||||
static __attribute__((no_instrument_function)) inline int allzeroes(const void *buf, size_t n) {
|
||||
uint8_t *p = (uint8_t *) buf;
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
@@ -83,11 +91,3 @@ static __attribute__((no_instrument_function)) inline int ismaxint(uint8_t *buf,
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint64_t get_tx_chain_id(void);
|
||||
|
||||
const char *get_displayable_ticker(const uint64_t *chain_id);
|
||||
|
||||
static const char HEXDIGITS[] = "0123456789abcdef";
|
||||
|
||||
#endif // _ETHUTILS_H_
|
||||
@@ -1,13 +1,16 @@
|
||||
// clang-format off
|
||||
|
||||
#ifndef _ETH_PLUGIN_INTERFACE_H_
|
||||
#define _ETH_PLUGIN_INTERFACE_H_
|
||||
#pragma once
|
||||
|
||||
#include "os.h"
|
||||
#include "cx.h"
|
||||
#include "ethUstream.h"
|
||||
#include "tokens.h"
|
||||
#include "shared_context.h"
|
||||
|
||||
// Include other header compatible with plugins
|
||||
#include "asset_info.h"
|
||||
#include "caller_api.h"
|
||||
#include "common_utils.h"
|
||||
#include "plugin_utils.h"
|
||||
#include "tx_content.h"
|
||||
|
||||
/*************************************************************************************************
|
||||
* Comments provided in this file are quick reminders on the usage of the plugin interface *
|
||||
@@ -218,6 +221,4 @@ typedef struct ethQueryContractUI_s {
|
||||
} ethQueryContractUI_t;
|
||||
// void handle_query_contract_ui(ethQueryContractUI_t *parameters);
|
||||
|
||||
#endif // _ETH_PLUGIN_INTERFACE_H_
|
||||
|
||||
// clang-format on
|
||||
42
src_common/plugin_utils.c
Normal file
42
src_common/plugin_utils.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "common_utils.h"
|
||||
#include "plugin_utils.h"
|
||||
|
||||
void copy_address(uint8_t* dst, const uint8_t* parameter, uint8_t dst_size) {
|
||||
uint8_t copy_size = MIN(dst_size, ADDRESS_LENGTH);
|
||||
memmove(dst, parameter + PARAMETER_LENGTH - copy_size, copy_size);
|
||||
}
|
||||
|
||||
void copy_parameter(uint8_t* dst, const uint8_t* parameter, uint8_t dst_size) {
|
||||
uint8_t copy_size = MIN(dst_size, PARAMETER_LENGTH);
|
||||
memmove(dst, parameter, copy_size);
|
||||
}
|
||||
|
||||
bool U2BE_from_parameter(const uint8_t* parameter, uint16_t* value) {
|
||||
if (allzeroes(parameter, PARAMETER_LENGTH - sizeof(uint16_t))) {
|
||||
*value = U2BE(parameter, PARAMETER_LENGTH - sizeof(uint16_t));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool U4BE_from_parameter(const uint8_t* parameter, uint32_t* value) {
|
||||
if (allzeroes(parameter, PARAMETER_LENGTH - sizeof(uint32_t))) {
|
||||
*value = U4BE(parameter, PARAMETER_LENGTH - sizeof(uint32_t));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool find_selector(uint32_t selector, const uint32_t* array, size_t size, size_t* idx) {
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
if (selector == array[i]) {
|
||||
if (idx != NULL) *idx = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
37
src_common/plugin_utils.h
Normal file
37
src_common/plugin_utils.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*****************************************************************************
|
||||
* Ledger
|
||||
* (c) 2023 Ledger SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "eth_plugin_interface.h"
|
||||
|
||||
#define SELECTOR_SIZE 4
|
||||
#define PARAMETER_LENGTH 32
|
||||
|
||||
void copy_address(uint8_t* dst, const uint8_t* parameter, uint8_t dst_size);
|
||||
|
||||
void copy_parameter(uint8_t* dst, const uint8_t* parameter, uint8_t dst_size);
|
||||
|
||||
// Get the value from the beginning of the parameter (right to left) and check if the rest of it is
|
||||
// zero
|
||||
bool U2BE_from_parameter(const uint8_t* parameter, uint16_t* value);
|
||||
bool U4BE_from_parameter(const uint8_t* parameter, uint32_t* value);
|
||||
|
||||
bool find_selector(uint32_t selector, const uint32_t* array, size_t size, size_t* idx);
|
||||
43
src_common/tx_content.h
Normal file
43
src_common/tx_content.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*******************************************************************************
|
||||
* 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.
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "os.h"
|
||||
#include "cx.h"
|
||||
#include "common_utils.h"
|
||||
|
||||
typedef struct txInt256_t {
|
||||
uint8_t value[INT256_LENGTH];
|
||||
uint8_t length;
|
||||
} txInt256_t;
|
||||
|
||||
typedef struct txContent_t {
|
||||
txInt256_t gasprice; // Used as MaxFeePerGas when dealing with EIP1559 transactions.
|
||||
txInt256_t startgas; // Also known as `gasLimit`.
|
||||
txInt256_t value;
|
||||
txInt256_t nonce;
|
||||
txInt256_t chainID;
|
||||
uint8_t destination[ADDRESS_LENGTH];
|
||||
uint8_t destinationLength;
|
||||
uint8_t v[8];
|
||||
uint8_t vLength;
|
||||
bool dataPresent;
|
||||
} txContent_t;
|
||||
@@ -1,8 +1,7 @@
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "utils.h"
|
||||
#include "common_utils.h"
|
||||
#include "feature_getPublicKey.h"
|
||||
#include "ethUtils.h"
|
||||
#include "common_ui.h"
|
||||
#include "os_io_seproxyhal.h"
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "ethUtils.h"
|
||||
|
||||
#include "feature_performPrivacyOperation.h"
|
||||
#include "common_ui.h"
|
||||
|
||||
@@ -4,29 +4,14 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "utils.h" // ARRAY_SIZE
|
||||
#include "common_utils.h" // ARRAY_SIZE
|
||||
#include "apdu_constants.h"
|
||||
#include "domain_name.h"
|
||||
#include "challenge.h"
|
||||
#include "mem.h"
|
||||
#include "hash_bytes.h"
|
||||
#include "network.h"
|
||||
|
||||
static const uint8_t DOMAIN_NAME_PUB_KEY[] = {
|
||||
#ifdef HAVE_DOMAIN_NAME_TEST_KEY
|
||||
0x04, 0xb9, 0x1f, 0xbe, 0xc1, 0x73, 0xe3, 0xba, 0x4a, 0x71, 0x4e, 0x01, 0x4e, 0xbc,
|
||||
0x82, 0x7b, 0x6f, 0x89, 0x9a, 0x9f, 0xa7, 0xf4, 0xac, 0x76, 0x9c, 0xde, 0x28, 0x43,
|
||||
0x17, 0xa0, 0x0f, 0x4f, 0x65, 0x0f, 0x09, 0xf0, 0x9a, 0xa4, 0xff, 0x5a, 0x31, 0x76,
|
||||
0x02, 0x55, 0xfe, 0x5d, 0xfc, 0x81, 0x13, 0x29, 0xb3, 0xb5, 0x0b, 0xe9, 0x91, 0x94,
|
||||
0xfc, 0xa1, 0x16, 0x19, 0xe6, 0x5f, 0x2e, 0xdf, 0xea
|
||||
#else
|
||||
0x04, 0x6a, 0x94, 0xe7, 0xa4, 0x2c, 0xd0, 0xc3, 0x3f, 0xdf, 0x44, 0x0c, 0x8e, 0x2a,
|
||||
0xb2, 0x54, 0x2c, 0xef, 0xbe, 0x5d, 0xb7, 0xaa, 0x0b, 0x93, 0xa9, 0xfc, 0x81, 0x4b,
|
||||
0x9a, 0xcf, 0xa7, 0x5e, 0xb4, 0xe5, 0x3d, 0x6f, 0x00, 0x25, 0x94, 0xbd, 0xb6, 0x05,
|
||||
0xd9, 0xb5, 0xbd, 0xa9, 0xfa, 0x4b, 0x4b, 0xf3, 0xa5, 0x49, 0x6f, 0xd3, 0x16, 0x4b,
|
||||
0xae, 0xf5, 0xaf, 0xcf, 0x90, 0xe8, 0x40, 0x88, 0x71
|
||||
#endif
|
||||
};
|
||||
#include "public_keys.h"
|
||||
|
||||
#define P1_FIRST_CHUNK 0x01
|
||||
#define P1_FOLLOWING_CHUNK 0x00
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "tokens.h"
|
||||
#include "public_keys.h"
|
||||
#include "common_ui.h"
|
||||
#include "os_io_seproxyhal.h"
|
||||
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "tokens.h"
|
||||
#include "utils.h"
|
||||
#include "asset_info.h"
|
||||
#include "common_utils.h"
|
||||
#include "common_ui.h"
|
||||
#include "os_io_seproxyhal.h"
|
||||
#include "network.h"
|
||||
#include "public_keys.h"
|
||||
|
||||
#define TYPE_SIZE 1
|
||||
#define VERSION_SIZE 1
|
||||
@@ -28,28 +30,6 @@
|
||||
|
||||
#define VERSION_1 1
|
||||
|
||||
static const uint8_t LEDGER_NFT_METADATA_PUBLIC_KEY[] = {
|
||||
#if defined(HAVE_NFT_TEST_KEY)
|
||||
0x04, 0x3c, 0xfb, 0x5f, 0xb3, 0x19, 0x05, 0xf4, 0xbd, 0x39, 0xd9, 0xd5, 0x35, 0xa4,
|
||||
0x0c, 0x26, 0xaa, 0xb5, 0x1c, 0x5d, 0x7d, 0x32, 0x19, 0xb2, 0x8a, 0xc9, 0x42, 0xb9,
|
||||
0x80, 0xfb, 0x20, 0x6c, 0xfb, 0x30, 0xb5, 0x1c, 0xc2, 0xde, 0x21, 0x19, 0xac, 0x03,
|
||||
0x8e, 0xbb, 0x0d, 0x7d, 0xd6, 0x54, 0x17, 0x70, 0x20, 0x4a, 0x3c, 0xed, 0x3a, 0x79,
|
||||
0xe2, 0x8b, 0x32, 0xfb, 0xb6, 0x72, 0x64, 0x68, 0xc0
|
||||
#elif defined(HAVE_NFT_STAGING_KEY)
|
||||
0x04, 0xf5, 0x70, 0x0c, 0xa1, 0xe8, 0x74, 0x24, 0xc7, 0xc7, 0xd1, 0x19, 0xe7, 0xe3,
|
||||
0xc1, 0x89, 0xb1, 0x62, 0x50, 0x94, 0xdb, 0x6e, 0xa0, 0x40, 0x87, 0xc8, 0x30, 0x00,
|
||||
0x7d, 0x0b, 0x46, 0x9a, 0x53, 0x11, 0xee, 0x6a, 0x1a, 0xcd, 0x1d, 0xa5, 0xaa, 0xb0,
|
||||
0xf5, 0xc6, 0xdf, 0x13, 0x15, 0x8d, 0x28, 0xcc, 0x12, 0xd1, 0xdd, 0xa6, 0xec, 0xe9,
|
||||
0x46, 0xb8, 0x9d, 0x5c, 0x05, 0x49, 0x92, 0x59, 0xc4
|
||||
#else // production key
|
||||
0x04, 0x98, 0x8d, 0xa6, 0xb2, 0x46, 0xf2, 0x8e, 0x77, 0xc1, 0xba, 0xb6, 0x75, 0xcb,
|
||||
0x2a, 0x27, 0x44, 0xf7, 0xf5, 0xce, 0xc5, 0x6a, 0xe6, 0xe0, 0x32, 0x23, 0x33, 0x7b,
|
||||
0x57, 0x94, 0xcd, 0x6a, 0xe0, 0x7d, 0x48, 0xb3, 0x0d, 0xb9, 0xcc, 0xb4, 0x0f, 0x5a,
|
||||
0x02, 0xa1, 0x1a, 0x3a, 0xb9, 0x9d, 0x5f, 0x59, 0x5a, 0x3d, 0x50, 0xa0, 0xe1, 0x30,
|
||||
0x23, 0xfd, 0x0d, 0x95, 0x87, 0x92, 0xd7, 0x97, 0x01
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef bool verificationAlgo(const cx_ecfp_public_key_t *,
|
||||
int,
|
||||
cx_md_t,
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "tokens.h"
|
||||
#include "public_keys.h"
|
||||
#include "eth_plugin_interface.h"
|
||||
#include "eth_plugin_internal.h"
|
||||
#include "plugin_utils.h"
|
||||
#include "common_ui.h"
|
||||
#include "os_io_seproxyhal.h"
|
||||
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "tokens.h"
|
||||
#include "asset_info.h"
|
||||
#include "eth_plugin_interface.h"
|
||||
#include "eth_plugin_internal.h"
|
||||
#include "utils.h"
|
||||
#include "plugin_utils.h"
|
||||
#include "common_utils.h"
|
||||
#include "common_ui.h"
|
||||
#include "os_io_seproxyhal.h"
|
||||
#include "network.h"
|
||||
#include "public_keys.h"
|
||||
|
||||
// Supported internal plugins
|
||||
#define ERC721_STR "ERC721"
|
||||
@@ -44,29 +47,6 @@ typedef enum AlgorithmID {
|
||||
ECC_SECG_P256K1__ECDSA_SHA_256 = 0x01,
|
||||
} AlgorithmID;
|
||||
|
||||
// Only used for signing NFT plugins (ERC721 and ERC1155)
|
||||
static const uint8_t LEDGER_NFT_SELECTOR_PUBLIC_KEY[] = {
|
||||
#if defined(HAVE_SET_PLUGIN_TEST_KEY)
|
||||
0x04, 0xc0, 0x55, 0xbc, 0x4e, 0xcf, 0x05, 0x5e, 0x2d, 0x85, 0x08, 0x5d, 0x35, 0x12,
|
||||
0x7a, 0x3d, 0xe6, 0x70, 0x5c, 0x7f, 0x88, 0x50, 0x55, 0xcd, 0x70, 0x71, 0xe8, 0x76,
|
||||
0x71, 0xbf, 0x19, 0x1f, 0xe3, 0x3c, 0xc8, 0xf0, 0x1a, 0xbc, 0x2f, 0x28, 0x7c, 0x81,
|
||||
0x9a, 0x14, 0x8a, 0xbe, 0x1b, 0x58, 0x1d, 0xf1, 0xb4, 0x94, 0x0a, 0xf5, 0xd4, 0xdc,
|
||||
0x3a, 0x4e, 0x6b, 0x60, 0x19, 0x17, 0x71, 0x2b, 0x37
|
||||
#elif defined(HAVE_NFT_STAGING_KEY)
|
||||
0x04, 0xf5, 0x70, 0x0c, 0xa1, 0xe8, 0x74, 0x24, 0xc7, 0xc7, 0xd1, 0x19, 0xe7, 0xe3,
|
||||
0xc1, 0x89, 0xb1, 0x62, 0x50, 0x94, 0xdb, 0x6e, 0xa0, 0x40, 0x87, 0xc8, 0x30, 0x00,
|
||||
0x7d, 0x0b, 0x46, 0x9a, 0x53, 0x11, 0xee, 0x6a, 0x1a, 0xcd, 0x1d, 0xa5, 0xaa, 0xb0,
|
||||
0xf5, 0xc6, 0xdf, 0x13, 0x15, 0x8d, 0x28, 0xcc, 0x12, 0xd1, 0xdd, 0xa6, 0xec, 0xe9,
|
||||
0x46, 0xb8, 0x9d, 0x5c, 0x05, 0x49, 0x92, 0x59, 0xc4
|
||||
#else
|
||||
0x04, 0xd8, 0x62, 0x6e, 0x01, 0x9e, 0x55, 0x3e, 0x19, 0x69, 0x56, 0xf1, 0x17, 0x4d,
|
||||
0xcd, 0xb8, 0x9a, 0x1c, 0xda, 0xc4, 0x93, 0x90, 0x08, 0xbc, 0x79, 0x77, 0x33, 0x6d,
|
||||
0x78, 0x24, 0xee, 0xe3, 0xa2, 0x62, 0x24, 0x1a, 0x62, 0x73, 0x52, 0x3b, 0x09, 0xb8,
|
||||
0xd0, 0xce, 0x0d, 0x39, 0xe8, 0x60, 0xc9, 0x4d, 0x02, 0x53, 0x58, 0xdb, 0xdc, 0x25,
|
||||
0x92, 0xc7, 0xc6, 0x48, 0x0d, 0x39, 0xce, 0xbb, 0xa3
|
||||
#endif
|
||||
};
|
||||
|
||||
// Verification function used to verify the signature
|
||||
typedef bool verificationAlgo(const cx_ecfp_public_key_t *,
|
||||
int,
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include "schema_hash.h"
|
||||
#include "filtering.h"
|
||||
#include "common_712.h"
|
||||
#include "ethUtils.h" // allzeroes
|
||||
#include "common_ui.h" // ui_idle
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,9 +8,8 @@
|
||||
#include "mem_utils.h"
|
||||
#include "shared_context.h"
|
||||
#include "ui_logic.h"
|
||||
#include "ethUtils.h" // KECCAK256_HASH_BYTESIZE
|
||||
#include "context_712.h" // contract_addr
|
||||
#include "utils.h" // u64_from_BE
|
||||
#include "common_utils.h" // u64_from_BE
|
||||
#include "apdu_constants.h" // APDU response codes
|
||||
#include "typed_data.h"
|
||||
#include "commands_712.h"
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "hash_bytes.h"
|
||||
#include "ethUstream.h" // INT256_LENGTH
|
||||
#include "apdu_constants.h" // APDU return codes
|
||||
#include "public_keys.h"
|
||||
#include "context_712.h"
|
||||
#include "commands_712.h"
|
||||
#include "typed_data.h"
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "commands_712.h"
|
||||
#include "type_hash.h"
|
||||
#include "shared_context.h"
|
||||
#include "ethUtils.h"
|
||||
#include "mem_utils.h"
|
||||
#include "ui_logic.h"
|
||||
#include "apdu_constants.h" // APDU response codes
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "os_pic.h"
|
||||
#include "apdu_constants.h" // APDU response codes
|
||||
#include "typed_data.h"
|
||||
#include "utils.h" // ARRAY_SIZE
|
||||
#include "common_utils.h" // ARRAY_SIZE
|
||||
|
||||
// Bit indicating they are more types associated to this typename
|
||||
#define TYPENAME_MORE_TYPE (1 << 7)
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "mem_utils.h"
|
||||
#include "type_hash.h"
|
||||
#include "shared_context.h"
|
||||
#include "ethUtils.h" // KECCAK256_HASH_BYTESIZE
|
||||
#include "format_hash_field_type.h"
|
||||
#include "hash_bytes.h"
|
||||
#include "apdu_constants.h" // APDU response codes
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
#include "mem_utils.h"
|
||||
#include "os_io.h"
|
||||
#include "shared_context.h"
|
||||
#include "ethUtils.h" // getEthDisplayableAddress
|
||||
#include "utils.h" // uint256_to_decimal
|
||||
#include "common_utils.h" // uint256_to_decimal
|
||||
#include "common_712.h"
|
||||
#include "context_712.h" // eip712_context_deinit
|
||||
#include "uint256.h" // tostring256 && tostring256_signed
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "utils.h"
|
||||
#include "common_utils.h"
|
||||
#include "common_ui.h"
|
||||
#include "common_712.h"
|
||||
#include "ethUtils.h"
|
||||
|
||||
void handleSignEIP712Message_v0(uint8_t p1,
|
||||
uint8_t p2,
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#include <ctype.h>
|
||||
#include "shared_context.h"
|
||||
#include "utils.h"
|
||||
#include "common_utils.h"
|
||||
#include "feature_signTx.h"
|
||||
#ifdef HAVE_STARKWARE
|
||||
#include "stark_utils.h"
|
||||
#endif
|
||||
#include "uint256.h"
|
||||
#include "eth_plugin_handler.h"
|
||||
#include "network.h"
|
||||
#include "ethUtils.h"
|
||||
#include "common_ui.h"
|
||||
#include "ui_callbacks.h"
|
||||
#include "apdu_constants.h"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "lib_standard_app/crypto_helpers.h"
|
||||
#include "os_io_seproxyhal.h"
|
||||
#include "shared_context.h"
|
||||
#include "utils.h"
|
||||
#include "common_utils.h"
|
||||
#include "common_ui.h"
|
||||
#include "handle_swap_sign_transaction.h"
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "shared_context.h"
|
||||
#include "apdu_constants.h"
|
||||
#include "ethUtils.h"
|
||||
#include "common_ui.h"
|
||||
|
||||
void handleStarkwareProvideQuantum(uint8_t p1,
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "apdu_constants.h"
|
||||
#include "stark_utils.h"
|
||||
#include "poorstream.h"
|
||||
#include "ethUtils.h"
|
||||
#include "common_ui.h"
|
||||
#include "os_io_seproxyhal.h"
|
||||
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
#include "shared_context.h"
|
||||
#include "ui_callbacks.h"
|
||||
#include "ui_nbgl.h"
|
||||
#include "ethUtils.h"
|
||||
#include "ui_signing.h"
|
||||
#include "plugins.h"
|
||||
#include "domain_name.h"
|
||||
#include "caller_api.h"
|
||||
#include "network_icons.h"
|
||||
#include "network.h"
|
||||
|
||||
#define TEXT_TX "transaction"
|
||||
// 1 more than actually displayed on screen, because of calculations in StaticReview
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "ui_nbgl.h"
|
||||
#include "nbgl_use_case.h"
|
||||
#include "glyphs.h"
|
||||
#include "caller_api.h"
|
||||
#include "network.h"
|
||||
|
||||
char g_stax_shared_buffer[SHARED_BUFFER_SIZE] = {0};
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include "ui_nbgl.h"
|
||||
#include "common_712.h"
|
||||
#include "network.h"
|
||||
#include "ethUtils.h"
|
||||
#include "ui_message_signing.h"
|
||||
#include "ui_signing.h"
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "ui_nbgl.h"
|
||||
#include "ui_signing.h"
|
||||
#include "starkDisplayUtils.h"
|
||||
#include "ethUtils.h"
|
||||
#include "network.h"
|
||||
|
||||
#ifdef HAVE_STARKWARE
|
||||
|
||||
@@ -5,7 +5,13 @@
|
||||
| :rotating_light: | Breaks build |
|
||||
| :warning: | Breaks compatibility with app |
|
||||
|
||||
## [latest](/) - 2023/12/07
|
||||
## [latest](/) - 2024/02/02
|
||||
|
||||
### Changed
|
||||
|
||||
* The SDK source code has been split into multiple smaller files
|
||||
|
||||
## [3b7e7ad](/../../commit/3b7e7ad) - 2023/12/07
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
201
src_plugin_sdk/LICENSE
Normal file
201
src_plugin_sdk/LICENSE
Normal file
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
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.
|
||||
@@ -14,5 +14,5 @@ Be careful, and weight your choices.
|
||||
If for some reasons you want to rebuild this SDK manually from [app-ethereum](https://github.com/LedgerHQ/app-ethereum) (reminder: it is rebuild automatically when building app-ethereum itself):
|
||||
|
||||
```shell
|
||||
$> python3 tools/build_sdk.py
|
||||
$> ./tools/build_sdk.sh
|
||||
```
|
||||
|
||||
21
src_plugin_sdk/src/eth_internals.h
Normal file
21
src_plugin_sdk/src/eth_internals.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/*******************************************************************************
|
||||
* 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.
|
||||
********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
// Empty file, introduced to not break compatibility following plugin-sdk structure rework
|
||||
#warning "Deprecated file, the sdk sources have been rationalized in several dedicated files."
|
||||
@@ -15,8 +15,8 @@
|
||||
* limitations under the License.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "eth_internals.h"
|
||||
#include "eth_plugin_interface.h"
|
||||
#include "lib_standard_app/swap_lib_calls.h" // RUN_APPLICATION
|
||||
|
||||
// Functions implemented by the plugin
|
||||
void handle_init_contract(ethPluginInitContract_t *parameters);
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
#include <string.h>
|
||||
#include "erc1155_plugin.h"
|
||||
#include "plugin_utils.h"
|
||||
#include "eth_plugin_internal.h"
|
||||
#include "ethUtils.h"
|
||||
#include "eth_plugin_handler.h"
|
||||
|
||||
static const uint8_t ERC1155_APPROVE_FOR_ALL_SELECTOR[SELECTOR_SIZE] = {0xa2, 0x2c, 0xb4, 0x65};
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <stdint.h>
|
||||
#include "ethUstream.h"
|
||||
#include "uint256.h"
|
||||
#include "nft.h"
|
||||
#include "asset_info.h"
|
||||
|
||||
// Internal plugin for EIP 1155: https://eips.ethereum.org/EIPS/eip-1155
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
#include <string.h>
|
||||
#include "erc1155_plugin.h"
|
||||
#include "plugin_utils.h"
|
||||
#include "eth_plugin_internal.h"
|
||||
#include "utils.h"
|
||||
#include "ethUtils.h"
|
||||
#include "common_utils.h"
|
||||
|
||||
static void handle_safe_transfer(ethPluginProvideParameter_t *msg, erc1155_context_t *context) {
|
||||
uint8_t new_value[INT256_LENGTH];
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
#include <string.h>
|
||||
#include "erc1155_plugin.h"
|
||||
#include "eth_plugin_internal.h"
|
||||
#include "eth_plugin_interface.h"
|
||||
#include "ethUtils.h"
|
||||
#include "utils.h"
|
||||
#include "common_utils.h"
|
||||
|
||||
static void set_approval_for_all_ui(ethQueryContractUI_t *msg, erc1155_context_t *context) {
|
||||
switch (msg->screenIndex) {
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
#include "eth_plugin_internal.h"
|
||||
#include "eth_plugin_handler.h"
|
||||
#include "shared_context.h"
|
||||
#include "ethUtils.h"
|
||||
#include "plugin_utils.h"
|
||||
#include "ethUstream.h"
|
||||
#include "utils.h"
|
||||
#include "common_utils.h"
|
||||
|
||||
typedef enum { ERC20_TRANSFER = 0, ERC20_APPROVE } erc20Selector_t;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#ifdef HAVE_NFT_SUPPORT
|
||||
|
||||
#include <string.h>
|
||||
#include "plugin_utils.h"
|
||||
#include "erc721_plugin.h"
|
||||
#include "eth_plugin_internal.h"
|
||||
#include "eth_plugin_interface.h"
|
||||
#include "ethUtils.h"
|
||||
#include "eth_plugin_handler.h"
|
||||
|
||||
static const uint8_t ERC721_APPROVE_SELECTOR[SELECTOR_SIZE] = {0x09, 0x5e, 0xa7, 0xb3};
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "ethUstream.h"
|
||||
#include "nft.h"
|
||||
#include "asset_info.h"
|
||||
|
||||
// Internal plugin for EIP 721: https://eips.ethereum.org/EIPS/eip-721
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifdef HAVE_NFT_SUPPORT
|
||||
|
||||
#include "erc721_plugin.h"
|
||||
#include "plugin_utils.h"
|
||||
#include "eth_plugin_internal.h"
|
||||
|
||||
static void handle_approve(ethPluginProvideParameter_t *msg, erc721_context_t *context) {
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
#include <string.h>
|
||||
#include "erc721_plugin.h"
|
||||
#include "eth_plugin_internal.h"
|
||||
#include "eth_plugin_interface.h"
|
||||
#include "ethUtils.h"
|
||||
#include "utils.h"
|
||||
#include "common_utils.h"
|
||||
|
||||
static void set_approval_ui(ethQueryContractUI_t *msg, erc721_context_t *context) {
|
||||
switch (msg->screenIndex) {
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
#include "eth_plugin_internal.h"
|
||||
#include "eth_plugin_handler.h"
|
||||
#include "shared_context.h"
|
||||
#include "ethUtils.h"
|
||||
#include "utils.h"
|
||||
#include "common_utils.h"
|
||||
|
||||
void getEth2PublicKey(uint32_t *bip32Path, uint8_t bip32PathLength, uint8_t *out);
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include <string.h>
|
||||
#include "os_io_seproxyhal.h"
|
||||
#include "uint256.h"
|
||||
#include "eth_plugin_interface.h"
|
||||
#include "shared_context.h" // TODO : rewrite as independant code
|
||||
#include "eth_plugin_internal.h" // TODO : rewrite as independant code
|
||||
#include "stark_utils.h"
|
||||
#include "utils.h"
|
||||
#include "ethUtils.h"
|
||||
#include "plugin_utils.h"
|
||||
#include "common_utils.h"
|
||||
#include "apdu_constants.h"
|
||||
|
||||
#ifdef HAVE_STARKWARE
|
||||
|
||||
@@ -1,227 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
'''
|
||||
This script extract a few specific definitions from app-ethereum that are
|
||||
required to exchange information with ethereum external plugins.
|
||||
It should always be launched from app-ethereum:
|
||||
|
||||
python3 tools/build_sdk.py
|
||||
|
||||
'''
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
|
||||
def extract_from_headers(sources, nodes_to_extract):
|
||||
cat_sources = []
|
||||
for source in sources:
|
||||
with open(source, 'r') as f:
|
||||
cat_sources += f.readlines()
|
||||
|
||||
sdk_body = []
|
||||
for key, values in nodes_to_extract.items():
|
||||
for value in values:
|
||||
node = []
|
||||
unclosed_curvy_brackets = False
|
||||
unclosed_parantheses = False
|
||||
for line in cat_sources:
|
||||
if key in line and value in line:
|
||||
node += [line]
|
||||
unclosed_curvy_brackets = line.count('{') - line.count('}')
|
||||
if not unclosed_curvy_brackets:
|
||||
break
|
||||
elif (key == "fn" and value in line) or unclosed_parantheses:
|
||||
node += [line]
|
||||
unclosed_parantheses = line.find(")") == -1
|
||||
if not unclosed_parantheses:
|
||||
break
|
||||
elif unclosed_curvy_brackets:
|
||||
node += [line]
|
||||
unclosed_curvy_brackets += line.count(
|
||||
'{') - line.count('}')
|
||||
if unclosed_curvy_brackets:
|
||||
continue
|
||||
else:
|
||||
break
|
||||
|
||||
sdk_body += [''.join(node)]
|
||||
|
||||
return '\n'.join(sdk_body)
|
||||
|
||||
|
||||
def extract_from_c_files(sources, nodes_to_extract):
|
||||
cat_sources = []
|
||||
for source in sources:
|
||||
with open(source, 'r') as f:
|
||||
cat_sources += f.readlines()
|
||||
|
||||
sdk_body = []
|
||||
for node_name in nodes_to_extract:
|
||||
node = []
|
||||
copying = False
|
||||
wait_curvy_bracket = True
|
||||
for line in cat_sources:
|
||||
if node_name in line:
|
||||
copying = True
|
||||
node += [line]
|
||||
unclosed_curvy_brackets = line.count('{') - line.count('}')
|
||||
elif copying:
|
||||
node += [line]
|
||||
unclosed_curvy_brackets += line.count('{') - line.count('}')
|
||||
if wait_curvy_bracket:
|
||||
wait_curvy_bracket = line.count('}') == 0
|
||||
if unclosed_curvy_brackets != 0 or wait_curvy_bracket:
|
||||
continue
|
||||
else:
|
||||
break
|
||||
|
||||
sdk_body += [''.join(node)]
|
||||
|
||||
return '\n'.join(sdk_body)
|
||||
|
||||
|
||||
def merge_headers(sources, nodes_to_extract):
|
||||
includes = [
|
||||
'#include <stdbool.h>',
|
||||
'#include <string.h>',
|
||||
'#include "os.h"',
|
||||
'#include "cx.h"',
|
||||
'#ifdef HAVE_NBGL',
|
||||
'#include "nbgl_types.h"',
|
||||
'#include "glyphs.h"',
|
||||
'#endif'
|
||||
]
|
||||
|
||||
body = extract_from_headers(sources, nodes_to_extract)
|
||||
|
||||
eth_internals_h = '\n\n'.join([
|
||||
"/* This file is auto-generated, don't edit it */",
|
||||
"#pragma once",
|
||||
'\n'.join(includes),
|
||||
body
|
||||
])
|
||||
|
||||
with open("ethereum-plugin-sdk/include/eth_internals.h", 'w') as f:
|
||||
f.write(eth_internals_h)
|
||||
|
||||
|
||||
def copy_header(header_to_copy, merged_headers):
|
||||
|
||||
merged_headers = [os.path.basename(path) for path in merged_headers]
|
||||
|
||||
with open(header_to_copy, 'r') as f:
|
||||
source = f.readlines()
|
||||
|
||||
eth_plugin_interface_h = [
|
||||
"/* This file is auto-generated, don't edit it */\n"]
|
||||
for line in source:
|
||||
eth_plugin_interface_h += [line]
|
||||
for header in merged_headers:
|
||||
if header in line:
|
||||
del eth_plugin_interface_h[-1]
|
||||
break
|
||||
|
||||
# add '#include "eth_internals.h"'
|
||||
include_index = eth_plugin_interface_h.index('#include "cx.h"\n')
|
||||
eth_plugin_interface_h.insert(
|
||||
include_index+1, '#include "eth_internals.h"\n')
|
||||
|
||||
# dump to file
|
||||
with open("ethereum-plugin-sdk/include/eth_plugin_interface.h", 'w') as f:
|
||||
f.writelines(eth_plugin_interface_h)
|
||||
|
||||
|
||||
def merge_c_files(sources, nodes_to_extract):
|
||||
includes = [
|
||||
'#include "eth_internals.h"'
|
||||
]
|
||||
|
||||
body = extract_from_c_files(sources, nodes_to_extract)
|
||||
|
||||
eth_internals_h = '\n\n'.join([
|
||||
"/* This file is auto-generated, don't edit it */",
|
||||
'\n'.join(includes),
|
||||
body
|
||||
])
|
||||
|
||||
with open("ethereum-plugin-sdk/include/eth_internals.c", 'w') as f:
|
||||
f.write(eth_internals_h)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# some nodes will be extracted from these headers and merged into a new
|
||||
# one, copied to sdk
|
||||
headers_to_merge = [
|
||||
"src/tokens.h",
|
||||
"src/chainConfig.h",
|
||||
"src/utils.h",
|
||||
"src_common/ethUstream.h",
|
||||
"src_common/ethUtils.h",
|
||||
"src/shared_context.h",
|
||||
"src/eth_plugin_internal.h",
|
||||
"src/nft.h",
|
||||
"src/swap_lib_calls.h",
|
||||
]
|
||||
nodes_to_extract = {
|
||||
"#define": ["MAX_TICKER_LEN",
|
||||
"ADDRESS_LENGTH",
|
||||
"INT256_LENGTH",
|
||||
"WEI_TO_ETHER",
|
||||
"SELECTOR_SIZE",
|
||||
"PARAMETER_LENGTH",
|
||||
"RUN_APPLICATION",
|
||||
"COLLECTION_NAME_MAX_LEN"],
|
||||
"typedef enum": [],
|
||||
"typedef struct": ["tokenDefinition_t",
|
||||
"txInt256_t",
|
||||
"txContent_t",
|
||||
"nftInfo_t",
|
||||
"caller_app_t"],
|
||||
"typedef union": ["extraInfo_t"],
|
||||
"__attribute__((no_instrument_function)) inline": ["int allzeroes"],
|
||||
"const": ["HEXDIGITS"],
|
||||
"fn": ["bool getEthAddressStringFromBinary",
|
||||
"bool getEthAddressFromKey",
|
||||
"bool getEthDisplayableAddress",
|
||||
"bool adjustDecimals",
|
||||
"bool uint256_to_decimal",
|
||||
"bool amountToString",
|
||||
"bool u64_to_string",
|
||||
"void copy_address",
|
||||
"void copy_parameter",
|
||||
"bool U2BE_from_parameter",
|
||||
"bool U4BE_from_parameter"]
|
||||
}
|
||||
merge_headers(headers_to_merge, nodes_to_extract)
|
||||
|
||||
# this header will be stripped from all #include related to previously
|
||||
# merged headers, then copied to sdk
|
||||
copy_header("src/eth_plugin_interface.h", headers_to_merge)
|
||||
|
||||
# extract and merge function bodies
|
||||
c_files_to_merge = [
|
||||
"src/utils.c",
|
||||
"src_common/ethUtils.c",
|
||||
"src/eth_plugin_internal.c",
|
||||
]
|
||||
merge_c_files(c_files_to_merge, nodes_to_extract["fn"])
|
||||
|
||||
files_to_copy = [
|
||||
"main.c",
|
||||
"plugin_utils.c",
|
||||
"plugin_utils.h",
|
||||
]
|
||||
for file in files_to_copy:
|
||||
shutil.copyfile("src_plugin_sdk/" + file,
|
||||
"ethereum-plugin-sdk/include/" + file)
|
||||
|
||||
files_to_copy = [
|
||||
"CHANGELOG.md",
|
||||
"README.md",
|
||||
"standard_plugin.mk",
|
||||
]
|
||||
for file in files_to_copy:
|
||||
shutil.copyfile("src_plugin_sdk/" + file,
|
||||
"ethereum-plugin-sdk/" + file)
|
||||
10
tools/build_sdk.sh
Executable file
10
tools/build_sdk.sh
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Clean the sdk
|
||||
find ./ethereum-plugin-sdk/ -mindepth 1 -maxdepth 1 ! -name .git -exec rm -r {} \;
|
||||
|
||||
# Copy exclusive files
|
||||
cp -r src_plugin_sdk/* ./ethereum-plugin-sdk/
|
||||
|
||||
# Copy common sources
|
||||
cp -r src_common/* ./ethereum-plugin-sdk/src/
|
||||
@@ -90,7 +90,7 @@ def main(output_dir: str) -> bool:
|
||||
|
||||
# get chain IDs and network names
|
||||
expr = r"{\.chain_id = ([0-9]*), \.name = \"(.*)\", \.ticker = \"(.*)\"},"
|
||||
with open("src_common/network.c") as f:
|
||||
with open("src/network.c") as f:
|
||||
for line in f.readlines():
|
||||
line = line.strip()
|
||||
if line.startswith("{") and line.endswith("},"):
|
||||
|
||||
Reference in New Issue
Block a user