Line data Source code
1 : // Copyright (c) 2009-2010 Satoshi Nakamoto 2 : // Copyright (c) 2009-2021 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 : #ifndef BITCOIN_KEY_IO_H 7 : #define BITCOIN_KEY_IO_H 8 : 9 : #include <key.h> 10 : #include <pubkey.h> 11 : #include <script/standard.h> 12 : 13 : #include <string> 14 : 15 : class CChainParams; 16 : 17 : CKey DecodeSecret(const std::string& str); 18 : std::string EncodeSecret(const CKey& key); 19 : 20 : CExtKey DecodeExtKey(const std::string& str); 21 : std::string EncodeExtKey(const CExtKey& extkey); 22 : CExtPubKey DecodeExtPubKey(const std::string& str); 23 : std::string EncodeExtPubKey(const CExtPubKey& extpubkey); 24 : 25 : std::string EncodeDestination(const CTxDestination& dest); 26 : CTxDestination DecodeDestination(const std::string& str); 27 : CTxDestination DecodeDestination(const std::string& str, std::string& error_msg); 28 : bool IsValidDestinationString(const std::string& str); 29 : bool IsValidDestinationString(const std::string& str, const CChainParams& params); 30 : 31 : /** 32 : * DIP-18 Dash Platform addresses (bech32m). 33 : * 34 : * Platform addresses decode to a 20-byte HASH160 prefixed by a type byte: 35 : * 0xb0 -> Platform P2PKH (addresses of the form dash1k... / tdash1k...) 36 : * 0x80 -> Platform P2SH (addresses of the form dash1s... / tdash1s...) 37 : * 38 : * Unlike base58 Dash addresses, Platform destinations have no on-chain 39 : * scriptPubKey: they are only valid as credit output recipients of an 40 : * asset-lock special transaction (see DIP-27 and src/evo/assetlocktx.h). 41 : */ 42 : struct PlatformP2PKHDestination : public BaseHash<uint160> 43 : { 44 : PlatformP2PKHDestination() = default; 45 12 : explicit PlatformP2PKHDestination(const uint160& hash) : BaseHash(hash) {} 46 : }; 47 : 48 : struct PlatformP2SHDestination : public BaseHash<uint160> 49 : { 50 : PlatformP2SHDestination() = default; 51 4 : explicit PlatformP2SHDestination(const uint160& hash) : BaseHash(hash) {} 52 : }; 53 : 54 : using PlatformDestination = std::variant<CNoDestination, PlatformP2PKHDestination, PlatformP2SHDestination>; 55 : 56 : bool IsValidPlatformDestination(const PlatformDestination& dest); 57 : std::string EncodePlatformDestination(const PlatformDestination& dest); 58 : PlatformDestination DecodePlatformDestination(const std::string& str); 59 : PlatformDestination DecodePlatformDestination(const std::string& str, std::string& error_str); 60 : PlatformDestination DecodePlatformDestination(const std::string& str, const CChainParams& params, std::string& error_str); 61 : 62 : #endif // BITCOIN_KEY_IO_H