PageRenderTime 1510ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/src/bech32.h

https://github.com/denis2342/bitcoin
C Header | 49 lines | 24 code | 12 blank | 13 comment | 0 complexity | 13d70856fa6cb95507c2ab2fe0b3ee1f MD5 | raw 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. // Bech32 and Bech32m are string encoding formats used in newer
  5. // address types. The outputs consist of a human-readable part
  6. // (alphanumeric), a separator character (1), and a base32 data
  7. // section, the last 6 characters of which are a checksum. The
  8. // module is namespaced under bech32 for historical reasons.
  9. //
  10. // For more information, see BIP 173 and BIP 350.
  11. #ifndef BITCOIN_BECH32_H
  12. #define BITCOIN_BECH32_H
  13. #include <stdint.h>
  14. #include <string>
  15. #include <vector>
  16. namespace bech32
  17. {
  18. enum class Encoding {
  19. INVALID, //!< Failed decoding
  20. BECH32, //!< Bech32 encoding as defined in BIP173
  21. BECH32M, //!< Bech32m encoding as defined in BIP350
  22. };
  23. /** Encode a Bech32 or Bech32m string. If hrp contains uppercase characters, this will cause an
  24. * assertion error. Encoding must be one of BECH32 or BECH32M. */
  25. std::string Encode(Encoding encoding, const std::string& hrp, const std::vector<uint8_t>& values);
  26. struct DecodeResult
  27. {
  28. Encoding encoding; //!< What encoding was detected in the result; Encoding::INVALID if failed.
  29. std::string hrp; //!< The human readable part
  30. std::vector<uint8_t> data; //!< The payload (excluding checksum)
  31. DecodeResult() : encoding(Encoding::INVALID) {}
  32. DecodeResult(Encoding enc, std::string&& h, std::vector<uint8_t>&& d) : encoding(enc), hrp(std::move(h)), data(std::move(d)) {}
  33. };
  34. /** Decode a Bech32 or Bech32m string. */
  35. DecodeResult Decode(const std::string& str);
  36. } // namespace bech32
  37. #endif // BITCOIN_BECH32_H