Skip to content

Commit

Permalink
Generate Everscale coin stub
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon authored and pashinov committed Jul 29, 2022
1 parent c055ff8 commit 889d777
Show file tree
Hide file tree
Showing 20 changed files with 503 additions and 0 deletions.
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())
}
}
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())
//)
}
}
1 change: 1 addition & 0 deletions docs/registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ This list is generated from [./registry.json](../registry.json)
| 330 | Terra Classic | LUNC | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/terra/info/logo.png" width="32" /> | <https://terra.money> |
| 354 | Polkadot | DOT | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/polkadot/info/logo.png" width="32" /> | <https://polkadot.network/> |
| 394 | Crypto.org | CRO | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/cryptoorg/info/logo.png" width="32" /> | <https://crypto.org/> |
| 396 | Everscale | EVER | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/everscale/info/logo.png" width="32" /> | <https://everscale.network/> |
| 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> |
Expand Down
1 change: 1 addition & 0 deletions include/TrustWalletCore/TWBlockchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ enum TWBlockchain {
TWBlockchainThorchain = 38, // Cosmos
TWBlockchainRonin = 39, // Ethereum
TWBlockchainKusama = 40, // Polkadot
TWBlockchainEverscale = 41, // TODO remove if the blockchain already exists, or just remove this comment if not
};

TW_EXTERN_C_END
1 change: 1 addition & 0 deletions include/TrustWalletCore/TWCoinType.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ enum TWCoinType {
TWCoinTypeKlaytn = 10008217,
TWCoinTypeMeter = 18000,
TWCoinTypeOKXChain = 996,
TWCoinTypeEverscale = 396,
};

/// Returns the blockchain for a coin type.
Expand Down
27 changes: 27 additions & 0 deletions registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,33 @@
"documentation": "https://polkadot.js.org/api/substrate/rpc.html"
}
},
{
"id": "everscale",
"name": "Everscale",
"coinId": 396,
"symbol": "EVER",
"decimals": 9,
"blockchain": "Everscale",
"derivation": [
{
"path": "m/44'/396'/0'/0/0"
}
],
"curve": "ed25519",
"publicKeyType": "ed25519",
"explorer": {
"url": "https://everscan.io",
"txPath": "/transactions/",
"accountPath": "/accounts/",
"sampleTx": "781238b2b0d15cd4cd2e2a0a142753750cd5e1b2c8b506fcede75a90e02f1268",
"sampleAccount": "0:d2bf59964a05dee84a0dd1ddc0ad83ba44d49719cf843d689dc8b726d0fb59d8"
},
"info": {
"url": "https://everscale.network/",
"source": "https://github.com/broxus/ton-wallet-api",
"documentation": "https://tonapi.broxus.com/ton/v3/swagger.yaml"
}
},
{
"id": "near",
"name": "NEAR",
Expand Down
3 changes: 3 additions & 0 deletions src/Coin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "Waves/Entry.h"
#include "Zcash/Entry.h"
#include "Zilliqa/Entry.h"
#include "Everscale/Entry.h" // TODO remove if the blockchain already exists, or just remove this comment if not
// end_of_coin_includes_marker_do_not_modify

using namespace TW;
Expand Down Expand Up @@ -97,6 +98,7 @@ VeChain::Entry vechainDP;
Waves::Entry wavesDP;
Zcash::Entry zcashDP;
Zilliqa::Entry zilliqaDP;
Everscale::Entry EverscaleDP; // TODO remove if the blockchain already exists, or just remove this comment if not
// end_of_coin_dipatcher_declarations_marker_do_not_modify

CoinEntry* coinDispatcher(TWCoinType coinType) {
Expand Down Expand Up @@ -144,6 +146,7 @@ CoinEntry* coinDispatcher(TWCoinType coinType) {
case TWBlockchainThorchain: entry = &thorchainDP; break;
case TWBlockchainRonin: entry = &roninDP; break;
case TWBlockchainKusama: entry = &kusamaDP; break;
case TWCoinTypeEverscale: entry = &EverscaleDP; break; // TODO remove if the blockchain already exists, or just remove this comment if not
// end_of_coin_dipatcher_switch_marker_do_not_modify

default: entry = nullptr; break;
Expand Down
31 changes: 31 additions & 0 deletions src/Everscale/Address.cpp
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";
}
38 changes: 38 additions & 0 deletions src/Everscale/Address.h
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
27 changes: 27 additions & 0 deletions src/Everscale/Entry.cpp
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);
}
23 changes: 23 additions & 0 deletions src/Everscale/Entry.h
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
26 changes: 26 additions & 0 deletions src/Everscale/Signer.cpp
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;
}
25 changes: 25 additions & 0 deletions src/Everscale/Signer.h
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
32 changes: 32 additions & 0 deletions src/proto/Everscale.proto
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;
}
28 changes: 28 additions & 0 deletions swift/Tests/Blockchains/EverscaleTests.swift
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
}
}
Loading

0 comments on commit 889d777

Please sign in to comment.