forked from trustwallet/wallet-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XAddress.h
57 lines (40 loc) · 1.46 KB
/
XAddress.h
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
// Copyright © 2017-2023 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::Ripple {
enum class TagFlag: byte { none = 0x00, classic = 0x01};
class XAddress {
public:
/// Number of bytes in a X-address.
static const size_t size = 31;
/// Public key hash length.
static const size_t keyHashSize = 20;
/// Address data consisting of public key hash
std::array<byte, keyHashSize> bytes;
/// destination tag
uint32_t tag;
/// destination tag flag, none/32/64bit
TagFlag flag = TagFlag::classic;
/// Determines whether a string makes a valid address.
static bool isValid(const std::string& string);
/// Initializes a Ripple X-address with a string representation.
explicit XAddress(const std::string& string);
/// Initializes a Ripple X-address with a public key.
explicit XAddress(const PublicKey& publicKey, const uint32_t tag);
/// Returns a string representation of the address.
std::string string() const;
};
inline bool operator==(const XAddress& lhs, const XAddress& rhs) {
return lhs.bytes == rhs.bytes;
}
} // namespace TW::Ripple
/// Wrapper for C interface.
struct TWRippleXAddress {
TW::Ripple::XAddress impl;
};