-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for output descriptors/miniscript.
Co-authored-by: Jon Griffiths <[email protected]>
- Loading branch information
1 parent
8bb8687
commit 4d430b8
Showing
27 changed files
with
4,873 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ libwally-core documentation | |
map | ||
psbt | ||
script | ||
descriptor | ||
symmetric | ||
transaction | ||
elements | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
#ifndef LIBWALLY_CORE_DESCRIPTOR_H | ||
#define LIBWALLY_CORE_DESCRIPTOR_H | ||
|
||
#include "wally_core.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
struct wally_map; | ||
/** An opaque type holding a parsed minscript/descriptor expression */ | ||
struct wally_descriptor; | ||
|
||
/* Miniscript type flag */ | ||
#define WALLY_MINISCRIPT_WITNESS_SCRIPT 0x00 /** Witness script */ | ||
#define WALLY_MINISCRIPT_TAPSCRIPT 0x01 /** Tapscript */ | ||
#define WALLY_MINISCRIPT_ONLY 0x02 /** Only allow miniscript (not descriptor) expressions */ | ||
|
||
#define WALLY_MS_IS_RANGED 0x01 /** Allows key ranges via '*' */ | ||
|
||
|
||
/** | ||
* Parse an output descriptor or miniscript expression. | ||
* | ||
* :param descriptor: Output descriptor or miniscript expression to parse. | ||
* :param vars_in: Map of variable names to values, or NULL. | ||
* :param network: ``WALLY_NETWORK_`` constant descripting the network the | ||
*| descriptor belongs to, or WALLY_NETWORK_NONE for miniscript-only expressions. | ||
* :param flags: Include ``WALLY_MINISCRIPT_ONLY`` to disallow descriptor | ||
*| expressions, ``WALLY_MINISCRIPT_TAPSCRIPT`` to use x-only pubkeys, or 0. | ||
* :param output: Destination for the resulting parsed descriptor. | ||
*| The descriptor returned should be freed using `wally_descriptor_free`. | ||
* | ||
* Variable names can be used in the descriptor string and will be substituted | ||
* with the contents of ``vars_in`` during parsing. Key names for ``vars_in`` | ||
* must be 16 characters or less in length and start with a letter. | ||
*/ | ||
WALLY_CORE_API int wally_descriptor_parse( | ||
const char *descriptor, | ||
const struct wally_map *vars_in, | ||
uint32_t network, | ||
uint32_t flags, | ||
struct wally_descriptor **output); | ||
|
||
/** | ||
* Free a parsed output descriptor or miniscript expression. | ||
* | ||
* :param descriptor: Parsed output descriptor or miniscript expression to free. | ||
*/ | ||
WALLY_CORE_API int wally_descriptor_free( | ||
struct wally_descriptor *descriptor); | ||
|
||
/** | ||
* Canonicalize a descriptor. | ||
* | ||
* :param descriptor: Parsed output descriptor or miniscript expression. | ||
* :param flags: For future use. Must be 0. | ||
* :param output: Destination for the resulting canonical descriptor. | ||
*| The string returned should be freed using `wally_free_string`. | ||
* | ||
* .. note:: Other canonicalization (hardened derivation indicator | ||
* mapping, and private to public key mapping) is not yet implemented. | ||
*/ | ||
WALLY_CORE_API int wally_descriptor_canonicalize( | ||
const struct wally_descriptor *descriptor, | ||
uint32_t flags, | ||
char **output); | ||
|
||
/** | ||
* Create an output descriptor checksum. | ||
* | ||
* :param descriptor: Parsed output descriptor or miniscript expression. | ||
* :param flags: For future use. Must be 0. | ||
* :param output: Destination for the resulting descriptor checksum. | ||
*| The string returned should be freed using `wally_free_string`. | ||
*/ | ||
WALLY_CORE_API int wally_descriptor_get_checksum( | ||
const struct wally_descriptor *descriptor, | ||
uint32_t flags, | ||
char **output); | ||
|
||
/** | ||
* Get the features used in a parsed output descriptor or miniscript expression. | ||
* | ||
* :param descriptor: Parsed output descriptor or miniscript expression. | ||
* :param value_out: Destination for the resulting ``WALLY_MS_`` feature flags. | ||
*/ | ||
WALLY_CORE_API int wally_descriptor_get_features( | ||
const struct wally_descriptor *descriptor, | ||
uint32_t *value_out); | ||
|
||
/** | ||
* Get the maximum length of a script corresponding to an output descriptor. | ||
* | ||
* :param descriptor: Parsed output descriptor or miniscript expression. | ||
* :param flags: For future use. Must be 0. | ||
* :param written: Destination for the resulting maximum script length. | ||
* | ||
* .. note:: This function overestimates the script size required, but is | ||
*| cheap to compute (does not require script generation). | ||
*/ | ||
WALLY_CORE_API int wally_descriptor_to_script_get_maximum_length( | ||
const struct wally_descriptor *descriptor, | ||
uint32_t flags, | ||
size_t *written); | ||
|
||
/** | ||
* Create a script corresponding to an output descriptor or miniscript expression. | ||
* | ||
* :param descriptor: Parsed output descriptor or miniscript expression. | ||
* :param depth: Depth of the expression tree to generate from. Pass 0 to generate from the root. | ||
* :param index: The zero-based index of the child at depth ``depth`` to generate from. | ||
* :param variant: The variant of descriptor to generate. Pass 0 for the default. | ||
* :param child_num: The BIP32 child number to derive, or 0 for static descriptors. | ||
* :param flags: For future use. Must be 0. | ||
* :param bytes_out: Destination for the resulting scriptPubKey or script. | ||
* :param len: The length of ``bytes_out`` in bytes. | ||
* :param written: Destination for the number of bytes written to ``bytes_out``. | ||
*/ | ||
WALLY_CORE_API int wally_descriptor_to_script( | ||
struct wally_descriptor *descriptor, | ||
uint32_t depth, | ||
uint32_t index, | ||
uint32_t variant, | ||
uint32_t child_num, | ||
uint32_t flags, | ||
unsigned char *bytes_out, | ||
size_t len, | ||
size_t *written); | ||
|
||
/** | ||
* Create an address corresponding to an output descriptor. | ||
* | ||
* :param descriptor: Parsed output descriptor. | ||
* :param variant: The variant of descriptor to generate. Pass 0 for the default. | ||
* :param child_num: The BIP32 child number to derive, or zero for static descriptors. | ||
* :param flags: For future use. Must be 0. | ||
* :param output: Destination for the resulting addresss. | ||
*| The string returned should be freed using `wally_free_string`. | ||
*/ | ||
WALLY_CORE_API int wally_descriptor_to_address( | ||
struct wally_descriptor *descriptor, | ||
uint32_t variant, | ||
uint32_t child_num, | ||
uint32_t flags, | ||
char **output); | ||
|
||
/** | ||
* Create addresses that correspond to the derived range of an output descriptor. | ||
* | ||
* :param descriptor: Parsed output descriptor. | ||
* :param variant: The variant of descriptor to generate. Pass 0 for the default. | ||
* :param child_num: The BIP32 child number to derive, or zero for static descriptors. | ||
* :param flags: For future use. Must be 0. | ||
* :param output: Destination for the resulting addresses. | ||
* :param num_outputs: The number of items in ``output``. Addresses will be | ||
*| generated into this array starting from child_num, incrementing by 1. | ||
*| The addresses returned should be freed using `wally_free_string`. | ||
*/ | ||
WALLY_CORE_API int wally_descriptor_to_addresses( | ||
struct wally_descriptor *descriptor, | ||
uint32_t variant, | ||
uint32_t child_num, | ||
uint32_t flags, | ||
char **output, | ||
size_t num_outputs); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* LIBWALLY_CORE_DESCRIPTOR_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.