Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Dgld 2 #3

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ xcode/
cmake-build-debug/
.cquery_cache/
.cxx/
CMakeCache.txt
CMakeFiles/

# Dependencies
node_modules
Expand Down
23 changes: 22 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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=libc++")
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)

Expand All @@ -18,6 +22,7 @@ else()
set(PREFIX "$ENV{PREFIX}")
endif()


include_directories(${PREFIX}/include)
link_directories(${PREFIX}/lib)

Expand Down Expand Up @@ -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: <https://developercommunity.visualstudio.com/content/problem/171290/android-ndk-include-paths-are-incorrect.html>
include_directories(BEFORE SYSTEM
$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
/usr/include/x86_64-linux-gnu/c++/7.5.0
/usr/include/c++/7.5.0
)
endif()
Original file line number Diff line number Diff line change
@@ -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())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you planning to add test cases here? Seems like you already have one working on C++ core level

}
}
Original file line number Diff line number Diff line change
@@ -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())
//)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

}
}
2 changes: 1 addition & 1 deletion bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,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 -j12 tests TrezorCryptoTests

if [ -x "$(command -v clang-tidy)" ]; then
Expand Down
4 changes: 2 additions & 2 deletions cmake/Protobuf.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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)
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

Expand Down
36 changes: 36 additions & 0 deletions coins.json
Original file line number Diff line number Diff line change
Expand Up @@ -1380,5 +1380,41 @@
"clientPublic": "https://api.elrond.com",
"clientDocs": "https://docs.elrond.com"
}
},
{
"id": "dgld",
"name": "DigitalGold",
"symbol": "DGLD",
"decimals": 8,
"blockchain": "Bitcoin",
"derivationPath": "m/44'/452'/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"
}
}
]






1 change: 1 addition & 0 deletions docs/coins.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ This list is generated from [./coins.json](../coins.json)
| 397 | NEAR | NEAR | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/near/info/logo.png" width="32" /> | <https://nearprotocol.com> |
| 425 | Aion | AION | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/aion/info/logo.png" width="32" /> | <https://aion.network> |
| 434 | Kusama | KSM | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/kusama/info/logo.png" width="32" /> | <https://kusama.network> |
| 452 | DigitalGold | DGLD | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/dgld/info/logo.png" width="32" /> | <https://dgld.ch/> |
| 457 | Aeternity | AE | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/aeternity/info/logo.png" width="32" /> | <https://aeternity.com> |
| 459 | Kava | KAVA | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/kava/info/logo.png" width="32" /> | <https://kava.io> |
| 461 | Filecoin | FIL | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/filecoin/info/logo.png" width="32" /> | <https://filecoin.io/> |
Expand Down
1 change: 1 addition & 0 deletions include/TrustWalletCore/TWCoinType.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ enum TWCoinType {
TWCoinTypePolkadot = 354,
TWCoinTypeFilecoin = 461,
TWCoinTypeElrond = 508,
TWCoinTypeDigitalGold = 452,
};

/// Returns the blockchain for a coin type.
Expand Down
5 changes: 3 additions & 2 deletions src/Base58.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <algorithm>
#include <cctype>
#include <cassert>

using namespace TW;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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); });
Copy link

@pavel-bc pavel-bc May 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a new requirement enforced by altered build flags?
I still see the old lines in upstream master - https://github.com/trustwallet/wallet-core/blob/master/src/Base58.cpp#L80

if (it != end) {
// Extra charaters at the end
return {};
Expand Down
7 changes: 5 additions & 2 deletions src/Base58Address.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ class Base58Address {
std::array<byte, size> bytes;

/// Determines whether a collection of bytes makes a valid address.
template <typename T>
static bool isValid(const T& data) {
static bool isValid(const Data& data) {
return data.size() == size;
}
/*template <typename T>
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) {
Expand Down
1 change: 1 addition & 0 deletions src/BinaryCoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <cstdint>
#include <vector>
#include <string>
#include <tuple>

namespace TW {

Expand Down
2 changes: 2 additions & 0 deletions src/Bitcoin/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ bool Entry::validateAddress(TWCoinType coin, const string& address, TW::byte p2p
case TWCoinTypeMonacoin:
case TWCoinTypeQtum:
case TWCoinTypeViacoin:
case TWCoinTypeDigitalGold:
case TWCoinTypeBitcoinGold:
return SegwitAddress::isValid(address, hrp)
|| Address::isValid(address, {{p2pkh}, {p2sh}});
Expand Down Expand Up @@ -73,6 +74,7 @@ string Entry::deriveAddress(TWCoinType coin, const PublicKey& publicKey, TW::byt
case TWCoinTypeQtum:
case TWCoinTypeRavencoin:
case TWCoinTypeZcoin:
case TWCoinTypeDigitalGold:
default:
return Address(publicKey, p2pkh).string();
}
Expand Down
1 change: 1 addition & 0 deletions src/Bitcoin/Entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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;
Expand Down
1 change: 1 addition & 0 deletions src/Bitcoin/Script.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <string>
#include <vector>
#include <cassert>

namespace TW::Bitcoin {

Expand Down
4 changes: 4 additions & 0 deletions src/Data.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ inline Data data(const byte* data, size_t size) {
return std::vector<byte>(data, data + size);
}

inline Data data(byte b) {
return std::vector<byte>({b});
}

inline void append(Data& data, const Data& suffix) {
data.insert(data.end(), suffix.begin(), suffix.end());
}
Expand Down
1 change: 1 addition & 0 deletions src/Encrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Data.h"
#include <TrezorCrypto/aes.h>
#include <cassert>
#include <cstring>

namespace TW::Encrypt {

Expand Down
2 changes: 2 additions & 0 deletions src/Filecoin/Address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "../Base32.h"
#include "../Data.h"

#include <cstring>

using namespace TW;
using namespace TW::Filecoin;

Expand Down
1 change: 1 addition & 0 deletions src/HDWallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <TrustWalletCore/TWHRP.h>

#include <array>
#include <cstring>

using namespace TW;

Expand Down
1 change: 1 addition & 0 deletions src/NEO/ReadData.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#pragma once

#include <cctype>
#include <climits>

#include "../Data.h"
#include "../BinaryCoding.h"
Expand Down
1 change: 1 addition & 0 deletions src/Nebulas/Address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../Base58.h"
#include "../Hash.h"
#include "../HexCoding.h"
#include <cstring>

using namespace TW::Nebulas;

Expand Down
1 change: 1 addition & 0 deletions src/Waves/Address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <HexCoding.h>
#include <cassert>
#include <stdexcept>
#include <cstring>

using namespace TW;
using namespace TW::Waves;
Expand Down
1 change: 1 addition & 0 deletions src/interface/TWStoredKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <stdexcept>
#include <cassert>


using namespace TW::Keystore;

struct TWStoredKey* _Nullable TWStoredKeyLoad(TWString* _Nonnull path) {
Expand Down
28 changes: 28 additions & 0 deletions swift/Tests/Blockchains/DigitalGoldTests.swift
Original file line number Diff line number Diff line change
@@ -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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And on Swift level too

}

func testSign() {
// TODO: Create implementation
}
}
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/local/src/gtest/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)

Expand Down
Loading