diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2017-08-25 18:12:39 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2017-09-28 16:02:16 -0700 |
commit | 8fd226705347c2b3955d0d98f8ca21e4325e6765 (patch) | |
tree | 0a5e9d0e14fddb614700a06d00cd5ae23955780a /src/bech32.h | |
parent | 1e46ebdf8618e585568ffc1b093c79cc9be07b57 (diff) |
Import Bech32 C++ reference code & tests
This includes a reformatted version of the Bech32 reference code
(see https://github.com/sipa/bech32/tree/master/ref/c%2B%2B), with
extra documentation.
Diffstat (limited to 'src/bech32.h')
-rw-r--r-- | src/bech32.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/bech32.h b/src/bech32.h new file mode 100644 index 0000000000..7ef7b22213 --- /dev/null +++ b/src/bech32.h @@ -0,0 +1,25 @@ +// Copyright (c) 2017 Pieter Wuille +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +// Bech32 is a string encoding format used in newer address types. +// The output consists of a human-readable part (alphanumeric), a +// separator character (1), and a base32 data section, the last +// 6 characters of which are a checksum. +// +// For more information, see BIP 173. + +#include <stdint.h> +#include <string> +#include <vector> + +namespace bech32 +{ + +/** Encode a Bech32 string. Returns the empty string in case of failure. */ +std::string Encode(const std::string& hrp, const std::vector<uint8_t>& values); + +/** Decode a Bech32 string. Returns (hrp, data). Empty hrp means failure. */ +std::pair<std::string, std::vector<uint8_t>> Decode(const std::string& str); + +} // namespace bech32 |