forked from trustwallet/wallet-core
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCashAddress.h
More file actions
55 lines (40 loc) · 1.57 KB
/
Copy pathCashAddress.h
File metadata and controls
55 lines (40 loc) · 1.57 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
// 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 "Address.h"
#include "../PublicKey.h"
#include <cstdint>
#include <string>
namespace TW::Bitcoin {
class CashAddress {
public:
/// Number of bytes in an address.
static const size_t size = 34;
/// Address data consisting of a prefix byte followed by the public key
/// hash.
std::array<byte, size> bytes;
/// Determines whether a collection of bytes makes a valid address.
template <typename T>
static bool isValid(const T& data) {
return data.size() == size && (data[0] == 0 || data[0] == 1);
}
/// Determines whether a string makes a valid address.
static bool isValid(const std::string& string);
/// Initializes a address with a string representation.
explicit CashAddress(const std::string& string);
/// Initializes a address with a collection of bytes.
explicit CashAddress(const std::vector<uint8_t>& data);
/// Initializes a address with a public key.
explicit CashAddress(const PublicKey& publicKey);
/// Returns a string representation of the address.
std::string string() const;
/// Returns the legacy address representation.
Address legacyAddress() const;
};
inline bool operator==(const CashAddress& lhs, const CashAddress& rhs) {
return lhs.bytes == rhs.bytes;
}
} // namespace TW::Bitcoin