5 #include <chainparams.h> 26 std::array<std::string, TOTAL_KEYS_GENERATED>
keys_str;
40 std::array<std::byte, 32> key_data{std::byte{1}};
43 key_data[31] = std::byte(i);
73 std::optional<uint8_t>
IdxFromHex(std::string_view hex_characters)
const {
74 if (hex_characters.size() != 2)
return {};
76 if (idx.size() != 1)
return {};
81 std::optional<std::string>
GetDescriptor(std::string_view mocked_desc)
const {
83 if (mocked_desc.size() < 7)
return {};
87 desc.reserve(mocked_desc.size());
90 for (
size_t i = 0; i < mocked_desc.size();) {
91 if (mocked_desc[i] ==
'%') {
92 if (i + 3 >= mocked_desc.size())
return {};
93 if (
const auto idx =
IdxFromHex(mocked_desc.substr(i + 1, 2))) {
100 desc += mocked_desc[i++];
127 std::vector<CScript> out_scripts;
128 (void)desc.
Expand(0, sig_provider, out_scripts, sig_provider, &cache);
133 if (!out_scripts.empty()) {
145 const bool is_nontop_or_nonsolvable{!is_solvable || !desc.
GetOutputType()};
146 const bool is_input_size_info_set{max_sat_maxsig && max_sat_nonmaxsig && max_elems};
147 assert(is_input_size_info_set || is_nontop_or_nonsolvable);
164 const std::string mocked_descriptor{buffer.begin(), buffer.end()};
168 const auto desc =
Parse(*descriptor, signing_provider,
error);
175 const std::string descriptor(buffer.begin(), buffer.end());
178 for (
const bool require_checksum : {
true,
false}) {
179 const auto desc =
Parse(descriptor, signing_provider,
error, require_checksum);
static constexpr size_t TOTAL_KEYS_GENERATED
How many keys we'll generate in total.
static UniValue Parse(std::string_view raw)
Parse string to UniValue or throw runtime_error if string contains invalid JSON.
virtual std::optional< int64_t > MaxSatisfactionWeight(bool use_max_sig) const =0
Get the maximum size of a satisfaction for this descriptor, in weight units.
virtual bool IsSingleType() const =0
Whether this descriptor will return one scriptPubKey or multiple (aka is or is not combo) ...
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
CPubKey GetPubKey() const
Compute the public key from a private key.
std::array< std::string, TOTAL_KEYS_GENERATED > keys_str
256 keys of various types.
static constexpr uint8_t KEY_TYPES_COUNT
Types are raw (un)compressed pubkeys, raw xonly pubkeys, raw privkeys (WIF), xpubs, xprvs.
bool IdIsXpub(uint8_t idx) const
bool IdIsXprv(uint8_t idx) const
std::optional< uint8_t > IdxFromHex(std::string_view hex_characters) const
Parse an id in the keys vectors from a 2-characters hex string.
bool IdIsCompPubKey(uint8_t idx) const
virtual bool IsSolvable() const =0
Whether this descriptor has all information about signing ignoring lack of private keys...
bool IdIsXOnlyPubKey(uint8_t idx) const
virtual bool ExpandFromCache(int pos, const DescriptorCache &read_cache, std::vector< CScript > &output_scripts, FlatSigningProvider &out) const =0
Expand a descriptor at a specified position using cached expansion data.
std::optional< std::string > GetDescriptor(std::string_view mocked_desc) const
Get an actual descriptor string from a descriptor string whose keys were mocked.
FUZZ_TARGET(mocked_descriptor_parse,.init=initialize_mocked_descriptor_parse)
virtual void ExpandPrivate(int pos, const SigningProvider &provider, FlatSigningProvider &out) const =0
Expand the private key for a descriptor at a specified position, if possible.
static void TestDescriptor(const Descriptor &desc, FlatSigningProvider &sig_provider, std::string &dummy)
Test a successfully parsed descriptor.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
An encapsulated public key.
virtual bool ToNormalizedString(const SigningProvider &provider, std::string &out, const DescriptorCache *cache=nullptr) const =0
Convert the descriptor to a normalized string.
void Init()
When initializing the target, populate the list of keys.
void initialize_descriptor_parse()
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
virtual std::optional< int64_t > MaxSatisfactionElems() const =0
Get the maximum size number of stack elements for satisfying this descriptor.
void initialize_mocked_descriptor_parse()
virtual std::optional< int64_t > ScriptSize() const =0
Get the size of the scriptPubKey for this descriptor.
virtual bool Expand(int pos, const SigningProvider &provider, std::vector< CScript > &output_scripts, FlatSigningProvider &out, DescriptorCache *write_cache=nullptr) const =0
Expand a descriptor at a specified position.
std::string EncodeExtPubKey(const CExtPubKey &key)
void SetSeed(Span< const std::byte > seed)
std::unique_ptr< Descriptor > InferDescriptor(const CScript &script, const SigningProvider &provider)
Find a descriptor for the specified script, using information from provider where possible...
Converts a mocked descriptor string to a valid one.
CExtPubKey Neuter() const
bool error(const char *fmt, const Args &... args)
Cache for single descriptor's derived extended pubkeys.
unsigned char * UCharCast(char *c)
MockedDescriptorConverter MOCKED_DESC_CONVERTER
The converter of mocked descriptors, needs to be initialized when the target is.
An encapsulated private key.
virtual bool IsRange() const =0
Whether the expansion of this descriptor depends on the position.
virtual std::optional< OutputType > GetOutputType() const =0
bool IdIsConstPrivKey(uint8_t idx) const
virtual std::string ToString(bool compat_format=false) const =0
Convert the descriptor back to a string, undoing parsing.
std::string EncodeSecret(const CKey &key)
virtual bool ToPrivateString(const SigningProvider &provider, std::string &out) const =0
Convert the descriptor to a private string.
std::string EncodeExtKey(const CExtKey &key)
void SelectParams(const ChainType chain)
Sets the params returned by Params() to those for the given chain type.
Interface for parsed descriptor objects.
bool IdIsUnCompPubKey(uint8_t idx) const