forked from trustwallet/wallet-core
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTWBase58.cpp
More file actions
45 lines (35 loc) · 1.4 KB
/
TWBase58.cpp
File metadata and controls
45 lines (35 loc) · 1.4 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
// 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.
#include <TrustWalletCore/TWBase58.h>
#include "../Base58.h"
#include <string>
using namespace TW;
TWString *_Nonnull TWBase58Encode(TWData *_Nonnull data) {
auto& d = *reinterpret_cast<const Data*>(data);
const auto str = Base58::bitcoin.encodeCheck(d);
return TWStringCreateWithUTF8Bytes(str.c_str());
}
TWString *_Nonnull TWBase58EncodeNoCheck(TWData *_Nonnull data) {
auto& d = *reinterpret_cast<const Data*>(data);
const auto encoded = Base58::bitcoin.encode(d);
return TWStringCreateWithUTF8Bytes(encoded.c_str());
}
TWData *_Nullable TWBase58Decode(TWString *_Nonnull string) {
auto& s = *reinterpret_cast<const std::string*>(string);
const auto decoded = Base58::bitcoin.decodeCheck(s);
if (decoded.empty()) {
return nullptr;
}
return TWDataCreateWithBytes(decoded.data(), decoded.size());
}
TWData *_Nullable TWBase58DecodeNoCheck(TWString *_Nonnull string) {
auto& s = *reinterpret_cast<const std::string*>(string);
const auto decoded = Base58::bitcoin.decode(s);
if (decoded.empty()) {
return nullptr;
}
return TWDataCreateWithBytes(decoded.data(), decoded.size());
}