#ifndef BITCOIN_TEST_FUZZ_UTIL_DESCRIPTOR_H
#define BITCOIN_TEST_FUZZ_UTIL_DESCRIPTOR_H
#include <key_io.h>
#include <util/strencodings.h>
#include <script/descriptor.h>
#include <test/fuzz/fuzz.h>
#include <functional>
class MockedDescriptorConverter {
private:
static constexpr uint8_t KEY_TYPES_COUNT{6};
static constexpr size_t TOTAL_KEYS_GENERATED{std::numeric_limits<uint8_t>::max() + 1};
std::array<std::string, TOTAL_KEYS_GENERATED> keys_str;
public:
bool IdIsCompPubKey(uint8_t idx) const { return idx % KEY_TYPES_COUNT == 0; }
bool IdIsUnCompPubKey(uint8_t idx) const { return idx % KEY_TYPES_COUNT == 1; }
bool IdIsXOnlyPubKey(uint8_t idx) const { return idx % KEY_TYPES_COUNT == 2; }
bool IdIsConstPrivKey(uint8_t idx) const { return idx % KEY_TYPES_COUNT == 3; }
bool IdIsXpub(uint8_t idx) const { return idx % KEY_TYPES_COUNT == 4; }
bool IdIsXprv(uint8_t idx) const { return idx % KEY_TYPES_COUNT == 5; }
void Init();
std::optional<uint8_t> IdxFromHex(std::string_view hex_characters) const;
std::optional<std::string> GetDescriptor(std::string_view mocked_desc) const;
};
constexpr int MAX_DEPTH{2};
bool HasDeepDerivPath(const FuzzBufferType& buff, const int max_depth = MAX_DEPTH);
constexpr int MAX_SUBS{1'000};
//! Maximum number of nested sub-fragments we'll allow in a descriptor.
constexpr size_t MAX_NESTED_SUBS{10'000};
/**
* Whether the buffer, if it represents a valid descriptor, contains a fragment with more
* sub-fragments than the given maximum.
*/
bool HasTooManySubFrag(const FuzzBufferType& buff, const int max_subs = MAX_SUBS,
const size_t max_nested_subs = MAX_NESTED_SUBS);
//! Default maximum number of wrappers per fragment.
constexpr int MAX_WRAPPERS{100};
/**
* Whether the buffer, if it represents a valid descriptor, contains a fragment with more
* wrappers than the given maximum.
*/
bool HasTooManyWrappers(const FuzzBufferType& buff, const int max_wrappers = MAX_WRAPPERS);
#endif // BITCOIN_TEST_FUZZ_UTIL_DESCRIPTOR_H