1 // Copyright (c) 2020 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <chainparams.h>
6 #include <key_io.h>
7 #include <rpc/util.h>
8 #include <script/signingprovider.h>
9 #include <script/standard.h>
10 #include <test/fuzz/fuzz.h>
11 
12 #include <cassert>
13 #include <cstdint>
14 #include <string>
15 #include <vector>
16 
initialize()17 void initialize()
18 {
19     static const ECCVerifyHandle verify_handle;
20     ECC_Start();
21     SelectParams(CBaseChainParams::MAIN);
22 }
23 
test_one_input(const std::vector<uint8_t> & buffer)24 void test_one_input(const std::vector<uint8_t>& buffer)
25 {
26     const std::string random_string(buffer.begin(), buffer.end());
27 
28     const CKey key = DecodeSecret(random_string);
29     if (key.IsValid()) {
30         assert(key == DecodeSecret(EncodeSecret(key)));
31     }
32 
33     const CExtKey ext_key = DecodeExtKey(random_string);
34     if (ext_key.key.size() == 32) {
35         assert(ext_key == DecodeExtKey(EncodeExtKey(ext_key)));
36     }
37 
38     const CExtPubKey ext_pub_key = DecodeExtPubKey(random_string);
39     if (ext_pub_key.pubkey.size() == CPubKey::COMPRESSED_SIZE) {
40         assert(ext_pub_key == DecodeExtPubKey(EncodeExtPubKey(ext_pub_key)));
41     }
42 
43     const CTxDestination tx_destination = DecodeDestination(random_string);
44     (void)DescribeAddress(tx_destination);
45     (void)GetKeyForDestination(/* store */ {}, tx_destination);
46     (void)GetScriptForDestination(tx_destination);
47     (void)IsValidDestination(tx_destination);
48 
49     (void)IsValidDestinationString(random_string);
50 }
51