Bitcoin Core  21.99.0
P2P Digital Currency
bech32.h
Go to the documentation of this file.
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 
20 namespace bech32
21 {
22 
23 enum class Encoding {
24  INVALID,
25 
26  BECH32,
27  BECH32M,
28 };
29 
32 std::string Encode(Encoding encoding, const std::string& hrp, const std::vector<uint8_t>& values);
33 
35 {
37  std::string hrp;
38  std::vector<uint8_t> data;
39 
41  DecodeResult(Encoding enc, std::string&& h, std::vector<uint8_t>&& d) : encoding(enc), hrp(std::move(h)), data(std::move(d)) {}
42 };
43 
45 DecodeResult Decode(const std::string& str);
46 
47 } // namespace bech32
48 
49 #endif // BITCOIN_BECH32_H
bech32::Decode
DecodeResult Decode(const std::string &str)
Decode a Bech32 or Bech32m string.
Definition: bech32.cpp:168
bech32::DecodeResult::data
std::vector< uint8_t > data
The payload (excluding checksum)
Definition: bech32.h:38
bech32::DecodeResult::hrp
std::string hrp
The human readable part.
Definition: bech32.h:37
bech32::DecodeResult
Definition: bech32.h:34
bech32::Encoding::BECH32
@ BECH32
Bech32 encoding as defined in BIP173.
bech32::Encoding::INVALID
@ INVALID
Failed decoding.
bech32
Definition: bech32.cpp:10
bech32::Encoding
Encoding
Definition: bech32.h:23
bech32::Encoding::BECH32M
@ BECH32M
Bech32m encoding as defined in BIP350.
bech32::DecodeResult::DecodeResult
DecodeResult()
Definition: bech32.h:40
bech32::DecodeResult::DecodeResult
DecodeResult(Encoding enc, std::string &&h, std::vector< uint8_t > &&d)
Definition: bech32.h:41
bech32::DecodeResult::encoding
Encoding encoding
What encoding was detected in the result; Encoding::INVALID if failed.
Definition: bech32.h:36
bech32::Encode
std::string Encode(Encoding encoding, const std::string &hrp, const data &values)
Encode a Bech32 or Bech32m string.
Definition: bech32.cpp:152