-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
503 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...c/androidTest/java/com/trustwallet/core/app/blockchains/everscale/TestEverscaleAddress.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright © 2017-2021 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.everscale | ||
|
||
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 TestEverscaleAddress { | ||
|
||
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.EVERSCALE) | ||
val expected = AnyAddress("__EXPECTED_RESULT_ADDRESS__", CoinType.EVERSCALE) | ||
|
||
assertEquals(pubkey.data().toHex(), "0x__EXPECTED_PUBKEY_DATA__") | ||
assertEquals(address.description(), expected.description()) | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...rc/androidTest/java/com/trustwallet/core/app/blockchains/everscale/TestEverscaleSigner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright © 2017-2021 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.everscale | ||
|
||
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 org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import wallet.core.jni.EverscaleSigner | ||
import wallet.core.jni.proto.Everscale | ||
|
||
class TestEverscaleSigner { | ||
|
||
init { | ||
System.loadLibrary("TrustWalletCore") | ||
} | ||
|
||
@Test | ||
fun EverscaleTransactionSigning() { | ||
// TODO: Finalize implementation | ||
|
||
//val transfer = Everscale.TransferMessage.newBuilder() | ||
// .setTo("...") | ||
// .setAmount(...) | ||
// ... | ||
// .build() | ||
//val signingInput = Everscale.SigningInput.newBuilder() | ||
// ... | ||
// .build() | ||
|
||
//val output: Everscale.SigningOutput = EverscaleSigner.sign(signingInput) | ||
|
||
//assertEquals( | ||
// "__EXPECTED_RESULT_DATA__", | ||
// Numeric.toHexString(output.encoded.toByteArray()) | ||
//) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright © 2017-2021 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::Everscale; | ||
|
||
bool Address::isValid(const std::string& string) { | ||
// TODO: Finalize implementation | ||
return false; | ||
} | ||
|
||
Address::Address(const std::string& string) { | ||
// TODO: Finalize implementation | ||
|
||
if (!isValid(string)) { | ||
throw std::invalid_argument("Invalid address string"); | ||
} | ||
} | ||
|
||
Address::Address(const PublicKey& publicKey) { | ||
// TODO: Finalize implementation | ||
} | ||
|
||
std::string Address::string() const { | ||
// TODO: Finalize implementation | ||
return "TODO"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright © 2017-2021 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 <string> | ||
|
||
namespace TW::Everscale { | ||
|
||
class Address { | ||
public: | ||
// TODO: Complete class definition | ||
|
||
/// Determines whether a string makes a valid address. | ||
static bool isValid(const std::string& string); | ||
|
||
/// Initializes a Everscale address with a string representation. | ||
explicit Address(const std::string& string); | ||
|
||
/// Initializes a Everscale address with a public key. | ||
explicit Address(const PublicKey& publicKey); | ||
|
||
/// Returns a string representation of the address. | ||
std::string string() const; | ||
}; | ||
|
||
inline bool operator==(const Address& lhs, const Address& rhs) { | ||
// TODO: Complete equality operator | ||
return true; | ||
} | ||
|
||
} // namespace TW::Everscale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright © 2017-2021 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 "Entry.h" | ||
|
||
#include "Address.h" | ||
#include "Signer.h" | ||
|
||
using namespace TW::Everscale; | ||
using namespace std; | ||
|
||
// Note: avoid business logic from here, rather just call into classes like Address, Signer, etc. | ||
|
||
bool Entry::validateAddress(TWCoinType coin, const string& address, TW::byte, TW::byte, const char*) const { | ||
return Address::isValid(address); | ||
} | ||
|
||
string Entry::deriveAddress(TWCoinType coin, const PublicKey& publicKey, TW::byte, const char*) const { | ||
return Address(publicKey).string(); | ||
} | ||
|
||
void Entry::sign(TWCoinType coin, const TW::Data& dataIn, TW::Data& dataOut) const { | ||
signTemplate<Signer, Proto::SigningInput>(dataIn, dataOut); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright © 2017-2021 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 "../CoinEntry.h" | ||
|
||
namespace TW::Everscale { | ||
|
||
/// Entry point for implementation of Everscale coin. | ||
/// Note: do not put the implementation here (no matter how simple), to avoid having coin-specific includes in this file | ||
class Entry: public CoinEntry { | ||
public: | ||
virtual bool validateAddress(TWCoinType coin, const std::string& address, TW::byte p2pkh, TW::byte p2sh, const char* hrp) const; | ||
virtual std::string deriveAddress(TWCoinType coin, const PublicKey& publicKey, TW::byte p2pkh, const char* hrp) const; | ||
virtual void sign(TWCoinType coin, const Data& dataIn, Data& dataOut) const; | ||
// normalizeAddress(): implement this if needed, e.g. Ethereum address is EIP55 checksummed | ||
}; | ||
|
||
} // namespace TW::Everscale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright © 2017-2021 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 "Signer.h" | ||
#include "Address.h" | ||
#include "../PublicKey.h" | ||
|
||
using namespace TW; | ||
using namespace TW::Everscale; | ||
|
||
|
||
Proto::SigningOutput Signer::sign(const Proto::SigningInput &input) noexcept { | ||
// TODO: Check and finalize implementation | ||
|
||
auto protoOutput = Proto::SigningOutput(); | ||
Data encoded; | ||
// auto privateKey = PrivateKey(Data(input.private_key().begin(), input.private_key().end())); | ||
// auto signature = privateKey.sign(payload, TWCurveED25519); | ||
// encoded = encodeSignature(signature); | ||
|
||
protoOutput.set_encoded(encoded.data(), encoded.size()); | ||
return protoOutput; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright © 2017-2021 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 "../PrivateKey.h" | ||
#include "../proto/Everscale.pb.h" | ||
|
||
namespace TW::Everscale { | ||
|
||
/// Helper class that performs Everscale transaction signing. | ||
class Signer { | ||
public: | ||
/// Hide default constructor | ||
Signer() = delete; | ||
|
||
/// Signs a Proto::SigningInput transaction | ||
static Proto::SigningOutput sign(const Proto::SigningInput& input) noexcept; | ||
}; | ||
|
||
} // namespace TW::Everscale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright © 2017-2021 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. | ||
|
||
syntax = "proto3"; | ||
|
||
package TW.Everscale.Proto; | ||
option java_package = "wallet.core.jni.proto"; | ||
|
||
// TODO: typical balance transfer, add more fields needed to sign | ||
message TransferMessage { | ||
int64 amount = 1; | ||
int64 fee = 2; | ||
string to = 3; | ||
} | ||
|
||
// TODO: Input data necessary to create a signed transaction. | ||
message SigningInput { | ||
bytes private_key = 1; | ||
|
||
oneof message_oneof { | ||
TransferMessage transfer = 2; | ||
} | ||
} | ||
|
||
// Transaction signing output. | ||
message SigningOutput { | ||
// Signed and encoded transaction bytes. | ||
bytes encoded = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright © 2017-2021 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 WalletCore | ||
import XCTest | ||
|
||
class EverscaleTests: 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: .everscale) | ||
let addressFromString = AnyAddress(string: "__ADDRESS_DATA__", coin: .everscale)! | ||
|
||
XCTAssertEqual(pubkey.data.hexString, "__EXPECTED_PUBKEY_DATA__") | ||
XCTAssertEqual(address.description, addressFromString.description) | ||
} | ||
|
||
func testSign() { | ||
// TODO: Create implementation | ||
} | ||
} |
Oops, something went wrong.