From 839a589d2c5c4bb1316b15014146dadbc18ffca1 Mon Sep 17 00:00:00 2001 From: Bartosz Tarnowski Date: Fri, 3 Apr 2020 16:42:01 +0100 Subject: [PATCH 01/14] Linux build. Makefiles fixed. Unit tests passing. --- .gitignore | 2 ++ CMakeLists.txt | 2 +- bootstrap.sh | 6 +++++- samples/cpp/CMakeLists.txt | 2 +- src/Base58.cpp | 5 +++-- src/BinaryCoding.h | 1 + src/Bitcoin/Script.h | 1 + src/Encrypt.cpp | 1 + src/Filecoin/Address.cpp | 2 ++ src/HDWallet.cpp | 1 + src/Keystore/StoredKey.cpp | 4 ++-- src/Keystore/StoredKey.h | 2 +- src/NEO/ReadData.cpp | 1 - src/NEO/ReadData.h | 1 + src/Nebulas/Address.cpp | 1 + src/Waves/Address.cpp | 1 + src/interface/TWStoredKey.cpp | 1 + tests/interface/TWStoredKeyTests.cpp | 22 +++++++++++++--------- tests/interface/TWTestUtilities.cpp | 3 ++- tools/install-dependencies | 2 +- trezor-crypto/src/bip32.c | 10 +++++----- walletconsole/lib/Coins.cpp | 1 + walletconsole/lib/Util.cpp | 1 + walletconsole/lib/Util.h | 1 + 24 files changed, 49 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 7a5561d7def..9e6a32631ab 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ xcode/ cmake-build-debug/ .cquery_cache/ .cxx/ +CMakeCache.txt +CMakeFiles/ # Dependencies node_modules diff --git a/CMakeLists.txt b/CMakeLists.txt index 151bb0fed14..5c2f3fa3b05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(TrustWalletCore) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++") set(CMAKE_EXPORT_COMPILE_COMMANDS 1) set(CMAKE_POSITION_INDEPENDENT_CODE ON) diff --git a/bootstrap.sh b/bootstrap.sh index e5ddf642a52..35b6325f02c 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -3,6 +3,8 @@ # Fail if any commands fails set -e +export CPLUS_INCLUDE_PATH=/usr/include/c++/7.5.0:/usr/include/x86_64-linux-gnu/c++/7.5.0 + echo "#### Initializing... ####" tools/install-dependencies @@ -10,7 +12,7 @@ echo "#### Generating files... ####" tools/generate-files echo "#### Building... ####" -cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Debug +cmake . -Bbuild -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ make -Cbuild tests TrezorCryptoTests if [ -x "$(command -v clang-tidy)" ]; then @@ -25,3 +27,5 @@ build/trezor-crypto/tests/TrezorCryptoTests ROOT="`dirname \"$0\"`" TESTS_ROOT="`(cd \"$ROOT/tests\" && pwd)`" build/tests/tests "$TESTS_ROOT" + +make -Cbuild walletconsole diff --git a/samples/cpp/CMakeLists.txt b/samples/cpp/CMakeLists.txt index 9f4dbfbde76..79b9aa62845 100644 --- a/samples/cpp/CMakeLists.txt +++ b/samples/cpp/CMakeLists.txt @@ -39,7 +39,7 @@ else () add_compile_options (-Werror=switch) endif () -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++") set (CMAKE_C_STANDARD 11) set (CMAKE_C_STANDARD_REQUIRED ON) diff --git a/src/Base58.cpp b/src/Base58.cpp index 207809114c3..d11312b3605 100644 --- a/src/Base58.cpp +++ b/src/Base58.cpp @@ -11,6 +11,7 @@ #include #include +#include using namespace TW; @@ -77,7 +78,7 @@ Data Base58::decode(const char* begin, const char* end) const { auto it = begin; // Skip leading spaces. - it = std::find_if_not(it, end, std::isspace); + it = std::find_if_not(it, end, [](unsigned char ch) -> bool { return std::isspace(ch); }); // Skip and count leading zeros. std::size_t zeroes = 0; @@ -118,7 +119,7 @@ Data Base58::decode(const char* begin, const char* end) const { } // Skip trailing spaces. - it = std::find_if_not(it, end, std::isspace); + it = std::find_if_not(it, end, [](unsigned char ch) -> bool { return std::isspace(ch); }); if (it != end) { // Extra charaters at the end return {}; diff --git a/src/BinaryCoding.h b/src/BinaryCoding.h index f5c6ff18067..36cca69a41e 100644 --- a/src/BinaryCoding.h +++ b/src/BinaryCoding.h @@ -12,6 +12,7 @@ #include #include #include +#include namespace TW { diff --git a/src/Bitcoin/Script.h b/src/Bitcoin/Script.h index f6b5de13427..2728c7bf4a4 100644 --- a/src/Bitcoin/Script.h +++ b/src/Bitcoin/Script.h @@ -13,6 +13,7 @@ #include #include +#include namespace TW::Bitcoin { diff --git a/src/Encrypt.cpp b/src/Encrypt.cpp index 7492fdb8b54..9782fd42c7f 100644 --- a/src/Encrypt.cpp +++ b/src/Encrypt.cpp @@ -8,6 +8,7 @@ #include "Data.h" #include #include +#include namespace TW::Encrypt { diff --git a/src/Filecoin/Address.cpp b/src/Filecoin/Address.cpp index f12887c612d..06ddb6799eb 100644 --- a/src/Filecoin/Address.cpp +++ b/src/Filecoin/Address.cpp @@ -9,6 +9,8 @@ #include "../Base32.h" #include "../Data.h" +#include + using namespace TW; using namespace TW::Filecoin; diff --git a/src/HDWallet.cpp b/src/HDWallet.cpp index 9d13c0af0d6..d4c2a149fdd 100644 --- a/src/HDWallet.cpp +++ b/src/HDWallet.cpp @@ -18,6 +18,7 @@ #include #include +#include using namespace TW; diff --git a/src/Keystore/StoredKey.cpp b/src/Keystore/StoredKey.cpp index 476fa336d7e..51f28116031 100644 --- a/src/Keystore/StoredKey.cpp +++ b/src/Keystore/StoredKey.cpp @@ -78,8 +78,8 @@ StoredKey StoredKey::createWithPrivateKeyAddDefaultAddress(const std::string& na return key; } -StoredKey::StoredKey(StoredKeyType type, std::string name, const std::string& password, Data data) - : type(type), id(), name(std::move(name)), payload(password, data), accounts() { +StoredKey::StoredKey(StoredKeyType type, const std::string& name, const std::string& password, Data data) + : type(type), id(), name(name), payload(password, data), accounts() { boost::uuids::random_generator gen; id = boost::lexical_cast(gen()); } diff --git a/src/Keystore/StoredKey.h b/src/Keystore/StoredKey.h index c742ba5423a..7f978fe36a2 100644 --- a/src/Keystore/StoredKey.h +++ b/src/Keystore/StoredKey.h @@ -119,7 +119,7 @@ class StoredKey { /// Initializes a `StoredKey` with a type, an encryption password, and unencrypted data. /// This contstructor will encrypt the provided data with default encryption /// parameters. - StoredKey(StoredKeyType type, std::string name, const std::string& password, Data data); + StoredKey(StoredKeyType type, const std::string& name, const std::string& password, Data data); }; } // namespace TW::Keystore diff --git a/src/NEO/ReadData.cpp b/src/NEO/ReadData.cpp index e419f944319..be1c8961002 100644 --- a/src/NEO/ReadData.cpp +++ b/src/NEO/ReadData.cpp @@ -7,7 +7,6 @@ #include "../Data.h" #include "ReadData.h" - TW::Data TW::readBytes(const TW::Data &from, int max, int initial_pos) { if (from.size() - initial_pos < max) { throw std::invalid_argument("Data::Cannot read enough bytes!"); diff --git a/src/NEO/ReadData.h b/src/NEO/ReadData.h index 80b86693f02..8c26c8c698c 100644 --- a/src/NEO/ReadData.h +++ b/src/NEO/ReadData.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include "../Data.h" #include "../BinaryCoding.h" diff --git a/src/Nebulas/Address.cpp b/src/Nebulas/Address.cpp index acdc595d17d..18aab56bad2 100644 --- a/src/Nebulas/Address.cpp +++ b/src/Nebulas/Address.cpp @@ -8,6 +8,7 @@ #include "../Base58.h" #include "../Hash.h" #include "../HexCoding.h" +#include using namespace TW::Nebulas; diff --git a/src/Waves/Address.cpp b/src/Waves/Address.cpp index 7b42ff51dc0..06f34b573db 100644 --- a/src/Waves/Address.cpp +++ b/src/Waves/Address.cpp @@ -13,6 +13,7 @@ #include #include #include +#include using namespace TW; using namespace TW::Waves; diff --git a/src/interface/TWStoredKey.cpp b/src/interface/TWStoredKey.cpp index 795cfa38ce9..4ad0b5773b8 100644 --- a/src/interface/TWStoredKey.cpp +++ b/src/interface/TWStoredKey.cpp @@ -14,6 +14,7 @@ #include #include + using namespace TW::Keystore; struct TWStoredKey* _Nullable TWStoredKeyLoad(TWString* _Nonnull path) { diff --git a/tests/interface/TWStoredKeyTests.cpp b/tests/interface/TWStoredKeyTests.cpp index b769752db9b..b2333cf4408 100644 --- a/tests/interface/TWStoredKeyTests.cpp +++ b/tests/interface/TWStoredKeyTests.cpp @@ -38,16 +38,19 @@ struct TWStoredKey *_Nonnull createDefaultStoredKey() { } TEST(TWStoredKey, loadPBKDF2Key) { - const auto filename = WRAPS(TWStringCreateWithUTF8Bytes((TESTS_ROOT + "/Keystore/Data/pbkdf2.json").c_str())); - const auto key = TWStoredKeyLoad(filename.get()); + const auto pbkdf2keyPath = string(TESTS_ROOT) + "/Keystore/Data/pbkdf2.json"; + //const auto filename = WRAPS(TWStringCreateWithUTF8Bytes(pbkdf2keyPath.c_str())); + const auto key = TWStoredKeyLoad(&pbkdf2keyPath); + ASSERT_NE(key, nullptr); const auto keyId = WRAPS(TWStoredKeyIdentifier(key)); EXPECT_EQ(string(TWStringUTF8Bytes(keyId.get())), "3198bc9c-6672-5ab3-d995-4942343ae5b6"); TWStoredKeyDelete(key); } TEST(TWStoredKey, loadNonexistent) { - const auto filenameInvalid = WRAPS(TWStringCreateWithUTF8Bytes((TESTS_ROOT + "_NO_/_SUCH_/_FILE_").c_str())); - EXPECT_EQ(TWStoredKeyLoad(filenameInvalid.get()), nullptr); + const string nonexistentPath = string(TESTS_ROOT) + "_NO_/_SUCH_/_FILE_"; + //const auto filenameInvalid = WRAPS(TWStringCreateWithUTF8Bytes(nonexistentPath.c_str())); + EXPECT_EQ(TWStoredKeyLoad(&nonexistentPath), nullptr); } TEST(TWStoredKey, createWallet) { @@ -171,9 +174,9 @@ TEST(TWStoredKey, importJsonInvalid) { } TEST(TWStoredKey, fixAddresses) { - const auto password = "password"; + const string password = "password"; const auto key = createAStoredKey(TWCoinTypeBitcoin, password); - EXPECT_TRUE(TWStoredKeyFixAddresses(key, WRAPS(TWStringCreateWithUTF8Bytes(password)).get())); + EXPECT_TRUE(TWStoredKeyFixAddresses(key, &password)); TWStoredKeyDelete(key); } @@ -192,9 +195,10 @@ TEST(TWStoredKey, importInvalidKey) { } TEST(TWStoredKey, removeAccountForCoin) { - auto password = "password"; - auto key = TWStoredKeyCreate("Test KeyStore", password); - auto wallet = TWStoredKeyWallet(key, password); + const string password = "password"; + const string name = "Test KeyStore"; + auto key = TWStoredKeyCreate(&name, &password); + auto wallet = TWStoredKeyWallet(key, &password); ASSERT_NE(TWStoredKeyAccountForCoin(key, TWCoinTypeEthereum, wallet), nullptr); ASSERT_NE(TWStoredKeyAccountForCoin(key, TWCoinTypeBitcoin, wallet), nullptr); diff --git a/tests/interface/TWTestUtilities.cpp b/tests/interface/TWTestUtilities.cpp index 14d256a89bc..462eac932b9 100644 --- a/tests/interface/TWTestUtilities.cpp +++ b/tests/interface/TWTestUtilities.cpp @@ -7,7 +7,8 @@ #include "TWTestUtilities.h" #include -#include +#include +//include using namespace std; diff --git a/tools/install-dependencies b/tools/install-dependencies index 53536a5afd5..31797bde74b 100755 --- a/tools/install-dependencies +++ b/tools/install-dependencies @@ -26,7 +26,7 @@ tar xzf release-$GTEST_VERSION.tar.gz # Build gtest cd googletest-release-$GTEST_VERSION -cmake -DCMAKE_INSTALL_PREFIX:PATH=$PREFIX -H. +cmake -DCMAKE_INSTALL_PREFIX:PATH=$PREFIX . make make install diff --git a/trezor-crypto/src/bip32.c b/trezor-crypto/src/bip32.c index b397a89abee..3f5d51c610f 100644 --- a/trezor-crypto/src/bip32.c +++ b/trezor-crypto/src/bip32.c @@ -632,11 +632,11 @@ int hdnode_sign(HDNode *node, const uint8_t *msg, uint32_t msg_len, HasherType h } else if (node->curve == &ed25519_keccak_info) { ed25519_sign_keccak(msg, msg_len, node->private_key, node->public_key + 1, sig); } else if (node->curve == &curve25519_info) { - uint8_t ed25519_public_key[32]; - memset(ed25519_public_key, 0, 32); - curve25519_pk_to_ed25519(ed25519_public_key, node->public_key + 1); - ed25519_sign(msg, msg_len, node->private_key, ed25519_public_key, sig); - const uint8_t sign_bit = ed25519_public_key[31] & 0x80; + uint8_t ed25519_public_key_val[32]; + memset(ed25519_public_key_val, 0, 32); + curve25519_pk_to_ed25519(ed25519_public_key_val, node->public_key + 1); + ed25519_sign(msg, msg_len, node->private_key, ed25519_public_key_val, sig); + const uint8_t sign_bit = ed25519_public_key_val[31] & 0x80; sig[63] = sig[63] & 127; sig[63] |= sign_bit; } diff --git a/walletconsole/lib/Coins.cpp b/walletconsole/lib/Coins.cpp index 368c1b9853e..b59344190b2 100644 --- a/walletconsole/lib/Coins.cpp +++ b/walletconsole/lib/Coins.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #define WRAPS(x) std::shared_ptr(x, TWStringDelete) diff --git a/walletconsole/lib/Util.cpp b/walletconsole/lib/Util.cpp index 5a54509998e..97018746885 100644 --- a/walletconsole/lib/Util.cpp +++ b/walletconsole/lib/Util.cpp @@ -14,6 +14,7 @@ #include #include #include +#include namespace TW::WalletConsole { diff --git a/walletconsole/lib/Util.h b/walletconsole/lib/Util.h index f86ed09e34e..5522610339b 100644 --- a/walletconsole/lib/Util.h +++ b/walletconsole/lib/Util.h @@ -8,6 +8,7 @@ #include #include +#include namespace TW::WalletConsole { From 927d36a0ea8a91eea88bb0696af56381d896f4bd Mon Sep 17 00:00:00 2001 From: Bartosz Tarnowski Date: Wed, 8 Apr 2020 14:06:47 +0100 Subject: [PATCH 02/14] DGLD skeleton generated. --- .../digitalgold/TestDigitalGoldAddress.kt | 33 +++++++++++++ .../digitalgold/TestDigitalGoldSigner.kt | 45 +++++++++++++++++ coins.json | 30 ++++++++++++ include/TrustWalletCore/TWCoinType.h | 1 + src/Bitcoin/DgldAddress.cpp | 31 ++++++++++++ src/Bitcoin/DgldAddress.h | 43 +++++++++++++++++ .../Tests/Blockchains/DigitalGoldTests.swift | 28 +++++++++++ tests/DigitalGold/AddressTests.cpp | 48 +++++++++++++++++++ tests/DigitalGold/SignerTests.cpp | 34 +++++++++++++ tests/DigitalGold/TWAnyAddressTests.cpp | 19 ++++++++ tests/DigitalGold/TWAnySignerTests.cpp | 19 ++++++++ tests/DigitalGold/TWCoinTypeTests.cpp | 34 +++++++++++++ 12 files changed, 365 insertions(+) create mode 100644 android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/digitalgold/TestDigitalGoldAddress.kt create mode 100644 android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/digitalgold/TestDigitalGoldSigner.kt create mode 100644 src/Bitcoin/DgldAddress.cpp create mode 100644 src/Bitcoin/DgldAddress.h create mode 100644 swift/Tests/Blockchains/DigitalGoldTests.swift create mode 100644 tests/DigitalGold/AddressTests.cpp create mode 100644 tests/DigitalGold/SignerTests.cpp create mode 100644 tests/DigitalGold/TWAnyAddressTests.cpp create mode 100644 tests/DigitalGold/TWAnySignerTests.cpp create mode 100644 tests/DigitalGold/TWCoinTypeTests.cpp diff --git a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/digitalgold/TestDigitalGoldAddress.kt b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/digitalgold/TestDigitalGoldAddress.kt new file mode 100644 index 00000000000..686b33d4ac4 --- /dev/null +++ b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/digitalgold/TestDigitalGoldAddress.kt @@ -0,0 +1,33 @@ +// Copyright © 2017-2020 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. + +package com.trustwallet.core.app.blockchains.digitalgold + +import com.trustwallet.core.app.utils.toHex +import com.trustwallet.core.app.utils.toHexByteArray +import org.junit.Assert.assertEquals +import org.junit.Test +import wallet.core.jni.* + +class TestDigitalGoldAddress { + + init { + System.loadLibrary("TrustWalletCore") + } + + @Test + fun testAddress() { + // TODO: Check and finalize implementation + + val key = PrivateKey("__PRIVATE_KEY_DATA__".toHexByteArray()) + val pubkey = key.publicKeyEd25519 + val address = AnyAddress(pubkey, CoinType.DIGITALGOLD) + val expected = AnyAddress("__EXPECTED_RESULT_ADDRESS__", CoinType.DIGITALGOLD) + + assertEquals(pubkey.data().toHex(), "0x__EXPECTED_PUBKEY_DATA__") + assertEquals(address.description(), expected.description()) + } +} diff --git a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/digitalgold/TestDigitalGoldSigner.kt b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/digitalgold/TestDigitalGoldSigner.kt new file mode 100644 index 00000000000..b3e2107b3b5 --- /dev/null +++ b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/digitalgold/TestDigitalGoldSigner.kt @@ -0,0 +1,45 @@ +// Copyright © 2017-2020 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. + +package com.trustwallet.core.app.blockchains.digitalgold + +import com.google.protobuf.ByteString +import com.trustwallet.core.app.utils.Numeric +import com.trustwallet.core.app.utils.toHexByteArray +import com.trustwallet.core.app.utils.toHexBytes +import com.trustwallet.core.app.utils.toHexBytesInByteString +import junit.framework.Assert.assertEquals +import org.junit.Test +import wallet.core.jni.BitcoinSigner +import wallet.core.jni.proto.Bitcoin + +class TestDigitalGoldSigner { + + init { + System.loadLibrary("TrustWalletCore") + } + + @Test + fun DigitalGoldTransactionSigning() { + // TODO: Finalize implementation + + //val transfer = DigitalGold.TransferMessage.newBuilder() + // .setTo("...") + // .setAmount(...) + // ... + // .build() + //val signingInput = DigitalGold.SigningInput.newBuilder() + // ... + // .build() + + //val output: DigitalGold.SigningOutput = DigitalGoldSigner.sign(signingInput) + + //assertEquals( + // "__EXPECTED_RESULT_DATA__", + // Numeric.toHexString(output.encoded.toByteArray()) + //) + } +} diff --git a/coins.json b/coins.json index 5fc87eb88cb..e763ba4358c 100644 --- a/coins.json +++ b/coins.json @@ -1332,5 +1332,35 @@ "clientPublic": "", "clientDocs": "https://docs.lotu.sh" } + }, + { + "id": "dgld", + "name": "DigitalGold", + "symbol": "DGLD", + "decimals": 8, + "blockchain": "Bitcoin", + "derivationPath": "m/91'/102'/0'/0/0", + "curve": "secp256k1", + "publicKeyType": "secp256k1", + "p2pkhPrefix": 38, + "p2shPrefix": 97, + "hrp": "bc", + "publicKeyHasher": "sha256ripemd", + "base58Hasher": "sha256d", + "xpub": "zpub", + "xprv": "zprv", + "explorer": { + "url": "https://explorer.dgld.ch", + "txPath": "/tx/", + "accountPath": "/address/", + "sampleTx": "68e203d1837aad907f4c09b22835e78304a7ae5c4268d0c2487958e3a1858b6e", + "sampleAccount": "g3X4Jwf9WLuBqET7tr2bCkDX3A2FGBrUm8" + }, + "info": { + "url": "https://dgld.ch/", + "client": "https://github.com/goldtokensa/ocean-wallet/releases", + "clientPublic": "", + "clientDocs": "https://github.com/goldtokensa/ocean-wallet/releases" + } } ] diff --git a/include/TrustWalletCore/TWCoinType.h b/include/TrustWalletCore/TWCoinType.h index 0c2a152cec0..6bcdde9de09 100644 --- a/include/TrustWalletCore/TWCoinType.h +++ b/include/TrustWalletCore/TWCoinType.h @@ -79,6 +79,7 @@ enum TWCoinType { TWCoinTypeKusama = 434, TWCoinTypePolkadot = 354, TWCoinTypeFilecoin = 461, + TWCoinTypeDigitalGold = 102, }; /// Returns the blockchain for a coin type. diff --git a/src/Bitcoin/DgldAddress.cpp b/src/Bitcoin/DgldAddress.cpp new file mode 100644 index 00000000000..afb46d08542 --- /dev/null +++ b/src/Bitcoin/DgldAddress.cpp @@ -0,0 +1,31 @@ +// Copyright © 2017-2020 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. + +#include "Address.h" + +using namespace TW::Bitcoin; + +bool DlgdAddress::isValid(const std::string& string) { + // TODO: Finalize implementation + return false; +} + +DlgdAddress::DlgdAddress(const std::string& string) { + // TODO: Finalize implementation + + if (!isValid(string)) { + throw std::invalid_argument("Invalid address string"); + } +} + +DlgdAddress::DlgdAddress(const PublicKey& publicKey) { + // TODO: Finalize implementation +} + +std::string DlgdAddress::string() const { + // TODO: Finalize implementation + return "TODO"; +} diff --git a/src/Bitcoin/DgldAddress.h b/src/Bitcoin/DgldAddress.h new file mode 100644 index 00000000000..c678f2ee058 --- /dev/null +++ b/src/Bitcoin/DgldAddress.h @@ -0,0 +1,43 @@ +// Copyright © 2017-2020 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. + +#pragma once + +#include "../Data.h" +#include "../PublicKey.h" + +#include + +namespace TW::Bitcoin { + +class DlgdAddress { + public: + // TODO: Complete class definition + + /// Determines whether a string makes a valid address. + static bool isValid(const std::string& string); + + /// Initializes a DigitalGold address with a string representation. + explicit DlgdAddress(const std::string& string); + + /// Initializes a DigitalGold address with a public key. + explicit DlgdAddress(const PublicKey& publicKey); + + /// Returns a string representation of the address. + std::string string() const; +}; + +inline bool operator==(const DlgdAddress& lhs, const DlgdAddress& rhs) { + // TODO: Complete equality operator + return true; +} + +} // namespace TW::Bitcoin + +/// Wrapper for C interface. +struct TWDigitalGoldAddress { + TW::Bitcoin::DlgdAddress impl; +}; diff --git a/swift/Tests/Blockchains/DigitalGoldTests.swift b/swift/Tests/Blockchains/DigitalGoldTests.swift new file mode 100644 index 00000000000..afa62c10593 --- /dev/null +++ b/swift/Tests/Blockchains/DigitalGoldTests.swift @@ -0,0 +1,28 @@ +// Copyright © 2017-2020 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. + +import TrustWalletCore +import XCTest + +class DigitalGoldTests: XCTestCase { + // TODO: Check and finalize implementation + + func testAddress() { + // TODO: Check and finalize implementation + + let key = PrivateKey(data: Data(hexString: "__PRIVATE_KEY_DATA__")!)! + let pubkey = key.getPublicKeyEd25519() + let address = AnyAddress(publicKey: pubkey, coin: .digitalgold) + let addressFromString = AnyAddress(string: "__ADDRESS_DATA__", coin: .digitalgold)! + + XCTAssertEqual(pubkey.data.hexString, "__EXPECTED_PUBKEY_DATA__") + XCTAssertEqual(address.description, addressFromString.description) + } + + func testSign() { + // TODO: Create implementation + } +} diff --git a/tests/DigitalGold/AddressTests.cpp b/tests/DigitalGold/AddressTests.cpp new file mode 100644 index 00000000000..0b61665e50d --- /dev/null +++ b/tests/DigitalGold/AddressTests.cpp @@ -0,0 +1,48 @@ +// Copyright © 2017-2020 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. + +#include "HexCoding.h" +#include "Bitcoin/DgldAddress.h" +#include "PublicKey.h" +#include "PrivateKey.h" +#include +#include + +using namespace TW; +using namespace TW::Bitcoin; + +TEST(DigitalGoldAddress, Valid) { + ASSERT_TRUE(Address::isValid("__ADD_VALID_ADDRESS_HERE__")); + + // TODO: Add more tests +} + +TEST(DigitalGoldAddress, Invalid) { + ASSERT_FALSE(Address::isValid("__ADD_INVALID_ADDRESS_HERE__")); + + // TODO: Add more tests +} + +TEST(DigitalGoldAddress, FromPrivateKey) { + // TODO: Check public key type, finalize implementation + + auto privateKey = PrivateKey(parse_hex("__PRIVATE_KEY_DATA__")); + auto address = DgldAddress(privateKey.getPublicKey(TWPublicKeyTypeED25519)); + ASSERT_EQ(address.string(), "__ADD_RESULTING_ADDRESS_HERE__"); +} + +TEST(DigitalGoldAddress, FromPublicKey) { + // TODO: Check public key type, finalize implementation + + auto publicKey = PublicKey(parse_hex("__PUBLIC_KEY_DATS__"), TWPublicKeyTypeED25519); + auto address = DgldAddress(publicKey); + ASSERT_EQ(address.string(), "__ADD_RESULTING_ADDRESS_HERE__"); +} + +TEST(DigitalGoldAddress, FromString) { + auto address = Address("__ADD_VALID_ADDRESS_HERE__"); + ASSERT_EQ(address.string(), "__ADD_SAME_VALID_ADDRESS_HERE__"); +} diff --git a/tests/DigitalGold/SignerTests.cpp b/tests/DigitalGold/SignerTests.cpp new file mode 100644 index 00000000000..628f3f61ade --- /dev/null +++ b/tests/DigitalGold/SignerTests.cpp @@ -0,0 +1,34 @@ +// Copyright © 2017-2020 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. + +#include "Bitcoin/Signer.h" +#include "Bitcoin/DgldAddress.h" +#include "HexCoding.h" +#include "PrivateKey.h" +#include "PublicKey.h" + +#include + +using namespace TW; +using namespace TW::Bitcoin; + +// TODO: Add tests + +TEST(DigitalGoldSigner, Sign) { + // TODO: Finalize test implementation + + //auto key = PrivateKey(parse_hex("__PRIVKEY_DATA__")); + //auto publicKey = key.getPublicKey(TWPublicKeyTypeED25519); + //auto from = Address(publicKey); + //auto to = Address("__TO_ADDRESS__"); + //... + //auto transaction = Transaction(...) + //auto signature = Signer::sign(key, transaction); + //auto result = transaction.serialize(signature); + + //ASSERT_EQ(hex(serialized), "__RESULT__"); + //ASSERT_EQ(...) +} diff --git a/tests/DigitalGold/TWAnyAddressTests.cpp b/tests/DigitalGold/TWAnyAddressTests.cpp new file mode 100644 index 00000000000..8537c7bc5a9 --- /dev/null +++ b/tests/DigitalGold/TWAnyAddressTests.cpp @@ -0,0 +1,19 @@ +// Copyright © 2017-2020 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. + +#include +#include "HexCoding.h" + +#include "../interface/TWTestUtilities.h" +#include + +using namespace TW; + +// TODO: Finalize tests + +TEST(TWDigitalGold, Address) { + // TODO: Finalize test implementation +} diff --git a/tests/DigitalGold/TWAnySignerTests.cpp b/tests/DigitalGold/TWAnySignerTests.cpp new file mode 100644 index 00000000000..593acfd700e --- /dev/null +++ b/tests/DigitalGold/TWAnySignerTests.cpp @@ -0,0 +1,19 @@ +// Copyright © 2017-2020 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. + +#include +#include "HexCoding.h" + +#include "../interface/TWTestUtilities.h" +#include + +using namespace TW; + +// TODO: Finalize tests + +TEST(TWAnySignerDigitalGold, Sign) { + // TODO: Finalize test implementation +} diff --git a/tests/DigitalGold/TWCoinTypeTests.cpp b/tests/DigitalGold/TWCoinTypeTests.cpp new file mode 100644 index 00000000000..632e8383af6 --- /dev/null +++ b/tests/DigitalGold/TWCoinTypeTests.cpp @@ -0,0 +1,34 @@ +// Copyright © 2017-2020 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. +// +// This is a GENERATED FILE, changes made here MAY BE LOST. +// Generated one-time (codegen/bin/cointests) +// + +#include "../interface/TWTestUtilities.h" +#include +#include + + +TEST(TWDigitalGoldCoinType, TWCoinType) { + auto symbol = WRAPS(TWCoinTypeConfigurationGetSymbol(TWCoinTypeDigitalGold)); + auto txId = TWStringCreateWithUTF8Bytes("68e203d1837aad907f4c09b22835e78304a7ae5c4268d0c2487958e3a1858b6e"); + auto txUrl = WRAPS(TWCoinTypeConfigurationGetTransactionURL(TWCoinTypeDigitalGold, txId)); + auto accId = TWStringCreateWithUTF8Bytes("g3X4Jwf9WLuBqET7tr2bCkDX3A2FGBrUm8"); + auto accUrl = WRAPS(TWCoinTypeConfigurationGetAccountURL(TWCoinTypeDigitalGold, accId)); + auto id = WRAPS(TWCoinTypeConfigurationGetID(TWCoinTypeDigitalGold)); + auto name = WRAPS(TWCoinTypeConfigurationGetName(TWCoinTypeDigitalGold)); + + ASSERT_EQ(TWCoinTypeConfigurationGetDecimals(TWCoinTypeDigitalGold), 8); + ASSERT_EQ(TWBlockchainBitcoin, TWCoinTypeBlockchain(TWCoinTypeDigitalGold)); + ASSERT_EQ(0x61, TWCoinTypeP2shPrefix(TWCoinTypeDigitalGold)); + ASSERT_EQ(0x0, TWCoinTypeStaticPrefix(TWCoinTypeDigitalGold)); + assertStringsEqual(symbol, "DGLD"); + assertStringsEqual(txUrl, "https://explorer.dgld.ch/tx/68e203d1837aad907f4c09b22835e78304a7ae5c4268d0c2487958e3a1858b6e"); + assertStringsEqual(accUrl, "https://explorer.dgld.ch/address/g3X4Jwf9WLuBqET7tr2bCkDX3A2FGBrUm8"); + assertStringsEqual(id, "dgld"); + assertStringsEqual(name, "DigitalGold"); +} From 189fed6c24a296b36f99718729cd03c8ad8b2b16 Mon Sep 17 00:00:00 2001 From: Bartosz Tarnowski Date: Thu, 9 Apr 2020 16:51:58 +0100 Subject: [PATCH 03/14] DGLD address logic. --- docs/coins.md | 1 + src/Base58Address.h | 7 ++-- src/Bitcoin/DgldAddress.cpp | 23 +----------- src/Bitcoin/DgldAddress.h | 58 +++++++++++++++++++++++------- src/Data.h | 4 +++ tests/DigitalGold/AddressTests.cpp | 37 ++++++++++++------- 6 files changed, 80 insertions(+), 50 deletions(-) diff --git a/docs/coins.md b/docs/coins.md index bd8b83ac4f5..5ec00b79182 100644 --- a/docs/coins.md +++ b/docs/coins.md @@ -16,6 +16,7 @@ This list is generated from [./coins.json](../coins.json) | 60 | Ethereum | ETH | | | | 61 | Ethereum Classic | ETC | | | | 74 | ICON | ICX | | | +| 102 | DigitalGold | DGLD | | | | 118 | Cosmos | ATOM | | | | 133 | Zcash | ZEC | | | | 136 | Zcoin | XZC | | | diff --git a/src/Base58Address.h b/src/Base58Address.h index c294f364161..1a887cc9c63 100644 --- a/src/Base58Address.h +++ b/src/Base58Address.h @@ -26,10 +26,13 @@ class Base58Address { std::array bytes; /// Determines whether a collection of bytes makes a valid address. - template - static bool isValid(const T& data) { + static bool isValid(const Data& data) { return data.size() == size; } + /*template + static bool isValid(const T& data) { + return data.size() == size; + }*/ /// Determines whether a string makes a valid address. static bool isValid(const std::string& string) { diff --git a/src/Bitcoin/DgldAddress.cpp b/src/Bitcoin/DgldAddress.cpp index afb46d08542..1ccdf90ddc1 100644 --- a/src/Bitcoin/DgldAddress.cpp +++ b/src/Bitcoin/DgldAddress.cpp @@ -4,28 +4,7 @@ // terms governing use, modification, and redistribution, is contained in the // file LICENSE at the root of the source code distribution tree. -#include "Address.h" +#include "DgldAddress.h" using namespace TW::Bitcoin; -bool DlgdAddress::isValid(const std::string& string) { - // TODO: Finalize implementation - return false; -} - -DlgdAddress::DlgdAddress(const std::string& string) { - // TODO: Finalize implementation - - if (!isValid(string)) { - throw std::invalid_argument("Invalid address string"); - } -} - -DlgdAddress::DlgdAddress(const PublicKey& publicKey) { - // TODO: Finalize implementation -} - -std::string DlgdAddress::string() const { - // TODO: Finalize implementation - return "TODO"; -} diff --git a/src/Bitcoin/DgldAddress.h b/src/Bitcoin/DgldAddress.h index c678f2ee058..2f686c28e84 100644 --- a/src/Bitcoin/DgldAddress.h +++ b/src/Bitcoin/DgldAddress.h @@ -9,35 +9,67 @@ #include "../Data.h" #include "../PublicKey.h" +#include "Address.h" +#include "SegwitAddress.h" + #include namespace TW::Bitcoin { -class DlgdAddress { +class DgldAddress : public Address { public: - // TODO: Complete class definition - /// Determines whether a string makes a valid address. - static bool isValid(const std::string& string); + static const byte ADDRTYPE_P2PKH = 38; + static const byte ADDRTYPE_P2SH = 97; + + explicit DgldAddress(const std::string& string) : Address(string) {} + /// Initializes a address with a collection of bytes. + explicit DgldAddress(const Data& data) : Address(data) {} + + /// Initializes a address with a public key and a prefix. + DgldAddress(const PublicKey& publicKey, byte prefix) : Address(publicKey, prefix) {} + + DgldAddress(const PublicKey& publicKey) : Address(publicKey, ADDRTYPE_P2PKH) {} + + static bool isValid(const std::string& string) { + return Address::isValid(string, {TW::data(ADDRTYPE_P2PKH), TW::data(ADDRTYPE_P2SH)}); + } +}; + + +inline bool operator==(const DgldAddress& lhs, const DgldAddress& rhs) { + return lhs.string() == rhs.string(); +} + + +/* - /// Initializes a DigitalGold address with a string representation. - explicit DlgdAddress(const std::string& string); +class DgldSegwitAddress : public SegwitAddress { + public: - /// Initializes a DigitalGold address with a public key. - explicit DlgdAddress(const PublicKey& publicKey); + DgldSegwitAddress(std::string hrp, int witver, std::vector witprog) : SegwitAddress(hrp, witver, witprog) {} - /// Returns a string representation of the address. - std::string string() const; + DgldSegwitAddress(const PublicKey& publicKey, int witver, std::string hrp) : SegwitAddress(publicKey, witver, hrp) {} }; -inline bool operator==(const DlgdAddress& lhs, const DlgdAddress& rhs) { + +inline bool operator==(const DgldSegwitAddress& lhs, const DgldSegwitAddress& rhs) { // TODO: Complete equality operator - return true; + return (&lhs) == (&rhs); } +*/ + } // namespace TW::Bitcoin /// Wrapper for C interface. struct TWDigitalGoldAddress { - TW::Bitcoin::DlgdAddress impl; + TW::Bitcoin::DgldAddress impl; +}; + +/* +struct TWDigitalGoldSegwitAddress { + TW::Bitcoin::DgldSegwitAddress impl; }; +*/ + diff --git a/src/Data.h b/src/Data.h index 4e80e18865a..3592ff89196 100644 --- a/src/Data.h +++ b/src/Data.h @@ -28,6 +28,10 @@ inline Data data(const byte* data, size_t size) { return std::vector(data, data + size); } +inline Data data(byte b) { + return std::vector({b}); +} + inline void append(Data& data, const Data& suffix) { data.insert(data.end(), suffix.begin(), suffix.end()); } diff --git a/tests/DigitalGold/AddressTests.cpp b/tests/DigitalGold/AddressTests.cpp index 0b61665e50d..42ae74516bc 100644 --- a/tests/DigitalGold/AddressTests.cpp +++ b/tests/DigitalGold/AddressTests.cpp @@ -15,34 +15,45 @@ using namespace TW; using namespace TW::Bitcoin; TEST(DigitalGoldAddress, Valid) { - ASSERT_TRUE(Address::isValid("__ADD_VALID_ADDRESS_HERE__")); - - // TODO: Add more tests + ASSERT_TRUE(DgldAddress::isValid("GJCMxPGMH3LVoGtZ3yEhPYbMVnYwSybBzi")); + ASSERT_TRUE(DgldAddress::isValid("GaLFdPjbDVGcv7v6xuhbvpXUq8mtMkR24y")); + ASSERT_TRUE(DgldAddress::isValid("GfxjHLysUq5XmPqtYPVyzdVm39QSDpFdET")); + ASSERT_TRUE(DgldAddress::isValid("Gdzoxj6QFLDndw5htN2hLJ8JwKRWYHdX2K")); + ASSERT_TRUE(DgldAddress::isValid("GJKt1CQ4wj2i7QTL2VzhXGQ7u7uUXJ7s5A")); + ASSERT_TRUE(DgldAddress::isValid("Gc5JdxYv2k1FfJMr689J66VxQ4yGp97GzZ")); + ASSERT_TRUE(DgldAddress::isValid("GdfXJwBdQUwD1nuySrQeZjFw8KEtPEoBeB")); + ASSERT_TRUE(DgldAddress::isValid("GcSsKzmisNB5KCH6wJr6NZyoSMyydVvi22")); + ASSERT_TRUE(DgldAddress::isValid("GKm9Uj8R6MPqNw2xkhXNYKsvUy46n8E655")); + ASSERT_TRUE(DgldAddress::isValid("GJu16E3CmFdSknrzbKpXacW2MPoLwiesTv")); + ASSERT_TRUE(DgldAddress::isValid("GTWUe2J9amAkhGm6ePrg2knPXYwNZWL2AH")); + ASSERT_TRUE(DgldAddress::isValid("GJBJoGst6SPYweTdE2rLXpc7ky3JaN8s3M")); + ASSERT_TRUE(DgldAddress::isValid("GYPHQbxED8GFtpHkZShNzAxyZDrUVKjPFC")); + + // TODO: test segwit addresses } TEST(DigitalGoldAddress, Invalid) { - ASSERT_FALSE(Address::isValid("__ADD_INVALID_ADDRESS_HERE__")); + ASSERT_FALSE(DgldAddress::isValid("GZ8fKGGqBZtenPR8hL-----BpMcagkXg5g")); + ASSERT_FALSE(DgldAddress::isValid("1MVk8kVbs7nepTGwbQN1H46UDjSDAUgcRU")); // valid bitcoin address, but invalid dgld address // TODO: Add more tests } TEST(DigitalGoldAddress, FromPrivateKey) { // TODO: Check public key type, finalize implementation - - auto privateKey = PrivateKey(parse_hex("__PRIVATE_KEY_DATA__")); - auto address = DgldAddress(privateKey.getPublicKey(TWPublicKeyTypeED25519)); - ASSERT_EQ(address.string(), "__ADD_RESULTING_ADDRESS_HERE__"); + auto privateKey = PrivateKey(parse_hex("63832fb769a6f12b0a403b8906d6b718a3994b1c1ace78be359a7ff39b3a7362")); + auto address = DgldAddress(privateKey.getPublicKey(TWPublicKeyTypeSECP256k1)); + ASSERT_EQ(address.string(), "GNxs8kNGP4E18is7TRvjh9WknrStwMmS2N"); } TEST(DigitalGoldAddress, FromPublicKey) { // TODO: Check public key type, finalize implementation - - auto publicKey = PublicKey(parse_hex("__PUBLIC_KEY_DATS__"), TWPublicKeyTypeED25519); + auto publicKey = PublicKey(parse_hex("028bd49b59eaa0aa4485ef35bc0433cf5071eeb41b229d17c5563d935ca474a9b4"), TWPublicKeyTypeSECP256k1); auto address = DgldAddress(publicKey); - ASSERT_EQ(address.string(), "__ADD_RESULTING_ADDRESS_HERE__"); + ASSERT_EQ(address.string(), "GSvAp2iiodmfkuS4xcpAyJo7s5xhPGw6YY"); } TEST(DigitalGoldAddress, FromString) { - auto address = Address("__ADD_VALID_ADDRESS_HERE__"); - ASSERT_EQ(address.string(), "__ADD_SAME_VALID_ADDRESS_HERE__"); + auto address = DgldAddress("GRZ3JdwD4LuiJd2x7kKfFVJr6MdHREj7ie"); + ASSERT_EQ(address.string(), "GRZ3JdwD4LuiJd2x7kKfFVJr6MdHREj7ie"); } From 7a965ebb08ee461cff2187e104ed0d24460f17c3 Mon Sep 17 00:00:00 2001 From: Bartosz Tarnowski Date: Tue, 14 Apr 2020 12:29:37 +0100 Subject: [PATCH 04/14] Derivation path changed to reflect BIP44. --- coins.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coins.json b/coins.json index e763ba4358c..5456f66e45a 100644 --- a/coins.json +++ b/coins.json @@ -1339,7 +1339,7 @@ "symbol": "DGLD", "decimals": 8, "blockchain": "Bitcoin", - "derivationPath": "m/91'/102'/0'/0/0", + "derivationPath": "m/44'/102'/0'/0/0", "curve": "secp256k1", "publicKeyType": "secp256k1", "p2pkhPrefix": 38, From 530600338a4a5268fa796a18fac7ab3bcf17e787 Mon Sep 17 00:00:00 2001 From: Bartosz Tarnowski Date: Tue, 14 Apr 2020 13:18:55 +0100 Subject: [PATCH 05/14] Fix for tests. --- tests/interface/TWStoredKeyTests.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/tests/interface/TWStoredKeyTests.cpp b/tests/interface/TWStoredKeyTests.cpp index b2333cf4408..b769752db9b 100644 --- a/tests/interface/TWStoredKeyTests.cpp +++ b/tests/interface/TWStoredKeyTests.cpp @@ -38,19 +38,16 @@ struct TWStoredKey *_Nonnull createDefaultStoredKey() { } TEST(TWStoredKey, loadPBKDF2Key) { - const auto pbkdf2keyPath = string(TESTS_ROOT) + "/Keystore/Data/pbkdf2.json"; - //const auto filename = WRAPS(TWStringCreateWithUTF8Bytes(pbkdf2keyPath.c_str())); - const auto key = TWStoredKeyLoad(&pbkdf2keyPath); - ASSERT_NE(key, nullptr); + const auto filename = WRAPS(TWStringCreateWithUTF8Bytes((TESTS_ROOT + "/Keystore/Data/pbkdf2.json").c_str())); + const auto key = TWStoredKeyLoad(filename.get()); const auto keyId = WRAPS(TWStoredKeyIdentifier(key)); EXPECT_EQ(string(TWStringUTF8Bytes(keyId.get())), "3198bc9c-6672-5ab3-d995-4942343ae5b6"); TWStoredKeyDelete(key); } TEST(TWStoredKey, loadNonexistent) { - const string nonexistentPath = string(TESTS_ROOT) + "_NO_/_SUCH_/_FILE_"; - //const auto filenameInvalid = WRAPS(TWStringCreateWithUTF8Bytes(nonexistentPath.c_str())); - EXPECT_EQ(TWStoredKeyLoad(&nonexistentPath), nullptr); + const auto filenameInvalid = WRAPS(TWStringCreateWithUTF8Bytes((TESTS_ROOT + "_NO_/_SUCH_/_FILE_").c_str())); + EXPECT_EQ(TWStoredKeyLoad(filenameInvalid.get()), nullptr); } TEST(TWStoredKey, createWallet) { @@ -174,9 +171,9 @@ TEST(TWStoredKey, importJsonInvalid) { } TEST(TWStoredKey, fixAddresses) { - const string password = "password"; + const auto password = "password"; const auto key = createAStoredKey(TWCoinTypeBitcoin, password); - EXPECT_TRUE(TWStoredKeyFixAddresses(key, &password)); + EXPECT_TRUE(TWStoredKeyFixAddresses(key, WRAPS(TWStringCreateWithUTF8Bytes(password)).get())); TWStoredKeyDelete(key); } @@ -195,10 +192,9 @@ TEST(TWStoredKey, importInvalidKey) { } TEST(TWStoredKey, removeAccountForCoin) { - const string password = "password"; - const string name = "Test KeyStore"; - auto key = TWStoredKeyCreate(&name, &password); - auto wallet = TWStoredKeyWallet(key, &password); + auto password = "password"; + auto key = TWStoredKeyCreate("Test KeyStore", password); + auto wallet = TWStoredKeyWallet(key, password); ASSERT_NE(TWStoredKeyAccountForCoin(key, TWCoinTypeEthereum, wallet), nullptr); ASSERT_NE(TWStoredKeyAccountForCoin(key, TWCoinTypeBitcoin, wallet), nullptr); From 30f4f4e2d270b562d163dee7f1b72de561b6b0aa Mon Sep 17 00:00:00 2001 From: Bartosz Tarnowski Date: Wed, 15 Apr 2020 13:33:15 +0100 Subject: [PATCH 06/14] Build fixes. --- cmake/Protobuf.cmake | 4 ++-- tests/CMakeLists.txt | 2 +- trezor-crypto/tests/CMakeLists.txt | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmake/Protobuf.cmake b/cmake/Protobuf.cmake index c9a6af88215..72f271d70d8 100644 --- a/cmake/Protobuf.cmake +++ b/cmake/Protobuf.cmake @@ -1,5 +1,5 @@ -set(protobuf_SOURCE_DIR ${CMAKE_SOURCE_DIR}/wallet-core/build/protobuf/staging/protobuf-3.9.0) -set(protobuf_source_dir ${CMAKE_SOURCE_DIR}/wallet-core/build/protobuf/staging/protobuf-3.9.0) +set(protobuf_SOURCE_DIR ${CMAKE_SOURCE_DIR}/build/protobuf/staging/protobuf-3.9.0) +set(protobuf_source_dir ${CMAKE_SOURCE_DIR}/build/protobuf/staging/protobuf-3.9.0) # Updated from https://github.com/protocolbuffers/protobuf/blob/master/cmake/libprotopuf.cmake diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f74d949fcdb..be1569b89cd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,7 +6,7 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # Add googletest directly to our build. This defines # the gtest and gtest_main targets. -add_subdirectory(${CMAKE_SOURCE_DIR}/wallet-core/build/gtest/staging/googletest-release-1.8.1 +add_subdirectory(${CMAKE_SOURCE_DIR}/build/gtest/staging/googletest-release-1.8.1 ${CMAKE_CURRENT_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL) diff --git a/trezor-crypto/tests/CMakeLists.txt b/trezor-crypto/tests/CMakeLists.txt index 36f9ca1bbb8..53420c90f7d 100644 --- a/trezor-crypto/tests/CMakeLists.txt +++ b/trezor-crypto/tests/CMakeLists.txt @@ -1,10 +1,10 @@ enable_testing() -find_library(check PATH ${CMAKE_SOURCE_DIR}/wallet-core/build/local/lib/pkgconfig NO_DEFAULT_PATH) +find_library(check PATH ${CMAKE_SOURCE_DIR}/build/local/lib/pkgconfig NO_DEFAULT_PATH) # Test executable add_executable(TrezorCryptoTests test_check.c) target_link_libraries(TrezorCryptoTests TrezorCrypto check) -target_include_directories(TrezorCryptoTests PRIVATE ${CMAKE_SOURCE_DIR}/wallet-core/src) +target_include_directories(TrezorCryptoTests PRIVATE ${CMAKE_SOURCE_DIR}/src) add_test(NAME test_check COMMAND TrezorCryptoTests) From 35238ebef87fca488692ae0093b39a4f3a8496a1 Mon Sep 17 00:00:00 2001 From: Bartosz Tarnowski Date: Wed, 15 Apr 2020 14:13:37 +0100 Subject: [PATCH 07/14] Entry code for DGLD. Coin parameters update. --- coins.json | 2 +- docs/coins.md | 2 +- include/TrustWalletCore/TWCoinType.h | 2 +- src/Bitcoin/DgldAddress.cpp | 10 ---------- src/Bitcoin/DgldAddress.h | 24 ------------------------ src/Bitcoin/Entry.cpp | 7 +++++++ src/Bitcoin/Entry.h | 1 + 7 files changed, 11 insertions(+), 37 deletions(-) delete mode 100644 src/Bitcoin/DgldAddress.cpp diff --git a/coins.json b/coins.json index 5456f66e45a..2d434d519e9 100644 --- a/coins.json +++ b/coins.json @@ -1339,7 +1339,7 @@ "symbol": "DGLD", "decimals": 8, "blockchain": "Bitcoin", - "derivationPath": "m/44'/102'/0'/0/0", + "derivationPath": "m/44'/452'/0'/0/0", "curve": "secp256k1", "publicKeyType": "secp256k1", "p2pkhPrefix": 38, diff --git a/docs/coins.md b/docs/coins.md index 5ec00b79182..0dc358583fb 100644 --- a/docs/coins.md +++ b/docs/coins.md @@ -16,7 +16,6 @@ This list is generated from [./coins.json](../coins.json) | 60 | Ethereum | ETH | | | | 61 | Ethereum Classic | ETC | | | | 74 | ICON | ICX | | | -| 102 | DigitalGold | DGLD | | | | 118 | Cosmos | ATOM | | | | 133 | Zcash | ZEC | | | | 136 | Zcoin | XZC | | | @@ -39,6 +38,7 @@ This list is generated from [./coins.json](../coins.json) | 397 | NEAR | NEAR | | | | 425 | Aion | AION | | | | 434 | Kusama | KSM | | | +| 452 | DigitalGold | DGLD | | | | 457 | Aeternity | AE | | | | 459 | Kava | KAVA | | | | 461 | Filecoin | FIL | | | diff --git a/include/TrustWalletCore/TWCoinType.h b/include/TrustWalletCore/TWCoinType.h index 6bcdde9de09..74a26ba3a88 100644 --- a/include/TrustWalletCore/TWCoinType.h +++ b/include/TrustWalletCore/TWCoinType.h @@ -79,7 +79,7 @@ enum TWCoinType { TWCoinTypeKusama = 434, TWCoinTypePolkadot = 354, TWCoinTypeFilecoin = 461, - TWCoinTypeDigitalGold = 102, + TWCoinTypeDigitalGold = 452, }; /// Returns the blockchain for a coin type. diff --git a/src/Bitcoin/DgldAddress.cpp b/src/Bitcoin/DgldAddress.cpp deleted file mode 100644 index 1ccdf90ddc1..00000000000 --- a/src/Bitcoin/DgldAddress.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright © 2017-2020 Trust Wallet. -// -// This file is part of Trust. The full Trust copyright notice, including -// terms governing use, modification, and redistribution, is contained in the -// file LICENSE at the root of the source code distribution tree. - -#include "DgldAddress.h" - -using namespace TW::Bitcoin; - diff --git a/src/Bitcoin/DgldAddress.h b/src/Bitcoin/DgldAddress.h index 2f686c28e84..396712c3056 100644 --- a/src/Bitcoin/DgldAddress.h +++ b/src/Bitcoin/DgldAddress.h @@ -42,24 +42,6 @@ inline bool operator==(const DgldAddress& lhs, const DgldAddress& rhs) { } -/* - -class DgldSegwitAddress : public SegwitAddress { - public: - - DgldSegwitAddress(std::string hrp, int witver, std::vector witprog) : SegwitAddress(hrp, witver, witprog) {} - - DgldSegwitAddress(const PublicKey& publicKey, int witver, std::string hrp) : SegwitAddress(publicKey, witver, hrp) {} -}; - - -inline bool operator==(const DgldSegwitAddress& lhs, const DgldSegwitAddress& rhs) { - // TODO: Complete equality operator - return (&lhs) == (&rhs); -} - -*/ - } // namespace TW::Bitcoin /// Wrapper for C interface. @@ -67,9 +49,3 @@ struct TWDigitalGoldAddress { TW::Bitcoin::DgldAddress impl; }; -/* -struct TWDigitalGoldSegwitAddress { - TW::Bitcoin::DgldSegwitAddress impl; -}; -*/ - diff --git a/src/Bitcoin/Entry.cpp b/src/Bitcoin/Entry.cpp index a64de869007..e2236061de3 100644 --- a/src/Bitcoin/Entry.cpp +++ b/src/Bitcoin/Entry.cpp @@ -9,6 +9,7 @@ #include "Address.h" #include "CashAddress.h" #include "SegwitAddress.h" +#include "DgldAddress.h" #include "Signer.h" using namespace TW::Bitcoin; @@ -29,6 +30,9 @@ bool Entry::validateAddress(TWCoinType coin, const string& address, TW::byte p2p return CashAddress::isValid(address) || Address::isValid(address, {{p2pkh}, {p2sh}}); + case TWCoinTypeDigitalGold: + return DgldAddress::isValid(address); + case TWCoinTypeDash: case TWCoinTypeDogecoin: case TWCoinTypeRavencoin: @@ -65,6 +69,9 @@ string Entry::deriveAddress(TWCoinType coin, const PublicKey& publicKey, TW::byt case TWCoinTypeBitcoinCash: return CashAddress(publicKey).string(); + case TWCoinTypeDigitalGold: + return DgldAddress(publicKey).string(); + case TWCoinTypeDash: case TWCoinTypeDogecoin: case TWCoinTypeMonacoin: diff --git a/src/Bitcoin/Entry.h b/src/Bitcoin/Entry.h index 51e0de06ad8..8a9ec707f88 100644 --- a/src/Bitcoin/Entry.h +++ b/src/Bitcoin/Entry.h @@ -27,6 +27,7 @@ class Entry: public CoinEntry { TWCoinTypeRavencoin, TWCoinTypeViacoin, TWCoinTypeZcoin, + TWCoinTypeDigitalGold, }; } virtual bool validateAddress(TWCoinType coin, const std::string& address, TW::byte p2pkh, TW::byte p2sh, const char* hrp) const; From 5e046a2988bf67518a827ac59e573020dcf339a2 Mon Sep 17 00:00:00 2001 From: Bartosz Tarnowski Date: Thu, 16 Apr 2020 11:16:48 +0100 Subject: [PATCH 08/14] DGLD address logic simplified. --- src/Bitcoin/DgldAddress.h | 51 ---------------------------- src/Bitcoin/Entry.cpp | 9 ++--- tests/DigitalGold/AddressTests.cpp | 53 ++++++++++++++++++------------ tests/DigitalGold/SignerTests.cpp | 2 +- 4 files changed, 35 insertions(+), 80 deletions(-) delete mode 100644 src/Bitcoin/DgldAddress.h diff --git a/src/Bitcoin/DgldAddress.h b/src/Bitcoin/DgldAddress.h deleted file mode 100644 index 396712c3056..00000000000 --- a/src/Bitcoin/DgldAddress.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright © 2017-2020 Trust Wallet. -// -// This file is part of Trust. The full Trust copyright notice, including -// terms governing use, modification, and redistribution, is contained in the -// file LICENSE at the root of the source code distribution tree. - -#pragma once - -#include "../Data.h" -#include "../PublicKey.h" - -#include "Address.h" -#include "SegwitAddress.h" - -#include - -namespace TW::Bitcoin { - -class DgldAddress : public Address { - public: - - static const byte ADDRTYPE_P2PKH = 38; - static const byte ADDRTYPE_P2SH = 97; - - explicit DgldAddress(const std::string& string) : Address(string) {} - /// Initializes a address with a collection of bytes. - explicit DgldAddress(const Data& data) : Address(data) {} - - /// Initializes a address with a public key and a prefix. - DgldAddress(const PublicKey& publicKey, byte prefix) : Address(publicKey, prefix) {} - - DgldAddress(const PublicKey& publicKey) : Address(publicKey, ADDRTYPE_P2PKH) {} - - static bool isValid(const std::string& string) { - return Address::isValid(string, {TW::data(ADDRTYPE_P2PKH), TW::data(ADDRTYPE_P2SH)}); - } -}; - - -inline bool operator==(const DgldAddress& lhs, const DgldAddress& rhs) { - return lhs.string() == rhs.string(); -} - - -} // namespace TW::Bitcoin - -/// Wrapper for C interface. -struct TWDigitalGoldAddress { - TW::Bitcoin::DgldAddress impl; -}; - diff --git a/src/Bitcoin/Entry.cpp b/src/Bitcoin/Entry.cpp index e2236061de3..2d548ee17ec 100644 --- a/src/Bitcoin/Entry.cpp +++ b/src/Bitcoin/Entry.cpp @@ -9,7 +9,6 @@ #include "Address.h" #include "CashAddress.h" #include "SegwitAddress.h" -#include "DgldAddress.h" #include "Signer.h" using namespace TW::Bitcoin; @@ -23,6 +22,7 @@ bool Entry::validateAddress(TWCoinType coin, const string& address, TW::byte p2p case TWCoinTypeMonacoin: case TWCoinTypeQtum: case TWCoinTypeViacoin: + case TWCoinTypeDigitalGold: return SegwitAddress::isValid(address, hrp) || Address::isValid(address, {{p2pkh}, {p2sh}}); @@ -30,9 +30,6 @@ bool Entry::validateAddress(TWCoinType coin, const string& address, TW::byte p2p return CashAddress::isValid(address) || Address::isValid(address, {{p2pkh}, {p2sh}}); - case TWCoinTypeDigitalGold: - return DgldAddress::isValid(address); - case TWCoinTypeDash: case TWCoinTypeDogecoin: case TWCoinTypeRavencoin: @@ -69,15 +66,13 @@ string Entry::deriveAddress(TWCoinType coin, const PublicKey& publicKey, TW::byt case TWCoinTypeBitcoinCash: return CashAddress(publicKey).string(); - case TWCoinTypeDigitalGold: - return DgldAddress(publicKey).string(); - case TWCoinTypeDash: case TWCoinTypeDogecoin: case TWCoinTypeMonacoin: case TWCoinTypeQtum: case TWCoinTypeRavencoin: case TWCoinTypeZcoin: + case TWCoinTypeDigitalGold: default: return Address(publicKey, p2pkh).string(); } diff --git a/tests/DigitalGold/AddressTests.cpp b/tests/DigitalGold/AddressTests.cpp index 42ae74516bc..ae22b98df65 100644 --- a/tests/DigitalGold/AddressTests.cpp +++ b/tests/DigitalGold/AddressTests.cpp @@ -5,7 +5,8 @@ // file LICENSE at the root of the source code distribution tree. #include "HexCoding.h" -#include "Bitcoin/DgldAddress.h" +#include "Bitcoin/Address.h" +#include "Coin.h" #include "PublicKey.h" #include "PrivateKey.h" #include @@ -15,45 +16,55 @@ using namespace TW; using namespace TW::Bitcoin; TEST(DigitalGoldAddress, Valid) { - ASSERT_TRUE(DgldAddress::isValid("GJCMxPGMH3LVoGtZ3yEhPYbMVnYwSybBzi")); - ASSERT_TRUE(DgldAddress::isValid("GaLFdPjbDVGcv7v6xuhbvpXUq8mtMkR24y")); - ASSERT_TRUE(DgldAddress::isValid("GfxjHLysUq5XmPqtYPVyzdVm39QSDpFdET")); - ASSERT_TRUE(DgldAddress::isValid("Gdzoxj6QFLDndw5htN2hLJ8JwKRWYHdX2K")); - ASSERT_TRUE(DgldAddress::isValid("GJKt1CQ4wj2i7QTL2VzhXGQ7u7uUXJ7s5A")); - ASSERT_TRUE(DgldAddress::isValid("Gc5JdxYv2k1FfJMr689J66VxQ4yGp97GzZ")); - ASSERT_TRUE(DgldAddress::isValid("GdfXJwBdQUwD1nuySrQeZjFw8KEtPEoBeB")); - ASSERT_TRUE(DgldAddress::isValid("GcSsKzmisNB5KCH6wJr6NZyoSMyydVvi22")); - ASSERT_TRUE(DgldAddress::isValid("GKm9Uj8R6MPqNw2xkhXNYKsvUy46n8E655")); - ASSERT_TRUE(DgldAddress::isValid("GJu16E3CmFdSknrzbKpXacW2MPoLwiesTv")); - ASSERT_TRUE(DgldAddress::isValid("GTWUe2J9amAkhGm6ePrg2knPXYwNZWL2AH")); - ASSERT_TRUE(DgldAddress::isValid("GJBJoGst6SPYweTdE2rLXpc7ky3JaN8s3M")); - ASSERT_TRUE(DgldAddress::isValid("GYPHQbxED8GFtpHkZShNzAxyZDrUVKjPFC")); + ASSERT_TRUE(Address::isValid("GJCMxPGMH3LVoGtZ3yEhPYbMVnYwSybBzi")); + ASSERT_TRUE(Address::isValid("GaLFdPjbDVGcv7v6xuhbvpXUq8mtMkR24y")); + ASSERT_TRUE(Address::isValid("GfxjHLysUq5XmPqtYPVyzdVm39QSDpFdET")); + ASSERT_TRUE(Address::isValid("Gdzoxj6QFLDndw5htN2hLJ8JwKRWYHdX2K")); + ASSERT_TRUE(Address::isValid("GJKt1CQ4wj2i7QTL2VzhXGQ7u7uUXJ7s5A")); + ASSERT_TRUE(Address::isValid("Gc5JdxYv2k1FfJMr689J66VxQ4yGp97GzZ")); + ASSERT_TRUE(Address::isValid("GdfXJwBdQUwD1nuySrQeZjFw8KEtPEoBeB")); + ASSERT_TRUE(Address::isValid("GcSsKzmisNB5KCH6wJr6NZyoSMyydVvi22")); + ASSERT_TRUE(Address::isValid("GKm9Uj8R6MPqNw2xkhXNYKsvUy46n8E655")); + ASSERT_TRUE(Address::isValid("GJu16E3CmFdSknrzbKpXacW2MPoLwiesTv")); + ASSERT_TRUE(Address::isValid("GTWUe2J9amAkhGm6ePrg2knPXYwNZWL2AH")); + ASSERT_TRUE(Address::isValid("GJBJoGst6SPYweTdE2rLXpc7ky3JaN8s3M")); + ASSERT_TRUE(Address::isValid("GYPHQbxED8GFtpHkZShNzAxyZDrUVKjPFC")); // TODO: test segwit addresses } TEST(DigitalGoldAddress, Invalid) { - ASSERT_FALSE(DgldAddress::isValid("GZ8fKGGqBZtenPR8hL-----BpMcagkXg5g")); - ASSERT_FALSE(DgldAddress::isValid("1MVk8kVbs7nepTGwbQN1H46UDjSDAUgcRU")); // valid bitcoin address, but invalid dgld address + + const byte p2pkh = p2pkhPrefix(TWCoinTypeDigitalGold); + const byte p2sh = p2shPrefix(TWCoinTypeDigitalGold); + + ASSERT_FALSE(Address::isValid("GZ8fKGGqBZtenPR8hL-----BpMcagkXg5g")); + ASSERT_FALSE(Address::isValid("1MVk8kVbs7nepTGwbQN1H46UDjSDAUgcRU", {{p2pkh}, {p2sh}})); // valid bitcoin address, but invalid dgld address // TODO: Add more tests } TEST(DigitalGoldAddress, FromPrivateKey) { - // TODO: Check public key type, finalize implementation + + const byte p2pkh = p2pkhPrefix(TWCoinTypeDigitalGold); + const byte p2sh = p2shPrefix(TWCoinTypeDigitalGold); + auto privateKey = PrivateKey(parse_hex("63832fb769a6f12b0a403b8906d6b718a3994b1c1ace78be359a7ff39b3a7362")); - auto address = DgldAddress(privateKey.getPublicKey(TWPublicKeyTypeSECP256k1)); + auto address = Address(privateKey.getPublicKey(TWPublicKeyTypeSECP256k1), p2pkh); ASSERT_EQ(address.string(), "GNxs8kNGP4E18is7TRvjh9WknrStwMmS2N"); } TEST(DigitalGoldAddress, FromPublicKey) { - // TODO: Check public key type, finalize implementation + + const byte p2pkh = p2pkhPrefix(TWCoinTypeDigitalGold); + const byte p2sh = p2shPrefix(TWCoinTypeDigitalGold); + auto publicKey = PublicKey(parse_hex("028bd49b59eaa0aa4485ef35bc0433cf5071eeb41b229d17c5563d935ca474a9b4"), TWPublicKeyTypeSECP256k1); - auto address = DgldAddress(publicKey); + auto address = Address(publicKey, p2pkh); ASSERT_EQ(address.string(), "GSvAp2iiodmfkuS4xcpAyJo7s5xhPGw6YY"); } TEST(DigitalGoldAddress, FromString) { - auto address = DgldAddress("GRZ3JdwD4LuiJd2x7kKfFVJr6MdHREj7ie"); + auto address = Address("GRZ3JdwD4LuiJd2x7kKfFVJr6MdHREj7ie"); ASSERT_EQ(address.string(), "GRZ3JdwD4LuiJd2x7kKfFVJr6MdHREj7ie"); } diff --git a/tests/DigitalGold/SignerTests.cpp b/tests/DigitalGold/SignerTests.cpp index 628f3f61ade..789de98713d 100644 --- a/tests/DigitalGold/SignerTests.cpp +++ b/tests/DigitalGold/SignerTests.cpp @@ -5,7 +5,7 @@ // file LICENSE at the root of the source code distribution tree. #include "Bitcoin/Signer.h" -#include "Bitcoin/DgldAddress.h" +#include "Bitcoin/Address.h" #include "HexCoding.h" #include "PrivateKey.h" #include "PublicKey.h" From 17dcd2406b39086a7c504441daa8a8b3abd6879b Mon Sep 17 00:00:00 2001 From: Bartosz Tarnowski Date: Tue, 28 Apr 2020 13:46:12 +0100 Subject: [PATCH 09/14] Build system fixes to allow compilation on Linux for Android. Package version updates. --- CMakeLists.txt | 23 ++++++++++++++++++++++- android/app/build.gradle | 18 +++++++++--------- android/build.gradle | 4 ++-- android/trustwalletcore/build.gradle | 5 +++-- bootstrap.sh | 2 -- 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c2f3fa3b05..173d827b445 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,11 @@ project(TrustWalletCore) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++") +if(ANDROID) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") +else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++") +endif() set(CMAKE_EXPORT_COMPILE_COMMANDS 1) set(CMAKE_POSITION_INDEPENDENT_CODE ON) @@ -18,6 +22,7 @@ else() set(PREFIX "$ENV{PREFIX}") endif() + include_directories(${PREFIX}/include) link_directories(${PREFIX}/lib) @@ -88,3 +93,19 @@ if(NOT ANDROID AND NOT IOS_PLATFORM AND NOT WASM) endif() configure_file(${CMAKE_CURRENT_SOURCE_DIR}/swift/cpp.xcconfig.in ${CMAKE_CURRENT_SOURCE_DIR}/swift/cpp.xcconfig @ONLY) + +if(ANDROID) + # Workaround: + include_directories(BEFORE SYSTEM + /home/bartek/Android/Sdk/ndk/21.1.6352462/sources/android/support/include + /home/bartek/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.8/include # stddef.h + /home/bartek/Android/Sdk/ndk/21.1.6352462/sysroot/usr/include + /home/bartek/Android/Sdk/ndk/21.1.6352462/sources/cxx-stl/llvm-libc++abi/include + /home/bartek/Android/Sdk/ndk/21.1.6352462/sources/cxx-stl/llvm-libc++/include + ) +else() + include_directories(BEFORE SYSTEM + /usr/include/x86_64-linux-gnu/c++/7.5.0 + /usr/include/c++/7.5.0 + ) +endif() diff --git a/android/app/build.gradle b/android/app/build.gradle index 609fbaf8b18..9f96e27ec1e 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -3,12 +3,12 @@ apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android' android { - compileSdkVersion 28 - buildToolsVersion '28.0.3' + compileSdkVersion 29 + buildToolsVersion '29.0.3' defaultConfig { applicationId "com.trustwallet.core.app" minSdkVersion 23 - targetSdkVersion 28 + targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -24,18 +24,18 @@ android { dependencies { implementation project(':trustwalletcore') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.appcompat:appcompat:1.1.0' // Tests - testImplementation 'junit:junit:4.12' - androidTestImplementation("androidx.test.espresso:espresso-core:3.1.0-beta02", { + testImplementation 'junit:junit:4.13' + androidTestImplementation('androidx.test.espresso:espresso-core:3.3.0-beta01', { exclude group: "com.android.support", module: "support-annotations" }) - androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.1' - androidTestImplementation 'androidx.test:runner:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0' + androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'android.arch.core:core-testing:1.1.1' - implementation 'io.grpc:grpc-protobuf:1.24.2' + implementation 'io.grpc:grpc-protobuf:1.29.0' } repositories { mavenCentral() diff --git a/android/build.gradle b/android/build.gradle index c3b350a38ce..8d60b26e84e 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,13 +1,13 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.21' + ext.kotlin_version = '1.3.72' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.6.1' + classpath 'com.android.tools.build:gradle:3.6.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' diff --git a/android/trustwalletcore/build.gradle b/android/trustwalletcore/build.gradle index 83bc1d15148..b7fee46694c 100644 --- a/android/trustwalletcore/build.gradle +++ b/android/trustwalletcore/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'maven-publish' group='com.github.trustwallet' android { - compileSdkVersion 28 + compileSdkVersion 29 defaultConfig { minSdkVersion 23 @@ -33,10 +33,11 @@ android { path "../../CMakeLists.txt" } } + buildToolsVersion = '29.0.3' } dependencies { - implementation 'io.grpc:grpc-protobuf:1.24.2' + implementation 'io.grpc:grpc-protobuf:1.29.0' } apply from: 'maven-push.gradle' diff --git a/bootstrap.sh b/bootstrap.sh index 35b6325f02c..51f0eb67298 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -3,8 +3,6 @@ # Fail if any commands fails set -e -export CPLUS_INCLUDE_PATH=/usr/include/c++/7.5.0:/usr/include/x86_64-linux-gnu/c++/7.5.0 - echo "#### Initializing... ####" tools/install-dependencies From e4159b024354f50dd6e3f33692fad32bd5ef9cd1 Mon Sep 17 00:00:00 2001 From: Bartosz Tarnowski Date: Wed, 29 Apr 2020 15:52:45 +0100 Subject: [PATCH 10/14] Android test app. --- android/app/build.gradle | 18 +++++++++--------- android/build.gradle | 4 ++-- android/trustwalletcore/build.gradle | 5 ++--- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 9f96e27ec1e..609fbaf8b18 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -3,12 +3,12 @@ apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android' android { - compileSdkVersion 29 - buildToolsVersion '29.0.3' + compileSdkVersion 28 + buildToolsVersion '28.0.3' defaultConfig { applicationId "com.trustwallet.core.app" minSdkVersion 23 - targetSdkVersion 29 + targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -24,18 +24,18 @@ android { dependencies { implementation project(':trustwalletcore') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.appcompat:appcompat:1.0.2' // Tests - testImplementation 'junit:junit:4.13' - androidTestImplementation('androidx.test.espresso:espresso-core:3.3.0-beta01', { + testImplementation 'junit:junit:4.12' + androidTestImplementation("androidx.test.espresso:espresso-core:3.1.0-beta02", { exclude group: "com.android.support", module: "support-annotations" }) - androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0' - androidTestImplementation 'androidx.test:runner:1.2.0' + androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.1' + androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'android.arch.core:core-testing:1.1.1' - implementation 'io.grpc:grpc-protobuf:1.29.0' + implementation 'io.grpc:grpc-protobuf:1.24.2' } repositories { mavenCentral() diff --git a/android/build.gradle b/android/build.gradle index 8d60b26e84e..c3b350a38ce 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,13 +1,13 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.72' + ext.kotlin_version = '1.3.21' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.6.3' + classpath 'com.android.tools.build:gradle:3.6.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' diff --git a/android/trustwalletcore/build.gradle b/android/trustwalletcore/build.gradle index b7fee46694c..83bc1d15148 100644 --- a/android/trustwalletcore/build.gradle +++ b/android/trustwalletcore/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'maven-publish' group='com.github.trustwallet' android { - compileSdkVersion 29 + compileSdkVersion 28 defaultConfig { minSdkVersion 23 @@ -33,11 +33,10 @@ android { path "../../CMakeLists.txt" } } - buildToolsVersion = '29.0.3' } dependencies { - implementation 'io.grpc:grpc-protobuf:1.29.0' + implementation 'io.grpc:grpc-protobuf:1.24.2' } apply from: 'maven-push.gradle' From e805e9ccbe5315322a2ccb845d678f4614dc109e Mon Sep 17 00:00:00 2001 From: Bartosz Tarnowski Date: Wed, 29 Apr 2020 16:44:29 +0100 Subject: [PATCH 11/14] Fixes for Android build. --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 173d827b445..59675c42667 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,11 +97,11 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/swift/cpp.xcconfig.in ${CMAKE_CURRENT if(ANDROID) # Workaround: include_directories(BEFORE SYSTEM - /home/bartek/Android/Sdk/ndk/21.1.6352462/sources/android/support/include - /home/bartek/Android/Sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.8/include # stddef.h - /home/bartek/Android/Sdk/ndk/21.1.6352462/sysroot/usr/include - /home/bartek/Android/Sdk/ndk/21.1.6352462/sources/cxx-stl/llvm-libc++abi/include - /home/bartek/Android/Sdk/ndk/21.1.6352462/sources/cxx-stl/llvm-libc++/include + $ENV{NDK_DIR}/sources/android/support/include + $ENV{NDK_DIR}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.8/include # stddef.h + $ENV{NDK_DIR}/sysroot/usr/include + $ENV{NDK_DIR}/sources/cxx-stl/llvm-libc++abi/include + $ENV{NDK_DIR}/sources/cxx-stl/llvm-libc++/include ) else() include_directories(BEFORE SYSTEM From 9c0c344d339b78d6d5703defba99a599b57bd4ae Mon Sep 17 00:00:00 2001 From: Bartosz Tarnowski Date: Mon, 4 May 2020 18:42:29 +0100 Subject: [PATCH 12/14] Fix wallet test. --- tests/interface/TWStoredKeyTests.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/interface/TWStoredKeyTests.cpp b/tests/interface/TWStoredKeyTests.cpp index b769752db9b..0756de087a0 100644 --- a/tests/interface/TWStoredKeyTests.cpp +++ b/tests/interface/TWStoredKeyTests.cpp @@ -192,9 +192,11 @@ TEST(TWStoredKey, importInvalidKey) { } TEST(TWStoredKey, removeAccountForCoin) { - auto password = "password"; - auto key = TWStoredKeyCreate("Test KeyStore", password); - auto wallet = TWStoredKeyWallet(key, password); + const auto name = WRAPS(TWStringCreateWithUTF8Bytes("Test Keystore")); + const auto password = WRAPS(TWStringCreateWithUTF8Bytes("password")); + + auto key = TWStoredKeyCreate(name.get(), password.get()); + auto wallet = TWStoredKeyWallet(key, password.get()); ASSERT_NE(TWStoredKeyAccountForCoin(key, TWCoinTypeEthereum, wallet), nullptr); ASSERT_NE(TWStoredKeyAccountForCoin(key, TWCoinTypeBitcoin, wallet), nullptr); From d7f4835dd78fd67dba55e574a6437afaa4e69b11 Mon Sep 17 00:00:00 2001 From: Bartosz Tarnowski Date: Tue, 12 May 2020 13:12:11 +0100 Subject: [PATCH 13/14] Signer tests for DGLD. --- tests/DigitalGold/AddressTests.cpp | 99 +++++++++--- tests/DigitalGold/SignerTests.cpp | 209 ++++++++++++++++++++++++-- tests/DigitalGold/TWCoinTypeTests.cpp | 29 ++-- 3 files changed, 289 insertions(+), 48 deletions(-) diff --git a/tests/DigitalGold/AddressTests.cpp b/tests/DigitalGold/AddressTests.cpp index ae22b98df65..180ab37e5a5 100644 --- a/tests/DigitalGold/AddressTests.cpp +++ b/tests/DigitalGold/AddressTests.cpp @@ -6,6 +6,7 @@ #include "HexCoding.h" #include "Bitcoin/Address.h" +#include "Bitcoin/Script.h" #include "Coin.h" #include "PublicKey.h" #include "PrivateKey.h" @@ -15,50 +16,43 @@ using namespace TW; using namespace TW::Bitcoin; +static const byte p2pkh = p2pkhPrefix(TWCoinTypeDigitalGold); +static const byte p2sh = p2shPrefix(TWCoinTypeDigitalGold); + TEST(DigitalGoldAddress, Valid) { - ASSERT_TRUE(Address::isValid("GJCMxPGMH3LVoGtZ3yEhPYbMVnYwSybBzi")); - ASSERT_TRUE(Address::isValid("GaLFdPjbDVGcv7v6xuhbvpXUq8mtMkR24y")); - ASSERT_TRUE(Address::isValid("GfxjHLysUq5XmPqtYPVyzdVm39QSDpFdET")); - ASSERT_TRUE(Address::isValid("Gdzoxj6QFLDndw5htN2hLJ8JwKRWYHdX2K")); - ASSERT_TRUE(Address::isValid("GJKt1CQ4wj2i7QTL2VzhXGQ7u7uUXJ7s5A")); - ASSERT_TRUE(Address::isValid("Gc5JdxYv2k1FfJMr689J66VxQ4yGp97GzZ")); - ASSERT_TRUE(Address::isValid("GdfXJwBdQUwD1nuySrQeZjFw8KEtPEoBeB")); - ASSERT_TRUE(Address::isValid("GcSsKzmisNB5KCH6wJr6NZyoSMyydVvi22")); - ASSERT_TRUE(Address::isValid("GKm9Uj8R6MPqNw2xkhXNYKsvUy46n8E655")); - ASSERT_TRUE(Address::isValid("GJu16E3CmFdSknrzbKpXacW2MPoLwiesTv")); - ASSERT_TRUE(Address::isValid("GTWUe2J9amAkhGm6ePrg2knPXYwNZWL2AH")); - ASSERT_TRUE(Address::isValid("GJBJoGst6SPYweTdE2rLXpc7ky3JaN8s3M")); - ASSERT_TRUE(Address::isValid("GYPHQbxED8GFtpHkZShNzAxyZDrUVKjPFC")); + + ASSERT_TRUE(Address::isValid("GJCMxPGMH3LVoGtZ3yEhPYbMVnYwSybBzi", {{p2pkh}, {p2sh}})); + ASSERT_TRUE(Address::isValid("GaLFdPjbDVGcv7v6xuhbvpXUq8mtMkR24y", {{p2pkh}, {p2sh}})); + ASSERT_TRUE(Address::isValid("GfxjHLysUq5XmPqtYPVyzdVm39QSDpFdET", {{p2pkh}, {p2sh}})); + ASSERT_TRUE(Address::isValid("Gdzoxj6QFLDndw5htN2hLJ8JwKRWYHdX2K", {{p2pkh}, {p2sh}})); + ASSERT_TRUE(Address::isValid("GJKt1CQ4wj2i7QTL2VzhXGQ7u7uUXJ7s5A", {{p2pkh}, {p2sh}})); + ASSERT_TRUE(Address::isValid("Gc5JdxYv2k1FfJMr689J66VxQ4yGp97GzZ", {{p2pkh}, {p2sh}})); + ASSERT_TRUE(Address::isValid("GdfXJwBdQUwD1nuySrQeZjFw8KEtPEoBeB", {{p2pkh}, {p2sh}})); + ASSERT_TRUE(Address::isValid("GcSsKzmisNB5KCH6wJr6NZyoSMyydVvi22", {{p2pkh}, {p2sh}})); + ASSERT_TRUE(Address::isValid("GKm9Uj8R6MPqNw2xkhXNYKsvUy46n8E655", {{p2pkh}, {p2sh}})); + ASSERT_TRUE(Address::isValid("GJu16E3CmFdSknrzbKpXacW2MPoLwiesTv", {{p2pkh}, {p2sh}})); + ASSERT_TRUE(Address::isValid("GTWUe2J9amAkhGm6ePrg2knPXYwNZWL2AH", {{p2pkh}, {p2sh}})); + ASSERT_TRUE(Address::isValid("GJBJoGst6SPYweTdE2rLXpc7ky3JaN8s3M", {{p2pkh}, {p2sh}})); + ASSERT_TRUE(Address::isValid("GYPHQbxED8GFtpHkZShNzAxyZDrUVKjPFC", {{p2pkh}, {p2sh}})); // TODO: test segwit addresses } TEST(DigitalGoldAddress, Invalid) { - const byte p2pkh = p2pkhPrefix(TWCoinTypeDigitalGold); - const byte p2sh = p2shPrefix(TWCoinTypeDigitalGold); - - ASSERT_FALSE(Address::isValid("GZ8fKGGqBZtenPR8hL-----BpMcagkXg5g")); + ASSERT_FALSE(Address::isValid("GZ8fKGGqBZtenPR8hL-----BpMcagkXg5g", {{p2pkh}, {p2sh}})); ASSERT_FALSE(Address::isValid("1MVk8kVbs7nepTGwbQN1H46UDjSDAUgcRU", {{p2pkh}, {p2sh}})); // valid bitcoin address, but invalid dgld address // TODO: Add more tests } TEST(DigitalGoldAddress, FromPrivateKey) { - - const byte p2pkh = p2pkhPrefix(TWCoinTypeDigitalGold); - const byte p2sh = p2shPrefix(TWCoinTypeDigitalGold); - auto privateKey = PrivateKey(parse_hex("63832fb769a6f12b0a403b8906d6b718a3994b1c1ace78be359a7ff39b3a7362")); auto address = Address(privateKey.getPublicKey(TWPublicKeyTypeSECP256k1), p2pkh); ASSERT_EQ(address.string(), "GNxs8kNGP4E18is7TRvjh9WknrStwMmS2N"); } TEST(DigitalGoldAddress, FromPublicKey) { - - const byte p2pkh = p2pkhPrefix(TWCoinTypeDigitalGold); - const byte p2sh = p2shPrefix(TWCoinTypeDigitalGold); - auto publicKey = PublicKey(parse_hex("028bd49b59eaa0aa4485ef35bc0433cf5071eeb41b229d17c5563d935ca474a9b4"), TWPublicKeyTypeSECP256k1); auto address = Address(publicKey, p2pkh); ASSERT_EQ(address.string(), "GSvAp2iiodmfkuS4xcpAyJo7s5xhPGw6YY"); @@ -68,3 +62,58 @@ TEST(DigitalGoldAddress, FromString) { auto address = Address("GRZ3JdwD4LuiJd2x7kKfFVJr6MdHREj7ie"); ASSERT_EQ(address.string(), "GRZ3JdwD4LuiJd2x7kKfFVJr6MdHREj7ie"); } + + +TEST(DigitalGoldAddress, ScriptTest) { + + auto privateKey1 = PrivateKey(parse_hex("63832fb769a6f12b0a403b8906d6b718a3994b1c1ace78be359a7ff39b3a7362")); + + auto address1a = Address(privateKey1.getPublicKey(TWPublicKeyTypeSECP256k1), p2pkh); + auto script1a = Script::buildForAddress(address1a.string(), TWCoinTypeDigitalGold); + ASSERT_FALSE(script1a.isPayToWitnessScriptHash()); + ASSERT_FALSE(script1a.isPayToScriptHash()); + ASSERT_EQ(script1a.bytes.size(), 25); + ASSERT_EQ(hex(script1a.bytes.begin(), script1a.bytes.end()), "76a9143828ccf7696ce8e8c16a397b103f0a4f3b876bf488ac"); + auto hash1a = Data(); + script1a.matchPayToPubkeyHash(hash1a); + ASSERT_EQ(hash1a.size(), 20); + ASSERT_EQ(hex(hash1a.begin(), hash1a.end()), "3828ccf7696ce8e8c16a397b103f0a4f3b876bf4"); + + auto address1b = Address(privateKey1.getPublicKey(TWPublicKeyTypeSECP256k1), p2sh); + auto script1b = Script::buildForAddress(address1b.string(), TWCoinTypeDigitalGold); + ASSERT_FALSE(script1b.isPayToWitnessScriptHash()); + ASSERT_TRUE(script1b.isPayToScriptHash()); + ASSERT_EQ(script1b.bytes.size(), 23); + ASSERT_EQ(hex(script1b.bytes.begin(), script1b.bytes.end()), "a9143828ccf7696ce8e8c16a397b103f0a4f3b876bf487"); + auto hash1b = Data(); + script1b.matchPayToScriptHash(hash1b); + ASSERT_EQ(hash1b.size(), 20); + ASSERT_EQ(hex(hash1b.begin(), hash1b.end()), "3828ccf7696ce8e8c16a397b103f0a4f3b876bf4"); + + auto privateKey2 = PrivateKey(parse_hex("63832fb769a6f12b0a403b8906d6b718a3994b1c1ace78be359a7ff39b3a7363")); + + auto address2a = Address(privateKey2.getPublicKey(TWPublicKeyTypeSECP256k1), p2pkh); + auto script2a = Script::buildForAddress(address2a.string(), TWCoinTypeDigitalGold); + ASSERT_FALSE(script2a.isPayToWitnessScriptHash()); + ASSERT_FALSE(script2a.isPayToScriptHash()); + ASSERT_EQ(script2a.bytes.size(), 25); + ASSERT_EQ(hex(script2a.bytes.begin(), script2a.bytes.end()), "76a9142f8a97924776e36fafaae12e41cf2b0f7d24597c88ac"); + auto hash2a = Data(); + script2a.matchPayToPubkeyHash(hash2a); + ASSERT_EQ(hash2a.size(), 20); + ASSERT_EQ(hex(hash2a.begin(), hash2a.end()), "2f8a97924776e36fafaae12e41cf2b0f7d24597c"); + + auto address2b = Address(privateKey2.getPublicKey(TWPublicKeyTypeSECP256k1), p2sh); + auto script2b = Script::buildForAddress(address2b.string(), TWCoinTypeDigitalGold); + ASSERT_FALSE(script2b.isPayToWitnessScriptHash()); + ASSERT_TRUE(script2b.isPayToScriptHash()); + ASSERT_EQ(script2b.bytes.size(), 23); + ASSERT_EQ(hex(script2b.bytes.begin(), script2b.bytes.end()), "a9142f8a97924776e36fafaae12e41cf2b0f7d24597c87"); + auto hash2b = Data(); + script2b.matchPayToScriptHash(hash2b); + ASSERT_EQ(hash2b.size(), 20); + ASSERT_EQ(hex(hash2b.begin(), hash2b.end()), "2f8a97924776e36fafaae12e41cf2b0f7d24597c"); + +} + + diff --git a/tests/DigitalGold/SignerTests.cpp b/tests/DigitalGold/SignerTests.cpp index 789de98713d..4a9cf99cccc 100644 --- a/tests/DigitalGold/SignerTests.cpp +++ b/tests/DigitalGold/SignerTests.cpp @@ -9,26 +9,209 @@ #include "HexCoding.h" #include "PrivateKey.h" #include "PublicKey.h" +#include "Coin.h" +#include "Bitcoin/Script.h" +#include #include using namespace TW; using namespace TW::Bitcoin; -// TODO: Add tests -TEST(DigitalGoldSigner, Sign) { - // TODO: Finalize test implementation +static const byte p2pkh = p2pkhPrefix(TWCoinTypeDigitalGold); +static const byte p2sh = p2shPrefix(TWCoinTypeDigitalGold); - //auto key = PrivateKey(parse_hex("__PRIVKEY_DATA__")); - //auto publicKey = key.getPublicKey(TWPublicKeyTypeED25519); - //auto from = Address(publicKey); - //auto to = Address("__TO_ADDRESS__"); - //... - //auto transaction = Transaction(...) - //auto signature = Signer::sign(key, transaction); - //auto result = transaction.serialize(signature); - //ASSERT_EQ(hex(serialized), "__RESULT__"); - //ASSERT_EQ(...) +TEST(DigitalGoldSigner, SignP2PKH) { + // Test spending from P2PKH address. A single private key is needed. + + auto inputTxHash = parse_hex("db6b1b20aa0fd7b23880be2ecbd4a98130974cf4748fb66092ac4d3ceb1a5477"); // transaction id to spend from (example, can be anything) + + auto privateKeyFrom = PrivateKey(parse_hex("63832fb769a6f12b0a403b8906d6b718a3994b1c1ace78be359a7ff39b3a7362")); // private key of the owner + auto toAddress = Address("GYPHQbxED8GFtpHkZShNzAxyZDrUVKjPFC"); // destination address + + auto publicKeyFrom = privateKeyFrom.getPublicKey(TWPublicKeyTypeSECP256k1); // public key (from private key) + auto fromAddress = Address(publicKeyFrom, p2pkh); // P2PKH source address (reconstructed from private key) + EXPECT_EQ(fromAddress.string(), "GNxs8kNGP4E18is7TRvjh9WknrStwMmS2N"); + auto redeemScript = Script::buildForAddress(fromAddress.string(), TWCoinTypeDigitalGold); + auto redeemScriptHash = redeemScript.hash(); //Hash::ripemd(Hash::sha256(redeemScript.bytes)); + + // optional sanity checks + auto publicKeyHash = Hash::ripemd(Hash::sha256(publicKeyFrom.bytes)); + EXPECT_EQ(hex(publicKeyHash.begin(), publicKeyHash.end()), "3828ccf7696ce8e8c16a397b103f0a4f3b876bf4"); + auto scriptSig = Script::buildPayToPublicKeyHash(publicKeyHash); + auto scriptSigHash = Hash::ripemd(Hash::sha256(scriptSig.bytes)); + EXPECT_EQ(hex(scriptSigHash.begin(), scriptSigHash.end()), "82472cab708d49bb1e80fae459d6ae0fa34a7bde"); + Data pubKeyHashExtracted; + redeemScript.matchPayToPubkeyHash(pubKeyHashExtracted); + EXPECT_EQ(hex(pubKeyHashExtracted.begin(), pubKeyHashExtracted.end()), hex(publicKeyHash.begin(), publicKeyHash.end())); + EXPECT_EQ(hex(redeemScriptHash.begin(), redeemScriptHash.end()), hex(scriptSigHash.begin(), scriptSigHash.end())); + + auto changeAddress = Address("GTWUe2J9amAkhGm6ePrg2knPXYwNZWL2AH"); // change address, should belong to the owner + + int inputAmount = 1000; // must cover output amount and the fee, rest will go to the change address + int outputAmount = 600; + + Proto::SigningInput input; + input.set_hash_type(TWBitcoinSigHashTypeAll); + input.set_coin_type(TWCoinTypeDigitalGold); + input.set_amount(outputAmount); // amount to send + input.set_byte_fee(1); + input.set_to_address(toAddress.string()); + input.set_change_address(changeAddress.string()); + + input.add_private_key(privateKeyFrom.bytes.data(), privateKeyFrom.bytes.size()); + (*input.mutable_scripts())[hex(redeemScriptHash.begin(), redeemScriptHash.end())] = std::string(redeemScript.bytes.begin(), redeemScript.bytes.end()); + + Proto::UnspentTransaction* utxo = input.add_utxo(); + utxo->set_amount(inputAmount); // amount to take + utxo->set_script(redeemScript.bytes.data(), redeemScript.bytes.size()); + utxo->mutable_out_point()->set_hash(inputTxHash.data(), inputTxHash.size()); // transaction id + utxo->mutable_out_point()->set_index(1); // index of output of the transaction + utxo->mutable_out_point()->set_sequence(12345678); + + auto plan = Signer::plan(input); + int feeAmount = plan.fee(); + int changeAmount = plan.change(); + + ASSERT_TRUE(feeAmount >= 0); + ASSERT_TRUE(changeAmount >= 0); + + input.set_allocated_plan(new Proto::TransactionPlan(std::move(plan))); + + ASSERT_TRUE(inputAmount == outputAmount + feeAmount + changeAmount); + + auto signature = Signer::sign(input); + + // TODO: match individual fields + auto correct_signed_transaction = "transaction {\n" + " version: 1\n" + " inputs {\n" + " previousOutput {\n" + " hash: \"\\333k\\033 \\252\\017\\327\\2628\\200\\276.\\313\\324\\251\\2010\\227L\\364t\\217\\266`\\222\\254M<\\353\\032Tw\"\n" + " index: 1\n" + " }\n" + " sequence: 12345678\n" + " script: \"G0D\\002 1@\\300\\177\\204}\\002r\\340\\367?a5\\262y\\202\\303\\'\\03377n\\235#P\\242\\376\\321\\215\\034>\\307\\002 {\\033E\\206\\253\\024\\202z\\375+!j\\264\\020\\345\\t8\\222/\\013\\271\\215\\271\\323\\336\\307(\\225\\237H\\356#\\001!\\002E\\036\\201UM\\260Lf_\\345-F2\\335\\232*\\326W]\\272-\\021)\\331(#\\031\\357\\363\\244LI\"\n" + " }\n" + " outputs {\n" + " value: 600\n" + " script: \"v\\251\\024\\237\\200-\\234o\\360:\\\"%\\026Q%N\\255\\\\\\363]\\262\\354\\325\\210\\254\"\n" + " }\n" + " outputs {\n" + " value: 174\n" + " script: \"v\\251\\024j\\003\\326\\\"P\\3748:x\\355\\253>\\246\\244\\3371A%\\207\\212\\210\\254\"\n" + " }\n" + "}\n" + "encoded: \"\\001\\000\\000\\000\\001\\333k\\033 \\252\\017\\327\\2628\\200\\276.\\313\\324\\251\\2010\\227L\\364t\\217\\266`\\222\\254M<\\353\\032Tw\\001\\000\\000\\000jG0D\\002 1@\\300\\177\\204}\\002r\\340\\367?a5\\262y\\202\\303\\'\\03377n\\235#P\\242\\376\\321\\215\\034>\\307\\002 {\\033E\\206\\253\\024\\202z\\375+!j\\264\\020\\345\\t8\\222/\\013\\271\\215\\271\\323\\336\\307(\\225\\237H\\356#\\001!\\002E\\036\\201UM\\260Lf_\\345-F2\\335\\232*\\326W]\\272-\\021)\\331(#\\031\\357\\363\\244LINa\\274\\000\\002X\\002\\000\\000\\000\\000\\000\\000\\031v\\251\\024\\237\\200-\\234o\\360:\\\"%\\026Q%N\\255\\\\\\363]\\262\\354\\325\\210\\254\\256\\000\\000\\000\\000\\000\\000\\000\\031v\\251\\024j\\003\\326\\\"P\\3748:x\\355\\253>\\246\\244\\3371A%\\207\\212\\210\\254\\000\\000\\000\\000\"\n" + "transaction_id: \"dac0ad7a0ee5b91b3eb20910a87001ea31271e800cc2d6c1e08c87b517462d60\"\n"; + + ASSERT_EQ(signature.Utf8DebugString(), correct_signed_transaction); +} + + + +TEST(DigitalGoldSigner, SignP2SH) { + // Test spending from P2SH address. 2-of-3 multisig script is used as example. 3 public keys are needed to generate the address, 2 private keys to spend from it. + + auto inputTxHash = parse_hex("db6b1b20aa0fd7b23880be2ecbd4a98130974cf4748fb66092ac4d3ceb1a5477"); // transaction id to spend from (example, can be anything) + + PrivateKey privateKeyFrom[3] = { + PrivateKey(parse_hex("63832fb769a6f12b0a403b8906d6b718a3994b1c1ace78be359a7ff39b3a7360")), // private key 1 + PrivateKey(parse_hex("63832fb769a6f12b0a403b8906d6b718a3994b1c1ace78be359a7ff39b3a7361")), // private key 2 + PrivateKey(parse_hex("63832fb769a6f12b0a403b8906d6b718a3994b1c1ace78be359a7ff39b3a7362")) // private key 3 + }; + auto toAddress = Address("GYPHQbxED8GFtpHkZShNzAxyZDrUVKjPFC"); // destination address + + std::vector publicKeyFrom; + for(int i = 0; i < 3; i++) { + publicKeyFrom.push_back(privateKeyFrom[i].getPublicKey(TWPublicKeyTypeSECP256k1)); // public key (from private key) + } + + Data redeemScriptSrc; // 2-of-3 multisig redeem script + redeemScriptSrc.push_back(OP_2); + for(int i = 0; i < 3; i++) { + redeemScriptSrc.push_back(publicKeyFrom[i].bytes.size()); + std::copy(publicKeyFrom[i].bytes.begin(), publicKeyFrom[i].bytes.end(), std::back_inserter(redeemScriptSrc)); + } + redeemScriptSrc.push_back(OP_3); + redeemScriptSrc.push_back(OP_CHECKMULTISIG); + + auto redeemScript = Script(std::move(redeemScriptSrc)); + auto redeemScriptHash = redeemScript.hash(); //Hash::ripemd(Hash::sha256(redeemScript.bytes)); + + Data fromAddressSrc; + fromAddressSrc.push_back(p2sh); + std::copy(redeemScriptHash.begin(), redeemScriptHash.end(), std::back_inserter(fromAddressSrc)); + auto fromAddress = Address(fromAddressSrc); + EXPECT_EQ(fromAddress.string(), "gP2d72von4mf3NUyT2EvpMi8TrFd7cYYUt"); + + auto changeAddress = Address("GTWUe2J9amAkhGm6ePrg2knPXYwNZWL2AH"); // change address, should belong to the owner + + int inputAmount = 1000; // must cover output amount and the fee, rest will go to the change address + int outputAmount = 600; + + Proto::SigningInput input; + input.set_hash_type(TWBitcoinSigHashTypeAll); + input.set_coin_type(TWCoinTypeDigitalGold); + input.set_amount(outputAmount); // amount to send + input.set_byte_fee(1); + input.set_to_address(toAddress.string()); + input.set_change_address(changeAddress.string()); + + for(int i = 0; i < 2; i++) { // only 2 private keys of 3 + input.add_private_key(privateKeyFrom[i].bytes.data(), privateKeyFrom[i].bytes.size()); + } + (*input.mutable_scripts())[hex(redeemScriptHash.begin(), redeemScriptHash.end())] = std::string(redeemScript.bytes.begin(), redeemScript.bytes.end()); + + Proto::UnspentTransaction* utxo = input.add_utxo(); + utxo->set_amount(inputAmount); // amount to take + utxo->set_script(redeemScript.bytes.data(), redeemScript.bytes.size()); + utxo->mutable_out_point()->set_hash(inputTxHash.data(), inputTxHash.size()); // source transaction id + utxo->mutable_out_point()->set_index(1); // index of output of the source transaction to spend from + utxo->mutable_out_point()->set_sequence(12345678); + + auto plan = Signer::plan(input); + + int feeAmount = plan.fee(); + int changeAmount = plan.change(); + + ASSERT_TRUE(feeAmount >= 0); + ASSERT_TRUE(changeAmount >= 0); + + // plan can still be modified + + input.set_allocated_plan(new Proto::TransactionPlan(std::move(plan))); + + ASSERT_TRUE(inputAmount == outputAmount + feeAmount + changeAmount); + + auto signature = Signer::sign(input); + + // TODO: match individual fields + auto correct_signed_transaction = "transaction {\n" + " version: 1\n" + " inputs {\n" + " previousOutput {\n" + " hash: \"\\333k\\033 \\252\\017\\327\\2628\\200\\276.\\313\\324\\251\\2010\\227L\\364t\\217\\266`\\222\\254M<\\353\\032Tw\"\n" + " index: 1\n" + " }\n" + " sequence: 12345678\n" + " script: \"\\000H0E\\002!\\000\\304\\263\\240\\375\\326\\250X:C\\3000\\3055\\206\\t\\003\\246\\335\\030\\324\\006\\242;\\372\\201{\\270<\\325\\335\\2175\\002 W\\275(\\207p\\231\\\"\\315\\007\\201w\\263p\\375e\\375\\010\\r8\\316Iy0\\352cF\\366\\241\\363\\325\\226\\251\\001G0D\\002 2\\343\\372A\\226K@\\3420t\\006\\2703\\016\\227]d\\333\\007\\037\\372W\\275\\017H\\227\\306\\202M\\2151\\273\\002 \\017\\217\\276\\362\\020iG\\\\\\347\\364\\375\\306\\263\\317D\\225}\\360\\007\\001 [J\\300\\022\\304^?\\322\\377\\036\\335\\001\"\n" + " }\n" + " outputs {\n" + " value: 600\n" + " script: \"v\\251\\024\\237\\200-\\234o\\360:\\\"%\\026Q%N\\255\\\\\\363]\\262\\354\\325\\210\\254\"\n" + " }\n" + " outputs {\n" + " value: 174\n" + " script: \"v\\251\\024j\\003\\326\\\"P\\3748:x\\355\\253>\\246\\244\\3371A%\\207\\212\\210\\254\"\n" + " }\n" + "}\n" + "encoded: \"\\001\\000\\000\\000\\001\\333k\\033 \\252\\017\\327\\2628\\200\\276.\\313\\324\\251\\2010\\227L\\364t\\217\\266`\\222\\254M<\\353\\032Tw\\001\\000\\000\\000\\222\\000H0E\\002!\\000\\304\\263\\240\\375\\326\\250X:C\\3000\\3055\\206\\t\\003\\246\\335\\030\\324\\006\\242;\\372\\201{\\270<\\325\\335\\2175\\002 W\\275(\\207p\\231\\\"\\315\\007\\201w\\263p\\375e\\375\\010\\r8\\316Iy0\\352cF\\366\\241\\363\\325\\226\\251\\001G0D\\002 2\\343\\372A\\226K@\\3420t\\006\\2703\\016\\227]d\\333\\007\\037\\372W\\275\\017H\\227\\306\\202M\\2151\\273\\002 \\017\\217\\276\\362\\020iG\\\\\\347\\364\\375\\306\\263\\317D\\225}\\360\\007\\001 [J\\300\\022\\304^?\\322\\377\\036\\335\\001Na\\274\\000\\002X\\002\\000\\000\\000\\000\\000\\000\\031v\\251\\024\\237\\200-\\234o\\360:\\\"%\\026Q%N\\255\\\\\\363]\\262\\354\\325\\210\\254\\256\\000\\000\\000\\000\\000\\000\\000\\031v\\251\\024j\\003\\326\\\"P\\3748:x\\355\\253>\\246\\244\\3371A%\\207\\212\\210\\254\\000\\000\\000\\000\"\n" + "transaction_id: \"5b09ae87620f65d7975e98abb0dedf21cb9e97c0d1ff943283999e9a4b7351fb\"\n"; + + ASSERT_EQ(signature.Utf8DebugString(), correct_signed_transaction); } + + diff --git a/tests/DigitalGold/TWCoinTypeTests.cpp b/tests/DigitalGold/TWCoinTypeTests.cpp index 632e8383af6..835750b1614 100644 --- a/tests/DigitalGold/TWCoinTypeTests.cpp +++ b/tests/DigitalGold/TWCoinTypeTests.cpp @@ -13,7 +13,20 @@ #include -TEST(TWDigitalGoldCoinType, TWCoinType) { +TEST(TWDigitalGoldCoinType, TWCoinTypeConfigurationGetDecimals) { + ASSERT_EQ(TWCoinTypeConfigurationGetDecimals(TWCoinTypeDigitalGold), 8); +} + +TEST(TWDigitalGoldCoinType, TWCoinTypeBlockchain) { + ASSERT_EQ(TWBlockchainBitcoin, TWCoinTypeBlockchain(TWCoinTypeDigitalGold)); +} + +TEST(TWDigitalGoldCoinType, TWCoinTypeXXXPrefix) { + ASSERT_EQ(38, TWCoinTypeP2pkhPrefix(TWCoinTypeDigitalGold)); + ASSERT_EQ(97, TWCoinTypeP2shPrefix(TWCoinTypeDigitalGold)); +} + +TEST(TWDigitalGoldCoinType, TWCoinTypeConfigurationXXX) { auto symbol = WRAPS(TWCoinTypeConfigurationGetSymbol(TWCoinTypeDigitalGold)); auto txId = TWStringCreateWithUTF8Bytes("68e203d1837aad907f4c09b22835e78304a7ae5c4268d0c2487958e3a1858b6e"); auto txUrl = WRAPS(TWCoinTypeConfigurationGetTransactionURL(TWCoinTypeDigitalGold, txId)); @@ -22,13 +35,9 @@ TEST(TWDigitalGoldCoinType, TWCoinType) { auto id = WRAPS(TWCoinTypeConfigurationGetID(TWCoinTypeDigitalGold)); auto name = WRAPS(TWCoinTypeConfigurationGetName(TWCoinTypeDigitalGold)); - ASSERT_EQ(TWCoinTypeConfigurationGetDecimals(TWCoinTypeDigitalGold), 8); - ASSERT_EQ(TWBlockchainBitcoin, TWCoinTypeBlockchain(TWCoinTypeDigitalGold)); - ASSERT_EQ(0x61, TWCoinTypeP2shPrefix(TWCoinTypeDigitalGold)); - ASSERT_EQ(0x0, TWCoinTypeStaticPrefix(TWCoinTypeDigitalGold)); - assertStringsEqual(symbol, "DGLD"); - assertStringsEqual(txUrl, "https://explorer.dgld.ch/tx/68e203d1837aad907f4c09b22835e78304a7ae5c4268d0c2487958e3a1858b6e"); - assertStringsEqual(accUrl, "https://explorer.dgld.ch/address/g3X4Jwf9WLuBqET7tr2bCkDX3A2FGBrUm8"); - assertStringsEqual(id, "dgld"); - assertStringsEqual(name, "DigitalGold"); + ASSERT_EQ(std::string(TWStringUTF8Bytes(symbol.get())), std::string("DGLD")); + ASSERT_EQ(std::string(TWStringUTF8Bytes(txUrl.get())), std::string("https://explorer.dgld.ch/tx/68e203d1837aad907f4c09b22835e78304a7ae5c4268d0c2487958e3a1858b6e")); + ASSERT_EQ(std::string(TWStringUTF8Bytes(accUrl.get())), std::string("https://explorer.dgld.ch/address/g3X4Jwf9WLuBqET7tr2bCkDX3A2FGBrUm8")); + ASSERT_EQ(std::string(TWStringUTF8Bytes(id.get())), std::string("dgld")); + ASSERT_EQ(std::string(TWStringUTF8Bytes(name.get())), std::string("DigitalGold")); } From 46e3bf54f80aca8816e2a9a6c1387737d609374f Mon Sep 17 00:00:00 2001 From: Bartosz Tarnowski Date: Tue, 12 May 2020 17:48:32 +0100 Subject: [PATCH 14/14] Fixes for tests and build system. --- bootstrap.sh | 7 ------- cmake/Protobuf.cmake | 9 ++------- samples/cpp/CMakeLists.txt | 2 +- src/Keystore/StoredKey.cpp | 4 ++-- src/Keystore/StoredKey.h | 2 +- tests/CMakeLists.txt | 2 +- tests/DigitalGold/AddressTests.cpp | 4 ++-- tests/DigitalGold/SignerTests.cpp | 2 +- tests/interface/TWStoredKeyTests.cpp | 7 ++++--- trezor-crypto/tests/CMakeLists.txt | 4 ++-- 10 files changed, 16 insertions(+), 27 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index c9b56f22136..509b427b5da 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -10,13 +10,8 @@ echo "#### Generating files... ####" tools/generate-files echo "#### Building... ####" -<<<<<<< HEAD cmake . -Bbuild -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -make -Cbuild tests TrezorCryptoTests -======= -cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Debug make -Cbuild -j12 tests TrezorCryptoTests ->>>>>>> blockchaincom/master if [ -x "$(command -v clang-tidy)" ]; then echo "#### Linting... ####" @@ -30,5 +25,3 @@ build/trezor-crypto/tests/TrezorCryptoTests ROOT="`dirname \"$0\"`" TESTS_ROOT="`(cd \"$ROOT/tests\" && pwd)`" build/tests/tests "$TESTS_ROOT" - -make -Cbuild walletconsole diff --git a/cmake/Protobuf.cmake b/cmake/Protobuf.cmake index b7dea816a48..7f27286911e 100644 --- a/cmake/Protobuf.cmake +++ b/cmake/Protobuf.cmake @@ -1,10 +1,5 @@ -<<<<<<< HEAD -set(protobuf_SOURCE_DIR ${CMAKE_SOURCE_DIR}/build/protobuf/staging/protobuf-3.9.0) -set(protobuf_source_dir ${CMAKE_SOURCE_DIR}/build/protobuf/staging/protobuf-3.9.0) -======= -set(protobuf_SOURCE_DIR ${CMAKE_SOURCE_DIR}/wallet-core/build/local/src/protobuf/protobuf-3.9.0) -set(protobuf_source_dir ${CMAKE_SOURCE_DIR}/wallet-core/build/local/src/protobuf/protobuf-3.9.0) ->>>>>>> blockchaincom/master +set(protobuf_SOURCE_DIR ${CMAKE_SOURCE_DIR}/build/local/src/protobuf/protobuf-3.9.0) +set(protobuf_source_dir ${CMAKE_SOURCE_DIR}/build/local/src/protobuf/protobuf-3.9.0) # Updated from https://github.com/protocolbuffers/protobuf/blob/master/cmake/libprotopuf.cmake diff --git a/samples/cpp/CMakeLists.txt b/samples/cpp/CMakeLists.txt index 79b9aa62845..9f4dbfbde76 100644 --- a/samples/cpp/CMakeLists.txt +++ b/samples/cpp/CMakeLists.txt @@ -39,7 +39,7 @@ else () add_compile_options (-Werror=switch) endif () -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++") +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") set (CMAKE_C_STANDARD 11) set (CMAKE_C_STANDARD_REQUIRED ON) diff --git a/src/Keystore/StoredKey.cpp b/src/Keystore/StoredKey.cpp index 092dec9f30b..bba73ee4907 100644 --- a/src/Keystore/StoredKey.cpp +++ b/src/Keystore/StoredKey.cpp @@ -78,8 +78,8 @@ StoredKey StoredKey::createWithPrivateKeyAddDefaultAddress(const std::string& na return key; } -StoredKey::StoredKey(StoredKeyType type, const std::string& name, const std::string& password, Data data) - : type(type), id(), name(name), payload(password, data), accounts() { +StoredKey::StoredKey(StoredKeyType type, std::string name, const Data& password, const Data& data) + : type(type), id(), name(std::move(name)), payload(password, data), accounts() { boost::uuids::random_generator gen; id = boost::lexical_cast(gen()); } diff --git a/src/Keystore/StoredKey.h b/src/Keystore/StoredKey.h index 559224374be..475271e9283 100644 --- a/src/Keystore/StoredKey.h +++ b/src/Keystore/StoredKey.h @@ -119,7 +119,7 @@ class StoredKey { /// Initializes a `StoredKey` with a type, an encryption password, and unencrypted data. /// This contstructor will encrypt the provided data with default encryption /// parameters. - StoredKey(StoredKeyType type, const std::string& name, const std::string& password, Data data); + StoredKey(StoredKeyType type, std::string name, const Data& password, const Data& data); }; } // namespace TW::Keystore diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index be1569b89cd..f6acfc476be 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,7 +6,7 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # Add googletest directly to our build. This defines # the gtest and gtest_main targets. -add_subdirectory(${CMAKE_SOURCE_DIR}/build/gtest/staging/googletest-release-1.8.1 +add_subdirectory(${CMAKE_SOURCE_DIR}/build/local/src/gtest/googletest-release-1.8.1 ${CMAKE_CURRENT_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL) diff --git a/tests/DigitalGold/AddressTests.cpp b/tests/DigitalGold/AddressTests.cpp index 180ab37e5a5..4b74744c586 100644 --- a/tests/DigitalGold/AddressTests.cpp +++ b/tests/DigitalGold/AddressTests.cpp @@ -75,7 +75,7 @@ TEST(DigitalGoldAddress, ScriptTest) { ASSERT_EQ(script1a.bytes.size(), 25); ASSERT_EQ(hex(script1a.bytes.begin(), script1a.bytes.end()), "76a9143828ccf7696ce8e8c16a397b103f0a4f3b876bf488ac"); auto hash1a = Data(); - script1a.matchPayToPubkeyHash(hash1a); + script1a.matchPayToPublicKeyHash(hash1a); ASSERT_EQ(hash1a.size(), 20); ASSERT_EQ(hex(hash1a.begin(), hash1a.end()), "3828ccf7696ce8e8c16a397b103f0a4f3b876bf4"); @@ -99,7 +99,7 @@ TEST(DigitalGoldAddress, ScriptTest) { ASSERT_EQ(script2a.bytes.size(), 25); ASSERT_EQ(hex(script2a.bytes.begin(), script2a.bytes.end()), "76a9142f8a97924776e36fafaae12e41cf2b0f7d24597c88ac"); auto hash2a = Data(); - script2a.matchPayToPubkeyHash(hash2a); + script2a.matchPayToPublicKeyHash(hash2a); ASSERT_EQ(hash2a.size(), 20); ASSERT_EQ(hex(hash2a.begin(), hash2a.end()), "2f8a97924776e36fafaae12e41cf2b0f7d24597c"); diff --git a/tests/DigitalGold/SignerTests.cpp b/tests/DigitalGold/SignerTests.cpp index 4a9cf99cccc..35511aed8d9 100644 --- a/tests/DigitalGold/SignerTests.cpp +++ b/tests/DigitalGold/SignerTests.cpp @@ -44,7 +44,7 @@ TEST(DigitalGoldSigner, SignP2PKH) { auto scriptSigHash = Hash::ripemd(Hash::sha256(scriptSig.bytes)); EXPECT_EQ(hex(scriptSigHash.begin(), scriptSigHash.end()), "82472cab708d49bb1e80fae459d6ae0fa34a7bde"); Data pubKeyHashExtracted; - redeemScript.matchPayToPubkeyHash(pubKeyHashExtracted); + redeemScript.matchPayToPublicKeyHash(pubKeyHashExtracted); EXPECT_EQ(hex(pubKeyHashExtracted.begin(), pubKeyHashExtracted.end()), hex(publicKeyHash.begin(), publicKeyHash.end())); EXPECT_EQ(hex(redeemScriptHash.begin(), redeemScriptHash.end()), hex(scriptSigHash.begin(), scriptSigHash.end())); diff --git a/tests/interface/TWStoredKeyTests.cpp b/tests/interface/TWStoredKeyTests.cpp index 521cb8d2d57..2a023e3d992 100644 --- a/tests/interface/TWStoredKeyTests.cpp +++ b/tests/interface/TWStoredKeyTests.cpp @@ -202,10 +202,11 @@ TEST(TWStoredKey, importInvalidKey) { } TEST(TWStoredKey, removeAccountForCoin) { - const auto name = WRAPS(TWStringCreateWithUTF8Bytes("Test Keystore")); - const auto password = WRAPS(TWStringCreateWithUTF8Bytes("password")); + const string name = "Test Keystore"; + const auto passwordString = WRAPS(TWStringCreateWithUTF8Bytes("password")); + const auto password = WRAPD(TWDataCreateWithBytes(reinterpret_cast(TWStringUTF8Bytes(passwordString.get())), TWStringSize(passwordString.get()))); - auto key = TWStoredKeyCreate(name.get(), password.get()); + auto key = TWStoredKeyCreate((const void*)&name, password.get()); auto wallet = TWStoredKeyWallet(key, password.get()); ASSERT_NE(TWStoredKeyAccountForCoin(key, TWCoinTypeEthereum, wallet), nullptr); diff --git a/trezor-crypto/tests/CMakeLists.txt b/trezor-crypto/tests/CMakeLists.txt index 53420c90f7d..36f9ca1bbb8 100644 --- a/trezor-crypto/tests/CMakeLists.txt +++ b/trezor-crypto/tests/CMakeLists.txt @@ -1,10 +1,10 @@ enable_testing() -find_library(check PATH ${CMAKE_SOURCE_DIR}/build/local/lib/pkgconfig NO_DEFAULT_PATH) +find_library(check PATH ${CMAKE_SOURCE_DIR}/wallet-core/build/local/lib/pkgconfig NO_DEFAULT_PATH) # Test executable add_executable(TrezorCryptoTests test_check.c) target_link_libraries(TrezorCryptoTests TrezorCrypto check) -target_include_directories(TrezorCryptoTests PRIVATE ${CMAKE_SOURCE_DIR}/src) +target_include_directories(TrezorCryptoTests PRIVATE ${CMAKE_SOURCE_DIR}/wallet-core/src) add_test(NAME test_check COMMAND TrezorCryptoTests)