Line data Source code
1 : // Copyright (c) 2018 The Bitcoin Core developers 2 : // Copyright (c) 2022 The PIVX 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 PIVX_SCRIPT_DESCRIPTOR_H 7 : #define PIVX_SCRIPT_DESCRIPTOR_H 8 : 9 : #include <script/script.h> 10 : #include <script/sign.h> 11 : 12 : #include <vector> 13 : 14 : // Descriptors are strings that describe a set of scriptPubKeys, together with 15 : // all information necessary to solve them. By combining all information into 16 : // one, they avoid the need to separately import keys and scripts. 17 : // 18 : // Descriptors may be ranged, which occurs when the public keys inside are 19 : // specified in the form of HD chains (xpubs). 20 : // 21 : // Descriptors always represent public information - public keys and scripts - 22 : // but in cases where private keys need to be conveyed along with a descriptor, 23 : // they can be included inside by changing public keys to private keys (WIF 24 : // format), and changing xpubs by xprvs. 25 : // 26 : // Reference documentation about the descriptor language can be found in 27 : // doc/descriptors.md. 28 : 29 : /** Interface for parsed descriptor objects. */ 30 37 : struct Descriptor { 31 0 : virtual ~Descriptor() = default; 32 : 33 : /** Whether the expansion of this descriptor depends on the position. */ 34 : virtual bool IsRange() const = 0; 35 : 36 : /** Convert the descriptor back to a string, undoing parsing. */ 37 : virtual std::string ToString() const = 0; 38 : 39 : /** Convert the descriptor to a private string. This fails if the provided provider does not have the relevant private keys. */ 40 : virtual bool ToPrivateString(const SigningProvider& provider, std::string& out) const = 0; 41 : 42 : /** Expand a descriptor at a specified position. 43 : * 44 : * pos: the position at which to expand the descriptor. If IsRange() is false, this is ignored. 45 : * provider: the provider to query for private keys in case of hardened derivation. 46 : * output_script: the expanded scriptPubKeys will be put here. 47 : * out: scripts and public keys necessary for solving the expanded scriptPubKeys will be put here (may be equal to provider). 48 : */ 49 : virtual bool Expand(int pos, const SigningProvider& provider, std::vector<CScript>& output_scripts, FlatSigningProvider& out) const = 0; 50 : }; 51 : 52 : /** Parse a descriptor string. Included private keys are put in out. Returns nullptr if parsing fails. */ 53 : std::unique_ptr<Descriptor> Parse(const std::string& descriptor, FlatSigningProvider& out); 54 : 55 : #endif // PIVX_SCRIPT_DESCRIPTOR_H