2010-08-29 18:58:15 +02:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2015-12-13 14:51:43 +01:00
|
|
|
// Copyright (c) 2009-2015 The Bitcoin Core developers
|
2014-10-31 01:43:19 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2012-05-18 16:02:28 +02:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2010-08-29 18:58:15 +02:00
|
|
|
|
2014-10-31 01:43:19 +01: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 16:47:17 +02: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 01:43:19 +01:00
|
|
|
* - E-mail usually won't line-break if there's no punctuation to break at.
|
2015-04-28 16:47:17 +02:00
|
|
|
* - Double-clicking selects the whole string as one word if it's all alphanumeric.
|
2014-10-31 01:43:19 +01:00
|
|
|
*/
|
2011-05-15 09:11:04 +02:00
|
|
|
#ifndef BITCOIN_BASE58_H
|
|
|
|
#define BITCOIN_BASE58_H
|
2010-08-29 18:58:15 +02:00
|
|
|
|
2021-03-22 18:10:27 +01:00
|
|
|
#include <attributes.h>
|
2020-08-19 13:39:33 +02:00
|
|
|
#include <span.h>
|
2021-03-22 18:10:27 +01:00
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2014-04-07 04:30:04 +02:00
|
|
|
/**
|
2020-08-19 13:39:33 +02:00
|
|
|
* Encode a byte span as a base58-encoded string
|
2014-04-07 04:30:04 +02:00
|
|
|
*/
|
2020-08-19 13:39:33 +02:00
|
|
|
std::string EncodeBase58(Span<const unsigned char> input);
|
2010-08-29 18:58:15 +02:00
|
|
|
|
2014-04-07 04:30:04 +02: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.
|
2019-08-06 05:08:33 +02:00
|
|
|
* psz cannot be nullptr.
|
2014-04-07 04:30:04 +02:00
|
|
|
*/
|
2019-12-12 10:55:37 +01:00
|
|
|
[[nodiscard]] bool DecodeBase58(const char* psz, std::vector<unsigned char>& vchRet, int max_ret_len);
|
2010-08-29 18:58:15 +02:00
|
|
|
|
2014-04-07 04:30:04 +02: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-07 04:30:04 +02:00
|
|
|
*/
|
2019-12-12 10:55:37 +01:00
|
|
|
[[nodiscard]] bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet, int max_ret_len);
|
2010-08-29 18:58:15 +02:00
|
|
|
|
2014-04-07 04:30:04 +02:00
|
|
|
/**
|
2020-08-19 13:39:33 +02:00
|
|
|
* Encode a byte span into a base58-encoded string, including checksum
|
2014-04-07 04:30:04 +02:00
|
|
|
*/
|
2020-08-19 13:39:33 +02:00
|
|
|
std::string EncodeBase58Check(Span<const unsigned char> input);
|
2010-08-29 18:58:15 +02:00
|
|
|
|
2014-04-07 04:30:04 +02:00
|
|
|
/**
|
|
|
|
* Decode a base58-encoded string (psz) that includes a checksum into a byte
|
|
|
|
* vector (vchRet), return true if decoding is successful
|
|
|
|
*/
|
2019-12-12 10:55:37 +01:00
|
|
|
[[nodiscard]] bool DecodeBase58Check(const char* psz, std::vector<unsigned char>& vchRet, int max_ret_len);
|
2010-08-29 18:58:15 +02:00
|
|
|
|
2014-04-07 04:30:04 +02:00
|
|
|
/**
|
|
|
|
* Decode a base58-encoded string (str) that includes a checksum into a byte
|
|
|
|
* vector (vchRet), return true if decoding is successful
|
|
|
|
*/
|
2019-12-12 10:55:37 +01:00
|
|
|
[[nodiscard]] bool DecodeBase58Check(const std::string& str, std::vector<unsigned char>& vchRet, int max_ret_len);
|
Merge #11117: Prepare for non-Base58 addresses (#3294)
* Merge #11117: Prepare for non-Base58 addresses
864cd2787 Move CBitcoinAddress to base58.cpp (Pieter Wuille)
5c8ff0d44 Introduce wrappers around CBitcoinAddress (Pieter Wuille)
Pull request description:
This patch removes the need for the intermediary Base58 type `CBitcoinAddress`, by providing {`Encode`,`Decode`,`IsValid`}`Destination` functions that directly operate on the conversion between `std::string`s and `CTxDestination`.
As a side, it also fixes a number of indentation issues, and removes probably several unnecessary implicit `CTxDestination`<->`CBitcoinAddress` conversions.
This change is far from complete. In follow-ups I'd like to:
* Split off the specific address and key encoding logic from base58.h, and move it to a address.h or so.
* Replace `CTxDestination` with a non-`boost::variant` version (which can be more efficient as `boost::variant` allocates everything on the heap, and remove the need for `boost::get<...>` and `IsValidDestination` calls everywhere).
* Do the same for `CBitcoinSecret`, `CBitcoinExtKey`, and `CBitcoinExtPubKey`.
However, I've tried to keep this patch to be minimally invasive, but still enough to support non-Base58 addresses. Perhaps a smaller patch is possible to hack Bech32 support into `CBitcoinAddress`, but I would consider that a move in the wrong direction.
Tree-SHA512: c2c77ffb57caeadf2429b1c2562ce60e8c7be8aa9f8e51b591f354b6b441162625b2efe14c023a1ae485cf2ed417263afa35c892891dfaa7844e7fbabccab85e
* CBitcoinAddress -> EncodeDestination in providertx.h
Signed-off-by: Pasta <pasta@dashboost.org>
* more CBitcoinAddress -> EncodeDestination in providertx.h
Signed-off-by: Pasta <pasta@dashboost.org>
* more CBitcoinAddress -> EncodeDestination in providertx.h
Signed-off-by: Pasta <pasta@dashboost.org>
* more CBitcoinAddress -> EncodeDestination in providertx.h
Signed-off-by: Pasta <pasta@dashboost.org>
* fix CBitcoinAddress GetKeyID check
Signed-off-by: Pasta <pasta@dashboost.org>
* fix providertx.cpp
Signed-off-by: Pasta <pasta@dashboost.org>
* hopefully fix governance-classes.cpp
Signed-off-by: Pasta <pasta@dashboost.org>
* partially fix governance-validators.cpp, unable to resolve "address.IsScript()"
Signed-off-by: Pasta <pasta@dashboost.org>
* partially fix governance-classes.cpp, unable to resolve "address.IsScript()"
Signed-off-by: Pasta <pasta@dashboost.org>
* fix governance-classes.h
Signed-off-by: Pasta <pasta@dashboost.org>
* DecodeTransaction -> DecodeDestination, fix governance-validators.cpp
Signed-off-by: Pasta <pasta@dashboost.org>
* More fixes for 3294
* Move GetIndexKey into rpc/misc.cpp near getAddressesFromParams
No need to have it in base58.cpp anymore as this is only used in getAddressesFromParams
Co-authored-by: Wladimir J. van der Laan <laanwj@gmail.com>
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
Co-authored-by: Alexander Block <ablock84@gmail.com>
2020-01-22 11:35:04 +01:00
|
|
|
|
2012-11-09 12:50:59 +01:00
|
|
|
#endif // BITCOIN_BASE58_H
|