-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathTWBitcoinAddress.h
More file actions
87 lines (71 loc) · 2.92 KB
/
Copy pathTWBitcoinAddress.h
File metadata and controls
87 lines (71 loc) · 2.92 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// SPDX-License-Identifier: Apache-2.0
//
// Copyright © 2017 Trust Wallet.
#pragma once
#include "TWBase.h"
#include "TWData.h"
#include "TWString.h"
TW_EXTERN_C_BEGIN
struct TWPublicKey;
/// Represents a legacy Bitcoin address in C++.
TW_EXPORT_CLASS
struct TWBitcoinAddress;
/// Compares two addresses for equality.
///
/// \param lhs The first address to compare.
/// \param rhs The second address to compare.
/// \return bool indicating the addresses are equal.
TW_EXPORT_STATIC_METHOD
bool TWBitcoinAddressEqual(struct TWBitcoinAddress *_Nonnull lhs, struct TWBitcoinAddress *_Nonnull rhs);
/// Determines if the data is a valid Bitcoin address.
///
/// \param data data to validate.
/// \return bool indicating if the address data is valid.
TW_EXPORT_STATIC_METHOD
bool TWBitcoinAddressIsValid(TWData *_Nonnull data);
/// Determines if the string is a valid Bitcoin address.
///
/// \param string string to validate.
/// \return bool indicating if the address string is valid.
TW_EXPORT_STATIC_METHOD
bool TWBitcoinAddressIsValidString(TWString *_Nonnull string);
/// Initializes an address from a Base58 sring. Must be deleted with TWBitcoinAddressDelete after use.
///
/// \param string Base58 string to initialize the address from.
/// \return TWBitcoinAddress pointer or nullptr if string is invalid.
TW_EXPORT_STATIC_METHOD
struct TWBitcoinAddress *_Nullable TWBitcoinAddressCreateWithString(TWString *_Nonnull string);
/// Initializes an address from raw data.
///
/// \param data Raw data to initialize the address from. Must be deleted with TWBitcoinAddressDelete after use.
/// \return TWBitcoinAddress pointer or nullptr if data is invalid.
TW_EXPORT_STATIC_METHOD
struct TWBitcoinAddress *_Nullable TWBitcoinAddressCreateWithData(TWData *_Nonnull data);
/// Initializes an address from a public key and a prefix byte.
///
/// \param publicKey Public key to initialize the address from.
/// \param prefix Prefix byte (p2pkh, p2sh, etc).
/// \return TWBitcoinAddress pointer or nullptr if public key is invalid.
TW_EXPORT_STATIC_METHOD
struct TWBitcoinAddress *_Nullable TWBitcoinAddressCreateWithPublicKey(struct TWPublicKey *_Nonnull publicKey, uint8_t prefix);
/// Deletes a legacy Bitcoin address.
///
/// \param address Address to delete.
TW_EXPORT_METHOD
void TWBitcoinAddressDelete(struct TWBitcoinAddress *_Nonnull address);
/// Returns the address in Base58 string representation.
///
/// \param address Address to get the string representation of.
TW_EXPORT_PROPERTY
TWString *_Nonnull TWBitcoinAddressDescription(struct TWBitcoinAddress *_Nonnull address);
/// Returns the address prefix.
///
/// \param address Address to get the prefix of.
TW_EXPORT_PROPERTY
uint8_t TWBitcoinAddressPrefix(struct TWBitcoinAddress *_Nonnull address);
/// Returns the key hash data.
///
/// \param address Address to get the keyhash data of.
TW_EXPORT_PROPERTY
TWData *_Nonnull TWBitcoinAddressKeyhash(struct TWBitcoinAddress *_Nonnull address);
TW_EXTERN_C_END