1
// Copyright © 2017-2020 Trust Wallet.
2
//
3
// This file is part of Trust. The full Trust copyright notice, including
4
// terms governing use, modification, and redistribution, is contained in the
5
// file LICENSE at the root of the source code distribution tree.
6

7
#pragma once
8

9
#include "Data.h"
10
#include "Hash.h"
11
#include "DerivationPath.h"
12
#include "PrivateKey.h"
13
#include "PublicKey.h"
14

15
#include <TrustWalletCore/TWBlockchain.h>
16
#include <TrustWalletCore/TWCoinType.h>
17
#include <TrustWalletCore/TWCurve.h>
18
#include <TrustWalletCore/TWHDVersion.h>
19
#include <TrustWalletCore/TWPurpose.h>
20

21
#include <string>
22
#include <vector>
23

24
namespace TW {
25

26
// Return the set of supported coin types.
27
std::vector<TWCoinType> getCoinTypes();
28

29
/// Validates an address for a particular coin.
30
bool validateAddress(TWCoinType coin, const std::string& address);
31

32
/// Validates and normalizes an address for a particular coin.
33
std::string normalizeAddress(TWCoinType coin, const std::string& address);
34

35
/// Returns the blockchain for a coin type.
36
TWBlockchain blockchain(TWCoinType coin);
37

38
/// Returns the purpose for a coin type.
39
TWPurpose purpose(TWCoinType coin);
40

41
/// Returns the curve that should be used for a coin type.
42
TWCurve curve(TWCoinType coin);
43

44
/// Returns the xpub HD version that should be used for a coin type.
45
TWHDVersion xpubVersion(TWCoinType coin);
46

47
/// Returns the xprv HD version that should be used for a coin type.
48
TWHDVersion xprvVersion(TWCoinType coin);
49

50
/// Returns the default derivation path for a particular coin.
51
DerivationPath derivationPath(TWCoinType coin);
52

53
/// Returns the public key type for a particular coin.
54
enum TWPublicKeyType publicKeyType(TWCoinType coin);
55

56
/// Derives the address for a particular coin from the private key.
57
std::string deriveAddress(TWCoinType coin, const PrivateKey& privateKey);
58

59
/// Derives the address for a particular coin from the public key.
60
std::string deriveAddress(TWCoinType coin, const PublicKey& publicKey);
61

62
/// Hasher for deriving the public key hash.
63
Hash::Hasher publicKeyHasher(TWCoinType coin);
64

65
/// Hasher to use for base 58 checksums.
66
Hash::Hasher base58Hasher(TWCoinType coin);
67

68
/// Returns static prefix for a coin type.
69
byte staticPrefix(TWCoinType coin);
70

71
/// Returns P2PKH prefix for a coin type.
72
byte p2pkhPrefix(TWCoinType coin);
73

74
/// Returns P2SH prefix for a coin type.
75
byte p2shPrefix(TWCoinType coin);
76

77
/// Returns human readable part for a coin type.
78
enum TWHRP hrp(TWCoinType coin);
79

80
// Note: use output parameter to avoid unneeded copies
81
void anyCoinSign(TWCoinType coinType, const Data& dataIn, Data& dataOut);
82

83
uint32_t slip44Id(TWCoinType coin);
84

85
std::string anySignJSON(TWCoinType coinType, const std::string& json, const Data& key);
86

87
bool supportsJSONSigning(TWCoinType coinType);
88

89
void anyCoinEncode(TWCoinType coinType, const Data& dataIn, Data& dataOut);
90

91
void anyCoinDecode(TWCoinType coinType, const Data& dataIn, Data& dataOut);
92

93
void anyCoinPlan(TWCoinType coinType, const Data& dataIn, Data& dataOut);
94

95
// Return coins handled by the same dispatcher as the given coin (mostly for testing)
96
const std::vector<TWCoinType> getSimilarCoinTypes(TWCoinType coinType);
97

98
// Contains only simple types.
99 1
struct CoinInfo {
100
    const char* id;
101
    const char* name;
102
    TWBlockchain blockchain;
103
    TWPurpose purpose;
104
    TWCurve curve;
105
    TWHDVersion xpubVersion;
106
    TWHDVersion xprvVersion;
107
    const char* derivationPath;
108
    TWPublicKeyType publicKeyType;
109
    byte staticPrefix;
110
    byte p2pkhPrefix;
111
    byte p2shPrefix;
112
    TWHRP hrp;
113
    Hash::Hasher publicKeyHasher;
114
    Hash::Hasher base58Hasher;
115
    const char* symbol;
116
    int decimals;
117
    const char* explorerTransactionUrl;
118
    const char* explorerAccountUrl;
119
    uint32_t slip44;
120
};
121

122
} // namespace TW

Read our documentation on viewing source code .

Loading