2010-08-29 16:58:15 +00:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2018-01-03 02:12:05 +09:00
|
|
|
// Copyright (c) 2009-2017 The Bitcoin Core developers
|
2014-10-31 08:43:19 +08:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2012-05-18 22:02:28 +08:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2010-08-29 16:58:15 +00:00
|
|
|
|
2014-10-31 08:43:19 +08: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 14:47:17 +00: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-31 08:43:19 +08:00
|
|
|
* - E-mail usually won't line-break if there's no punctuation to break at.
|
2015-04-28 14:47:17 +00:00
|
|
|
* - Double-clicking selects the whole string as one word if it's all alphanumeric.
|
2014-10-31 08:43:19 +08:00
|
|
|
*/
|
2011-05-15 09:11:04 +02:00
|
|
|
#ifndef BITCOIN_BASE58_H
|
|
|
|
#define BITCOIN_BASE58_H
|
2010-08-29 16:58:15 +00:00
|
|
|
|
2017-11-10 13:57:53 +13:00
|
|
|
#include <chainparams.h>
|
|
|
|
#include <key.h>
|
|
|
|
#include <pubkey.h>
|
|
|
|
#include <script/standard.h>
|
|
|
|
#include <support/allocators/zeroafterfree.h>
|
2013-04-13 00:13:08 -05:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2014-04-06 22:30:04 -04:00
|
|
|
/**
|
2014-04-12 23:34:00 +02:00
|
|
|
* Encode a byte sequence as a base58-encoded string.
|
2017-08-07 07:36:37 +02:00
|
|
|
* pbegin and pend cannot be nullptr, unless both are.
|
2014-04-06 22:30:04 -04:00
|
|
|
*/
|
2014-04-12 23:34:00 +02:00
|
|
|
std::string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend);
|
2010-08-29 16:58:15 +00:00
|
|
|
|
2014-04-06 22:30:04 -04:00
|
|
|
/**
|
|
|
|
* Encode a byte vector as a base58-encoded string
|
|
|
|
*/
|
2014-05-09 23:42:20 +02:00
|
|
|
std::string EncodeBase58(const std::vector<unsigned char>& vch);
|
2010-08-29 16:58:15 +00:00
|
|
|
|
2014-04-06 22:30:04 -04:00
|
|
|
/**
|
2014-04-12 23:34:00 +02:00
|
|
|
* Decode a base58-encoded string (psz) into a byte vector (vchRet).
|
|
|
|
* return true if decoding is successful.
|
2017-08-07 07:36:37 +02:00
|
|
|
* psz cannot be nullptr.
|
2014-04-06 22:30:04 -04:00
|
|
|
*/
|
2014-04-12 23:34:00 +02:00
|
|
|
bool DecodeBase58(const char* psz, std::vector<unsigned char>& vchRet);
|
2010-08-29 16:58:15 +00:00
|
|
|
|
2014-04-06 22:30:04 -04:00
|
|
|
/**
|
2014-04-12 23:34:00 +02:00
|
|
|
* Decode a base58-encoded string (str) into a byte vector (vchRet).
|
|
|
|
* return true if decoding is successful.
|
2014-04-06 22:30:04 -04:00
|
|
|
*/
|
2014-05-09 23:42:20 +02:00
|
|
|
bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet);
|
2010-08-29 16:58:15 +00:00
|
|
|
|
2014-04-06 22:30:04 -04:00
|
|
|
/**
|
|
|
|
* Encode a byte vector into a base58-encoded string, including checksum
|
|
|
|
*/
|
2014-05-09 23:42:20 +02:00
|
|
|
std::string EncodeBase58Check(const std::vector<unsigned char>& vchIn);
|
2010-08-29 16:58:15 +00:00
|
|
|
|
2014-04-06 22:30:04 -04:00
|
|
|
/**
|
|
|
|
* Decode a base58-encoded string (psz) that includes a checksum into a byte
|
|
|
|
* vector (vchRet), return true if decoding is successful
|
|
|
|
*/
|
2014-05-09 23:42:20 +02:00
|
|
|
inline bool DecodeBase58Check(const char* psz, std::vector<unsigned char>& vchRet);
|
2010-08-29 16:58:15 +00:00
|
|
|
|
2014-04-06 22:30:04 -04:00
|
|
|
/**
|
|
|
|
* Decode a base58-encoded string (str) that includes a checksum into a byte
|
|
|
|
* vector (vchRet), return true if decoding is successful
|
|
|
|
*/
|
2014-05-09 23:42:20 +02:00
|
|
|
inline bool DecodeBase58Check(const std::string& str, std::vector<unsigned char>& vchRet);
|
2010-08-29 16:58:15 +00:00
|
|
|
|
2017-09-19 16:49:52 -07:00
|
|
|
CKey DecodeSecret(const std::string& str);
|
|
|
|
std::string EncodeSecret(const CKey& key);
|
2011-07-11 21:48:09 +02:00
|
|
|
|
2017-09-19 17:13:46 -07:00
|
|
|
CExtKey DecodeExtKey(const std::string& str);
|
|
|
|
std::string EncodeExtKey(const CExtKey& extkey);
|
|
|
|
CExtPubKey DecodeExtPubKey(const std::string& str);
|
|
|
|
std::string EncodeExtPubKey(const CExtPubKey& extpubkey);
|
2013-07-15 01:05:25 +02:00
|
|
|
|
2017-08-22 18:02:33 -07:00
|
|
|
std::string EncodeDestination(const CTxDestination& dest);
|
|
|
|
CTxDestination DecodeDestination(const std::string& str);
|
|
|
|
bool IsValidDestinationString(const std::string& str);
|
|
|
|
bool IsValidDestinationString(const std::string& str, const CChainParams& params);
|
|
|
|
|
2012-11-09 12:50:59 +01:00
|
|
|
#endif // BITCOIN_BASE58_H
|