diff --git a/.gitmodules b/.gitmodules index 0e3514a..1e37be5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "ethereum-plugin-sdk"] path = ethereum-plugin-sdk - url = https://github.com/LedgerHQ/ethereum-plugin-sdk.git + url = https://github.com/LedgerHQ/ethereum-plugin-sdk diff --git a/ethereum-plugin-sdk b/ethereum-plugin-sdk new file mode 160000 index 0000000..e959f38 --- /dev/null +++ b/ethereum-plugin-sdk @@ -0,0 +1 @@ +Subproject commit e959f38be9eed12dcaf253aec9988d9c61f76e6d diff --git a/ethereum-plugin-sdk/LICENSE b/ethereum-plugin-sdk/LICENSE deleted file mode 100644 index 8dada3e..0000000 --- a/ethereum-plugin-sdk/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - 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. diff --git a/ethereum-plugin-sdk/README.md b/ethereum-plugin-sdk/README.md deleted file mode 100644 index ec31dd6..0000000 --- a/ethereum-plugin-sdk/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# ethereum-plugin-sdk - -This repository is meant to be linked as submodule and used in external plugins working with [app-ethereum](https://github.com/LedgerHQ/app-ethereum). -It is composed of a few headers containing definitions about app-ethereum's internal transaction parsing state and some structures to communicate via shared memory. - -## Updating this SDK - -This SDK is updated at (app-ethereum) build time every time one of app-ethereum internals structures of interest are modified. -If this SDK gets updated, it is possible that all plugins must be recompiled (and eventually updated to work again with the update) with this new SDK. -Be careful, and weight your choices. - -## Manual build - -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): - -``` -cd app-ethereum -python3 ethereum-plugin-sdk/build_sdk.py -``` diff --git a/ethereum-plugin-sdk/build_sdk.py b/ethereum-plugin-sdk/build_sdk.py deleted file mode 100644 index 34d63c5..0000000 --- a/ethereum-plugin-sdk/build_sdk.py +++ /dev/null @@ -1,175 +0,0 @@ -''' -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 ethereum-plugin-sdk/build_sdk.py - -''' - -import os - - -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 unclosed_curvy_brackets == False: - break - elif (key == "fn" and value in line) or unclosed_parantheses: - node += [line] - unclosed_parantheses = line.find(")") == -1 - if unclosed_parantheses == False: - 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 "os.h"', - '#include "cx.h"', - '#include ', - '#include ' - ] - - 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" - ] - nodes_to_extract = { - "#define": ["MAX_TICKER_LEN", "ADDRESS_LENGTH", "INT256_LENGTH", "WEI_TO_ETHER", "SELECTOR_SIZE", "PARAMETER_LENGTH", "RUN_APPLICATION"], - "typedef enum": [], - "typedef struct": ["tokenDefinition_t", "txInt256_t", "txContent_t"], - "__attribute__((no_instrument_function)) inline": ["int allzeroes"], - "const": ["HEXDIGITS"], - "fn": ["void getEthAddressStringFromBinary", "void getEthAddressFromKey", "void getEthDisplayableAddress", "bool adjustDecimals", "bool uint256_to_decimal", "void amountToString", "void u64_to_string"] - } - 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" - ] - merge_c_files(c_files_to_merge, nodes_to_extract["fn"]) diff --git a/ethereum-plugin-sdk/include/eth_internals.c b/ethereum-plugin-sdk/include/eth_internals.c deleted file mode 100644 index 49833cc..0000000 --- a/ethereum-plugin-sdk/include/eth_internals.c +++ /dev/null @@ -1,248 +0,0 @@ -/* This file is auto-generated, don't edit it */ - -#include "eth_internals.h" - -void getEthAddressStringFromBinary(uint8_t *address, - char *out, - cx_sha3_t *sha3Context, - uint64_t chainId) { - // save some precious stack space - union locals_union { - uint8_t hashChecksum[INT256_LENGTH]; - uint8_t tmp[51]; - } locals_union; - - uint8_t i; - bool eip1191 = false; - uint32_t offset = 0; - switch (chainId) { - case 30: - case 31: - eip1191 = true; - break; - } - if (eip1191) { - u64_to_string(chainId, (char *) locals_union.tmp, sizeof(locals_union.tmp)); - offset = strnlen((char *) locals_union.tmp, sizeof(locals_union.tmp)); - strlcat((char *) locals_union.tmp + offset, "0x", sizeof(locals_union.tmp) - offset); - offset = strnlen((char *) locals_union.tmp, sizeof(locals_union.tmp)); - } - for (i = 0; i < 20; i++) { - uint8_t digit = address[i]; - locals_union.tmp[offset + 2 * i] = HEXDIGITS[(digit >> 4) & 0x0f]; - locals_union.tmp[offset + 2 * i + 1] = HEXDIGITS[digit & 0x0f]; - } - cx_keccak_init(sha3Context, 256); - cx_hash((cx_hash_t *) sha3Context, - CX_LAST, - locals_union.tmp, - offset + 40, - locals_union.hashChecksum, - 32); - for (i = 0; i < 40; i++) { - uint8_t digit = address[i / 2]; - if ((i % 2) == 0) { - digit = (digit >> 4) & 0x0f; - } else { - digit = digit & 0x0f; - } - if (digit < 10) { - out[i] = HEXDIGITS[digit]; - } else { - int v = (locals_union.hashChecksum[i / 2] >> (4 * (1 - i % 2))) & 0x0f; - if (v >= 8) { - out[i] = HEXDIGITS[digit] - 'a' + 'A'; - } else { - out[i] = HEXDIGITS[digit]; - } - } - } - out[40] = '\0'; -} - -void getEthAddressFromKey(cx_ecfp_public_key_t *publicKey, uint8_t *out, cx_sha3_t *sha3Context) { - uint8_t hashAddress[INT256_LENGTH]; - cx_keccak_init(sha3Context, 256); - cx_hash((cx_hash_t *) sha3Context, CX_LAST, publicKey->W + 1, 64, hashAddress, 32); - memmove(out, hashAddress + 12, 20); -} - -void getEthDisplayableAddress(uint8_t *in, - char *out, - size_t out_len, - cx_sha3_t *sha3, - uint64_t chainId) { - if (out_len < 43) { - strlcpy(out, "ERROR", out_len); - return; - } - out[0] = '0'; - out[1] = 'x'; - getEthAddressStringFromBinary(in, out + 2, sha3, chainId); -} - -bool adjustDecimals(char *src, - uint32_t srcLength, - char *target, - uint32_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 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; -} - -void amountToString(const uint8_t *amount, - uint8_t amount_size, - uint8_t decimals, - const char *ticker, - char *out_buffer, - uint8_t out_buffer_size) { - char tmp_buffer[100] = {0}; - - if (uint256_to_decimal(amount, amount_size, tmp_buffer, sizeof(tmp_buffer)) == false) { - THROW(EXCEPTION_OVERFLOW); - } - - 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 (adjustDecimals(tmp_buffer, - amount_len, - out_buffer + ticker_len, - out_buffer_size - ticker_len - 1, - decimals) == false) { - THROW(EXCEPTION_OVERFLOW); - } - - out_buffer[out_buffer_size - 1] = '\0'; -} - -void 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) { - THROW(0x6502); - } - 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++; - } -} diff --git a/ethereum-plugin-sdk/include/eth_internals.h b/ethereum-plugin-sdk/include/eth_internals.h deleted file mode 100644 index 6716b85..0000000 --- a/ethereum-plugin-sdk/include/eth_internals.h +++ /dev/null @@ -1,91 +0,0 @@ -/* This file is auto-generated, don't edit it */ - -#pragma once - -#include "os.h" -#include "cx.h" -#include -#include - -#define MAX_TICKER_LEN 12 // 10 characters + ' ' + '\0' - -#define ADDRESS_LENGTH 20 - -#define INT256_LENGTH 32 - -#define WEI_TO_ETHER 18 - -#define SELECTOR_SIZE 4 - -#define PARAMETER_LENGTH 32 - -#define RUN_APPLICATION 1 - -typedef struct tokenDefinition_t { -#ifdef HAVE_CONTRACT_NAME_IN_DESCRIPTOR - uint8_t contractName[ADDRESS_LENGTH]; -#endif - uint8_t address[ADDRESS_LENGTH]; - char ticker[MAX_TICKER_LEN]; - uint8_t decimals; -} tokenDefinition_t; - -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; - -static __attribute__((no_instrument_function)) inline int allzeroes(void *buf, size_t n) { - uint8_t *p = (uint8_t *) buf; - for (size_t i = 0; i < n; ++i) { - if (p[i]) { - return 0; - } - } - return 1; -} - -static const char HEXDIGITS[] = "0123456789abcdef"; - -void getEthAddressStringFromBinary(uint8_t *address, - char *out, - cx_sha3_t *sha3Context, - uint64_t chainId); - -void getEthAddressFromKey(cx_ecfp_public_key_t *publicKey, uint8_t *out, cx_sha3_t *sha3Context); - -void getEthDisplayableAddress(uint8_t *in, - char *out, - size_t out_len, - cx_sha3_t *sha3, - uint64_t chainId); - -bool adjustDecimals(char *src, - uint32_t srcLength, - char *target, - uint32_t targetLength, - uint8_t decimals); - -bool uint256_to_decimal(const uint8_t *value, size_t value_len, char *out, size_t out_len); - -void amountToString(const uint8_t *amount, - uint8_t amount_len, - uint8_t decimals, - const char *ticker, - char *out_buffer, - uint8_t out_buffer_size); - -void u64_to_string(uint64_t src, char *dst, uint8_t dst_size); diff --git a/ethereum-plugin-sdk/include/eth_plugin_interface.h b/ethereum-plugin-sdk/include/eth_plugin_interface.h deleted file mode 100644 index 59a2516..0000000 --- a/ethereum-plugin-sdk/include/eth_plugin_interface.h +++ /dev/null @@ -1,180 +0,0 @@ -/* This file is auto-generated, don't edit it */ -#ifndef __ETH_PLUGIN_INTERFACE_H__ - -#define __ETH_PLUGIN_INTERFACE_H__ - -#include "os.h" -#include "cx.h" -#include "eth_internals.h" - -#define PLUGIN_ID_LENGTH 30 - -// Interface version. To be updated everytime we introduce breaking changes to the plugin interface. -typedef enum { - ETH_PLUGIN_INTERFACE_VERSION_1 = 1, // Version 1 - ETH_PLUGIN_INTERFACE_VERSION_2 = 2, - ETH_PLUGIN_INTERFACE_VERSION_LATEST = 3, -} eth_plugin_interface_version_t; - -typedef enum { - - ETH_PLUGIN_INIT_CONTRACT = 0x0101, - ETH_PLUGIN_PROVIDE_PARAMETER = 0x0102, - ETH_PLUGIN_FINALIZE = 0x0103, - ETH_PLUGIN_PROVIDE_TOKEN = 0x0104, - ETH_PLUGIN_QUERY_CONTRACT_ID = 0x0105, - ETH_PLUGIN_QUERY_CONTRACT_UI = 0x0106, - ETH_PLUGIN_CHECK_PRESENCE = 0x01FF - -} eth_plugin_msg_t; - -typedef enum { - // Unsuccesful return values - ETH_PLUGIN_RESULT_ERROR = 0x00, - ETH_PLUGIN_RESULT_UNAVAILABLE = 0x01, - ETH_PLUGIN_RESULT_UNSUCCESSFUL = 0x02, // Used for comparison - - // Successful return values - ETH_PLUGIN_RESULT_SUCCESSFUL = 0x03, // Used for comparison - ETH_PLUGIN_RESULT_OK = 0x04, - ETH_PLUGIN_RESULT_OK_ALIAS = 0x05, - ETH_PLUGIN_RESULT_FALLBACK = 0x06 - -} eth_plugin_result_t; - -typedef enum { - - ETH_UI_TYPE_AMOUNT_ADDRESS = 0x01, - ETH_UI_TYPE_GENERIC = 0x02 - -} eth_ui_type_t; - -typedef void (*PluginCall)(int, void *); - -// Shared objects, read-write - -typedef struct ethPluginSharedRW_t { - cx_sha3_t *sha3; - -} ethPluginSharedRW_t; - -// Shared objects, read-only - -typedef struct ethPluginSharedRO_t { - txContent_t *txContent; - -} ethPluginSharedRO_t; - -// Init Contract - -typedef struct ethPluginInitContract_t { - uint8_t interfaceVersion; - uint8_t result; - - // in - ethPluginSharedRW_t *pluginSharedRW; - ethPluginSharedRO_t *pluginSharedRO; - uint8_t *pluginContext; - size_t pluginContextLength; - uint8_t *selector; // 4 bytes selector - size_t dataSize; - - char *alias; // 29 bytes alias if ETH_PLUGIN_RESULT_OK_ALIAS set - -} ethPluginInitContract_t; - -// Provide parameter - -typedef struct ethPluginProvideParameter_t { - ethPluginSharedRW_t *pluginSharedRW; - ethPluginSharedRO_t *pluginSharedRO; - uint8_t *pluginContext; - uint8_t *parameter; // 32 bytes parameter - uint32_t parameterOffset; - - uint8_t result; - -} ethPluginProvideParameter_t; - -// Finalize - -typedef struct ethPluginFinalize_t { - ethPluginSharedRW_t *pluginSharedRW; - ethPluginSharedRO_t *pluginSharedRO; - uint8_t *pluginContext; - - uint8_t *tokenLookup1; // set by the plugin if a token should be looked up - uint8_t *tokenLookup2; - - uint8_t *amount; // set an uint256 pointer if uiType is UI_AMOUNT_ADDRESS - uint8_t *address; // set to the destination address if uiType is UI_AMOUNT_ADDRESS. Set to the - // user's address if uiType is UI_TYPE_GENERIC - - uint8_t uiType; - uint8_t numScreens; // ignored if uiType is UI_AMOUNT_ADDRESS - uint8_t result; - -} ethPluginFinalize_t; - -// If uiType is UI_AMOUNT_ADDRESS, the amount and address provided by the plugin will be used -// If tokenLookup1 is set, the amount is provided for this token - -// if uiType is UI_TYPE_GENERIC, the ETH application provides tokens if requested then prompts -// for each UI field -// The first field is forced by the ETH app to be the name + version of the plugin handling the -// request The last field is the fee amount - -// Provide token - -typedef struct ethPluginProvideToken_t { - ethPluginSharedRW_t *pluginSharedRW; - ethPluginSharedRO_t *pluginSharedRO; - uint8_t *pluginContext; - - tokenDefinition_t *token1; // set by the ETH application, to be saved by the plugin - tokenDefinition_t *token2; - - uint8_t additionalScreens; // Used by the plugin if it needs to display additional screens - // based on the information received from the token definitions. - - uint8_t result; - -} ethPluginProvideToken_t; - -// Query Contract name and version - -// This is always called on the non aliased contract - -typedef struct ethQueryContractID_t { - ethPluginSharedRW_t *pluginSharedRW; - ethPluginSharedRO_t *pluginSharedRO; - uint8_t *pluginContext; - - char *name; - size_t nameLength; - char *version; - size_t versionLength; - - uint8_t result; - -} ethQueryContractID_t; - -// Query Contract UI - -typedef struct ethQueryContractUI_t { - ethPluginSharedRW_t *pluginSharedRW; - ethPluginSharedRO_t *pluginSharedRO; - uint8_t *pluginContext; - uint8_t screenIndex; - char network_ticker[MAX_TICKER_LEN]; - - char *title; - size_t titleLength; - char *msg; - size_t msgLength; - - uint8_t result; - -} ethQueryContractUI_t; - -#endif