forked from trustwallet/wallet-core
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAddress.h
More file actions
65 lines (45 loc) · 1.81 KB
/
Copy pathAddress.h
File metadata and controls
65 lines (45 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// 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 "Prefixes.h"
#include <string>
namespace TW::EOS {
class Address {
public:
/// Determines whether a string makes a valid EOS address.
static bool isValid(const std::string& string);
/// Determines whether the given byte array is a valid keyBuffer
static bool isValid(const Data& bytes, Type type = Type::Legacy);
/// Initializes a EOS address from a string representation.
Address(const std::string& string);
/// Initializes a EOS address from a public key.
Address(const PublicKey& publicKey, Type type = Type::Legacy);
/// Initializes a EOS address from a byte array.
Address(const Data& data, Type type = Type::Legacy);
/// Returns a string representation of the EOS address.
std::string string() const;
friend bool operator==(const Address& lhs, const Address& rhs);
inline std::string prefix() const { return pubPrefixForType(type); }
protected:
// Class constants
static const size_t PublicKeyDataSize = 33;
static const size_t ChecksumSize = 4;
static const size_t KeyDataSize = PublicKeyDataSize + ChecksumSize;
Data keyData;
Type type;
static uint32_t createChecksum(const Data& bytes, Type type);
static bool extractKeyData(const std::string& string, Address *address = nullptr);
};
inline bool operator==(const Address& lhs, const Address& rhs) {
return lhs.keyData == rhs.keyData
&& lhs.type == rhs.type;
}
} // namespace TW::EOS
struct TWEOSAddress {
TW::EOS::Address impl;
};