IoTeX client
bech32.h
1// Copyright (c) 2017, 2021 Pieter Wuille
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5// Bech32 and Bech32m are string encoding formats used in newer
6// address types. The outputs consist of a human-readable part
7// (alphanumeric), a separator character (1), and a base32 data
8// section, the last 6 characters of which are a checksum. The
9// module is namespaced under bech32 for historical reasons.
10//
11// For more information, see BIP 173 and BIP 350.
12
13#ifndef BITCOIN_BECH32_H
14#define BITCOIN_BECH32_H
15
16#include <stdint.h>
17#include <string>
18#include <vector>
19
20namespace bech32
21{
22
23enum class Encoding
24{
25 INVALID,
26
27 BECH32,
28 BECH32M,
29};
30
34std::string Encode(Encoding encoding, const std::string& hrp, const std::vector<uint8_t>& values);
35
37{
38 Encoding encoding;
40 std::string hrp;
41 std::vector<uint8_t> data;
42
43 DecodeResult() : encoding(Encoding::INVALID)
44 {
45 }
46 DecodeResult(Encoding enc, std::string&& h, std::vector<uint8_t>&& d) :
47 encoding(enc), hrp(std::move(h)), data(std::move(d))
48 {
49 }
50};
51
53DecodeResult Decode(const std::string& str);
54} // namespace bech32
55
56#endif // BITCOIN_BECH32_H
Definition: bech32.h:37
Encoding encoding
Definition: bech32.h:38
std::vector< uint8_t > data
The payload (excluding checksum)
Definition: bech32.h:41
std::string hrp
The human readable part.
Definition: bech32.h:40