|  | 
|  | 1 | +#ifndef LIBWALLY_CORE_DESCRIPTOR_H | 
|  | 2 | +#define LIBWALLY_CORE_DESCRIPTOR_H | 
|  | 3 | + | 
|  | 4 | +#include "wally_core.h" | 
|  | 5 | + | 
|  | 6 | +#ifdef __cplusplus | 
|  | 7 | +extern "C" { | 
|  | 8 | +#endif | 
|  | 9 | + | 
|  | 10 | +struct wally_map; | 
|  | 11 | + | 
|  | 12 | +/* Miniscript type flag */ | 
|  | 13 | +#define WALLY_MINISCRIPT_WITNESS_SCRIPT 0x00 /** Witness script */ | 
|  | 14 | +#define WALLY_MINISCRIPT_TAPSCRIPT      0x01 /** Tapscript */ | 
|  | 15 | + | 
|  | 16 | +/** | 
|  | 17 | + * Canonicalize a descriptor. | 
|  | 18 | + * | 
|  | 19 | + * :param descriptor: Output descriptor. | 
|  | 20 | + * :param vars_in: Map of variable names to values, or NULL. | 
|  | 21 | + * :param flags: For future use. Must be 0. | 
|  | 22 | + * :param output: Destination for the resulting canonical descriptor. | 
|  | 23 | + *|    The string returned should be freed using `wally_free_string`. | 
|  | 24 | + * | 
|  | 25 | + * Replaces any variables from ``vars_in`` with their mapped values, | 
|  | 26 | + * and adds a checksum if required. Key names for ``vars_in`` must be 16 | 
|  | 27 | + * characters or less and start with a letter. | 
|  | 28 | + * | 
|  | 29 | + * .. note:: Other canonicalization (hardened derivation indicator | 
|  | 30 | + * mapping, and private to public key mapping) is not yet implemented. | 
|  | 31 | + */ | 
|  | 32 | +WALLY_CORE_API int wally_descriptor_canonicalize( | 
|  | 33 | +    const char *descriptor, | 
|  | 34 | +    const struct wally_map *vars_in, | 
|  | 35 | +    uint32_t flags, | 
|  | 36 | +    char **output); | 
|  | 37 | + | 
|  | 38 | +/** | 
|  | 39 | + * Create a script corresponding to a miniscript string. | 
|  | 40 | + * | 
|  | 41 | + * :param miniscript: Miniscript string. | 
|  | 42 | + * :param vars_in: Map of variable names to values, or NULL. | 
|  | 43 | + * :param child_num: The BIP32 child number to derive. | 
|  | 44 | + * :param flags: Flags controlling the type of script to create. Use one of | 
|  | 45 | + *|    ``WALLY_MINISCRIPT_WITNESS_SCRIPT`` or ``WALLY_MINISCRIPT_TAPSCRIPT``. | 
|  | 46 | + * :param bytes_out: Destination for the resulting scriptPubkey. | 
|  | 47 | + * :param len: The length of ``bytes_out`` in bytes. | 
|  | 48 | + * :param written: Destination for the number of bytes written to ``bytes_out``. | 
|  | 49 | + */ | 
|  | 50 | +WALLY_CORE_API int wally_miniscript_to_script( | 
|  | 51 | +    const char *miniscript, | 
|  | 52 | +    const struct wally_map *vars_in, | 
|  | 53 | +    uint32_t child_num, | 
|  | 54 | +    uint32_t flags, | 
|  | 55 | +    unsigned char *bytes_out, | 
|  | 56 | +    size_t len, | 
|  | 57 | +    size_t *written); | 
|  | 58 | + | 
|  | 59 | +/** | 
|  | 60 | + * Create a scriptPubKey corresponding to an output descriptor. | 
|  | 61 | + * | 
|  | 62 | + * :param descriptor: Output descriptor. | 
|  | 63 | + * :param vars_in: Map of variable names to values, or NULL. | 
|  | 64 | + * :param child_num: The BIP32 child number to derive. | 
|  | 65 | + * :param network: ``WALLY_NETWORK_`` constant descripting the network to generate for. | 
|  | 66 | + * :param depth: Number of the descriptor depth. Default is 0. | 
|  | 67 | + * :param index: Number of the descriptor index. Default is 0. | 
|  | 68 | + * :param flags: For future use. Must be 0. | 
|  | 69 | + * :param bytes_out: Destination for the resulting scriptPubkey. | 
|  | 70 | + * :param len: The length of ``bytes_out`` in bytes. | 
|  | 71 | + * :param written: Destination for the number of bytes written to ``bytes_out``. | 
|  | 72 | + */ | 
|  | 73 | +WALLY_CORE_API int wally_descriptor_to_scriptpubkey( | 
|  | 74 | +    const char *descriptor, | 
|  | 75 | +    const struct wally_map *vars_in, | 
|  | 76 | +    uint32_t child_num, | 
|  | 77 | +    uint32_t network, | 
|  | 78 | +    uint32_t depth, | 
|  | 79 | +    uint32_t index, | 
|  | 80 | +    uint32_t flags, | 
|  | 81 | +    unsigned char *bytes_out, | 
|  | 82 | +    size_t len, | 
|  | 83 | +    size_t *written); | 
|  | 84 | + | 
|  | 85 | +/** | 
|  | 86 | + * Create an address corresponding to an output descriptor. | 
|  | 87 | + * | 
|  | 88 | + * :param descriptor: Output descriptor. | 
|  | 89 | + * :param vars_in: Map of variable names to values, or NULL. | 
|  | 90 | + * :param child_num: The BIP32 child number to derive. | 
|  | 91 | + * :param network: ``WALLY_NETWORK_`` constant descripting the network to generate for. | 
|  | 92 | + * :param flags: For future use. Must be 0. | 
|  | 93 | + * :param output: Destination for the resulting addresss. | 
|  | 94 | + *|    The string returned should be freed using `wally_free_string`. | 
|  | 95 | + */ | 
|  | 96 | +WALLY_CORE_API int wally_descriptor_to_address( | 
|  | 97 | +    const char *descriptor, | 
|  | 98 | +    const struct wally_map *vars_in, | 
|  | 99 | +    uint32_t child_num, | 
|  | 100 | +    uint32_t network, | 
|  | 101 | +    uint32_t flags, | 
|  | 102 | +    char **output); | 
|  | 103 | + | 
|  | 104 | +/** | 
|  | 105 | + * Create addresses that correspond to the derived range of an output descriptor. | 
|  | 106 | + * | 
|  | 107 | + * :param descriptor: Output descriptor. | 
|  | 108 | + * :param vars_in: Map of variable names to values, or NULL. | 
|  | 109 | + * :param child_num: The first BIP32 child number to derive. | 
|  | 110 | + * :param network: ``WALLY_NETWORK_`` constant descripting the network to generate for. | 
|  | 111 | + * :param flags: For future use. Must be 0. | 
|  | 112 | + * :param output: Destination for the resulting addresses. | 
|  | 113 | + * :param num_outputs: The number of items in ``output``. Addresses will be | 
|  | 114 | + *|    generated into this array starting from child_num, incrementing by 1. | 
|  | 115 | + *|    The addresses returned should be freed using `wally_free_string`. | 
|  | 116 | + */ | 
|  | 117 | +WALLY_CORE_API int wally_descriptor_to_addresses( | 
|  | 118 | +    const char *descriptor, | 
|  | 119 | +    const struct wally_map *vars_in, | 
|  | 120 | +    uint32_t child_num, | 
|  | 121 | +    uint32_t network, | 
|  | 122 | +    uint32_t flags, | 
|  | 123 | +    char **output, | 
|  | 124 | +    size_t num_outputs); | 
|  | 125 | + | 
|  | 126 | +/** | 
|  | 127 | + * Create an output descriptor checksum. | 
|  | 128 | + * | 
|  | 129 | + * :param descriptor: Output descriptor. | 
|  | 130 | + * :param vars_in: Map of variable names to values, or NULL. | 
|  | 131 | + * :param flags: For future use. Must be 0. | 
|  | 132 | + * :param output: Destination for the resulting descriptor checksum. | 
|  | 133 | + *|    The string returned should be freed using `wally_free_string`. | 
|  | 134 | + */ | 
|  | 135 | +WALLY_CORE_API int wally_descriptor_get_checksum( | 
|  | 136 | +    const char *descriptor, | 
|  | 137 | +    const struct wally_map *vars_in, | 
|  | 138 | +    uint32_t flags, | 
|  | 139 | +    char **output); | 
|  | 140 | + | 
|  | 141 | +#ifdef __cplusplus | 
|  | 142 | +} | 
|  | 143 | +#endif | 
|  | 144 | + | 
|  | 145 | +#endif /* LIBWALLY_CORE_DESCRIPTOR_H */ | 
0 commit comments