base58.h raw

   1  // Copyright (c) 2009-2010 Satoshi Nakamoto
   2  // Copyright (c) 2009-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  /**
   7   * Why base-58 instead of standard base-64 encoding?
   8   * - Don't want 0OIl characters that look the same in some fonts and
   9   *      could be used to create visually identical looking data.
  10   * - A string with non-alphanumeric characters is not as easily accepted as input.
  11   * - E-mail usually won't line-break if there's no punctuation to break at.
  12   * - Double-clicking selects the whole string as one word if it's all alphanumeric.
  13   */
  14  #ifndef BITCOIN_BASE58_H
  15  #define BITCOIN_BASE58_H
  16  
  17  #include <span>
  18  #include <string>
  19  #include <vector>
  20  
  21  /**
  22   * Encode a byte span as a base58-encoded string
  23   */
  24  std::string EncodeBase58(std::span<const unsigned char> input);
  25  
  26  /**
  27   * Decode a base58-encoded string (str) into a byte vector (vchRet).
  28   * return true if decoding is successful.
  29   */
  30  [[nodiscard]] bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet, int max_ret_len);
  31  
  32  /**
  33   * Encode a byte span into a base58-encoded string, including checksum
  34   */
  35  std::string EncodeBase58Check(std::span<const unsigned char> input);
  36  
  37  /**
  38   * Decode a base58-encoded string (str) that includes a checksum into a byte
  39   * vector (vchRet), return true if decoding is successful
  40   */
  41  [[nodiscard]] bool DecodeBase58Check(const std::string& str, std::vector<unsigned char>& vchRet, int max_ret_len);
  42  
  43  #endif // BITCOIN_BASE58_H
  44