Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
bech32.h
Go to the documentation of this file.
1
// Copyright (c) 2017, 2021 Pieter Wuille
2
// Copyright (c) 2021-present The Bitcoin Core developers
3
// Distributed under the MIT software license, see the accompanying
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6
// Bech32 and Bech32m are string encoding formats used in newer
7
// address types. The outputs consist of a human-readable part
8
// (alphanumeric), a separator character (1), and a base32 data
9
// section, the last 6 characters of which are a checksum. The
10
// module is namespaced under bech32 for historical reasons.
11
//
12
// For more information, see BIP 173 and BIP 350.
13
14
#ifndef BITCOIN_BECH32_H
15
#define BITCOIN_BECH32_H
16
17
#include <cstddef>
18
#include <cstdint>
19
#include <string>
20
#include <utility>
21
#include <vector>
22
23
namespace
bech32
24
{
25
26
inline
constexpr
size_t
CHECKSUM_SIZE
= 6;
27
inline
constexpr
char
SEPARATOR
=
'1'
;
28
29
enum class
Encoding
{
30
INVALID,
31
32
BECH32
,
33
BECH32M
,
34
};
35
40
enum
CharLimit
:
size_t
{
41
BECH32
= 90,
42
};
43
46
std::string
Encode
(
Encoding
encoding,
const
std::string& hrp,
const
std::vector<uint8_t>& values);
47
48
struct
DecodeResult
49
{
50
Encoding
encoding
;
51
std::string
hrp
;
52
std::vector<uint8_t>
data
;
53
54
DecodeResult
() :
encoding
(
Encoding
::INVALID) {}
55
DecodeResult
(
Encoding
enc, std::string&& h, std::vector<uint8_t>&& d) :
encoding
(enc),
hrp
(
std
::move(h)),
data
(
std
::move(d)) {}
56
};
57
59
DecodeResult
Decode
(
const
std::string& str,
CharLimit
limit =
CharLimit::BECH32
);
60
62
std::pair<std::string, std::vector<int>>
LocateErrors
(
const
std::string& str,
CharLimit
limit =
CharLimit::BECH32
);
63
64
}
// namespace bech32
65
66
#endif
// BITCOIN_BECH32_H
bech32
Definition
bech32.cpp:14
bech32::LocateErrors
std::pair< std::string, std::vector< int > > LocateErrors(const std::string &str, CharLimit limit)
Find index of an incorrect character in a Bech32 string.
Definition
bech32.cpp:402
bech32::Encoding
Encoding
Definition
bech32.h:29
bech32::Encoding::BECH32M
@ BECH32M
Bech32m encoding as defined in BIP350.
Definition
bech32.h:33
bech32::CharLimit
CharLimit
Character limits for Bech32(m) encoded strings.
Definition
bech32.h:40
bech32::BECH32
@ BECH32
BIP173/350 imposed character limit for Bech32(m) encoded addresses. This guarantees finding up to 4 e...
Definition
bech32.h:41
bech32::Decode
DecodeResult Decode(const std::string &str, CharLimit limit)
Decode a Bech32 or Bech32m string.
Definition
bech32.cpp:373
bech32::Encode
std::string Encode(Encoding encoding, const std::string &hrp, const data &values)
Encode a Bech32 or Bech32m string.
Definition
bech32.cpp:357
bech32::CHECKSUM_SIZE
constexpr size_t CHECKSUM_SIZE
Definition
bech32.h:26
bech32::SEPARATOR
constexpr char SEPARATOR
Definition
bech32.h:27
std
Definition
transaction.h:420
bech32::DecodeResult::encoding
Encoding encoding
What encoding was detected in the result; Encoding::INVALID if failed.
Definition
bech32.h:50
bech32::DecodeResult::data
std::vector< uint8_t > data
The payload (excluding checksum).
Definition
bech32.h:52
bech32::DecodeResult::DecodeResult
DecodeResult(Encoding enc, std::string &&h, std::vector< uint8_t > &&d)
Definition
bech32.h:55
bech32::DecodeResult::hrp
std::string hrp
The human readable part.
Definition
bech32.h:51
bech32::DecodeResult::DecodeResult
DecodeResult()
Definition
bech32.h:54
Generated on
for Bitcoin Core by
1.18.0