2010-08-29 12:58:15 -04:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2018-07-26 18:36:45 -04:00
|
|
|
// Copyright (c) 2009-2018 The Bitcoin Core developers
|
2014-10-30 21:43:19 -03:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2012-05-18 10:02:28 -04:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2010-08-29 12:58:15 -04:00
|
|
|
|
2014-10-30 21:43:19 -03:00
|
|
|
/**
|
|
|
|
* Why base-58 instead of standard base-64 encoding?
|
|
|
|
* - Don't want 0OIl characters that look the same in some fonts and
|
2015-04-28 11:47:17 -03:00
|
|
|
* could be used to create visually identical looking data.
|
|
|
|
* - A string with non-alphanumeric characters is not as easily accepted as input.
|
2014-10-30 21:43:19 -03:00
|
|
|
* - E-mail usually won't line-break if there's no punctuation to break at.
|
2015-04-28 11:47:17 -03:00
|
|
|
* - Double-clicking selects the whole string as one word if it's all alphanumeric.
|
2014-10-30 21:43:19 -03:00
|
|
|
*/
|
2011-05-15 03:11:04 -04:00
|
|
|
#ifndef BITCOIN_BASE58_H
|
|
|
|
#define BITCOIN_BASE58_H
|
2010-08-29 12:58:15 -04:00
|
|
|
|
2018-09-25 02:00:36 -03:00
|
|
|
#include <attributes.h>
|
|
|
|
|
2013-04-13 02:13:08 -03:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2014-04-06 23:30:04 -03:00
|
|
|
/**
|
2014-04-12 18:34:00 -03:00
|
|
|
* Encode a byte sequence as a base58-encoded string.
|
2017-08-07 01:36:37 -04:00
|
|
|
* pbegin and pend cannot be nullptr, unless both are.
|
2014-04-06 23:30:04 -03:00
|
|
|
*/
|
2014-04-12 18:34:00 -03:00
|
|
|
std::string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend);
|
2010-08-29 12:58:15 -04:00
|
|
|
|
2014-04-06 23:30:04 -03:00
|
|
|
/**
|
|
|
|
* Encode a byte vector as a base58-encoded string
|
|
|
|
*/
|
2014-05-09 17:42:20 -04:00
|
|
|
std::string EncodeBase58(const std::vector<unsigned char>& vch);
|
2010-08-29 12:58:15 -04:00
|
|
|
|
2014-04-06 23:30:04 -03:00
|
|
|
/**
|
2014-04-12 18:34:00 -03:00
|
|
|
* Decode a base58-encoded string (psz) into a byte vector (vchRet).
|
|
|
|
* return true if decoding is successful.
|
2017-08-07 01:36:37 -04:00
|
|
|
* psz cannot be nullptr.
|
2014-04-06 23:30:04 -03:00
|
|
|
*/
|
2018-09-25 02:00:36 -03:00
|
|
|
NODISCARD bool DecodeBase58(const char* psz, std::vector<unsigned char>& vchRet);
|
2010-08-29 12:58:15 -04:00
|
|
|
|
2014-04-06 23:30:04 -03:00
|
|
|
/**
|
2014-04-12 18:34:00 -03:00
|
|
|
* Decode a base58-encoded string (str) into a byte vector (vchRet).
|
|
|
|
* return true if decoding is successful.
|
2014-04-06 23:30:04 -03:00
|
|
|
*/
|
2018-09-25 02:00:36 -03:00
|
|
|
NODISCARD bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet);
|
2010-08-29 12:58:15 -04:00
|
|
|
|
2014-04-06 23:30:04 -03:00
|
|
|
/**
|
|
|
|
* Encode a byte vector into a base58-encoded string, including checksum
|
|
|
|
*/
|
2014-05-09 17:42:20 -04:00
|
|
|
std::string EncodeBase58Check(const std::vector<unsigned char>& vchIn);
|
2010-08-29 12:58:15 -04:00
|
|
|
|
2014-04-06 23:30:04 -03:00
|
|
|
/**
|
|
|
|
* Decode a base58-encoded string (psz) that includes a checksum into a byte
|
|
|
|
* vector (vchRet), return true if decoding is successful
|
|
|
|
*/
|
2018-09-25 02:00:36 -03:00
|
|
|
NODISCARD bool DecodeBase58Check(const char* psz, std::vector<unsigned char>& vchRet);
|
2010-08-29 12:58:15 -04:00
|
|
|
|
2014-04-06 23:30:04 -03:00
|
|
|
/**
|
|
|
|
* Decode a base58-encoded string (str) that includes a checksum into a byte
|
|
|
|
* vector (vchRet), return true if decoding is successful
|
|
|
|
*/
|
2018-09-25 02:00:36 -03:00
|
|
|
NODISCARD bool DecodeBase58Check(const std::string& str, std::vector<unsigned char>& vchRet);
|
2017-08-22 22:02:33 -03:00
|
|
|
|
2012-11-09 08:50:59 -03:00
|
|
|
#endif // BITCOIN_BASE58_H
|