Bitcoin Core 22.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
20namespace bech32
21{
22
23enum class Encoding {
24 INVALID,
25
26 BECH32,
27 BECH32M,
28};
29
32std::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
45DecodeResult Decode(const std::string& str);
46
47} // namespace bech32
48
49#endif // BITCOIN_BECH32_H
Encoding
Definition: bech32.h:23
@ INVALID
Failed decoding.
@ BECH32
Bech32 encoding as defined in BIP173.
@ BECH32M
Bech32m encoding as defined in BIP350.
std::string Encode(Encoding encoding, const std::string &hrp, const data &values)
Encode a Bech32 or Bech32m string.
Definition: bech32.cpp:182
DecodeResult Decode(const std::string &str)
Decode a Bech32 or Bech32m string.
Definition: bech32.cpp:198
static const int64_t values[]
A selection of numbers that do not trigger int64_t overflow when added/subtracted.
Encoding encoding
What encoding was detected in the result; Encoding::INVALID if failed.
Definition: bech32.h:36
std::vector< uint8_t > data
The payload (excluding checksum)
Definition: bech32.h:38
DecodeResult(Encoding enc, std::string &&h, std::vector< uint8_t > &&d)
Definition: bech32.h:41
std::string hrp
The human readable part.
Definition: bech32.h:37